mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Make state change status updates consistent (#6538)
State transitions call respective functions in the status component where unit variables and status are actually handled.
This commit is contained in:
parent
11547d7ff8
commit
24846e6f74
@ -44,7 +44,7 @@ class ACE_Medical_StateMachine {
|
|||||||
};
|
};
|
||||||
class Unconscious {
|
class Unconscious {
|
||||||
onState = QFUNC(handleStateUnconscious);
|
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 {
|
class DeathAI {
|
||||||
targetState = "Dead";
|
targetState = "Dead";
|
||||||
condition = QUOTE(!isPlayer _this && {GVAR(unconsciousConditionAI)});
|
condition = QUOTE(!isPlayer _this && {GVAR(unconsciousConditionAI)});
|
||||||
@ -53,7 +53,7 @@ class ACE_Medical_StateMachine {
|
|||||||
targetState = "Injured";
|
targetState = "Injured";
|
||||||
condition = QEFUNC(medical_status,hasStableVitals);
|
condition = QEFUNC(medical_status,hasStableVitals);
|
||||||
events[] = {QEGVAR(medical,WakeUp)};
|
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 {
|
class FatalTransitions {
|
||||||
targetState = "CardiacArrest";
|
targetState = "CardiacArrest";
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
/*
|
/*
|
||||||
* Author: BaerMitUmlaut
|
* 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:
|
* Arguments:
|
||||||
* 0: The Unit <OBJECT>
|
* 0: The Unit <OBJECT>
|
||||||
@ -21,4 +22,5 @@ _time = _time + random [_time*-0.1, 0, _time*0.1];
|
|||||||
_unit setVariable [QGVAR(cardiacArrestTime), _time];
|
_unit setVariable [QGVAR(cardiacArrestTime), _time];
|
||||||
_unit setVariable [QGVAR(cardiacArrestStart), CBA_missionTime];
|
_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);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
/*
|
/*
|
||||||
* Author: SilentSpike
|
* Author: SilentSpike
|
||||||
* Handles a unit reaching the point of death.
|
* Handles a unit reaching the point of death (calls for a status update).
|
||||||
*
|
*
|
||||||
* Arguments:
|
* Arguments:
|
||||||
* 0: The Unit <OBJECT>
|
* 0: The Unit <OBJECT>
|
||||||
@ -19,7 +19,4 @@ params ["_unit"];
|
|||||||
// Send a local event before death
|
// Send a local event before death
|
||||||
[QEGVAR(medical,death), [_unit]] call CBA_fnc_localEvent;
|
[QEGVAR(medical,death), [_unit]] call CBA_fnc_localEvent;
|
||||||
|
|
||||||
_unit setVariable [VAR_HEART_RATE, 0, true];
|
[_unit] call EFUNC(medical_status,setDead);
|
||||||
_unit setVariable [VAR_BLOOD_PRESS, [0, 0], true];
|
|
||||||
|
|
||||||
_unit setDamage 1;
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
/*
|
/*
|
||||||
* Author: BaerMitUmlaut
|
* Author: RedBery
|
||||||
* Handles a unit entering cardiac arrest.
|
* Handles a unit leaving cardiac arrest (calls for a status update).
|
||||||
|
* Clears countdown timer variables.
|
||||||
*
|
*
|
||||||
* Arguments:
|
* Arguments:
|
||||||
* 0: The Unit <OBJECT>
|
* 0: The Unit <OBJECT>
|
||||||
@ -14,7 +15,10 @@
|
|||||||
|
|
||||||
params ["_unit"];
|
params ["_unit"];
|
||||||
|
|
||||||
_unit setVariable [VAR_CRDC_ARRST, false, true];
|
_unit setVariable [QGVAR(cardiacArrestTime), nil];
|
||||||
_unit setVariable [QEGVAR(medical,cardiacArrestStart), 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 setVariable [QGVAR(lastTimeUpdated), CBA_missionTime];
|
||||||
|
|
||||||
|
[_unit, false] call EFUNC(medical_status,setCardiacArrest);
|
||||||
|
@ -11,4 +11,4 @@ PREP(isBeingDragged);
|
|||||||
PREP(isInStableCondition);
|
PREP(isInStableCondition);
|
||||||
PREP(setCardiacArrest);
|
PREP(setCardiacArrest);
|
||||||
PREP(setDead);
|
PREP(setDead);
|
||||||
PREP(setUnconsciousStatemachine);
|
PREP(setUnconscious);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
/*
|
/*
|
||||||
* Author: Glowbal
|
* 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.
|
* Marks a unit as in cardiac arrest and sets heart rate to 0.
|
||||||
* Timer is a random value between 120 and 720 seconds.
|
* Will put the unit in an unconscious state if not already.
|
||||||
*
|
*
|
||||||
* Arguments:
|
* Arguments:
|
||||||
* 0: The unit that will be put in cardiac arrest state <OBJECT>
|
* 0: The unit that will be put in cardiac arrest state <OBJECT>
|
||||||
@ -10,19 +10,19 @@
|
|||||||
* Return Value:
|
* Return Value:
|
||||||
* None
|
* None
|
||||||
*
|
*
|
||||||
* Example:
|
* Public: No
|
||||||
* [bob] call ace_medical_fnc_setCardiacArrest
|
|
||||||
*
|
|
||||||
* Public: yes
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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];
|
// No heart rate in cardiac arrest, low heart rate if revived
|
||||||
_unit setVariable [VAR_HEART_RATE, 0, true];
|
_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;
|
||||||
|
@ -10,17 +10,17 @@
|
|||||||
* Return Value:
|
* Return Value:
|
||||||
* None
|
* None
|
||||||
*
|
*
|
||||||
* Example:
|
|
||||||
* [bob, "bloodloss"] call ace_medical_status_fnc_setDead;
|
|
||||||
*
|
|
||||||
* Public: No
|
* Public: No
|
||||||
*/
|
*/
|
||||||
|
|
||||||
params ["_unit", ["_reason", "unknown"]];
|
params ["_unit", ["_reason", "unknown"]];
|
||||||
|
|
||||||
// wait a frame to escape handleDamage
|
// No heart rate or blood pressure to measure when dead
|
||||||
// @TODO Test if this is still necessary
|
_unit setVariable [VAR_HEART_RATE, 0, true];
|
||||||
[EFUNC(medical_engine,setStructuralDamage), [_unit, 1]] call CBA_fnc_execNextFrame;
|
_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 _lastShooter = _unit getVariable [QEGVAR(medical_engine,lastShooter), objNull];
|
||||||
private _lastInstigator = _unit getVariable [QEGVAR(medical_engine,lastInstigator), objNull];
|
private _lastInstigator = _unit getVariable [QEGVAR(medical_engine,lastInstigator), objNull];
|
||||||
|
47
addons/medical_status/functions/fnc_setUnconscious.sqf
Normal file
47
addons/medical_status/functions/fnc_setUnconscious.sqf
Normal file
@ -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 <OBJECT>
|
||||||
|
* 1: Set unconscious <BOOL>
|
||||||
|
*
|
||||||
|
* Return Value:
|
||||||
|
* Success <BOOL>
|
||||||
|
*
|
||||||
|
* 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;
|
@ -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 <OBJECT>
|
|
||||||
* 1: Set unconsciouns <BOOL>
|
|
||||||
*
|
|
||||||
* ReturnValue:
|
|
||||||
* Success? <BOOLEAN>
|
|
||||||
*
|
|
||||||
* 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)
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user