From e9248ea866764f4d833b0b1b5d2fb2b7e2f4755f Mon Sep 17 00:00:00 2001 From: LinkIsGrim <69561145+LinkIsGrim@users.noreply.github.com> Date: Sat, 14 Dec 2024 09:37:25 -0300 Subject: [PATCH 1/5] Medical - Add API for getting unit wounds --- addons/medical/XEH_PREP.hpp | 3 ++ .../functions/fnc_getBandagedWounds.sqf | 31 +++++++++++++++++ .../medical/functions/fnc_getOpenWounds.sqf | 34 +++++++++++++++++++ .../functions/fnc_getStitchedWounds.sqf | 31 +++++++++++++++++ 4 files changed, 99 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..a501b900065 --- /dev/null +++ b/addons/medical/functions/fnc_getBandagedWounds.sqf @@ -0,0 +1,31 @@ +#include "..\script_component.hpp" +/* + * Author: LinkInsGrim + * 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_getOpenWounds + * + * Public: Yes + */ + +params ["_unit", "_bodyPart"]; + +private _bandagedWounds = []; + +{ + _bandagedWounds pushBack +_x; // manual deep copy so modification doesn't affect unit state +} forEach (GET_OPEN_WOUNDS(_patient) getOrDefault [toLowerANSI _bodyPart, []]); + +_bandagedWounds diff --git a/addons/medical/functions/fnc_getOpenWounds.sqf b/addons/medical/functions/fnc_getOpenWounds.sqf new file mode 100644 index 00000000000..9f04a1bd013 --- /dev/null +++ b/addons/medical/functions/fnc_getOpenWounds.sqf @@ -0,0 +1,34 @@ +#include "..\script_component.hpp" +/* + * Author: LinkInsGrim + * 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", "_bodyPart"]; + +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..014eb6ffd45 --- /dev/null +++ b/addons/medical/functions/fnc_getStitchedWounds.sqf @@ -0,0 +1,31 @@ +#include "..\script_component.hpp" +/* + * Author: LinkInsGrim + * 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_getOpenWounds + * + * Public: Yes + */ + +params ["_unit", "_bodyPart"]; + +private _stitchedWounds = []; + +{ + _stitchedWounds pushBack +_x; // manual deep copy so modification doesn't affect unit state +} forEach (GET_STITCHED_WOUNDS(_patient) getOrDefault [toLowerANSI _bodyPart, []]); + +_stitchedWounds From fc745aaab0172aa6d4dc835f04307e194d3e034c Mon Sep 17 00:00:00 2001 From: LinkIsGrim <69561145+LinkIsGrim@users.noreply.github.com> Date: Sat, 14 Dec 2024 09:43:10 -0300 Subject: [PATCH 2/5] fix headers --- addons/medical/functions/fnc_getBandagedWounds.sqf | 2 +- addons/medical/functions/fnc_getStitchedWounds.sqf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/medical/functions/fnc_getBandagedWounds.sqf b/addons/medical/functions/fnc_getBandagedWounds.sqf index a501b900065..23c349f49da 100644 --- a/addons/medical/functions/fnc_getBandagedWounds.sqf +++ b/addons/medical/functions/fnc_getBandagedWounds.sqf @@ -15,7 +15,7 @@ * 3: Wound Damage * * Example: - * [player, "head"] call ace_medical_fnc_getOpenWounds + * [player, "head"] call ace_medical_fnc_getBandagedWounds * * Public: Yes */ diff --git a/addons/medical/functions/fnc_getStitchedWounds.sqf b/addons/medical/functions/fnc_getStitchedWounds.sqf index 014eb6ffd45..804094f1016 100644 --- a/addons/medical/functions/fnc_getStitchedWounds.sqf +++ b/addons/medical/functions/fnc_getStitchedWounds.sqf @@ -15,7 +15,7 @@ * 3: Wound Damage * * Example: - * [player, "head"] call ace_medical_fnc_getOpenWounds + * [player, "head"] call ace_medical_fnc_getStitchedWounds * * Public: Yes */ From 2cbc06efd6dbd897f1a48aab0379267d851642c9 Mon Sep 17 00:00:00 2001 From: LinkIsGrim <69561145+LinkIsGrim@users.noreply.github.com> Date: Sun, 15 Dec 2024 16:37:40 -0300 Subject: [PATCH 3/5] fix name in headers --- addons/medical/functions/fnc_getBandagedWounds.sqf | 2 +- addons/medical/functions/fnc_getOpenWounds.sqf | 2 +- addons/medical/functions/fnc_getStitchedWounds.sqf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/medical/functions/fnc_getBandagedWounds.sqf b/addons/medical/functions/fnc_getBandagedWounds.sqf index 23c349f49da..8a99593e9f5 100644 --- a/addons/medical/functions/fnc_getBandagedWounds.sqf +++ b/addons/medical/functions/fnc_getBandagedWounds.sqf @@ -1,6 +1,6 @@ #include "..\script_component.hpp" /* - * Author: LinkInsGrim + * Author: LinkIsGrim * Returns a copy of unit's bandaged wounds on a body part. * * Arguments: diff --git a/addons/medical/functions/fnc_getOpenWounds.sqf b/addons/medical/functions/fnc_getOpenWounds.sqf index 9f04a1bd013..fea3a02c89e 100644 --- a/addons/medical/functions/fnc_getOpenWounds.sqf +++ b/addons/medical/functions/fnc_getOpenWounds.sqf @@ -1,6 +1,6 @@ #include "..\script_component.hpp" /* - * Author: LinkInsGrim + * Author: LinkIsGrim * Returns a copy of unit's open wounds on a body part. * * Arguments: diff --git a/addons/medical/functions/fnc_getStitchedWounds.sqf b/addons/medical/functions/fnc_getStitchedWounds.sqf index 804094f1016..dd4239cfa30 100644 --- a/addons/medical/functions/fnc_getStitchedWounds.sqf +++ b/addons/medical/functions/fnc_getStitchedWounds.sqf @@ -1,6 +1,6 @@ #include "..\script_component.hpp" /* - * Author: LinkInsGrim + * Author: LinkIsGrim * Returns a copy of unit's stitched wounds on a body part. * * Arguments: From 2a72e751c837a700a243cad903aa86b3a8987c36 Mon Sep 17 00:00:00 2001 From: LinkIsGrim <69561145+LinkIsGrim@users.noreply.github.com> Date: Sun, 15 Dec 2024 16:44:58 -0300 Subject: [PATCH 4/5] add errors and type checking --- .../functions/fnc_getBandagedWounds.sqf | 24 +++++++++++++++++-- .../medical/functions/fnc_getOpenWounds.sqf | 22 ++++++++++++++++- .../functions/fnc_getStitchedWounds.sqf | 22 ++++++++++++++++- 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/addons/medical/functions/fnc_getBandagedWounds.sqf b/addons/medical/functions/fnc_getBandagedWounds.sqf index 8a99593e9f5..5b270c86e4d 100644 --- a/addons/medical/functions/fnc_getBandagedWounds.sqf +++ b/addons/medical/functions/fnc_getBandagedWounds.sqf @@ -20,12 +20,32 @@ * Public: Yes */ -params ["_unit", "_bodyPart"]; +params [["_unit", objNull, [objNull]], ["_bodyPart", "", [""]]]; + +if (isNull _unit) exitWith { + ERROR("getBandagedWounds - bad call, null unit"); + + [] +}; + +if !(_unit isKindOf "CAManBase") exitWith { + ERROR_2("getBandagedWounds - bad call, 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 - bad call, 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 [toLowerANSI _bodyPart, []]); +} forEach (GET_OPEN_WOUNDS(_patient) getOrDefault [_bodyPart, []]); _bandagedWounds diff --git a/addons/medical/functions/fnc_getOpenWounds.sqf b/addons/medical/functions/fnc_getOpenWounds.sqf index fea3a02c89e..34a972b6475 100644 --- a/addons/medical/functions/fnc_getOpenWounds.sqf +++ b/addons/medical/functions/fnc_getOpenWounds.sqf @@ -20,7 +20,27 @@ * Public: Yes */ -params ["_unit", "_bodyPart"]; +params [["_unit", objNull, [objNull]], ["_bodyPart", "", [""]]]; + +if (isNull _unit) exitWith { + ERROR("getOpenWounds - bad call, null unit"); + + [] +}; + +if !(_unit isKindOf "CAManBase") exitWith { + ERROR_2("getOpenWounds - bad call, 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 - bad call, invalid body part %1, expected one of %2",_bodyPart,ALL_BODY_PARTS); + + [] +}; private _openWounds = []; diff --git a/addons/medical/functions/fnc_getStitchedWounds.sqf b/addons/medical/functions/fnc_getStitchedWounds.sqf index dd4239cfa30..24fa4345717 100644 --- a/addons/medical/functions/fnc_getStitchedWounds.sqf +++ b/addons/medical/functions/fnc_getStitchedWounds.sqf @@ -20,7 +20,27 @@ * Public: Yes */ -params ["_unit", "_bodyPart"]; +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 = []; From d2c20e8029a1698251bfc14654c61e327159d3af Mon Sep 17 00:00:00 2001 From: LinkIsGrim <69561145+LinkIsGrim@users.noreply.github.com> Date: Sun, 15 Dec 2024 16:46:17 -0300 Subject: [PATCH 5/5] fix error inconsistency --- addons/medical/functions/fnc_getBandagedWounds.sqf | 6 +++--- addons/medical/functions/fnc_getOpenWounds.sqf | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/medical/functions/fnc_getBandagedWounds.sqf b/addons/medical/functions/fnc_getBandagedWounds.sqf index 5b270c86e4d..5da49c94d61 100644 --- a/addons/medical/functions/fnc_getBandagedWounds.sqf +++ b/addons/medical/functions/fnc_getBandagedWounds.sqf @@ -23,13 +23,13 @@ params [["_unit", objNull, [objNull]], ["_bodyPart", "", [""]]]; if (isNull _unit) exitWith { - ERROR("getBandagedWounds - bad call, null unit"); + ERROR("getBandagedWounds - null unit"); [] }; if !(_unit isKindOf "CAManBase") exitWith { - ERROR_2("getBandagedWounds - bad call, unit %1 is not child of CAManBase - type %2",_unit,typeOf _unit); + ERROR_2("getBandagedWounds - unit %1 is not child of CAManBase - type %2",_unit,typeOf _unit); [] }; @@ -37,7 +37,7 @@ if !(_unit isKindOf "CAManBase") exitWith { _bodyPart = toLowerANSI _bodyPart; if !(_bodyPart in ALL_BODY_PARTS) exitWith { - ERROR_2("getBandagedWounds - bad call, invalid body part %1, expected one of %2",_bodyPart,ALL_BODY_PARTS); + ERROR_2("getBandagedWounds - invalid body part %1, expected one of %2",_bodyPart,ALL_BODY_PARTS); [] }; diff --git a/addons/medical/functions/fnc_getOpenWounds.sqf b/addons/medical/functions/fnc_getOpenWounds.sqf index 34a972b6475..36d43fb7535 100644 --- a/addons/medical/functions/fnc_getOpenWounds.sqf +++ b/addons/medical/functions/fnc_getOpenWounds.sqf @@ -23,13 +23,13 @@ params [["_unit", objNull, [objNull]], ["_bodyPart", "", [""]]]; if (isNull _unit) exitWith { - ERROR("getOpenWounds - bad call, null unit"); + ERROR("getOpenWounds - null unit"); [] }; if !(_unit isKindOf "CAManBase") exitWith { - ERROR_2("getOpenWounds - bad call, unit %1 is not child of CAManBase - type %2",_unit,typeOf _unit); + ERROR_2("getOpenWounds - unit %1 is not child of CAManBase - type %2",_unit,typeOf _unit); [] }; @@ -37,7 +37,7 @@ if !(_unit isKindOf "CAManBase") exitWith { _bodyPart = toLowerANSI _bodyPart; if !(_bodyPart in ALL_BODY_PARTS) exitWith { - ERROR_2("getOpenWounds - bad call, invalid body part %1, expected one of %2",_bodyPart,ALL_BODY_PARTS); + ERROR_2("getOpenWounds - invalid body part %1, expected one of %2",_bodyPart,ALL_BODY_PARTS); [] };