Skip to content

Commit 6114bdd

Browse files
committed
reworked edge-case items in replace_container
1 parent 6f3b9b3 commit 6114bdd

10 files changed

+111
-88
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class GVAR(exceptions) {
2+
class acex_intelitems_document {
3+
code = QFUNC(exceptionsAceItems);
4+
mode = "local";
5+
};
6+
class acex_intelitems_notepad: acex_intelitems_document {};
7+
class acex_intelitems_photo: acex_intelitems_document {};
8+
class ACE_SpareBarrel: acex_intelitems_document {
9+
mode = "server";
10+
};
11+
};

addons/wardrobe/XEH_PREP.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ PREP(addActionsIcon);
44
PREP(addActionsName);
55
PREP(canModifyTo);
66
PREP(compareComponents);
7+
PREP(exceptionsAceItems);
78
PREP(getAvailableItemVariants);
8-
PREP(getIndexFromMagID);
99
PREP(getItemVariants);
1010
PREP(isModifiable);
1111
PREP(replace);
1212
PREP(replaceContainer);
1313
PREP(replaceOther);
14-
PREP(setIndexForMagID);
15-
PREP(spareBarrelUpdateMagIDs);

addons/wardrobe/XEH_postInit.sqf

Lines changed: 0 additions & 3 deletions
This file was deleted.

addons/wardrobe/XEH_preInit.sqf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,23 @@ PREP_RECOMPILE_END;
1010

1111
missionNamespace setVariable [QGVAR(inProgress), false];
1212

