From 6ddd020a0f2e939f34805c82db1e3725c8b61804 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Sun, 15 Dec 2024 19:04:21 -0300 Subject: [PATCH] Medical - Add API for getting unit wounds (#10544) --- addons/medical/XEH_PREP.hpp | 3 ++ .../functions/fnc_getBandagedWounds.sqf | 51 ++++++++++++++++++ .../medical/functions/fnc_getOpenWounds.sqf | 54 +++++++++++++++++++ .../functions/fnc_getStitchedWounds.sqf | 51 ++++++++++++++++++ 4 files changed, 159 insertions(+) create mode 100644 addons/medical/functions/fnc_getBandagedWounds.sqf create mode 100644 addons/medical/functions/fnc_getOpenWounds.sqf create mode 100644 addons/medical/functions/fnc_getStitchedWounds.sqf diff --git a/addons/medical/XEH_PREP.hpp b/addons/medical/XEH_PREP.hpp index d1edb26493b..072cb6262c1 100644 --- a/addons/medical/XEH_PREP.hpp +++ b/addons/medical/XEH_PREP.hpp @@ -2,5 +2,8 @@ PREP(addDamageToUnit); PREP(adjustPainLevel); PREP(deserializeState); PREP(fullHeal); +PREP(getBandagedWounds); +PREP(getOpenWounds); +PREP(getStitchedWounds); PREP(serializeState); PREP(setUnconscious); diff --git a/addons/medical/functions/fnc_getBandagedWounds.sqf b/addons/medical/functions/fnc_getBandagedWounds.sqf new file mode 100644 index 00000000000..5da49c94d61 --- /dev/null +++ b/addons/medical/functions/fnc_getBandagedWounds.sqf @@ -0,0 +1,51 @@ +#include "..\script_component.hpp" +/* + * Author: LinkIsGrim + * Returns a copy of unit's bandaged wounds on a body part. + * + * Arguments: + * 0: Unit + * 1: Body Part + * + * Return Value: + * Wounds : + * 0: Wound Class ID + * 1: Wound Bandaged Amount + * 2: Wound Bleeding Coef + * 3: Wound Damage + * + * Example: + * [player, "head"] call ace_medical_fnc_getBandagedWounds + * + * Public: Yes + */ + +params [["_unit", objNull, [objNull]], ["_bodyPart", "", [""]]]; + +if (isNull _unit) exitWith { + ERROR("getBandagedWounds - null unit"); + + [] +}; + +if !(_unit isKindOf "CAManBase") exitWith { + ERROR_2("getBandagedWounds - unit %1 is not child of CAManBase - type %2",_unit,typeOf _unit); + + [] +}; + +_bodyPart = toLowerANSI _bodyPart; + +if !(_bodyPart in ALL_BODY_PARTS) exitWith { + ERROR_2("getBandagedWounds - invalid body part %1, expected one of %2",_bodyPart,ALL_BODY_PARTS); + + [] +}; + +private _bandagedWounds = []; + +{ + _bandagedWounds pushBack +_x; // manual deep copy so modification doesn't affect unit state +} forEach (GET_OPEN_WOUNDS(_patient) getOrDefault [_bodyPart, []]); + +_bandagedWounds diff --git a/addons/medical/functions/fnc_getOpenWounds.sqf b/addons/medical/functions/fnc_getOpenWounds.sqf new file mode 100644 index 00000000000..36d43fb7535 --- /dev/null +++ b/addons/medical/functions/fnc_getOpenWounds.sqf @@ -0,0 +1,54 @@ +#include "..\script_component.hpp" +/* + * Author: LinkIsGrim + * Returns a copy of unit's open wounds on a body part. + * + * Arguments: + * 0: Unit + * 1: Body Part + * + * Return Value: + * Wounds : + * 0: Wound Class ID + * 1: Wound Open Amount + * 2: Wound Bleeding Coef + * 3: Wound Damage + * + * Example: + * [player, "head"] call ace_medical_fnc_getOpenWounds + * + * Public: Yes + */ + +params [["_unit", objNull, [objNull]], ["_bodyPart", "", [""]]]; + +if (isNull _unit) exitWith { + ERROR("getOpenWounds - null unit"); + + [] +}; + +if !(_unit isKindOf "CAManBase") exitWith { + ERROR_2("getOpenWounds - unit %1 is not child of CAManBase - type %2",_unit,typeOf _unit); + + [] +}; + +_bodyPart = toLowerANSI _bodyPart; + +if !(_bodyPart in ALL_BODY_PARTS) exitWith { + ERROR_2("getOpenWounds - invalid body part %1, expected one of %2",_bodyPart,ALL_BODY_PARTS); + + [] +}; + +private _openWounds = []; + +{ + _x params ["", "_xAmount"]; + if (_xAmount > 0) then { // bandaged wounds are open wounds with count 0, skip those + _openWounds pushBack +_x; // manual deep copy so modification doesn't affect unit state + }; +} forEach (GET_OPEN_WOUNDS(_patient) getOrDefault [toLowerANSI _bodyPart, []]); + +_openWounds diff --git a/addons/medical/functions/fnc_getStitchedWounds.sqf b/addons/medical/functions/fnc_getStitchedWounds.sqf new file mode 100644 index 00000000000..24fa4345717 --- /dev/null +++ b/addons/medical/functions/fnc_getStitchedWounds.sqf @@ -0,0 +1,51 @@ +#include "..\script_component.hpp" +/* + * Author: LinkIsGrim + * Returns a copy of unit's stitched wounds on a body part. + * + * Arguments: + * 0: Unit + * 1: Body Part + * + * Return Value: + * Wounds : + * 0: Wound Class ID + * 1: Wound Stitched Amount + * 2: Wound Bleeding Coef + * 3: Wound Damage + * + * Example: + * [player, "head"] call ace_medical_fnc_getStitchedWounds + * + * Public: Yes + */ + +params [["_unit", objNull, [objNull]], ["_bodyPart", "", [""]]]; + +if (isNull _unit) exitWith { + ERROR("getStitchedWounds - null unit"); + + [] +}; + +if !(_unit isKindOf "CAManBase") exitWith { + ERROR_2("getStitchedWounds - unit %1 is not child of CAManBase - type %2",_unit,typeOf _unit); + + [] +}; + +_bodyPart = toLowerANSI _bodyPart; + +if !(_bodyPart in ALL_BODY_PARTS) exitWith { + ERROR_2("getStitchedWounds - invalid body part %1, expected one of %2",_bodyPart,ALL_BODY_PARTS); + + [] +}; + +private _stitchedWounds = []; + +{ + _stitchedWounds pushBack +_x; // manual deep copy so modification doesn't affect unit state +} forEach (GET_STITCHED_WOUNDS(_patient) getOrDefault [toLowerANSI _bodyPart, []]); + +_stitchedWounds