2015-02-08 09:01:32 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal
|
2016-12-06 19:42:10 +00:00
|
|
|
* Update the heart rate
|
2015-02-07 22:55:48 +00:00
|
|
|
*
|
2015-02-08 09:01:32 +00:00
|
|
|
* Arguments:
|
|
|
|
* 0: The Unit <OBJECT>
|
2016-12-06 11:58:12 +00:00
|
|
|
* 1: Time since last update <NUMBER>
|
2016-12-06 19:42:10 +00:00
|
|
|
* 2: Sync value? <BOOL>
|
2015-02-08 09:01:32 +00:00
|
|
|
*
|
|
|
|
* ReturnValue:
|
2017-04-22 15:57:32 +00:00
|
|
|
* Current Heart Rate <NUMBER>
|
|
|
|
*
|
|
|
|
* Example:
|
2018-05-08 08:17:47 +00:00
|
|
|
* [player, 1, false] call ace_medical_vitals_fnc_updateHeartRate
|
2015-02-08 09:01:32 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
2015-02-07 22:55:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2016-12-06 19:42:10 +00:00
|
|
|
params ["_unit", "_deltaT", "_syncValue"];
|
2015-02-07 22:55:48 +00:00
|
|
|
|
2016-12-06 16:26:11 +00:00
|
|
|
private _hrTargetAdjustment = 0;
|
|
|
|
private _adjustment = _unit getVariable [QGVAR(heartRateAdjustments), []];
|
2016-12-06 19:42:10 +00:00
|
|
|
|
|
|
|
if (!(_adjustment isEqualTo [])) then {
|
|
|
|
{
|
|
|
|
_x params ["_value", "_timeTillMaxEffect", "_maxTimeInSystem", "_timeInSystem"];
|
|
|
|
if (abs _value > 0 && {_maxTimeInSystem > 0}) then {
|
|
|
|
if (_timeInSystem >= _maxTimeInSystem) then {
|
2017-04-22 15:57:32 +00:00
|
|
|
_adjustment set [_forEachIndex, ObjNull];
|
2016-12-06 19:42:10 +00:00
|
|
|
} else {
|
|
|
|
_timeInSystem = _timeInSystem + _deltaT;
|
|
|
|
private _effectRatio = ((_timeInSystem / (1 max _timeTillMaxEffect)) ^ 2) min 1;
|
|
|
|
_hrTargetAdjustment = _hrTargetAdjustment + _value * _effectRatio * (_maxTimeInSystem - _timeInSystem) / _maxTimeInSystem;
|
|
|
|
_x set [3, _timeInSystem];
|
|
|
|
};
|
2015-02-07 22:55:48 +00:00
|
|
|
} else {
|
2016-12-06 19:42:10 +00:00
|
|
|
_adjustment set [_forEachIndex, ObjNull];
|
2015-02-07 22:55:48 +00:00
|
|
|
};
|
2016-12-06 19:42:10 +00:00
|
|
|
} forEach _adjustment;
|
2016-06-13 00:34:56 +00:00
|
|
|
|
2016-12-06 19:42:10 +00:00
|
|
|
_adjustment = _adjustment - [ObjNull];
|
|
|
|
_unit setVariable [QGVAR(heartRateAdjustments), _adjustment, _syncValue];
|
|
|
|
};
|
|
|
|
|
2018-05-08 09:16:12 +00:00
|
|
|
private _heartRate = GET_HEART_RATE(_unit);
|
2016-12-06 16:26:11 +00:00
|
|
|
|
|
|
|
if (!(_unit getVariable [QGVAR(inCardiacArrest), false])) then {
|
2016-12-06 19:42:10 +00:00
|
|
|
private _hrChange = 0;
|
2016-12-06 16:26:11 +00:00
|
|
|
private _bloodVolume = _unit getVariable [QGVAR(bloodVolume), DEFAULT_BLOOD_VOLUME];
|
|
|
|
if (_bloodVolume > BLOOD_VOLUME_CLASS_4_HEMORRHAGE) then {
|
2018-05-08 08:28:16 +00:00
|
|
|
GET_BLOOD_PRESSURE(_unit) params ["_bloodPressureL", "_bloodPressureH"];
|
2016-12-06 16:26:11 +00:00
|
|
|
private _meanBP = (2/3) * _bloodPressureH + (1/3) * _bloodPressureL;
|
2018-05-08 07:47:03 +00:00
|
|
|
private _painLevel = GET_PAIN_PERCEIVED(_unit);
|
2017-04-22 15:57:32 +00:00
|
|
|
|
2016-12-06 16:26:11 +00:00
|
|
|
private _targetBP = 107;
|
|
|
|
if (_bloodVolume < BLOOD_VOLUME_CLASS_3_HEMORRHAGE) then {
|
|
|
|
_targetBP = _targetBP * (_bloodVolume / DEFAULT_BLOOD_VOLUME);
|
|
|
|
};
|
2017-04-22 15:57:32 +00:00
|
|
|
|
2016-12-06 16:40:05 +00:00
|
|
|
private _targetHR = 80;
|
2016-12-06 16:26:11 +00:00
|
|
|
if (_bloodVolume < BLOOD_VOLUME_CLASS_2_HEMORRHAGE) then {
|
|
|
|
_targetHR = _heartRate * (_targetBP / (45 max _meanBP));
|
|
|
|
};
|
|
|
|
if (_painLevel > 0.2) then {
|
|
|
|
_targetHR = _targetHR max (80 + 50 * _painLevel);
|
|
|
|
};
|
2016-12-06 16:40:05 +00:00
|
|
|
_targetHR = _targetHR + _hrTargetAdjustment;
|
2017-04-22 15:57:32 +00:00
|
|
|
|
2016-12-06 16:26:11 +00:00
|
|
|
_hrChange = round(_targetHR - _heartRate) / 2;
|
|
|
|
} else {
|
2016-12-06 19:42:10 +00:00
|
|
|
_hrChange = -round(_heartRate / 10);
|
2015-02-07 22:55:48 +00:00
|
|
|
};
|
2017-04-22 15:57:32 +00:00
|
|
|
_heartRate = (_heartRate + _deltaT * _hrChange) max 0;
|
2015-02-07 22:55:48 +00:00
|
|
|
};
|
2016-12-05 20:34:20 +00:00
|
|
|
|
2018-05-08 09:16:12 +00:00
|
|
|
SET_HEART_RATE(_unit,_heartRate,_syncValue);
|
2017-04-22 15:57:32 +00:00
|
|
|
|
|
|
|
_heartRate
|
|
|
|
|