Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Medical Engine - Remove ACE_HDBracket hitpoint #9732

Merged
merged 21 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
25 changes: 6 additions & 19 deletions addons/medical_engine/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,15 @@
[_new] call FUNC(updateDamageEffects); // Run on new controlled unit to update QGVAR(aimFracture)
}, true] call CBA_fnc_addPlayerEventHandler;


["CAManBase", "init", {
params ["_unit"];

// Check if last hit point is our dummy.
private _allHitPoints = getAllHitPointsDamage _unit param [0, []];
reverse _allHitPoints;
while {(_allHitPoints param [0, ""]) select [0,1] == "#"} do { WARNING_1("Ignoring Reflector hitpoint %1", _allHitPoints deleteAt 0); };

if (_allHitPoints param [0, ""] != "ACE_HDBracket") then {
private _config = configOf _unit;
if (getText (_config >> "simulation") == "UAVPilot") exitWith {TRACE_1("ignore UAV AI",typeOf _unit);};
if (getNumber (_config >> "isPlayableLogic") == 1) exitWith {TRACE_1("ignore logic unit",typeOf _unit)};
ERROR_1("Bad hitpoints for unit type ""%1""",typeOf _unit);
} else {
// Calling this function inside curly brackets allows the usage of
// "exitWith", which would be broken with "HandleDamage" otherwise.
_unit setVariable [
QEGVAR(medical,HandleDamageEHID),
_unit addEventHandler ["HandleDamage", {_this call FUNC(handleDamage)}]
];
};
// Calling this function inside curly brackets allows the usage of
// "exitWith", which would be broken with "HandleDamage" otherwise.
_unit setVariable [
QEGVAR(medical,HandleDamageEHID),
_unit addEventHandler ["HandleDamage", {_this call FUNC(handleDamage)}]
];
veteran29 marked this conversation as resolved.
Show resolved Hide resolved
}, nil, [IGNORE_BASE_UAVPILOTS], true] call CBA_fnc_addClassEventHandler;

#ifdef DEBUG_MODE_FULL
Expand Down
31 changes: 16 additions & 15 deletions addons/medical_engine/functions/fnc_handleDamage.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* Public: No
*/
params ["_unit", "_selection", "_damage", "_shooter", "_ammo", "_hitPointIndex", "_instigator", "_hitpoint"];
params ["_unit", "_selection", "_damage", "_shooter", "_ammo", "_hitPointIndex", "_instigator", "_hitpoint", "_directHit", "_context"];

// HD sometimes triggers for remote units - ignore.
if !(local _unit) exitWith {nil};
Expand All @@ -32,6 +32,11 @@ if (_hitPoint isEqualTo "") then {
if !(isDamageAllowed _unit && {_unit getVariable [QEGVAR(medical,allowDamage), true]}) exitWith {_oldDamage};

private _newDamage = _damage - _oldDamage;

// _newDamage == 0 happens occasionally for vehiclehit events (see line 80 onwards), just exit early to save some frametime
// context 4 is engine "bleeding". For us, it's just a duplicate event for #structural which we can ignore without any issues
if (_context == 4 || _newDamage == 0) exitWith {_oldDamage};

// Get scaled armor value of hitpoint and calculate damage before armor
// We scale using passThrough to handle explosive-resistant armor properly (#9063)
// We need realDamage to determine which limb was hit correctly
Expand All @@ -42,7 +47,7 @@ if (_hitPoint isNotEqualTo "#structural") then {
private _damageCoef = linearConversion [0, 1, GVAR(damagePassThroughEffect), 1, _armorCoef];
_newDamage = _newDamage * _damageCoef;
};
TRACE_4("Received hit",_hitpoint,_ammo,_newDamage,_realDamage);
TRACE_6("Received hit",_hitpoint,_ammo,_newDamage,_realDamage,_directHit,_context);

// Drowning doesn't fire the EH for each hitpoint so the "ace_hdbracket" code never runs
// Damage occurs in consistent increments
Expand Down Expand Up @@ -78,7 +83,6 @@ if (

// Receiving explosive damage inside a vehicle doesn't trigger for each hitpoint
// This is the case for mines, explosives, artillery, and catasthrophic vehicle explosions
// Triggers twice, but that doesn't matter as damage is low
if (
_hitPoint isEqualTo "#structural" &&
{!isNull _vehicle} &&
Expand All @@ -99,9 +103,13 @@ if (
0
};

// This hitpoint is set to trigger last, evaluate all the stored damage values
// to determine where wounds are applied
if (_hitPoint isEqualTo "ace_hdbracket") exitWith {
// Damages are stored for "ace_hdbracket" event triggered last
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved
_unit setVariable [format [QGVAR($%1), _hitPoint], [_realDamage, _newDamage]];

// 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
// Don't exit, as the last iteration can be one of the hitpoints that we need to keep _oldDamage for
if (_context == 2) then {
_unit setVariable [QEGVAR(medical,lastDamageSource), _shooter];
_unit setVariable [QEGVAR(medical,lastInstigator), _instigator];

Expand Down Expand Up @@ -194,16 +202,9 @@ if (_hitPoint isEqualTo "ace_hdbracket") exitWith {
QGVAR($HitLeftArm),QGVAR($HitRightArm),QGVAR($HitLeftLeg),QGVAR($HitRightLeg),
QGVAR($#structural)
];

0
};

// Damages are stored for "ace_hdbracket" event triggered last
_unit setVariable [format [QGVAR($%1), _hitPoint], [_realDamage, _newDamage]];

// Engine damage to these hitpoints controls blood visuals, limping, weapon sway
// Handled in fnc_damageBodyPart, persist here
if (_hitPoint in ["hithead", "hitbody", "hithands", "hitlegs"]) exitWith {_oldDamage};

// We store our own damage values so engine damage is unnecessary
0
// For all other hitpoints, we store our own damage values, so engine damage is unnecessary
[0, _oldDamage] select (_hitPoint in ["hithead", "hitbody", "hithands", "hitlegs"])
11 changes: 0 additions & 11 deletions addons/medical_engine/script_macros_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,4 @@
};\
class HitRightLeg: HitLeftLeg {\
name = "leg_r";\
};\
class ACE_HDBracket {\
armor = 1;\
material = -1;\
name = "head";\
passThrough = 0;\
radius = 1;\
explosionShielding = 1;\
visual = "";\
minimalHit = 0;\
depends = "HitHead";\
}