From 3b82510751b87a2db1897e3f6ee1c29350735d6a Mon Sep 17 00:00:00 2001 From: ulteq Date: Thu, 8 Dec 2016 12:59:30 +0100 Subject: [PATCH] Merge new wounds into existing wounds whenever possible * Todo: separate 'amountOf' into two variables (wound count and bandage percentage) --- .../functions/fnc_handleIncapacitation.sqf | 4 ++-- .../functions/fnc_woundsHandler.sqf | 20 +++++++++++++++++- .../functions/fnc_woundsHandlerSQF.sqf | 21 +++++++++++++++++-- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/addons/medical/functions/fnc_handleIncapacitation.sqf b/addons/medical/functions/fnc_handleIncapacitation.sqf index d8e302cf6d..1e9ba01051 100644 --- a/addons/medical/functions/fnc_handleIncapacitation.sqf +++ b/addons/medical/functions/fnc_handleIncapacitation.sqf @@ -21,9 +21,9 @@ _bodyPartDamage params ["_headDamage", "_bodyDamage", "_leftArmDamage", "_rightA // Exclude non penetrating body damage { - _x params ["", "", "_bodyPartN", "", "", "_damage"]; + _x params ["", "", "_bodyPartN", "_amountOf", "", "_damage"]; if (_bodyPartN == 1 && {_damage < PENETRATION_THRESHOLD}) then { - _bodyDamage = _bodyDamage - _damage; + _bodyDamage = _bodyDamage - (_amountOf * _damage); }; } forEach (_unit getVariable [QGVAR(openWounds), []]); diff --git a/addons/medical_damage/functions/fnc_woundsHandler.sqf b/addons/medical_damage/functions/fnc_woundsHandler.sqf index 2696498cab..593c6bf63f 100644 --- a/addons/medical_damage/functions/fnc_woundsHandler.sqf +++ b/addons/medical_damage/functions/fnc_woundsHandler.sqf @@ -75,7 +75,25 @@ private _bodyPartDamage = _unit getVariable [QEGVAR(medical,bodyPartDamage), [0, [_unit, true] call EFUNC(medical_engine,setLimping); }; - _openWounds pushBack _x; + // if possible merge into existing wounds + private _createNewWound = true; + { + _x params ["", "_classID", "_bodyPartN", "_oldAmountOf", "_oldBleeding", "_oldDamage"]; + if (_woundClassIDToAdd == _classID && {_bodyPartNToAdd == _bodyPartN && {(round(_damage * 10) / 10) == (round(_oldDamage * 10) / 10)}}) then { + private _oldCategory = (floor ((0 max _oldBleeding min 0.1) / 0.05)); + private _newCategory = (floor ((0 max _bleeding min 0.1) / 0.05)); + if (_oldCategory == _newCategory) exitWith { + private _newBleeding = (_oldAmountOf * _oldBleeding + _bleeding); + private _newAmountOf = _newBleeding / _oldBleeding; + _x set [3, _newAmountOf]; + _createNewWound = false; + }; + }; + } forEach _openWounds; + + if (_createNewWound) then { + _openWounds pushBack _x; + }; } forEach _woundsCreated; _unit setVariable [QEGVAR(medical,openWounds), _openWounds, true]; diff --git a/addons/medical_damage/functions/fnc_woundsHandlerSQF.sqf b/addons/medical_damage/functions/fnc_woundsHandlerSQF.sqf index 334cbf04eb..b24591d8cf 100644 --- a/addons/medical_damage/functions/fnc_woundsHandlerSQF.sqf +++ b/addons/medical_damage/functions/fnc_woundsHandlerSQF.sqf @@ -125,8 +125,25 @@ private _woundsCreated = []; [_unit, true] call EFUNC(medical_engine,setLimping); }; - // Since it is a new injury, we will have to add it to the open wounds array to store it - _openWounds pushBack _injury; + // if possible merge into existing wounds + private _createNewWound = true; + { + _x params ["", "_classID", "_bodyPartN", "_oldAmountOf", "_oldBleeding", "_oldDamage"]; + if (_woundClassIDToAdd == _classID && {_bodyPartNToAdd == _bodyPartN && {(round(_damage * 10) / 10) == (round(_oldDamage * 10) / 10)}}) then { + private _oldCategory = (floor ((0 max _oldBleeding min 0.1) / 0.05)); + private _newCategory = (floor ((0 max _bleeding min 0.1) / 0.05)); + if (_oldCategory == _newCategory) exitWith { + private _newBleeding = (_oldAmountOf * _oldBleeding + _bleeding); + private _newAmountOf = _newBleeding / _oldBleeding; + _x set [3, _newAmountOf]; + _createNewWound = false; + }; + }; + } forEach _openWounds; + + if (_createNewWound) then { + _openWounds pushBack _injury; + }; // New injuries will also increase the wound ID _woundID = _woundID + 1;