2015-02-08 09:01:32 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal
|
|
|
|
* Updates the vitals. Is expected to be called every second.
|
2015-02-07 22:55:48 +00:00
|
|
|
*
|
2015-02-08 09:01:32 +00:00
|
|
|
* Arguments:
|
|
|
|
* 0: The Unit <OBJECT>
|
|
|
|
*
|
|
|
|
* ReturnValue:
|
|
|
|
* <NIL>
|
|
|
|
*
|
|
|
|
* Public: No
|
2015-02-07 22:55:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-08-22 14:25:10 +00:00
|
|
|
params ["_unit", "_interval"];
|
2015-09-03 15:18:37 +00:00
|
|
|
TRACE_3("ACE_DEBUG",_unit,_interval,_unit);
|
2015-03-15 00:48:50 +00:00
|
|
|
if (_interval == 0) exitWith {};
|
|
|
|
|
2016-06-13 00:11:21 +00:00
|
|
|
private _lastTimeValuesSynced = _unit getVariable [QGVAR(lastMomentValuesSynced), 0];
|
|
|
|
private _syncValues = (CBA_missionTime - _lastTimeValuesSynced >= (10 + floor(random(10))) && GVAR(keepLocalSettingsSynced));
|
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
|
|
|
};
|
|
|
|
|
2016-09-01 10:46:08 +00:00
|
|
|
private _bloodVolume = (_unit getVariable [QGVAR(bloodVolume), 100]) + ([_unit, _syncValues] call FUNC(getBloodVolumeChange));
|
2015-04-14 18:40:38 +00:00
|
|
|
_bloodVolume = _bloodVolume max 0;
|
|
|
|
|
2015-11-30 16:27:09 +00:00
|
|
|
_unit setVariable [QGVAR(bloodVolume), _bloodVolume, _syncValues];
|
2015-02-07 22:55:48 +00:00
|
|
|
|
2015-09-03 15:18:37 +00:00
|
|
|
TRACE_3("ACE_DEBUG",_bloodVolume,_syncValues,_unit);
|
2015-02-07 22:55:48 +00:00
|
|
|
// Set variables for synchronizing information across the net
|
2015-04-28 18:47:11 +00:00
|
|
|
if (_bloodVolume < 100) then {
|
2016-06-13 10:18:56 +00:00
|
|
|
if (_bloodVolume < 90) then {
|
|
|
|
TRACE_4("ACE_DEBUG",_bloodVolume,_unit getVariable QGVAR(hasLostBlood),_syncValues,_unit);
|
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-09-03 15:18:37 +00:00
|
|
|
TRACE_4("ACE_DEBUG", _bloodVolume,_unit getVariable QGVAR(hasLostBlood),_syncValues,_unit);
|
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-09-03 20:17:59 +00:00
|
|
|
TRACE_4("ACE_DEBUG",_bloodVolume,_unit getVariable QGVAR(hasLostBlood),_syncValues,_unit);
|
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
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-09-03 15:18:37 +00:00
|
|
|
TRACE_3("ACE_DEBUG",[_unit] call FUNC(getBloodLoss),_unit getVariable QGVAR(isBleeding),_unit);
|
2015-04-22 20:36:41 +00:00
|
|
|
if (([_unit] call FUNC(getBloodLoss)) > 0) then {
|
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
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-06-13 00:11:21 +00:00
|
|
|
private _painStatus = _unit getVariable [QGVAR(pain), 0];
|
2015-09-04 14:37:20 +00:00
|
|
|
TRACE_4("ACE_DEBUG",_painStatus,_unit getVariable QGVAR(hasPain),_unit getVariable QGVAR(painSuppress),_unit);
|
2015-11-30 16:27:09 +00:00
|
|
|
if (_painStatus > (_unit getVariable [QGVAR(painSuppress), 0])) then {
|
|
|
|
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-06-13 10:18:56 +00:00
|
|
|
if (_bloodVolume < 30) exitWith {
|
|
|
|
[_unit] call FUNC(setDead);
|
|
|
|
};
|
|
|
|
|
|
|
|
if ([_unit] call EFUNC(common,isAwake)) then {
|
|
|
|
if (_bloodVolume < 60) then {
|
|
|
|
if (random(1) > 0.9) then {
|
|
|
|
[_unit, true, 15 + random(20)] call FUNC(setUnconscious);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-03-12 06:33:44 +00:00
|
|
|
if (GVAR(level) == 1) then {
|
2015-09-04 17:21:10 +00:00
|
|
|
TRACE_5("ACE_DEBUG_BASIC_VITALS",_painStatus,_unit getVariable QGVAR(hasPain),_unit getVariable QGVAR(morphine),_syncValues,_unit);
|
2015-03-12 06:33:44 +00:00
|
|
|
// reduce pain
|
2015-04-28 17:30:35 +00:00
|
|
|
if (_painStatus > 0) then {
|
|
|
|
_unit setVariable [QGVAR(pain), (_painStatus - 0.001 * _interval) max 0, _syncValues];
|
2015-03-12 06:33:44 +00:00
|
|
|
};
|
2015-02-07 22:55:48 +00:00
|
|
|
|
2015-03-12 06:33:44 +00:00
|
|
|
// reduce painkillers
|
|
|
|
if (_unit getVariable [QGVAR(morphine), 0] > 0) then {
|
2015-04-28 17:30:35 +00:00
|
|
|
_unit setVariable [QGVAR(morphine), ((_unit getVariable [QGVAR(morphine), 0]) - 0.0015 * _interval) max 0, _syncValues];
|
2015-03-12 06:33:44 +00:00
|
|
|
};
|
2015-02-07 22:55:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// handle advanced medical, with vitals
|
2015-03-08 12:56:24 +00:00
|
|
|
if (GVAR(level) >= 2) then {
|
2015-09-04 14:37:20 +00:00
|
|
|
TRACE_6("ACE_DEBUG_ADVANCED_VITALS",_painStatus,_bloodVolume, _unit getVariable QGVAR(hasPain),_unit getVariable QGVAR(morphine),_syncValues,_unit);
|
2015-02-07 22:55:48 +00:00
|
|
|
|
2016-02-29 01:08:59 +00:00
|
|
|
// Handle pain due tourniquets, that have been applied more than 120 s ago
|
|
|
|
private _oldTourniquets = (_unit getVariable [QGVAR(tourniquets), []]) select {_x > 0 && {CBA_missionTime - _x > 120}};
|
|
|
|
// Increase pain at a rate of 0.001 units/s per old tourniquet
|
|
|
|
_painStatus = _painStatus + (count _oldTourniquets) * 0.001 * _interval;
|
2016-02-28 23:50:28 +00:00
|
|
|
|
2015-02-07 22:55:48 +00:00
|
|
|
// Set the vitals
|
2016-06-13 00:11:21 +00:00
|
|
|
private _heartRate = (_unit getVariable [QGVAR(heartRate), 80]) + (([_unit] call FUNC(getHeartRateChange)) * _interval);
|
2015-11-30 16:27:09 +00:00
|
|
|
_unit setVariable [QGVAR(heartRate), _heartRate max 0, _syncValues];
|
2015-02-07 22:55:48 +00:00
|
|
|
|
2016-06-13 00:11:21 +00:00
|
|
|
private _bloodPressure = [_unit] call FUNC(getBloodPressure);
|
2015-11-30 16:27:09 +00:00
|
|
|
_unit setVariable [QGVAR(bloodPressure), _bloodPressure, _syncValues];
|
2015-02-07 22:55:48 +00:00
|
|
|
|
2016-06-13 00:11:21 +00:00
|
|
|
_painReduce = [0.001, 0.002] select (_painStatus > 5);
|
2016-02-29 01:08:59 +00:00
|
|
|
|
|
|
|
// @todo: replace this and the rest of the setVariable with EFUNC(common,setApproximateVariablePublic)
|
|
|
|
_unit setVariable [QGVAR(pain), (_painStatus - _painReduce * _interval) max 0, _syncValues];
|
|
|
|
|
2015-09-03 15:18:37 +00:00
|
|
|
TRACE_8("ACE_DEBUG_ADVANCED_VITALS",_painStatus,_painReduce,_heartRate,_bloodVolume,_bloodPressure,_interval,_syncValues,_unit);
|
2015-02-07 22:55:48 +00:00
|
|
|
|
|
|
|
// Check vitals for medical status
|
|
|
|
// TODO check for in revive state instead of variable
|
2015-08-22 14:25:10 +00:00
|
|
|
_bloodPressure params ["_bloodPressureL", "_bloodPressureH"];
|
2015-02-07 22:55:48 +00:00
|
|
|
|
2015-11-30 16:27:09 +00:00
|
|
|
if (!(_unit getVariable [QGVAR(inCardiacArrest),false])) then {
|
2015-02-07 22:55:48 +00:00
|
|
|
if (_heartRate < 10 || _bloodPressureH < 30 || _bloodVolume < 20) then {
|
2015-04-17 18:40:24 +00:00
|
|
|
[_unit, true, 10+ random(20)] call FUNC(setUnconscious); // safety check to ensure unconsciousness for units if they are not dead already.
|
2015-02-07 22:55:48 +00:00
|
|
|
};
|
|
|
|
|
2016-06-13 00:11:21 +00:00
|
|
|
if ((_bloodPressureH > 260)
|
|
|
|
|| {_bloodPressureL < 40 && ({_heartRate > 190})}
|
|
|
|
|| {(_bloodPressureH > 145 && {_heartRate > 150})}) then {
|
|
|
|
|
2015-02-07 22:55:48 +00:00
|
|
|
if (random(1) > 0.7) then {
|
|
|
|
[_unit] call FUNC(setCardiacArrest);
|
|
|
|
};
|
|
|
|
};
|
2016-06-13 00:11:21 +00:00
|
|
|
if (_heartRate > 200 || (_heartRate < 20)) then {
|
2015-02-07 22:55:48 +00:00
|
|
|
[_unit] call FUNC(setCardiacArrest);
|
|
|
|
};
|
2015-02-07 23:08:36 +00:00
|
|
|
};
|
2015-02-07 22:55:48 +00:00
|
|
|
};
|