From da4da784d963aeba2ea5046e9fc8fe47dcef5890 Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 22 Apr 2019 11:33:58 +0200 Subject: [PATCH] fix CBA_fnc_compatibleMagazines skipping muzzle magazines (#1122) --- addons/common/fnc_compatibleMagazines.sqf | 52 ++++++++++++++++------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/addons/common/fnc_compatibleMagazines.sqf b/addons/common/fnc_compatibleMagazines.sqf index cf46c20d9..5b17677cc 100644 --- a/addons/common/fnc_compatibleMagazines.sqf +++ b/addons/common/fnc_compatibleMagazines.sqf @@ -29,27 +29,49 @@ if (_weapon isEqualType "") then { }; private _cacheKey = str _weapon; -if (_cacheKey == "") exitWith { ERROR_1("Weapon Does Not Exist %1",_this); [] }; -if (isNil QGVAR(magNamespace)) then { GVAR(magNamespace) = call CBA_fnc_createNamespace; }; +if (_cacheKey == "") exitWith { + ERROR_1("Weapon Does Not Exist %1",_this); + [] +}; -private _returnMags = GVAR(magNamespace) getVariable _cacheKey; +if (isNil QGVAR(magNamespace)) then { + GVAR(magNamespace) = call CBA_fnc_createNamespace; +}; + +private _compatibleMagazines = GVAR(magNamespace) getVariable _cacheKey; + +if (isNil "_compatibleMagazines") then { + _compatibleMagazines = []; + + private _fnc_appendMagazines = { + params ["_muzzle"]; + + _compatibleMagazines append getArray (_muzzle >> "magazines"); -if (isNil "_returnMags") then { - _returnMags = getArray (_weapon >> "magazines"); - { - private _wellConfig = configFile >> "CfgMagazineWells" >> _x; { - _returnMags append getArray _x; - } forEach configProperties [_wellConfig, "isArray _x", false]; - } forEach (getArray (_weapon >> "magazineWell")); + private _wellConfig = configFile >> "CfgMagazineWells" >> _x; + + { + _compatibleMagazines append getArray _x; + } forEach configProperties [_wellConfig, "isArray _x", false]; + } forEach getArray (_muzzle >> "magazineWell"); + }; + + { + if (_x == "this") then { + _weapon call _fnc_appendMagazines; + } else { + (_weapon >> _x) call _fnc_appendMagazines + }; + } forEach getArray (_weapon >> "muzzles"); private _cfgMagazines = configFile >> "CfgMagazines"; - _returnMags = _returnMags select {isClass (_cfgMagazines >> _x)}; - _returnMags = _returnMags apply {configName (_cfgMagazines >> _x)}; - _returnMags = _returnMags arrayIntersect _returnMags; + _compatibleMagazines = _compatibleMagazines select {isClass (_cfgMagazines >> _x)}; + _compatibleMagazines = _compatibleMagazines apply {configName (_cfgMagazines >> _x)}; + _compatibleMagazines = _compatibleMagazines arrayIntersect _compatibleMagazines; - GVAR(magNamespace) setVariable [_cacheKey, _returnMags]; + GVAR(magNamespace) setVariable [_cacheKey, _compatibleMagazines]; }; -+_returnMags ++_compatibleMagazines