From bdea0fcdbab53d4d5a5d67652f41d37733523447 Mon Sep 17 00:00:00 2001 From: Zakant Date: Sun, 18 Jun 2017 01:28:16 +0200 Subject: [PATCH] [Medical Rewrite] Adding respawn compatibility (#5020) * Added respawn transition * Removed respawn transition from statemachine and added manual transition comment * Changed transiton to manual. Added easy way to get current status as well * Updated event reference * Fixed manualTransition call * Minor headers changes --- addons/medical/ACE_Medical_StateMachine.hpp | 2 ++ addons/medical/CfgEventHandlers.hpp | 8 +++++++ addons/medical/XEH_PREP.hpp | 2 ++ addons/medical/functions/fnc_getUnitState.sqf | 22 +++++++++++++++++ .../medical/functions/fnc_handleRespawn.sqf | 24 +++++++++++++++++++ 5 files changed, 58 insertions(+) create mode 100644 addons/medical/functions/fnc_getUnitState.sqf create mode 100644 addons/medical/functions/fnc_handleRespawn.sqf diff --git a/addons/medical/ACE_Medical_StateMachine.hpp b/addons/medical/ACE_Medical_StateMachine.hpp index 3e9848ef6f..b2e676b143 100644 --- a/addons/medical/ACE_Medical_StateMachine.hpp +++ b/addons/medical/ACE_Medical_StateMachine.hpp @@ -1,3 +1,5 @@ +// Manual transitions applied to this statemachine +// - medical_fnc_handleRespawn:18 class ACE_Medical_StateMachine { list = "allUnits select {local _x}"; skipNull = 1; diff --git a/addons/medical/CfgEventHandlers.hpp b/addons/medical/CfgEventHandlers.hpp index a6ea04545c..604cb0783a 100644 --- a/addons/medical/CfgEventHandlers.hpp +++ b/addons/medical/CfgEventHandlers.hpp @@ -23,3 +23,11 @@ class Extended_Init_EventHandlers { }; }; }; + +class Extended_Respawn_EventHandlers { + class CAManBase { + class ADDON { + respawn = QUOTE(call FUNC(handleRespawn)); + }; + }; +}; diff --git a/addons/medical/XEH_PREP.hpp b/addons/medical/XEH_PREP.hpp index 9c40ee1b2b..daf0727054 100644 --- a/addons/medical/XEH_PREP.hpp +++ b/addons/medical/XEH_PREP.hpp @@ -15,9 +15,11 @@ PREP(getBloodPressure); PREP(getBloodVolumeChange); PREP(getCardiacOutput); PREP(getPainLevel); +PREP(getUnitState); PREP(handleIncapacitation); PREP(handleKilled); PREP(handleLocal); +PREP(handleRespawn); PREP(handleStateDefault); PREP(handleStateInjured); PREP(handleStateUnconscious); diff --git a/addons/medical/functions/fnc_getUnitState.sqf b/addons/medical/functions/fnc_getUnitState.sqf new file mode 100644 index 0000000000..6821124e32 --- /dev/null +++ b/addons/medical/functions/fnc_getUnitState.sqf @@ -0,0 +1,22 @@ +/* + * Author: Zakant + * Gets the name of the current medical state of an unit. Unit has to be local to the caller. + * + * Arguments: + * 0: The Unit + * + * Return Value: + * Name of the current medical state of the unit + * + * Example: + * [player] call ace_medical_fnc_getUnitState + * + * Public: Yes + */ +#include "script_component.hpp" + +params ["_unit"]; + +if (!local _unit) exitWith { ERROR("unit is not local"); }; + +[_unit, GVAR(STATE_MACHINE)] call CBA_statemachine_fnc_getCurrentState diff --git a/addons/medical/functions/fnc_handleRespawn.sqf b/addons/medical/functions/fnc_handleRespawn.sqf new file mode 100644 index 0000000000..db2dfe2945 --- /dev/null +++ b/addons/medical/functions/fnc_handleRespawn.sqf @@ -0,0 +1,24 @@ +/* + * Author: Zakant + * Handles respawn of a unit. + * + * Arguments: + * 0: The Unit + * + * Return Value: + * None + * + * Example: + * [player] call ace_medical_fnc_handleRespawn + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit"]; +TRACE_2("handleRespawn",_unit,local _unit); + +if (!local _unit) exitWith {}; + +_unit call FUNC(init); // Call init to reset the medical states for the unit. +[_unit, GVAR(STATE_MACHINE), _unit call FUNC(getUnitState), "Default"] call CBA_statemachine_fnc_manualTransition; // Move the unit to the default medical state