diff --git a/addons/medical/functions/fnc_getHeartRateChange.sqf b/addons/medical/functions/fnc_getHeartRateChange.sqf index c2dab052f4..3ccccc2671 100644 --- a/addons/medical/functions/fnc_getHeartRateChange.sqf +++ b/addons/medical/functions/fnc_getHeartRateChange.sqf @@ -4,6 +4,7 @@ * * Arguments: * 0: The Unit + * 1: Time since last update * * ReturnValue: * Change in heart Rate @@ -13,28 +14,24 @@ #include "script_component.hpp" -params ["_unit"]; +params ["_unit", "_deltaT"]; private _hrIncrease = 0; if (!(_unit getVariable [QGVAR(inCardiacArrest),false])) then { + private _hrTargetAdjustment = 0; private _adjustment = _unit getVariable [QGVAR(heartRateAdjustments), []]; { - _x params ["_values", "_time", "_callBack"]; - if (abs _values > 0) then { - if (_time <= 0) then { - _time = 1; - }; - private _change = (_values / _time); - _hrIncrease = _hrIncrease + _change; - - if ( (_time - 1) <= 0) then { - _time = 0; + _x params ["_value", "_timeTillMaxEffect", "_maxTimeInSystem", "_timeInSystem", "_callBack"]; + if (abs _value > 0 && {_maxTimeInSystem > 0}) then { + if (_timeInSystem >= _maxTimeInSystem) then { _adjustment set [_forEachIndex, ObjNull]; [_unit] call _callBack; } else { - _time = _time - 1; - _adjustment set [_forEachIndex, [_values - _change, _time]]; + _timeInSystem = _timeInSystem + _deltaT; + private _effectRatio = (_timeInSystem / (1 max _timeTillMaxEffect)) min 1; + _hrTargetAdjustment = _value * _effectRatio * (_maxTimeInSystem - _timeInSystem) / _maxTimeInSystem; + _x set [3, _timeInSystem]; }; } else { _adjustment set [_forEachIndex, ObjNull]; @@ -44,7 +41,7 @@ if (!(_unit getVariable [QGVAR(inCardiacArrest),false])) then { _adjustment = _adjustment - [ObjNull]; _unit setVariable [QGVAR(heartRateAdjustments), _adjustment]; - + if (!(_unit getVariable [QGVAR(inCardiacArrest), false])) then { private _heartRate = (_unit getVariable [QGVAR(heartRate), 80]); private _bloodVolume = _unit getVariable [QGVAR(bloodVolume), DEFAULT_BLOOD_VOLUME]; @@ -60,11 +57,10 @@ if (!(_unit getVariable [QGVAR(inCardiacArrest),false])) then { _targetBP = _targetBP * (_bloodVolume / DEFAULT_BLOOD_VOLUME); }; if (_hasPain && {_pain > 0.2}) then { - _targetHR = 130; - }; - if (_heartRate < _targetHR) then { - _hrChange = round(_targetHR - _heartRate) / 2; + _targetHR = _targetHR + 50 * _pain; }; + _targetHR = _targetHR + _hrTargetAdjustment; + _hrChange = round(_targetHR - _heartRate) / 2; if ((_meanBP > _targetBP && {_heartRate > _targetHR}) || {_bloodVolume < BLOOD_VOLUME_CLASS_2_HEMORRHAGE && {_heartRate < 200}}) then { _hrChange = 2 * round(_targetBP - _meanBP); if (_hrChange < 0) then { @@ -78,4 +74,4 @@ if (!(_unit getVariable [QGVAR(inCardiacArrest),false])) then { }; }; -_hrIncrease +(_deltaT * _hrIncrease) diff --git a/addons/medical/functions/fnc_handleUnitVitals.sqf b/addons/medical/functions/fnc_handleUnitVitals.sqf index 7bcce0d74e..7775020ff3 100644 --- a/addons/medical/functions/fnc_handleUnitVitals.sqf +++ b/addons/medical/functions/fnc_handleUnitVitals.sqf @@ -88,7 +88,7 @@ private _oldTourniquets = (_unit getVariable [QGVAR(tourniquets), []]) select {_ // Increase pain at a rate of 0.001 units/s per old tourniquet _painStatus = _painStatus + (count _oldTourniquets) * 0.001 * _deltaT; -private _heartRate = (_unit getVariable [QGVAR(heartRate), 80]) + _deltaT * ([_unit] call FUNC(getHeartRateChange)); +private _heartRate = (_unit getVariable [QGVAR(heartRate), 80]) + ([_unit, _deltaT] call FUNC(getHeartRateChange)); _unit setVariable [QGVAR(heartRate), 0 max _heartRate, _syncValues]; private _bloodPressure = [_unit] call FUNC(getBloodPressure); diff --git a/addons/medical_treatment/ACE_Medical_Treatment.hpp b/addons/medical_treatment/ACE_Medical_Treatment.hpp index b89fd72105..2cbcfde16c 100644 --- a/addons/medical_treatment/ACE_Medical_Treatment.hpp +++ b/addons/medical_treatment/ACE_Medical_Treatment.hpp @@ -557,7 +557,7 @@ class ADDON { class Medication { // How much does the pain get reduced? painReduce = 0; - // How much will the heart rate be increased when the HR is low (below 55)? {minIncrease, maxIncrease, seconds} + // How much will the heart rate be increased when the HR is low (below 55)? {minIncrease, maxIncrease, seconds until max. effect} hrIncreaseLow[] = {0, 0, 0}; hrIncreaseNormal[] = {0, 0, 0}; hrIncreaseHigh[] = {0, 0, 0}; diff --git a/addons/medical_treatment/XEH_PREP.hpp b/addons/medical_treatment/XEH_PREP.hpp index 0a7f916447..f6b0cd6be9 100644 --- a/addons/medical_treatment/XEH_PREP.hpp +++ b/addons/medical_treatment/XEH_PREP.hpp @@ -34,6 +34,7 @@ PREP(treatmentFullHealTreatmentTime); PREP(treatmentSurgicalKit_onProgress); // misc +PREP(addHeartRateAdjustment); PREP(addToLog); PREP(addToTriageCard); PREP(addUnloadPatientActions); diff --git a/addons/medical_treatment/functions/fnc_addHeartRateAdjustment.sqf b/addons/medical_treatment/functions/fnc_addHeartRateAdjustment.sqf new file mode 100644 index 0000000000..fb978e5ff0 --- /dev/null +++ b/addons/medical_treatment/functions/fnc_addHeartRateAdjustment.sqf @@ -0,0 +1,26 @@ +/* + * Author: Glowbal, KoffeinFlummi + * Increase the heart rate target of a local unit by given number during the given amount of seconds. + * + * Arguments: + * 0: The unit + * 1: value + * 2: time until max. effect (seconds) + * 3: time in system (seconds) + * 4: callback + * + * Return Value: + * None + * + * Public: Yes + */ + +#include "script_component.hpp" + +params [["_unit", objNull, [objNull]], ["_value", 0, [0]], ["_timeTillMaxEffect", 1, [0]], ["_timeInSystem", 1, [0]], ["_callBack", {}, [{}]]]; + +private _adjustment = _unit getVariable [QEGVAR(medical,heartRateAdjustments), []]; +_adjustment pushBack [_value, _timeTillMaxEffect, _timeInSystem, 0, _callBack]; +_unit setVariable [QEGVAR(medical,heartRateAdjustments), _adjustment]; + +["ace_heartRateAdjustmentAdded", [_unit, _value, _time]] call CBA_fnc_localEvent; diff --git a/addons/medical_treatment/functions/fnc_medicationEffectLoop.sqf b/addons/medical_treatment/functions/fnc_medicationEffectLoop.sqf index f7cdfdad07..a4066cc414 100644 --- a/addons/medical_treatment/functions/fnc_medicationEffectLoop.sqf +++ b/addons/medical_treatment/functions/fnc_medicationEffectLoop.sqf @@ -18,7 +18,7 @@ #include "script_component.hpp" -params ["_unit", "_variableName", "_amountDecreased","_decreaseRate", "_viscosityAdjustmentRate", "_painReduceRate"]; +params ["_unit", "_variableName", "_amountDecreased", "_decreaseRate", "_viscosityAdjustmentRate", "_painReduceRate"]; // If the unit died the loop is finished if (!alive _unit) exitWith {}; diff --git a/addons/medical_treatment/functions/fnc_onMedicationUsage.sqf b/addons/medical_treatment/functions/fnc_onMedicationUsage.sqf index 03b74cffe2..fae5c717f2 100644 --- a/addons/medical_treatment/functions/fnc_onMedicationUsage.sqf +++ b/addons/medical_treatment/functions/fnc_onMedicationUsage.sqf @@ -44,7 +44,7 @@ if (!_foundEntry) then { private _usedMeds = _target getVariable [_variable, 0]; if (_usedMeds >= floor (_maxDosage + round(random(2))) && _maxDosage >= 1) then { - [_target] call EFUNC(medical,setDead); + [QEGVAR(medical,CriticalVitals), _target] call CBA_fnc_localEvent; }; private _hasOverDosed = 0; diff --git a/addons/medical_treatment/functions/fnc_treatmentMedicationLocal.sqf b/addons/medical_treatment/functions/fnc_treatmentMedicationLocal.sqf index d0fc0d58d5..70c4a75d53 100644 --- a/addons/medical_treatment/functions/fnc_treatmentMedicationLocal.sqf +++ b/addons/medical_treatment/functions/fnc_treatmentMedicationLocal.sqf @@ -95,12 +95,12 @@ private _heartRate = _target getVariable [QEGVAR(medical,heartRate), 70]; if (alive _target) then { if (_heartRate > 0) then { if (_heartRate <= 45) then { - [_target, ((_hrIncreaseLow select 0) + random ((_hrIncreaseLow select 1) - (_hrIncreaseLow select 0))), (_hrIncreaseLow select 2), _hrCallback] call FUNC(addHeartRateAdjustment); + [_target, ((_hrIncreaseLow select 0) + random ((_hrIncreaseLow select 1) - (_hrIncreaseLow select 0))), (_hrIncreaseLow select 2), _timeInSystem, _hrCallback] call FUNC(addHeartRateAdjustment); } else { if (_heartRate > 120) then { - [_target, ((_hrIncreaseHigh select 0) + random ((_hrIncreaseHigh select 1) - (_hrIncreaseHigh select 0))), (_hrIncreaseHigh select 2), _hrCallback] call FUNC(addHeartRateAdjustment); + [_target, ((_hrIncreaseHigh select 0) + random ((_hrIncreaseHigh select 1) - (_hrIncreaseHigh select 0))), (_hrIncreaseHigh select 2), _timeInSystem, _hrCallback] call FUNC(addHeartRateAdjustment); } else { - [_target, ((_hrIncreaseNorm select 0) + random ((_hrIncreaseNorm select 1) - (_hrIncreaseNorm select 0))), (_hrIncreaseNorm select 2), _hrCallback] call FUNC(addHeartRateAdjustment); + [_target, ((_hrIncreaseNorm select 0) + random ((_hrIncreaseNorm select 1) - (_hrIncreaseNorm select 0))), (_hrIncreaseNorm select 2), _timeInSystem, _hrCallback] call FUNC(addHeartRateAdjustment); }; }; };