Fix statemachine not running

This commit is contained in:
Thomas Kooi
2018-07-15 14:21:41 +02:00
parent 19f3b753f0
commit 78d91edae2
6 changed files with 23 additions and 12 deletions

View File

@ -5,7 +5,7 @@ class ACE_Medical_StateMachine {
skipNull = 1;
class Default {
onState = QFUNC(handleStateDefault);
onState = QUOTE(call FUNC(handleStateDefault));
class Injury {
targetState = "Injured";
events[] = {QGVAR(Injury)};
@ -24,7 +24,7 @@ class ACE_Medical_StateMachine {
};
};
class Injured {
onState = QFUNC(handleStateInjured);
onState = QUOTE(call FUNC(handleStateInjured));
class FullHeal {
targetState = "Default";
events[] = {QGVAR(FullHeal)};
@ -43,7 +43,7 @@ class ACE_Medical_StateMachine {
};
};
class Unconscious {
onState = QFUNC(handleStateUnconscious);
onState = QUOTE(call FUNC(handleStateUnconscious));
onStateEntered = QUOTE([ARR_2(_this,(true))] call EFUNC(medical,setUnconsciousStatemachine));
class DeathAI {
targetState = "Dead";
@ -67,7 +67,7 @@ class ACE_Medical_StateMachine {
class FatalInjury {
// Transition state for handling instant death
// This state raises the next transition in the same frame
onStateEntered = QFUNC(enteredStateFatalInjury);
onStateEntered = QUOTE(call FUNC(enteredStateFatalInjury));
class DeathAI {
events[] = {QGVAR(FatalInjuryInstantTransition)};
targetState = "Dead";
@ -77,7 +77,7 @@ class ACE_Medical_StateMachine {
events[] = {QGVAR(FatalInjuryInstantTransition)};
targetState = "CardiacArrest";
condition = QUOTE(EGVAR(medical,fatalInjuryCondition) > 0);
onTransition = QFUNC(transitionSecondChance);
onTransition = QUOTE(call FUNC(transitionSecondChance));
};
class Death {
events[] = {QGVAR(FatalInjuryInstantTransition)};
@ -86,15 +86,15 @@ class ACE_Medical_StateMachine {
};
};
class CardiacArrest {
onStateEntered = QFUNC(enteredStateCardiacArrest);
onStateLeaving = QFUNC(leftStateCardiacArrest);
onStateEntered = QUOTE(call FUNC(enteredStateCardiacArrest));
onStateLeaving = QUOTE(call FUNC(leftStateCardiacArrest));
class DeathAI {
targetState = "Dead";
condition = QUOTE(!isPlayer _this && {EGVAR(medical,fatalInjuryConditionAI)});
};
class Timeout {
targetState = "Dead";
condition = QEFUNC(medical,conditionCardiacArrestTimer);
condition = QUOTE(call EFUNC(medical,conditionCardiacArrestTimer));
};
class Reanimation {
targetState = "Unconscious";
@ -102,11 +102,13 @@ class ACE_Medical_StateMachine {
};
class Execution {
targetState = "Dead";
condition = QEFUNC(medical,conditionExecutionDeath);
condition = QUOTE(call EFUNC(medical,conditionExecutionDeath));
events[] = {QGVAR(FatalInjury)};
};
};
class Dead {
// TODO: this needs to be handled by a function instead of inline scripts
// Probably also needs additional logic to deal with edge cases
onStateEntered = "_this setDamage 1"; // killing a unit also exits the state machine for this unit
};
};

View File

@ -15,3 +15,4 @@ class CfgPatches {
};
#include "Statemachine.hpp"
#include "CfgEventHandlers.hpp"

View File

@ -3,6 +3,8 @@
params ["_unit", "_stateName"];
TRACE_2("defaultState:", _unit, _stateName);
// If the unit died the loop is finished
if (!alive _unit) exitWith {};

View File

@ -13,21 +13,22 @@
* Public: Yes
*/
#include "script_component.hpp"
#define MORPHINE_PAIN_SUPPRESSION 0.6
params ["_target", "_className", "_partIndex"];
TRACE_3("params",_target,_className,_partIndex);
if (!EGVAR(medical,advancedMedication)) exitWith {
TRACE_1("MedicalSettingAdvancedMedication is:", EGVAR(medical,advancedMedication));
if (_className == "Morphine") exitWith {
#define MORPHINE_PAIN_SUPPRESSION 0.6
private _painSupress = GET_PAIN_SUPPRESS(_target);
_target setVariable [VAR_PAIN_SUPP, (_painSupress + MORPHINE_PAIN_SUPPRESSION) min 1, true];
};
if (_className == "Epinephrine") exitWith {
[QEGVAR(medical,WakeUp), _target] call CBA_fnc_localEvent;
};
};
TRACE_1("Running treatmentMedicationLocal with Advanced configuration for", _target);
private _tourniquets = _target getVariable [QEGVAR(medical,tourniquets), [0,0,0,0,0,0]];
@ -80,6 +81,7 @@ if (alive _target) then {
// Adjust the heart rate based upon config entry
if (_heartRateChange != 0) then {
TRACE_1("heartRateChange", _heartRateChange);
private _adjustments = _target getVariable [VAR_HEART_RATE_ADJ,[]];
_adjustments pushBack [_heartRateChange, _timeTillMaxEffect, _timeInSystem, 0];
_target setVariable [VAR_HEART_RATE_ADJ, _adjustments];
@ -87,6 +89,7 @@ if (alive _target) then {
// Adjust the pain suppression based upon config entry
if (_painReduce > 0) then {
TRACE_1("painReduce", _painReduce);
private _adjustments = _target getVariable [VAR_PAIN_SUPP_ADJ,[]];
_adjustments pushBack [_painReduce, _timeTillMaxEffect, _timeInSystem, 0];
_target setVariable [VAR_PAIN_SUPP_ADJ, _adjustments];
@ -94,6 +97,7 @@ if (alive _target) then {
// Adjust the peripheral resistance based upon config entry
if (_viscosityChange != 0) then {
TRACE_1("viscosityChange", _viscosityChange);
private _adjustments = _target getVariable [VAR_PERIPH_RES_ADJ,[]];
_adjustments pushBack [_viscosityChange, _timeTillMaxEffect, _timeInSystem, 0];
_target setVariable [VAR_PERIPH_RES_ADJ, _adjustments];

View File

@ -13,3 +13,5 @@ class CfgPatches {
VERSION_CONFIG;
};
};
#include "CfgEventHandlers.hpp"

View File

@ -21,7 +21,7 @@
params ["_unit", "_deltaT", "_syncValue"];
private _hrTargetAdjustment = 0;
private _adjustments = GETVAR(_unit,VAR_HEART_RATE_ADJ,[]);
private _adjustments = _unit getVariable [VAR_HEART_RATE_ADJ,[]];
if !(_adjustments isEqualTo []) then {
{