2016-06-30 21:43:25 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
|
|
|
// Delay between state runs
|
2016-07-07 09:46:55 +00:00
|
|
|
#define DELAY 1
|
2016-07-02 14:34:28 +00:00
|
|
|
#define DEFAULT_STATE [0, "Default", {}, {}, {}, []]
|
2016-06-30 21:43:25 +00:00
|
|
|
|
|
|
|
GVAR(monitoredUnitsList) = [];
|
|
|
|
GVAR(monitoredUnitsListIsSorted) = false;
|
|
|
|
|
|
|
|
[{
|
|
|
|
params ["_args", "_pfhId"];
|
|
|
|
|
|
|
|
if (!GVAR(monitoredUnitsListIsSorted)) then {
|
|
|
|
GVAR(monitoredUnitsList) sort true;
|
|
|
|
GVAR(monitoredUnitsListIsSorted) = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
private _delete = false;
|
|
|
|
private _exit = false;
|
|
|
|
{
|
|
|
|
_x params ["_unit"];
|
|
|
|
|
2016-07-02 14:34:28 +00:00
|
|
|
if (!isNull _unit && alive _unit) then {
|
2016-07-07 15:22:08 +00:00
|
|
|
private _unitState = _unit getVariable [QGVAR(state), [CBA_missionTime, DEFAULT_STATE]];
|
2016-06-30 21:43:25 +00:00
|
|
|
_unitState params ["_lastTime", "_state"];
|
|
|
|
|
|
|
|
if ((_lastTime + DELAY) > CBA_missionTime) exitWith {_exit = true;};
|
|
|
|
_state params ["_name", "_handler", "_onEntry", "_onExit", "_transitions"];
|
|
|
|
_unitState set [0, CBA_missionTime];
|
|
|
|
|
|
|
|
_unit setvariable [QGVAR(state), _unitState];
|
|
|
|
|
2016-07-07 09:46:55 +00:00
|
|
|
[_unit, _name, _lastTime] call _handler;
|
2016-06-30 21:43:25 +00:00
|
|
|
} else {
|
|
|
|
_delete = true;
|
|
|
|
GVAR(monitoredUnitsList) set [_forEachIndex, objNull];
|
|
|
|
};
|
2016-07-07 10:04:26 +00:00
|
|
|
if (_exit) exitWith {};
|
2016-06-30 21:43:25 +00:00
|
|
|
} forEach GVAR(monitoredUnitsList);
|
|
|
|
|
|
|
|
if (_delete) then {
|
|
|
|
GVAR(monitoredUnitsList) = GVAR(monitoredUnitsList) - [objNull];
|
|
|
|
};
|
|
|
|
}, 0, []] call CBA_fnc_addPerFrameHandler;
|