From a50276ddaf6a88cbb0f3ae16218159bfcb9a33c6 Mon Sep 17 00:00:00 2001 From: Glowbal Date: Tue, 3 Feb 2015 21:47:45 +0100 Subject: [PATCH 1/3] Added a getTypeOfDamage function. --- .../medical/functions/fnc_getTypeOfDamage.sqf | 31 +++++++++++++++++++ addons/medical/functions/fnc_handleDamage.sqf | 16 +++++----- 2 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 addons/medical/functions/fnc_getTypeOfDamage.sqf diff --git a/addons/medical/functions/fnc_getTypeOfDamage.sqf b/addons/medical/functions/fnc_getTypeOfDamage.sqf new file mode 100644 index 0000000000..2153a5659c --- /dev/null +++ b/addons/medical/functions/fnc_getTypeOfDamage.sqf @@ -0,0 +1,31 @@ +/** + * fn_getTypeOfDamage.sqf + * @Descr: N/A + * @Author: Glowbal + * + * @Arguments: [] + * @Return: + * @PublicAPI: false + */ + +#include "script_component.hpp" + +private ["_typeOfProjectile","_typeOfInjury"]; +_typeOfProjectile = _this select 0; +_typeOfInjury = switch (true) do { + case (_typeOfProjectile isKindOf "Backblast"): {"backblast"}; + case (_typeOfProjectile iskindof "BulletBase"): {"Bullet"}; + case (_typeOfProjectile iskindof "GrenadeCore"): {"Grenade"}; + case (_typeOfProjectile iskindof "TimeBombCore"): {"Explosive"}; + case (_typeOfProjectile iskindof "MineCore"): {"Explosive"}; + case (_typeOfProjectile iskindof "FuelExplosion"): {"Explosive"}; + case (_typeOfProjectile iskindof "ShellBase"): {"Shell"}; + case (_typeOfProjectile iskindof "RocketBase"): {"Explosive"}; + case (_typeOfProjectile iskindof "MissileBase"): {"Explosive"}; + case (_typeOfProjectile iskindof "LaserBombCore"): {"Explosive"}; + case (_typeOfProjectile iskindof "BombCore"): {"Explosive"}; + case (_typeOfProjectile iskindof "Grenade"): {"Grenade"}; + case (_typeOfProjectile == "VehicleCrash"): {"VehicleCrash"}; + default {"Unknown"}; +}; +_typeOfInjury \ No newline at end of file diff --git a/addons/medical/functions/fnc_handleDamage.sqf b/addons/medical/functions/fnc_handleDamage.sqf index d3f70dfb05..e2ef7f40f3 100644 --- a/addons/medical/functions/fnc_handleDamage.sqf +++ b/addons/medical/functions/fnc_handleDamage.sqf @@ -17,7 +17,7 @@ #include "script_component.hpp" -private ["_damageReturn"]; +private ["_damageReturn", "_typeOfDamage"]; if !(local (_this select 0)) exitWith {nil}; @@ -25,19 +25,17 @@ if (typeName (_this select 4) == "OBJECT") then { _this set [4, typeOf (_this select 4)]; }; - _damageReturn = (_this select 2); - +_typeOfDamage = [_this select 4] call FUNC(getTypeOfDamage) if (GVAR(level) >= 0) then { - _damageReturn = (_this + [_damageReturn]) call FUNC(handleDamage_basic); + _damageReturn = (_this + [_damageReturn, _typeOfDamage]) call FUNC(handleDamage_basic); }; if (GVAR(level) >= 1) then { - _damageReturn = (_this + [_damageReturn]) call FUNC(handleDamage_medium); -}; + _damageReturn = (_this + [_damageReturn, _typeOfDamage]) call FUNC(handleDamage_medium); -if (GVAR(level) >= 2) then { - _damageReturn = (_this + [_damageReturn]) call FUNC(handleDamage_advanced); + if (GVAR(level) >= 2) then { + _damageReturn = (_this + [_damageReturn, _typeOfDamage]) call FUNC(handleDamage_advanced); + }; }; - _damageReturn From 0a403ff4221e51ed912aef1d8c071f7e80b2879c Mon Sep 17 00:00:00 2001 From: Glowbal Date: Tue, 3 Feb 2015 21:48:08 +0100 Subject: [PATCH 2/3] Added initial advanced medical handleDamage functionality. --- addons/medical/functions/fnc_handleAirway.sqf | 30 +++++++++ .../functions/fnc_handleDamage_advanced.sqf | 19 ++++++ .../medical/functions/fnc_handleFractures.sqf | 67 +++++++++++++++++++ .../functions/fnc_handleInternalInjuries.sqf | 21 ++++++ .../functions/fnc_selectionNameToNumber.sqf | 13 ++++ 5 files changed, 150 insertions(+) create mode 100644 addons/medical/functions/fnc_handleAirway.sqf create mode 100644 addons/medical/functions/fnc_handleFractures.sqf create mode 100644 addons/medical/functions/fnc_handleInternalInjuries.sqf create mode 100644 addons/medical/functions/fnc_selectionNameToNumber.sqf diff --git a/addons/medical/functions/fnc_handleAirway.sqf b/addons/medical/functions/fnc_handleAirway.sqf new file mode 100644 index 0000000000..ff675c2780 --- /dev/null +++ b/addons/medical/functions/fnc_handleAirway.sqf @@ -0,0 +1,30 @@ +/** + * fn_assignAirwayStatus.sqf + * @Descr: N/A + * @Author: Glowbal + * + * @Arguments: [] + * @Return: + * @PublicAPI: false + */ + +#include "script_component.hpp" + +private ["_unit", "_selectionName", "_amountOfDamage", "_sourceOfDamage", "_typeOfDamage", "_bodyPartn"]; +_unit = _this select 0; +_selectionName = _this select 1; +_amountOfDamage = _this select 2; +_sourceOfDamage = _this select 3; +_typeOfDamage = _this select 4; +_bodyPartn = [_selectionName] call FUNC(selectionNameToNumber); + +// We process only the head for airway. +if (_bodyPartn != 0) exitwith {}; + +if (_amountOfDamage > 0.4) then { + if (random(1) >= 0.8) then { + if !(_unit getvariable[QGVAR(airwayCollapsed), false]) then { + _unit setvariable [QGVAR(airwayCollapsed), true, true]; + }; + }; +}; diff --git a/addons/medical/functions/fnc_handleDamage_advanced.sqf b/addons/medical/functions/fnc_handleDamage_advanced.sqf index e69de29bb2..aa2a14489a 100644 --- a/addons/medical/functions/fnc_handleDamage_advanced.sqf +++ b/addons/medical/functions/fnc_handleDamage_advanced.sqf @@ -0,0 +1,19 @@ +private ["_unit","_selectionName","_amountOfDamage","_sourceOfDamage","_typeOfProjectile","_typeOfDamage"]; +_unit = _this select 0; +_selectionName = _this select 1; +_amountOfDamage = _this select 2; +_sourceOfDamage = _this select 3; +_typeOfProjectile = _this select 4; +_returnDamage = _this select 5; +_typeOfDamage = _this select 6; //[_typeOfProjectile] call FUNC(getTypeOfDamage); + +if (GVAR(enableAirway)) then { + [_unit,_selectionName,_amountOfDamage,_sourceOfDamage, _typeOfDamage] call FUNC(handleAirway); +}; +if (GVAR(enableFractures)) then { + [_unit,_selectionName,_amountOfDamage,_sourceOfDamage, _typeOfDamage] call FUNC(handleFractures); +}; +if (GVAR(enableInternalBleeding)) then { + [_unit,_selectionName,_amountOfDamage,_sourceOfDamage, _typeOfDamage] call FUNC(handleInternalInjuries); +}; +_returnDamage; \ No newline at end of file diff --git a/addons/medical/functions/fnc_handleFractures.sqf b/addons/medical/functions/fnc_handleFractures.sqf new file mode 100644 index 0000000000..1fac4f5729 --- /dev/null +++ b/addons/medical/functions/fnc_handleFractures.sqf @@ -0,0 +1,67 @@ +/** + * fn_assignFractures.sqf + * @Descr: N/A + * @Author: Glowbal + * + * @Arguments: [] + * @Return: + * @PublicAPI: false + */ + +#include "script_component.hpp" + +private ["_unit", "_selectionName", "_amountOfDamage", "_sourceOfDamage", "_typeOfDamage", "_bodyPartn", "_fractures", "_fractureType"]; +_unit = _this select 0; +_selectionName = _this select 1; +_amountOfDamage = _this select 2; +_sourceOfDamage = _this select 3; +_typeOfDamage = _this select 4; +_bodyPartn = [_selectionName] call FUNC(selectionNameToNumber); + +_fractureType = 1; +if (_amountOfDamage > 0.05) then { + + // TODO specify fractures based off typeOfInjury details better. + switch (_typeOfDamage) do { + case "Bullet": { + _fractureType = round(random(2)); + }; + case "Grenade": { + _fractureType = round(random(2)); + if (_fractureType < 1) then { + _fractureType = 1; + }; + }; + case "Explosive": { + _fractureType = round(random(2)); + if (_fractureType < 1) then { + _fractureType = 1; + }; + }; + case "Shell": { + _fractureType = round(random(2)); + if (_fractureType < 1) then { + _fractureType = 1; + }; + }; + case "Unknown": { + _fractureType = round(random(1)); + }; + case "VehicleCrash": { + _fractureType = round(random(0)); + }; + default { + _fractureType = round(random(1)); + }; + }; + + private ["_fractures", "_fractureID", "_amountOf"]; + _fractures = _unit getvariable[QGVAR(fractures), []]; + _fractureID = 1; + _amountOf = count _fractures; + if (_amountOf > 0) then { + _fractureID = (_fractures select (_amountOf - 1) select 0) + 1; + }; + _fractures pushback [_fractureID, _fractureType, _bodyPartn, 1 /* percentage treated */]; + _unit setvariable [GVAR(fractures), _fractures, true]; +}; \ No newline at end of file diff --git a/addons/medical/functions/fnc_handleInternalInjuries.sqf b/addons/medical/functions/fnc_handleInternalInjuries.sqf new file mode 100644 index 0000000000..b9a13ae173 --- /dev/null +++ b/addons/medical/functions/fnc_handleInternalInjuries.sqf @@ -0,0 +1,21 @@ +/** + * fn_assignFractures.sqf + * @Descr: N/A + * @Author: Glowbal + * + * @Arguments: [] + * @Return: + * @PublicAPI: false + */ + +#include "script_component.hpp" + +private ["_unit", "_selectionName", "_amountOfDamage", "_sourceOfDamage", "_typeOfDamage", "_bodyPartn"]; +_unit = _this select 0; +_selectionName = _this select 1; +_amountOfDamage = _this select 2; +_sourceOfDamage = _this select 3; +_typeOfDamage = _this select 4; +_bodyPartn = [_selectionName] call FUNC(selectionNameToNumber); + +// TODO implement internal injuries diff --git a/addons/medical/functions/fnc_selectionNameToNumber.sqf b/addons/medical/functions/fnc_selectionNameToNumber.sqf new file mode 100644 index 0000000000..de717d6a33 --- /dev/null +++ b/addons/medical/functions/fnc_selectionNameToNumber.sqf @@ -0,0 +1,13 @@ +/** + * fn_getBodyPartNumber.sqf + * @Descr: N/A + * @Author: Glowbal + * + * @Arguments: [] + * @Return: + * @PublicAPI: false + */ + +#include "script_component.hpp" + +(["head","body","hand_l","hand_r","leg_l","leg_r"] find (_this select 0)); \ No newline at end of file From 596d018f45d34ae8f713efcd3c0c3c2e3156af07 Mon Sep 17 00:00:00 2001 From: Glowbal Date: Tue, 3 Feb 2015 21:48:53 +0100 Subject: [PATCH 3/3] Added function PREPs. --- addons/medical/XEH_preInit.sqf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/medical/XEH_preInit.sqf b/addons/medical/XEH_preInit.sqf index a1a096ac91..577ce8c940 100644 --- a/addons/medical/XEH_preInit.sqf +++ b/addons/medical/XEH_preInit.sqf @@ -6,5 +6,10 @@ PREP(handleDamage); PREP(handleDamage_advanced); PREP(handleDamage_basic); PREP(handleDamage_medium); +PREP(handleAirway); +PREP(handleFractures); +PREP(handleInternalInjuries); +PREP(getTypeOfDamage); +PREP(selectionNameToNumber); ADDON = true;