Fix incorrect backpack space calculation

Fixes not being able to purchase into a half full backpack and free slot
counts text incorrect when buying into backpack.
This commit is contained in:
ebaydayz
2016-05-08 16:21:24 -04:00
parent 84e64be47e
commit 5120d8a488
3 changed files with 54 additions and 23 deletions

View File

@@ -2,7 +2,7 @@ private ["_selection","_return","_toBuyWeaps","_toBuyMags","_toBuyBags","_toolsT
,"_currentSec","_currentPrim","_currentTool","_p","_b","_check0","_check1","_check2","_check3","_check4","_mags","_weaps","_bags"
,"_normalBags","_normalMags","_normalWeaps","_allowedMags","_allowedPrimary","_allowedTools","_allowedSidearm","_allowedWeapons","_allowedBackpacks"
,"_totalSpace","_totalNewSpace","_counter","_parentClasses","_alreadyInBackpack","_kinds","_kinds2","_kinds3","_ammmounts","_ammmounts2","_ammmounts3",
"_actualMags","_toolClasses","_duplicate","_quantity","_tool"
"_actualMags","_toolClasses","_duplicate","_quantity","_tool","_totalBagSlots"
];
_selection = Z_SellingFrom;
_return = false;
@@ -205,7 +205,8 @@ if(_selection == 0) then{ //backpack
}forEach _kinds2;
_allowedWeapons = getNumber (configFile >> 'CfgVehicles' >> (typeOf _backpack) >> 'transportMaxWeapons') - count(_normalWeaps);
_allowedMags = getNumber (configFile >> 'CfgVehicles' >> (typeOf _backpack) >> 'transportMaxMagazines') - count(_normalMags);
_totalBagSlots = getNumber (configFile >> 'CfgVehicles' >> (typeOf _backpack) >> 'transportMaxMagazines');
_allowedMags = _totalBagSlots - count(_normalMags);
@@ -234,7 +235,7 @@ if(_selection == 0) then{ //backpack
_totalSpace = _alreadyInBackpack + _totalNewSpace;
}else {
systemChat format[localize "STR_EPOCH_TRADE_NEED_BAG", _allowedMags];
systemChat localize "STR_EPOCH_TRADE_NEED_BAG";
};
_check1 = false;
@@ -258,10 +259,10 @@ if(_selection == 0) then{ //backpack
systemChat format[localize "STR_EPOCH_TRADE_BAG_BAGS", _allowedBackpacks ];
};
if( _totalSpace <= _allowedMags)then{
if( _totalSpace <= _totalBagSlots)then{
_check4 = true;
}else{
systemChat format["Total space succeeded: Mag=1, Tool=1, Side=5, Primary=10 slots and your bag capacity is %1 where you tried %2 slots.", _allowedMags, _totalNewSpace];
systemChat localize "STR_EPOCH_TRADE_BACKPACK_FULL";
};
if(_check0 && _check1 && _check2 && _check3 && _check4)then{

View File

@@ -1,5 +1,6 @@
private["_selection","_returnArray","_allowedMags","_allowedWeapons","_allowedBackpacks","_allowedTools","_allowedPrimary","_allowedSidearm","_formattedText","_pic"
,"_backpack","_vehicleWeapons","_vehicleMagazines","_vehicleBackpacks","_tempWeaponsArray","_tempBackpackArray","_tempMagazinesArray","_actualMags"];
,"_backpack","_vehicleWeapons","_vehicleMagazines","_vehicleBackpacks","_tempWeaponsArray","_tempBackpackArray","_tempMagazinesArray","_actualMags"
,"_normalMags","_normalWeaps","_kinds","_kinds2","_amounts","_amounts2","_counter"];
#include "defines.sqf";
_selection = _this select 0;
@@ -69,13 +70,11 @@ if(_selection == 1) then{ //vehicle
_returnArray = [_allowedMags - _vehicleMagazines, _allowedWeapons - _vehicleWeapons, _allowedBackpacks - _vehicleBackpacks];
};
if(_selection == 0) then{ //backpack
_allowedWeapons = 0;
_allowedMags = 0;
_allowedBackpacks = 0;
_vehicleMagazines = 0;
_vehicleWeapons = 0;
_totalBagSlots = 0;
_alreadyInBackpack = 0;
_backpack = unitBackpack player;
if (!isNil "_backpack") then {
if (!isNull _backpack) then {
_pic = getText (configFile >> 'CfgVehicles' >> (typeOf _backpack) >> 'picture');
_formattedText = format [
@@ -84,23 +83,51 @@ if(_selection == 0) then{ //backpack
];
(findDisplay Z_AT_DIALOGWINDOW displayCtrl Z_AT_CONTAINERINFO) ctrlSetStructuredText parseText _formattedText;
_tempMagazinesArray = getMagazineCargo Z_vehicle;
_tempMagazinesArray = getMagazineCargo _backpack;
_tempWeaponsArray = getWeaponCargo _backpack;
_normalMags = [];
_normalWeaps = [];
_kinds = _tempMagazinesArray select 0;
_amounts = _tempMagazinesArray select 1;
{
_vehicleMagazines = _vehicleMagazines + _x;
}count ( _tempMagazinesArray select 1);
_tempWeaponsArray = getWeaponCargo Z_vehicle;
{
_vehicleWeapons = _vehicleWeapons + _x;
}count ( _tempWeaponsArray select 1);
_allowedWeapons = getNumber (configFile >> 'CfgVehicles' >> (typeOf _backpack) >> 'transportMaxWeapons');
_allowedMags = getNumber (configFile >> 'CfgVehicles' >> (typeOf _backpack) >> 'transportMaxMagazines');
_allowedBackpacks = 0;
_counter = 0;
while {_counter < (_amounts select _forEachIndex)} do {
_normalMags set [count(_normalMags), _x];
_counter = _counter + 1;
};
_returnArray = [_allowedMags - _vehicleMagazines ,_allowedWeapons - _vehicleWeapons, _allowedBackpacks];
} forEach _kinds;
_kinds2 = _tempWeaponsArray select 0;
_amounts2 = _tempWeaponsArray select 1;
{
_counter = 0;
while {_counter < (_amounts2 select _forEachIndex)} do {
_normalWeaps set [count(_normalWeaps), _x];
_counter = _counter + 1;
};
} forEach _kinds2;
_totalBagSlots = getNumber (configFile >> 'CfgVehicles' >> (typeOf _backpack) >> 'transportMaxMagazines');
_currentPrim = 0;
_currentSec = 0;
_currentTool = 0;
{
_parentClasses = [(configFile >> "CfgWeapons" >> _x ),true] call BIS_fnc_returnParents;
if ('ItemCore' in _parentClasses or 'Binocular' in _parentClasses) then {
_currentTool = _currentTool + 1;
} else {
if ('PistolCore' in _parentClasses) then {
_currentSec = _currentSec + 1;
} else {
_currentPrim = _currentPrim + 1;
};
};
} count _normalWeaps;
_alreadyInBackpack = (10 * _currentPrim) + (5 * _currentSec) + _currentTool + count(_normalMags);
};
_returnArray = [_totalBagSlots - _alreadyInBackpack, floor((_totalBagSlots - _alreadyInBackpack) / 10), _allowedBackpacks];
};
(findDisplay Z_AT_DIALOGWINDOW displayCtrl Z_AT_SLOTSDISPLAY) ctrlSetText format["%1/%2/%3",_returnArray select 1,_returnArray select 0,_returnArray select 2];

View File

@@ -15733,6 +15733,9 @@
<English>You need a backpack.</English>
<Russian>Вам нужен рюкзак.</Russian>
</Key>
<Key ID="STR_EPOCH_TRADE_BACKPACK_FULL">
<English>Total backpack space exceeded.</English>
</Key>
<Key ID="STR_EPOCH_TRADE_BAG_WEPS">
<English>Only %1 weapons fit in the backpack.</English>
<Russian>В рюкзак поместится оружия: %1.</Russian>