Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix CBA_fnc_compatibleMagazines skipping muzzle magazines #1122

Merged
merged 1 commit into from
Apr 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 37 additions & 15 deletions addons/common/fnc_compatibleMagazines.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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