Skip to content

Commit bdddb64

Browse files
authored
Merge pull request #185 from DeliciousJaffa/warehouse_prefix_fix
Fix Warehouse not saving ace items + Transfer improvments
2 parents f92b575 + 6c687f5 commit bdddb64

12 files changed

Lines changed: 133 additions & 127 deletions

addons/overthrow_main/functions/AI/fn_getSoldier.sqf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ if(_scope isEqualTo "") then {
6666
if(count _tertiary > 0) then {
6767
private _got = false;
6868
{
69-
private _d = warehouse getvariable [_x,[_x,0]];
70-
private _num = _d select 1;
69+
private _d = warehouse getvariable [format["item_%1",_x],[_x,0]];
70+
_d params ["_cls",["_num",0,[0]]];
7171
if(_num > 0) then {
7272
_tertiary = _x;
7373
_got = true;

addons/overthrow_main/functions/UI/dialogs/fn_warehouseDialog.sqf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
private _cursel = lbCurSel 1500;
22
lbClear 1500;
3-
private _sorted = [allVariables warehouse,[],{_x},"ASCEND"] call BIS_fnc_SortBy;
3+
private _itemVars = (allVariables warehouse) select {((toLower _x select [0,5]) isEqualTo "item_")};
4+
_itemVars sort true;
45
private _numitems = 0;
56
{
6-
private _d = warehouse getVariable [_x,[_x,0]];
7+
private _d = warehouse getVariable [_x,false];
78
if(_d isEqualType []) then {
8-
_d params ["_cls", "_num"];
9-
if (!(_cls isEqualType {}) && {_num > 0}) then {
9+
_d params ["_cls", ["_num",0,[0]]];
10+
if (!(_cls isEqualType {}) && _num > 0) then {
1011
_numitems = _numitems + 1;
1112
([_cls] call {
1213
params ["_cls"];
@@ -41,7 +42,7 @@ private _numitems = 0;
4142
lbSetData [1500,_idx,_cls];
4243
};
4344
};
44-
}foreach(_sorted);
45+
}foreach(_itemVars);
4546

4647
if(_cursel >= _numitems) then {_cursel = 0};
4748
lbSetCurSel [1500, _cursel];

addons/overthrow_main/functions/actions/fn_transferHelper.sqf

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ _this spawn {
3939

4040
if(_iswarehouse) then {
4141
{
42-
_cls = _x select 0;
43-
_d = warehouse getVariable [(_x select 0),[_cls,0]];
44-
if(typename _d == "ARRAY") then {
45-
_num = _x select 1;
42+
_x params ["_cls", "_num"];
43+
_d = warehouse getVariable [format["item_%1",_cls],[_cls,0]];
44+
if(_d isEqualType []) then {
45+
_d params ["_wCls",["_in",0]];
4646
_in = _d select 1;
47-
warehouse setVariable[_cls,[_cls,_in + _num],true];
47+
warehouse setVariable[format["item_%1",_cls],[_cls,_in + _num],true];
4848
};
4949
}foreach(_target call OT_fnc_unitStock);
5050
clearMagazineCargoGlobal _target;
@@ -56,51 +56,48 @@ _this spawn {
5656
_x params [["_cls",""], ["_max",0]];
5757
private _count = 0;
5858
private _full = false;
59-
while {_count < _max} do {
60-
if(!(_veh isKindOf "Truck_F" || _veh isKindOf "ReammoBox_F") && !(_veh canAdd _cls)) exitWith {
61-
_full = true;
59+
60+
if ((_veh isKindOf "Truck_F" || _veh isKindOf "ReammoBox_F")) then {
61+
_count = _max;
62+
} else {
63+
while {_count < _max} do {
64+
if(!(_veh canAdd [_cls,_count+1])) exitWith {_full = true;};
65+
_count = _count + 1;
6266
};
63-
_count = _count + 1;
64-
[_veh, _cls] call {
65-
params ["_veh", "_cls"];
67+
};
68+
69+
if (_count > 0) then {
70+
[_veh, _target, _cls, _count] call {
71+
params ["_veh", "_target" ,"_cls", "_count"];
6672
if(_cls isKindOf "Bag_Base") exitWith {
6773
_cls = _cls call BIS_fnc_basicBackpack;
68-
_veh addBackpackCargoGlobal [_cls,1];
74+
_veh addBackpackCargoGlobal [_cls,_count];
75+
[_target, _cls, _count] call CBA_fnc_removeBackpackCargo;
6976
};
7077
if(_cls isKindOf ["Rifle",configFile >> "CfgWeapons"]) exitWith {
71-
_veh addWeaponCargoGlobal [_cls,1];
78+
_veh addWeaponCargoGlobal [_cls,_count];
79+
[_target, _cls, _count] call CBA_fnc_removeWeaponCargo;
7280
};
7381
if(_cls isKindOf ["Launcher",configFile >> "CfgWeapons"]) exitWith {
74-
_veh addWeaponCargoGlobal [_cls,1];
82+
_veh addWeaponCargoGlobal [_cls,_count];
83+
[_target, _cls, _count] call CBA_fnc_removeWeaponCargo;
7584
};
7685
if(_cls isKindOf ["Pistol",configFile >> "CfgWeapons"]) exitWith {
77-
_veh addWeaponCargoGlobal [_cls,1];
86+
_veh addWeaponCargoGlobal [_cls,_count];
87+
[_target, _cls, _count] call CBA_fnc_removeWeaponCargo;
7888
};
7989
if(_cls isKindOf ["Binocular",configFile >> "CfgWeapons"]) exitWith {
80-
_veh addWeaponCargoGlobal [_cls,1];
90+
_veh addWeaponCargoGlobal [_cls,_count];
91+
[_target, _cls, _count] call CBA_fnc_removeWeaponCargo;
8192
};
8293
if(_cls isKindOf ["CA_Magazine",configFile >> "CfgMagazines"]) exitWith {
83-
_veh addMagazineCargoGlobal [_cls,1];
94+
_veh addMagazineCargoGlobal [_cls,_count];
95+
[_target, _cls, _count] call CBA_fnc_removeMagazineCargo;
96+
};
97+
_veh addItemCargoGlobal [_cls,_count];
98+
if !([_target, _cls, _count] call CBA_fnc_removeItemCargo) then {
99+
[_target, _cls, _count] call CBA_fnc_removeWeaponCargo;
84100
};
85-
_veh addItemCargoGlobal [_cls,1];
86-
};
87-
};
88-
[_target, _cls, _count] call {
89-
params ["_target", "_cls", "_count"];
90-
if(_cls isKindOf "Bag_Base") exitWith {
91-
[_target, _cls, _count] call CBA_fnc_removeBackpackCargo;
92-
};
93-
if(_cls isKindOf ["Rifle",configFile >> "CfgWeapons"]) exitWith {
94-
[_target, _cls, _count] call CBA_fnc_removeWeaponCargo;
95-
};
96-
if(_cls isKindOf ["Launcher",configFile >> "CfgWeapons"]) exitWith {
97-
[_target, _cls, _count] call CBA_fnc_removeWeaponCargo;
98-
};
99-
if(_cls isKindOf ["CA_Magazine",configFile >> "CfgMagazines"]) exitWith {
100-
[_target, _cls, _count] call CBA_fnc_removeMagazineCargo;
101-
};
102-
if !([_target, _cls, _count] call CBA_fnc_removeItemCargo) then {
103-
[_target, _cls, _count] call CBA_fnc_removeWeaponCargo;
104101
};
105102
};
106103
if(_full) exitWith {hint "The vehicle is full, use a truck or ammobox for more storage"};

addons/overthrow_main/functions/actions/fn_transferLegit.sqf

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,38 +38,44 @@ _doTransfer = {
3838
_full = false;
3939
if(_iswarehouse) then {
4040
{
41-
_count = 0;
42-
_d = warehouse getVariable [_x,[_x,0]];
43-
if(typename _d isEqualTo "ARRAY") then {
44-
_cls = _d select 0;
45-
_num = _d select 1;
41+
private _count = 0;
42+
_d = warehouse getVariable [_x,false];
43+
if(_d isEqualType []) then {
44+
params ["_cls",["_num",0,[0]]];
4645
if(_num > 0) then {
4746
if(_cls in OT_allItems) then {
4847
while {_count < _num} do {
49-
if !(_veh canAdd _cls) exitWith {_full = true;warehouse setVariable [_cls,_num - _count,true]};
50-
_veh addItemCargoGlobal [_cls,1];
48+
if(!(_veh canAdd [_cls,_count+1])) exitWith {_full = true};
5149
_count = _count + 1;
5250
};
53-
if !(_full) then {
54-
warehouse setVariable [_cls,nil,true];
51+
if (_count > 0) then {
52+
_veh addItemCargoGlobal [_cls,_count];
53+
if (_count isEqualTo _num) then {
54+
warehouse setVariable [_x,nil,true];
55+
} else {
56+
warehouse setVariable [_x,[_cls,_num - _count],true];
57+
};
5558
};
5659
};
5760
};
5861
};
5962
if(_full) exitWith {};
60-
}foreach(allvariables warehouse);
63+
}foreach((allVariables warehouse) select {((toLower _x select [0,5]) isEqualTo "item_")});
6164
}else{
6265
{
63-
_count = 0;
64-
_cls = _x select 0;
66+
private _count = 0;
67+
params ["_cls","_num"];
6568
if(_cls in OT_allItems) then {
66-
while {_count < (_x select 1)} do {
67-
if !(_veh canAdd _cls) exitWith {_full = true};
68-
_veh addItemCargoGlobal [_cls,1];
69+
while {_count < _num} do {
70+
if(!(_veh canAdd [_cls,_count+1])) exitWith {_full = true;};
6971
_count = _count + 1;
7072
};
71-
if !([_target, _cls, _count] call CBA_fnc_removeItemCargo) then {
72-
[_target, _cls, _count] call CBA_fnc_removeWeaponCargo;
73+
74+
if (_count > 0) then {
75+
_veh addItemCargoGlobal [_cls,_count];
76+
if !([_target, _cls, _count] call CBA_fnc_removeItemCargo) then {
77+
[_target, _cls, _count] call CBA_fnc_removeWeaponCargo;
78+
};
7379
};
7480
};
7581
if(_full) exitWith {};

addons/overthrow_main/functions/actions/fn_warehouseTake.sqf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ OT_taking = true;
44
private _idx = lbCurSel 1500;
55
private _cls = lbData [1500,_idx];
66
private _num = _this select 0;
7-
private _d = warehouse getVariable [_cls,[_cls,0]];
8-
private _in = _d select 1;
7+
private _d = warehouse getVariable [format["item_%1",_cls],[_cls,0]];
8+
_d params ["_wCls", ["_in",0,[0]]];
99

1010
if(_num > _in || _num isEqualTo -1) then {
1111
_num = _in;
@@ -55,9 +55,9 @@ while {_count < _num} do {
5555

5656
private _newnum = _in - _num;
5757
if(_newnum > 0) then {
58-
warehouse setVariable [_cls,[_cls,_newnum],true];
58+
warehouse setVariable [format["item_%1",_cls],[_cls,_newnum],true];
5959
}else{
60-
warehouse setVariable [_cls,nil,true];
60+
warehouse setVariable [format["item_%1",_cls],nil,true];
6161
};
6262

6363
[] call OT_fnc_warehouseDialog;

addons/overthrow_main/functions/save/fn_loadGame.sqf

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,31 @@ sleep 0.2;
8585
// todo _set = false?
8686
};
8787
if(_key == "warehouse") then {
88-
{
89-
_x params ["_subkey","_subval"];
90-
if !(isNil {_subval}) then {
91-
if!(toLower (_subkey select [0,4]) in ["cba_","bis_"] ) then {
92-
warehouse setVariable [_subkey,_subval,true];
93-
};
88+
private _version = _val param [0,1,[0]];
89+
switch (_version) do {
90+
case 2: {
91+
_val deleteAt 0;
92+
{
93+
_x params ["_itemClass",["_itemCount",0,[0]]];
94+
if (_itemCount > 0) then {
95+
warehouse setVariable [format["item_%1",_itemClass],[_itemClass,_itemCount],true];
96+
};
97+
}foreach(_val);
9498
};
95-
}foreach(_val);
99+
default {
100+
{
101+
_x params ["_itemClassL","_itemData"];
102+
if !(isNil "_itemData") then {
103+
if (_itemData isEqualType []) then {
104+
_itemData params ["_cls",["_num",0,[0]]];
105+
if (_num > 0) then {
106+
warehouse setVariable [format["item_%1",_itemClassL],_itemData,true];
107+
};
108+
};
109+
};
110+
}foreach(_val select {!(((toLower (_val#0)) select [0,4]) in ["cba_","bis_"])});
111+
};
112+
};
96113
_set = false;
97114
};
98115
if(_key == "vehicles") then {

addons/overthrow_main/functions/save/fn_saveGame.sqf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,10 @@ if !(_quiet) then {
171171
"Step 6/11 - Saving warehouse" remoteExecCall ["OT_fnc_notifyAndLog",0,false];
172172
};
173173

174-
private _warehouse = (allvariables warehouse select _prefixFilter) apply {
175-
[ _x, warehouse getVariable _x]
176-
};
174+
private _warehouse = [2]; //First element is save version
175+
_warehouse append ((allVariables warehouse) select {((toLower _x select [0,5]) isEqualTo "item_")} apply {
176+
[_x select [5], (warehouse getVariable _x) param [1,0,[0]]]
177+
});
177178
_data pushback ["warehouse",_warehouse];
178179

179180
if !(_quiet) then {

addons/overthrow_main/functions/warehouse/fn_findHelmetInWarehouse.sqf

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
private _found = "";
22
private _possible = [];
33
{
4-
private _d = warehouse getvariable [_x,[_x,0]];
5-
if(typename _d isEqualTo "ARRAY") then {
6-
_d params ["_cls","_num"];
7-
if(!isNil "_num") then {
8-
if(_num isEqualType 0 && {_num > 0} && {_cls in OT_allHelmets}) then {
9-
_possible pushback _cls;
10-
};
11-
}else{
12-
warehouse setvariable [_x,nil,true];
4+
private _d = warehouse getvariable [_x,false];
5+
if(_d isEqualType []) then {
6+
_d params ["_cls",["_num",0,[0]]];
7+
if(_num > 0 && {_cls in OT_allHelmets}) then {
8+
_possible pushback _cls;
139
};
1410
};
15-
}foreach(allvariables warehouse);
11+
}foreach((allVariables warehouse) select {((toLower _x select [0,5]) isEqualTo "item_")});
1612

1713
if(count _possible > 0) then {
1814
private _sorted = [_possible,[],{(cost getvariable [_x,[200]]) select 0},"DESCEND"] call BIS_fnc_SortBy;

addons/overthrow_main/functions/warehouse/fn_findScopeInWarehouse.sqf

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,20 @@ params ["_range"];
22
private _found = "";
33
private _possible = [];
44
{
5-
private _d = warehouse getvariable [_x,[_x,0]];
6-
if(typename _d isEqualTo "ARRAY") then {
7-
_d params ["_cls","_num"];
8-
if(!isNil "_num") then {
9-
if(_num isEqualType 0 && {_num > 0} && {_cls in OT_allOptics}) then {
10-
private _allModes = "true" configClasses ( configFile >> "cfgWeapons" >> _cls >> "ItemInfo" >> "OpticsModes" );
11-
private _max = 0;
12-
{
13-
_max = _max max getNumber (_x >> "distanceZoomMax");
14-
}foreach(_allModes);
5+
private _d = warehouse getvariable [_x,false];
6+
if(_d isEqualType []) then {
7+
_d params ["_cls",["_num",0,[0]]];
8+
if(_num > 0 && {_cls in OT_allOptics}) then {
9+
private _allModes = "true" configClasses ( configFile >> "cfgWeapons" >> _cls >> "ItemInfo" >> "OpticsModes" );
10+
private _max = 0;
11+
{
12+
_max = _max max getNumber (_x >> "distanceZoomMax");
13+
}foreach(_allModes);
1514

16-
if(_max >= _range) then {_possible pushback _cls};
17-
};
18-
}else{
19-
warehouse setvariable [_x,nil,true];
15+
if(_max >= _range) then {_possible pushback _cls};
2016
};
2117
};
22-
}foreach(allvariables warehouse);
18+
}foreach((allVariables warehouse) select {((toLower _x select [0,5]) isEqualTo "item_")});
2319

2420
if(count _possible > 0) then {
2521
private _sorted = [_possible,[],{(cost getvariable [_x,[200]]) select 0},"DESCEND"] call BIS_fnc_SortBy;

addons/overthrow_main/functions/warehouse/fn_findVestInWarehouse.sqf

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
private _found = "";
22
private _possible = [];
33
{
4-
private _d = warehouse getvariable [_x,[_x,0]];
4+
private _d = warehouse getvariable [_x,false];
55
if(_d isEqualType []) then {
6-
_d params ["_cls","_num"];
7-
if(!isNil "_num") then {
8-
if(_num isEqualType 0 && {_num > 0} && {_cls in OT_allVests}) then {
9-
_possible pushback _cls;
10-
};
11-
}else{
12-
warehouse setvariable [_x,nil,true];
6+
_d params ["_cls",["_num",0,[0]]];
7+
if(_num > 0 && {_cls in OT_allVests}) then {
8+
_possible pushback _cls;
139
};
1410
};
15-
}foreach(allvariables warehouse);
11+
}foreach((allVariables warehouse) select {((toLower _x select [0,5]) isEqualTo "item_")});
1612

1713
if(count _possible > 0) then {
1814
private _sorted = [_possible,[],{(cost getvariable [_x,[200]]) select 0},"DESCEND"] call BIS_fnc_SortBy;

0 commit comments

Comments
 (0)