2015-02-10 04:22:10 +00:00
|
|
|
/*
|
2016-11-08 13:47:12 +00:00
|
|
|
* Author: KoffeinFlummi, Commy2, Ruthberg
|
2015-02-10 04:22:10 +00:00
|
|
|
* Check if weapon optics changed and reset zeroing if needed
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Player <OBJECT>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
2015-08-07 14:43:06 +00:00
|
|
|
* Example:
|
|
|
|
* [player] call ace_scopes_fnc_inventoryCheck
|
|
|
|
*
|
2015-02-10 04:22:10 +00:00
|
|
|
* Public: No
|
|
|
|
*/
|
2015-01-16 12:15:14 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-08-07 14:43:06 +00:00
|
|
|
params ["_player"];
|
|
|
|
|
2016-11-12 10:23:14 +00:00
|
|
|
private _adjustment = ACE_player getVariable [QGVAR(Adjustment), [[0, 0, 0], [0, 0, 0], [0, 0, 0]]];
|
|
|
|
private _updateAdjustment = false;
|
2015-01-16 12:15:14 +00:00
|
|
|
|
2016-07-24 04:08:40 +00:00
|
|
|
private _newOptics = [_player] call FUNC(getOptics);
|
2015-01-16 12:15:14 +00:00
|
|
|
{
|
2015-02-10 04:22:10 +00:00
|
|
|
if (_newOptics select _forEachIndex != _x) then {
|
2016-11-16 11:23:46 +00:00
|
|
|
private _opticConfig = configFile >> "CfgWeapons" >> (_newOptics select _forEachIndex);
|
|
|
|
private _opticType = getNumber(_opticConfig >> "ItemInfo" >> "opticType");
|
2016-11-08 13:47:12 +00:00
|
|
|
private _maxVertical = [];
|
2017-11-29 10:38:19 +00:00
|
|
|
private _verticalIncrement = -1;
|
2016-11-08 13:47:12 +00:00
|
|
|
private _maxHorizontal = [];
|
2017-11-29 10:38:19 +00:00
|
|
|
private _horizontalIncrement = -1;
|
|
|
|
if (GVAR(simplifiedZeroing)) then {
|
|
|
|
private _maxDistanceZoomMax = 300;
|
|
|
|
private _maxDiscreteDistanceSize = 0;
|
|
|
|
{
|
|
|
|
_maxDistanceZoomMax = _maxDistanceZoomMax max (getNumber ( _x >> "distanceZoomMax"));
|
|
|
|
_maxDiscreteDistanceSize = _maxDiscreteDistanceSize max (count getArray (_x >> "discreteDistance"));
|
|
|
|
} forEach ("isArray (_x >> 'discreteDistance')" configClasses (_opticConfig >> "ItemInfo" >> "OpticsModes"));
|
|
|
|
if (_maxDiscreteDistanceSize < 2 && {getNumber (_opticConfig >> "ACE_ScopeAdjust_VerticalIncrement") != 0}) then {
|
|
|
|
_maxVertical = [50, _maxDistanceZoomMax];
|
|
|
|
_verticalIncrement = 50;
|
|
|
|
} else {
|
|
|
|
_maxVertical = [0, 0];
|
|
|
|
_verticalIncrement = 0;
|
|
|
|
};
|
|
|
|
_maxHorizontal = [0, 0];
|
|
|
|
_horizontalIncrement = 0;
|
2016-11-08 13:47:12 +00:00
|
|
|
} else {
|
2017-11-29 10:38:19 +00:00
|
|
|
if (isNumber (_opticConfig >> "ACE_ScopeAdjust_VerticalIncrement")) then {
|
|
|
|
_verticalIncrement = getNumber (_opticConfig >> "ACE_ScopeAdjust_VerticalIncrement");
|
|
|
|
};
|
|
|
|
if (isNumber (_opticConfig >> "ACE_ScopeAdjust_HorizontalIncrement")) then {
|
|
|
|
_horizontalIncrement = getNumber (_opticConfig >> "ACE_ScopeAdjust_HorizontalIncrement");
|
|
|
|
};
|
|
|
|
if (isArray (_opticConfig >> "ACE_ScopeAdjust_Vertical")) then {
|
|
|
|
_maxVertical = getArray (_opticConfig >> "ACE_ScopeAdjust_Vertical");
|
|
|
|
};
|
|
|
|
if (isArray (_opticConfig >> "ACE_ScopeAdjust_Horizontal")) then {
|
|
|
|
_maxHorizontal = getArray (_opticConfig >> "ACE_ScopeAdjust_Horizontal");
|
|
|
|
};
|
|
|
|
if (GVAR(forceUseOfAdjustmentTurrets) && _opticType == 2) then {
|
|
|
|
if (_maxVertical isEqualTo []) then { _maxVertical = [-4, 30]; };
|
|
|
|
if (_maxHorizontal isEqualTo []) then { _maxHorizontal = [-6, 6]; };
|
|
|
|
if (_verticalIncrement == -1) then { _verticalIncrement = 0.1; };
|
|
|
|
if (_horizontalIncrement == -1) then { _horizontalIncrement = 0.1; };
|
|
|
|
} else {
|
|
|
|
if (_maxVertical isEqualTo []) then { _maxVertical = [0, 0]; };
|
|
|
|
if (_maxHorizontal isEqualTo []) then { _maxHorizontal = [0, 0]; };
|
|
|
|
if (_verticalIncrement == -1) then { _verticalIncrement = 0; };
|
|
|
|
if (_horizontalIncrement == -1) then { _horizontalIncrement = 0; };
|
|
|
|
};
|
2016-11-08 13:47:12 +00:00
|
|
|
};
|
|
|
|
(GVAR(scopeAdjust) select _forEachIndex) set [0, _maxVertical];
|
|
|
|
(GVAR(scopeAdjust) select _forEachIndex) set [1, _verticalIncrement];
|
|
|
|
(GVAR(scopeAdjust) select _forEachIndex) set [2, _maxHorizontal];
|
|
|
|
(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])];
|
2015-01-16 12:15:14 +00:00
|
|
|
};
|
|
|
|
} forEach GVAR(Optics);
|
|
|
|
|
2016-11-13 10:27:12 +00:00
|
|
|
private _newGuns = [primaryWeapon _player, secondaryWeapon _player, handgunWeapon _player];
|
2016-11-08 16:51:55 +00:00
|
|
|
{
|
|
|
|
if ((_newOptics select _x) != (GVAR(Optics) select _x) || (_newGuns select _x != GVAR(Guns) select _x)) then {
|
2017-12-15 09:25:00 +00:00
|
|
|
GVAR(baseAngle) set [_x, [_player, _x, _newGuns select _x, _newOptics select _x] call FUNC(getBaseAngle)];
|
2017-12-14 12:43:32 +00:00
|
|
|
GVAR(boreHeight) set [_x, [_player, _x] call FUNC(getBoreHeight)];
|
2017-11-12 11:12:49 +00:00
|
|
|
|
2016-11-08 16:51:55 +00:00
|
|
|
if ((_newOptics select _x) == "") then {
|
|
|
|
// Check if the weapon comes with an integrated optic
|
2017-03-08 18:31:26 +00:00
|
|
|
private _weaponConfig = configFile >> "CfgWeapons" >> (_newGuns select _x);
|
2017-11-29 10:38:19 +00:00
|
|
|
private _maxVertical = [0, 0];
|
2016-11-08 16:51:55 +00:00
|
|
|
private _verticalIncrement = 0;
|
2017-11-29 10:38:19 +00:00
|
|
|
private _maxHorizontal = [0, 0];
|
2016-11-08 16:51:55 +00:00
|
|
|
private _horizontalIncrement = 0;
|
2017-11-29 10:38:19 +00:00
|
|
|
if (GVAR(simplifiedZeroing)) then {
|
|
|
|
private _maxZeroing = 300 max (getNumber (_weaponConfig >> "maxZeroing"));
|
|
|
|
private _maxDiscreteDistanceSize = count getArray (configFile >> "CfgWeapons" >> (_newGuns select _x) >> "discreteDistance");
|
|
|
|
if (_maxDiscreteDistanceSize < 2 && {getNumber (_weaponConfig >> "ACE_ScopeAdjust_VerticalIncrement") != 0}) then {
|
|
|
|
_maxVertical = [50, _maxZeroing];
|
|
|
|
_verticalIncrement = 50;
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
_verticalIncrement = getNumber (_weaponConfig >> "ACE_ScopeAdjust_VerticalIncrement");
|
2016-11-08 16:51:55 +00:00
|
|
|
_horizontalIncrement = getNumber (_weaponConfig >> "ACE_ScopeAdjust_HorizontalIncrement");
|
|
|
|
_maxVertical = getArray (_weaponConfig >> "ACE_ScopeAdjust_Vertical");
|
|
|
|
_maxHorizontal = getArray (_weaponConfig >> "ACE_ScopeAdjust_Horizontal");
|
|
|
|
};
|
2017-03-08 18:31:26 +00:00
|
|
|
TRACE_5("",_newGuns select _x,_verticalIncrement,_horizontalIncrement,_maxVertical,_maxHorizontal);
|
2016-11-08 16:51:55 +00:00
|
|
|
(GVAR(scopeAdjust) select _x) set [0, _maxVertical];
|
|
|
|
(GVAR(scopeAdjust) select _x) set [1, _verticalIncrement];
|
|
|
|
(GVAR(scopeAdjust) select _x) set [2, _maxHorizontal];
|
|
|
|
(GVAR(scopeAdjust) select _x) set [3, _horizontalIncrement];
|
|
|
|
GVAR(canAdjustElevation) set [_x, (_verticalIncrement > 0) && !(_maxVertical isEqualTo [0, 0])];
|
|
|
|
GVAR(canAdjustWindage) set [_x, (_horizontalIncrement > 0) && !(_maxHorizontal isEqualTo [0, 0])];
|
|
|
|
};
|
2017-11-17 18:08:03 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
};
|
2017-11-29 10:38:19 +00:00
|
|
|
private _defaultElevation = [0, 300] select GVAR(simplifiedZeroing);
|
|
|
|
if (!((_adjustment select _forEachIndex) isEqualTo [_defaultElevation, 0, _persistentZero])) then {
|
|
|
|
_adjustment set [_forEachIndex, [_defaultElevation, 0, _persistentZero]];
|
2017-11-17 18:08:03 +00:00
|
|
|
_updateAdjustment = true;
|
|
|
|
};
|
2016-11-08 16:51:55 +00:00
|
|
|
}
|
|
|
|
} forEach [0, 1, 2];
|
|
|
|
|
2016-11-12 10:23:14 +00:00
|
|
|
if (_updateAdjustment) then {
|
|
|
|
[ACE_player, QGVAR(Adjustment), _adjustment, 0.5] call EFUNC(common,setVariablePublic);
|
|
|
|
};
|
|
|
|
|
2015-02-10 04:22:10 +00:00
|
|
|
GVAR(Optics) = _newOptics;
|
2016-11-08 16:15:16 +00:00
|
|
|
GVAR(Guns) = _newGuns;
|