Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIDecoIsEnemyWithinRadius.c
Go to the documentation of this file.
1 class SCR_AIDecoIsEnemyWithinRadius : DecoratorScripted
2 {
3  static const string WAYPOINT_PORT = "WaypointIn";
4  static const string LOCATION_PORT = "LocationOut";
5 
6  //---------------------------------------------------------------------------------------------------
7  protected static ref TStringArray s_aVarsOut = {
8  LOCATION_PORT
9  };
10  override TStringArray GetVariablesOut()
11  {
12  return s_aVarsOut;
13  }
14 
15  //---------------------------------------------------------------------------------------------------
16  protected static ref TStringArray s_aVarsIn = {
17  WAYPOINT_PORT
18  };
19  override TStringArray GetVariablesIn()
20  {
21  return s_aVarsIn;
22  }
23 
24  //---------------------------------------------------------------------------------------------------
25  // Checks if at least one enemy known to group is within the completion radius
26  bool TestLocationOfKnownEnemies(SCR_AIGroupUtilityComponent groupUtility, AIWaypoint waypoint)
27  {
28  float waypointRadiusSq = waypoint.GetCompletionRadius() * waypoint.GetCompletionRadius();
29 
30  vector wpOrigin = waypoint.GetOrigin();
31 
32  foreach (SCR_AITargetInfo tgtInfo : groupUtility.m_Perception.m_aTargets)
33  {
34  if (tgtInfo.m_eCategory == EAITargetInfoCategory.DESTROYED)
35  continue;
36 
37  if (vector.DistanceSq(tgtInfo.m_vWorldPos, wpOrigin) < waypointRadiusSq)
38  {
39  SetVariableOut(LOCATION_PORT, tgtInfo.m_vWorldPos);
40  return true;
41  }
42  }
43  return false;
44  }
45 
46  //---------------------------------------------------------------------------------------------------
47  protected override bool TestFunction(AIAgent owner)
48  {
49  AIWaypoint waypoint;
50  SCR_AIGroupUtilityComponent guc;
51 
52  AIGroup group = AIGroup.Cast(owner);
53  if (!group)
54  return false;
55 
56  if ( !GetVariableIn(WAYPOINT_PORT,waypoint) )
57  waypoint = group.GetCurrentWaypoint();
58  if (! waypoint )
59  {
60  Print("Node IsEnemyWithinRadius executed without valid waypoint!");
61  return false;
62  };
63  guc = SCR_AIGroupUtilityComponent.Cast(owner.FindComponent(SCR_AIGroupUtilityComponent));
64  if ( !guc )
65  {
66  Print("Node IsEnemyWithinRadius executed on owner without group utility component!");
67  return false;
68  }
69  return TestLocationOfKnownEnemies(guc, waypoint);
70  }
71 
72  //---------------------------------------------------------------------------------------------------
73  protected override bool VisibleInPalette()
74  {
75  return true;
76  }
77 
78  protected override string GetOnHoverDescription()
79  {
80  return "Decorator that test that at least one detected enemy is within completion radius of waypoint, current waypoint is used if none is provided";
81  }
82 };
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
SCR_AIDecoIsEnemyWithinRadius
Definition: SCR_AIDecoIsEnemyWithinRadius.c:1
EAITargetInfoCategory
EAITargetInfoCategory
Definition: SCR_AITargetInfo.c:1