Scopes - Persistent zero adjustments (#5753)

* Makes manual zero adjustments (advanced ballistics only) for each weapon & scope combination persistent across game restarts / mission restarts / weapon or scope changes.
This commit is contained in:
ulteq 2017-11-17 19:08:03 +01:00 committed by GitHub
parent 257bde4eef
commit aab09584b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View File

@ -19,7 +19,8 @@ params ["_unit"];
if (vehicle _unit != _unit) exitWith {false};
private _weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex);
private _weaponClass = currentWeapon _unit;
private _weaponIndex = [_unit, _weaponClass] call EFUNC(common,getWeaponIndex);
if (_weaponIndex < 0) exitWith {false};
private _adjustment = _unit getVariable [QGVAR(Adjustment), [[0, 0, 0], [0, 0, 0], [0, 0, 0]]];
@ -29,6 +30,13 @@ _zeroing params ["_elevation", "_windage", "_zero"];
_zero = round((_zero + _elevation) * 10) / 10;
_elevation = 0;
private _opticsClass = ([_unit] call FUNC(getOptics)) select _weaponIndex;
if (_zero != 0) then {
profileNamespace setVariable [format[QGVAR(PersistentZero_%1_%2), _weaponClass, _opticsClass], _zero];
} else {
profileNamespace setVariable [format[QGVAR(PersistentZero_%1_%2), _weaponClass, _opticsClass], nil];
};
[_unit, _elevation, _windage, _zero] call FUNC(applyScopeAdjustment);
true

View File

@ -64,12 +64,6 @@ 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 {
// The optic or the weapon changed, set adjustment to zero
if (!((_adjustment select _forEachIndex) isEqualTo [0, 0, 0])) then {
_adjustment set [_forEachIndex, [0, 0, 0]];
_updateAdjustment = true;
};
GVAR(baseAngle) set [_x, [_player, _x] call FUNC(getBaseAngle)];
GVAR(boreHeight) set [_x, [_player, _x] call FUNC(getBoreHeight)];
@ -100,6 +94,17 @@ private _newGuns = [primaryWeapon _player, secondaryWeapon _player, handgunWeapo
GVAR(canAdjustElevation) set [_x, (_verticalIncrement > 0) && !(_maxVertical isEqualTo [0, 0])];
GVAR(canAdjustWindage) set [_x, (_horizontalIncrement > 0) && !(_maxHorizontal isEqualTo [0, 0])];
};
// The optic or the weapon changed, reset the adjustment
private _persistentZero = profileNamespace getVariable [format[QGVAR(PersistentZero_%1_%2), _newGuns select _x, _newOptics select _x], 0];
((GVAR(scopeAdjust) select _x) select 0) params ["_minElevation", "_maxElevation"];
if (!(_persistentZero isEqualType 0) || {_persistentZero < _minElevation || _persistentZero > _maxElevation}) then {
_persistentZero = 0;
};
if (!((_adjustment select _forEachIndex) isEqualTo [0, 0, _persistentZero])) then {
_adjustment set [_forEachIndex, [0, 0, _persistentZero]];
_updateAdjustment = true;
};
}
} forEach [0, 1, 2];