Skip to content

Commit

Permalink
RangeCard - Take bore height into account
Browse files Browse the repository at this point in the history
  • Loading branch information
ulteq committed Nov 28, 2016
1 parent 23ff625 commit c5187fd
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 43 deletions.
2 changes: 1 addition & 1 deletion addons/rangecard/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CfgVehicles {
class GVAR(makeCopy) {
displayName = CSTRING(CopyRangeCard);
condition = QUOTE(call FUNC(canShow) && !GVAR(RangeCardOpened));
statement = QUOTE(GVAR(ammoClassCopy) = GVAR(ammoClass); GVAR(magazineClassCopy) = GVAR(magazineClass); GVAR(weaponClassCopy) = GVAR(ammoClass););
statement = QUOTE(GVAR(zeroRangeCopy)=GVAR(zeroRange); GVAR(boreHeightCopy)=GVAR(boreHeight); GVAR(ammoClassCopy)=GVAR(ammoClass); GVAR(magazineClassCopy)=GVAR(magazineClass); GVAR(weaponClassCopy)=GVAR(weaponClass););
showDisabled = 0;
priority = 0.1;
icon = QPATHTOF(UI\RangeCard_Icon.paa);
Expand Down
2 changes: 2 additions & 0 deletions addons/rangecard/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ GVAR(RangeCardOpened) = false;
GVAR(controls) = [];

GVAR(zeroRange) = 100;
GVAR(boreHeight) = 3.81;
GVAR(ammoClass) = "B_65x39_Caseless";
GVAR(magazineClass) = "30Rnd_65x39_caseless_mag";
GVAR(weaponClass) = "arifle_MXM_F";

GVAR(zeroRangeCopy) = 100;
GVAR(boreHeightCopy) = 3.81;
GVAR(ammoClassCopy) = "";//"ACE_762x51_Ball_M118LR";
GVAR(magazineClassCopy) = "";//"ACE_20Rnd_762x51_M118LR_Mag";
GVAR(weaponClassCopy) = "";//srifle_DMR_06_olive_F";
4 changes: 2 additions & 2 deletions addons/rangecard/functions/fnc_openRangeCard.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ if (_this) then {

createDialog "ACE_RangeCard_Dialog";

[GVAR(zeroRangeCopy), GVAR(ammoClassCopy), GVAR(magazineClassCopy), GVAR(weaponClassCopy)] call FUNC(updateRangeCard);
[GVAR(zeroRangeCopy), GVAR(boreHeightCopy), GVAR(ammoClassCopy), GVAR(magazineClassCopy), GVAR(weaponClassCopy)] call FUNC(updateRangeCard);
};
} else {
if (ACE_player call FUNC(updateClassNames)) then {
GVAR(RangeCardOpened) = true;

createDialog "ACE_RangeCard_Dialog";

[GVAR(zeroRange), GVAR(ammoClass), GVAR(magazineClass), GVAR(weaponClass)] call FUNC(updateRangeCard);
[GVAR(zeroRange), GVAR(boreHeight), GVAR(ammoClass), GVAR(magazineClass), GVAR(weaponClass)] call FUNC(updateRangeCard);
};
};
2 changes: 2 additions & 0 deletions addons/rangecard/functions/fnc_updateClassNames.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ if (_ammoClass == "") exitWith { (GVAR(ammoClass) != "" && GVAR(magazineClass) !

if (_unit == ACE_player) then {
GVAR(zeroRange) = [_unit] call EFUNC(scopes,getCurrentZeroRange);
GVAR(boreHeight) = [_unit, 0] call EFUNC(scopes,getBoreHeight);
GVAR(ammoClass) = _ammoClass;
GVAR(magazineClass) = _magazineClass;
GVAR(weaponClass) = _weaponClass;
} else {
GVAR(zeroRangeCopy) = [_unit] call EFUNC(scopes,getCurrentZeroRange);
GVAR(boreHeightCopy) = [_unit, 0] call EFUNC(scopes,getBoreHeight);
GVAR(ammoClassCopy) = _ammoClass;
GVAR(magazineClassCopy) = _magazineClass;
GVAR(weaponClassCopy) = _weaponClass;
Expand Down
18 changes: 9 additions & 9 deletions addons/rangecard/functions/fnc_updateRangeCard.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
*
* Arguments:
* 0: zero range <NUMBER>
* 1: ammo class <STRING>
* 2: magazine class <STRING>
* 3: weapon class <STRING>
* 1: bore height <NUMBER>
* 2: ammo class <STRING>
* 3: magazine class <STRING>
* 4: weapon class <STRING>
*
* Return Value:
* Nothing
Expand All @@ -21,9 +22,9 @@
disableSerialization;
#define __dsp (uiNamespace getVariable "RangleCard_Display")

private ["_airFriction", "_ammoConfig", "_atmosphereModel", "_transonicStabilityCoef", "_barrelLength", "_barrelTwist", "_bc", "_boreHeight", "_cacheEntry", "_column", "_control", "_dragModel", "_i", "_muzzleVelocity", "_offset", "_row", "_weaponConfig", "_initSpeed", "_initSpeedCoef"];
private ["_airFriction", "_ammoConfig", "_atmosphereModel", "_transonicStabilityCoef", "_barrelLength", "_barrelTwist", "_bc", "_cacheEntry", "_column", "_control", "_dragModel", "_i", "_muzzleVelocity", "_offset", "_row", "_weaponConfig", "_initSpeed", "_initSpeedCoef"];

params ["_zeroRange", "_ammoClass", "_magazineClass", "_weaponClass"];
params ["_zeroRange", "_boreHeight", "_ammoClass", "_magazineClass", "_weaponClass"];

if (_ammoClass == "" || _magazineClass == "" || _weaponClass == "") exitWith {};

Expand Down Expand Up @@ -106,7 +107,6 @@ if (count (_ammoConfig select 6) > 0) then {
_transonicStabilityCoef = _ammoConfig select 4;
_dragModel = _ammoConfig select 5;
_atmosphereModel = _ammoConfig select 8;
_boreHeight = 3.81;

private _useABConfig = (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]);
if (_bc == 0) then {
Expand Down Expand Up @@ -157,7 +157,7 @@ if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) t
ctrlSetText [77004 , ""];
};

_cacheEntry = missionNamespace getVariable format[QGVAR(%1_%2_%3_%4), _zeroRange, _ammoClass, _weaponClass, missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]];
_cacheEntry = missionNamespace getVariable format[QGVAR(%1_%2_%3_%4_%5), _zeroRange, _boreHeight, _ammoClass, _weaponClass, missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]];
if (isNil {_cacheEntry}) then {
private _scopeBaseAngle = if (!_useABConfig) then {
private _zeroAngle = "ace_advanced_ballistics" callExtension format ["zeroAngleVanilla:%1:%2:%3:%4", _zeroRange, _muzzleVelocity, _airFriction, _boreHeight];
Expand Down Expand Up @@ -192,7 +192,7 @@ if (isNil {_cacheEntry}) then {
};
};

missionNamespace setVariable [format[QGVAR(%1_%2_%3_%4), _zeroRange, _ammoClass, _weaponClass, missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]], [GVAR(rangeCardDataElevation), GVAR(rangeCardDataWindage), GVAR(rangeCardDataLead), GVAR(rangeCardDataMVs), GVAR(lastValidRow)]];
missionNamespace setVariable [format[QGVAR(%1_%2_%3_%4_%5), _zeroRange, _boreHeight, _ammoClass, _weaponClass, missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]], [GVAR(rangeCardDataElevation), GVAR(rangeCardDataWindage), GVAR(rangeCardDataLead), GVAR(rangeCardDataMVs), GVAR(lastValidRow)]];
} else {
GVAR(rangeCardDataElevation) = _cacheEntry select 0;
GVAR(rangeCardDataWindage) = _cacheEntry select 1;
Expand Down Expand Up @@ -243,7 +243,7 @@ for "_column" from 0 to 8 do {

if (_useABConfig) then {
ctrlSetText [770020, "For best results keep ammunition at ambient air temperature. Tables calculated for the above listed barrel"];
ctrlSetText [770021, "and load with optic mounted 1.5'' above line of bore."];
ctrlSetText [770021, format["and load with optic mounted %1'' above line of bore.", round((_boreHeight / 2.54) * 10) / 10]];
} else {
ctrlSetText [770020, ""];
ctrlSetText [770021, ""];
Expand Down
1 change: 1 addition & 0 deletions addons/scopes/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PREP(applyScopeAdjustment);
PREP(calculateZeroAngleCorrection);
PREP(canAdjustZero);
PREP(firedEH);
PREP(getBoreHeight);
PREP(getCurrentZeroRange);
PREP(getOptics);
PREP(initModuleSettings);
Expand Down
57 changes: 57 additions & 0 deletions addons/scopes/functions/fnc_getBoreHeight.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Author: Ruthberg
* Gets the bore height of the weapon & optic combination with the given weapon index
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Weapon index <NUMBER>
*
* Return Value:
* bore height <NUMBER>
*
* Example:
* [player] call ace_scopes_fnc_getBoreHeight
*
* Public: Yes
*/
#include "script_component.hpp"

params ["_player", "_weaponIndex"];

if (_weaponIndex < 0 || {_weaponIndex > 2}) exitWith { 0 };

private _weaponClass = [primaryWeapon _player, secondaryWeapon _player, handgunWeapon _player] select _weaponIndex;
private _opticsClass = ([_player] call FUNC(getOptics)) select _weaponIndex;

if (_opticsClass == "") then { _opticsClass = _weaponClass; };

// Determine rail height above bore
private _railHeightAboveBore = 0;
private _weaponConfig = configFile >> "CfgWeapons" >> _weaponClass;
if (isNumber (_weaponConfig >> "ACE_RailHeightAboveBore")) then {
_railHeightAboveBore = getNumber(_weaponConfig >> "ACE_RailHeightAboveBore");
} else {
switch (_weaponIndex) do {
case 0: { _railHeightAboveBore = 2.0; }; // Rifle
case 2: { _railHeightAboveBore = 0.7; }; // Pistol
};
};
// Determine scope height above rail
private _scopeHeightAboveRail = 0;
private _opticConfig = configFile >> "CfgWeapons" >> _opticsClass;
if (isNumber (_opticConfig >> "ACE_ScopeHeightAboveRail")) then {
_scopeHeightAboveRail = getNumber(_opticConfig >> "ACE_ScopeHeightAboveRail");
} else {
switch (getNumber(_opticConfig >> "ItemInfo" >> "opticType")) do {
case 1: { _scopeHeightAboveRail = 3.0; }; // RCO or similar
case 2: { _scopeHeightAboveRail = 4.0; }; // High power scope
default {
switch (_weaponIndex) do {
case 0: { _scopeHeightAboveRail = 0.5; }; // Rifle iron sights
case 2: { _scopeHeightAboveRail = 0.3; }; // Pistol iron sights
};
};
};
};

(_railHeightAboveBore + _scopeHeightAboveRail)
4 changes: 2 additions & 2 deletions addons/scopes/functions/fnc_getCurrentZeroRange.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* 0: Unit <OBJECT>
*
* Return Value:
* current zero range
* current zero range <NUMBER>
*
* Example:
* _unit call ace_scopes_fnc_getCurrentZeroRange
* [player] call ace_scopes_fnc_getCurrentZeroRange
*
* Public: No
*/
Expand Down
31 changes: 2 additions & 29 deletions addons/scopes/functions/fnc_inventoryCheck.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -69,35 +69,8 @@ private _newGuns = [primaryWeapon _player, secondaryWeapon _player, handgunWeapo
_adjustment set [_forEachIndex, [0, 0, 0]];
_updateAdjustment = true;
};
// Determine rail height above bore
private _railHeightAboveBore = 0;
private _weaponConfig = configFile >> "CfgWeapons" >> (_newGuns select _x);
if (isNumber (_weaponConfig >> "ACE_RailHeightAboveBore")) then {
_railHeightAboveBore = getNumber(_weaponConfig >> "ACE_RailHeightAboveBore");
} else {
switch (_x) do {
case 0: { _railHeightAboveBore = 2.0; }; // Rifle
case 2: { _railHeightAboveBore = 0.7; }; // Pistol
};
};
// Determine scope height above rail
private _scopeHeightAboveRail = 0;
private _opticConfig = configFile >> "CfgWeapons" >> (_newOptics select _x);
if (isNumber (_opticConfig >> "ACE_ScopeHeightAboveRail")) then {
_scopeHeightAboveRail = getNumber(_opticConfig >> "ACE_ScopeHeightAboveRail");
} else {
switch (getNumber(_opticConfig >> "ItemInfo" >> "opticType")) do {
case 1: { _scopeHeightAboveRail = 3.0; }; // RCO or similar
case 2: { _scopeHeightAboveRail = 4.0; }; // High power scope
default {
switch (_x) do {
case 0: { _scopeHeightAboveRail = 0.5; }; // Rifle iron sights
case 2: { _scopeHeightAboveRail = 0.3; }; // Pistol iron sights
};
};
};
};
GVAR(boreHeight) set [_x, _railHeightAboveBore + _scopeHeightAboveRail];

GVAR(boreHeight) set [_x, [_player, _x] call FUNC(getBoreHeight)];

if ((_newOptics select _x) == "") then {
// Check if the weapon comes with an integrated optic
Expand Down

0 comments on commit c5187fd

Please sign in to comment.