From f1aaa9a676abdc80ef93d09f8703dc5a143d4be6 Mon Sep 17 00:00:00 2001 From: lambdatiger Date: Thu, 17 Oct 2024 19:47:22 -0500 Subject: [PATCH 1/4] Added delay to AI hearing explosions --- addons/eventhandlers/CfgEventHandlers.hpp | 2 +- addons/eventhandlers/XEH_PREP.hpp | 1 + .../functions/fnc_delayExplosionEH.sqf | 35 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 addons/eventhandlers/functions/fnc_delayExplosionEH.sqf diff --git a/addons/eventhandlers/CfgEventHandlers.hpp b/addons/eventhandlers/CfgEventHandlers.hpp index 1bf4a32f..76b7e5ed 100644 --- a/addons/eventhandlers/CfgEventHandlers.hpp +++ b/addons/eventhandlers/CfgEventHandlers.hpp @@ -18,7 +18,7 @@ class Extended_PostInit_EventHandlers { class Extended_Explosion_Eventhandlers { class CAManBase { class LAMBS_CAManBase_Explosion { - Explosion = QUOTE(_this call FUNC(explosionEH)); + Explosion = QUOTE(_this call FUNC(delayExplosionEH)); }; }; }; diff --git a/addons/eventhandlers/XEH_PREP.hpp b/addons/eventhandlers/XEH_PREP.hpp index b59ab1c2..917839ca 100644 --- a/addons/eventhandlers/XEH_PREP.hpp +++ b/addons/eventhandlers/XEH_PREP.hpp @@ -1 +1,2 @@ +PREP(delayExplosionEH); PREP(explosionEH); diff --git a/addons/eventhandlers/functions/fnc_delayExplosionEH.sqf b/addons/eventhandlers/functions/fnc_delayExplosionEH.sqf new file mode 100644 index 00000000..5b69c8a2 --- /dev/null +++ b/addons/eventhandlers/functions/fnc_delayExplosionEH.sqf @@ -0,0 +1,35 @@ +#include "script_component.hpp" +/* + * Author: Lambda.Tiger + * Delayed reaction to explosions. The delay is calculated on + * a) A base line of reaction time + * b) Distance from the explosion + * c) AI general skill + * + * Arguments: + * BIS Explosion EH + * + * Return Value: + * None + * + * Example: + * [BIS EXPLOSION EH ARGS] call lambs_eventhandlers_fnc_explosionEH; + * + * Public: No +*/ +params [ + ["_unit", objNull], + "", + ["_explosionSource", objNull] +]; + +if (!alive _unit || + !(local _unit) || + isPlayer _unit) exitWith {}; + +private _skill = _unit skill "general"; +private _timeOfFlight = (_unit distance _explosionSource) / 343; // 343 m/s - good value for speed of sound +// min delay of 160 ms based on +// EFFECTS OF PREKNOWLEDGE AND STIMULUS INTENSITY UPON SIMPLE REACTION TIME by J. M. Speiss +// Loudness and reaction time: I by D. L. Kohfeld, J. L. Santee, and N. D. Wallace +[{_this call FUNC(explosionEH)}, _this, 0.16 + _timeOfFlight + 0.2 * (1 - random _skill)] call CBA_fnc_waitAndExecute; From 3954e2725b633dd4b6229d52566cae0f91dcc496 Mon Sep 17 00:00:00 2001 From: lambdatiger Date: Thu, 17 Oct 2024 20:12:29 -0500 Subject: [PATCH 2/4] fixed null object for explosion source --- addons/eventhandlers/functions/fnc_delayExplosionEH.sqf | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/addons/eventhandlers/functions/fnc_delayExplosionEH.sqf b/addons/eventhandlers/functions/fnc_delayExplosionEH.sqf index 5b69c8a2..43efa6bb 100644 --- a/addons/eventhandlers/functions/fnc_delayExplosionEH.sqf +++ b/addons/eventhandlers/functions/fnc_delayExplosionEH.sqf @@ -13,7 +13,7 @@ * None * * Example: - * [BIS EXPLOSION EH ARGS] call lambs_eventhandlers_fnc_explosionEH; + * [BIS EXPLOSION EH ARGS] call lambs_eventhandlers_fnc_delayExplosionEH; * * Public: No */ @@ -28,7 +28,11 @@ if (!alive _unit || isPlayer _unit) exitWith {}; private _skill = _unit skill "general"; -private _timeOfFlight = (_unit distance _explosionSource) / 343; // 343 m/s - good value for speed of sound +private _timeOfFlight = if (isNull _explosionSource) then { + 0.03 // 10 m radius +} else { + (_unit distance _explosionSource) / 343 // 343 m/s - good value for speed of sound +}; // min delay of 160 ms based on // EFFECTS OF PREKNOWLEDGE AND STIMULUS INTENSITY UPON SIMPLE REACTION TIME by J. M. Speiss // Loudness and reaction time: I by D. L. Kohfeld, J. L. Santee, and N. D. Wallace From 420a83448f08542fe26dc50652f9341d4c3e5795 Mon Sep 17 00:00:00 2001 From: lambdatiger Date: Fri, 18 Oct 2024 22:56:07 -0500 Subject: [PATCH 3/4] Added a number of exit conditions --- .../eventhandlers/functions/fnc_delayExplosionEH.sqf | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/eventhandlers/functions/fnc_delayExplosionEH.sqf b/addons/eventhandlers/functions/fnc_delayExplosionEH.sqf index 43efa6bb..c4512a65 100644 --- a/addons/eventhandlers/functions/fnc_delayExplosionEH.sqf +++ b/addons/eventhandlers/functions/fnc_delayExplosionEH.sqf @@ -23,9 +23,10 @@ params [ ["_explosionSource", objNull] ]; -if (!alive _unit || - !(local _unit) || - isPlayer _unit) exitWith {}; +if (!GVAR(ExplosionEventHandlerEnabled) + || !(local _unit) + || isPlayer _unit + || {!(_unit call EFUNC(main,isAlive))}) exitWith {}; private _skill = _unit skill "general"; private _timeOfFlight = if (isNull _explosionSource) then { @@ -36,4 +37,6 @@ private _timeOfFlight = if (isNull _explosionSource) then { // min delay of 160 ms based on // EFFECTS OF PREKNOWLEDGE AND STIMULUS INTENSITY UPON SIMPLE REACTION TIME by J. M. Speiss // Loudness and reaction time: I by D. L. Kohfeld, J. L. Santee, and N. D. Wallace -[{_this call FUNC(explosionEH)}, _this, 0.16 + _timeOfFlight + 0.2 * (1 - random _skill)] call CBA_fnc_waitAndExecute; +private _delay = 0.16 + _timeOfFlight + 0.2 * random (1 - _skill); +if (_unit getVariable [QGVAR(explosionReactionTime), 0] > time + _delay) exitWith {}; +[{_this call FUNC(explosionEH)}, _this, _delay] call CBA_fnc_waitAndExecute; From 08354d5ffe723569218d46e86f65b359c6f65b4f Mon Sep 17 00:00:00 2001 From: lambdatiger Date: Fri, 18 Oct 2024 22:56:27 -0500 Subject: [PATCH 4/4] emphasized (maybe overemphasized) skill delay --- addons/eventhandlers/functions/fnc_delayExplosionEH.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/eventhandlers/functions/fnc_delayExplosionEH.sqf b/addons/eventhandlers/functions/fnc_delayExplosionEH.sqf index c4512a65..8ae251f2 100644 --- a/addons/eventhandlers/functions/fnc_delayExplosionEH.sqf +++ b/addons/eventhandlers/functions/fnc_delayExplosionEH.sqf @@ -37,6 +37,6 @@ private _timeOfFlight = if (isNull _explosionSource) then { // min delay of 160 ms based on // EFFECTS OF PREKNOWLEDGE AND STIMULUS INTENSITY UPON SIMPLE REACTION TIME by J. M. Speiss // Loudness and reaction time: I by D. L. Kohfeld, J. L. Santee, and N. D. Wallace -private _delay = 0.16 + _timeOfFlight + 0.2 * random (1 - _skill); +private _delay = 0.16 + _timeOfFlight + 0.5 * random (1 - _skill); if (_unit getVariable [QGVAR(explosionReactionTime), 0] > time + _delay) exitWith {}; [{_this call FUNC(explosionEH)}, _this, _delay] call CBA_fnc_waitAndExecute;