From 1b6b0aaf0b8fa223dfdeeaa33289e5eb48cddba0 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Mon, 18 Dec 2023 14:02:09 -0300 Subject: [PATCH] Medical - Fix hanging when vehicle crew receive fatal damage (#9681) * fix undefined var in trace * fix high damage hang * update comment * Update fnc_woundsHandlerVehiclehit.sqf --- .../functions/fnc_woundsHandlerVehiclehit.sqf | 13 +++++++++++-- .../medical_engine/functions/fnc_handleDamage.sqf | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/addons/medical_damage/functions/fnc_woundsHandlerVehiclehit.sqf b/addons/medical_damage/functions/fnc_woundsHandlerVehiclehit.sqf index 9c4f864f97c..5f4bd359413 100644 --- a/addons/medical_damage/functions/fnc_woundsHandlerVehiclehit.sqf +++ b/addons/medical_damage/functions/fnc_woundsHandlerVehiclehit.sqf @@ -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 diff --git a/addons/medical_engine/functions/fnc_handleDamage.sqf b/addons/medical_engine/functions/fnc_handleDamage.sqf index 6483f6de648..8db9950a86a 100644 --- a/addons/medical_engine/functions/fnc_handleDamage.sqf +++ b/addons/medical_engine/functions/fnc_handleDamage.sqf @@ -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];