Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common - Replace canAdd with CBA_fnc_canAddItem #1561

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions addons/common/fnc_addBackpackCargo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ if (isNull _config || {getNumber (_config >> "scope") < 1} || {getNumber (_confi
};

if (_verify) then {
if (_container canAdd [_item, _count]) then {
if ([_container, _item, _count] call CBA_fnc_canAddItem) then {
_container addBackpackCargoGlobal [_item, _count];
_return = true;
} else {
while {_container canAdd _item && {_count > 0}} do {
while {[_container, _item] call CBA_fnc_canAddItem && {_count > 0}} do {
_container addBackpackCargoGlobal [_item, 1];
_count = _count - 1;
};
Expand Down
2 changes: 1 addition & 1 deletion addons/common/fnc_addItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if (isNull _config || {getNumber (_config >> "scope") < 1}) exitWith {
};

if (_verify) then {
if (_unit canAdd _item) then {
if ([_unit, _item] call CBA_fnc_canAddItem) then {
_unit addItem _item;
_return = true;
} else {
Expand Down
4 changes: 2 additions & 2 deletions addons/common/fnc_addItemCargo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ if (isNull _config || {getNumber (_config >> "scope") < 1}) exitWith {
};

if (_verify) then {
if (_container canAdd [_item, _count]) then {
if ([_container, _item, _count] call CBA_fnc_canAddItem) then {
_container addItemCargoGlobal [_item, _count];
_return = true;
} else {
while {_container canAdd _item && {_count > 0}} do {
while {[_container, _item] call CBA_fnc_canAddItem && {_count > 0}} do {
_container addItemCargoGlobal [_item, 1];
_count = _count - 1;
};
Expand Down
4 changes: 2 additions & 2 deletions addons/common/fnc_addMagazineCargo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ if (isNull _config || {getNumber (_config >> "scope") < 2}) exitWith {
};

if (_verify) then {
if (_container canAdd [_item, _count]) then {
if ([_container, _item, _count] call CBA_fnc_canAddItem) then {
_container addMagazineAmmoCargo [_item, _count, _ammo];
_return = true;
} else {
while {_container canAdd _item && {_count > 0}} do {
while {[_container, _item] call CBA_fnc_canAddItem && {_count > 0}} do {
_container addMagazineAmmoCargo [_item, 1, _ammo];
_count = _count - 1;
};
Expand Down
4 changes: 2 additions & 2 deletions addons/common/fnc_addWeaponCargo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ if (isNull _config || {getNumber (_config >> "scope") < 1}) exitWith {
};

if (_verify) then {
if (_container canAdd [_item, _count]) then {
if ([_container, _item, _count] call CBA_fnc_canAddItem) then {
_container addWeaponCargoGlobal [_item, _count];
_return = true;
} else {
while {_container canAdd _item && {_count > 0}} do {
while {[_container, _item] call CBA_fnc_canAddItem && {_count > 0}} do {
_container addWeaponCargoGlobal [_item, 1];
_count = _count - 1;
};
Expand Down
17 changes: 10 additions & 7 deletions addons/common/fnc_canAddItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ if (isNull _unit || {_item isEqualTo ""}) exitWith {false};
#define TYPE_VEST 701
#define TYPE_UNIFORM 801
#define TYPE_BACKPACK 901
#define FLOAT_CORRECTION 0.0001

if (isNil QGVAR(itemMassAllowedSlots)) then {
GVAR(itemMassAllowedSlots) = createHashMap;
Expand All @@ -54,6 +55,7 @@ if (isNil "_mass") then {
_allowedSlots = [TYPE_UNIFORM, TYPE_VEST, TYPE_BACKPACK];
private _cfgWeaponsItem = configFile >> "CfgWeapons" >> _item;
private _cfgMagazinesItem = configFile >> "CfgMagazines" >> _item;
private _cfgVehiclesItem = configFile >> "CfgVehicles" >> _item;
private _cfgGlassesItem = configFile >> "CfgGlasses" >> _item;
switch true do {
case (isClass _cfgWeaponsItem): {
Expand All @@ -75,9 +77,10 @@ if (isNil "_mass") then {
_cfgWeaponSlotsInfo >> "allowedSlots"
];
};
case (isClass _cfgMagazinesItem): {
_mass = getNumber (_cfgMagazinesItem >> "mass");
private _cfgAllowedSlots = _cfgMagazinesItem >> "allowedSlots";
case (isClass _cfgMagazinesItem || {isClass _cfgVehiclesItem}): {
private _cfgItem = [_cfgVehiclesItem, _cfgMagazinesItem] select isClass _cfgMagazinesItem;
_mass = getNumber (_cfgItem >> "mass");
private _cfgAllowedSlots = _cfgItem >> "allowedSlots";
if (isArray _cfgAllowedSlots) then {
_allowedSlots = getArray _cfgAllowedSlots;
};
Expand Down Expand Up @@ -105,7 +108,7 @@ if (_unit isKindOf "CAManBase") then {
_mass == 0
|| {
// each time subtract whole number of items which can be put in container
_count = _count - floor (maxLoad uniformContainer _unit * (1 - loadUniform _unit) / _mass);
_count = _count - floor (maxLoad uniformContainer _unit * (1 - loadUniform _unit) / _mass + FLOAT_CORRECTION);
_count <= 0
}
}
Expand All @@ -117,7 +120,7 @@ if (_unit isKindOf "CAManBase") then {
&& {
_mass == 0
|| {
_count = _count - floor (maxLoad vestContainer _unit * (1 - loadVest _unit) / _mass);
_count = _count - floor (maxLoad vestContainer _unit * (1 - loadVest _unit) / _mass + FLOAT_CORRECTION);
_count <= 0
}
}
Expand All @@ -129,7 +132,7 @@ if (_unit isKindOf "CAManBase") then {
&& {
_mass == 0
|| {
_count = _count - floor (maxLoad backpackContainer _unit * (1 - loadBackpack _unit) / _mass);
_count = _count - floor (maxLoad backpackContainer _unit * (1 - loadBackpack _unit) / _mass + FLOAT_CORRECTION);
_count <= 0
}
}
Expand All @@ -140,7 +143,7 @@ if (_unit isKindOf "CAManBase") then {
// is a vehicle, crate etc.
_mass == 0
|| {
_count = _count - floor (maxLoad _unit * (1 - load _unit) / _mass);
_count = _count - floor (maxLoad _unit * (1 - load _unit) / _mass + FLOAT_CORRECTION);
_count <= 0
}
};