Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Medical - epiBoostsSpontaneousWakeUp #7076

Merged
merged 7 commits into from
Sep 28, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions addons/medical/dev/watchVariable.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -127,27 +127,23 @@ 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;
_peripheralResistanceAdjustment = _peripheralResistanceAdjustment + _flowAdjust * _effectRatio;
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;

Expand Down
9 changes: 9 additions & 0 deletions addons/medical/initSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 6 additions & 0 deletions addons/medical/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
<French>La probabilité pour qu'une unité en état stable puisse reprendre conscience (état vérifié toutes les 15 secondes).</French>
<Portuguese>A probabilidade que uma unidade com vitais estabilizados possa recuperar consciências (verificado a cada 15 segundos)</Portuguese>
</Key>
<Key ID="STR_ACE_Medical_spontaneousWakeUpEpinephrineBoost_DisplayName">
<English>Epinephrine Increases Wake Up Chance</English>
</Key>
<Key ID="STR_ACE_Medical_spontaneousWakeUpEpinephrineBoost_Description">
<English>Increases how often spontaneous wake up checks happen when patient has Epinephrine in their system</English>
PabstMirror marked this conversation as resolved.
Show resolved Hide resolved
</Key>
<Key ID="STR_ACE_Medical_Limping_DisplayName">
<English>Limping</English>
<Russian>Хромота</Russian>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
1 change: 1 addition & 0 deletions addons/medical_status/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PREP(getBloodLoss);
PREP(getBloodPressure);
PREP(getBloodVolumeChange);
PREP(getCardiacOutput);
PREP(getMedicationCount);
PREP(handleKilled);
PREP(hasStableVitals);
PREP(initUnit);
Expand Down
39 changes: 39 additions & 0 deletions addons/medical_status/functions/fnc_getMedicationCount.sqf
Original file line number Diff line number Diff line change
@@ -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 <OBJECT>
* 1: Medication (not case sensitive) <STRING>
* 2: Get raw count (true) or effect ratio (false) <BOOL>(default: true)
*
* Return Value:
* Medication count (float) <NUMBER>
*
* 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
2 changes: 1 addition & 1 deletion addons/medical_treatment/functions/fnc_medicationLocal.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 8 additions & 20 deletions addons/medical_treatment/functions/fnc_onMedicationUsage.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Arguments:
* 0: The patient <OBJECT>
* 1: Medication Treatment classname <STRING>
* 2: Max dosage <NUMBER>
* 2: Max dosage (0 to ignore) <NUMBER>
* 3: Incompatable medication <ARRAY<STRING>>
*
* Return Value:
Expand All @@ -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;
};
Expand Down