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

Disposable - Updated cba_disposable_fnc_replaceMagazineCargo #1662

Merged
5 changes: 0 additions & 5 deletions addons/disposable/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ GVAR(NormalLaunchers) = [] call CBA_fnc_createNamespace;
GVAR(LoadedLaunchers) = [] call CBA_fnc_createNamespace;
GVAR(UsedLaunchers) = [] call CBA_fnc_createNamespace;
GVAR(magazines) = [];
GVAR(BackpackLaunchers) = createHashMap;
GVAR(MagazineLaunchers) = [] call CBA_fnc_createNamespace;

private _cfgWeapons = configFile >> "CfgWeapons";
Expand All @@ -50,10 +49,6 @@ private _cfgMagazines = configFile >> "CfgMagazines";
GVAR(MagazineLaunchers) setVariable [_magazine, _loadedLauncher];
};

if (_fitsInBackpacks) then {
GVAR(BackpackLaunchers) set [_loadedLauncher, true];
};

// check if mass entries add up
private _massLauncher = getNumber (_cfgWeapons >> _launcher >> "WeaponSlotsInfo" >> "mass");
private _massMagazine = getNumber (_cfgMagazines >> _magazine >> "mass");
Expand Down
50 changes: 15 additions & 35 deletions addons/disposable/fnc_replaceMagazineCargo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,41 @@ Description:
Replaces disposable launcher magazines with loaded disposable launchers.

Parameters:
_box - Any object with cargo <OBJECT>
_container - Any object with cargo <OBJECT>

Returns:
Nothing.

Examples:
(begin example)
_box call cba_disposable_fnc_replaceMagazineCargo
_container call cba_disposable_fnc_replaceMagazineCargo
(end)

Author:
commy2
commy2, johnb43
---------------------------------------------------------------------------- */

if (!GVAR(replaceDisposableLauncher)) exitWith {};

params ["_box"];
if (!local _box) exitWith {};
if (missionNamespace getVariable [QGVAR(disableMagazineReplacement), false]) exitWith {};

private _uniformContainer = uniformContainer _box;
if (!isNull _uniformContainer) then {
_uniformContainer call FUNC(replaceMagazineCargo);
};
params ["_container"];

private _vestContainer = vestContainer _box;
if (!isNull _vestContainer) then {
_vestContainer call FUNC(replaceMagazineCargo);
};
if (!local _container) exitWith {};
if (missionNamespace getVariable [QGVAR(disableMagazineReplacement), false]) exitWith {};

private _backpackContainer = backpackContainer _box;
if (!isNull _backpackContainer) then {
_backpackContainer call FUNC(replaceMagazineCargo);
};
private _containers = everyBackpack _container;
_containers append ([uniformContainer _container, vestContainer _container, backpackContainer _container] select {!isNull _x});
johnb432 marked this conversation as resolved.
Show resolved Hide resolved

// Replace all magazines recursively
{
_x call FUNC(replaceMagazineCargo);
} forEach everyBackpack _box;
} forEach _containers;

if (magazineCargo _box arrayIntersect GVAR(magazines) isEqualTo []) exitWith {};
private _magazines = (magazineCargo _container) select {_x in GVAR(magazines)};

private _magazines = magazinesAmmoCargo _box;
clearMagazineCargoGlobal _box;

private _isBackpack = getNumber (configOf _box >> "isBackpack") != -1;
if (_magazines isEqualTo []) exitWith {};

// Replace magazines with disposable launchers
{
_x params ["_magazine", "_ammo"];

if (_magazine in GVAR(magazines)) then {
private _loadedLauncher = GVAR(MagazineLaunchers) getVariable _magazine;
if (!_isBackpack || {_loadedLauncher in GVAR(BackpackLaunchers)}) then {
_box addWeaponCargoGlobal [_loadedLauncher, 1];
};
} else {
_box addMagazineAmmoCargo [_magazine, 1, _ammo];
};
_container addMagazineCargoGlobal [_x, -1];
_container addWeaponCargoGlobal [GVAR(MagazineLaunchers) getVariable _x, 1];
} forEach _magazines;