Add handling of magazine overflow in AdvTrade and free slot icons

- Added proper handling of pistol mags and regular mags in gear to
prevent magazine overflow
- Added pre-check if return change will overflow gear + backpack free
space. If change will not fit in gear + backpack free space then buy is
prevented with a message notifying the player. In the case of a sale it
proceeds anyway, but notifies player if overflow occurs (see comments in
returnChange)
- Consolidated duplicate code for calculating free space and returning
cargo of an object into new calcFreeSpace
- Old calculateFreeSpace renamed to displayFreeSpace
- Added Weps/Mags/Bags icons to free slot numbers display
This commit is contained in:
ebaydayz
2016-07-31 18:38:39 -04:00
parent d7cb2b446e
commit a5be49c546
20 changed files with 359 additions and 422 deletions

View File

@@ -1,19 +1,24 @@
private ["_selection","_return","_toBuyWeaps","_toBuyMags","_toBuyBags","_toolsToBuy","_sidearmToBuy","_primaryToBuy","_currentPrimarys"
,"_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","_amounts","_amounts2","_amounts3",
"_actualMags","_toolClasses","_duplicate","_quantity","_tool","_totalBagSlots"
private ["_selection","_return","_toBuyWeaps","_toBuyTotalMags","_toBuyBags","_toolsToBuy","_sidearmToBuy"
,"_primaryToBuy","_currentPrimarys","_p","_b","_check0","_check1","_check2","_check3","_check4","_allowedMags"
,"_allowedPrimary","_allowedTools","_allowedSidearm","_allowedBackpacks","_parentClasses","_toolClasses"
,"_duplicate","_quantity","_tool","_totalBagSlots","_pistolMags","_regularMags","_toBuyPistolMags"
,"_toBuyRegularMags","_type","_freeSpace","_backpack","_totalSpace"
];
_selection = Z_SellingFrom;
_return = false;
_toBuyWeaps = _this select 0;
_toBuyMags = _this select 1;
_toBuyPistolMags = (_this select 1) select 0;
_toBuyRegularMags = (_this select 1) select 1;
_toBuyTotalMags = _toBuyPistolMags + _toBuyRegularMags;
_toBuyBags = _this select 2;
_toolsToBuy = _this select 3;
_sidearmToBuy = _this select 4;
_primaryToBuy = _this select 5;
_vehiclesToBuy = _this select 6;
_toolClasses = _this select 7;
_allowedMags = 0;
_allowedWeapons = 0;
_allowedBackpacks = 0;
if (_vehiclesToBuy > 1) exitWith {systemChat localize "STR_EPOCH_TRADE_ONE_VEHICLE"; false;};
if (_vehiclesToBuy > 0) then {
@@ -21,8 +26,16 @@ if (_vehiclesToBuy > 0) then {
};
if (_selection == 2) then { //gear
_actualMags = {!(_x in MeleeMagazines)} count (magazines player);
_allowedMags = 20 - _actualMags;
_pistolMags = 0;
_regularMags = 0;
{
_type = getNumber (configFile >> "CfgMagazines" >> _x >> "type");
if (_type == 16) then {_pistolMags = _pistolMags + 1;}; // 16 = WeaponSlotHandGunItem (pistol ammo slot)
if (_type == 256) then {_regularMags = _regularMags + 1;}; // 256 = WeaponSlotItem (normal magazine)
} count (magazines player);
_allowedPistolMags = 8 - _pistolMags;
_allowedRegularMags = 12 - _regularMags;
_currentPrimarys = 0;
@@ -75,10 +88,10 @@ if (_selection == 2) then { //gear
} else {
systemChat format[localize "STR_EPOCH_TRADE_GEAR_FULL", _allowedPrimary, _allowedSidearm , _allowedTools];
};
if (_allowedMags >= _toBuyMags) then {
if (_allowedPistolMags >= _toBuyPistolMags && _allowedRegularMags >= _toBuyRegularMags) then {
_check2 = true;
} else {
systemChat format[localize "STR_EPOCH_TRADE_MAGS_FULL",_allowedMags];
systemChat format[localize "STR_EPOCH_TRADE_MAGS_FULL",_allowedRegularMags,_allowedPistolMags];
};
if (_allowedBackpacks >= _toBuyBags) then {
_check3 = true;
@@ -88,52 +101,11 @@ if (_selection == 2) then { //gear
};
if (_selection == 1) then { //vehicle
_allowedMags = 0;
_allowedWeapons = 0;
_allowedBackpacks = 0;
if (!isNull Z_vehicle) then {
_mags = getMagazineCargo Z_vehicle;
_weaps = getWeaponCargo Z_vehicle;
_bags = getBackpackCargo Z_vehicle;
_normalMags = [];
_normalWeaps = [];
_normalBags = [];
_kinds = _mags select 0;
_amounts = _mags select 1;
{
_counter = 0 ;
while {_counter < (_amounts select _forEachIndex)} do {
_normalMags set [count(_normalMags),_x];
_counter = _counter + 1;
};
} forEach _kinds;
_kinds2 = _weaps select 0;
_amounts2 = _weaps select 1;
{
_counter = 0 ;
while {_counter < (_amounts2 select _forEachIndex)} do {
_normalWeaps set [count(_normalWeaps),_x];
_counter = _counter + 1;
};
} forEach _kinds2;
_kinds3 = _bags select 0;
_amounts3 = _bags select 1;
{
_counter = 0 ;
while{_counter < (_amounts3 select _forEachIndex)} do {
_normalBags set [count(_normalBags),_x];
_counter = _counter + 1;
};
} forEach _kinds3;
_allowedWeapons = getNumber (configFile >> 'CfgVehicles' >> (typeOf Z_vehicle) >> 'transportMaxWeapons') - count(_normalWeaps);
_allowedMags = getNumber (configFile >> 'CfgVehicles' >> (typeOf Z_vehicle) >> 'transportMaxMagazines') - count(_normalMags);
_allowedBackpacks = getNumber (configFile >> 'CfgVehicles' >> (typeOf Z_vehicle) >> 'transportMaxBackpacks') - count(_normalBags);
_freeSpace = [Z_vehicle,0,0,0,0] call Z_calcFreeSpace;
_allowedMags = _freeSpace select 1;
_allowedWeapons = _freeSpace select 2;
_allowedBackpacks = _freeSpace select 3;
};
_check1 = false;
@@ -145,7 +117,7 @@ if (_selection == 1) then { //vehicle
} else {
systemChat format[localize "STR_EPOCH_TRADE_VEHICLE_WEPS", _allowedWeapons];
};
if (_allowedMags >= _toBuyMags) then {
if (_allowedMags >= _toBuyTotalMags) then {
_check2 = true;
} else {
systemChat format[localize "STR_EPOCH_TRADE_VEHICLE_MAGS", _allowedMags];
@@ -160,71 +132,18 @@ if (_selection == 1) then { //vehicle
};
if (_selection == 0) then { //backpack
_allowedWeapons = 0;
_allowedMags = 0;
_allowedBackpacks = 0;
_totalSpace = 0;
_totalNewSpace = 0;
_totalBagSlots = 0;
_backpack = unitBackpack player;
_check0 = false;
if (!isNull _backpack) then {
_check0 = true;
_mags = getMagazineCargo _backpack;
_weaps = getWeaponCargo _backpack;
_normalMags = [];
_normalWeaps = [];
_kinds = _mags select 0;
_amounts = _mags select 1;
{
_counter = 0 ;
while {_counter < (_amounts select _forEachIndex)} do {
_normalMags set [count(_normalMags), _x];
_counter = _counter + 1;
};
} forEach _kinds;
_kinds2 = _weaps select 0;
_amounts2 = _weaps select 1;
{
_counter = 0 ;
while {_counter < (_amounts2 select _forEachIndex)} do {
_normalWeaps set [count(_normalWeaps), _x];
_counter = _counter + 1;
};
} forEach _kinds2;
_allowedWeapons = getNumber (configFile >> 'CfgVehicles' >> (typeOf _backpack) >> 'transportMaxWeapons') - count(_normalWeaps);
_totalBagSlots = getNumber (configFile >> 'CfgVehicles' >> (typeOf _backpack) >> 'transportMaxMagazines');
_allowedMags = _totalBagSlots - count(_normalMags);
_currentPrim = 0;
_currentSec = 0;
_currentTool = 0;
{
_parentClasses = [(configFile >> "CfgWeapons" >> _x),true] call BIS_fnc_returnParents;
if ('ItemCore' in _parentClasses || '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);
_totalNewSpace = 10 * _primaryToBuy + 5 * _sidearmToBuy + _toolsToBuy + _toBuyMags;
_totalSpace = _alreadyInBackpack + _totalNewSpace;
_freeSpace = [_backpack,_primaryToBuy,_sidearmToBuy,_toolsToBuy,_toBuyTotalMags] call Z_calcFreeSpace;
_totalSpace = _freeSpace select 0;
_allowedMags = _freeSpace select 1;
_allowedWeapons = _freeSpace select 2;
_totalBagSlots = _freeSpace select 4;
} else {
systemChat localize "STR_EPOCH_TRADE_NO_BACKPACK";
};
@@ -239,12 +158,12 @@ if (_selection == 0) then { //backpack
} else {
systemChat format[localize "STR_EPOCH_TRADE_BAG_WEPS", _allowedWeapons];
};
if (_allowedMags >= _toBuyMags) then {
if (_allowedMags >= _toBuyTotalMags) then {
_check2 = true;
} else {
systemChat format[localize "STR_EPOCH_TRADE_BAG_MAGS", _allowedMags];
};
if (_allowedBackpacks >= _toBuyBags) then {
if (_toBuyBags < 1) then { // A backpack can not hold any backpacks
_check3 = true;
};
@@ -257,4 +176,4 @@ if (_selection == 0) then { //backpack
if (_check0 && _check1 && _check2 && _check3 && _check4) then { _return = true; };
};
_return;
_return