Skip to content

Commit c82b51f

Browse files
mrschickrautamiekkaLinkIsGrim
authored
Arsenal - Reuse current inventory containers when importing invalid loadouts (#10364)
Co-authored-by: Jouni Järvinen <rautamiekka@users.noreply.github.com> Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>
1 parent 03d3b80 commit c82b51f

File tree

9 files changed

+105
-27
lines changed

9 files changed

+105
-27
lines changed

addons/arsenal/XEH_PREP.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ PREP(onSelChangedRightListnBox);
7070
PREP(open3DEN);
7171
PREP(openBox);
7272
PREP(portVALoadouts);
73+
PREP(preventOverfilling);
7374
PREP(refresh);
7475
PREP(removeAction);
7576
PREP(removeBox);
@@ -79,6 +80,7 @@ PREP(removeStat);
7980
PREP(removeVirtualItems);
8081
PREP(renameDefaultLoadout);
8182
PREP(replaceUniqueItemsLoadout);
83+
PREP(recoverInvalidContainers);
8284
PREP(saveLoadout);
8385
PREP(scanConfig);
8486
PREP(showItem);

addons/arsenal/functions/fnc_buttonImport.sqf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ if (GVAR(shiftState) && {is3DEN}) then {
5454

5555
// Check if CBA extended loadout array
5656
if ((count _extendedLoadout) == 2) then {
57+
// Verify the loadout and attempt to recover any invalid containers
58+
_extendedLoadout = [_extendedLoadout, true] call FUNC(verifyLoadout);
59+
// Since verification nests the extended loadout array, undo that after container recovery
60+
_extendedLoadout = ([GVAR(center), _extendedLoadout] call FUNC(recoverInvalidContainers)) select 0;
61+
5762
[GVAR(center), _extendedLoadout] call CBA_fnc_setLoadout;
5863

5964
// Update current item list and unique items

addons/arsenal/functions/fnc_buttonLoadoutsLoad.sqf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ private _extendedLoadout = switch (GVAR(currentLoadoutsTab)) do {
3737
// Apply loadout to unit
3838
[GVAR(center), _extendedLoadout, true] call CBA_fnc_setLoadout;
3939

40+
// Prevent overloading of inventory containers
41+
GVAR(center) call FUNC(preventOverfilling);
42+
4043
// Update current item list and unique items
4144
[true] call FUNC(refresh);
4245

addons/arsenal/functions/fnc_fillLoadoutsList.sqf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ if (GVAR(currentLoadoutsTab) != IDC_buttonSharedLoadouts) then {
6868

6969
// If not in cache, get info and cache it
7070
if (isNil "_loadoutCachedInfo") then {
71-
_loadoutCachedInfo = [_loadoutData] call FUNC(verifyLoadout);
71+
// Run verification in "recover" mode to salvage invalid containers, replacing them with those currently being worn
72+
_loadoutCachedInfo = [_loadoutData, true] call FUNC(verifyLoadout);
73+
_loadoutCachedInfo = [GVAR(center), _loadoutCachedInfo] call FUNC(recoverInvalidContainers);
7274
_contentPanelCtrl setVariable [_loadoutNameAndTab, _loadoutCachedInfo];
7375

7476
_loadoutCachedInfo params ["", "_nullItemsList", "_unavailableItemsList", "_missingExtendedInfo"];

addons/arsenal/functions/fnc_onSelChangedLeft.sqf

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,8 @@ switch (GVAR(currentLeftPanel)) do {
332332
_loadout set [IDX_LOADOUT_UNIFORM, [_item, GVAR(currentItems) select IDX_CURR_UNIFORM_ITEMS]];
333333
GVAR(center) setUnitLoadout _loadout;
334334

335-
private _uniformItems = uniformItems GVAR(center);
336-
private _index = count _uniformItems - 1;
337-
338335
// Remove any items that can't fit in the container (this prevents overloading)
339-
while {loadUniform GVAR(center) > 1 && {_index >= 0}} do {
340-
GVAR(center) removeItemFromUniform (_uniformItems select _index);
341-
DEC(_index);
342-
};
336+
[GVAR(center), uniformContainer GVAR(center)] call FUNC(preventOverfilling);
343337

344338
GVAR(currentItems) set [IDX_CURR_UNIFORM, _item];
345339

@@ -373,14 +367,8 @@ switch (GVAR(currentLeftPanel)) do {
373367
_loadout set [IDX_LOADOUT_VEST, [_item, GVAR(currentItems) select IDX_CURR_VEST_ITEMS]];
374368
GVAR(center) setUnitLoadout _loadout;
375369

376-
private _vestItems = vestItems GVAR(center);
377-
private _index = count _vestItems - 1;
378-
379370
// Remove any items that can't fit in the container (this prevents overloading)
380-
while {loadVest GVAR(center) > 1 && {_index >= 0}} do {
381-
GVAR(center) removeItemFromVest (_vestItems select _index);
382-
DEC(_index);
383-
};
371+
[GVAR(center), vestContainer GVAR(center)] call FUNC(preventOverfilling);
384372

385373
GVAR(currentItems) set [IDX_CURR_VEST, _item];
386374

@@ -414,14 +402,8 @@ switch (GVAR(currentLeftPanel)) do {
414402
_loadout set [IDX_LOADOUT_BACKPACK, [_item, GVAR(currentItems) select IDX_CURR_BACKPACK_ITEMS]];
415403
GVAR(center) setUnitLoadout _loadout;
416404

417-
private _backpackItems = backpackItems GVAR(center);
418-
private _index = count _backpackItems - 1;
419-
420405
// Remove any items that can't fit in the container (this prevents overloading)
421-
while {loadBackpack GVAR(center) > 1 && {_index >= 0}} do {
422-
GVAR(center) removeItemFromBackpack (_backpackItems select _index);
423-
DEC(_index);
424-
};
406+
[GVAR(center), backpackContainer GVAR(center)] call FUNC(preventOverfilling);
425407

426408
GVAR(currentItems) set [IDX_CURR_BACKPACK, _item];
427409

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "..\script_component.hpp"
2+
#include "..\defines.hpp"
3+
/*
4+
* Author: Alganthe, johnb43, mrschick
5+
* Checks the current loadout of the given unit for inventory containers (uniform/vest/backpack) filled beyond their max load, removing excess items if present.
6+
*
7+
* Arguments:
8+
* 0: Unit to check for overfill <OBJECT>
9+
* 1: Which container to check. If unit, will go through all containers starting from uniform <OBJECT>
10+
*
11+
* Return Value:
12+
* None
13+
*
14+
* Public: No
15+
*/
16+
17+
params ["_unit", ["_container", objNull]];
18+
19+
if (isNull _container || _container isEqualTo _unit) then {
20+
_container = [uniformContainer _unit, vestContainer _unit, backpackContainer _unit];
21+
} else {
22+
_container = [_container];
23+
};
24+
25+
{
26+
private _currentContainer = _x;
27+
{
28+
_currentContainer addItemCargoGlobal [_x, -1];
29+
30+
if (load _currentContainer <= 1) then {
31+
break;
32+
};
33+
} forEachReversed (itemCargo _currentContainer);
34+
} forEach (_container select {load _x > 1});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "..\script_component.hpp"
2+
#include "..\defines.hpp"
3+
/*
4+
* Author: mrschick
5+
* Attempts to recover a loadout with invalid containers by substituting them for the currently worn containers.
6+
* It is meant to be passed a loadout modified by `[loadout, true] call ace_arsenal_fnc_verifyLoadout`, nested in the format: `[[_loadout, _extendedInfo], _nullItemsList, _unavailableItemsList, _missingExtendedInfo]`
7+
*
8+
* Arguments:
9+
* 0: Unit from which to get valid (worn) containers <OBJECT>
10+
* 1: Verified loadout to insert valid containers into <ARRAY>
11+
*
12+
* Return Value:
13+
* Copy of the passed loadout, with recovered containers <ARRAY>
14+
*
15+
* Public: No
16+
*/
17+
18+
params ["_unit", "_loadout"];
19+
20+
// Work on a copy of the original array
21+
private _loadoutData = +_loadout;
22+
23+
{
24+
_x params ["_containerIdx", "_wornContainer"];
25+
26+
// Only modify the loadout if it has a filled invalid container to be recovered
27+
if (
28+
(_loadoutData#0#0#_containerIdx isNotEqualTo []) &&
29+
{_loadoutData#0#0#_containerIdx#0 == ""}
30+
) then {
31+
// Replace loadout container with worn one, if present
32+
if (_wornContainer == "") then {
33+
(_loadoutData#0#0) set [_containerIdx, []];
34+
} else {
35+
(_loadoutData#0#0#_containerIdx) set [0, _wornContainer];
36+
};
37+
};
38+
} forEach [
39+
[3, uniform _unit],
40+
[4, vest _unit],
41+
[5, backpack _unit]
42+
];
43+
44+
_loadoutData

addons/arsenal/functions/fnc_verifyLoadout.sqf

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*
77
* Arguments:
88
* 0: Loadout <ARRAY> (CBA Extended Loadout or getUnitLoadout format)
9+
* 1: Whether to attempt to recover invalid containers <BOOL>
910
*
1011
* Return Value:
1112
* Verified loadout and missing / unavailable items list and count <ARRAY>
@@ -15,7 +16,7 @@
1516

1617
#define NOT_IN_ARSENAL !(_name in GVAR(virtualItemsFlat))
1718

18-
params ["_loadout"];
19+
params ["_loadout", ["_recoverInvalidContainers", false]];
1920

2021
private _extendedInfo = createHashMap;
2122

@@ -37,7 +38,8 @@ private _missingExtendedInfo = [];
3738

3839
// Search for all items and check their availability
3940
private _fnc_filterLoadout = {
40-
_this apply {
41+
params ["_loadout", ["_recoverInvalidContainers", false]];
42+
_loadout apply {
4143
if (_x isEqualType "" && {_x != ""}) then {
4244
_name = _x call EFUNC(common,getConfigName);
4345

@@ -70,11 +72,13 @@ private _fnc_filterLoadout = {
7072
} else {
7173
// Handle arrays
7274
if (_x isEqualType []) then {
73-
_itemArray = _x call _fnc_filterLoadout;
75+
_itemArray = [_x, true] call _fnc_filterLoadout;
76+
7477
// If "" is given as a container, an error is thrown, therefore, filter out all unavailable/null containers
75-
if (count _itemArray == 2 && {(_itemArray select 0) isEqualTo ""} && {(_itemArray select 1) isEqualType []}) then {
78+
if (!_recoverInvalidContainers && {count _itemArray == 2} && {(_itemArray select 0) isEqualTo ""} && {(_itemArray select 1) isEqualType []}) then {
7679
_itemArray = [];
7780
};
81+
7882
_itemArray
7983
} else {
8084
// All other types and empty strings
@@ -86,7 +90,7 @@ private _fnc_filterLoadout = {
8690

8791
// Convert loadout to config case and replace null/unavailable items
8892
// Loadout might come from a different modpack, which might have different config naming
89-
_loadout = _loadout call _fnc_filterLoadout;
93+
_loadout = [_loadout, _recoverInvalidContainers] call _fnc_filterLoadout;
9094

9195
{
9296
private _class = _extendedInfo getOrDefault [_x, ""];

docs/wiki/feature/arsenal.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ Saving loadouts from the default and public tabs will save them in your profile,
5353

5454
All loadouts can be loaded, however items not available or missing, will NOT be added. This limitation applies to all tabs as well as imported loadouts.
5555

56+
In the case of a stored loadout's uniform, vest or backpack not being available or missing, loading it will retain the currently equipped uniform/vest/backpack and attempt to fill it with the stored one's content that is available in the arsenal.
57+
5658
The color coding for loadouts is as follows:
5759
- White: All items are available and will be loaded.
5860
- Grey: Some items in that loadout are not available in that box.

0 commit comments

Comments
 (0)