From 8bd064cd3b148e86e8d132acc31b4f860873087c Mon Sep 17 00:00:00 2001 From: Vdauphin Date: Fri, 1 Jun 2018 05:48:19 +0200 Subject: [PATCH] Cargo - Support of object without `ace_cargo_size` defined in config or `-1` config value (#6364) * Add: Now findUnloadPosition support also cargo object - use of ace_cargo_fnc_getSizeItem to determine size of item - prefer the config way instead of manually set size - This will also take into account object manually added to the cargo system with ace_cargo_fnc_setsize - use the cargo object for ace_cargo_fnc_unloadItem. * FIX: old work around * FIX: error when cargo module is not loaded * As suggested by @orbis2358 This fix handle the case when cargo module is not loaded for scheduled and unscheduled environnement. * Use ACE framework to check if module is present * FIX: EFUNC and isEqualto - _itemSize here is always number - here we are in common module (addons/common/functions/fnc_findUnloadPosition) so FUNC is ace_common_fnc * FIX case where config value is `-1` - if the config value is -1, get the `ace_cargo_size` from the `ace_cargo_fnc_getSizeItem - https://github.com/acemod/ACE3/issues/6357#issuecomment-393525374 --- addons/cargo/functions/fnc_unloadItem.sqf | 4 +--- .../functions/fnc_findUnloadPosition.sqf | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/addons/cargo/functions/fnc_unloadItem.sqf b/addons/cargo/functions/fnc_unloadItem.sqf index 702f145405f..f63e4367aa1 100644 --- a/addons/cargo/functions/fnc_unloadItem.sqf +++ b/addons/cargo/functions/fnc_unloadItem.sqf @@ -20,10 +20,8 @@ params ["_item", "_vehicle", ["_unloader", objNull]]; TRACE_3("params",_item,_vehicle,_unloader); -private _itemClass = if (_item isEqualType "") then {_item} else {typeOf _item}; - //This covers testing vehicle stability and finding a safe position -private _emptyPosAGL = [_vehicle, _itemClass, _unloader] call EFUNC(common,findUnloadPosition); +private _emptyPosAGL = [_vehicle, _item, _unloader] call EFUNC(common,findUnloadPosition); TRACE_1("findUnloadPosition",_emptyPosAGL); if ((count _emptyPosAGL) != 3) exitWith { diff --git a/addons/common/functions/fnc_findUnloadPosition.sqf b/addons/common/functions/fnc_findUnloadPosition.sqf index 85818cbda13..818b15a8645 100644 --- a/addons/common/functions/fnc_findUnloadPosition.sqf +++ b/addons/common/functions/fnc_findUnloadPosition.sqf @@ -5,7 +5,7 @@ * * Arguments: * 0: Source Vehicle - * 1: Cargo Classname + * 1: Cargo or * 2: Unloader (player) (default: objNull) * 3: Max Distance (meters) (default: 10) * 4: Check Vehicle is Stable (default: true) @@ -27,8 +27,8 @@ //Manual collision tests (count and radius): #define COL_TEST_COUNT 12 -params ["_vehicle", "_typeOfCargo", ["_theUnloader", objNull], ["_maxDistance", 10], ["_checkVehicleIsStable", true]]; -TRACE_5("params",_vehicle,_typeOfCargo,_theUnloader,_maxDistance,_checkVehicleIsStable); +params ["_vehicle", "_cargo", ["_theUnloader", objNull], ["_maxDistance", 10], ["_checkVehicleIsStable", true]]; +TRACE_5("params",_vehicle,_cargo,_theUnloader,_maxDistance,_checkVehicleIsStable); scopeName "main"; @@ -40,12 +40,22 @@ if (_checkVehicleIsStable) then { }; private _radiusOfItem = 1; -if (_typeOfCargo isKindOf "CAManBase") then { +if (_cargo isKindOf "CAManBase") then { _radiusOfItem = 1.1; } else { //`sizeOf` is unreliable, and does not work with object types that don't exist on map, so estimate size based on cargo size - if (isNumber (configFile >> "CfgVehicles" >> _typeOfCargo >> QEGVAR(cargo,size))) then { - _radiusOfItem = (((getNumber (configFile >> "CfgVehicles" >> _typeOfCargo >> QEGVAR(cargo,size))) ^ 0.35) max 0.75); + private _typeOfCargo = if (_cargo isEqualType "") then {_cargo} else {typeOf _cargo}; + private _itemSize = if (isNumber (configFile >> "CfgVehicles" >> _typeOfCargo >> QEGVAR(cargo,size)) && {getNumber (configFile >> "CfgVehicles" >> _typeOfCargo >> QEGVAR(cargo,size)) != -1}) then { + getNumber (configFile >> "CfgVehicles" >> _typeOfCargo >> QEGVAR(cargo,size)); + } else { + if (["ace_cargo"] call FUNC(isModLoaded)) then { + [_cargo] call EFUNC(cargo,getSizeItem); + } else { + _radiusOfItem; + }; + }; + if (_itemSize != -1) then { + _radiusOfItem = (_itemSize ^ 0.35) max 0.75; }; };