Scopes - Fix 'boreHeight' and 'baseAngle' MP synchronization (#5917)

* Scopes - Unify 'getBaseAngle' & 'getBoreHeight' API

* Scopes - Fix boreHeight and baseAngle MP synchronization
* TODO: Cache the calculation or use publicVariables instead

* Cleanup unused GVARs

* Scopes - Cache getBaseAngle and getBoreHeight results

* Sync baseAngle/boreHeight

* Remove boreHeight/Angle caching

* Cleanup inv check
This commit is contained in:
ulteq 2017-12-15 17:22:31 +01:00 committed by PabstMirror
parent a97dea896f
commit f9d729c874
4 changed files with 29 additions and 15 deletions

View File

@ -13,8 +13,6 @@ GVAR(Optics) = ["", "", ""];
GVAR(Guns) = ["", "", ""];
GVAR(canAdjustElevation) = [false, false, false];
GVAR(canAdjustWindage) = [false, false, false];
GVAR(baseAngle) = [0, 0, 0];
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]];
["ace_settingsInitialized", {

View File

@ -32,8 +32,8 @@ _zeroing = _zeroing vectorMultiply MRAD_TO_DEG(1);
if (GVAR(correctZeroing) || GVAR(simplifiedZeroing)) then {
private _advancedBallistics = missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false];
private _baseAngle = GVAR(baseAngle) select _weaponIndex;
private _boreHeight = GVAR(boreHeight) select _weaponIndex;
private _baseAngle = (_unit getVariable [QGVAR(baseAngle), [0,0,0]]) select _weaponIndex;
private _boreHeight = (_unit getVariable [QGVAR(boreHeight), [0,0,0]]) 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

@ -1,24 +1,27 @@
/*
* Author: Ruthberg
* Gets the base angle of the currently used weapon & optic combination
* Gets the base angle of the weapon & optic combination with the given weapon index
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Weapon index <NUMBER>
* 2: Weapon <CLASS>
* 3: Optic <CLASS>
*
* Return Value:
* base angle <NUMBER>
*
* Example:
* [player, 0, "srifle_LRR_F", "optic_LRPS"] call ace_scopes_fnc_getBaseAngle
* [player, 0] call ace_scopes_fnc_getBaseAngle
*
* Public: Yes
*/
#include "script_component.hpp"
params ["_player", "_weaponIndex", "_weaponClass", "_opticsClass"];
params ["_unit", "_weaponIndex"];
if (_weaponIndex < 0 || {_weaponIndex > 2}) exitWith { 0 };
private _weaponClass = [primaryWeapon _unit, secondaryWeapon _unit, handgunWeapon _unit] select _weaponIndex;
private _opticsClass = ([_unit] call FUNC(getOptics)) select _weaponIndex;
private _weaponConfig = configFile >> "CfgWeapons" >> _weaponClass;
private _baseAngle = getNumber(_weaponConfig >> "ACE_IronSightBaseAngle");

View File

@ -79,15 +79,17 @@ private _newOptics = [_player] call FUNC(getOptics);
};
} forEach GVAR(Optics);
private _unitBaseAngle = +(_player getVariable [QGVAR(baseAngle), [0,0,0]]);
private _unitBoreHeight = +(_player getVariable [QGVAR(boreHeight), [0,0,0]]);
private _newGuns = [primaryWeapon _player, secondaryWeapon _player, handgunWeapon _player];
{
if ((_newOptics select _x) != (GVAR(Optics) select _x) || (_newGuns select _x != GVAR(Guns) select _x)) then {
GVAR(baseAngle) set [_x, [_player, _x, _newGuns select _x, _newOptics select _x] call FUNC(getBaseAngle)];
GVAR(boreHeight) set [_x, [_player, _x] call FUNC(getBoreHeight)];
_unitBaseAngle set [_x, [_player, _x] call FUNC(getBaseAngle)];
_unitBoreHeight set [_x, [_player, _x] call FUNC(getBoreHeight)];
if ((_newOptics select _x) == "") then {
// Check if the weapon comes with an integrated optic
private _weaponConfig = configFile >> "CfgWeapons" >> (_newGuns select _x);
// Check if the weapon comes with an integrated optic
private _weaponConfig = configFile >> "CfgWeapons" >> (_newGuns select _x);
private _maxVertical = [0, 0];
private _verticalIncrement = 0;
private _maxHorizontal = [0, 0];
@ -113,7 +115,7 @@ 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"];
@ -128,6 +130,17 @@ private _newGuns = [primaryWeapon _player, secondaryWeapon _player, handgunWeapo
}
} forEach [0, 1, 2];
if (GVAR(correctZeroing) || GVAR(simplifiedZeroing)) then {
if (!(_unitBaseAngle isEqualTo (_player getVariable [QGVAR(baseAngle), [0,0,0]]))) then {
TRACE_2("syncing",_unitBaseAngle,_player getVariable QGVAR(baseAngle));
_player setVariable [QGVAR(baseAngle), _unitBaseAngle, true];
};
if (!(_unitBoreHeight isEqualTo (_player getVariable [QGVAR(boreHeight), [0,0,0]]))) then {
TRACE_2("syncing",_unitBoreHeight,_player getVariable QGVAR(boreHeight));
_player setVariable [QGVAR(boreHeight), _unitBoreHeight, true];
};
};
if (_updateAdjustment) then {
[ACE_player, QGVAR(Adjustment), _adjustment, 0.5] call EFUNC(common,setVariablePublic);
};