From d6507cf1193fab5763585b85e2591b6b87689def Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sat, 28 Sep 2019 16:11:32 -0500 Subject: [PATCH] Medical - epiBoostsSpontaneousWakeUp (#7076) * Medical - epiBoostsSpontaneousWakeUp * Update initSettings.sqf * Move setting, add strings * Update initSettings.sqf * Update addons/medical/stringtable.xml Co-Authored-By: mharis001 <34453221+mharis001@users.noreply.github.com> --- addons/medical/dev/watchVariable.sqf | 18 ++++----- addons/medical/initSettings.sqf | 9 +++++ addons/medical/stringtable.xml | 6 +++ .../functions/fnc_handleStateUnconscious.sqf | 8 +++- addons/medical_status/XEH_PREP.hpp | 1 + .../functions/fnc_getMedicationCount.sqf | 39 +++++++++++++++++++ .../functions/fnc_medicationLocal.sqf | 2 +- .../functions/fnc_onMedicationUsage.sqf | 28 ++++--------- 8 files changed, 78 insertions(+), 33 deletions(-) create mode 100644 addons/medical_status/functions/fnc_getMedicationCount.sqf diff --git a/addons/medical/dev/watchVariable.sqf b/addons/medical/dev/watchVariable.sqf index 36cc690936..b09a0f7144 100644 --- a/addons/medical/dev/watchVariable.sqf +++ b/addons/medical/dev/watchVariable.sqf @@ -127,17 +127,11 @@ GVAR(dev_watchVariableRunning) = true; private _hrTargetAdjustment = 0; private _painSupressAdjustment = 0; private _peripheralResistanceAdjustment = 0; - private _medicationCounts = []; + private _uniqueMedications = []; private _rawMedications = (_unit getVariable [VAR_MEDICATIONS, []]) apply { _x params ["_medication", "_timeAdded", "_timeTillMaxEffect", "_maxTimeInSystem", "_hrAdjust", "_painAdjust", "_flowAdjust"]; + _uniqueMedications pushBackUnique _medication; private _timeInSystem = CBA_missionTime - _timeAdded; - private _index = _medicationCounts find _medication; - if (_index < 0) then { - _index = _medicationCounts pushBack _medication; - _medicationCounts pushBack 0 - }; - _medicationCounts set [(_index + 1), (_medicationCounts select (_index + 1)) + linearConversion [_timeTillMaxEffect, _maxTimeInSystem, _timeInSystem, 1, 0, true]]; - private _effectRatio = (((_timeInSystem / _timeTillMaxEffect) ^ 2) min 1) * (_maxTimeInSystem - _timeInSystem) / _maxTimeInSystem; _hrTargetAdjustment = _hrTargetAdjustment + _hrAdjust * _effectRatio; _painSupressAdjustment = _painSupressAdjustment + _painAdjust * _effectRatio; @@ -145,9 +139,11 @@ GVAR(dev_watchVariableRunning) = true; format ["%1 [%2 / %3][%4][%5,%6,%7]",_medication,_timeInSystem toFixed 0,_maxTimeInSystem toFixed 0, _effectRatio toFixed 2, _hrAdjust toFixed 1, _painAdjust toFixed 2, _flowAdjust toFixed 1]; }; _return pushBack format ["Adjusts: [HR %1][PS %2][PR %3]", _hrTargetAdjustment toFixed 2, _painSupressAdjustment toFixed 2, _peripheralResistanceAdjustment toFixed 2]; - for "_i" from 0 to (count _medicationCounts) - 1 step 2 do { - _return pushBack format ["-%1: %2", _medicationCounts select _i, _medicationCounts select _i + 1]; - }; + { + private _medicationCount = [_unit, _x, true] call EFUNC(medical_status,getMedicationCount); + private _medicationEffectiveness = [_unit, _x, false] call EFUNC(medical_status,getMedicationCount); + _return pushBack format ["-%1: C: %2 - E: %3", _x, _medicationCount toFixed 2, _medicationEffectiveness toFixed 2]; + } forEach _uniqueMedications; _return pushBack "------- Medications Raw: -------"; _return append _rawMedications; diff --git a/addons/medical/initSettings.sqf b/addons/medical/initSettings.sqf index 9b1aee8464..6eaed9623a 100644 --- a/addons/medical/initSettings.sqf +++ b/addons/medical/initSettings.sqf @@ -28,3 +28,12 @@ [0, 1, 0.05, 2], true ] call CBA_settings_fnc_init; + +[ + QGVAR(spontaneousWakeUpEpinephrineBoost), + "SLIDER", + [LSTRING(spontaneousWakeUpEpinephrineBoost_DisplayName), LSTRING(spontaneousWakeUpEpinephrineBoost_Description)], + LSTRING(Category), + [1, 30, 1, 1], + true +] call CBA_settings_fnc_init; diff --git a/addons/medical/stringtable.xml b/addons/medical/stringtable.xml index da4684dfa9..39bcf9b56a 100644 --- a/addons/medical/stringtable.xml +++ b/addons/medical/stringtable.xml @@ -33,6 +33,12 @@ La probabilité pour qu'une unité en état stable puisse reprendre conscience (état vérifié toutes les 15 secondes). A probabilidade que uma unidade com vitais estabilizados possa recuperar consciências (verificado a cada 15 segundos) + + Epinephrine Increases Wake Up Chance + + + Increases how often spontaneous wake up checks happen when patient has Epinephrine in their system. + Limping Хромота diff --git a/addons/medical_statemachine/functions/fnc_handleStateUnconscious.sqf b/addons/medical_statemachine/functions/fnc_handleStateUnconscious.sqf index 9968e26645..5fb94333c2 100644 --- a/addons/medical_statemachine/functions/fnc_handleStateUnconscious.sqf +++ b/addons/medical_statemachine/functions/fnc_handleStateUnconscious.sqf @@ -39,7 +39,13 @@ if (EGVAR(medical,spontaneousWakeUpChance) > 0) then { _unit setVariable [QEGVAR(medical,lastWakeUpCheck), CBA_missionTime]; }; - if (CBA_missionTime - _lastWakeUpCheck > SPONTANEOUS_WAKE_UP_INTERVAL) then { + private _wakeUpCheckInterval = SPONTANEOUS_WAKE_UP_INTERVAL; + if (EGVAR(medical,spontaneousWakeUpEpinephrineBoost) > 1) then { + private _epiEffectiveness = [_unit, "Epinephrine", false] call EFUNC(medical_status,getMedicationCount); + _wakeUpCheckInterval = _wakeUpCheckInterval * linearConversion [0, 1, _epiEffectiveness, 1, 1 / EGVAR(medical,spontaneousWakeUpEpinephrineBoost), true]; + TRACE_2("epiBoost",_epiEffectiveness,_wakeUpCheckInterval); + }; + if (CBA_missionTime - _lastWakeUpCheck > _wakeUpCheckInterval) then { TRACE_2("Checking for wake up",_unit,EGVAR(medical,spontaneousWakeUpChance)); _unit setVariable [QEGVAR(medical,lastWakeUpCheck), CBA_missionTime]; diff --git a/addons/medical_status/XEH_PREP.hpp b/addons/medical_status/XEH_PREP.hpp index 18f5ee699a..5d5f2f464c 100644 --- a/addons/medical_status/XEH_PREP.hpp +++ b/addons/medical_status/XEH_PREP.hpp @@ -4,6 +4,7 @@ PREP(getBloodLoss); PREP(getBloodPressure); PREP(getBloodVolumeChange); PREP(getCardiacOutput); +PREP(getMedicationCount); PREP(handleKilled); PREP(hasStableVitals); PREP(initUnit); diff --git a/addons/medical_status/functions/fnc_getMedicationCount.sqf b/addons/medical_status/functions/fnc_getMedicationCount.sqf new file mode 100644 index 0000000000..5c8b3bfd57 --- /dev/null +++ b/addons/medical_status/functions/fnc_getMedicationCount.sqf @@ -0,0 +1,39 @@ +#include "script_component.hpp" +/* + * Author: PabstMirror + * Gets effective count of medications in a unit's system + * (each medication dose is scaled from 0..1 based on time till max effect and max time in system) + * + * Arguments: + * 0: The patient + * 1: Medication (not case sensitive) + * 2: Get raw count (true) or effect ratio (false) (default: true) + * + * Return Value: + * Medication count (float) + * + * Example: + * [player, "Epinephrine"] call ace_medical_status_fnc_getMedicationCount + * + * Public: No + */ + +params ["_target", "_medication", ["_getCount", true]]; + +private _return = 0; +{ + _x params ["_xMed", "_timeAdded", "_timeTillMaxEffect", "_maxTimeInSystem"]; + if (_xMed == _medication) then { + private _timeInSystem = CBA_missionTime - _timeAdded; + if (_getCount) then { + // just return effective count, a medication will always start at 1 and only drop after reaching timeTilMaxEffect + _return = _return + linearConversion [_timeTillMaxEffect, _maxTimeInSystem, _timeInSystem, 1, 0, true]; + } else { + // as used in handleUnitVitals, a medication effectiveness will start low, ramp up to timeTillMaxEffect, and then drop off + _return = _return + (((_timeInSystem / _timeTillMaxEffect) ^ 2) min 1) * (_maxTimeInSystem - _timeInSystem) / _maxTimeInSystem; + }; + }; +} forEach (_target getVariable [VAR_MEDICATIONS, []]); + +TRACE_4("getMedicationCount",_target,_medication,_getCount,_return); +_return diff --git a/addons/medical_treatment/functions/fnc_medicationLocal.sqf b/addons/medical_treatment/functions/fnc_medicationLocal.sqf index 30b64860e6..bb14e14b5b 100644 --- a/addons/medical_treatment/functions/fnc_medicationLocal.sqf +++ b/addons/medical_treatment/functions/fnc_medicationLocal.sqf @@ -38,7 +38,7 @@ if (!GVAR(advancedMedication)) exitWith { }; }; }; -TRACE_1("Running treatmentMedicationLocal with Advanced configuration for", _target); +TRACE_1("Running treatmentMedicationLocal with Advanced configuration for",_patient); // Handle tourniquet on body part blocking blood flow at injection site diff --git a/addons/medical_treatment/functions/fnc_onMedicationUsage.sqf b/addons/medical_treatment/functions/fnc_onMedicationUsage.sqf index 9784acb1ab..1f9ef981dd 100644 --- a/addons/medical_treatment/functions/fnc_onMedicationUsage.sqf +++ b/addons/medical_treatment/functions/fnc_onMedicationUsage.sqf @@ -6,7 +6,7 @@ * Arguments: * 0: The patient * 1: Medication Treatment classname - * 2: Max dosage + * 2: Max dosage (0 to ignore) * 3: Incompatable medication > * * Return Value: @@ -21,33 +21,21 @@ params ["_target", "_className", "_maxDosage", "_incompatibleMedication"]; TRACE_4("onMedicationUsage",_target,_className,_maxDosage,_incompatibleMedication); -private _fnc_getMedicationCount = { - params ["_target", "_medication"]; - private _return = 0; - { - _x params ["_xMed", "_timeAdded", "_timeTillMaxEffect", "_maxTimeInSystem"]; - if (_xMed == _medication) then { - private _timeInSystem = CBA_missionTime - _timeAdded; - _return = _return + linearConversion [_timeTillMaxEffect, _maxTimeInSystem, _timeInSystem, 1, 0, true]; - }; - } forEach (_target getVariable [VAR_MEDICATIONS, []]); - TRACE_2("getMedicationCount",_medication,_return); - _return -}; - private _overdosedMedications = []; // Check for overdose from current medication -private _currentDose = [_target, _className] call _fnc_getMedicationCount; -if (_currentDose >= floor (_maxDosage + round(random(2))) && {_maxDosage >= 1}) then { - TRACE_1("exceeded max dose",_currentDose); - _overdosedMedications pushBackUnique _className; +if (_maxDosage > 0) then { + private _currentDose = [_target, _className] call EFUNC(medical_status,getMedicationCount); + if (_currentDose >= floor (_maxDosage + round(random(2)))) then { + TRACE_1("exceeded max dose",_currentDose); + _overdosedMedications pushBackUnique _className; + }; }; // Check incompatible medication (format [med,limit]) { _x params ["_xMed", "_xLimit"]; - private _inSystem = [_target, _xMed] call _fnc_getMedicationCount; + private _inSystem = [_target, _xMed] call EFUNC(medical_status,getMedicationCount); if (_inSystem> _xLimit) then { _overdosedMedications pushBackUnique _xMed; };