Skip to content

Commit

Permalink
Damage Handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Cplhardcore committed Nov 30, 2024
1 parent 2b93099 commit 02e526b
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 13 deletions.
3 changes: 3 additions & 0 deletions addons/medical_damage/ACE_Medical_Injuries.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ class ACE_Medical_Injuries {
// explosives create more and smaller wounds than grenades
thresholds[] = {{20, 15}, {8, 7}, {2, 3}, {1.2, 2}, {0.4, 1}, {0,0}};
selectionSpecific = 0;
class woundHandlers: woundHandlers {
GVAR(woundsHandlerExplosion) = QFUNC(woundsHandlerExplosion);
};
class Avulsion {
weighting[] = {{1, 1}, {0.8, 0}};
};
Expand Down
1 change: 1 addition & 0 deletions addons/medical_damage/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ PREP(parseWoundHandlersCfg);
PREP(woundReceived);
PREP(woundsHandlerBase);
PREP(woundsHandlerBurning);
PREP(woundsHandlerExplosion);
PREP(woundsHandlerVehiclecrash);
PREP(woundsHandlerVehiclehit);
24 changes: 13 additions & 11 deletions addons/medical_damage/functions/fnc_woundsHandlerBase.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,19 @@ private _bodyPartVisParams = [_unit, false, false, false, false]; // params arra
{ // forEach _allDamages
_x params ["_damage", "_bodyPart"];
_bodyPart = toLowerANSI _bodyPart;
if (_bodyPart == "head") then {
private _isNeck = (random 1) < 0.1; // 10% chance for neck damage
_bodyPart = ["head", "neck"] select (_isNeck);
};
if (_bodyPart in ["leftarm", "rightarm", "leftleg", "rightleg"]) then {
private _isUpper = (random 1) < 0.5;
switch (_bodyPart) do {
case "leftarm": { _bodyPart = ["leftarm", "upperleftarm"] select (_isUpper);};
case "rightarm": { _bodyPart = ["rightarm", "upperrightarm"] select (_isUpper);};
case "leftleg": { _bodyPart = ["leftleg", "upperleftleg"] select (_isUpper);};
case "rightleg": { _bodyPart = ["rightleg", "upperrightleg"] select (_isUpper); };
if (_typeOfDamage != "explosive") then {
if (_bodyPart == "head") then {
private _isNeck = (random 1) < 0.1; // 10% chance for neck damage
_bodyPart = ["head", "neck"] select (_isNeck);
};
if (_bodyPart in ["leftarm", "rightarm", "leftleg", "rightleg"]) then {
private _isUpper = (random 1) < 0.5;
switch (_bodyPart) do {
case "leftarm": { _bodyPart = ["leftarm", "upperleftarm"] select (_isUpper); };
case "rightarm": { _bodyPart = ["rightarm", "upperrightarm"] select (_isUpper); };
case "leftleg": { _bodyPart = ["leftleg", "upperleftleg"] select (_isUpper); };
case "rightleg": { _bodyPart = ["rightleg", "upperrightleg"] select (_isUpper); };
};
};
};
// silently ignore structural damage
Expand Down
63 changes: 63 additions & 0 deletions addons/medical_damage/functions/fnc_woundsHandlerExplosion.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "..\script_component.hpp"
/*
* Author: Cplhardcore
* Custom wound handler for explosions
*
* Arguments:
* 0: Unit That Was Hit <OBJECT>
* 1: Damage done to each body part <ARRAY>
* 2: Type of the damage done <STRING>
*
* Return Value:
* None
*
* Example:
* [player, [[0.5, "#structural", 1.5]], "vehiclehit"] call ace_medical_damage_fnc_woundsHandlerExplosion
*
* Public: No
*/
params ["_unit", "_allDamages", "_typeOfDamage"];
TRACE_3("woundsHandlerExplosion",_unit,_allDamages,_typeOfDamage);

// damage can sometimes be negative (why?)
// damage to structural is low unless it's a very large explosion, in which case it is typically >= 1
private _damageToApply = (abs (_allDamages select 0 select 0));
private _damageMap = createHashMap;
private _allBodyParts = ALL_BODY_PARTS; // micro-optimization here and above, don't recreate this array every time

// use a hashmap so we only create one entry in _newDamages per body part
{
private _damageData = _x;
_damageData params ["_engineDamage", "_bodyPart", "_realDamage"];
switch (true) do {
case (_bodyPart isEqualTo "LeftArm"): {
_damageMap set ["LeftArm", _damageToApply * 0.5];
_damageMap set ["UpperLeftArm", _damageToApply * 0.5];
};
case (_bodyPart isEqualTo "RightArm"): {
_damageMap set ["RightArm", _damageToApply * 0.5];
_damageMap set ["UpperRightArm", _damageToApply * 0.5];
};
case (_bodyPart isEqualTo "LeftLeg"): {
_damageMap set ["LeftLeg", _damageToApply * 0.5];
_damageMap set ["UpperLeftLeg", _damageToApply * 0.5];
};
case (_bodyPart isEqualTo "RightLeg"): {
_damageMap set ["RightLeg", _damageToApply * 0.5];
_damageMap set ["UpperRightLeg",_damageToApply * 0.5];
};
default {
_damageMap set [_bodyPart, _damageToApply];
};
TRACE_1("Explosion Damage Map handled, passing damage",_damageMap);
};

} forEach _allDamages;

private _newDamages = [];
{
_newDamages pushBack [_damageMap get _x, _x, _damageToApply];
} forEach (keys _damageMap); // micro-optimization again, two 'get's is still faster than iterating over a hashmap

TRACE_1("Explosion handled, passing damage",_newDamages);
[_unit, _newDamages, _typeOfDamage] //return
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "..\script_component.hpp"
/*
* Author: Pterolatypus, LinkIsGrim
* Custom wound handler for vehicle hits and explosions, sends damage to a random hitpoint
* Custom wound handler for vehicle hits and vehicleexplosions, sends damage to a random hitpoint
*
* Arguments:
* 0: Unit That Was Hit <OBJECT>
Expand Down
2 changes: 1 addition & 1 deletion addons/medical_damage/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define COMPONENT_BEAUTIFIED Medical Damage
#include "\z\ace\addons\main\script_mod.hpp"

// #define DEBUG_MODE_FULL
#define DEBUG_MODE_FULL
// #define DISABLE_COMPILE_CACHE
// #define ENABLE_PERFORMANCE_COUNTERS

Expand Down

0 comments on commit 02e526b

Please sign in to comment.