From 429bffd03940886cfa11196b1a9aa2e5542e3094 Mon Sep 17 00:00:00 2001 From: ulteq Date: Tue, 8 Nov 2016 17:15:16 +0100 Subject: [PATCH] Moves the bore height calculation into FUNC(inventoryCheck) --- addons/scopes/XEH_postInit.sqf | 2 + addons/scopes/functions/fnc_firedEH.sqf | 31 +------------- .../scopes/functions/fnc_inventoryCheck.sqf | 42 +++++++++++++++++-- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/addons/scopes/XEH_postInit.sqf b/addons/scopes/XEH_postInit.sqf index 5e04faefba..cf4df55b57 100644 --- a/addons/scopes/XEH_postInit.sqf +++ b/addons/scopes/XEH_postInit.sqf @@ -10,8 +10,10 @@ if (!hasInterface) exitWith {}; GVAR(Optics) = ["", "", ""]; +GVAR(Guns) = ["", "", ""]; GVAR(canAdjustElevation) = [false, false, false]; GVAR(canAdjustWindage) = [false, false, false]; +GVAR(boreHeight) = [0, 0, 0]; GVAR(scopeAdjust) = [[[0,0],0,[0,0],0], [[0,0],0,[0,0],0], [[0,0],0,[0,0],0]]; // Check inventory when it changes diff --git a/addons/scopes/functions/fnc_firedEH.sqf b/addons/scopes/functions/fnc_firedEH.sqf index 7baf19c948..47aefb6c26 100644 --- a/addons/scopes/functions/fnc_firedEH.sqf +++ b/addons/scopes/functions/fnc_firedEH.sqf @@ -28,37 +28,8 @@ TRACE_1("Adjusting With",_zeroing); _zeroing = _zeroing vectorMultiply 0.05625; if (_ammo isKindOf "BulletBase") then { - private _railHeightAboveBore = 0; - private _scopeHeightAboveRail = 0; - // Determine rail height above bore - private _weaponConfig = configFile >> "CfgWeapons" >> _weapon; - 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 _optic = GVAR(Optics) select _weaponIndex; - private _opticConfig = configFile >> "CfgWeapons" >> _optic; - 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 - }; - }; - }; - }; private _advancedBallistics = missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]; - private _boreHeight = _railHeightAboveBore + _scopeHeightAboveRail; + private _boreHeight = GVAR(boreHeight) select _weaponIndex; private _oldZeroRange = currentZeroing _unit; private _newZeroRange = [_unit] call FUNC(getCurrentZeroRange); private _zeroCorrection = missionNamespace getVariable format[QGVAR(%1_%2_%3_%4_%5_%6_%7), _oldZeroRange, _newZeroRange, _boreHeight, _weapon, _ammo, _magazine, _advancedBallistics]; diff --git a/addons/scopes/functions/fnc_inventoryCheck.sqf b/addons/scopes/functions/fnc_inventoryCheck.sqf index 8ec8e50123..cf33a02c5d 100644 --- a/addons/scopes/functions/fnc_inventoryCheck.sqf +++ b/addons/scopes/functions/fnc_inventoryCheck.sqf @@ -26,6 +26,41 @@ if (isNil "_adjustment") then { }; private _newOptics = [_player] call FUNC(getOptics); +private _newGuns = [primaryWeapon _player, secondaryWeapon _player, handgunWeapon _player]; + +{ + if ((_newOptics select _x) != (GVAR(Optics) select _x) || (_newGuns select _x != GVAR(Guns) select _x)) then { + // 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]; + } +} forEach [0, 1, 2]; { if (_newOptics select _forEachIndex != _x) then { @@ -68,11 +103,12 @@ private _newOptics = [_player] call FUNC(getOptics); (GVAR(scopeAdjust) select _forEachIndex) set [3, _horizontalIncrement]; GVAR(canAdjustElevation) set [_forEachIndex, (_verticalIncrement > 0) && !(_maxVertical isEqualTo [0, 0])]; GVAR(canAdjustWindage) set [_forEachIndex, (_horizontalIncrement > 0) && !(_maxHorizontal isEqualTo [0, 0])]; - // Does not work reliably - //private _hideVanillaZeroing = (getNumber(_opticConfig >> "ItemInfo" >> "opticType") == 2 && (GVAR(canAdjustElevation) select _forEachIndex)) || {isNumber (_opticConfig >> "ACE_ScopeZeroRange")}; - //private _result = ["zeroing", !_hideVanillaZeroing, false] call EFUNC(ui,setAdvancedElement); + private _hideVanillaZeroing = (getNumber(_opticConfig >> "ItemInfo" >> "opticType") == 2 && {GVAR(canAdjustElevation) select _forEachIndex}) || {isNumber (_opticConfig >> "ACE_ScopeZeroRange")}; + ["ace_scopes", true, "zeroing", !_hideVanillaZeroing] call EFUNC(ui,setElementVisibility); }; } forEach GVAR(Optics); _adjustment = ACE_player getVariable QGVAR(Adjustment); GVAR(Optics) = _newOptics; +GVAR(Guns) = _newGuns; +