From a3c4c60b7f70a1febb19329288699e9eabae502f Mon Sep 17 00:00:00 2001 From: Glowbal Date: Sun, 8 Feb 2015 13:06:44 +0100 Subject: [PATCH] Added possibility to add unconscious conditions. --- addons/medical/XEH_preInit.sqf | 3 ++ .../functions/fnc_addToInjuredCollection.sqf | 19 +++++++----- .../functions/fnc_addUnconsciousCondition.sqf | 25 ++++++++++++++++ .../functions/fnc_getUnconsciousCondition.sqf | 30 +++++++++++++++++++ .../functions/fnc_handleUnitVitals.sqf | 4 +-- .../functions/fnc_setCardiacArrest.sqf | 2 +- 6 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 addons/medical/functions/fnc_addUnconsciousCondition.sqf create mode 100644 addons/medical/functions/fnc_getUnconsciousCondition.sqf diff --git a/addons/medical/XEH_preInit.sqf b/addons/medical/XEH_preInit.sqf index 56cd67e249..5c1945817c 100644 --- a/addons/medical/XEH_preInit.sqf +++ b/addons/medical/XEH_preInit.sqf @@ -21,6 +21,9 @@ PREP(getCardiacOutput); PREP(setCardiacArrest); PREP(addToInjuredCollection); PREP(setUnconscious); +PREP(getUnconsciousCondition); +PREP(addUnconsciousCondition); + GVAR(injuredUnitCollection) = []; ADDON = true; diff --git a/addons/medical/functions/fnc_addToInjuredCollection.sqf b/addons/medical/functions/fnc_addToInjuredCollection.sqf index 064b62bb5a..c832dc1a3c 100644 --- a/addons/medical/functions/fnc_addToInjuredCollection.sqf +++ b/addons/medical/functions/fnc_addToInjuredCollection.sqf @@ -1,11 +1,14 @@ -/** - * fnc_addToInjuredCollection.sqf - * @Descr: N/A - * @Author: Glowbal +/* + * Author: Glowbal + * Enabled the vitals loop for a unit. * - * @Arguments: [] - * @Return: - * @PublicAPI: false + * Arguments: + * 0: The Unit + * + * ReturnValue: + * + * + * Public: Yes */ #include "script_component.hpp" @@ -33,7 +36,7 @@ if ([_unit] call FUNC(hasMedicalEnabled)) then { _pain = _unit getvariable [QGVAR(pain), 0]; if (_pain > 45) then { if (random(1) > 0.6) then { - // [_unit] call FUNC(setUnconsciousState); + [_unit] call FUNC(setUnconscious); }; //[_unit] call FUNC(playInjuredSound); }; diff --git a/addons/medical/functions/fnc_addUnconsciousCondition.sqf b/addons/medical/functions/fnc_addUnconsciousCondition.sqf new file mode 100644 index 0000000000..579a55ca1f --- /dev/null +++ b/addons/medical/functions/fnc_addUnconsciousCondition.sqf @@ -0,0 +1,25 @@ +/* + * Author: Glowbal + * Adds new condition for the unconscious state. Conditions are not actively checked for units unless unit is in unconscious state. + * + * Arguments: + * 0: Code, should return a boolean + * + * ReturnValue: + * + * + * Public: Yes + */ + +#include "script_component.hpp" + +if (isnil QGVAR(unconsciousConditions)) then { + GVAR(unconsciousConditions) = []; +}; +if (typeName _this == typeName []) then { + { + if (typeName _x == typeName {}) then { + GVAR(unconsciousConditions) pushback _x; + }; + }foreach _this; +}; diff --git a/addons/medical/functions/fnc_getUnconsciousCondition.sqf b/addons/medical/functions/fnc_getUnconsciousCondition.sqf new file mode 100644 index 0000000000..19d3bdec1d --- /dev/null +++ b/addons/medical/functions/fnc_getUnconsciousCondition.sqf @@ -0,0 +1,30 @@ +/* + * Author: Glowbal + * Get whatever or not a unit should be or stay unconscious. + * + * Arguments: + * 0: The Unit + * + * ReturnValue: + * Should the unit stay unconscious? + * + * Public: Yes + */ + +#include "script_component.hpp" + +private ["_unit","_return"]; +_unit = _this select 0; + +if (isnil QGVAR(unconsciousConditions)) then { + GVAR(unconsciousConditions) = []; +}; + +_return = false; +{ + if (typeName _x == typeName {} && {([_unit] call _x)}) exitwith { + _return = true; + }; +}foreach GVAR(unconsciousConditions); + +_return; diff --git a/addons/medical/functions/fnc_handleUnitVitals.sqf b/addons/medical/functions/fnc_handleUnitVitals.sqf index 3df90ddb1b..566aedbbf8 100644 --- a/addons/medical/functions/fnc_handleUnitVitals.sqf +++ b/addons/medical/functions/fnc_handleUnitVitals.sqf @@ -62,7 +62,7 @@ if (_bloodVolume < 30) exitwith { if ([_unit] call EFUNC(common,isAwake)) then { if (_bloodVolume < 60) then { if (random(1) > 0.9) then { - //[_unit] call FUNC(setUnconsciousState); + [_unit] call FUNC(setUnconscious); }; }; }; @@ -101,7 +101,7 @@ if ((missionNamespace getvariable[QGVAR(setting_AdvancedLevel), 0]) > 0) exitwit if (!(_unit getvariable [QGVAR(inCardiacArrest),false])) then { if (_heartRate < 10 || _bloodPressureH < 30 || _bloodVolume < 20) then { - //[_unit] call FUNC(setUnconsciousState); // safety check to ensure unconsciousness for units if they are not dead already. + [_unit] call FUNC(setUnconscious); // safety check to ensure unconsciousness for units if they are not dead already. }; if (_bloodPressureH > 260) then { diff --git a/addons/medical/functions/fnc_setCardiacArrest.sqf b/addons/medical/functions/fnc_setCardiacArrest.sqf index 9767978a16..6b63d71f79 100644 --- a/addons/medical/functions/fnc_setCardiacArrest.sqf +++ b/addons/medical/functions/fnc_setCardiacArrest.sqf @@ -23,7 +23,7 @@ _unit setvariable [QGVAR(heartRate), 0]; ["Medical_onEnteredCardiacArrest", [_unit]] call ace_common_fnc_localEvent; -//[_unit] call FUNC(setUnconsciousState); +[_unit] call FUNC(setUnconscious); _counter = 120 + round(random(600)); _timer = 0;