Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIDefendActivity.c
Go to the documentation of this file.
2 {
3  ref SCR_BTParam<AIWaypoint> m_Waypoint = new SCR_BTParam<AIWaypoint>(SCR_AIActionTask.WAYPOINT_PORT);
4  ref SCR_BTParam<vector> m_vAttackLocation = new SCR_BTParam<vector>(SCR_AIActionTask.ATTACK_LOCATION_PORT);
5 
6  protected ref array<AIAgent> m_aRadialCoverAgents = {};
7  //-------------------------------------------------------------------------------------------------
8  void InitParameters(AIWaypoint waypoint, float priorityLevel)
9  {
10  m_Waypoint.Init(this, waypoint);
11  m_vAttackLocation.Init(this, vector.Zero);
12  m_fPriorityLevel.Init(this, priorityLevel);
13  }
14 
15  //-------------------------------------------------------------------------------------------------
16  void SCR_AIDefendActivity(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint, AIWaypoint waypoint, vector attackLocation, float priority = PRIORITY_ACTIVITY_DEFEND, float priorityLevel = PRIORITY_LEVEL_NORMAL)
17  {
18  InitParameters(waypoint, priorityLevel);
19  m_sBehaviorTree = "AI/BehaviorTrees/Chimera/Group/ActivityDefend.bt";
20  SetPriority(priority);
21  if (!waypoint)
22  {
23  m_vAttackLocation.m_Value = attackLocation;
24  return;
25  }
26  else
27  {
28  float waypointRadius = waypoint.GetCompletionRadius();
29  vector waypointPositionWorld = waypoint.GetOrigin();
30  if (attackLocation == vector.Zero) // use orientation of the waypoint
31  {
32  float rotationAngle = waypoint.GetAngles()[1] * Math.DEG2RAD;
33  vector attackPositionWorld;
34  attackPositionWorld[0] = waypointPositionWorld[0] + Math.Sin(rotationAngle) * waypointRadius;
35  attackPositionWorld[2] = waypointPositionWorld[2] + Math.Cos(rotationAngle) * waypointRadius;
36  attackPositionWorld[1] = waypointPositionWorld[1];
37  m_vAttackLocation.m_Value = attackPositionWorld; // attack direction is a point on the circumference of waypoint given by the orientation of the waypoint
38  }
39  else
40  {
41  m_vAttackLocation.m_Value = (attackLocation - waypointPositionWorld).Normalized() * waypointRadius + waypointPositionWorld;
42  }
43  }
44  }
45 
46  //-------------------------------------------------------------------------------------------------
47  void AddAgentToRadialCover (AIAgent agent)
48  {
49  if (m_aRadialCoverAgents.Find(agent) == -1)
50  m_aRadialCoverAgents.Insert(agent);
51  }
52 
53  //-------------------------------------------------------------------------------------------------
54  void ClearRadialCoverAgents ()
55  {
56  m_aRadialCoverAgents.Clear();
57  }
58 
59  //-------------------------------------------------------------------------------------------------
60  int FindRadialCoverAgent (AIAgent agent)
61  {
62  return m_aRadialCoverAgents.Find(agent);
63  }
64 
65  //-------------------------------------------------------------------------------------------------
66  int GetRadialCoverAgentsCount ()
67  {
68  return m_aRadialCoverAgents.Count();
69  }
70 
71  //-------------------------------------------------------------------------------------------------
72  override string GetActionDebugInfo()
73  {
74  return this.ToString() + " defending area of " + m_Waypoint.ToString();
75  }
76 
77  //-------------------------------------------------------------------------------------------------
78  override void OnActionDeselected()
79  {
80  super.OnActionDeselected();
81  SCR_AIGroup group = SCR_AIGroup.Cast(m_Utility.GetAIAgent());
82  if (group)
83  group.ReleaseCompartments();
84  SendCancelMessagesToAllAgents();
85  }
86 
87  //-------------------------------------------------------------------------------------------------
88  override void OnActionFailed()
89  {
90  super.OnActionFailed();
91  SCR_AIGroup group = SCR_AIGroup.Cast(m_Utility.GetAIAgent());
92  if (group)
93  group.ReleaseCompartments();
94  SendCancelMessagesToAllAgents();
95  }
96 
97  //-------------------------------------------------------------------------------------------------
98  override void OnActionCompleted()
99  {
100  super.OnActionCompleted();
101  SendCancelMessagesToAllAgents();
102  }
103 };
SCR_AIDefendActivity
Definition: SCR_AIDefendActivity.c:1
m_fPriorityLevel
float m_fPriorityLevel
Definition: SendGoalMessage.c:3
SCR_AIActivityBase
Definition: SCR_AIActivity.c:1
m_Waypoint
protected AIWaypoint m_Waypoint
Definition: SCR_AmbientPatrolSpawnPointComponent.c:48
SCR_AIGroup
Definition: SCR_AIGroup.c:68
SCR_AIActionTask
Definition: SCR_AIBehaviorTask.c:1