Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Medical Statemachine - Fix locality EH breaking current state #7136

Merged
merged 3 commits into from
Sep 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions addons/medical_statemachine/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ class Extended_PreInit_EventHandlers {
};
};

class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};

class Extended_Respawn_EventHandlers {
class CAManBase {
class ADDON {
Expand Down
1 change: 0 additions & 1 deletion addons/medical_statemachine/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ PREP(handleStateInjured);
PREP(handleStateUnconscious);
PREP(leftStateCardiacArrest);
PREP(localityChangedEH);
PREP(localityTransfer);
PREP(resetStateDefault);
PREP(transitionSecondChance);
3 changes: 0 additions & 3 deletions addons/medical_statemachine/XEH_postInit.sqf

This file was deleted.

56 changes: 46 additions & 10 deletions addons/medical_statemachine/functions/fnc_localityChangedEH.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "script_component.hpp"
/*
* Author: PabstMirror
* Handles locality switch.
* Handles locality switch. Will also be called at unit init.
* Because state machine state is local only, when a unit transfers locality we need to manually transition to it's current state
*
* Arguments:
* 0: Unit <OBJECT>
Expand All @@ -19,15 +20,50 @@
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];
if (!alive _unit) exitWith {};

if (_isLocal) then {
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;
TRACE_1("local",_currentState);

switch (true) do {
case (IN_CRDC_ARRST(_unit)): {
if (_currentState == "CardiacArrest") exitWith {};
_unit setVariable [VAR_CRDC_ARRST, false]; // force reset vars so setCardiacArrest can run (enteredStateCardiacArrest will also be called)
_unit setVariable [VAR_UNCON, false];
TRACE_1("manually changing state to CardiacArrest",_currentState);
[_unit, EGVAR(medical,STATE_MACHINE), _currentState, "CardiacArrest", {}, "LocalityChange"] call CBA_statemachine_fnc_manualTransition;
};
case (IS_UNCONSCIOUS(_unit)): {
if (_currentState == "Unconscious") exitWith {};
_unit setVariable [VAR_UNCON, false]; // force reset var so ace_medical_status_fnc_setUnconscious can run
TRACE_1("manually changing state to Unconscious",_currentState);
[_unit, EGVAR(medical,STATE_MACHINE), _currentState, "Unconscious", {}, "LocalityChange"] call CBA_statemachine_fnc_manualTransition;
};
case (IS_BLEEDING(_unit) || {IS_IN_PAIN(_unit)}): {
if (_currentState == "Injured") exitWith {};
TRACE_1("manually changing state to Injured",_currentState);
[_unit, EGVAR(medical,STATE_MACHINE), _currentState, "Injured", {}, "LocalityChange"] call CBA_statemachine_fnc_manualTransition;
};
default {
// If locality transfers back and forth, we could be in an old state and should transfer back to default
if (_currentState == "Default") exitWith {};
TRACE_1("manually changing state to Default",_currentState);
[_unit, EGVAR(medical,STATE_MACHINE), _currentState, "Default", {}, "LocalityChange"] call CBA_statemachine_fnc_manualTransition;
};
};
} else {
/*
// Not sure if this is even needed, idea is that on locality transfer we broadcast more up to date info
Copy link
Member

@TheMagnetar TheMagnetar Sep 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be the case in order to send the latest information, specially if the medical states vary between clients (you have a completely different medical state and some information may be even lost). In any case, it should be done before doing a manual transition to a particular state in my opinion.


private _lastTimeUpdated = _unit getVariable [QEGVAR(medical_vitals,lastTimeUpdated), 1e99];
private _deltaT = CBA_missionTime - _lastTimeUpdated;
TRACE_1("not local",_deltaT);
if (_deltaT < 5) then {
// If locality changed and we have recently updated vitals, broadcast globally now
_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];
};
*/
};
26 changes: 0 additions & 26 deletions addons/medical_statemachine/functions/fnc_localityTransfer.sqf

This file was deleted.