Skip to content

Commit

Permalink
Fix updating body part visuals (#5141)
Browse files Browse the repository at this point in the history
  • Loading branch information
PabstMirror authored Jun 8, 2017
1 parent f715eda commit 382028e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 41 deletions.
5 changes: 4 additions & 1 deletion addons/medical_damage/functions/fnc_woundsHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion addons/medical_damage/functions/fnc_woundsHandlerSQF.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -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];
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions addons/medical_engine/functions/fnc_damageBodyPart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* Arguments:
* 0: Unit <OBJECT>
* 1: Selection, can be "Head", "Body", "Arms" or "Legs" <STRING>
* 2: Damage <BOOLEAN>
* 2: Damaged <BOOLEAN>
*
* 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
Expand All @@ -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;

Expand Down
57 changes: 20 additions & 37 deletions addons/medical_engine/functions/fnc_updateBodyPartVisuals.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,35 @@
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Body part, can be "Head", "Body", "LeftArm", "RightArm", "LeftLeg", "RightLeg" or "All" <STRING>
* 1: Update Head <BOOLEAN>
* 2: Update Body <BOOLEAN>
* 3: Update Arms <BOOLEAN>
* 4: Update Legs <BOOLEAN>
*
* 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);
};

0 comments on commit 382028e

Please sign in to comment.