Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 27 additions & 31 deletions addons/main/functions/fnc_handleDamage.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ private _multiplierArray = switch (true) do {
};

private _modifiedNewDamage = _newDamage;
private _modifiedRealDamage = _realDamage;

// If default settings, we don't need to change anything, so skip calculcations and let ace handle damage
if (_multiplierArray isNotEqualTo DEFAULT_SETTINGS) then {
Expand All @@ -136,28 +135,25 @@ if (_multiplierArray isNotEqualTo DEFAULT_SETTINGS) then {
switch (true) do {
case (_armorMin >= 1 && {_armor < _armorMin}): {
// This will decrease damage
_modifiedNewDamage = _newDamage * _armor / _armorMin;
_modifiedRealDamage = _realDamage * _armor / _armorMin;
Copy link
Owner

@johnb432 johnb432 Oct 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why I added this is because there are instances where shooting e.g. at the torso would trigger damage on limbs. The problem was (can't reproduce it in 2.18) that the adjusted damage of the torso was lower than the damage done to the limbs, so the wounds would appear on the limbs and not the torso.

As said, I can't reproduce it anymore, but I'm not comfortable removing it just yet.

_modifiedNewDamage = _realDamage / _armorMin;

TRACE_6("Under min armor",_armor,_armorMin,_newDamage,_modifiedNewDamage,_realDamage,_modifiedRealDamage);
TRACE_5("Under min armor",_armor,_armorMin,_newDamage,_modifiedNewDamage,_realDamage);
};
case (_armorMax >= 1 && {_armor > _armorMax}): {
// This will increase damage
_modifiedNewDamage = _newDamage * _armor / _armorMax;
_modifiedRealDamage = _realDamage * _armor / _armorMax;
_modifiedNewDamage = _realDamage / _armorMax;

TRACE_6("Over max armor",_armor,_armorMax,_newDamage,_modifiedNewDamage,_realDamage,_modifiedRealDamage);
TRACE_5("Over max armor",_armor,_armorMax,_newDamage,_modifiedNewDamage,_realDamage);
};
};

_modifiedNewDamage = _modifiedNewDamage / _hitPointMultiplier;
_modifiedRealDamage = _modifiedRealDamage / _hitPointMultiplier;

TRACE_5("Hitpoint damage multiplied",_armor,_newDamage,_modifiedNewDamage,_realDamage,_modifiedRealDamage);
TRACE_4("Hitpoint damage multiplied",_armor,_newDamage,_modifiedNewDamage,_realDamage);
};

// Damages are stored for last iteration of the HandleDamage event (_context == 2)
_unit setVariable [format ["ace_medical_engine_$%1", _hitPoint], [_realDamage, _newDamage, _modifiedRealDamage, _modifiedNewDamage]];
_unit setVariable [format ["ace_medical_engine_$%1", _hitPoint], [_realDamage, _newDamage, _modifiedNewDamage]];

// Ref https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#HandleDamage
// Context 2 means this is the last iteration of HandleDamage, so figure out which hitpoint took the most real damage and send wound event
Expand All @@ -166,51 +162,51 @@ if (_context == 2) then {
_unit setVariable ["ace_medical_lastDamageSource", _shooter];
_unit setVariable ["ace_medical_lastInstigator", _instigator];

private _damageStructural = _unit getVariable ["ace_medical_engine_$#structural", [0,0,0,0]];
private _damageStructural = _unit getVariable ["ace_medical_engine_$#structural", [0,0,0]];

// --- Head
private _damageHead = [
_unit getVariable ["ace_medical_engine_$HitFace", [0,0,0,0]],
_unit getVariable ["ace_medical_engine_$HitNeck", [0,0,0,0]],
_unit getVariable ["ace_medical_engine_$HitHead", [0,0,0,0]]
_unit getVariable ["ace_medical_engine_$HitFace", [0,0,0]],
_unit getVariable ["ace_medical_engine_$HitNeck", [0,0,0]],
_unit getVariable ["ace_medical_engine_$HitHead", [0,0,0]]
];
_damageHead sort false;
_damageHead = _damageHead select 0;

// --- Body
private _damageBody = [
_unit getVariable ["ace_medical_engine_$HitPelvis", [0,0,0,0]],
_unit getVariable ["ace_medical_engine_$HitAbdomen", [0,0,0,0]],
_unit getVariable ["ace_medical_engine_$HitDiaphragm", [0,0,0,0]],
_unit getVariable ["ace_medical_engine_$HitChest", [0,0,0,0]]
_unit getVariable ["ace_medical_engine_$HitPelvis", [0,0,0]],
_unit getVariable ["ace_medical_engine_$HitAbdomen", [0,0,0]],
_unit getVariable ["ace_medical_engine_$HitDiaphragm", [0,0,0]],
_unit getVariable ["ace_medical_engine_$HitChest", [0,0,0]]
// HitBody removed as it's a placeholder hitpoint and the high armor value (1000) throws the calculations off
];
_damageBody sort false;
_damageBody = _damageBody select 0;

// --- Arms and Legs
private _damageLeftArm = _unit getVariable ["ace_medical_engine_$HitLeftArm", [0,0,0,0]];
private _damageRightArm = _unit getVariable ["ace_medical_engine_$HitRightArm", [0,0,0,0]];
private _damageLeftLeg = _unit getVariable ["ace_medical_engine_$HitLeftLeg", [0,0,0,0]];
private _damageRightLeg = _unit getVariable ["ace_medical_engine_$HitRightLeg", [0,0,0,0]];
private _damageLeftArm = _unit getVariable ["ace_medical_engine_$HitLeftArm", [0,0,0]];
private _damageRightArm = _unit getVariable ["ace_medical_engine_$HitRightArm", [0,0,0]];
private _damageLeftLeg = _unit getVariable ["ace_medical_engine_$HitLeftLeg", [0,0,0]];
private _damageRightLeg = _unit getVariable ["ace_medical_engine_$HitRightLeg", [0,0,0]];

// Find hit point that received the maxium damage
// Priority used for sorting if incoming damage is equal
private _allDamages = [
// Real damage (ignoring armor), Actual damage (with armor), Real damage modified (ignoring armor), Modified damage (with armor)
[_damageHead select 0, PRIORITY_HEAD, _damageHead select 1, "Head", _damageHead param [2, _damageHead select 0], _damageHead param [3, _damageHead select 1]],
[_damageBody select 0, PRIORITY_BODY, _damageBody select 1, "Body", _damageBody param [2, _damageBody select 0], _damageBody param [3, _damageBody select 1]],
[_damageLeftArm select 0, PRIORITY_LEFT_ARM, _damageLeftArm select 1, "LeftArm", _damageLeftArm param [2, _damageLeftArm select 0], _damageLeftArm param [3, _damageLeftArm select 1]],
[_damageRightArm select 0, PRIORITY_RIGHT_ARM, _damageRightArm select 1, "RightArm", _damageRightArm param [2, _damageRightArm select 0], _damageRightArm param [3, _damageRightArm select 1]],
[_damageLeftLeg select 0, PRIORITY_LEFT_LEG, _damageLeftLeg select 1, "LeftLeg", _damageLeftLeg param [2, _damageLeftLeg select 0], _damageLeftLeg param [3, _damageLeftLeg select 1]],
[_damageRightLeg select 0, PRIORITY_RIGHT_LEG, _damageRightLeg select 1, "RightLeg", _damageRightLeg param [2, _damageRightLeg select 0], _damageRightLeg param [3, _damageRightLeg select 1]],
[_damageStructural select 0, PRIORITY_STRUCTURAL, _damageStructural select 1, "#structural", _damageStructural param [2, _damageStructural select 0], _damageStructural param [3, _damageStructural select 1]]
// Real damage, Damage (with armor), Modified damage (with armor)
[_damageHead select 0, PRIORITY_HEAD, _damageHead select 1, "Head", _damageHead param [2, _damageHead select 1]],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you fail to get _modifiedRealDamage from a body part, you are going to get _newDamage instead?

The reason I added the param is in case other mods decide to set the array length at 2, they would be overwriting the changes done by this mod. Using _newDamage makes no sense when _realDamage is available - it's better to have no effect than a weird side effect.

[_damageBody select 0, PRIORITY_BODY, _damageBody select 1, "Body", _damageBody param [2, _damageBody select 1]],
[_damageLeftArm select 0, PRIORITY_LEFT_ARM, _damageLeftArm select 1, "LeftArm", _damageLeftArm param [2, _damageLeftArm select 1]],
[_damageRightArm select 0, PRIORITY_RIGHT_ARM, _damageRightArm select 1, "RightArm", _damageRightArm param [2, _damageRightArm select 1]],
[_damageLeftLeg select 0, PRIORITY_LEFT_LEG, _damageLeftLeg select 1, "LeftLeg", _damageLeftLeg param [2, _damageLeftLeg select 1]],
[_damageRightLeg select 0, PRIORITY_RIGHT_LEG, _damageRightLeg select 1, "RightLeg", _damageRightLeg param [2, _damageRightLeg select 1]],
[_damageStructural select 0, PRIORITY_STRUCTURAL, _damageStructural select 1, "#structural", _damageStructural param [2, _damageStructural select 1]]
];
TRACE_2("incoming",_allDamages,_damageStructural);

_allDamages sort false;
// Use modified damages instead of initial ones
_allDamages = _allDamages apply {[_x select 5, _x select 3, _x select 4]};
_allDamages = _allDamages apply {[_x select 4, _x select 3, _x select 0]};

// Environmental damage sources all have empty ammo string
// No explicit source given, we infer from differences between them
Expand Down