-
Notifications
You must be signed in to change notification settings - Fork 740
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Medical Treatment - Extract stitching & trauma code (#10543)
Co-authored-by: PabstMirror <[email protected]> Co-authored-by: johnb432 <[email protected]>
- Loading branch information
1 parent
630c35b
commit 77248d7
Showing
19 changed files
with
149 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "..\script_component.hpp" | ||
/* | ||
* Author: LinkIsGrim | ||
* Add trauma to a body part. | ||
* | ||
* Arguments: | ||
* 0: Patient <OBJECT> | ||
* 1: Body Part <STRING> | ||
* 2: Amount of trauma to add, negative to remove <NUMBER> | ||
* | ||
* Return Value: | ||
* None | ||
* | ||
* Example: | ||
* [player, "head", -5] call ace_medical_treatment_fnc_addTrauma | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params ["_unit", "_bodyPart", "_trauma"]; | ||
|
||
private _partIndex = ALL_BODY_PARTS find _bodyPart; | ||
private _bodyPartDamage = GET_BODYPART_DAMAGE(_unit); | ||
private _newDam = (_bodyPartDamage select _partIndex) + _trauma; | ||
|
||
// Prevent obscenely small damage from lack of floating precision | ||
if (_trauma < 0 && _newDam < 0.05) then { | ||
_bodyPartDamage set [_partIndex, 0]; | ||
} else { | ||
_bodyPartDamage set [_partIndex, _newDam]; | ||
}; | ||
|
||
// Update body part visuals | ||
switch (_bodyPart) do { | ||
case "head": { [_unit, true, false, false, false] call EFUNC(medical_engine,updateBodyPartVisuals); }; | ||
case "body": { [_unit, false, true, false, false] call EFUNC(medical_engine,updateBodyPartVisuals); }; | ||
case "leftarm"; | ||
case "rightarm": { [_unit, false, false, true, false] call EFUNC(medical_engine,updateBodyPartVisuals); }; | ||
default { [_unit, false, false, false, true] call EFUNC(medical_engine,updateBodyPartVisuals); }; | ||
}; | ||
|
||
TRACE_2("trauma - added damage",_trauma,_newDam); | ||
_unit setVariable [VAR_BODYPART_DAMAGE, _bodyPartDamage, true]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "..\script_component.hpp" | ||
/* | ||
* Author: BaerMitUmlaut, mharis001, LinkIsGrim | ||
* Stitches a wound (either the first or a specific wound) from a body part. | ||
* | ||
* Arguments: | ||
* 0: Patient <OBJECT> | ||
* 1: Body Part <STRING> | ||
* 2: Wound Array, will close first wound on body part if empty <ARRAY> (default: []) | ||
* | ||
* Return Value: | ||
* Wound was stitched <BOOL> | ||
* | ||
* Example: | ||
* [player, "head"] call ace_medical_treatment_fnc_stitchWound | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params ["_patient", "_bodyPart", ["_treatedWound", []]]; | ||
|
||
private _bandagedWounds = GET_BANDAGED_WOUNDS(_patient); | ||
private _bandagedWoundsOnPart = _bandagedWounds getOrDefault [_bodyPart, []]; | ||
|
||
// Get the first stitchable wound from bandaged wounds, or make sure the passed wound exists | ||
private _bandagedIndex = (count _bandagedWoundsOnPart) - 1; | ||
if (_treatedWound isEqualTo []) then { | ||
_treatedWound = _bandagedWoundsOnPart param [_bandagedIndex, _treatedWound]; | ||
} else { | ||
_bandagedIndex = _bandagedWoundsOnPart find _treatedWound; | ||
}; | ||
|
||
// Wound doesn't exist or there are no bandaged wounds to stitch | ||
if (_bandagedIndex == -1) exitWith {false}; | ||
|
||
// Remove the wound from bandagedWounds | ||
_bandagedWoundsOnPart deleteAt _bandagedIndex; | ||
|
||
_treatedWound params ["_treatedID", "_treatedAmountOf", "", "_treatedDamageOf"]; | ||
|
||
// Check if we need to add a new stitched wound or increase the amount of an existing one | ||
private _stitchedWounds = GET_STITCHED_WOUNDS(_patient); | ||
private _stitchedWoundsOnPart = _stitchedWounds getOrDefault [_bodyPart, [], true]; | ||
|
||
private _stitchedIndex = _stitchedWoundsOnPart findIf { | ||
_x params ["_classID"]; | ||
_classID == _treatedID | ||
}; | ||
|
||
if (_stitchedIndex == -1) then { | ||
_stitchedWoundsOnPart pushBack _treatedWound; | ||
} else { | ||
private _wound = _stitchedWoundsOnPart select _stitchedIndex; | ||
_wound set [1, (_wound select 1) + _treatedAmountOf]; | ||
}; | ||
|
||
if (GVAR(clearTrauma) == 1) then { | ||
TRACE_2("trauma - clearing trauma after stitching",_bodyPart,_treatedWound); | ||
[_patient, _bodyPart, -(_treatedDamageOf * _treatedAmountOf)] call FUNC(addTrauma); | ||
}; | ||
|
||
_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]} | ||
&& {_bodyPart in ["leftleg", "rightleg"]} | ||
) then { | ||
TRACE_3("Updating damage effects",_patient,_bodyPart,local _patient); | ||
[QEGVAR(medical_engine,updateDamageEffects), _patient, _patient] call CBA_fnc_targetEvent; | ||
}; | ||
|
||
true // return |
Oops, something went wrong.