From ec9e6c088b4d504ff7d34643dae9aa3183b251cb Mon Sep 17 00:00:00 2001 From: mharis001 <34453221+mharis001@users.noreply.github.com> Date: Sat, 28 Sep 2019 16:48:19 -0400 Subject: [PATCH] Medical - Only stitch wounds on not bleeding body parts (#7044) * Only stitch wounds on not bleeding body parts --- addons/medical/dev/watchVariable.sqf | 2 +- .../medical_engine/script_macros_medical.hpp | 3 ++ .../functions/fnc_isInStableCondition.sqf | 8 ++-- addons/medical_treatment/XEH_PREP.hpp | 1 + .../functions/fnc_canStitch.sqf | 4 +- .../functions/fnc_getStitchTime.sqf | 6 +-- .../functions/fnc_getStitchableWounds.sqf | 33 +++++++++++++ .../functions/fnc_surgicalKitProgress.sqf | 48 ++++++++++++------- 8 files changed, 77 insertions(+), 28 deletions(-) create mode 100644 addons/medical_treatment/functions/fnc_getStitchableWounds.sqf diff --git a/addons/medical/dev/watchVariable.sqf b/addons/medical/dev/watchVariable.sqf index 44eca21b95..36cc690936 100644 --- a/addons/medical/dev/watchVariable.sqf +++ b/addons/medical/dev/watchVariable.sqf @@ -91,7 +91,7 @@ GVAR(dev_watchVariableRunning) = true; // Wounds: - _return pushBack "------- Wounds: -------"; + _return pushBack "------- Open Wounds: -------"; private _wounds = GET_OPEN_WOUNDS(_unit); { _x params ["_xClassID", "_xBodyPartN", "_xAmountOf", "_xBleeding", "_xDamage"]; diff --git a/addons/medical_engine/script_macros_medical.hpp b/addons/medical_engine/script_macros_medical.hpp index 13084d8ae0..103a28cbec 100644 --- a/addons/medical_engine/script_macros_medical.hpp +++ b/addons/medical_engine/script_macros_medical.hpp @@ -94,6 +94,9 @@ #define DEFAULT_BANDAGE_REOPENING_MIN_DELAY 120 #define DEFAULT_BANDAGE_REOPENING_MAX_DELAY 200 +// Time it takes to stitch one wound +#define WOUND_STITCH_TIME 5 + #define DEFAULT_TOURNIQUET_VALUES [0,0,0,0,0,0] #define DEFAULT_FRACTURE_VALUES [0,0,0,0,0,0] diff --git a/addons/medical_status/functions/fnc_isInStableCondition.sqf b/addons/medical_status/functions/fnc_isInStableCondition.sqf index 56226d3024..36ff02ac2b 100644 --- a/addons/medical_status/functions/fnc_isInStableCondition.sqf +++ b/addons/medical_status/functions/fnc_isInStableCondition.sqf @@ -17,7 +17,7 @@ params ["_unit"]; -(alive _unit - && {!IS_UNCONSCIOUS(_unit)} - && {GET_WOUND_BLEEDING(_unit) == 0} - && {_unit call FUNC(hasStableVitals)}) +alive _unit +&& {!IS_UNCONSCIOUS(_unit)} +&& {GET_WOUND_BLEEDING(_unit) == 0} +&& {_unit call FUNC(hasStableVitals)} diff --git a/addons/medical_treatment/XEH_PREP.hpp b/addons/medical_treatment/XEH_PREP.hpp index 5b18bba14e..7bdd1eff36 100644 --- a/addons/medical_treatment/XEH_PREP.hpp +++ b/addons/medical_treatment/XEH_PREP.hpp @@ -29,6 +29,7 @@ PREP(fullHeal); PREP(fullHealLocal); PREP(getBandageTime); PREP(getHealTime); +PREP(getStitchableWounds); PREP(getStitchTime); PREP(getTriageStatus); PREP(handleBandageOpening); diff --git a/addons/medical_treatment/functions/fnc_canStitch.sqf b/addons/medical_treatment/functions/fnc_canStitch.sqf index 6d1ab36465..ea4318874d 100644 --- a/addons/medical_treatment/functions/fnc_canStitch.sqf +++ b/addons/medical_treatment/functions/fnc_canStitch.sqf @@ -1,6 +1,6 @@ #include "script_component.hpp" /* - * Author: Katalam + * Author: Katalam, mharis001 * Checks if the patient can be stitched. * * Arguments: @@ -18,4 +18,4 @@ params ["", "_patient"]; -!(GET_BANDAGED_WOUNDS(_patient) isEqualTo []) +!(_patient call FUNC(getStitchableWounds) isEqualTo []) diff --git a/addons/medical_treatment/functions/fnc_getStitchTime.sqf b/addons/medical_treatment/functions/fnc_getStitchTime.sqf index 81bf948ab2..9d0254605a 100644 --- a/addons/medical_treatment/functions/fnc_getStitchTime.sqf +++ b/addons/medical_treatment/functions/fnc_getStitchTime.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: mharis001 - * Calculates the Surgical Kit treatment time based on the amount of bandaged wounds. + * Calculates the Surgical Kit treatment time based on the amount of stitchable wounds. * * Arguments: * 0: Medic (not used) @@ -16,8 +16,6 @@ * Public: No */ -#define TIME_PER_WOUND 5 - params ["", "_patient"]; -count GET_BANDAGED_WOUNDS(_patient) * TIME_PER_WOUND +count (_patient call FUNC(getStitchableWounds)) * WOUND_STITCH_TIME diff --git a/addons/medical_treatment/functions/fnc_getStitchableWounds.sqf b/addons/medical_treatment/functions/fnc_getStitchableWounds.sqf new file mode 100644 index 0000000000..a46d878409 --- /dev/null +++ b/addons/medical_treatment/functions/fnc_getStitchableWounds.sqf @@ -0,0 +1,33 @@ +#include "script_component.hpp" +/* + * Author: mharis001 + * Returns a list of all the stitchable wounds that the given unit has. + * A stitchable wound is a bandaged wound on a body part that does not have any bleeding wounds. + * + * Arguments: + * 0: Unit + * + * Return Value: + * Stitchable Wounds + * + * Example: + * [player] call ace_medical_treatment_fnc_getStitchableWounds + * + * Public: No + */ + +params ["_unit"]; + +private _bleedingBodyParts = GET_OPEN_WOUNDS(_unit) select { + _x params ["", "", "_amountOf", "_bleedingRate"]; + + _amountOf > 0 && {_bleedingRate > 0} +} apply { + _x select 1 +}; + +GET_BANDAGED_WOUNDS(_unit) select { + _x params ["", "_bodyPartN"]; + + !(_bodyPartN in _bleedingBodyParts) +} diff --git a/addons/medical_treatment/functions/fnc_surgicalKitProgress.sqf b/addons/medical_treatment/functions/fnc_surgicalKitProgress.sqf index e41cdf16b7..9dcd7265e1 100644 --- a/addons/medical_treatment/functions/fnc_surgicalKitProgress.sqf +++ b/addons/medical_treatment/functions/fnc_surgicalKitProgress.sqf @@ -1,6 +1,6 @@ #include "script_component.hpp" /* - * Author: BaerMitUmlaut + * Author: BaerMitUmlaut, mharis001 * Handles the surgical kit treatment by periodically closing bandaged wounds. * * Arguments: @@ -22,28 +22,42 @@ params ["_args", "_elapsedTime", "_totalTime"]; _args params ["", "_patient"]; +private _stitchableWounds = _patient call FUNC(getStitchableWounds); + +// Stop treatment if there are no wounds that can be stitched remaining +if (_stitchableWounds isEqualTo []) exitWith {false}; + +// Not enough time has elapsed to stitch a wound +if (_totalTime - _elapsedTime > (count _stitchableWounds - 1) * WOUND_STITCH_TIME) exitWith {true}; + private _bandagedWounds = GET_BANDAGED_WOUNDS(_patient); private _stitchedWounds = GET_STITCHED_WOUNDS(_patient); -// Stop treatment if there are no wounds that can be stitched remaining -if (_bandagedWounds isEqualTo []) exitWith { false }; +// Remove the first stitchable wound from the bandaged wounds +private _treatedWound = _bandagedWounds deleteAt (_bandagedWounds find (_stitchableWounds select 0)); +_treatedWound params ["_treatedID", "_treatedBodyPartN", "_treatedAmountOf"]; -// Check if enough time has elapsed to stitch another wound -if (_totalTime - _elapsedTime <= (count _bandagedWounds - 1) * 5) then { - private _treatedWound = _bandagedWounds deleteAt 0; +// Check if we need to add a new stitched wound or increase the amount of an existing one +private _woundIndex = _stitchedWounds findIf { + _x params ["_classID", "_bodyPartN"]; + + _classID == _treatedID && {_bodyPartN == _treatedBodyPartN} +}; + +if (_woundIndex == -1) then { _stitchedWounds pushBack _treatedWound; - _patient setVariable [VAR_BANDAGED_WOUNDS, _bandagedWounds, true]; - _patient setVariable [VAR_STITCHED_WOUNDS, _stitchedWounds, true]; - TRACE_3("stitched",_treatedWound,count _bandagedWounds,count _stitchedWounds); +} else { + private _wound = _stitchedWounds select _woundIndex; + _wound set [2, (_wound select 2) + _treatedAmountOf]; +}; - // Check if we fixed limping from this treatment - if ((EGVAR(medical,limping) == 2) && {_patient getVariable [QEGVAR(medical,isLimping), false]}) then { - _treatedWound params ["", "_partN"]; - if (_partN > 3) then { // only for LEG wounds - TRACE_3("updating damage effects",_patient,_partN,local _patient); - [QEGVAR(medical_engine,updateDamageEffects), [_patient], _patient] call CBA_fnc_patientEvent; - }; - }; +_patient setVariable [VAR_BANDAGED_WOUNDS, _bandagedWounds, true]; +_patient setVariable [VAR_STITCHED_WOUNDS, _stitchedWounds, true]; + +// Check if we fixed limping by stitching this wound (only for leg wounds) +if (EGVAR(medical,limping) == 2 && {_patient getVariable [QEGVAR(medical,isLimping), false]} && {_treatedBodyPartN > 3}) then { + TRACE_3("Updating damage effects",_patient,_treatedBodyPartN,local _patient); + [QEGVAR(medical_engine,updateDamageEffects), _patient, _patient] call CBA_fnc_targetEvent; }; true