Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIInvestigateClusterActivity.c
Go to the documentation of this file.
2 {
3  protected ref TFireteamLockRefArray m_aFireteamsInvestigate = {};
4  protected ref TFireteamLockRefArray m_aFireteamsCover = {};
5 
6  protected bool m_bOrdersSent = false;
7 
8  protected static const float INVESTIGATION_RADIUS_MIN = 20.0;
9 
10  //------------------------------------------------------------------------------------
13  void SCR_AIInvestigateClusterActivity(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint,
14  notnull SCR_AITargetClusterState clusterState,
15  notnull TFireteamLockRefArray ftInvestigate, notnull TFireteamLockRefArray ftCover)
16  {
17  SetPriority(PRIORITY_ACTIVITY_INVESTIGATE_CLUSTER);
18  SetIsUniqueInActionQueue(false);
19 
20  foreach (auto ft : ftInvestigate)
21  {
22  RegisterFireteam(ft);
23  m_aFireteamsInvestigate.Insert(ft);
24  }
25 
26  foreach (auto ft : ftCover)
27  {
28  RegisterFireteam(ft);
29  m_aFireteamsCover.Insert(ft);
30  }
31  }
32 
33  //------------------------------------------------------------------------------------
34  void GetSpecificFireteams(notnull TFireteamLockRefArray fireteamsInvestigate, notnull TFireteamLockRefArray fireteamsCover)
35  {
36  fireteamsInvestigate.Clear();
37  fireteamsCover.Clear();
38 
39  foreach (auto ft : m_aFireteamsInvestigate)
40  fireteamsInvestigate.Insert(ft);
41 
42  foreach (auto ft : m_aFireteamsCover)
43  fireteamsCover.Insert(ft);
44  }
45 
46  //------------------------------------------------------------------------------------
47  override void OnFireteamRemovedFromGroup(SCR_AIGroupFireteam ft)
48  {
49  // Was it an investigating fireteam?
50  if (SCR_AIGroupFireteamLock.RemoveFireteamLock(m_aFireteamsInvestigate, ft))
51  {
52  if (m_aFireteamsInvestigate.IsEmpty())
53  {
54  #ifdef AI_DEBUG
55  AddDebugMessage("All investigating fireteams are destroyed, activity is failed");
56  #endif
57 
58  Fail();
59  }
60  }
61  else
62  {
63  SCR_AIGroupFireteamLock.RemoveFireteamLock(m_aFireteamsCover, ft);
64  }
65 
66  UnregisterFireteam(ft);
67  }
68 
69  //------------------------------------------------------------------------------------
70  override void OnActionSelected()
71  {
72  super.OnActionSelected();
73 
74  if (!m_bOrdersSent)
75  {
76  vector investigatePos;
77  float investigateRadius;
78  CalculateInvestigationArea(m_ClusterState, investigatePos, investigateRadius);
79 
80  AICommunicationComponent comms = m_Utility.m_Owner.GetCommunicationComponent();
81  if (!comms)
82  return;
83 
84  SendInvestigateMessages(comms, investigatePos, investigateRadius);
85  }
86 
87  // !! It runs once and then is suspended, we don't need to run the behavior tree for it.
88  //SetActionIsSuspended(true);
89  }
90 
91  //------------------------------------------------------------------------------------
92  override void OnActionDeselected()
93  {
94  super.OnActionDeselected();
95  m_bOrdersSent = false;
96  SendCancelMessages();
97  }
98 
99  //------------------------------------------------------------------------------------
100  override void OnActionCompleted()
101  {
102  super.OnActionCompleted();
103  SendCancelMessages();
104  }
105 
106  //------------------------------------------------------------------------------------
107  override void OnActionFailed()
108  {
109  super.OnActionFailed();
110  SendCancelMessages();
111  }
112 
113  //------------------------------------------------------------------------------------
114  override void OnActionRemoved()
115  {
116  // Release fireteams instantly, if action is still referenced by something else
117  super.OnActionRemoved();
118  m_aFireteamsInvestigate.Clear();
119  m_aFireteamsCover.Clear();
120  }
121 
122  //------------------------------------------------------------------------------------
123  protected void SendCancelMessages()
124  {
125  AICommunicationComponent comms = m_Utility.m_Owner.GetCommunicationComponent();
126  if (!comms)
127  return;
128 
129  // Send to all agents in all assigned fireteams
130  array<AIAgent> agents = {};
131  foreach (SCR_AIGroupFireteamLock ft : m_aAssignedFireteams)
132  {
133  ft.GetFireteam().GetMembers(agents);
134  foreach (AIAgent agent : agents)
135  {
136  if (!agent)
137  continue;
138 
139  SCR_AIMessage_Cancel msg = SCR_AIMessage_Cancel.Create(this);
140 
141  msg.SetReceiver(agent);
142  comms.RequestBroadcast(msg, agent);
143  }
144  }
145  }
146 
147  //------------------------------------------------------------------------------------
148  protected void SendInvestigateMessages(AICommunicationComponent comms, vector pos, float radius)
149  {
150  array<AIAgent> agents = {};
151  foreach (SCR_AIGroupFireteamLock ft : m_aFireteamsInvestigate)
152  {
153  ft.GetFireteam().GetMembers(agents);
154  foreach (AIAgent agent : agents)
155  {
156  if (!agent)
157  continue;
158 
159  if (SCR_AICompartmentHandling.IsInCompartment(agent))
160  continue;
161 
162  // Duration is large, since soldiers' investigation is tied to this activity
163  SCR_AIMessage_Investigate msg = SCR_AIMessage_Investigate.Create(pos, radius, true, duration: 10000);
164  msg.m_RelatedGroupActivity = this;
165  msg.SetReceiver(agent);
166  comms.RequestBroadcast(msg, agent);
167  }
168  }
169 
170  foreach (SCR_AIGroupFireteamLock ft : m_aFireteamsCover)
171  {
172  ft.GetFireteam().GetMembers(agents);
173  foreach (AIAgent agent : agents)
174  {
175  if (!agent)
176  continue;
177 
178  if (SCR_AICompartmentHandling.IsInCompartment(agent))
179  continue;
180 
182  msg.m_RelatedGroupActivity = this;
183  msg.SetReceiver(agent);
184  comms.RequestBroadcast(msg, agent);
185  }
186  }
187  }
188 
189  //------------------------------------------------------------------------------------
191  static void CalculateInvestigationArea(notnull SCR_AITargetClusterState s, out vector outCenterPos, out float outRadius)
192  {
193  const float minRadius = INVESTIGATION_RADIUS_MIN;
194 
195  vector center = 0.5*(s.m_vBBMin + s.m_vBBMax);
196  float radius = Math.Max(minRadius, vector.DistanceXZ(center, s.m_vBBMax));
197 
198  outCenterPos = center;
199  outRadius = radius;
200  }
201 
202  //------------------------------------------------------------------------------------------------
203  override string GetDebugPanelText()
204  {
205  // List all assigned fireteams
206  string str = "FTs: (";
207  foreach (SCR_AIGroupFireteamLock ftLock : m_aFireteamsInvestigate)
208  str = str + string.Format("%1, ", m_Utility.m_FireteamMgr.GetFireteamId(ftLock.GetFireteam()));
209  str = str + "| ";
210  foreach (SCR_AIGroupFireteamLock ftLock : m_aFireteamsCover)
211  str = str + string.Format("%1, ", m_Utility.m_FireteamMgr.GetFireteamId(ftLock.GetFireteam()));
212 
213  str = str + string.Format(") => C: %1", m_Utility.m_Perception.GetTargetClusterStateId(m_ClusterState));
214 
215  return str;
216  }
217 }
SCR_AIMessage_CoverCluster
void SCR_AIMessage_CoverCluster()
Definition: SCR_AIMessage.c:332
SCR_AIMessage_Cancel
Definition: SCR_AIMessage.c:263
SCR_AIMessage_CoverCluster
Definition: SCR_AIMessage.c:338
SCR_AIGroupFireteam
Definition: SCR_AIGroupFireteam.c:1
SCR_AIFireteamsClusterActivity
Definition: SCR_AIFireteamsClusterActivity.c:6
TFireteamLockRefArray
array< ref SCR_AIGroupFireteamLock > TFireteamLockRefArray
Definition: SCR_AIGroupFireteamLock.c:6
SCR_AIMessage_Investigate
Definition: SCR_AIMessage.c:400
SCR_AIGroupFireteamLock
Definition: SCR_AIGroupFireteamLock.c:9
SCR_AIInvestigateClusterActivity
Definition: SCR_AIInvestigateClusterActivity.c:1
SCR_AITargetClusterState
void SCR_AITargetClusterState(SCR_AIGroupTargetCluster cluster)
Definition: SCR_AITargetClusterState.c:38
SCR_AICompartmentHandling
Definition: SCR_AIUtils.c:76