From 793ef7bba52d3a7578598c5c4c5a127101fc2891 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Thu, 22 Jun 2023 04:04:19 -0300 Subject: [PATCH] Dragging - Use improved loadAbs for weight calculation (#8457) * use improved loadAbs for weight calculation * fix double counted backpack cargo --------- Co-authored-by: Salluci <69561145+Salluci@users.noreply.github.com> --- addons/dragging/functions/fnc_getWeight.sqf | 79 +++------------------ 1 file changed, 10 insertions(+), 69 deletions(-) diff --git a/addons/dragging/functions/fnc_getWeight.sqf b/addons/dragging/functions/fnc_getWeight.sqf index c9d978cf7d..ad81661748 100644 --- a/addons/dragging/functions/fnc_getWeight.sqf +++ b/addons/dragging/functions/fnc_getWeight.sqf @@ -18,78 +18,19 @@ params ["_object"]; -private _weight = 0; -private _cfgWeapons = configFile >> "CfgWeapons"; -private _cfgGlasses = configFile >> "CfgGlasses"; -private _cfgVehicles = configFile >> "CfgVehicles"; -private _cfgMagazines = configFile >> "CfgMagazines"; - -// Add the masses of "regular" items in the object's inventory -// Handle separating CfgGlasses items from this cargo array -getItemCargo _object params ["_itemTypes", "_itemCounts"]; - -{ - private _itemConfig = if (isClass (_cfgGlasses >> _x)) then { - _cfgGlasses >> _x - } else { - _cfgWeapons >> _x >> "ItemInfo" - }; - - _weight = _weight + getNumber (_itemConfig >> "mass") * (_itemCounts select _forEachIndex); -} forEach _itemTypes; - -// Add the masses of magazine items in the object's inventory -getMagazineCargo _object params ["_magazineTypes", "_magazineCounts"]; - -{ - _weight = _weight + getNumber (_cfgMagazines >> _x >> "mass") * (_magazineCounts select _forEachIndex); -} forEach _magazineTypes; - -// Add the masses of backpack items in the object's inventory -getBackpackCargo _object params ["_backpackTypes", "_backpackCounts"]; - -{ - _weight = _weight + getNumber (_cfgVehicles >> _x >> "mass") * (_backpackCounts select _forEachIndex); -} forEach _backpackTypes; - -{ - _x params ["_weapon", "_muzzle", "_pointer", "_optic", "_primaryMagazine", "_secondaryMagazine", "_bipod"]; - - // Add the weapon's mass - _weight = _weight + getNumber (_cfgWeapons >> _weapon >> "WeaponSlotsInfo" >> "mass"); - - // Add the masses of the weapon's attachments if they exist - { - if (_x != "") then { - _weight = _weight + getNumber (_cfgWeapons >> _x >> "ItemInfo" >> "mass"); - }; - } forEach [_muzzle, _pointer, _optic, _bipod]; - - // Add the masses of the weapon's magazines if they exist - { - _x params ["_magazine"]; - - if (!isNil "_magazine") then { - _weight = _weight + getNumber (_cfgMagazines >> _magazine >> "mass"); - }; - } forEach [_primaryMagazine, _secondaryMagazine]; -} forEach weaponsItemsCargo _object; +private _weight = loadAbs _object; // Add the mass of the object itself -// The mass of sub-containers such as vests was added through the items cargo // The container object is generally of type SupplyX and has mass of zero -_weight = _weight + getNumber (_cfgVehicles >> typeOf _object >> "mass"); +_weight = _weight + getNumber (configOf _object >> "mass"); + +// Contents of backpacks get counted twice (see https://github.com/acemod/ACE3/pull/8457#issuecomment-1062522447) +// This is a workaround until that is fixed on BI's end +{ + _x params ["", "_container"]; + _weight = _weight - (loadAbs _container); +} forEach (everyContainer _object); // Mass in Arma isn't an exact amount but rather a volume/weight value // This attempts to work around that by making it a usable value (sort of) -// Note: this is done before the recursive calls to avoid reducing the weight multiple times -_weight = _weight * 0.5; - -// Handle sub-containers within the object's inventory -{ - _x params ["", "_container"]; - - _weight = _weight + (_container call FUNC(getWeight)); -} forEach everyContainer _object; - -_weight +_weight * 0.5;