Skip to content

Commit

Permalink
Cargo - Support of object without ace_cargo_size defined in config …
Browse files Browse the repository at this point in the history
…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
-
 #6357 (comment)
  • Loading branch information
Vdauphin authored and PabstMirror committed Jun 1, 2018
1 parent 655600b commit 8bd064c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 1 addition & 3 deletions addons/cargo/functions/fnc_unloadItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 16 additions & 6 deletions addons/common/functions/fnc_findUnloadPosition.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* Arguments:
* 0: Source Vehicle <OBJECT>
* 1: Cargo Classname <STRING>
* 1: Cargo <OBJECT> or <STRING>
* 2: Unloader (player) <OBJECT> (default: objNull)
* 3: Max Distance (meters) <NUMBER> (default: 10)
* 4: Check Vehicle is Stable <BOOL> (default: true)
Expand All @@ -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";

Expand All @@ -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;
};
};

Expand Down

0 comments on commit 8bd064c

Please sign in to comment.