From 24846e6f7450fdb9da1d938a139ba5a5f54c6214 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Sat, 25 Aug 2018 16:40:22 +0100 Subject: [PATCH] Make state change status updates consistent (#6538) State transitions call respective functions in the status component where unit variables and status are actually handled. --- addons/medical_statemachine/Statemachine.hpp | 4 +- .../fnc_enteredStateCardiacArrest.sqf | 6 ++- .../functions/fnc_enteredStateDeath.sqf | 7 +-- .../functions/fnc_leftStateCardiacArrest.sqf | 12 +++-- addons/medical_status/XEH_PREP.hpp | 2 +- .../functions/fnc_setCardiacArrest.sqf | 24 ++++----- .../medical_status/functions/fnc_setDead.sqf | 12 ++--- .../functions/fnc_setUnconscious.sqf | 47 ++++++++++++++++++ .../fnc_setUnconsciousStatemachine.sqf | 49 ------------------- 9 files changed, 82 insertions(+), 81 deletions(-) create mode 100644 addons/medical_status/functions/fnc_setUnconscious.sqf delete mode 100644 addons/medical_status/functions/fnc_setUnconsciousStatemachine.sqf diff --git a/addons/medical_statemachine/Statemachine.hpp b/addons/medical_statemachine/Statemachine.hpp index e99649c06e..32196dbd3a 100644 --- a/addons/medical_statemachine/Statemachine.hpp +++ b/addons/medical_statemachine/Statemachine.hpp @@ -44,7 +44,7 @@ class ACE_Medical_StateMachine { }; class Unconscious { onState = QFUNC(handleStateUnconscious); - onStateEntered = QUOTE([ARR_2(_this,(true))] call EFUNC(medical_status,setUnconsciousStatemachine)); + onStateEntered = QUOTE([ARR_2(_this,(true))] call EFUNC(medical_status,setUnconscious)); class DeathAI { targetState = "Dead"; condition = QUOTE(!isPlayer _this && {GVAR(unconsciousConditionAI)}); @@ -53,7 +53,7 @@ class ACE_Medical_StateMachine { targetState = "Injured"; condition = QEFUNC(medical_status,hasStableVitals); events[] = {QEGVAR(medical,WakeUp)}; - onTransition = QUOTE([ARR_2(_this,(false))] call EFUNC(medical_status,setUnconsciousStatemachine)); + onTransition = QUOTE([ARR_2(_this,(false))] call EFUNC(medical_status,setUnconscious)); }; class FatalTransitions { targetState = "CardiacArrest"; diff --git a/addons/medical_statemachine/functions/fnc_enteredStateCardiacArrest.sqf b/addons/medical_statemachine/functions/fnc_enteredStateCardiacArrest.sqf index 077294793b..408367b6b6 100644 --- a/addons/medical_statemachine/functions/fnc_enteredStateCardiacArrest.sqf +++ b/addons/medical_statemachine/functions/fnc_enteredStateCardiacArrest.sqf @@ -1,7 +1,8 @@ #include "script_component.hpp" /* * Author: BaerMitUmlaut - * Handles a unit entering cardiac arrest. + * Handles a unit entering cardiac arrest (calls for a status update). + * Sets required variables for countdown timer until death. * * Arguments: * 0: The Unit @@ -21,4 +22,5 @@ _time = _time + random [_time*-0.1, 0, _time*0.1]; _unit setVariable [QGVAR(cardiacArrestTime), _time]; _unit setVariable [QGVAR(cardiacArrestStart), CBA_missionTime]; -[_unit] call EFUNC(medical_status,setCardiacArrest); +// Update the unit status to reflect cardiac arrest +[_unit, true] call EFUNC(medical_status,setCardiacArrest); diff --git a/addons/medical_statemachine/functions/fnc_enteredStateDeath.sqf b/addons/medical_statemachine/functions/fnc_enteredStateDeath.sqf index 7ec96bd43a..3e536ee463 100644 --- a/addons/medical_statemachine/functions/fnc_enteredStateDeath.sqf +++ b/addons/medical_statemachine/functions/fnc_enteredStateDeath.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: SilentSpike - * Handles a unit reaching the point of death. + * Handles a unit reaching the point of death (calls for a status update). * * Arguments: * 0: The Unit @@ -19,7 +19,4 @@ params ["_unit"]; // Send a local event before death [QEGVAR(medical,death), [_unit]] call CBA_fnc_localEvent; -_unit setVariable [VAR_HEART_RATE, 0, true]; -_unit setVariable [VAR_BLOOD_PRESS, [0, 0], true]; - -_unit setDamage 1; +[_unit] call EFUNC(medical_status,setDead); diff --git a/addons/medical_statemachine/functions/fnc_leftStateCardiacArrest.sqf b/addons/medical_statemachine/functions/fnc_leftStateCardiacArrest.sqf index 642fc66f47..160cc6a827 100644 --- a/addons/medical_statemachine/functions/fnc_leftStateCardiacArrest.sqf +++ b/addons/medical_statemachine/functions/fnc_leftStateCardiacArrest.sqf @@ -1,7 +1,8 @@ #include "script_component.hpp" /* - * Author: BaerMitUmlaut - * Handles a unit entering cardiac arrest. + * Author: RedBery + * Handles a unit leaving cardiac arrest (calls for a status update). + * Clears countdown timer variables. * * Arguments: * 0: The Unit @@ -14,7 +15,10 @@ params ["_unit"]; -_unit setVariable [VAR_CRDC_ARRST, false, true]; +_unit setVariable [QGVAR(cardiacArrestTime), nil]; _unit setVariable [QEGVAR(medical,cardiacArrestStart), nil]; -_unit setVariable [VAR_HEART_RATE, 40, true]; + +// Temporary fix for vitals loop on cardiac arrest exit _unit setVariable [QGVAR(lastTimeUpdated), CBA_missionTime]; + +[_unit, false] call EFUNC(medical_status,setCardiacArrest); diff --git a/addons/medical_status/XEH_PREP.hpp b/addons/medical_status/XEH_PREP.hpp index d0c3f743d5..3b74368c2a 100644 --- a/addons/medical_status/XEH_PREP.hpp +++ b/addons/medical_status/XEH_PREP.hpp @@ -11,4 +11,4 @@ PREP(isBeingDragged); PREP(isInStableCondition); PREP(setCardiacArrest); PREP(setDead); -PREP(setUnconsciousStatemachine); +PREP(setUnconscious); diff --git a/addons/medical_status/functions/fnc_setCardiacArrest.sqf b/addons/medical_status/functions/fnc_setCardiacArrest.sqf index 4b09736698..32c858b36d 100644 --- a/addons/medical_status/functions/fnc_setCardiacArrest.sqf +++ b/addons/medical_status/functions/fnc_setCardiacArrest.sqf @@ -1,8 +1,8 @@ #include "script_component.hpp" /* * Author: Glowbal - * Triggers a unit into the Cardiac Arrest state from CMS. Will put the unit in an unconscious state and run a countdown timer until unit dies. - * Timer is a random value between 120 and 720 seconds. + * Marks a unit as in cardiac arrest and sets heart rate to 0. + * Will put the unit in an unconscious state if not already. * * Arguments: * 0: The unit that will be put in cardiac arrest state @@ -10,19 +10,19 @@ * Return Value: * None * - * Example: - * [bob] call ace_medical_fnc_setCardiacArrest - * - * Public: yes + * Public: No */ -params ["_unit"]; +params ["_unit", "_active"]; -if IN_CRDC_ARRST(_unit) exitWith {}; +// No change to make +if (_active isEqualTo IN_CRDC_ARRST(_unit)) exitWith {}; -_unit setVariable [VAR_CRDC_ARRST, true, true]; -_unit setVariable [VAR_HEART_RATE, 0, true]; +// No heart rate in cardiac arrest, low heart rate if revived +_unit setVariable [VAR_CRDC_ARRST, _active, true]; +_unit setVariable [VAR_HEART_RATE, [40, 0] select _active, true]; -["ace_cardiacArrestEntered", [_unit]] call CBA_fnc_localEvent; +// Cardiac arrest is an extension of unconsciousness +[_unit, _active] call FUNC(setUnconscious); -[_unit, true] call FUNC(setUnconsciousStatemachine); +["ace_cardiacArrest", [_unit, _active]] call CBA_fnc_localEvent; diff --git a/addons/medical_status/functions/fnc_setDead.sqf b/addons/medical_status/functions/fnc_setDead.sqf index 3526c65f68..12a07cd617 100644 --- a/addons/medical_status/functions/fnc_setDead.sqf +++ b/addons/medical_status/functions/fnc_setDead.sqf @@ -10,17 +10,17 @@ * Return Value: * None * - * Example: - * [bob, "bloodloss"] call ace_medical_status_fnc_setDead; - * * Public: No */ params ["_unit", ["_reason", "unknown"]]; -// wait a frame to escape handleDamage -// @TODO Test if this is still necessary -[EFUNC(medical_engine,setStructuralDamage), [_unit, 1]] call CBA_fnc_execNextFrame; +// No heart rate or blood pressure to measure when dead +_unit setVariable [VAR_HEART_RATE, 0, true]; +_unit setVariable [VAR_BLOOD_PRESS, [0, 0], true]; + +// Kill the unit without changing visual apperance +[_unit, 1] call EFUNC(medical_engine,setStructuralDamage); private _lastShooter = _unit getVariable [QEGVAR(medical_engine,lastShooter), objNull]; private _lastInstigator = _unit getVariable [QEGVAR(medical_engine,lastInstigator), objNull]; diff --git a/addons/medical_status/functions/fnc_setUnconscious.sqf b/addons/medical_status/functions/fnc_setUnconscious.sqf new file mode 100644 index 0000000000..26d74fca10 --- /dev/null +++ b/addons/medical_status/functions/fnc_setUnconscious.sqf @@ -0,0 +1,47 @@ +#include "script_component.hpp" +/* + * Author: Glowbal + * Sets a unit in the unconscious state. + * For Internal Use: Called from the state machine. + * + * Arguments: + * 0: The unit that will be put in an unconscious state + * 1: Set unconscious + * + * Return Value: + * Success + * + * Public: No + */ + +params ["_unit", "_active"]; + +// No change to make +if (_active isEqualTo IS_UNCONSCIOUS(_unit)) exitWith {}; + +_unit setVariable [VAR_UNCON, _active, true]; + +// Toggle unit ragdoll state +[_unit, _active] call EFUNC(medical_engine,setUnconsciousAnim); + +if (_active) then { + // Don't bother setting this if not used + if (EGVAR(medical,spontaneousWakeUpChance) > 0) then { + _unit setVariable [QGVAR(lastWakeUpCheck), CBA_missiontime]; + }; + + if (_unit == ACE_player) then { + if (visibleMap) then {openMap false}; + + while {dialog} do { + closeDialog 0; + }; + }; +} else { + // Unit has woken up, no longer need to track this + _unit setVariable [QGVAR(lastWakeUpCheck), nil]; +}; + +// This event doesn't correspond to unconscious in statemachine +// It's for any time a unit changes consciousness (including cardiac arrest) +["ace_unconscious", [_unit, _active]] call CBA_fnc_globalEvent; diff --git a/addons/medical_status/functions/fnc_setUnconsciousStatemachine.sqf b/addons/medical_status/functions/fnc_setUnconsciousStatemachine.sqf deleted file mode 100644 index 45e1f8d3f3..0000000000 --- a/addons/medical_status/functions/fnc_setUnconsciousStatemachine.sqf +++ /dev/null @@ -1,49 +0,0 @@ -#include "script_component.hpp" -/* - * Author: Glowbal - * Sets a unit in the unconscious state. - * For Internal Use: Called from the state machine. - * - * Arguments: - * 0: The unit that will be put in an unconscious state - * 1: Set unconsciouns - * - * ReturnValue: - * Success? - * - * Example: - * [bob, true] call ace_medical_fnc_setUnconsciousStatemachine - * - * Public: No - */ - -params ["_unit", "_knockOut"]; -TRACE_2("setUnconsciousStatemachine",_unit,_knockOut); - -if (_knockOut isEqualTo IS_UNCONSCIOUS(_unit)) exitWith {TRACE_1("No Change - Exiting",_knockOut);}; - -_unit setVariable [VAR_UNCON, _knockOut, true]; -["ace_unconscious", [_unit, _knockOut]] call CBA_fnc_globalEvent; -[_unit, _knockOut] call EFUNC(medical_engine,setUnconsciousAnim); - - -if (_knockOut) then { - // --- knock out - if (EGVAR(medical,spontaneousWakeUpChance) > 0) then { // Don't bother setting this if not used - private _lastWakeUpCheck = CBA_missiontime max (_unit getVariable [QGVAR(lastWakeUpCheck), 0]); - TRACE_2("setting lastWakeUpCheck",_lastWakeUpCheck,(_lastWakeUpCheck - CBA_missiontime)); - _unit setVariable [QGVAR(lastWakeUpCheck), _lastWakeUpCheck]; - }; - - if (_unit == ACE_player) then { - if (visibleMap) then {openMap false}; - - while {dialog} do { - closeDialog 0; - }; - }; - [QEGVAR(medical,Unconscious), _unit] call CBA_fnc_localEvent; -} else { - // --- wake up - _unit setVariable [QGVAR(lastWakeUpCheck), nil]; // clear this now (min wait time could be set to a very high value) -};