Moves the bore height calculation into FUNC(inventoryCheck)

This commit is contained in:
ulteq 2016-11-08 17:15:16 +01:00 committed by ulteq
parent a687c49d2a
commit 429bffd039
3 changed files with 42 additions and 33 deletions

View File

@ -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

View File

@ -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];

View File

@ -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;