Cargo - Fix loaded cargo not being deleted when vehicle is destroyed (#7851)

This commit is contained in:
mharis001 2020-08-18 13:42:09 -04:00 committed by GitHub
parent c8bb046d31
commit 4d769e4b8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 12 deletions

View File

@ -16,11 +16,3 @@ class Extended_PostInit_EventHandlers {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};
class Extended_Killed_EventHandlers {
class All {
class ADDON {
serverKilled = QUOTE(call FUNC(handleDestroyed));
};
};
};

View File

@ -4,6 +4,7 @@ PREP(canLoadItemIn);
PREP(canUnloadItem);
PREP(getCargoSpaceLeft);
PREP(getSizeItem);
PREP(handleDeleted);
PREP(handleDestroyed);
PREP(initObject);
PREP(initVehicle);

View File

@ -13,4 +13,10 @@ GVAR(initializedVehicleClasses) = [];
GVAR(cargoHolderTypes) = ["Car", "Air", "Tank", "Ship", "Cargo_base_F", "Land_PaperBox_closed_F"];
GVAR(disableParadropEffectsClasstypes) = ["Car_F"];
if (isServer) then {
["All", "Deleted", LINKFUNC(handleDeleted)] call CBA_fnc_addClassEventHandler;
};
["All", "Killed", LINKFUNC(handleDestroyed)] call CBA_fnc_addClassEventHandler;
ADDON = true;

View File

@ -0,0 +1,25 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Handles an object being deleted by deleting all loaded cargo.
*
* Arguments:
* 0: Object <OBJECT>
*
* Return Value:
* None
*
* Example:
* [_object] call ace_cargo_fnc_handleDeleted
*
* Public: No
*/
params ["_object"];
{
if (_x isEqualType objNull) then {
detach _x;
deleteVehicle _x;
};
} forEach (_object getVariable [QGVAR(loaded), []]);

View File

@ -1,7 +1,7 @@
#include "script_component.hpp"
/*
* Author: Glowbal
* Handle object being destroyed. Only runs on server.
* Handle object being destroyed.
*
* Arguments:
* 0: Object <OBJECT>
@ -10,7 +10,7 @@
* None
*
* Example:
* [object] call ace_cargo_fnc_handleDestroyed
* [_object] call ace_cargo_fnc_handleDestroyed
*
* Public: No
*/
@ -24,9 +24,9 @@ if (_loaded isEqualTo []) exitWith {};
{
// TODO Do we want to be able to recover destroyed equipment?
if (_x isEqualType objNull) then {
detach _x;
deleteVehicle _x;
};
nil
} count _loaded;
} forEach _loaded;
[_vehicle] call FUNC(validateCargoSpace);