ACE3/addons/cargo/functions/fnc_handleDestroyed.sqf

46 lines
1.2 KiB
Plaintext
Raw Permalink Normal View History

#include "..\script_component.hpp"
2015-08-10 21:07:47 +00:00
/*
* Author: mharis001, Glowbal
* 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:
* cursorObject call ace_cargo_fnc_handleDestroyed
2015-08-16 20:41:35 +00:00
*
2015-08-10 21:07:47 +00:00
* Public: No
*/
params ["_object"];
2015-08-10 21:07:47 +00:00
private _loaded = _object getVariable [QGVAR(loaded), []];
2015-08-10 21:07:47 +00:00
if (_loaded isNotEqualTo []) then {
// Delete all cargo
{
if (_x isEqualType objNull) then {
detach _x;
deleteVehicle _x;
};
} forEach _loaded;
2015-08-10 21:07:47 +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];
};