Skip to content

Commit

Permalink
Medical - Fix hanging when vehicle crew receive fatal damage (#9681)
Browse files Browse the repository at this point in the history
* fix undefined var in trace

* fix high damage hang

* update comment

* Update fnc_woundsHandlerVehiclehit.sqf
  • Loading branch information
LinkIsGrim authored Dec 18, 2023
1 parent 5458fdf commit 1b6b0aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions addons/medical_damage/functions/fnc_woundsHandlerVehiclehit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,21 @@ if (count _allDamages > 1) exitWith {_this};
// 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 _newDamages = [];
private _damageMap = createHashMap;
private _bodyPart = "";
private _allBodyParts = ALL_BODY_PARTS; // micro-optimization here and above, don't recreate this array every time

// hitpoints are randomized, more damage means more wounds in different body parts
// use a hashmap so we only create one entry in _newDamages per body part
for "_i" from 1 to (_damageToApply * 6) do {
_newDamages pushBack [_damageToApply, selectRandom ALL_BODY_PARTS, _damageToApply]
_bodyPart = selectRandom _allBodyParts;
_damageMap set [_bodyPart, (_damageMap getOrDefault [_bodyPart, 0]) + _damageToApply];
};

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("Vehicle explosion handled, passing damage", _newDamages);
[_unit, _newDamages, _typeOfDamage] //return
2 changes: 1 addition & 1 deletion addons/medical_engine/functions/fnc_handleDamage.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if (
{GET_NUMBER(_ammoCfg >> "indirectHit", 0) > 0}
}
) exitwith {
TRACE_6("Vehicle hit",_unit,_shooter,_instigator,_damage,_newDamage,_damages);
TRACE_5("Vehicle hit",_unit,_shooter,_instigator,_damage,_newDamage);

_unit setVariable [QEGVAR(medical,lastDamageSource), _shooter];
_unit setVariable [QEGVAR(medical,lastInstigator), _instigator];
Expand Down

0 comments on commit 1b6b0aa

Please sign in to comment.