diff --git a/addons/cargo/XEH_PREP.hpp b/addons/cargo/XEH_PREP.hpp index 79351a1230..a23bff00aa 100644 --- a/addons/cargo/XEH_PREP.hpp +++ b/addons/cargo/XEH_PREP.hpp @@ -1,10 +1,12 @@ PREP(addCargoItem); PREP(addCargoVehiclesActions); +PREP(canItemCargo); PREP(canLoadItemIn); PREP(canShowUnloadAllVehicles); PREP(canUnloadItem); PREP(getCargoSpaceLeft); PREP(getSizeItem); +PREP(getSurfaceItem); PREP(getVehicleCargo); PREP(handleDeleted); PREP(handleDestroyed); diff --git a/addons/cargo/functions/fnc_canItemCargo.sqf b/addons/cargo/functions/fnc_canItemCargo.sqf new file mode 100644 index 0000000000..c46ea8afa4 --- /dev/null +++ b/addons/cargo/functions/fnc_canItemCargo.sqf @@ -0,0 +1,37 @@ +#include "script_component.hpp" +/* + * Author: Vdauphin + * Check if an item will fit in the empty space already used by loaded items. + * + * Arguments: + * 0: Vehicle + * 1: Item + * 2: Items from vehicle cargo + * + * Return Value: + * Will fit or not the space occupied by items + * + * Example: + * [] call ace_cargo_fnc_canItemCargo + * + * Public: No + */ + +params [ + "_vehicle", + "_item", + ["_items", [], [[]]] +]; + +if ( + _items isEqualTo [] || + {!((_vehicle canVehicleCargo _item) select 1)} +) exitWith {false}; + +private _itemSurface = [_item] call FUNC(getSurfaceItem); +private _itemsSurface = 0; +{ + _itemsSurface = _itemsSurface + ([_item] call FUNC(getSurfaceItem)); +} forEach _items; + +_itemSurface <= _itemsSurface diff --git a/addons/cargo/functions/fnc_getSurfaceItem.sqf b/addons/cargo/functions/fnc_getSurfaceItem.sqf new file mode 100644 index 0000000000..ad110ba2dd --- /dev/null +++ b/addons/cargo/functions/fnc_getSurfaceItem.sqf @@ -0,0 +1,26 @@ +#include "script_component.hpp" +/* + * Author: Vdauphin + * Get surface of an item. + * + * Arguments: + * 0: Object + * + * Return Value: + * Surface in m² + * + * Example: + * [player] call ace_cargo_fnc_getSurfaceItem + * + * Public: No + */ + +params ["_object"]; + +private _bbr = 0 boundingBoxReal _object; +private _p1 = _bbr select 0; +private _p2 = _bbr select 1; +private _width = abs ((_p2 select 0) - (_p1 select 0)); +private _length = abs ((_p2 select 1) - (_p1 select 1)); + +_width * _length diff --git a/addons/cargo/functions/fnc_getVehicleCargo.sqf b/addons/cargo/functions/fnc_getVehicleCargo.sqf index 17a3713fb6..43dc6edc70 100644 --- a/addons/cargo/functions/fnc_getVehicleCargo.sqf +++ b/addons/cargo/functions/fnc_getVehicleCargo.sqf @@ -18,5 +18,5 @@ params ["_vehicle"]; (getVehicleCargo _vehicle - (_vehicle getVariable [QGVAR(loaded), []])) select { - !(_x getVariable [QGVAR(isCargoNet), false]) + !(_x getVariable [QGVAR(isCargoNet), false]) } diff --git a/addons/cargo/functions/fnc_loadItem.sqf b/addons/cargo/functions/fnc_loadItem.sqf index 1077765e86..88d9e9047c 100644 --- a/addons/cargo/functions/fnc_loadItem.sqf +++ b/addons/cargo/functions/fnc_loadItem.sqf @@ -36,39 +36,30 @@ _vehicle setVariable [QGVAR(space), _space - _itemSize, true]; if (_item isEqualType objNull) then { detach _item; if !(_vehicle setVehicleCargo _item) then { - private _vehicleCargo = getVehicleCargo _vehicle; - if ( - (_vehicle canVehicleCargo _item) isEqualTo [false, true] && // Could be loaded if _vehicle was empty - {_vehicleCargo findIf { - !(_x in _loaded) && // Don't use ViV if ViV was used outside of ACE Cargo - !(_x getVariable [QGVAR(isCargoNet), false]) - } isEqualTo -1} - ) then { - private _cargoNet = createVehicle ["CargoNet_01_box_F", [0, 0, 0], [], 0, "CAN_COLLIDE"]; - if ((_vehicle canVehicleCargo _cargoNet) select 1) then { - while {!(_vehicle setVehicleCargo _cargoNet)} do { // Move ViV cargo to ACE Cargo - private _itemViV = _vehicleCargo deleteAt 0; - if (_itemViV getVariable [QGVAR(isCargoNet), false]) exitWith { // The vehicle is already full of cargo net - deleteVehicle _cargoNet; - _item setVariable [QGVAR(cargoNet), _itemViV, true]; - }; - if !(objNull setVehicleCargo _itemViV) exitWith {deleteVehicle _cargoNet;}; + private _itemsCargo = _loaded arrayIntersect getVehicleCargo _vehicle; + private _cargoNet = createVehicle ["CargoNet_01_box_F", [0, 0, 0], [], 0, "CAN_COLLIDE"]; + if ([_vehicle, _cargoNet, _itemsCargo] call FUNC(canItemCargo)) then { + while {!(_vehicle setVehicleCargo _cargoNet)} do { // Move ViV cargo to ACE Cargo + if (_itemsCargo isEqualTo []) exitWith {deleteVehicle _cargoNet; /*Should not happen*/}; + private _itemViV = _itemsCargo deleteAt 0; - _itemViV setVariable [QGVAR(cargoNet), _cargoNet, true]; - _itemViV attachTo [_vehicle, [0,0,-100]]; - [QEGVAR(common,hideObjectGlobal), [_itemViV, true]] call CBA_fnc_serverEvent; + if !(objNull setVehicleCargo _itemViV) exitWith {deleteVehicle _cargoNet;}; - // Some objects below water will take damage over time and eventualy become "water logged" and unfixable (because of negative z attach) - [_itemViV, "blockDamage", "ACE_cargo", true] call EFUNC(common,statusEffect_set); - }; - if !(isNull _cargoNet) then { - _cargoNet setVariable [QGVAR(isCargoNet), true, true]; - _item setVariable [QGVAR(cargoNet), _cargoNet, true]; - }; - } else { - deleteVehicle _cargoNet; + _itemViV setVariable [QGVAR(cargoNet), _cargoNet, true]; + _itemViV attachTo [_vehicle, [0,0,-100]]; + [QEGVAR(common,hideObjectGlobal), [_itemViV, true]] call CBA_fnc_serverEvent; + + // Some objects below water will take damage over time and eventualy become "water logged" and unfixable (because of negative z attach) + [_itemViV, "blockDamage", "ACE_cargo", true] call EFUNC(common,statusEffect_set); }; + } else { + deleteVehicle _cargoNet; }; + if !(isNull _cargoNet) then { + _cargoNet setVariable [QGVAR(isCargoNet), true, true]; + _item setVariable [QGVAR(cargoNet), _cargoNet, true]; + }; + _item attachTo [_vehicle, [0,0,-100]]; [QEGVAR(common,hideObjectGlobal), [_item, true]] call CBA_fnc_serverEvent;