From cdd1de04f036d3924d0c172cf5f3311a773ad49e Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 7 May 2019 09:08:00 -0500 Subject: [PATCH] Medical - Transfer state machine state on locality (#6950) * Medical - Transfer state machine state on locality * Fix feedback isUnconscious var * Exclude AI --- addons/medical_feedback/XEH_postInit.sqf | 3 +- .../medical_statemachine/CfgEventHandlers.hpp | 9 +++++ addons/medical_statemachine/XEH_PREP.hpp | 2 ++ addons/medical_statemachine/XEH_postInit.sqf | 2 ++ .../functions/fnc_handleStateDefault.sqf | 8 +---- .../functions/fnc_handleStateInjured.sqf | 8 +---- .../functions/fnc_handleStateUnconscious.sqf | 8 +---- .../functions/fnc_localityChangedEH.sqf | 33 +++++++++++++++++++ .../functions/fnc_localityTransfer.sqf | 26 +++++++++++++++ 9 files changed, 76 insertions(+), 23 deletions(-) create mode 100644 addons/medical_statemachine/functions/fnc_localityChangedEH.sqf create mode 100644 addons/medical_statemachine/functions/fnc_localityTransfer.sqf diff --git a/addons/medical_feedback/XEH_postInit.sqf b/addons/medical_feedback/XEH_postInit.sqf index faa826a534..546f3de95f 100644 --- a/addons/medical_feedback/XEH_postInit.sqf +++ b/addons/medical_feedback/XEH_postInit.sqf @@ -56,8 +56,7 @@ GVAR(heartBeatEffectRunning) = false; // Update effects to match new unit's current status (this also handles respawn) ["unit", { params ["_new"]; - - private _status = _new getVariable ["ace_unconscious", false]; + private _status = IS_UNCONSCIOUS(_new); if (["task_force_radio"] call EFUNC(common,isModLoaded)) then { _new setVariable ["tf_voiceVolume", [1, 0] select _status, true]; diff --git a/addons/medical_statemachine/CfgEventHandlers.hpp b/addons/medical_statemachine/CfgEventHandlers.hpp index f0de7ed461..cf0dbfc1de 100644 --- a/addons/medical_statemachine/CfgEventHandlers.hpp +++ b/addons/medical_statemachine/CfgEventHandlers.hpp @@ -23,3 +23,12 @@ class Extended_Respawn_EventHandlers { }; }; }; + +class Extended_Local_EventHandlers { + class CAManBase { + class ADDON { + local = QUOTE(call FUNC(localityChangedEH)); + exclude[] = {"B_UAV_AI","O_UAV_AI","UAV_AI_base_F"}; + }; + }; +}; diff --git a/addons/medical_statemachine/XEH_PREP.hpp b/addons/medical_statemachine/XEH_PREP.hpp index e2e27963b1..26595cfb62 100644 --- a/addons/medical_statemachine/XEH_PREP.hpp +++ b/addons/medical_statemachine/XEH_PREP.hpp @@ -7,5 +7,7 @@ PREP(handleStateDefault); PREP(handleStateInjured); PREP(handleStateUnconscious); PREP(leftStateCardiacArrest); +PREP(localityChangedEH); +PREP(localityTransfer); PREP(resetStateDefault); PREP(transitionSecondChance); diff --git a/addons/medical_statemachine/XEH_postInit.sqf b/addons/medical_statemachine/XEH_postInit.sqf index 421c54b49f..89d8891fdb 100644 --- a/addons/medical_statemachine/XEH_postInit.sqf +++ b/addons/medical_statemachine/XEH_postInit.sqf @@ -1 +1,3 @@ #include "script_component.hpp" + +[QGVAR(localityTransfer), LINKFUNC(localityTransfer)] call CBA_fnc_addEventHandler; diff --git a/addons/medical_statemachine/functions/fnc_handleStateDefault.sqf b/addons/medical_statemachine/functions/fnc_handleStateDefault.sqf index 34187fca28..33cb1d29c0 100644 --- a/addons/medical_statemachine/functions/fnc_handleStateDefault.sqf +++ b/addons/medical_statemachine/functions/fnc_handleStateDefault.sqf @@ -19,13 +19,7 @@ params ["_unit"]; // If the unit died the loop is finished if (!alive _unit) exitWith {}; - -// If locality changed, broadcast the last medical state and finish the local loop -if (!local _unit) exitWith { - _unit setVariable [VAR_HEART_RATE, GET_HEART_RATE(_unit), true]; - _unit setVariable [VAR_BLOOD_PRESS, _unit getVariable [VAR_BLOOD_PRESS, [80, 120]], true]; - _unit setVariable [VAR_BLOOD_VOL, GET_BLOOD_VOLUME(_unit), true]; -}; +if (!local _unit) exitWith {}; [_unit] call EFUNC(medical_vitals,handleUnitVitals); diff --git a/addons/medical_statemachine/functions/fnc_handleStateInjured.sqf b/addons/medical_statemachine/functions/fnc_handleStateInjured.sqf index a75397c876..50f4a6bfa6 100644 --- a/addons/medical_statemachine/functions/fnc_handleStateInjured.sqf +++ b/addons/medical_statemachine/functions/fnc_handleStateInjured.sqf @@ -19,13 +19,7 @@ params ["_unit"]; // If the unit died the loop is finished if (!alive _unit) exitWith {}; - -// If locality changed, broadcast the last medical state and finish the local loop -if (!local _unit) exitWith { - _unit setVariable [VAR_HEART_RATE, GET_HEART_RATE(_unit), true]; - _unit setVariable [VAR_BLOOD_PRESS, _unit getVariable [VAR_BLOOD_PRESS, [80, 120]], true]; - _unit setVariable [VAR_BLOOD_VOL, GET_BLOOD_VOLUME(_unit), true]; -}; +if (!local _unit) exitWith {}; [_unit] call EFUNC(medical_vitals,handleUnitVitals); diff --git a/addons/medical_statemachine/functions/fnc_handleStateUnconscious.sqf b/addons/medical_statemachine/functions/fnc_handleStateUnconscious.sqf index fdb730c0bf..7bc147e1be 100644 --- a/addons/medical_statemachine/functions/fnc_handleStateUnconscious.sqf +++ b/addons/medical_statemachine/functions/fnc_handleStateUnconscious.sqf @@ -19,13 +19,7 @@ params ["_unit"]; // If the unit died the loop is finished if (!alive _unit) exitWith {}; - -// If locality changed, broadcast the last medical state and finish the local loop -if (!local _unit) exitWith { - _unit setVariable [VAR_HEART_RATE, GET_HEART_RATE(_unit), true]; - _unit setVariable [VAR_BLOOD_PRESS, _unit getVariable [VAR_BLOOD_PRESS, [80, 120]], true]; - _unit setVariable [VAR_BLOOD_VOL, GET_BLOOD_VOLUME(_unit), true]; -}; +if (!local _unit) exitWith {}; [_unit] call EFUNC(medical_vitals,handleUnitVitals); diff --git a/addons/medical_statemachine/functions/fnc_localityChangedEH.sqf b/addons/medical_statemachine/functions/fnc_localityChangedEH.sqf new file mode 100644 index 0000000000..1bcc9a9bde --- /dev/null +++ b/addons/medical_statemachine/functions/fnc_localityChangedEH.sqf @@ -0,0 +1,33 @@ +#include "script_component.hpp" +/* + * Author: PabstMirror + * Handles locality switch. + * + * Arguments: + * 0: Unit + * 1: isLocal + * + * Return Value: + * None + * + * Example: + * [player, true] call ace_medical_statemachine_fnc_localityChangedEH + * + * Public: No + */ + +params ["_unit", "_isLocal"]; +TRACE_2("localityChangedEH",_unit,_isLocal); + +if (!alive _unit) exitWith {TRACE_1("dead", _this)}; + +if (!_isLocal) then { + // If locality changed, broadcast the last medical state + _unit setVariable [VAR_HEART_RATE, GET_HEART_RATE(_unit), true]; + _unit setVariable [VAR_BLOOD_PRESS, _unit getVariable [VAR_BLOOD_PRESS, [80, 120]], true]; + _unit setVariable [VAR_BLOOD_VOL, GET_BLOOD_VOLUME(_unit), true]; + + private _currentState = [_unit, EGVAR(medical,STATE_MACHINE)] call CBA_statemachine_fnc_getCurrentState; + TRACE_2("sending current state",_unit,_currentState); + [QGVAR(localityTransfer), [_unit, _currentState], _unit] call CBA_fnc_targetEvent; +}; diff --git a/addons/medical_statemachine/functions/fnc_localityTransfer.sqf b/addons/medical_statemachine/functions/fnc_localityTransfer.sqf new file mode 100644 index 0000000000..abf4ddd5a3 --- /dev/null +++ b/addons/medical_statemachine/functions/fnc_localityTransfer.sqf @@ -0,0 +1,26 @@ +#include "script_component.hpp" +/* + * Author: PabstMirror + * Handles locality switch. + * + * Arguments: + * 0: Unit + * 1: State + * + * Return Value: + * None + * + * Example: + * [player, "Injured"] call ace_medical_statemachine_fnc_localityTransfer + * + * Public: No + */ + +params ["_unit", "_currentState"]; +TRACE_2("localityTransfer",_unit,_currentState); + +private _oldState = [_unit, EGVAR(medical,STATE_MACHINE)] call CBA_statemachine_fnc_getCurrentState; +if (_oldState != _currentState) then { + TRACE_2("changing state",_oldState,_currentState); + [_unit, EGVAR(medical,STATE_MACHINE), _oldState, _currentState, {}, "LocalityChange"] call CBA_statemachine_fnc_manualTransition; +};