2015-02-08 09:01:32 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal
|
2017-04-22 15:57:32 +00:00
|
|
|
* Updates the vitals. Called from the statemachine's onState functions.
|
2015-02-07 22:55:48 +00:00
|
|
|
*
|
2015-02-08 09:01:32 +00:00
|
|
|
* Arguments:
|
|
|
|
* 0: The Unit <OBJECT>
|
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2018-05-08 08:17:47 +00:00
|
|
|
* [player] call ace_medical_vitals_fnc_handleUnitVitals
|
2017-04-22 15:57:32 +00:00
|
|
|
*
|
2015-02-08 09:01:32 +00:00
|
|
|
* Public: No
|
2015-02-07 22:55:48 +00:00
|
|
|
*/
|
2017-04-22 15:57:32 +00:00
|
|
|
// #define DEBUG_MODE_FULL
|
2015-02-07 22:55:48 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2016-12-05 20:34:20 +00:00
|
|
|
params ["_unit"];
|
2016-10-12 19:59:32 +00:00
|
|
|
|
2017-04-22 15:57:32 +00:00
|
|
|
private _lastTimeUpdated = _unit getVariable [QGVAR(lastTimeUpdated), 0];
|
|
|
|
private _deltaT = (CBA_missionTime - _lastTimeUpdated) min 10;
|
|
|
|
if (_deltaT < 1) exitWith {}; // state machines could be calling this very rapidly depending on number of local units
|
2016-12-05 20:34:20 +00:00
|
|
|
|
2017-04-26 15:16:09 +00:00
|
|
|
BEGIN_COUNTER(Vitals);
|
|
|
|
|
|
|
|
_unit setVariable [QGVAR(lastTimeUpdated), CBA_missionTime];
|
2016-06-13 00:11:21 +00:00
|
|
|
private _lastTimeValuesSynced = _unit getVariable [QGVAR(lastMomentValuesSynced), 0];
|
2016-12-05 20:34:20 +00:00
|
|
|
private _syncValues = (CBA_missionTime - _lastTimeValuesSynced) >= (10 + floor(random(10)));
|
2016-10-12 19:59:32 +00:00
|
|
|
|
2015-03-08 12:56:24 +00:00
|
|
|
if (_syncValues) then {
|
2016-03-02 10:01:39 +00:00
|
|
|
_unit setVariable [QGVAR(lastMomentValuesSynced), CBA_missionTime];
|
2015-03-08 12:56:24 +00:00
|
|
|
};
|
|
|
|
|
2018-05-08 09:16:12 +00:00
|
|
|
private _bloodVolume = (_unit getVariable [QGVAR(bloodVolume), DEFAULT_BLOOD_VOLUME]) + ([_unit, _deltaT, _syncValues] call EFUNC(medical_status,getBloodVolumeChange));
|
2016-12-05 20:34:20 +00:00
|
|
|
_bloodVolume = 0 max _bloodVolume min DEFAULT_BLOOD_VOLUME;
|
2015-04-14 18:40:38 +00:00
|
|
|
|
2016-12-05 20:34:20 +00:00
|
|
|
// @todo: replace this and the rest of the setVariable with EFUNC(common,setApproximateVariablePublic)
|
2015-11-30 16:27:09 +00:00
|
|
|
_unit setVariable [QGVAR(bloodVolume), _bloodVolume, _syncValues];
|
2015-02-07 22:55:48 +00:00
|
|
|
|
|
|
|
// Set variables for synchronizing information across the net
|
2016-12-05 20:34:20 +00:00
|
|
|
if (_bloodVolume < BLOOD_VOLUME_CLASS_1_HEMORRHAGE) then {
|
|
|
|
if (_bloodVolume < BLOOD_VOLUME_CLASS_3_HEMORRHAGE) then {
|
2015-11-30 16:27:09 +00:00
|
|
|
if (_unit getVariable [QGVAR(hasLostBlood), 0] != 2) then {
|
|
|
|
_unit setVariable [QGVAR(hasLostBlood), 2, true];
|
2015-04-28 18:47:11 +00:00
|
|
|
};
|
|
|
|
} else {
|
2015-11-30 16:27:09 +00:00
|
|
|
if (_unit getVariable [QGVAR(hasLostBlood), 0] != 1) then {
|
|
|
|
_unit setVariable [QGVAR(hasLostBlood), 1, true];
|
2015-04-28 18:47:11 +00:00
|
|
|
};
|
2016-06-13 10:18:56 +00:00
|
|
|
};
|
2015-02-07 22:55:48 +00:00
|
|
|
} else {
|
2015-11-30 16:27:09 +00:00
|
|
|
if (_unit getVariable [QGVAR(hasLostBlood), 0] != 0) then {
|
|
|
|
_unit setVariable [QGVAR(hasLostBlood), 0, true];
|
2015-02-07 22:55:48 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-04-27 15:03:55 +00:00
|
|
|
private _bloodLoss = GET_BLOOD_LOSS(_unit);
|
2016-09-18 17:48:49 +00:00
|
|
|
if (_bloodLoss > 0) then {
|
|
|
|
_unit setVariable [QGVAR(bloodloss), _bloodLoss, _syncValues];
|
|
|
|
|
2016-12-05 20:34:20 +00:00
|
|
|
[QGVAR(Injury), _unit] call CBA_fnc_localEvent;
|
2016-10-12 19:59:32 +00:00
|
|
|
|
2015-11-30 16:27:09 +00:00
|
|
|
if !(_unit getVariable [QGVAR(isBleeding), false]) then {
|
|
|
|
_unit setVariable [QGVAR(isBleeding), true, true];
|
2015-02-07 22:55:48 +00:00
|
|
|
};
|
|
|
|
} else {
|
2015-11-30 16:27:09 +00:00
|
|
|
if (_unit getVariable [QGVAR(isBleeding), false]) then {
|
|
|
|
_unit setVariable [QGVAR(isBleeding), false, true];
|
2015-02-07 22:55:48 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-05-08 07:47:03 +00:00
|
|
|
private _painLevel = GET_PAIN_PERCEIVED(_unit);
|
2016-12-06 16:26:11 +00:00
|
|
|
if (_painLevel > 0) then {
|
2015-11-30 16:27:09 +00:00
|
|
|
if !(_unit getVariable [QGVAR(hasPain), false]) then {
|
|
|
|
_unit setVariable [QGVAR(hasPain), true, true];
|
2015-02-07 22:55:48 +00:00
|
|
|
};
|
|
|
|
} else {
|
2015-11-30 16:27:09 +00:00
|
|
|
if (_unit getVariable [QGVAR(hasPain), false]) then {
|
|
|
|
_unit setVariable [QGVAR(hasPain), false, true];
|
2015-02-07 22:55:48 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-12-05 20:34:20 +00:00
|
|
|
// Handle pain due tourniquets, that have been applied more than 120 s ago
|
2016-12-09 16:48:27 +00:00
|
|
|
private _tourniquetPain = 0;
|
|
|
|
private _tourniquets = _unit getVariable [QGVAR(tourniquets), [0,0,0,0,0,0]];
|
|
|
|
{
|
|
|
|
if (_x > 0 && {CBA_missionTime - _x > 120}) then {
|
|
|
|
_tourniquetPain = _tourniquetPain max (CBA_missionTime - _x - 120) * 0.001;
|
|
|
|
};
|
|
|
|
} forEach _tourniquets;
|
2018-05-09 15:52:26 +00:00
|
|
|
[_unit, _tourniquetPain] call EFUNC(medical,adjustPainLevel);
|
2016-12-09 16:48:27 +00:00
|
|
|
|
2017-04-22 15:57:32 +00:00
|
|
|
private _heartRate = [_unit, _deltaT, _syncValues] call FUNC(updateHeartRate);
|
2016-12-06 19:42:10 +00:00
|
|
|
[_unit, _deltaT, _syncValues] call FUNC(updatePainSuppress);
|
|
|
|
[_unit, _deltaT, _syncValues] call FUNC(updatePeripheralResistance);
|
|
|
|
|
2018-05-08 08:28:16 +00:00
|
|
|
private _bloodPressure = GET_BLOOD_PRESSURE(_unit);
|
2016-12-05 20:34:20 +00:00
|
|
|
_unit setVariable [QGVAR(bloodPressure), _bloodPressure, _syncValues];
|
2016-02-28 23:50:28 +00:00
|
|
|
|
2018-05-08 09:16:12 +00:00
|
|
|
private _cardiacOutput = [_unit] call EFUNC(medical_status,getCardiacOutput);
|
2016-12-05 20:34:20 +00:00
|
|
|
if (_bloodLoss > BLOOD_LOSS_KNOCK_OUT_THRESHOLD * _cardiacOutput) then {
|
|
|
|
[QGVAR(CriticalVitals), _unit] call CBA_fnc_localEvent;
|
|
|
|
};
|
2016-02-29 01:08:59 +00:00
|
|
|
|
2016-12-05 20:34:20 +00:00
|
|
|
#ifdef DEBUG_MODE_FULL
|
2016-12-09 17:43:32 +00:00
|
|
|
if (!isPlayer _unit) then {
|
2016-12-07 10:41:58 +00:00
|
|
|
hintSilent format["blood volume: %1, blood loss: [%2, %3]\nhr: %4, bp: %5, pain: %6", round(_bloodVolume * 100) / 100, round(_bloodLoss * 1000) / 1000, round((_bloodLoss / (0.001 max _cardiacOutput)) * 100) / 100, round(_heartRate), _bloodPressure, round(_painLevel * 100) / 100];
|
2016-12-05 20:34:20 +00:00
|
|
|
};
|
|
|
|
#endif
|
2015-02-07 22:55:48 +00:00
|
|
|
|
2016-12-05 20:34:20 +00:00
|
|
|
_bloodPressure params ["_bloodPressureL", "_bloodPressureH"];
|
2016-12-06 16:26:11 +00:00
|
|
|
if (_bloodPressureL < 40 || {_heartRate < 30}) then {
|
2016-12-05 20:34:20 +00:00
|
|
|
[QGVAR(CriticalVitals), _unit] call CBA_fnc_localEvent;
|
|
|
|
};
|
|
|
|
if ((_heartRate < 20) || {_heartRate > 220} || {_bloodPressureH < 50}) then {
|
|
|
|
[QGVAR(FatalVitals), _unit] call CBA_fnc_localEvent;
|
|
|
|
};
|
2016-06-13 00:11:21 +00:00
|
|
|
|
2017-04-26 15:16:09 +00:00
|
|
|
END_COUNTER(Vitals);
|