4 protected static const float PROJECTILE_FLYBY_RADIUS = 13;
5 protected static const float PROJECTILE_FLYBY_RADIUS_SQ = PROJECTILE_FLYBY_RADIUS * PROJECTILE_FLYBY_RADIUS;
6 protected static const float AI_WEAPONFIRED_REACTION_DISTANCE = 500;
8 override bool PerformReaction(notnull SCR_AIUtilityComponent utility, notnull
SCR_AIThreatSystem threatSystem, AIDangerEvent dangerEvent)
10 IEntity shooter = dangerEvent.GetObject();
16 IEntity shooterRoot = shooter.GetRootParent();
19 if (!agent || !agent.IsEnemy(shooterRoot))
23 shooter.GetBounds(min, max);
24 vector lookPosition = shooter.GetOrigin() + (min + max) * 0.5;
26 vector myOrigin = utility.m_OwnerEntity.GetOrigin();
27 float distance = vector.Distance(myOrigin, shooter.GetOrigin());
29 bool flyby = IsFlyby(myOrigin,
distance, shooter);
32 threatSystem.ThreatProjectileFlyby(dangerEvent.GetCount());
34 threatSystem.ThreatShotFired(
distance, dangerEvent.GetCount());
38 utility.m_LookAction.LookAt(lookPosition, utility.m_LookAction.PRIO_DANGER_EVENT, 3.0);
42 AIGroup myGroup = AIGroup.Cast(utility.GetOwner().GetParentGroup());
43 if (myGroup && myGroup.GetLeaderAgent() == agent)
44 NotifyGroup(myGroup, shooterRoot, lookPosition);
48 if (utility.m_CombatComponent.GetCurrentTarget() !=
null ||
49 distance > AI_WEAPONFIRED_REACTION_DISTANCE)
53 vector turretDismountCheckPosition = lookPosition;
54 bool mustDismountTurret = utility.m_CombatComponent.DismountTurretCondition(turretDismountCheckPosition,
true);
55 if (mustDismountTurret)
57 utility.m_CombatComponent.TryAddDismountTurretActions(turretDismountCheckPosition);
61 bool addObserveBehavior =
false;
64 if (investigateBehavior && investigateBehavior.GetActionState() ==
EAIActionState.RUNNING)
67 addObserveBehavior =
true;
69 else if (oldObserveBehavior)
72 addObserveBehavior =
true;
74 else if (!oldObserveBehavior)
75 addObserveBehavior =
true;
77 if (addObserveBehavior)
82 utility.AddAction(observeBehavior);
84 else if (oldObserveBehavior && flyby)
89 oldObserveBehavior.SetUseMovement(
true);
95 void NotifyGroup(AIGroup group, IEntity shooter, vector posWorld)
97 SCR_AIGroupUtilityComponent groupUtilityComp = SCR_AIGroupUtilityComponent.Cast(group.FindComponent(SCR_AIGroupUtilityComponent));
100 PerceptionManager pm =
GetGame().GetPerceptionManager();
103 float timestamp = pm.GetTime();
104 groupUtilityComp.m_Perception.AddOrUpdateGunshot(shooter, posWorld, timestamp);
109 bool IsFlyby(vector myPos,
float distanceToShooter, IEntity shooter)
112 BaseWeaponManagerComponent weaponMgr = BaseWeaponManagerComponent.Cast(shooter.FindComponent(BaseWeaponManagerComponent));
116 vector muzzleTransform[4];
117 weaponMgr.GetCurrentMuzzleTransform(muzzleTransform);
118 vector muzzlePos = muzzleTransform[3];
120 if ( distanceToShooter > PROJECTILE_FLYBY_RADIUS &&
121 Math3D.IntersectionPointCylinder(myPos, muzzleTransform[3], muzzleTransform[2], PROJECTILE_FLYBY_RADIUS) )