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

Eventhandlers - Add Delay to AI Explosion Reaction #418

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion addons/eventhandlers/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
};
};
1 change: 1 addition & 0 deletions addons/eventhandlers/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PREP(delayExplosionEH);
PREP(explosionEH);
39 changes: 39 additions & 0 deletions addons/eventhandlers/functions/fnc_delayExplosionEH.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#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_delayExplosionEH;
*
* Public: No
*/
params [
["_unit", objNull],
"",
["_explosionSource", objNull]
];

if (!alive _unit ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should move/do more of the checks we do in the here before we run the waitAndExecute

Copy link
Author

Choose a reason for hiding this comment

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

I agree, but I think a few of these could change in time:

  • !GVAR(ExplosionEventHandlerEnabled) - should have been there
  • !alive - covers isNull - probably could be replaced with {!(_unit call EFUNC(main,isAlive))
  • {!isNul objectParent _unit} - could be added, but units may be getting in/out and the transition happens in time
  • {(stance _unit) isEqualTo "PRONE"} - a thing that could be changing in that ~0.15-0.3 ms
  • {_unit getVariable [QGVAR(explosionReactionTime), 0] > time} - delay could be computed and then checked against this statement

I'll make the changes I think I made clear I think are good ideas, but for checking if a unit is in a vehicle or is prone I could go either way on.

!(local _unit) ||
isPlayer _unit) exitWith {};

private _skill = _unit skill "general";
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
[{_this call FUNC(explosionEH)}, _this, 0.16 + _timeOfFlight + 0.2 * (1 - random _skill)] call CBA_fnc_waitAndExecute;
Loading