From 9cad5873d06d7624e7527ea686787ea241c74f31 Mon Sep 17 00:00:00 2001 From: ulteq Date: Sat, 18 Nov 2017 13:59:42 +0100 Subject: [PATCH] Scopes - Adds 'Reset zero' interaction (advanced ballistics only) (#5789) * Allows you to reset any zero adjustment on your current scope --- addons/scopes/CfgVehicles.hpp | 10 +++++ addons/scopes/XEH_PREP.hpp | 2 + addons/scopes/functions/fnc_adjustZero.sqf | 2 +- addons/scopes/functions/fnc_canAdjustZero.sqf | 2 +- addons/scopes/functions/fnc_canResetZero.sqf | 31 +++++++++++++++ addons/scopes/functions/fnc_resetZero.sqf | 38 +++++++++++++++++++ addons/scopes/stringtable.xml | 4 ++ 7 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 addons/scopes/functions/fnc_canResetZero.sqf create mode 100644 addons/scopes/functions/fnc_resetZero.sqf diff --git a/addons/scopes/CfgVehicles.hpp b/addons/scopes/CfgVehicles.hpp index a9ff3eb1a7..b3dca0f6ed 100644 --- a/addons/scopes/CfgVehicles.hpp +++ b/addons/scopes/CfgVehicles.hpp @@ -13,6 +13,16 @@ class CfgVehicles { //icon = QPATHTOF(UI\...); // TODO exceptions[] = {"notOnMap", "isNotInside", "isNotSwimming", "isNotSitting"}; }; + class GVAR(resetZero) { + // Updates the zero reference + displayName = CSTRING(ResetZero); + condition = QUOTE([ACE_player] call FUNC(canResetZero)); + statement = QUOTE([ACE_player] call FUNC(resetZero)); + showDisabled = 0; + priority = 0.2; + //icon = QPATHTOF(UI\...); // TODO + exceptions[] = {"notOnMap", "isNotInside", "isNotSwimming", "isNotSitting"}; + }; }; }; }; diff --git a/addons/scopes/XEH_PREP.hpp b/addons/scopes/XEH_PREP.hpp index f420fab2bc..58b4e494f2 100644 --- a/addons/scopes/XEH_PREP.hpp +++ b/addons/scopes/XEH_PREP.hpp @@ -4,6 +4,7 @@ PREP(adjustZero); PREP(applyScopeAdjustment); PREP(calculateZeroAngleCorrection); PREP(canAdjustZero); +PREP(canResetZero); PREP(firedEH); PREP(getBaseAngle); PREP(getBoreHeight); @@ -11,4 +12,5 @@ PREP(getCurrentZeroRange); PREP(getOptics); PREP(initModuleSettings); PREP(inventoryCheck); +PREP(resetZero); PREP(showZeroing); diff --git a/addons/scopes/functions/fnc_adjustZero.sqf b/addons/scopes/functions/fnc_adjustZero.sqf index 39a3b29114..011f674248 100644 --- a/addons/scopes/functions/fnc_adjustZero.sqf +++ b/addons/scopes/functions/fnc_adjustZero.sqf @@ -1,6 +1,6 @@ /* * Author: KoffeinFlummi, Ruthberg - * Updates the zero reference for the current scope + * Updates the zero adjustment of the current scope * * Arguments: * 0: Unit diff --git a/addons/scopes/functions/fnc_canAdjustZero.sqf b/addons/scopes/functions/fnc_canAdjustZero.sqf index 037fedd1b5..60e7b90499 100644 --- a/addons/scopes/functions/fnc_canAdjustZero.sqf +++ b/addons/scopes/functions/fnc_canAdjustZero.sqf @@ -1,6 +1,6 @@ /* * Author: KoffeinFlummi, Ruthberg - * Changes the adjustment for the current scope + * Checks if the unit can change the zero adjustment of the current scope * * Arguments: * 0: Unit diff --git a/addons/scopes/functions/fnc_canResetZero.sqf b/addons/scopes/functions/fnc_canResetZero.sqf new file mode 100644 index 0000000000..fe9def4a19 --- /dev/null +++ b/addons/scopes/functions/fnc_canResetZero.sqf @@ -0,0 +1,31 @@ +/* + * Author: KoffeinFlummi, Ruthberg + * Checks if the unit can reset the zero adjustment of the current scope + * + * Arguments: + * 0: Unit + * + * Return Value: + * Can we reset the zero reference? + * + * Example: + * [player] call ace_scopes_fnc_canResetZero + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit"]; + +if (cameraView == "GUNNER") exitWith {false}; +if (vehicle _unit != _unit) exitWith {false}; +if (!(missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false])) exitWith {false}; + +private _weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex); +if (_weaponIndex < 0) exitWith {false}; + +private _adjustment = _unit getVariable [QGVAR(Adjustment), [[0, 0, 0], [0, 0, 0], [0, 0, 0]]]; +private _zero = (_adjustment select _weaponIndex) select 2; + +// You can only reset your zero reference, if it is not 0 already +_zero != 0 diff --git a/addons/scopes/functions/fnc_resetZero.sqf b/addons/scopes/functions/fnc_resetZero.sqf new file mode 100644 index 0000000000..14366e5924 --- /dev/null +++ b/addons/scopes/functions/fnc_resetZero.sqf @@ -0,0 +1,38 @@ +/* + * Author: KoffeinFlummi, Ruthberg + * Resets the zero adjustment of the current scope + * + * Arguments: + * 0: Unit + * + * Return Value: + * true + * + * Example: + * [player] call ace_scopes_fnc_resetZero + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit"]; + +if (vehicle _unit != _unit) exitWith {false}; + +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]]]; +private _zeroing = _adjustment select _weaponIndex; +_zeroing params ["_elevation", "_windage", "_zero"]; + +_elevation = round((_zero + _elevation) * 10) / 10; +_zero = 0; + +private _opticsClass = ([_unit] call FUNC(getOptics)) select _weaponIndex; +profileNamespace setVariable [format[QGVAR(PersistentZero_%1_%2), _weaponClass, _opticsClass], nil]; + +[_unit, _elevation, _windage, _zero] call FUNC(applyScopeAdjustment); + +true diff --git a/addons/scopes/stringtable.xml b/addons/scopes/stringtable.xml index d717674b88..cda40c99e6 100644 --- a/addons/scopes/stringtable.xml +++ b/addons/scopes/stringtable.xml @@ -368,6 +368,10 @@ 设定归零 設定歸零 + + Reset zero adjustment + Nullung zurücksetzen + This module adds windage and elevation adjustment turrets on high power rifle scopes. Dieses Modul fügt Absehenverstellung (horizontal und vertikal) zu Zielfernrohren hinzu.