diff --git a/addons/medical_damage/functions/fnc_woundsHandlerVehiclehit.sqf b/addons/medical_damage/functions/fnc_woundsHandlerVehiclehit.sqf index 9c4f864f97..5f4bd35941 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 6483f6de64..8db9950a86 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];