Merge medical core and medical state. Add working version of the state machine, re-add sounds

This commit is contained in:
Glowbal 2016-07-02 16:34:28 +02:00
parent 2d330e36e0
commit e8eb729e04
26 changed files with 143 additions and 116 deletions

View File

@ -5,15 +5,15 @@ class ACE_Medical_StateMachine {
onStateLeaving = "";
class Injury {
targetState = "Injured";
events[] = {'TakenInjury'};
events[] = {"TakenInjury"};
};
class CriticalInjuryOrVitals {
targetState = "Unconscious";
events[] = {'InjuryCritical', 'CriticalVitals'};
events[] = {"InjuryCritical", "CriticalVitals"};
};
class FatalInjuryOrVitals {
targetState = "Dead";
events[] = {'FatalVitals', 'InjuryFatal'};
events[] = {"FatalVitals", "InjuryFatal"};
};
};
class Injured {
@ -23,19 +23,19 @@ class ACE_Medical_StateMachine {
class FullHeal {
targetState = "Default";
events[] = {'FullHeal'};
events[] = {"FullHeal"};
};
class LastWoundTreated {
targetState = "Default";
events[] = {'LastWoundTreated'};
events[] = {"LastWoundTreated"};
};
class CriticalInjuryOrVitals {
targetState = "Unconscious";
events[] = {'InjuryCritical', 'CriticalVitals'};
events[] = {"InjuryCritical", "CriticalVitals"};
};
class FatalInjuryOrVitals {
targetState = "Dead";
events[] = {'FatalVitals', 'InjuryFatal'};
events[] = {"FatalVitals", "InjuryFatal"};
};
};
class Unconscious {
@ -45,16 +45,16 @@ class ACE_Medical_StateMachine {
class WakeUpFromKnockDown {
targetState = "Injured";
condition = QUOTE(_unit call FUNC(hasStableVitals));
events[] = {'MinUnconsciousTimer'};
events[] = {"MinUnconsciousTimer"};
};
class WakeUpStable {
targetState = "Injured";
condition = "unitUnconsciousTimer >= MinUnconsciousTimer";
events[] = {'VitalsWentStable'};
events[] = {"VitalsWentStable"};
};
class FatalTransitions {
targetState = "Dead";
events[] = {'InjuryFatal', 'FatalVitals', 'UnconsciousTimerRanOut'};
events[] = {"InjuryFatal", "FatalVitals", "UnconsciousTimerRanOut"};
};
};
class Dead {
@ -66,24 +66,24 @@ class ACE_Medical_StateMachine {
onStateLeaving = QUOTE(DFUNC(leavingRevive)); // leave unconscious animation & state
class FullHeal {
targetState = "Default";
events[] = {'fullyHealed'};
events[] = {"fullyHealed"};
onTransition = "";
};
class Revived {
targetState = "Injured";
events[] = {'Revived'};
events[] = {"Revived"};
onTransition = "";
};
class TimerRanOut {
targetState = "Dead";
condition = "timerValue >= maxReviveTime";
events[] = {'ReviveTimer'};
events[] = {"ReviveTimer"};
onTransition = "";
};
class FatalTransitions {
targetState = "Dead";
condition = "killOnFatalDamageInRevive && inReviveState >= 10";
events[] = {'FatalInjury'};
events[] = {"FatalInjury"};
};
};
};

View File

@ -0,0 +1,37 @@
class CfgSounds {
class ACE_heartbeat_fast_1 {
name = "ACE_heartbeat_fast_1";
sound[] = {QPATHTOF(sounds\heart_beats\fast_1.wav), "db+1", 1};
titles[] = {};
};
class ACE_heartbeat_fast_2 {
name = "ACE_heartbeat_fast_2";
sound[] = {QPATHTOF(sounds\heart_beats\fast_2.wav), "db+1", 1};
titles[] = {};
};
class ACE_heartbeat_fast_3 {
name = "ACE_heartbeat_fast_3";
sound[] = {QPATHTOF(sounds\heart_beats\fast_3.wav), "db+1", 1};
titles[] = {};
};
class ACE_heartbeat_norm_1 {
name = "ACE_heartbeat_norm_1";
sound[] = {QPATHTOF(sounds\heart_beats\norm_1.wav), "db+1", 1};
titles[] = {};
};
class ACE_heartbeat_norm_2 {
name = "ACE_heartbeat_norm_2";
sound[] = {QPATHTOF(sounds\heart_beats\norm_2.wav), "db+1", 1};
titles[] = {};
};
class ACE_heartbeat_slow_1 {
name = "ACE_heartbeat_slow_1";
sound[] = {QPATHTOF(sounds\heart_beats\slow_1.wav), "db+1", 1};
titles[] = {};
};
class ACE_heartbeat_slow_2 {
name = "ACE_heartbeat_slow_2";
sound[] = {QPATHTOF(sounds\heart_beats\slow_2.wav), "db+1", 1};
titles[] = {};
};
};

View File

@ -1,6 +1,7 @@
PREP(addStateHandler);
PREP(adjustPainLevel);
PREP(createStateMachine);
PREP(getBloodLoss);
PREP(getBloodPressure);
PREP(getBloodVolumeChange);
@ -18,3 +19,5 @@ PREP(parseConfigForInjuries);
PREP(selectionNameToNumber);
PREP(setHitPointDamage);
PREP(setStructuralDamage);
PREP(stateEvent);
PREP(stateMachine);

View File

@ -0,0 +1,23 @@
#include "script_component.hpp"
GVAR(heartBeatSounds_Fast) = ["ACE_heartbeat_fast_1", "ACE_heartbeat_fast_2", "ACE_heartbeat_fast_3"];
GVAR(heartBeatSounds_Normal) = ["ACE_heartbeat_norm_1", "ACE_heartbeat_norm_2"];
GVAR(heartBeatSounds_Slow) = ["ACE_heartbeat_slow_1", "ACE_heartbeat_slow_2"];
["ace_unconscious", {
params ["_unit", "_status"];
if (local _unit) then {
if (_status) then {
_unit setVariable ["tf_voiceVolume", 0, true];
_unit setVariable ["tf_unable_to_use_radio", true, true];
_unit setVariable ["acre_sys_core_isDisabled", true, true];
} else {
_unit setVariable ["tf_voiceVolume", 1, true];
_unit setVariable ["tf_unable_to_use_radio", false, true];
_unit setVariable ["acre_sys_core_isDisabled", false, true];
};
};
}] call CBA_fnc_addEventHandler;

View File

@ -8,6 +8,7 @@ GVAR(HITPOINTS) = ["HitHead", "HitBody", "HitLeftArm", "HitRightArm", "HitLeftLe
GVAR(SELECTIONS) = ["head", "body", "hand_l", "hand_r", "leg_l", "leg_r"];
call FUNC(parseConfigForInjuries);
GVAR(STATE_MACHINE) = (configFile >> "ACE_Medical_StateMachine") call FUNC(createStateMachine);
//Hack for #3168 (units in static weapons do not take any damage):
//doing a manual pre-load with a small distance seems to fix the LOD problems with handle damage not returning full results

View File

@ -15,4 +15,7 @@ class CfgPatches {
};
#include "CfgEventHandlers.hpp"
#include "CfgSounds.hpp"
#include "injuries.hpp"
#include "ACE_Medical_StateMachine.hpp"

View File

@ -5,9 +5,10 @@ params ["_stateMachineConfig"];
private _getCode = {
params ["_config", "_attribute"];
private _value = getText (_config >> _attribute);
if (_value == "") {_value = "true"};
if (_value == "") then {_value = "true"};
compile _value;
};
private _stateMachine = call CBA_fnc_createNamespace;
private _states = [];
{
@ -21,7 +22,7 @@ private _states = [];
{
private _transitionName = configName _x;
private _targetState = getText (_x >> "targetState");
private _events = getArray (_x >> "events");
private _events = getArray (_x >> "events") apply { toLower _x};
private _condition = [_x, "condition"] call _getCode;
private _onTransition = [_x, "onTransition"] call _getCode;
@ -40,14 +41,12 @@ private _getState = {
_state;
};
_stateMachine setvariable [QGVAR(allStates), _states];
// Now we have collected all the states, link them in transitions so we do not have to look them up on state transitions
{
_x params ["", "", "", "", "_transitions"];
{
_x params ["", "", "", "", "_targetState"];
private _state = [_targetState] call _getState;
_x set [4, _state];
} forEach _transitions;
_x params ["_stateName"];
_stateMachine setvariable [_stateName, _x];
} forEach _states;
_states;
_stateMachine;

View File

@ -0,0 +1,52 @@
/*
* Author: Glowbal
*
*
* Arguments:
* 0: The Unit <OBJECT>
* 1: Event name <STRING>
* 2: Event Arguments
*
* ReturnValue:
* Name of the state after handling the state event <STRING>
*
* Example:
* [unit, "TakenInjury", []] call ace_medical_stateEvent;
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit", "_event", "_args"];
diag_log format["ace_medical_stateEvent: %1", _this];
_event = toLower _event;
private _unitState = _unit getvariable [QGVAR(state), [CBA_missionTime, GVAR(STATE_MACHINE) getVariable "Default"]];
_unitState params ["_lastTime", "_state"];
_state params ["_name", "_handler", "_onEntry", "_onExit", "_transitions"];
private _newStateName = _name;
{
_x params ["_transitionName", "_condition", "_events", "_onTransition", "_targetStateName"];
if (_event in _events && {[_unit, _event, _args] call _condition}) exitWith {
private _targetState = GVAR(STATE_MACHINE) getVariable _targetStateName;
_targetState params ["_targetStateName", "_targetStateHandler", "_targetStateOnEntry", "_targetStateOnExit", "_targetStateTansitions"];
_newStateName = _targetStateName;
// Handle state leaving
[_unit, _event, _args] call _onExit;
[_unit, _event, _args] call _onTransition;
// Switch the state
_unitState set [1, _targetState];
_unit setvariable [QGVAR(state), _unitState];
// Enter the state
[_unit, _event, _args] call _targetStateOnEntry;
};
} forEach _transitions;
_newStateName;

View File

@ -2,7 +2,7 @@
// Delay between state runs
#define DELAY 10
#define DEFAULT_STATE [0, "Default", {}, {}, {}, []];
#define DEFAULT_STATE [0, "Default", {}, {}, {}, []]
GVAR(monitoredUnitsList) = [];
GVAR(monitoredUnitsListIsSorted) = false;
@ -20,7 +20,7 @@ GVAR(monitoredUnitsListIsSorted) = false;
{
_x params ["_unit"];
if (!isNull _unit && alive _unit) {
if (!isNull _unit && alive _unit) then {
private _unitState = _unit getvariable [QGVAR(state), [CBA_missionTime, DEFAULT_STATE]];
_unitState params ["_lastTime", "_state"];

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1 +0,0 @@
z\ace\addons\medical_state

View File

@ -1,11 +0,0 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preStart));
};
};
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};

View File

@ -1,7 +0,0 @@
#include "script_component.hpp"
ADDON = false;
#include "XEH_PREP.hpp"
ADDON = true;

View File

@ -1,3 +0,0 @@
#include "script_component.hpp"
#include "XEH_PREP.hpp"

View File

@ -1,17 +0,0 @@
#include "script_component.hpp"
class CfgPatches {
class ADDON {
name = COMPONENT_NAME;
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_medical"};
author = ECSTRING(common,ACETeam);
authors[] = {""};
url = ECSTRING(main,URL);
VERSION_CONFIG;
};
};
#include "CfgEventHandlers.hpp"

View File

@ -1,33 +0,0 @@
#include "script_component.hpp"
params ["_unit", "_event", "_args"];
private _unitState = _unit getvariable [QGVAR(state), [CBA_missionTime, DEFAULT_STATE]];
_unitState params ["_lastTime", "_state"];
_state params ["_name", "_handler", "_onEntry", "_onExit", "_transitions"];
{
_x params ["_transitionName", "_condition", "_events", "_onTransition", "_targetState"];
if (_condition && {_event in _events}) exitWith {
_targetState params ["_targetStateName", "_targetStateHandler", "_targetStateOnEntry", "_targetStateOnExit", "_targetStateTansitions"];
// Handle state leaving
[_unit, _event, _args] call {
params ["_unit", "_event", "_args"];
[_unit, _event, _args] call _onExit;
[_unit, _event, _args] call _onTransition;
};
// Switch the state
_unitState set [1, _targetState];
_unit setvariable [QGVAR(state), _unitState];
// Enter the state
[_unit, _event, _args] call {
params ["_unit", "_event", "_args"];
[_unit, _event, _args] call _targetStateOnEntry;
};
};
} forEach _transitions;

View File

@ -1 +0,0 @@
#include "\z\ace\addons\medical_state\script_component.hpp"

View File

@ -1,18 +0,0 @@
#define COMPONENT medical_state
#define COMPONENT_BEAUTIFIED Medical State Machine
#include "\z\ace\addons\main\script_mod.hpp"
// #define DEBUG_MODE_FULL
// #define DISABLE_COMPILE_CACHE
// #define CBA_DEBUG_SYNCHRONOUS
// #define ENABLE_PERFORMANCE_COUNTERS
#ifdef DEBUG_ENABLED_MEDICAL_STATE
#define DEBUG_MODE_FULL
#endif
#ifdef DEBUG_SETTINGS_MEDICAL_STATE
#define DEBUG_SETTINGS DEBUG_SETTINGS_MEDICAL_STATE
#endif
#include "\z\ace\addons\main\script_macros.hpp"