From 54c13c5f4235c4e1a19f90a727ef5a5e98fd1917 Mon Sep 17 00:00:00 2001 From: Dystopian Date: Tue, 3 May 2022 03:54:04 +0400 Subject: [PATCH] Move carry mag getting code to function (#8888) --- addons/csw/XEH_PREP.hpp | 1 + .../fnc_aceRearmGetCarryMagazines.sqf | 8 +----- .../functions/fnc_assemble_pickupWeapon.sqf | 8 +----- addons/csw/functions/fnc_getCarryMagazine.sqf | 28 +++++++++++++++++++ .../functions/fnc_reload_actionsUnload.sqf | 9 +----- .../fnc_staticWeaponInit_unloadExtraMags.sqf | 8 +----- 6 files changed, 33 insertions(+), 29 deletions(-) create mode 100644 addons/csw/functions/fnc_getCarryMagazine.sqf diff --git a/addons/csw/XEH_PREP.hpp b/addons/csw/XEH_PREP.hpp index 98050873ef..5966578aca 100644 --- a/addons/csw/XEH_PREP.hpp +++ b/addons/csw/XEH_PREP.hpp @@ -19,6 +19,7 @@ PREP(assemble_pickupWeapon); PREP(canGetIn); PREP(getIn); +PREP(getCarryMagazine); PREP(proxyWeapon); PREP(reload_actionsLoad); diff --git a/addons/csw/functions/fnc_aceRearmGetCarryMagazines.sqf b/addons/csw/functions/fnc_aceRearmGetCarryMagazines.sqf index e14b0e2d45..ac51d03347 100644 --- a/addons/csw/functions/fnc_aceRearmGetCarryMagazines.sqf +++ b/addons/csw/functions/fnc_aceRearmGetCarryMagazines.sqf @@ -31,13 +31,7 @@ private _allCarryMags = []; private _weapon = _x; { private _xMag = _x; - private _carryMag = GVAR(vehicleMagCache) get _xMag; - if (isNil "_carryMag") then { - private _groups = "getNumber (_x >> _xMag) == 1 && {isClass (configFile >> 'CfgMagazines' >> configName _x)}" configClasses (configFile >> QGVAR(groups)); - _carryMag = configName (_groups param [0, configNull]); - GVAR(vehicleMagCache) set [_x, _carryMag]; - TRACE_2("setting cache",_xMag,_carryMag); - }; + private _carryMag = _xMag call FUNC(getCarryMagazine); if (_carryMag != "") then { _turretMagsCSW pushBackUnique _xMag; _allCarryMags pushBackUnique _carryMag; diff --git a/addons/csw/functions/fnc_assemble_pickupWeapon.sqf b/addons/csw/functions/fnc_assemble_pickupWeapon.sqf index d50702387e..51c2a5128d 100644 --- a/addons/csw/functions/fnc_assemble_pickupWeapon.sqf +++ b/addons/csw/functions/fnc_assemble_pickupWeapon.sqf @@ -41,13 +41,7 @@ { _x params ["_xMag", "", "_xAmmo"]; - private _carryMag = GVAR(vehicleMagCache) get _xMag; - if (isNil "_carryMag") then { - private _groups = "getNumber (_x >> _xMag) == 1 && {isClass (configFile >> 'CfgMagazines' >> configName _x)}" configClasses (configFile >> QGVAR(groups)); - _carryMag = configName (_groups param [0, configNull]); - GVAR(vehicleMagCache) set [_xMag, _carryMag]; - TRACE_2("setting cache",_xMag,_carryMag); - }; + private _carryMag = _xMag call FUNC(getCarryMagazine); if ((_xAmmo > 0) && {_carryMag != ""}) then { TRACE_2("Removing ammo",_xMag,_carryMag); [_player, _carryMag, _xAmmo] call FUNC(reload_handleReturnAmmo); diff --git a/addons/csw/functions/fnc_getCarryMagazine.sqf b/addons/csw/functions/fnc_getCarryMagazine.sqf new file mode 100644 index 0000000000..4535512e2d --- /dev/null +++ b/addons/csw/functions/fnc_getCarryMagazine.sqf @@ -0,0 +1,28 @@ +#include "script_component.hpp" +/* + * Author: PabstMirror, Dystopian + * Gets magazine that the player can carry, suitable to vehicle magazine + * + * Arguments: + * 0: Vehicle Magazine + * + * Return Value: + * Carry Magazine + * + * Example: + * "1Rnd_GAT_missiles" call ace_csw_fnc_getCarryMagazine + * + * Public: No + */ + +params ["_vehicleMag"]; + +private _carryMag = GVAR(vehicleMagCache) get _vehicleMag; +if (isNil "_carryMag") then { + private _groups = "getNumber (_x >> _vehicleMag) == 1 && {isClass (configFile >> 'CfgMagazines' >> configName _x)}" configClasses (configFile >> QGVAR(groups)); + _carryMag = configName (_groups param [0, configNull]); + GVAR(vehicleMagCache) set [_vehicleMag, _carryMag]; + TRACE_2("setting cache",_vehicleMag,_carryMag); +}; + +_carryMag diff --git a/addons/csw/functions/fnc_reload_actionsUnload.sqf b/addons/csw/functions/fnc_reload_actionsUnload.sqf index 8a7e628fd8..0f4e9cb7de 100644 --- a/addons/csw/functions/fnc_reload_actionsUnload.sqf +++ b/addons/csw/functions/fnc_reload_actionsUnload.sqf @@ -60,14 +60,7 @@ private _cfgMagazines = configFile >> "CfgMagazines"; if ((_xAmmo > 0) && {!(_xMag in _handeledMagTypes)}) then { _handeledMagTypes pushBack _xMag; - private _carryMag = GVAR(vehicleMagCache) get _xMag; - - if (isNil "_carryMag") then { - private _groups = "getNumber (_x >> _xMag) == 1 && {isClass (configFile >> 'CfgMagazines' >> configName _x)}" configClasses (configFile >> QGVAR(groups)); - _carryMag = configName (_groups param [0, configNull]); - GVAR(vehicleMagCache) set [_xMag, _carryMag]; - TRACE_2("setting cache",_xMag,_carryMag); - }; + private _carryMag = _xMag call FUNC(getCarryMagazine); if (_carryMag == "") exitWith {}; private _displayName = getText (_cfgMagazines >> _carryMag >> "displayName"); diff --git a/addons/csw/functions/fnc_staticWeaponInit_unloadExtraMags.sqf b/addons/csw/functions/fnc_staticWeaponInit_unloadExtraMags.sqf index e25f0075a7..a1104afd74 100644 --- a/addons/csw/functions/fnc_staticWeaponInit_unloadExtraMags.sqf +++ b/addons/csw/functions/fnc_staticWeaponInit_unloadExtraMags.sqf @@ -36,13 +36,7 @@ private _containerMagazineCount = []; { _x params ["_xMag", "_xTurret", "_xAmmo"]; - private _carryMag = GVAR(vehicleMagCache) get _xMag; - if (isNil "_carryMag") then { - private _groups = "getNumber (_x >> _xMag) == 1 && {isClass (configFile >> 'CfgMagazines' >> configName _x)}" configClasses (configFile >> QGVAR(groups)); - _carryMag = configName (_groups param [0, configNull]); - GVAR(vehicleMagCache) set [_xMag, _carryMag]; - TRACE_2("setting cache",_xMag,_carryMag); - }; + private _carryMag = _xMag call FUNC(getCarryMagazine); if (_carryMag != "") then { if ((_desiredAmmo > 0) && {_loadedMagazineInfo isEqualTo []}) then { private _loadedMagAmmo = _desiredAmmo min _xAmmo;