diff --git a/addons/cargo/functions/fnc_canItemCargo.sqf b/addons/cargo/functions/fnc_canItemCargo.sqf index c46ea8afa4..c248822cc9 100644 --- a/addons/cargo/functions/fnc_canItemCargo.sqf +++ b/addons/cargo/functions/fnc_canItemCargo.sqf @@ -1,37 +1,32 @@ -#include "script_component.hpp" +#include "..\script_component.hpp" /* * Author: Vdauphin - * Check if an item will fit in the empty space already used by loaded items. + * Checks if an item would fit in the space currently used by loaded items. * * Arguments: - * 0: Vehicle - * 1: Item + * 0: Item + * 1: Vehicle * 2: Items from vehicle cargo * * Return Value: - * Will fit or not the space occupied by items + * Ig the item would fit or not * * Example: - * [] call ace_cargo_fnc_canItemCargo + * ["ACE_Wheel", cursorObject, []] call ace_cargo_fnc_canItemCargo * * Public: No */ -params [ - "_vehicle", - "_item", - ["_items", [], [[]]] -]; +params ["_item", "_vehicle", "_items"]; -if ( - _items isEqualTo [] || - {!((_vehicle canVehicleCargo _item) select 1)} -) exitWith {false}; +// If there are no items or if the item can't fit in the vehicle when empty, skip +if (_items isEqualTo [] || {!((_vehicle canVehicleCargo _item) select 1)}) exitWith {false}; -private _itemSurface = [_item] call FUNC(getSurfaceItem); +private _itemSurface = _item call FUNC(getSurfaceItem); private _itemsSurface = 0; + { - _itemsSurface = _itemsSurface + ([_item] call FUNC(getSurfaceItem)); + _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 index ad110ba2dd..761157b42c 100644 --- a/addons/cargo/functions/fnc_getSurfaceItem.sqf +++ b/addons/cargo/functions/fnc_getSurfaceItem.sqf @@ -1,7 +1,7 @@ -#include "script_component.hpp" +#include "..\script_component.hpp" /* * Author: Vdauphin - * Get surface of an item. + * Gets surface of an item. * * Arguments: * 0: Object @@ -10,7 +10,7 @@ * Surface in m² * * Example: - * [player] call ace_cargo_fnc_getSurfaceItem + * cursorObject call ace_cargo_fnc_getSurfaceItem * * Public: No */ diff --git a/addons/cargo/functions/fnc_loadItem.sqf b/addons/cargo/functions/fnc_loadItem.sqf index ab019f53ce..2930075d2a 100644 --- a/addons/cargo/functions/fnc_loadItem.sqf +++ b/addons/cargo/functions/fnc_loadItem.sqf @@ -47,18 +47,30 @@ _vehicle setVariable [QGVAR(space), _cargoSpace - _itemSize, true]; if (_item isEqualType objNull) then { detach _item; + // If the object couldn't be loaded as ViV, try to compact the existing ViV cargo if !(_vehicle setVehicleCargo _item) then { - private _itemsCargo = _loaded arrayIntersect getVehicleCargo _vehicle; + private _itemsViVCargo = _loaded arrayIntersect (getVehicleCargo _vehicle); private _cargoNet = createVehicle [GVAR(cargoNetType), [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; - if !(objNull setVehicleCargo _itemViV) exitWith {deleteVehicle _cargoNet;}; + if ([_cargoNet, _vehicle, _itemsViVCargo] call FUNC(canItemCargo)) then { + // Move ViV cargo to ACE Cargo + while {!(_vehicle setVehicleCargo _cargoNet)} do { + if (_itemsViVCargo isEqualTo []) exitWith { + // Should not happen + deleteVehicle _cargoNet; + }; + private _itemViV = _itemsViVCargo deleteAt 0; + + // If the ViV object couldn't be unloaded, quit + if !(objNull setVehicleCargo _itemViV) exitWith { + deleteVehicle _cargoNet; + }; + + // If the ViV object was unloaded, store it as regular cargo _itemViV setVariable [QGVAR(cargoNet), _cargoNet, true]; - _itemViV attachTo [_vehicle, [0,0,-100]]; + _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) @@ -67,7 +79,8 @@ if (_item isEqualType objNull) then { } else { deleteVehicle _cargoNet; }; - if !(isNull _cargoNet) then { + + if (!isNull _cargoNet) then { _cargoNet setVariable [QGVAR(isCargoNet), true, true]; _item setVariable [QGVAR(cargoNet), _cargoNet, true]; }; @@ -85,7 +98,7 @@ if (_item isEqualType objNull) then { [QEGVAR(zeus,removeObjects), [[_item], _objectCurators]] call CBA_fnc_serverEvent; }; - + // Some objects below water will take damage over time, eventually becoming "water logged" and unfixable (because of negative z attach) [_item, "blockDamage", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); }; diff --git a/addons/cargo/functions/fnc_unload.sqf b/addons/cargo/functions/fnc_unload.sqf index 2bf7e7ec76..71b48df23f 100644 --- a/addons/cargo/functions/fnc_unload.sqf +++ b/addons/cargo/functions/fnc_unload.sqf @@ -1,4 +1,4 @@ -#include "script_component.hpp" +#include "..\script_component.hpp" /* * Author: Glowbal, ViperMaul * Unload object from vehicle. @@ -8,9 +8,10 @@ * 1: Vehicle with the item loaded * 2: Unloading position * 3: If the object was deployed + * 4: Object's direction, used when deployed * * Return Value: - * Object unloaded + * Object that was unloaded * * Example: * ["ACE_Wheel", cursorObject, getPos player, false] call ace_cargo_fnc_unload @@ -18,7 +19,7 @@ * Public: No */ -params ["_item", "_posAGL", "_vehicle", "_deployed"]; +params ["_item", "_vehicle", "_posAGL", "_deployed", "_direction"]; // Unload item from cargo private _loaded = _vehicle getVariable [QGVAR(loaded), []]; @@ -27,7 +28,7 @@ _vehicle setVariable [QGVAR(loaded), _loaded, true]; // Update cargo space remaining private _cargoSpace = _vehicle call FUNC(getCargoSpaceLeft); -_vehicle setVariable [QGVAR(space), _cargoSpace + _itemSize, true]; +_vehicle setVariable [QGVAR(space), _cargoSpace + (_item call FUNC(getSizeItem)), true]; private _object = _item; @@ -37,9 +38,9 @@ if (_object isEqualType objNull) then { // If player unloads via deployment, set direction first, then unload if (_deployed) then { - [QGVAR(setDirAndUnload), [_object, _emptyPosAGL, _direction], _object] call CBA_fnc_targetEvent; + [QGVAR(setDirAndUnload), [_object, _posAGL, _direction], _object] call CBA_fnc_targetEvent; } else { - [QGVAR(serverUnload), [_object, _emptyPosAGL]] call CBA_fnc_serverEvent; + [QGVAR(serverUnload), [_object, _posAGL]] call CBA_fnc_serverEvent; }; if (["ace_zeus"] call EFUNC(common,isModLoaded)) then { @@ -52,28 +53,28 @@ if (_object isEqualType objNull) then { }; private _cargoNet = _object getVariable [QGVAR(cargoNet), objNull]; - if !(isNull _cargoNet) then { - private _itemsRemaining = _loaded select { - _x getVariable [QGVAR(cargoNet), objNull] isEqualTo _cargoNet - }; - if (_itemsRemaining isEqualTo []) then { - objNull setVehicleCargo _cargoNet; - deleteVehicle _cargoNet; - }; + + // Delete cargo net if no items remain on it + if ( + !isNull _cargoNet && + {(_loaded findIf {_x isEqualType objNull && {_x getVariable [QGVAR(cargoNet), objNull] == _cargoNet}}) == -1} + ) then { + objNull setVehicleCargo _cargoNet; + deleteVehicle _cargoNet; }; } else { objNull setVehicleCargo _object; _object setPosASL (AGLtoASL _posAGL); }; } else { - _object = createVehicle [_item, _emptyPosAGL, [], 0, "NONE"]; + _object = createVehicle [_item, _posAGL, [], 0, "NONE"]; // If player unloads via deployment, set direction. Must happen before setPosASL command according to wiki if (_deployed) then { _object setDir _direction; }; - _object setPosASL (AGLtoASL _emptyPosAGL); + _object setPosASL (AGLtoASL _posAGL); [QEGVAR(common,fixCollision), _object] call CBA_fnc_localEvent; [QEGVAR(common,fixPosition), _object] call CBA_fnc_localEvent; diff --git a/addons/cargo/functions/fnc_unloadItem.sqf b/addons/cargo/functions/fnc_unloadItem.sqf index 5feb3dc631..b51c711130 100644 --- a/addons/cargo/functions/fnc_unloadItem.sqf +++ b/addons/cargo/functions/fnc_unloadItem.sqf @@ -8,8 +8,8 @@ * 1: Holder object (vehicle) (default: objNull) * 2: Unloader (default: objNull) * 3: Deploy parameters (default: []) - * - 0: Position AGL - * - 1: Direction + * - 0: Position AGL (default: []) + * - 1: Direction (default: 0) * * Return Value: * Object unloaded @@ -20,8 +20,8 @@ * Public: Yes */ -params [["_item", "", [objNull, ""]], ["_vehicle", objNull, [objNull]], ["_unloader", objNull, [objNull]], ["_deploy", []]]; -_deploy params ["_emptyPosAGL", "_direction"]; +params [["_item", "", [objNull, ""]], ["_vehicle", objNull, [objNull]], ["_unloader", objNull, [objNull]], ["_deploy", [], [[]]]]; +_deploy params [["_emptyPosAGL", [], [[]], 3], ["_direction", 0, [0]]]; TRACE_4("params",_item,_vehicle,_unloader,_deploy); @@ -68,7 +68,7 @@ if (_emptyPosAGL isEqualTo []) exitWith { false // return }; -private _object = [_item, _vehicle, _emptyPosAGL, _deployed] call FUNC(unload); +private _object = [_item, _vehicle, _emptyPosAGL, _deployed, _direction] call FUNC(unload); // Dragging integration if (!_deployed) then {