Skip to content

Commit ad703fd

Browse files
PabstMirrorrautamiekkajohnb432
authored
Medical Statemachine - Optimize medical handling for uninjured AI units (#11101)
* Medical Statemachine - Optimize medical handling for uninjured AI units * reset vitals deltaT * fix locality, doc * Update medical-framework.md * Update docs/wiki/framework/medical-framework.md Co-authored-by: Jouni Järvinen <rautamiekka@users.noreply.github.com> * Activate on calls to ace_medical_fnc APIs * Update fnc_fullHeal.sqf * ace_medical_statemachine_fnc_checkForMedicalActivity * Update fnc_deserializeState.sqf * move to engine * Update script_component.hpp * Apply suggestion from @PabstMirror * checkForMedicalActivity and add note to not change * Update docs/wiki/framework/medical-framework.md Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> --------- Co-authored-by: Jouni Järvinen <rautamiekka@users.noreply.github.com> Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
1 parent 714d2b9 commit ad703fd

File tree

12 files changed

+101
-0
lines changed

12 files changed

+101
-0
lines changed

addons/medical/functions/fnc_adjustPainLevel.sqf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ params ["_unit", "_addedPain"];
2121

2222
if (!local _unit) exitWith { ERROR_1("unit [%1] is not local",_unit); };
2323

24+
if (!IS_MEDICAL_ACTIVITY(_unit)) then { [QGVAR(activateMedical), _unit] call CBA_fnc_localEvent; };
25+
2426
private _pain = GET_PAIN(_unit);
2527

2628
_pain = 0 max (_pain + _addedPain) min 1;

addons/medical/functions/fnc_deserializeState.sqf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,7 @@ if (_currentState in ["Unconscious", "CardiacArrest"] && {_targetState in ["Defa
125125
[_unit, false] call EFUNC(medical_status,setUnconsciousState);
126126
};
127127

128+
// Manually activate if non-defaults are present
129+
[_unit] call EFUNC(medical_engine,checkForMedicalActivity);
130+
128131
_state call CBA_fnc_deleteNamespace;

addons/medical/functions/fnc_fullHeal.sqf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ if (!alive _patient) exitWith {
2727
ERROR_2("fullHeal [medic %1][patient %2] Patient is dead or null",_medic,_patient);
2828
};
2929

30+
if (!IS_MEDICAL_ACTIVITY(_patient)) then { [QGVAR(activateMedical), _patient, _patient] call CBA_fnc_targetEvent; };
31+
3032
[_medic, _patient, "", "", objNull, "", false, _logMessage] call EFUNC(medical_treatment,fullHeal);

addons/medical/functions/fnc_setUnconscious.sqf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ if (_knockOut isEqualTo IS_UNCONSCIOUS(_unit)) exitWith {
4343
false
4444
};
4545

46+
if (!IS_MEDICAL_ACTIVITY(_unit)) then { [QGVAR(activateMedical), _unit] call CBA_fnc_localEvent; };
47+
4648
if (currentWeapon _unit != primaryWeapon _unit) then {
4749
_unit selectWeapon primaryWeapon _unit;
4850
};

addons/medical_engine/XEH_PREP.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
PREP(applyAnimAfterRagdoll);
2+
PREP(checkForMedicalActivity);
23
PREP(damageBodyPart);
34
PREP(disableThirdParty);
45
PREP(getHitpointArmor);

addons/medical_engine/XEH_postInit.sqf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
["CAManBase", "init", {
1010
params ["_unit"];
11+
[LINKFUNC(checkForMedicalActivity), _unit, 2] call CBA_fnc_waitAndExecute;
1112

1213
if (unitIsUAV _unit) exitWith {TRACE_1("ignore UAV AI",typeOf _unit);};
1314
if (getNumber (configOf _unit >> "isPlayableLogic") == 1) exitWith {TRACE_1("ignore logic unit",typeOf _unit);};

addons/medical_engine/XEH_preInit.sqf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ if (isNil QUOTE(PAIN_FADE_TIME)) then {PAIN_FADE_TIME = PAIN_FADE_TIME_DEFAULT};
2020
if (isNil QUOTE(LIMPING_DAMAGE_THRESHOLD)) then {LIMPING_DAMAGE_THRESHOLD = LIMPING_DAMAGE_THRESHOLD_DEFAULT};
2121
if (isNil QUOTE(FRACTURE_DAMAGE_THRESHOLD)) then {FRACTURE_DAMAGE_THRESHOLD = FRACTURE_DAMAGE_THRESHOLD_DEFAULT};
2222
if (isNil QUOTE(CARDIAC_OUTPUT_MIN)) then {CARDIAC_OUTPUT_MIN = CARDIAC_OUTPUT_MIN_DEFAULT};
23+
if (isNil QUOTE(MEDICAL_ACTIVITY)) then {MEDICAL_ACTIVITY = MEDICAL_ACTIVITY_DEFAULT};
2324
// Derive the alternate fatal damage coefficients
2425
if (isNil QUOTE(FATAL_SUM_DAMAGE_WEIBULL_K) || isNil QUOTE(FATAL_SUM_DAMAGE_WEIBULL_L)) then {
2526
private _x1 = 0.5;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include "..\script_component.hpp"
2+
/*
3+
* Author: PabstMirror
4+
* Checks for scripted medical activity on a unit
5+
*
6+
* Arguments:
7+
* 0: Unit <OBJECT>
8+
*
9+
* Return Value:
10+
* None
11+
*
12+
* Example:
13+
* [player] call ace_medical_engine_fnc_checkForMedicalActivity
14+
*
15+
* Public: No
16+
*/
17+
params ["_unit"];
18+
TRACE_1("checkForMedicalActivity",_unit);
19+
20+
if (!alive _unit || {!local _unit}) exitWith {};
21+
if (IS_MEDICAL_ACTIVITY(_unit)) exitWith {};
22+
23+
{
24+
_x params ["_var", "_default"];
25+
if (_unit isNil _var) then { continue };
26+
private _current = _unit getVariable [_var, _default];
27+
if (_current isNotEqualTo _default) exitWith {
28+
TRACE_2("unit has non-defaults",_unit,_var);
29+
[QEGVAR(medical,activateMedical), _unit] call CBA_fnc_localEvent;
30+
};
31+
} forEach [
32+
[VAR_BLOOD_VOL, DEFAULT_BLOOD_VOLUME],
33+
[VAR_HEART_RATE, DEFAULT_HEART_RATE],
34+
[VAR_BLOOD_PRESS, [80, 120]],
35+
[VAR_HEMORRHAGE, 0],
36+
[VAR_PAIN, 0],
37+
[VAR_PAIN_SUPP, 0],
38+
[VAR_OPEN_WOUNDS, createHashMap],
39+
[VAR_BANDAGED_WOUNDS, createHashMap],
40+
[VAR_STITCHED_WOUNDS, createHashMap],
41+
[VAR_FRACTURES, DEFAULT_FRACTURE_VALUES],
42+
[VAR_TOURNIQUET, DEFAULT_TOURNIQUET_VALUES],
43+
[VAR_MEDICATIONS, []],
44+
[QEGVAR(medical,occludedMedications), []],
45+
[QEGVAR(medical,ivBags), []],
46+
[VAR_BODYPART_DAMAGE, DEFAULT_BODYPART_DAMAGE_VALUES]
47+
];
48+

addons/medical_engine/script_macros_medical.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,9 @@
223223

224224
// Ignore UAV/Drone AI Base Classes
225225
#define IGNORE_BASE_UAVPILOTS "B_UAV_AI", "O_UAV_AI", "UAV_AI_base_F"
226+
227+
// Medical Activity (optimization for AI)
228+
#define VAR_MEDICAL_ACTIVITY QEGVAR(medical,medicalActivity)
229+
#define MEDICAL_ACTIVITY EGVAR(medical,const_medicalActivity)
230+
#define MEDICAL_ACTIVITY_DEFAULT false
231+
#define IS_MEDICAL_ACTIVITY(unit) (unit getVariable [VAR_MEDICAL_ACTIVITY, MEDICAL_ACTIVITY])

addons/medical_statemachine/XEH_postInit.sqf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,26 @@
1212
[{_this enableSimulation true}, _unit, 2] call CBA_fnc_waitAndExecute;
1313
};
1414
}] call CBA_fnc_addEventHandler;
15+
16+
17+
[QEGVAR(medical,activateMedical), { // should be called where unit is local
18+
params ["_unit"];
19+
_unit setVariable [VAR_MEDICAL_ACTIVITY, true, true];
20+
TRACE_2("activating medical",_unit,typeOf _unit);
21+
// Because vitals loop has never run, set to 1 second ago to avoid large time delta (would hit max of 10 seconds)
22+
if (_unit isNil QEGVAR(medical_vitals,lastTimeUpdated)) then {
23+
_unit setVariable [QEGVAR(medical_vitals,lastTimeUpdated), CBA_missionTime - 1];
24+
};
25+
}] call CBA_fnc_addEventHandler;
26+
[QEGVAR(medical,woundReceived), {
27+
params ["_unit"];
28+
if (!IS_MEDICAL_ACTIVITY(_unit)) then {
29+
[QEGVAR(medical,activateMedical), _unit] call CBA_fnc_localEvent;
30+
};
31+
}] call CBA_fnc_addEventHandler;
32+
["ace_treatmentStarted", {
33+
params ["", "_patient"];
34+
if (!IS_MEDICAL_ACTIVITY(_patient)) then {
35+
[QEGVAR(medical,activateMedical), _patient, _patient] call CBA_fnc_targetEvent;
36+
};
37+
}] call CBA_fnc_addEventHandler;

0 commit comments

Comments
 (0)