From d46dea2f462cb50714381293ed6d1953598c2263 Mon Sep 17 00:00:00 2001 From: "eugene.tretyak" Date: Tue, 27 Jul 2021 18:06:35 +0300 Subject: [PATCH 1/4] Add option to replace launcher magazine to disposable in backpack --- addons/disposable/XEH_preInit.sqf | 6 ++++++ addons/disposable/fnc_replaceMagazineCargo.sqf | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/disposable/XEH_preInit.sqf b/addons/disposable/XEH_preInit.sqf index 1bf757187c..4a8d361678 100644 --- a/addons/disposable/XEH_preInit.sqf +++ b/addons/disposable/XEH_preInit.sqf @@ -27,6 +27,7 @@ GVAR(NormalLaunchers) = [] call CBA_fnc_createNamespace; GVAR(LoadedLaunchers) = [] call CBA_fnc_createNamespace; GVAR(UsedLaunchers) = [] call CBA_fnc_createNamespace; GVAR(magazines) = []; +GVAR(BackpackReplaceableMagazines) = []; GVAR(MagazineLaunchers) = [] call CBA_fnc_createNamespace; private _cfgWeapons = configFile >> "CfgWeapons"; @@ -35,6 +36,7 @@ private _cfgMagazines = configFile >> "CfgMagazines"; { private _launcher = configName _x; private _magazine = configName (_cfgMagazines >> (getArray (_cfgWeapons >> _launcher >> "magazines") select 0)); + private _replaceInBackpack = [_cfgMagazines >> _magazine, QGVAR(launcherFitsBackpack), 0] call BIS_fnc_returnConfigEntry > 0; getArray _x params ["_loadedLauncher", "_usedLauncher"]; GVAR(LoadedLaunchers) setVariable [_launcher, _loadedLauncher]; @@ -48,6 +50,10 @@ private _cfgMagazines = configFile >> "CfgMagazines"; GVAR(MagazineLaunchers) setVariable [_magazine, _loadedLauncher]; }; + if (_replaceInBackpack) then { + GVAR(BackpackReplaceableMagazines) pushBackUnique _magazine; + }; + // check if mass entries add up private _massLauncher = getNumber (_cfgWeapons >> _launcher >> "WeaponSlotsInfo" >> "mass"); private _massMagazine = getNumber (_cfgMagazines >> _magazine >> "mass"); diff --git a/addons/disposable/fnc_replaceMagazineCargo.sqf b/addons/disposable/fnc_replaceMagazineCargo.sqf index a01682b111..08f2032d9a 100644 --- a/addons/disposable/fnc_replaceMagazineCargo.sqf +++ b/addons/disposable/fnc_replaceMagazineCargo.sqf @@ -56,7 +56,7 @@ private _isBackpack = getNumber (configOf _box >> "isBackpack") != -1; _x params ["_magazine", "_ammo"]; if (_magazine in GVAR(magazines)) then { - if !(_isBackpack) then { + if (!_isBackpack || _magazine in GVAR(BackpackReplaceableMagazines)) then { _box addWeaponCargoGlobal [GVAR(MagazineLaunchers) getVariable _magazine, 1]; }; } else { From 4c5e197632a3430f1b60bb1994c17f0106838143 Mon Sep 17 00:00:00 2001 From: "eugene.tretyak" Date: Tue, 27 Jul 2021 18:18:38 +0300 Subject: [PATCH 2/4] Replace with lazy condition --- addons/disposable/fnc_replaceMagazineCargo.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/disposable/fnc_replaceMagazineCargo.sqf b/addons/disposable/fnc_replaceMagazineCargo.sqf index 08f2032d9a..f90363e596 100644 --- a/addons/disposable/fnc_replaceMagazineCargo.sqf +++ b/addons/disposable/fnc_replaceMagazineCargo.sqf @@ -56,7 +56,7 @@ private _isBackpack = getNumber (configOf _box >> "isBackpack") != -1; _x params ["_magazine", "_ammo"]; if (_magazine in GVAR(magazines)) then { - if (!_isBackpack || _magazine in GVAR(BackpackReplaceableMagazines)) then { + if (!_isBackpack || {_magazine in GVAR(BackpackReplaceableMagazines)}) then { _box addWeaponCargoGlobal [GVAR(MagazineLaunchers) getVariable _magazine, 1]; }; } else { From 8fb2402efefc656927a040b8be225218eae8517a Mon Sep 17 00:00:00 2001 From: "eugene.tretyak" Date: Tue, 27 Jul 2021 21:33:41 +0300 Subject: [PATCH 3/4] Fixes after review --- addons/disposable/XEH_preInit.sqf | 8 ++++---- addons/disposable/fnc_replaceMagazineCargo.sqf | 5 +++-- addons/disposable/script_component.hpp | 4 ++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/addons/disposable/XEH_preInit.sqf b/addons/disposable/XEH_preInit.sqf index 4a8d361678..e205d9b679 100644 --- a/addons/disposable/XEH_preInit.sqf +++ b/addons/disposable/XEH_preInit.sqf @@ -27,7 +27,7 @@ GVAR(NormalLaunchers) = [] call CBA_fnc_createNamespace; GVAR(LoadedLaunchers) = [] call CBA_fnc_createNamespace; GVAR(UsedLaunchers) = [] call CBA_fnc_createNamespace; GVAR(magazines) = []; -GVAR(BackpackReplaceableMagazines) = []; +GVAR(BackpackLaunchers) = createHashMap; GVAR(MagazineLaunchers) = [] call CBA_fnc_createNamespace; private _cfgWeapons = configFile >> "CfgWeapons"; @@ -36,8 +36,8 @@ private _cfgMagazines = configFile >> "CfgMagazines"; { private _launcher = configName _x; private _magazine = configName (_cfgMagazines >> (getArray (_cfgWeapons >> _launcher >> "magazines") select 0)); - private _replaceInBackpack = [_cfgMagazines >> _magazine, QGVAR(launcherFitsBackpack), 0] call BIS_fnc_returnConfigEntry > 0; getArray _x params ["_loadedLauncher", "_usedLauncher"]; + private _fitsInBackpacks = TYPE_BACKPACK in getArray(configFile >> "CfgWeapons" >> _loadedLauncher >> "WeaponSlotsInfo" >> "allowedSlots"); GVAR(LoadedLaunchers) setVariable [_launcher, _loadedLauncher]; GVAR(UsedLaunchers) setVariable [_launcher, _usedLauncher]; @@ -50,8 +50,8 @@ private _cfgMagazines = configFile >> "CfgMagazines"; GVAR(MagazineLaunchers) setVariable [_magazine, _loadedLauncher]; }; - if (_replaceInBackpack) then { - GVAR(BackpackReplaceableMagazines) pushBackUnique _magazine; + if (_fitsInBackpacks) then { + GVAR(BackpackLaunchers) set [_loadedLauncher, true]; }; // check if mass entries add up diff --git a/addons/disposable/fnc_replaceMagazineCargo.sqf b/addons/disposable/fnc_replaceMagazineCargo.sqf index f90363e596..89e3da9e6b 100644 --- a/addons/disposable/fnc_replaceMagazineCargo.sqf +++ b/addons/disposable/fnc_replaceMagazineCargo.sqf @@ -56,8 +56,9 @@ private _isBackpack = getNumber (configOf _box >> "isBackpack") != -1; _x params ["_magazine", "_ammo"]; if (_magazine in GVAR(magazines)) then { - if (!_isBackpack || {_magazine in GVAR(BackpackReplaceableMagazines)}) then { - _box addWeaponCargoGlobal [GVAR(MagazineLaunchers) getVariable _magazine, 1]; + private _loadedLauncher = GVAR(MagazineLaunchers) getVariable _magazine; + if (!_isBackpack || {_loadedLauncher in GVAR(BackpackLaunchers)}) then { + _box addWeaponCargoGlobal [_loadedLauncher, 1]; }; } else { _box addMagazineAmmoCargo [_magazine, 1, _ammo]; diff --git a/addons/disposable/script_component.hpp b/addons/disposable/script_component.hpp index 1478b6a099..02a2f8fd12 100644 --- a/addons/disposable/script_component.hpp +++ b/addons/disposable/script_component.hpp @@ -19,3 +19,7 @@ #include "\a3\ui_f\hpp\defineResincl.inc" #define WEAPON_MAGAZINES(unit,weapon) (weaponsItems (unit) select {_x select 0 == (weapon)} param [0, []] select {_x isEqualType []}) + +#define TYPE_VEST 701 +#define TYPE_UNIFORM 801 +#define TYPE_BACKPACK 901 From 54a59070ff4c2e36589b46d258120d5573e462ff Mon Sep 17 00:00:00 2001 From: 10Dozen Date: Wed, 28 Jul 2021 12:11:43 +0300 Subject: [PATCH 4/4] Update addons/disposable/XEH_preInit.sqf Co-authored-by: commy2 --- addons/disposable/XEH_preInit.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/disposable/XEH_preInit.sqf b/addons/disposable/XEH_preInit.sqf index e205d9b679..5d982efe8f 100644 --- a/addons/disposable/XEH_preInit.sqf +++ b/addons/disposable/XEH_preInit.sqf @@ -37,7 +37,7 @@ private _cfgMagazines = configFile >> "CfgMagazines"; private _launcher = configName _x; private _magazine = configName (_cfgMagazines >> (getArray (_cfgWeapons >> _launcher >> "magazines") select 0)); getArray _x params ["_loadedLauncher", "_usedLauncher"]; - private _fitsInBackpacks = TYPE_BACKPACK in getArray(configFile >> "CfgWeapons" >> _loadedLauncher >> "WeaponSlotsInfo" >> "allowedSlots"); + private _fitsInBackpacks = TYPE_BACKPACK in getArray (configFile >> "CfgWeapons" >> _loadedLauncher >> "WeaponSlotsInfo" >> "allowedSlots"); GVAR(LoadedLaunchers) setVariable [_launcher, _loadedLauncher]; GVAR(UsedLaunchers) setVariable [_launcher, _usedLauncher];