ACE3/addons/scopes/functions/fnc_adjustScope.sqf

78 lines
2.8 KiB
Plaintext
Raw Normal View History

/*
* Author: KoffeinFlummi, Ruthberg
* Changes the adjustment for the current scope
*
* Argument:
* 0: Unit <OBJECT>
* 1: Turret and Direction <NUMBER>
* 2: Major Step <BOOL>
*
* Return value:
* Did we adjust anything? <BOOL>
*
2015-08-07 14:43:06 +00:00
* Example:
* [player, ELEVATION_UP, false] call ace_scopes_fnc_adjustScope
*
* Public: No
*/
#include "script_component.hpp"
2015-08-08 09:25:45 +00:00
private ["_weaponIndex", "_zeroing", "_optic", "_opticConfig", "_verticalIncrement", "_horizontalIncrement", "_maxVertical", "_maxHorizontal", "_adjustment"];
2015-08-07 14:43:06 +00:00
params ["_unit", "_turretAndDirection", "_majorStep"];
if (!(_unit isKindOf "Man")) exitWith {false};
if (currentMuzzle _unit != currentWeapon _unit) exitWith {false};
2015-02-12 14:57:55 +00:00
_weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex);
if (_weaponIndex < 0) exitWith {false};
_adjustment = _unit getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
2015-08-07 14:43:06 +00:00
_adjustment = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]; // [Windage, Elevation, Zero]
};
if (isNil QGVAR(Optics)) then {
GVAR(Optics) = ["", "", ""];
};
_optic = GVAR(Optics) select _weaponIndex;
2015-08-07 14:43:06 +00:00
_opticConfig = configFile >> "CfgWeapons" >> _optic;
_verticalIncrement = getNumber (_opticConfig >> "ACE_ScopeAdjust_VerticalIncrement");
_horizontalIncrement = getNumber (_opticConfig >> "ACE_ScopeAdjust_HorizontalIncrement");
_maxVertical = getArray (_opticConfig >> "ACE_ScopeAdjust_Vertical");
_maxHorizontal = getArray (_opticConfig >> "ACE_ScopeAdjust_Horizontal");
if ((count _maxHorizontal < 2) || (count _maxVertical < 2)) exitWith {false};
if ((_verticalIncrement == 0) && (_turretAndDirection in [ELEVATION_UP, ELEVATION_DOWN])) exitWith {false};
if ((_horizontalIncrement == 0) && (_turretAndDirection in [WINDAGE_UP, WINDAGE_DOWN])) exitWith {false};
2016-05-03 00:32:44 +00:00
_zeroing = _adjustment select _weaponIndex;
2015-08-07 14:43:06 +00:00
_zeroing params ["_elevation", "_windage", "_zero"];
switch (_turretAndDirection) do {
case ELEVATION_UP: { _elevation = _elevation + _verticalIncrement };
case ELEVATION_DOWN: { _elevation = _elevation - _verticalIncrement };
case WINDAGE_LEFT: { _windage = _windage - _horizontalIncrement };
case WINDAGE_RIGHT: { _windage = _windage + _horizontalIncrement };
};
if (_majorStep) then {
switch (_turretAndDirection) do {
2015-04-14 08:47:09 +00:00
case ELEVATION_UP: { _elevation = ceil(_elevation) };
case ELEVATION_DOWN: { _elevation = floor(_elevation) };
case WINDAGE_LEFT: { _windage = floor(_windage) };
case WINDAGE_RIGHT: { _windage = ceil(_windage) };
};
};
_elevation = round(_elevation * 10) / 10;
_windage = round(_windage * 10) / 10;
if ((_elevation + _zero) < _maxVertical select 0 or (_elevation + _zero) > _maxVertical select 1) exitWith {false};
if (_windage < _maxHorizontal select 0 or _windage > _maxHorizontal select 1) exitWith {false};
[_unit, _elevation, _windage, _zero] call FUNC(applyScopeAdjustment);
true