From 4a705df2b8bb2360defed2a93b2adc10b0a8f3fe Mon Sep 17 00:00:00 2001 From: LinkIsGrim Date: Sun, 14 Jan 2024 13:45:32 -0300 Subject: [PATCH 01/19] Medical Engine - Remove ACE_HDBracket hitpoint --- addons/medical_engine/XEH_postInit.sqf | 25 +++++-------------- .../functions/fnc_handleDamage.sqf | 25 ++++++++----------- .../medical_engine/script_macros_config.hpp | 11 -------- 3 files changed, 17 insertions(+), 44 deletions(-) diff --git a/addons/medical_engine/XEH_postInit.sqf b/addons/medical_engine/XEH_postInit.sqf index 6455904f95e..129e0b1aea0 100644 --- a/addons/medical_engine/XEH_postInit.sqf +++ b/addons/medical_engine/XEH_postInit.sqf @@ -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)}] + ]; }, nil, [IGNORE_BASE_UAVPILOTS], true] call CBA_fnc_addClassEventHandler; #ifdef DEBUG_MODE_FULL diff --git a/addons/medical_engine/functions/fnc_handleDamage.sqf b/addons/medical_engine/functions/fnc_handleDamage.sqf index 8db9950a86a..5f35121e8c3 100644 --- a/addons/medical_engine/functions/fnc_handleDamage.sqf +++ b/addons/medical_engine/functions/fnc_handleDamage.sqf @@ -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}; @@ -42,7 +42,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 @@ -99,9 +99,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 +_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]; @@ -194,16 +198,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"]) diff --git a/addons/medical_engine/script_macros_config.hpp b/addons/medical_engine/script_macros_config.hpp index 611a8ad3569..7f65a4b9129 100644 --- a/addons/medical_engine/script_macros_config.hpp +++ b/addons/medical_engine/script_macros_config.hpp @@ -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";\ } From daa7a170cc9196993f1a7542418d3eafe161367e Mon Sep 17 00:00:00 2001 From: LinkIsGrim Date: Sun, 14 Jan 2024 14:21:48 -0300 Subject: [PATCH 02/19] skip context 4 --- addons/medical_engine/functions/fnc_handleDamage.sqf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/medical_engine/functions/fnc_handleDamage.sqf b/addons/medical_engine/functions/fnc_handleDamage.sqf index 5f35121e8c3..b3d685045d0 100644 --- a/addons/medical_engine/functions/fnc_handleDamage.sqf +++ b/addons/medical_engine/functions/fnc_handleDamage.sqf @@ -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 @@ -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} && From 8c50fbc8a22db9314937503464248b92a49a916b Mon Sep 17 00:00:00 2001 From: LinkIsGrim Date: Sun, 14 Jan 2024 15:17:30 -0300 Subject: [PATCH 03/19] move checks to vars --- .../functions/fnc_handleDamage.sqf | 31 ++++++++++++------- addons/medical_engine/script_component.hpp | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/addons/medical_engine/functions/fnc_handleDamage.sqf b/addons/medical_engine/functions/fnc_handleDamage.sqf index b3d685045d0..bf7f793a712 100644 --- a/addons/medical_engine/functions/fnc_handleDamage.sqf +++ b/addons/medical_engine/functions/fnc_handleDamage.sqf @@ -1,3 +1,4 @@ +#define DEBUG_MODE_FULL #include "..\script_component.hpp" /* * Author: commy2, kymckay @@ -20,8 +21,9 @@ if !(local _unit) exitWith {nil}; // Get missing meta info private _oldDamage = 0; +private _structuralDamage = _context == 0; -if (_hitPoint isEqualTo "") then { +if (_structuralDamage) then { _hitPoint = "#structural"; _oldDamage = damage _unit; } else { @@ -35,14 +37,17 @@ 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}; +if (_context == 4 || _newDamage == 0) exitWith { + TRACE_4("Skipping engine bleeding or 0 zero damage",_ammo,_newDamage,_directHit,_context); + _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 [_unit, _hitpoint] call FUNC(getHitpointArmor) params ["_armor", "_armorScaled"]; private _realDamage = _newDamage * _armor; -if (_hitPoint isNotEqualTo "#structural") then { +if (!_structuralDamage) then { private _armorCoef = _armor/_armorScaled; private _damageCoef = linearConversion [0, 1, GVAR(damagePassThroughEffect), 1, _armorCoef]; _newDamage = _newDamage * _damageCoef; @@ -52,7 +57,7 @@ TRACE_6("Received hit",_hitpoint,_ammo,_newDamage,_realDamage,_directHit,_contex // Drowning doesn't fire the EH for each hitpoint so the "ace_hdbracket" code never runs // Damage occurs in consistent increments if ( - _hitPoint isEqualTo "#structural" && + _structuralDamage && {getOxygenRemaining _unit <= 0.5} && {_damage isEqualTo (_oldDamage + 0.005)} ) exitWith { @@ -64,14 +69,16 @@ if ( // Faster than (vehicle _unit), also handles dead units private _vehicle = objectParent _unit; +private _inVehicle = !isNull _vehicle; +private _environmentDamage = _ammo == ""; // Crashing a vehicle doesn't fire the EH for each hitpoint so the "ace_hdbracket" code never runs // It does fire the EH multiple times, but this seems to scale with the intensity of the crash if ( - EGVAR(medical,enableVehicleCrashes) && - {_hitPoint isEqualTo "#structural"} && - {_ammo isEqualTo ""} && - {!isNull _vehicle} && + (EGVAR(medical,enableVehicleCrashes) && + _environmentDamage && + _inVehicle && + _structuralDamage) && {vectorMagnitude (velocity _vehicle) > 5} // todo: no way to detect if stationary and another vehicle hits you ) exitWith { @@ -84,9 +91,9 @@ 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 if ( - _hitPoint isEqualTo "#structural" && - {!isNull _vehicle} && - {_ammo isNotEqualTo ""} && + (_structuralDamage && + !_environmentDamage && + _inVehicle) && { private _ammoCfg = configFile >> "CfgAmmo" >> _ammo; GET_NUMBER(_ammoCfg >> "explosive", 0) > 0 || @@ -160,7 +167,7 @@ if (_context == 2) then { // Environmental damage sources all have empty ammo string // No explicit source given, we infer from differences between them - if (_ammo isEqualTo "") then { + if (_environmentDamage) then { // Any collision with terrain/vehicle/object has a shooter // Check this first because burning can happen at any velocity if !(isNull _shooter) then { diff --git a/addons/medical_engine/script_component.hpp b/addons/medical_engine/script_component.hpp index 59cd015080e..ee16cdf1e0c 100644 --- a/addons/medical_engine/script_component.hpp +++ b/addons/medical_engine/script_component.hpp @@ -3,7 +3,7 @@ #include "\z\ace\addons\main\script_mod.hpp" // #define DEBUG_MODE_FULL -// #define DISABLE_COMPILE_CACHE +#define DISABLE_COMPILE_CACHE // #define ENABLE_PERFORMANCE_COUNTERS #ifdef DEBUG_ENABLED_MEDICAL_ENGINE From dae10be8fd259d51b6a9e7fdb1d618ad40127d33 Mon Sep 17 00:00:00 2001 From: LinkIsGrim Date: Sun, 14 Jan 2024 15:21:54 -0300 Subject: [PATCH 04/19] skip uav/logic entities --- addons/medical_engine/XEH_postInit.sqf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/medical_engine/XEH_postInit.sqf b/addons/medical_engine/XEH_postInit.sqf index 129e0b1aea0..ac1c6c5bdee 100644 --- a/addons/medical_engine/XEH_postInit.sqf +++ b/addons/medical_engine/XEH_postInit.sqf @@ -9,6 +9,9 @@ ["CAManBase", "init", { params ["_unit"]; + if (unitIsUAV _unit) exitWith {TRACE_1("ignore UAV AI",typeOf _unit);}; + if (getNumber (configOf _unit >> "isPlayableLogic") == 1) exitWith {TRACE_1("ignore logic unit",typeOf _unit);}; + // Calling this function inside curly brackets allows the usage of // "exitWith", which would be broken with "HandleDamage" otherwise. _unit setVariable [ From 84c2febc5b2fafe1f94172327c066dde34e591f8 Mon Sep 17 00:00:00 2001 From: LinkIsGrim Date: Sun, 14 Jan 2024 15:29:30 -0300 Subject: [PATCH 05/19] add check for arm/leg hitpoints --- addons/medical_engine/XEH_postInit.sqf | 5 +++++ addons/medical_engine/XEH_preInit.sqf | 2 ++ 2 files changed, 7 insertions(+) diff --git a/addons/medical_engine/XEH_postInit.sqf b/addons/medical_engine/XEH_postInit.sqf index ac1c6c5bdee..25b9d11ce55 100644 --- a/addons/medical_engine/XEH_postInit.sqf +++ b/addons/medical_engine/XEH_postInit.sqf @@ -12,6 +12,11 @@ if (unitIsUAV _unit) exitWith {TRACE_1("ignore UAV AI",typeOf _unit);}; if (getNumber (configOf _unit >> "isPlayableLogic") == 1) exitWith {TRACE_1("ignore logic unit",typeOf _unit);}; + private _allHitPoints = getAllHitPointsDamage _unit param [0, []]; + if ((_allHitPoints arrayIntersect GVAR(hitpoints)) isNotEqualTo GVAR(hitpoints)) exitWith { + ERROR_1("Bad hitpoints for unit type ""%1""",typeOf _unit); + }; + // Calling this function inside curly brackets allows the usage of // "exitWith", which would be broken with "HandleDamage" otherwise. _unit setVariable [ diff --git a/addons/medical_engine/XEH_preInit.sqf b/addons/medical_engine/XEH_preInit.sqf index dab2e7efe32..c2c24c50ccc 100644 --- a/addons/medical_engine/XEH_preInit.sqf +++ b/addons/medical_engine/XEH_preInit.sqf @@ -45,6 +45,8 @@ GVAR(animations) setVariable [QUNCON_ANIM(faceDown), [QUNCON_ANIM(1),QUNCON_ANIM GVAR(animations) setVariable [QUNCON_ANIM(faceLeft), [QUNCON_ANIM(7),QUNCON_ANIM(8),QUNCON_ANIM(1_1),QUNCON_ANIM(7_1),QUNCON_ANIM(8_1)]]; GVAR(animations) setVariable [QUNCON_ANIM(faceRight), [QUNCON_ANIM(5),QUNCON_ANIM(6),QUNCON_ANIM(10),QUNCON_ANIM(5_1),QUNCON_ANIM(6_1)]]; +GVAR(hitpoints) = ["hitleftarm", "hitrightarm", "hitleftleg", "hitrightleg"]; + private _fnc_fixStatic = { params ["_vehicle"]; private _type = typeOf _vehicle; From 3f030c14a647cb13e13124d6ca6b9697eb6a0810 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Sun, 14 Jan 2024 16:52:30 -0300 Subject: [PATCH 06/19] Update addons/medical_engine/functions/fnc_handleDamage.sqf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jouni Järvinen --- addons/medical_engine/functions/fnc_handleDamage.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/medical_engine/functions/fnc_handleDamage.sqf b/addons/medical_engine/functions/fnc_handleDamage.sqf index bf7f793a712..df72566f96b 100644 --- a/addons/medical_engine/functions/fnc_handleDamage.sqf +++ b/addons/medical_engine/functions/fnc_handleDamage.sqf @@ -38,7 +38,7 @@ 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 { - TRACE_4("Skipping engine bleeding or 0 zero damage",_ammo,_newDamage,_directHit,_context); + TRACE_4("Skipping engine bleeding or zero damage",_ammo,_newDamage,_directHit,_context); _oldDamage }; From 12e3fd8a958b9cde890cce09e75958d63945e416 Mon Sep 17 00:00:00 2001 From: LinkIsGrim Date: Mon, 15 Jan 2024 23:19:58 -0300 Subject: [PATCH 07/19] don't skip context 2 --- addons/medical_engine/functions/fnc_handleDamage.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/medical_engine/functions/fnc_handleDamage.sqf b/addons/medical_engine/functions/fnc_handleDamage.sqf index df72566f96b..fdc0b5b7a4e 100644 --- a/addons/medical_engine/functions/fnc_handleDamage.sqf +++ b/addons/medical_engine/functions/fnc_handleDamage.sqf @@ -37,7 +37,7 @@ 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 { +if (_context != 2 && {_context == 4 || _newDamage == 0}) exitWith { TRACE_4("Skipping engine bleeding or zero damage",_ammo,_newDamage,_directHit,_context); _oldDamage }; From 56e0b157f26bbad3e4e4501a93572b4f4946127b Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:19:07 -0300 Subject: [PATCH 08/19] clearer custom hitpoint array name --- addons/medical_engine/XEH_postInit.sqf | 2 +- addons/medical_engine/XEH_preInit.sqf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/medical_engine/XEH_postInit.sqf b/addons/medical_engine/XEH_postInit.sqf index f161404b3db..6a0f241d589 100644 --- a/addons/medical_engine/XEH_postInit.sqf +++ b/addons/medical_engine/XEH_postInit.sqf @@ -13,7 +13,7 @@ if (getNumber (configOf _unit >> "isPlayableLogic") == 1) exitWith {TRACE_1("ignore logic unit",typeOf _unit);}; private _allHitPoints = getAllHitPointsDamage _unit param [0, []]; - if ((_allHitPoints arrayIntersect GVAR(hitpoints)) isNotEqualTo GVAR(hitpoints)) exitWith { + if ((_allHitPoints arrayIntersect GVAR(customHitpoints)) isNotEqualTo GVAR(customHitpoints)) exitWith { ERROR_1("Bad hitpoints for unit type ""%1""",typeOf _unit); }; diff --git a/addons/medical_engine/XEH_preInit.sqf b/addons/medical_engine/XEH_preInit.sqf index 509eb6ec587..e98b2b28d16 100644 --- a/addons/medical_engine/XEH_preInit.sqf +++ b/addons/medical_engine/XEH_preInit.sqf @@ -46,7 +46,7 @@ GVAR(animations) setVariable [QUNCON_ANIM(faceDown), [QUNCON_ANIM(1),QUNCON_ANIM GVAR(animations) setVariable [QUNCON_ANIM(faceLeft), [QUNCON_ANIM(7),QUNCON_ANIM(8),QUNCON_ANIM(1_1),QUNCON_ANIM(7_1),QUNCON_ANIM(8_1)]]; GVAR(animations) setVariable [QUNCON_ANIM(faceRight), [QUNCON_ANIM(5),QUNCON_ANIM(6),QUNCON_ANIM(10),QUNCON_ANIM(5_1),QUNCON_ANIM(6_1)]]; -GVAR(hitpoints) = ["hitleftarm", "hitrightarm", "hitleftleg", "hitrightleg"]; +GVAR(customHitpoints) = ["hitleftarm", "hitrightarm", "hitleftleg", "hitrightleg"]; private _fnc_fixStatic = { params ["_vehicle"]; From d4101d86726ac86c7f65ddfbc31c62546c59f81f Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:19:28 -0300 Subject: [PATCH 09/19] reenable compile cache --- addons/medical_engine/script_component.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/medical_engine/script_component.hpp b/addons/medical_engine/script_component.hpp index ee16cdf1e0c..59cd015080e 100644 --- a/addons/medical_engine/script_component.hpp +++ b/addons/medical_engine/script_component.hpp @@ -3,7 +3,7 @@ #include "\z\ace\addons\main\script_mod.hpp" // #define DEBUG_MODE_FULL -#define DISABLE_COMPILE_CACHE +// #define DISABLE_COMPILE_CACHE // #define ENABLE_PERFORMANCE_COUNTERS #ifdef DEBUG_ENABLED_MEDICAL_ENGINE From cf0c78a0d6818293e33e36b4ff02d8064edcd33c Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:25:15 -0300 Subject: [PATCH 10/19] remove debug mode --- addons/medical_engine/functions/fnc_handleDamage.sqf | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/medical_engine/functions/fnc_handleDamage.sqf b/addons/medical_engine/functions/fnc_handleDamage.sqf index 3ab652f3d49..875abc87c76 100644 --- a/addons/medical_engine/functions/fnc_handleDamage.sqf +++ b/addons/medical_engine/functions/fnc_handleDamage.sqf @@ -1,4 +1,3 @@ -#define DEBUG_MODE_FULL #include "..\script_component.hpp" /* * Author: commy2, kymckay From 7ed530a9f531ef57b0408b282a651ecd5dc1cca5 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:28:30 -0300 Subject: [PATCH 11/19] lazy eval --- addons/medical_engine/functions/fnc_handleDamage.sqf | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/addons/medical_engine/functions/fnc_handleDamage.sqf b/addons/medical_engine/functions/fnc_handleDamage.sqf index 875abc87c76..d489f309ae3 100644 --- a/addons/medical_engine/functions/fnc_handleDamage.sqf +++ b/addons/medical_engine/functions/fnc_handleDamage.sqf @@ -74,10 +74,8 @@ private _environmentDamage = _ammo == ""; // Crashing a vehicle doesn't fire the EH for each hitpoint so the "ace_hdbracket" code never runs // It does fire the EH multiple times, but this seems to scale with the intensity of the crash if ( - (EGVAR(medical,enableVehicleCrashes) && - _environmentDamage && - _inVehicle && - _structuralDamage) && + EGVAR(medical,enableVehicleCrashes) && + {_environmentDamage && _inVehicle && _structuralDamage} && {vectorMagnitude (velocity _vehicle) > 5} // todo: no way to detect if stationary and another vehicle hits you ) exitWith { From 37ee2f09d7ca06c8a6cc4041585e0ab618da6801 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:29:09 -0300 Subject: [PATCH 12/19] whitespace --- addons/medical_engine/functions/fnc_handleDamage.sqf | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/addons/medical_engine/functions/fnc_handleDamage.sqf b/addons/medical_engine/functions/fnc_handleDamage.sqf index d489f309ae3..d21095833a8 100644 --- a/addons/medical_engine/functions/fnc_handleDamage.sqf +++ b/addons/medical_engine/functions/fnc_handleDamage.sqf @@ -88,9 +88,7 @@ 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 if ( - (_structuralDamage && - !_environmentDamage && - _inVehicle) && + (_structuralDamage && !_environmentDamage && _inVehicle) && { private _ammoCfg = configFile >> "CfgAmmo" >> _ammo; GET_NUMBER(_ammoCfg >> "explosive",0) > 0 || From 93c7b80976b895fc7d6c7a161937d8eb6e9468f2 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:30:04 -0300 Subject: [PATCH 13/19] update comment --- addons/medical_engine/functions/fnc_handleDamage.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/medical_engine/functions/fnc_handleDamage.sqf b/addons/medical_engine/functions/fnc_handleDamage.sqf index d21095833a8..b63c11691ee 100644 --- a/addons/medical_engine/functions/fnc_handleDamage.sqf +++ b/addons/medical_engine/functions/fnc_handleDamage.sqf @@ -105,7 +105,7 @@ if ( 0 }; -// Damages are stored for "ace_hdbracket" event triggered last +// Damages are stored for last iteration of the HandleDamage event (_context == 2) _unit setVariable [format [QGVAR($%1), _hitPoint], [_realDamage, _newDamage]]; // Ref https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#HandleDamage From 0b26be299695f8ba4a147c90a18d5a711980e78e Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Thu, 28 Mar 2024 11:26:38 -0300 Subject: [PATCH 14/19] Update fnc_handleDamage.sqf header --- addons/medical_engine/functions/fnc_handleDamage.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/medical_engine/functions/fnc_handleDamage.sqf b/addons/medical_engine/functions/fnc_handleDamage.sqf index b63c11691ee..b463c6bfa74 100644 --- a/addons/medical_engine/functions/fnc_handleDamage.sqf +++ b/addons/medical_engine/functions/fnc_handleDamage.sqf @@ -1,9 +1,9 @@ #include "..\script_component.hpp" /* - * Author: commy2, kymckay + * Author: commy2, kymckay, LinkIsGrim * HandleDamage EH where wound events are raised based on incoming damage. * Be aware that for each source of damage, the EH can fire multiple times (once for each hitpoint). - * We store these incoming damages and compare them on our final hitpoint: "ace_hdbracket". + * We store these incoming damages and compare them on last iteration of the event (_context == 2). * * Arguments: * Handle damage EH From f99d67e0b258240587912441c5cd1fc126d69e74 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Thu, 4 Apr 2024 08:07:40 -0300 Subject: [PATCH 15/19] Update addons/medical_engine/functions/fnc_handleDamage.sqf Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> --- addons/medical_engine/functions/fnc_handleDamage.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/medical_engine/functions/fnc_handleDamage.sqf b/addons/medical_engine/functions/fnc_handleDamage.sqf index b463c6bfa74..61de4997b9e 100644 --- a/addons/medical_engine/functions/fnc_handleDamage.sqf +++ b/addons/medical_engine/functions/fnc_handleDamage.sqf @@ -88,7 +88,7 @@ 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 if ( - (_structuralDamage && !_environmentDamage && _inVehicle) && + (!_environmentDamage && _inVehicle && _structuralDamage) && { private _ammoCfg = configFile >> "CfgAmmo" >> _ammo; GET_NUMBER(_ammoCfg >> "explosive",0) > 0 || From a035a110167800fb5077d4ab86f6743ea995cf96 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Sun, 2 Jun 2024 23:48:51 -0300 Subject: [PATCH 16/19] Update addons/medical_engine/XEH_postInit.sqf Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> --- addons/medical_engine/XEH_postInit.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/medical_engine/XEH_postInit.sqf b/addons/medical_engine/XEH_postInit.sqf index 6a0f241d589..eb71c7c3f45 100644 --- a/addons/medical_engine/XEH_postInit.sqf +++ b/addons/medical_engine/XEH_postInit.sqf @@ -13,7 +13,7 @@ if (getNumber (configOf _unit >> "isPlayableLogic") == 1) exitWith {TRACE_1("ignore logic unit",typeOf _unit);}; private _allHitPoints = getAllHitPointsDamage _unit param [0, []]; - if ((_allHitPoints arrayIntersect GVAR(customHitpoints)) isNotEqualTo GVAR(customHitpoints)) exitWith { + if ((GVAR(customHitpoints) arrayIntersect _allHitPoints) isNotEqualTo GVAR(customHitpoints)) exitWith { ERROR_1("Bad hitpoints for unit type ""%1""",typeOf _unit); }; From 5fe3c06e44ad7c9cfbf5c8a108ac6694079b7b57 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Fri, 7 Jun 2024 11:52:55 -0300 Subject: [PATCH 17/19] update hitpoint test --- addons/medical/dev/test_hitpointConfigs.sqf | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/addons/medical/dev/test_hitpointConfigs.sqf b/addons/medical/dev/test_hitpointConfigs.sqf index 9de5c5e6868..422cff4e0a4 100644 --- a/addons/medical/dev/test_hitpointConfigs.sqf +++ b/addons/medical/dev/test_hitpointConfigs.sqf @@ -21,23 +21,16 @@ INFO_1("Checking uniforms for correct medical hitpoints [%1 units]",count _units private _testPass = true; { private _typeOf = configName _x; - private _hitpoints = (configProperties [_x >> "HitPoints", "isClass _x", true]) apply {configName _x}; - - // _typeOf createUnit [position player, group player, "z = this"]; - // deleteVehicle z; - - private _lastHitpoint = (_hitpoints param [(count _hitpoints) - 1, "#array"]); - if (_lastHitpoint != "ACE_HDBracket") then { - WARNING_2("%1 has bad last hitpoint: %2",_typeOf,_hitpoints); + private _hitpoints = (configProperties [_x >> "HitPoints", "isClass _x", true]) apply {toLowerANSI _x}; + private _expectedHitPoints = ["hitleftarm","hitrightarm","hitleftleg","hitrightleg","hithead","hitbody"]; + private _missingHitPoints = _expectedHitPoints select {!(_x in _hitpoints)}; + if (_missingHitPoints isNotEqualTo []) then { + WARNING_3("%1 missing ace hitpoints: %2 - class hitpoints: %3,_typeOf,_missingHitPoints,_hitpoints); _testPass = false; }; - if (((_hitpoints findIf {_x == "HitLeftArm"}) == -1) || {(_hitpoints findIf {_x == "HitRightArm"}) == -1} - || {(_hitpoints findIf {_x == "HitLeftLeg"}) == -1} || {(_hitpoints findIf {_x == "HitRightLeg"}) == -1} - || {(_hitpoints findIf {_x == "HitHead"}) == -1} || {(_hitpoints findIf {_x == "HitBody"}) == -1}) then { - WARNING_2("%1 missing ace hitpoints: %2",_typeOf,_hitpoints); - _testPass = false; - }; + // _typeOf createUnit [position player, group player, "z = this"]; + // deleteVehicle z; } forEach _units; _testPass From 52995d70534cd0f0f7a65df23afe4b76e53db342 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Fri, 7 Jun 2024 11:53:15 -0300 Subject: [PATCH 18/19] missing " --- addons/medical/dev/test_hitpointConfigs.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/medical/dev/test_hitpointConfigs.sqf b/addons/medical/dev/test_hitpointConfigs.sqf index 422cff4e0a4..c33607440d6 100644 --- a/addons/medical/dev/test_hitpointConfigs.sqf +++ b/addons/medical/dev/test_hitpointConfigs.sqf @@ -25,7 +25,7 @@ private _testPass = true; private _expectedHitPoints = ["hitleftarm","hitrightarm","hitleftleg","hitrightleg","hithead","hitbody"]; private _missingHitPoints = _expectedHitPoints select {!(_x in _hitpoints)}; if (_missingHitPoints isNotEqualTo []) then { - WARNING_3("%1 missing ace hitpoints: %2 - class hitpoints: %3,_typeOf,_missingHitPoints,_hitpoints); + WARNING_3("%1 missing ace hitpoints: %2 - class hitpoints: %3",_typeOf,_missingHitPoints,_hitpoints); _testPass = false; }; From 43a2beb5f0eac70dd9f7e75a35c1aa504a252bb2 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Fri, 7 Jun 2024 12:05:17 -0300 Subject: [PATCH 19/19] Update addons/medical/dev/test_hitpointConfigs.sqf Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> --- addons/medical/dev/test_hitpointConfigs.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/medical/dev/test_hitpointConfigs.sqf b/addons/medical/dev/test_hitpointConfigs.sqf index c33607440d6..7bdeb189c23 100644 --- a/addons/medical/dev/test_hitpointConfigs.sqf +++ b/addons/medical/dev/test_hitpointConfigs.sqf @@ -21,7 +21,7 @@ INFO_1("Checking uniforms for correct medical hitpoints [%1 units]",count _units private _testPass = true; { private _typeOf = configName _x; - private _hitpoints = (configProperties [_x >> "HitPoints", "isClass _x", true]) apply {toLowerANSI _x}; + private _hitpoints = (configProperties [_x >> "HitPoints", "isClass _x", true]) apply {toLowerANSI configName _x}; private _expectedHitPoints = ["hitleftarm","hitrightarm","hitleftleg","hitrightleg","hithead","hitbody"]; private _missingHitPoints = _expectedHitPoints select {!(_x in _hitpoints)}; if (_missingHitPoints isNotEqualTo []) then {