2023-09-12 18:58:10 +00:00
#include "..\script_component.hpp"
2015-08-10 21:07:47 +00:00
/*
2024-05-27 06:19:33 +00:00
* Author: mharis001, Glowbal, drofseh
2023-11-17 23:07:28 +00:00
* Handles an object being destroyed/deleted.
* If object contained loaded cargo, the cargo is deleted.
* If object was loaded cargo, it's removed from loaded cargo list.
2015-08-10 21:07:47 +00:00
*
* Arguments:
* 0: Object <OBJECT>
*
2016-06-18 09:50:41 +00:00
* Return Value:
2015-08-10 21:07:47 +00:00
* None
*
2015-08-16 20:41:35 +00:00
* Example:
2023-11-17 23:07:28 +00:00
* cursorObject call ace_cargo_fnc_handleDestroyed
2015-08-16 20:41:35 +00:00
*
2015-08-10 21:07:47 +00:00
* Public: No
*/
2023-11-17 23:07:28 +00:00
params ["_object"];
2015-08-10 21:07:47 +00:00
2024-05-27 06:19:33 +00:00
private _killed = false;
if (count _this > 1) then {_killed = true}; // The Killed event has 4 params. The Deleted event only has 1 param.
2023-11-17 23:07:28 +00:00
private _loaded = _object getVariable [QGVAR(loaded), []];
2015-08-10 21:07:47 +00:00
2023-11-17 23:07:28 +00:00
if (_loaded isNotEqualTo []) then {
// Delete all cargo
{
if (_x isEqualType objNull) then {
2024-05-27 06:50:53 +00:00
private _delete = true;
2024-05-27 06:19:33 +00:00
if (_killed && {random 100 < GVAR(unloadOnKilled)}) then {
2024-05-27 06:50:53 +00:00
_delete = !([_x, _object] call ace_cargo_fnc_unloadItem); // If a safe position to unload cannot be found fnc_unloadItem returns false, delete cargo instead
};
if (_delete) then {
2024-05-27 06:19:33 +00:00
detach _x;
deleteVehicle _x;
};
2023-11-17 23:07:28 +00:00
};
2024-05-27 06:50:53 +00:00
} forEachReversed _loaded;
2015-08-10 21:07:47 +00:00
2023-11-17 23:07:28 +00:00
// In case vehicle is killed, but not deleted, reset loaded list
_object setVariable [QGVAR(loaded), [], true];
};
// Update remaining cargo space, if loaded as cargo in a vehicle
private _vehicle = attachedTo _object;
if (!isNull _vehicle && {_object in (_vehicle getVariable [QGVAR(loaded), []])}) then {
private _cargoSpace = _vehicle call FUNC(getCargoSpaceLeft);
private _itemSize = (_object call FUNC(getSizeItem)) max 0; // don't let negative size items increase space
_vehicle setVariable [QGVAR(space), _cargoSpace + _itemSize, true];
};