From 2fc11d38e0d3a072400673c4b8d7b6cbf0160d33 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 11 Jun 2019 19:25:05 -0500 Subject: [PATCH] Medical - Fix unconsicous problems with minWaitingTime and fullHealLocal (#7030) * Medical - Fix setUnconsicous minWaitingTime * Fix fullHeallocal restoring unconscious with unstable vitals --- addons/medical_statemachine/XEH_preInit.sqf | 2 ++ .../functions/fnc_handleStateUnconscious.sqf | 5 ++-- .../medical_status/functions/fnc_initUnit.sqf | 3 ++ .../functions/fnc_setUnconscious.sqf | 3 +- addons/medical_treatment/XEH_postInit.sqf | 30 +++++++++---------- .../functions/fnc_fullHealLocal.sqf | 17 +++++------ addons/medical_vitals/XEH_preInit.sqf | 2 ++ addons/zeus/functions/fnc_moduleHeal.sqf | 2 +- 8 files changed, 36 insertions(+), 28 deletions(-) diff --git a/addons/medical_statemachine/XEH_preInit.sqf b/addons/medical_statemachine/XEH_preInit.sqf index 2d8754ad32..d77d8067a8 100644 --- a/addons/medical_statemachine/XEH_preInit.sqf +++ b/addons/medical_statemachine/XEH_preInit.sqf @@ -2,7 +2,9 @@ ADDON = false; +PREP_RECOMPILE_START; #include "XEH_PREP.hpp" +PREP_RECOMPILE_END; #include "initSettings.sqf" diff --git a/addons/medical_statemachine/functions/fnc_handleStateUnconscious.sqf b/addons/medical_statemachine/functions/fnc_handleStateUnconscious.sqf index 7bc147e1be..1f124d2682 100644 --- a/addons/medical_statemachine/functions/fnc_handleStateUnconscious.sqf +++ b/addons/medical_statemachine/functions/fnc_handleStateUnconscious.sqf @@ -31,7 +31,7 @@ if (_painLevel > 0) then { // Handle spontaneous wakeup from unconsciousness if (EGVAR(medical,spontaneousWakeUpChance) > 0) then { if (_unit call EFUNC(medical_status,hasStableVitals)) then { - private _lastWakeUpCheck = _unit getVariable [QEGVAR(medical,lastWakeUpCheck), CBA_missionTime]; + private _lastWakeUpCheck = _unit getVariable [QEGVAR(medical,lastWakeUpCheck), 0]; if (CBA_missionTime - _lastWakeUpCheck > SPONTANEOUS_WAKE_UP_INTERVAL) then { TRACE_2("Checking for wake up",_unit,EGVAR(medical,spontaneousWakeUpChance)); _unit setVariable [QEGVAR(medical,lastWakeUpCheck), CBA_missionTime]; @@ -42,6 +42,7 @@ if (EGVAR(medical,spontaneousWakeUpChance) > 0) then { }; } else { // Unstable vitals, procrastinate the next wakeup check - _unit setVariable [QEGVAR(medical,lastWakeUpCheck), CBA_missionTime]; + private _lastWakeUpCheck = _unit getVariable [QEGVAR(medical,lastWakeUpCheck), 0]; + _unit setVariable [QEGVAR(medical,lastWakeUpCheck), _lastWakeUpCheck max CBA_missionTime]; }; }; diff --git a/addons/medical_status/functions/fnc_initUnit.sqf b/addons/medical_status/functions/fnc_initUnit.sqf index 859ea83e80..0dcf1ee7b4 100644 --- a/addons/medical_status/functions/fnc_initUnit.sqf +++ b/addons/medical_status/functions/fnc_initUnit.sqf @@ -72,6 +72,9 @@ if (_isRespawn) then { // medication _unit setVariable [VAR_MEDICATIONS, [], true]; + + // Unconscious spontanious wake up chance + _unit setVariable [QEGVAR(medical,lastWakeUpCheck), nil]; }; [{ diff --git a/addons/medical_status/functions/fnc_setUnconscious.sqf b/addons/medical_status/functions/fnc_setUnconscious.sqf index 5c3a24d759..a7869c6417 100644 --- a/addons/medical_status/functions/fnc_setUnconscious.sqf +++ b/addons/medical_status/functions/fnc_setUnconscious.sqf @@ -27,7 +27,8 @@ _unit setVariable [VAR_UNCON, _active, true]; if (_active) then { // Don't bother setting this if not used if (EGVAR(medical,spontaneousWakeUpChance) > 0) then { - _unit setVariable [QEGVAR(medical,lastWakeUpCheck), CBA_missionTime]; + private _lastWakeUpCheck = _unit getVariable [QEGVAR(medical,lastWakeUpCheck), 0]; // could be set higher from ace_medical_fnc_setUnconscious + _unit setVariable [QEGVAR(medical,lastWakeUpCheck), _lastWakeUpCheck max CBA_missionTime]; }; if (_unit == ACE_player) then { diff --git a/addons/medical_treatment/XEH_postInit.sqf b/addons/medical_treatment/XEH_postInit.sqf index 76222dca57..1896d8d9f1 100644 --- a/addons/medical_treatment/XEH_postInit.sqf +++ b/addons/medical_treatment/XEH_postInit.sqf @@ -13,26 +13,26 @@ [_unit] call FUNC(checkItems); }] call CBA_fnc_addEventHandler; -["loadout", FUNC(checkItems)] call CBA_fnc_addPlayerEventHandler; +["loadout", LINKFUNC(checkItems)] call CBA_fnc_addPlayerEventHandler; // Handle body removal and litter on server if (isServer) then { - [QGVAR(createLitterServer), FUNC(createLitterServer)] call CBA_fnc_addEventHandler; - ["ace_placedInBodyBag", FUNC(removeBody)] call CBA_fnc_addEventHandler; + [QGVAR(createLitterServer), LINKFUNC(createLitterServer)] call CBA_fnc_addEventHandler; + ["ace_placedInBodyBag", LINKFUNC(removeBody)] call CBA_fnc_addEventHandler; }; // Treatment events -[QGVAR(bandageLocal), FUNC(bandageLocal)] call CBA_fnc_addEventHandler; -[QGVAR(checkBloodPressureLocal), FUNC(checkBloodPressureLocal)] call CBA_fnc_addEventHandler; -[QGVAR(checkPulseLocal), FUNC(checkPulseLocal)] call CBA_fnc_addEventHandler; -[QGVAR(cprLocal), FUNC(cprLocal)] call CBA_fnc_addEventHandler; -[QGVAR(fullHealLocal), FUNC(fullHealLocal)] call CBA_fnc_addEventHandler; -[QGVAR(ivBagLocal), FUNC(ivBagLocal)] call CBA_fnc_addEventHandler; -[QGVAR(medicationLocal), FUNC(medicationLocal)] call CBA_fnc_addEventHandler; -[QGVAR(placeInBodyBag), FUNC(placeInBodyBag)] call CBA_fnc_addEventHandler; -[QGVAR(splintLocal), FUNC(splintLocal)] call CBA_fnc_addEventHandler; -[QGVAR(tourniquetLocal), FUNC(tourniquetLocal)] call CBA_fnc_addEventHandler; +[QGVAR(bandageLocal), LINKFUNC(bandageLocal)] call CBA_fnc_addEventHandler; +[QGVAR(checkBloodPressureLocal), LINKFUNC(checkBloodPressureLocal)] call CBA_fnc_addEventHandler; +[QGVAR(checkPulseLocal), LINKFUNC(checkPulseLocal)] call CBA_fnc_addEventHandler; +[QGVAR(cprLocal), LINKFUNC(cprLocal)] call CBA_fnc_addEventHandler; +[QGVAR(fullHealLocal), LINKFUNC(fullHealLocal)] call CBA_fnc_addEventHandler; +[QGVAR(ivBagLocal), LINKFUNC(ivBagLocal)] call CBA_fnc_addEventHandler; +[QGVAR(medicationLocal), LINKFUNC(medicationLocal)] call CBA_fnc_addEventHandler; +[QGVAR(placeInBodyBag), LINKFUNC(placeInBodyBag)] call CBA_fnc_addEventHandler; +[QGVAR(splintLocal), LINKFUNC(splintLocal)] call CBA_fnc_addEventHandler; +[QGVAR(tourniquetLocal), LINKFUNC(tourniquetLocal)] call CBA_fnc_addEventHandler; // Logging events -[QGVAR(addToLog), FUNC(addToLog)] call CBA_fnc_addEventHandler; -[QGVAR(addToTriageCard), FUNC(addToTriageCard)] call CBA_fnc_addEventHandler; +[QGVAR(addToLog), LINKFUNC(addToLog)] call CBA_fnc_addEventHandler; +[QGVAR(addToTriageCard), LINKFUNC(addToTriageCard)] call CBA_fnc_addEventHandler; diff --git a/addons/medical_treatment/functions/fnc_fullHealLocal.sqf b/addons/medical_treatment/functions/fnc_fullHealLocal.sqf index 75ccb26674..d8b53d2718 100644 --- a/addons/medical_treatment/functions/fnc_fullHealLocal.sqf +++ b/addons/medical_treatment/functions/fnc_fullHealLocal.sqf @@ -16,6 +16,7 @@ */ params ["_patient"]; +TRACE_1("fullHealLocal",_patient); if (!alive _patient) exitWith {}; @@ -26,12 +27,6 @@ if IN_CRDC_ARRST(_patient) then { [QEGVAR(medical,CPRSucceeded), _patient] call CBA_fnc_localEvent; }; -if IS_UNCONSCIOUS(_patient) then { - TRACE_1("Waking up",_patient); - // Wake patient up first or unconscious variables will be reset - [QEGVAR(medical,WakeUp), _patient] call CBA_fnc_localEvent; -}; - _patient setVariable [VAR_PAIN, 0, true]; _patient setVariable [VAR_BLOOD_VOL, DEFAULT_BLOOD_VOLUME, true]; @@ -59,9 +54,13 @@ _patient setVariable [QEGVAR(medical,ivBags), nil, true]; // Damage storage _patient setVariable [QEGVAR(medical,bodyPartDamage), [0,0,0,0,0,0], true]; -#ifdef DEBUG_TESTRESULTS -_patient setVariable [QEGVAR(medical,bodyPartStatus), [0,0,0,0,0,0], true]; -#endif + +// wakeup needs to be done after achieving stable vitals, but before manually reseting unconc var +if IS_UNCONSCIOUS(_patient) then { + if (!([_patient] call EFUNC(medical_status,hasStableVitals))) then { WARNING_1("fullheal [%1] did not restore stable vitals",_patient); }; + TRACE_1("Waking up",_patient); + [QEGVAR(medical,WakeUp), _patient] call CBA_fnc_localEvent; +}; // Generic medical admin _patient setVariable [VAR_CRDC_ARRST, false, true]; diff --git a/addons/medical_vitals/XEH_preInit.sqf b/addons/medical_vitals/XEH_preInit.sqf index a7feade1c3..b47cf6628d 100644 --- a/addons/medical_vitals/XEH_preInit.sqf +++ b/addons/medical_vitals/XEH_preInit.sqf @@ -2,6 +2,8 @@ ADDON = false; +PREP_RECOMPILE_START; #include "XEH_PREP.hpp" +PREP_RECOMPILE_END; ADDON = true; diff --git a/addons/zeus/functions/fnc_moduleHeal.sqf b/addons/zeus/functions/fnc_moduleHeal.sqf index 287a84ac79..627c48ef36 100644 --- a/addons/zeus/functions/fnc_moduleHeal.sqf +++ b/addons/zeus/functions/fnc_moduleHeal.sqf @@ -45,7 +45,7 @@ switch (false) do { // Heal validated target if (["ace_medical"] call EFUNC(common,isModLoaded)) then { TRACE_1("healing with ace_medical",_unit); - [QEGVAR(medical_treatment,treatmentFullHealLocal), [_unit], _unit] call CBA_fnc_targetEvent; + [QEGVAR(medical_treatment,fullHealLocal), [_unit], _unit] call CBA_fnc_targetEvent; } else { // BI's scripted revive system if ((missionNamespace getVariable ["bis_revive_mode", 0]) != 0) then {