From 382028e662f68ce4df30dea235d973fdc4f7f477 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Thu, 8 Jun 2017 13:50:38 -0500 Subject: [PATCH] Fix updating body part visuals (#5141) --- .../functions/fnc_woundsHandler.sqf | 5 +- .../functions/fnc_woundsHandlerSQF.sqf | 4 +- .../functions/fnc_damageBodyPart.sqf | 5 +- .../functions/fnc_updateBodyPartVisuals.sqf | 57 +++++++------------ 4 files changed, 30 insertions(+), 41 deletions(-) diff --git a/addons/medical_damage/functions/fnc_woundsHandler.sqf b/addons/medical_damage/functions/fnc_woundsHandler.sqf index 766680e5a55..688ff86fd75 100644 --- a/addons/medical_damage/functions/fnc_woundsHandler.sqf +++ b/addons/medical_damage/functions/fnc_woundsHandler.sqf @@ -41,10 +41,12 @@ private _woundDamage = _damage / ((count _woundsCreated) max 1); // If the damag private _painLevel = 0; private _critialDamage = false; private _bodyPartDamage = _unit getVariable [QEGVAR(medical,bodyPartDamage), [0,0,0,0,0,0]]; +private _bodyPartVisParams = [_unit, false, false, false, false]; // params array for EFUNC(medical_engine,updateBodyPartVisuals); { _x params ["", "_woundClassIDToAdd", "_bodyPartNToAdd", "", "_bleeding"]; _bodyPartDamage set [_bodyPartNToAdd, (_bodyPartDamage select _bodyPartNToAdd) + _woundDamage]; + _bodyPartVisParams set [[1,2,3,3,4,4] select _bodyPartNToAdd, true]; // Mark the body part index needs updating // The higher the nastiness likelihood the higher the change to get a painful and bloody wound private _nastinessLikelihood = linearConversion [0, 20, _woundDamage, 0.5, 30, true]; @@ -107,7 +109,8 @@ private _bodyPartDamage = _unit getVariable [QEGVAR(medical,bodyPartDamage), [0, _unit setVariable [QEGVAR(medical,openWounds), _openWounds, true]; _unit setVariable [QEGVAR(medical,bodyPartDamage), _bodyPartDamage, true]; -[_unit, _bodyPart] call EFUNC(medical_engine,updateBodyPartVisuals); +_bodyPartVisParams call EFUNC(medical_engine,updateBodyPartVisuals); + [_unit, _painLevel] call EFUNC(medical,adjustPainLevel); [_unit, "hit", PAIN_TO_SCREAM(_painLevel)] call EFUNC(medical_engine,playInjuredSound); diff --git a/addons/medical_damage/functions/fnc_woundsHandlerSQF.sqf b/addons/medical_damage/functions/fnc_woundsHandlerSQF.sqf index 9dcd25521dc..10af92bf178 100644 --- a/addons/medical_damage/functions/fnc_woundsHandlerSQF.sqf +++ b/addons/medical_damage/functions/fnc_woundsHandlerSQF.sqf @@ -74,6 +74,7 @@ private _woundID = _unit getVariable [QGVAR(lastUniqueWoundID), 1]; // Unique w private _painLevel = 0; private _critialDamage = false; private _bodyPartDamage = _unit getVariable [QEGVAR(medical,bodyPartDamage), [0,0,0,0,0,0]]; +private _bodyPartVisParams = [_unit, false, false, false, false]; // params array for EFUNC(medical_engine,updateBodyPartVisuals); private _woundsCreated = []; { _x params ["_thresholdMinDam", "_thresholdWoundCount"]; @@ -92,6 +93,7 @@ private _woundsCreated = []; private _bodyPartNToAdd = [floor random 6, _bodyPartN] select _isSelectionSpecific; // 6 == count ALL_BODY_PARTS _bodyPartDamage set [_bodyPartNToAdd, (_bodyPartDamage select _bodyPartNToAdd) + _woundDamage]; + _bodyPartVisParams set [[1,2,3,3,4,4] select _bodyPartNToAdd, true]; // Mark the body part index needs updating // Create a new injury. Format [ID, classID, bodypart, percentage treated, bleeding rate] _injury = [_woundID, _woundClassIDToAdd, _bodyPartNToAdd, 1, _injuryBleedingRate]; @@ -165,7 +167,7 @@ private _woundsCreated = []; _unit setVariable [QEGVAR(medical,openWounds), _openWounds, true]; _unit setVariable [QEGVAR(medical,bodyPartDamage), _bodyPartDamage, true]; -[_unit, _bodyPart] call EFUNC(medical_engine,updateBodyPartVisuals); +_bodyPartVisParams call EFUNC(medical_engine,updateBodyPartVisuals); [_unit, _painLevel] call EFUNC(medical,adjustPainLevel); [_unit, "hit", PAIN_TO_SCREAM(_painLevel)] call EFUNC(medical_engine,playInjuredSound); diff --git a/addons/medical_engine/functions/fnc_damageBodyPart.sqf b/addons/medical_engine/functions/fnc_damageBodyPart.sqf index cac5266cadf..a1d9b4ba30a 100644 --- a/addons/medical_engine/functions/fnc_damageBodyPart.sqf +++ b/addons/medical_engine/functions/fnc_damageBodyPart.sqf @@ -5,13 +5,13 @@ * Arguments: * 0: Unit * 1: Selection, can be "Head", "Body", "Arms" or "Legs" - * 2: Damage + * 2: Damaged * * Return Value: * None * * Example: - * [player, "HEAD"] call ace_medical_engine_fnc_damageBodyPart + * [player, "HEAD", true] call ace_medical_engine_fnc_damageBodyPart * * Notes: * Head: Blood visuals @ 0.45 @@ -24,6 +24,7 @@ #include "script_component.hpp" params ["_unit", "_selection", "_damage"]; +TRACE_3("damageBodyPart",_unit,_selection,_damage); _damage = [0, DAMAGED_MIN_THRESHOLD] select _damage; diff --git a/addons/medical_engine/functions/fnc_updateBodyPartVisuals.sqf b/addons/medical_engine/functions/fnc_updateBodyPartVisuals.sqf index d7479ae7589..0b674499268 100644 --- a/addons/medical_engine/functions/fnc_updateBodyPartVisuals.sqf +++ b/addons/medical_engine/functions/fnc_updateBodyPartVisuals.sqf @@ -4,52 +4,35 @@ * * Arguments: * 0: Unit - * 1: Body part, can be "Head", "Body", "LeftArm", "RightArm", "LeftLeg", "RightLeg" or "All" + * 1: Update Head + * 2: Update Body + * 3: Update Arms + * 4: Update Legs * * Return Value: * None * * Example: - * [player, "HEAD"] call ace_medical_engine_fnc_updateBodyPartVisuals + * [player, true, true, true, true] call ace_medical_engine_fnc_updateBodyPartVisuals * * Public: No */ #include "script_component.hpp" -params ["_unit", "_bodyPart"]; - -if (_bodyPart == "All") exitWith { - [_unit, "Head"] call FUNC(updateBodyPartVisuals); - [_unit, "Body"] call FUNC(updateBodyPartVisuals); - [_unit, "LeftArm"] call FUNC(updateBodyPartVisuals); - [_unit, "RightArm"] call FUNC(updateBodyPartVisuals); - [_unit, "LeftLeg"] call FUNC(updateBodyPartVisuals); - [_unit, "RightLeg"] call FUNC(updateBodyPartVisuals); -}; - -private _affectedBodyParts = [_bodyPart]; - -switch (toLower _bodyPart) do { - case "leftarm"; - case "rightarm": { - _bodyPart = "Arms"; - _affectedBodyParts = ["LeftArm", "RightArm"]; - }; - - case "leftleg"; - case "rightleg": { - _bodyPart = "Legs"; - _affectedBodyParts = ["LeftLeg", "RightLeg"]; - }; -}; +params ["_unit", "_updateHead", "_updateBody", "_updateArms", "_updateLegs"]; +TRACE_5("updateBodyPartVisuals",_unit,_updateHead,_updateBody,_updateArms,_updateLegs); private _bodyPartDamage = _unit getVariable [QEGVAR(medical,bodyPartDamage), [0,0,0,0,0,0]]; -private _damageOnAffectedBodyParts = 0; -{ - private _partIndex = ALL_BODY_PARTS find toLower _x; - private _damageOnBodyPart = _bodyPartDamage select _partIndex; - // report maximum of both legs or arms - _damageOnAffectedBodyParts = _damageOnAffectedBodyParts max _damageOnBodyPart; -} forEach _affectedBodyParts; - -[_unit, _bodyPart, _damageOnAffectedBodyParts > VISUAL_BODY_DAMAGE_THRESHOLD] call FUNC(damageBodyPart); + +if (_updateHead) then { + [_unit, "head", (_bodyPartDamage select 0) > VISUAL_BODY_DAMAGE_THRESHOLD] call FUNC(damageBodyPart); +}; +if (_updateBody) then { + [_unit, "body", (_bodyPartDamage select 1) > VISUAL_BODY_DAMAGE_THRESHOLD] call FUNC(damageBodyPart); +}; +if (_updateArms) then { + [_unit, "arms", ((_bodyPartDamage select 2) max (_bodyPartDamage select 3)) > VISUAL_BODY_DAMAGE_THRESHOLD] call FUNC(damageBodyPart); +}; +if (_updateLegs) then { + [_unit, "legs", ((_bodyPartDamage select 4) max (_bodyPartDamage select 5)) > VISUAL_BODY_DAMAGE_THRESHOLD] call FUNC(damageBodyPart); +};