13+
// Cache Wardrobe Replace Exceptions
14+
private _map = createHashMap;
15+
{
16+
_map set [
17+
configName _x,
18+
[
19+
toLower getText (_x >> "mode"),
20+
getText (_x >> "code") call CBA_fnc_convertStringCode
21+
]
22+
];
23+
} forEach ("true" configClasses (configFile >> QGVAR(exceptions)));
24+
GVAR(exceptions) = _map;
25+
26+
[
27+
QGVAR(exceptions),
28+
{ _this call (GVAR(exceptions) get (_this#0) select 1) }
29+
] call CBA_fnc_addEventHandler;
30+
31+
1332
ADDON = true;

addons/wardrobe/config.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ class CfgPatches {
2121
#include "CfgEventHandlers.hpp"
2222
#include "CfgSounds.hpp"
2323
#include "CfgVehicles.hpp"
24+
2425
#include "CfgWardrobe.hpp"
26+
#include "CfgWardrobe_Exceptions.hpp"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "../script_component.hpp"
2+
3+
/*
4+
* Author: OverlordZorn
5+
* Wardrobe ExceptionHandling Function for ACE Items (Intel and Sparebarrels).
6+
*
7+
* Arguments:
8+
* 0: Magazine Classname <STRING>
9+
* 1: old Magazine IDs as Strings <ARRAY>
10+
* 2: new Magazine IDs as Strings <ARRAY>
11+
*
12+
* Return Value:
13+
* None
14+
*
15+
* Example:
16+
* [_className, _oldMagIDs, _newMagIDs] call ace_wardrobe_fnc_exceptionsAceItems
17+
*
18+
* Public: No
19+
*/
20+
21+
params ["_className", "_oldMagIDs", "_newMagIDs"];
22+
23+
if (count _oldMagIDs != count _newMagIDs) exitWith { ERROR_1("Not Equal Number of magID's provided: %1",_this) };
24+
25+
switch (_className) do {
26+
case "acex_intelitems_document";
27+
case "acex_intelitems_notepad";
28+
case "acex_intelitems_photo": {
29+
private _namespace = EGVAR(intelItems,intelMap);
30+
{
31+
private _oldMagID = _x;
32+
private _newMagID = _newMagIDs select _forEachIndex;
33+
34+
private _intelID = _namespace getVariable [_oldMagID, -1];
35+
36+
if (_intelID == -1) then { continue };
37+
38+
_namespace setVariable [_newMagID, _intelID, true];
39+
} forEach _oldMagIDs;
40+
};
41+
42+
case "ACE_SpareBarrel": {
43+
private _map = EGVAR(overheating,storedSpareBarrels);
44+
{
45+
private _oldID = _x;
46+
if !(_oldID in _map) then { continue };
47+
_map set [_newMagIDs # _forEachIndex , _map deleteAt _oldID];
48+
} forEach _oldMagIDs;
49+
};
50+
};

addons/wardrobe/functions/fnc_getIndexFromMagID.sqf

Lines changed: 0 additions & 25 deletions
This file was deleted.

addons/wardrobe/functions/fnc_replaceContainer.sqf

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,46 @@
2020

2121
params ["_player", "_classTarget", "_equipmentType"];
2222

23-
toFixed 0;
24-
private _magazineDetails = (magazinesAmmoFull _player) apply { [_x#0, _x#-2, _x#6] };
25-
private _loadout = _player call CBA_fnc_getLoadout;
23+
private _allMags = (magazinesAmmoFull _player) apply { _x#0 };
2624

27-
// handle special cases - pre replace
28-
// ace intel items
29-
INTEL_PRE(_document,acex_intelitems_document);
30-
INTEL_PRE(_notepad,acex_intelitems_notepad);
31-
INTEL_PRE(_photo,acex_intelitems_photo);
25+
// Identify Exceptions
26+
private _exceptions = []; // nested Array of [Classname, Array of old ID's, Array of new id's]
27+
{
28+
private _className = _x;
29+
if (_className in _allMags) then {
30+
_exceptions pushBack [
31+
_className,
32+
[_player, _className] call CBA_fnc_getMagazineIndex,
33+
[]
34+
];
35+
};
36+
} forEach keys GVAR(exceptions);
3237

33-
// ace overheating
34-
private _spareBarrel = _magazineDetails findIf { _x#0 == "ACE_SpareBarrel" } > -1;
35-
if (_spareBarrel) then { _spareBarrel = [_player, "ACE_SpareBarrel"] call CBA_fnc_getMagazineIndex };
38+
private _loadout = _player call CBA_fnc_getLoadout;
3639

37-
// replace wearable
40+
// Replace Wearable Container
3841
switch (_equipmentType) do {
3942
case "UNIFORM": { _loadout # 0 # 3 set [0, _classTarget]; };
4043
case "VEST": { _loadout # 0 # 4 set [0, _classTarget]; };
4144
case "BACKPACK": { _loadout # 0 # 5 set [0, _classTarget]; };
4245
};
4346

44-
// apply new loadout
47+
// Apply new loadout
4548
[_player, _loadout] call CBA_fnc_setLoadout;
4649

47-
// handle special cases - post replace
48-
// ace intel items
49-
INTEL_POST(_document,acex_intelitems_document);
50-
INTEL_POST(_notepad,acex_intelitems_notepad);
51-
INTEL_POST(_photo,acex_intelitems_photo);
50+
// Update Exceptions with new magID's
51+
{ _x set [ 2, [_player, _x#0] call CBA_fnc_getMagazineIndex ]; } forEach _exceptions;
52+
53+
54+
// Resolve Exceptions
55+
{
56+
// ["_className", "_oldMagIDs", "_newMagIDs"];
57+
switch (GVAR(exceptions) get (_x#0) select 0) do {
58+
case "local": { [QGVAR(exceptions), _x] call CBA_fnc_localEvent; };
59+
case "server": { [QGVAR(exceptions), _x] call CBA_fnc_serverEvent; };
60+
};
61+
} forEach _exceptions;
5262

53-
// ace overheating
54-
if (_spareBarrel isEqualType []) then {
55-
private _newMagIDsSpareBarrel = [_player, "ACE_SpareBarrel"] call CBA_fnc_getMagazineIndex;
56-
[QGVAR(updateMagIDs), [_spareBarrel, _newMagIDsSpareBarrel]] call CBA_fnc_serverEvent;
57-
};
5863

5964
GVAR(inProgress) = false; // re-enable action
6065

addons/wardrobe/functions/fnc_setIndexForMagID.sqf

Lines changed: 0 additions & 25 deletions
This file was deleted.

addons/wardrobe/script_macros_wardrobe.hpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ class EGVAR(wardrobe,base_U_jacket_open);\
1515
class EGVAR(wardrobe,base_U_jacket_closed)
1616

1717

18-
// REPLACE
19-
#define INTEL_PRE(varName,className)\
20-
private varName = _magazineDetails findIf { _x select 0 == QUOTE(className) } > -1;\
21-
if (varName) then { varName = [_player, QUOTE(className)] call CBA_fnc_getMagazineIndex apply { _x call FUNC(getIndexFromMagID) } }
22-
23-
#define INTEL_POST(varName,className)\
24-
if (varName isEqualType []) then { { [_x, varName select _forEachIndex] call FUNC(setIndexForMagID); } forEach ( [_player, QUOTE(className)] call CBA_fnc_getMagazineIndex ); }
25-
26-
2718
// Config
2819
// Adjust Weight of CfgWeapons Wearables
2920
#define MASS(var)\

0 commit comments

Comments
 (0)