mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Rename and add comments to the function that tracks the units vital loop. Use waitAndExecute instead of a pfh for better performance.
This commit is contained in:
parent
f758a90351
commit
3bbabac2d7
@ -11,11 +11,11 @@ PREP(actionLoadUnit);
|
||||
PREP(actionUnloadUnit);
|
||||
PREP(addDamageToUnit);
|
||||
PREP(addHeartRateAdjustment);
|
||||
PREP(addToInjuredCollection);
|
||||
PREP(addToLog);
|
||||
PREP(addToTriageCard);
|
||||
PREP(addUnconsciousCondition);
|
||||
PREP(addUnloadPatientActions);
|
||||
PREP(addVitalLoop);
|
||||
PREP(adjustPainLevel);
|
||||
PREP(canAccessMedicalEquipment);
|
||||
PREP(canTreat);
|
||||
@ -96,6 +96,7 @@ PREP(treatmentTourniquet);
|
||||
PREP(treatmentTourniquetLocal);
|
||||
PREP(useItem);
|
||||
PREP(useItems);
|
||||
PREP(vitalLoop);
|
||||
PREP(displayPatientInformation);
|
||||
PREP(displayTriageCard);
|
||||
PREP(dropDownTriageCard);
|
||||
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Author: Glowbal
|
||||
* Enabled the vitals loop for a unit.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: The Unit <OBJECT>
|
||||
*
|
||||
* ReturnValue:
|
||||
* None
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
params ["_unit", ["_force", false]];
|
||||
|
||||
if ([_unit] call FUNC(hasMedicalEnabled) || _force) then {
|
||||
|
||||
if !(local _unit) exitWith {
|
||||
["addToInjuredCollection", _unit, [_unit, _force]] call EFUNC(common,targetEvent);
|
||||
};
|
||||
|
||||
if ((_unit getVariable[QGVAR(addedToUnitLoop),false] || !alive _unit) && !_force) exitWith{};
|
||||
_unit setVariable [QGVAR(addedToUnitLoop), true, true];
|
||||
|
||||
[{
|
||||
params ["_args", "_idPFH"];
|
||||
_args params ["_unit", "_interval"];
|
||||
_interval = ACE_time - _interval;
|
||||
(_this select 0) set [1, ACE_time];
|
||||
|
||||
if (!alive _unit || !local _unit) then {
|
||||
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
||||
if (!local _unit) then {
|
||||
if (GVAR(level) >= 2) then {
|
||||
_unit setVariable [QGVAR(heartRate), _unit getVariable [QGVAR(heartRate), 80], true];
|
||||
_unit setVariable [QGVAR(bloodPressure), _unit getVariable [QGVAR(bloodPressure), [80, 120]], true];
|
||||
};
|
||||
_unit setVariable [QGVAR(bloodVolume), _unit getVariable [QGVAR(bloodVolume), 100], true];
|
||||
};
|
||||
} else {
|
||||
[_unit, _interval] call FUNC(handleUnitVitals);
|
||||
|
||||
private "_pain";
|
||||
_pain = _unit getVariable [QGVAR(pain), 0];
|
||||
if (_pain > (_unit getVariable [QGVAR(painSuppress), 0])) then {
|
||||
// This introduces wierd unconscious behaviour for basic medical and possibly also advanced.
|
||||
// TODO This is disabled as it's considered non critical code.
|
||||
// We will need to decide if we want unconscious triggered on high pain levels or if we can get rid of this entirely.
|
||||
/*if (_pain > 0.7 && {random(1) > 0.6}) then {
|
||||
[_unit] call FUNC(setUnconscious);
|
||||
};*/
|
||||
|
||||
[_unit, _pain] call FUNC(playInjuredSound);
|
||||
};
|
||||
};
|
||||
}, 1, [_unit, ACE_time]] call CBA_fnc_addPerFrameHandler;
|
||||
};
|
30
addons/medical/functions/fnc_addVitalLoop.sqf
Normal file
30
addons/medical/functions/fnc_addVitalLoop.sqf
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Author: Glowbal
|
||||
* Enabled the vitals loop for a unit.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: The Unit <OBJECT>
|
||||
*
|
||||
* ReturnValue:
|
||||
* None
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
params ["_unit", ["_force", false]];
|
||||
|
||||
if !([_unit] call FUNC(hasMedicalEnabled) || _force) exitWith {};
|
||||
|
||||
if !(local _unit) exitWith {
|
||||
["addVitalLoop", _unit, [_unit, _force]] call EFUNC(common,targetEvent);
|
||||
};
|
||||
|
||||
// Quit if the unit already has a vital loop, or is dead, unless it's forced
|
||||
if ((_unit getVariable[QGVAR(addedToUnitLoop),false] || !alive _unit) && !_force) exitWith{};
|
||||
|
||||
// Schedule the loop to be executed again later
|
||||
// @todo: should the loop be started righ away instead?
|
||||
_unit setVariable [QGVAR(addedToUnitLoop), true, true];
|
||||
[DFUNC(vitalLoop), 1, [_unit, ACE_time]] call EFUNC(common,waitAndExecute);
|
@ -35,6 +35,6 @@ _pain = _pain max 0;
|
||||
_unit setVariable [QGVAR(pain), _pain];
|
||||
|
||||
//Start up the vital watching (if not already running)
|
||||
[_unit] call FUNC(addToInjuredCollection);
|
||||
[_unit] call FUNC(addVitalLoop);
|
||||
|
||||
_pain
|
||||
|
@ -102,8 +102,8 @@ if ((_minLethalDamage <= _newDamage) && {[_unit, [_effectiveSelectionName] call
|
||||
_damageReturn = _damageReturn min 0.89;
|
||||
};
|
||||
|
||||
|
||||
[_unit] call FUNC(addToInjuredCollection);
|
||||
// Start the loop that tracks the unit vitals
|
||||
[_unit] call FUNC(addVitalLoop);
|
||||
|
||||
if (_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)]) exitWith {
|
||||
private _delayedUnconsicous = false;
|
||||
|
@ -17,8 +17,9 @@
|
||||
|
||||
params ["_unit", "_local"];
|
||||
if (_local) then {
|
||||
// If the unit had a loop tracking its vitals, restart it locally
|
||||
if (_unit getVariable[QGVAR(addedToUnitLoop),false]) then {
|
||||
[_unit, true] call FUNC(addToInjuredCollection);
|
||||
[_unit, true] call FUNC(addVitalLoop);
|
||||
};
|
||||
|
||||
if ((_unit getVariable ["ACE_isUnconscious",false]) && {count (_unit getVariable [QGVAR(unconsciousArguments), []]) >= 6}) then {
|
||||
|
@ -16,7 +16,8 @@
|
||||
private ["_tourniquets", "_part", "_applyingTo"];
|
||||
params ["_target", "_tourniquetItem", "_selectionName"];
|
||||
|
||||
[_target] call FUNC(addToInjuredCollection);
|
||||
//If we're not already tracking vitals, start:
|
||||
[_target] call FUNC(addVitalLoop);
|
||||
|
||||
_part = [_selectionName] call FUNC(selectionNameToNumber);
|
||||
|
||||
|
@ -92,7 +92,7 @@ _args call FUNC(createLitter);
|
||||
|
||||
//If we're not already tracking vitals, start:
|
||||
if (!(_target getVariable [QGVAR(addedToUnitLoop),false])) then {
|
||||
[_target] call FUNC(addToInjuredCollection);
|
||||
[_target] call FUNC(addVitalLoop);
|
||||
};
|
||||
|
||||
["medical_treatmentSuccess", [_caller, _target, _selectionName, _className]] call EFUNC(common,localEvent);
|
||||
|
48
addons/medical/functions/fnc_vitalLoop.sqf
Normal file
48
addons/medical/functions/fnc_vitalLoop.sqf
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Author: Glowbal, esteldunedain
|
||||
* Vital loop for a unit.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: The Unit <OBJECT>
|
||||
* 1: Time of last computation <NUMBER>
|
||||
*
|
||||
* ReturnValue:
|
||||
* None
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
params ["_unit", "_lastTime"];
|
||||
|
||||
// If the unit died the loop is finished
|
||||
if (!alive _unit) exitWith {};
|
||||
|
||||
// If locality changed, broadcast the last medical state and finish the local loop
|
||||
if (!local _unit) exitWith {
|
||||
if (GVAR(level) >= 2) then {
|
||||
_unit setVariable [QGVAR(heartRate), _unit getVariable [QGVAR(heartRate), 80], true];
|
||||
_unit setVariable [QGVAR(bloodPressure), _unit getVariable [QGVAR(bloodPressure), [80, 120]], true];
|
||||
};
|
||||
_unit setVariable [QGVAR(bloodVolume), _unit getVariable [QGVAR(bloodVolume), 100], true];
|
||||
};
|
||||
|
||||
// Handle unit vitals
|
||||
[_unit, ACE_time - _lastTime] call FUNC(handleUnitVitals);
|
||||
|
||||
// Play injured sounds
|
||||
private _pain = _unit getVariable [QGVAR(pain), 0];
|
||||
if (_pain > (_unit getVariable [QGVAR(painSuppress), 0])) then {
|
||||
// This introduces wierd unconscious behaviour for basic medical and possibly also advanced.
|
||||
// TODO This is disabled as it's considered non critical code.
|
||||
// We will need to decide if we want unconscious triggered on high pain levels or if we can get rid of this entirely.
|
||||
/*if (_pain > 0.7 && {random(1) > 0.6}) then {
|
||||
[_unit] call FUNC(setUnconscious);
|
||||
};*/
|
||||
|
||||
[_unit, _pain] call FUNC(playInjuredSound);
|
||||
};
|
||||
|
||||
// Schedule the loop to be executed again later
|
||||
[DFUNC(vitalLoop), 1, [_unit, ACE_time]] call EFUNC(common,waitAndExecute);
|
Loading…
Reference in New Issue
Block a user