Skip to content

Commit

Permalink
Medical - Transfer state machine state on locality (#6950)
Browse files Browse the repository at this point in the history
* Medical - Transfer state machine state on locality

* Fix feedback isUnconscious var

* Exclude AI
  • Loading branch information
PabstMirror authored May 7, 2019
1 parent a23b22a commit cdd1de0
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 23 deletions.
3 changes: 1 addition & 2 deletions addons/medical_feedback/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
9 changes: 9 additions & 0 deletions addons/medical_statemachine/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
};
};
};
2 changes: 2 additions & 0 deletions addons/medical_statemachine/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ PREP(handleStateDefault);
PREP(handleStateInjured);
PREP(handleStateUnconscious);
PREP(leftStateCardiacArrest);
PREP(localityChangedEH);
PREP(localityTransfer);
PREP(resetStateDefault);
PREP(transitionSecondChance);
2 changes: 2 additions & 0 deletions addons/medical_statemachine/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#include "script_component.hpp"

[QGVAR(localityTransfer), LINKFUNC(localityTransfer)] call CBA_fnc_addEventHandler;
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
33 changes: 33 additions & 0 deletions addons/medical_statemachine/functions/fnc_localityChangedEH.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "script_component.hpp"
/*
* Author: PabstMirror
* Handles locality switch.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: isLocal <BOOL>
*
* 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;
};
26 changes: 26 additions & 0 deletions addons/medical_statemachine/functions/fnc_localityTransfer.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "script_component.hpp"
/*
* Author: PabstMirror
* Handles locality switch.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: State <STRING>
*
* 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;
};

0 comments on commit cdd1de0

Please sign in to comment.