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-05-15 03:16:44 +00:00
|
|
|
private ["_unit", "_heartRate","_bloodPressure","_bloodVolume","_painStatus", "_lastTimeValuesSynced", "_syncValues", "_airwayStatus", "_blood", "_bloodPressureH", "_bloodPressureL", "_interval", "_lastMomentVitalsHandled"];
|
2015-02-07 22:55:48 +00:00
|
|
|
_unit = _this select 0;
|
|
|
|
|
2015-05-15 03:16:44 +00:00
|
|
|
_lastMomentVitalsHandled = _unit getVariable [QGVAR(lastMomentVitalsHandled), -1];
|
2015-03-15 00:48:50 +00:00
|
|
|
_unit setVariable [QGVAR(lastMomentVitalsHandled), time];
|
|
|
|
|
2015-05-15 03:16:44 +00:00
|
|
|
//If QGVAR(lastMomentVitalsHandled) is undefined then assume 1 second interval:
|
|
|
|
_interval = if (_lastMomentVitalsHandled == -1) then {1} else {time - _lastMomentVitalsHandled};
|
|
|
|
|
2015-03-15 00:48:50 +00:00
|
|
|
if (_interval == 0) exitWith {};
|
|
|
|
|
2015-03-08 12:56:24 +00:00
|
|
|
_lastTimeValuesSynced = _unit getvariable [QGVAR(lastMomentValuesSynced), 0];
|
2015-04-05 18:23:07 +00:00
|
|
|
_syncValues = (time - _lastTimeValuesSynced >= (10 + floor(random(10))) && GVAR(keepLocalSettingsSynced));
|
2015-03-08 12:56:24 +00:00
|
|
|
if (_syncValues) then {
|
|
|
|
_unit setvariable [QGVAR(lastMomentValuesSynced), time];
|
|
|
|
};
|
|
|
|
|
2015-04-17 17:13:23 +00:00
|
|
|
_bloodVolume = (_unit getvariable [QGVAR(bloodVolume), 100]) + ([_unit] call FUNC(getBloodVolumeChange));
|
2015-04-14 18:40:38 +00:00
|
|
|
_bloodVolume = _bloodVolume max 0;
|
|
|
|
|
2015-03-08 12:56:24 +00:00
|
|
|
_unit setvariable [QGVAR(bloodVolume), _bloodVolume, _syncValues];
|
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 {
|
2015-04-28 20:19:30 +00:00
|
|
|
if ((_bloodVolume < 90 && (GVAR(level) == 2)) || _bloodVolume <= 45) then {
|
2015-04-28 18:47:11 +00:00
|
|
|
if (_unit getvariable [QGVAR(hasLostBlood), 0] != 2) then {
|
|
|
|
_unit setvariable [QGVAR(hasLostBlood), 2, true];
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
if (_unit getvariable [QGVAR(hasLostBlood), 0] != 1) then {
|
|
|
|
_unit setvariable [QGVAR(hasLostBlood), 1, true];
|
|
|
|
};
|
|
|
|
}
|
2015-02-07 22:55:48 +00:00
|
|
|
} else {
|
2015-04-28 18:47:11 +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-04-22 20:36:41 +00:00
|
|
|
if (([_unit] call FUNC(getBloodLoss)) > 0) then {
|
2015-02-07 22:55:48 +00:00
|
|
|
if !(_unit getvariable [QGVAR(isBleeding), false]) then {
|
|
|
|
_unit setvariable [QGVAR(isBleeding), true, true];
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
if (_unit getvariable [QGVAR(isBleeding), false]) then {
|
|
|
|
_unit setvariable [QGVAR(isBleeding), false, true];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-02-08 12:18:08 +00:00
|
|
|
_painStatus = _unit getvariable [QGVAR(pain), 0];
|
2015-02-07 22:55:48 +00:00
|
|
|
if (_painStatus > 0) then {
|
|
|
|
if !(_unit getvariable [QGVAR(hasPain), false]) then {
|
|
|
|
_unit setvariable [QGVAR(hasPain), true, true];
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
if (_unit getvariable [QGVAR(hasPain), false]) then {
|
|
|
|
_unit setvariable [QGVAR(hasPain), false, true];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-03-12 06:33:44 +00:00
|
|
|
if (GVAR(level) == 1) then {
|
|
|
|
// 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
|
|
|
|
2015-03-15 02:26:00 +00:00
|
|
|
// bleeding
|
|
|
|
_blood = _unit getVariable [QGVAR(bloodVolume), 100];
|
2015-04-14 18:40:38 +00:00
|
|
|
if (_blood <= 35 and !(_unit getVariable ["ACE_isUnconscious", false])) then {
|
|
|
|
[_unit, true] call FUNC(setUnconscious);
|
|
|
|
};
|
|
|
|
if (_blood == 0) then {
|
|
|
|
[_unit] call FUNC(setDead);
|
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-03-15 02:26:10 +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 {
|
2015-04-17 18:40:24 +00:00
|
|
|
[_unit, true, 15 + random(20)] call FUNC(setUnconscious);
|
2015-03-15 02:26:10 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2015-02-07 22:55:48 +00:00
|
|
|
|
|
|
|
// Set the vitals
|
2015-04-17 17:13:23 +00:00
|
|
|
_heartRate = (_unit getvariable [QGVAR(heartRate), 80]) + (([_unit] call FUNC(getHeartRateChange)) * _interval);
|
2015-03-08 12:56:24 +00:00
|
|
|
_unit setvariable [QGVAR(heartRate), _heartRate, _syncValues];
|
2015-02-07 22:55:48 +00:00
|
|
|
|
|
|
|
_bloodPressure = [_unit] call FUNC(getBloodPressure);
|
2015-03-08 12:56:24 +00:00
|
|
|
_unit setvariable [QGVAR(bloodPressure), _bloodPressure, _syncValues];
|
2015-02-07 22:55:48 +00:00
|
|
|
|
2015-03-21 09:55:40 +00:00
|
|
|
// TODO Disabled until implemented fully
|
2015-02-07 22:55:48 +00:00
|
|
|
// Handle airway
|
2015-03-21 09:55:40 +00:00
|
|
|
/*if (GVAR(setting_allowAirwayInjuries)) then {
|
2015-02-07 22:55:48 +00:00
|
|
|
_airwayStatus = _unit getvariable [QGVAR(airwayStatus), 100];
|
|
|
|
if (((_unit getvariable [QGVAR(airwayOccluded), false]) || (_unit getvariable [QGVAR(airwayCollapsed), false])) && !((_unit getvariable [QGVAR(airwaySecured), false]))) then {
|
|
|
|
if (_airwayStatus >= 0.5) then {
|
2015-03-15 00:48:50 +00:00
|
|
|
_unit setvariable [QGVAR(airwayStatus), _airwayStatus - 0.5 * _interval, _syncValues];
|
2015-02-07 22:55:48 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
if !((_unit getvariable [QGVAR(airwayOccluded), false]) || (_unit getvariable [QGVAR(airwayCollapsed), false])) then {
|
2015-03-08 14:58:35 +00:00
|
|
|
if (_airwayStatus < 100) then {
|
2015-03-15 00:48:50 +00:00
|
|
|
_unit setvariable [QGVAR(airwayStatus), (_airwayStatus + 1.5 * _interval) min 100, _syncValues];
|
2015-02-07 22:55:48 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2015-03-08 14:58:35 +00:00
|
|
|
if (_airwayStatus < 80) then {
|
|
|
|
[_unit] call FUNC(setUnconscious);
|
|
|
|
if (_airwayStatus <= 0) then {
|
|
|
|
[_unit, true] call FUNC(setDead);
|
|
|
|
};
|
|
|
|
};
|
2015-03-21 09:55:40 +00:00
|
|
|
};*/
|
2015-02-07 22:55:48 +00:00
|
|
|
|
|
|
|
// Check vitals for medical status
|
|
|
|
// TODO check for in revive state instead of variable
|
2015-03-21 09:55:40 +00:00
|
|
|
_bloodPressureL = _bloodPressure select 0;
|
2015-02-07 22:55:48 +00:00
|
|
|
_bloodPressureH = _bloodPressure select 1;
|
|
|
|
|
|
|
|
if (!(_unit getvariable [QGVAR(inCardiacArrest),false])) then {
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
if (_bloodPressureH > 260) then {
|
|
|
|
if (random(1) > 0.7) then {
|
|
|
|
[_unit] call FUNC(setCardiacArrest);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if (_bloodPressureL < 40 && _heartRate > 190) then {
|
|
|
|
if (random(1) > 0.7) then {
|
|
|
|
[_unit] call FUNC(setCardiacArrest);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if (_bloodPressureH > 145 && _heartRate > 150) then {
|
|
|
|
if (random(1) > 0.7) then {
|
|
|
|
[_unit] call FUNC(setCardiacArrest);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if (_heartRate > 200) then {
|
|
|
|
[_unit] call FUNC(setCardiacArrest);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (_heartRate < 20) then {
|
|
|
|
[_unit] call FUNC(setCardiacArrest);
|
|
|
|
};
|
2015-02-07 23:08:36 +00:00
|
|
|
};
|
2015-04-05 18:11:54 +00:00
|
|
|
|
|
|
|
// syncing any remaining values
|
|
|
|
if (_syncValues) then {
|
|
|
|
{
|
|
|
|
private "_value";
|
|
|
|
_value = _unit getvariable _x;
|
|
|
|
if !(isnil "_value") then {
|
|
|
|
_unit setvariable [_x,(_unit getvariable [_x, 0]), true];
|
|
|
|
};
|
|
|
|
}foreach GVAR(IVBags);
|
|
|
|
};
|
2015-02-07 22:55:48 +00:00
|
|
|
};
|