Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIAttackClusterActivity.c
Go to the documentation of this file.
2 {
3  protected ref TFireteamLockArray m_aFireteamsAttack = {};
4  protected ref TFireteamLockArray m_aFireteamsCover = {};
5 
6  bool m_bOrdersSent = false;
7 
8  //------------------------------------------------------------------------------------
9  void SCR_AIAttackClusterActivity(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint,
10  notnull SCR_AITargetClusterState clusterState,
11  notnull TFireteamLockRefArray ftAttack, notnull TFireteamLockRefArray ftCover)
12  {
13  SetPriority(PRIORITY_ACTIVITY_ATTACK_CLUSTER);
14  SetIsUniqueInActionQueue(false);
15 
16  m_ClusterState = clusterState;
17 
18  foreach (auto ft : ftAttack)
19  {
20  RegisterFireteam(ft);
21  m_aFireteamsAttack.Insert(ft);
22  }
23 
24  foreach (auto ft : ftCover)
25  {
26  RegisterFireteam(ft);
27  m_aFireteamsCover.Insert(ft);
28  }
29  }
30 
31  //------------------------------------------------------------------------------------
32  void GetSpecificFireteams(notnull TFireteamLockRefArray fireteamsAttack, notnull TFireteamLockRefArray fireteamsCover)
33  {
34  fireteamsAttack.Clear();
35  fireteamsCover.Clear();
36 
37  foreach (auto ft : m_aFireteamsAttack)
38  fireteamsAttack.Insert(ft);
39 
40  foreach (auto ft : m_aFireteamsCover)
41  fireteamsCover.Insert(ft);
42  }
43 
44  //------------------------------------------------------------------------------------
45  override void OnFireteamRemovedFromGroup(SCR_AIGroupFireteam ft)
46  {
47  if (SCR_AIGroupFireteamLock.RemoveFireteamLock(m_aFireteamsAttack, ft))
48  {
49  // Was an attacking fireteam
50  if (m_aFireteamsAttack.IsEmpty())
51  {
52  #ifdef AI_DEBUG
53  AddDebugMessage("All attacking fireteams are destroyed, activity is failed");
54  #endif
55  Fail();
56  }
57  }
58  else
59  {
60  SCR_AIGroupFireteamLock.RemoveFireteamLock(m_aFireteamsCover, ft);
61  }
62 
63  UnregisterFireteam(ft);
64  }
65 
66  //------------------------------------------------------------------------------------
67  override void OnActionSelected()
68  {
69  super.OnActionSelected();
70 
71  if (!m_bOrdersSent)
72  {
73  SCR_ChimeraAIAgent leader = SCR_ChimeraAIAgent.Cast(m_Utility.m_Owner.GetLeaderAgent());
74  if (leader)
75  {
76  SCR_AICommsHandler commsHandler = SCR_AISoundHandling.FindCommsHandler(leader);
77  if (!commsHandler.CanBypass())
78  {
79  foreach (SCR_AIGroupFireteamLock ftLock : m_aFireteamsAttack)
80  {
81  IEntity talkRequestEntity = ftLock.GetFireteam().GetFirstMemberEntity();
82 
83  int flankValue = Math.RandomIntInclusive(0, 1);
84  SCR_AITalkRequest rq = new SCR_AITalkRequest(ECommunicationType.REPORT_FLANK, talkRequestEntity, vector.Zero, flankValue, false, false, SCR_EAITalkRequestPreset.MANDATORY);
85  commsHandler.AddRequest(rq);
86  }
87  }
88  }
89 
90  SendAttackMessages();
91  m_bOrdersSent = true;
92  }
93 
94  // !! It runs once and then is suspended, we don't need to run the behavior tree for it.
95  //SetActionIsSuspended(true);
96  }
97 
98  //------------------------------------------------------------------------------------
99  override void OnActionDeselected()
100  {
101  super.OnActionDeselected();
102  m_bOrdersSent = false;
103  SendCancelMessages();
104  }
105 
106  //------------------------------------------------------------------------------------
107  override void OnActionCompleted()
108  {
109  super.OnActionCompleted();
110  SendCancelMessages();
111  }
112 
113  //------------------------------------------------------------------------------------
114  override void OnActionFailed()
115  {
116  super.OnActionFailed();
117  SendCancelMessages();
118  }
119 
120  //------------------------------------------------------------------------------------
121  override void OnActionRemoved()
122  {
123  // Release fireteams instantly, if action is still referenced by something else
124  super.OnActionRemoved();
125  m_aFireteamsAttack.Clear();
126  m_aFireteamsCover.Clear();
127  }
128 
129 
130  //------------------------------------------------------------------------------------
131  void SendAttackMessages()
132  {
133  AICommunicationComponent comms = m_Utility.m_Owner.GetCommunicationComponent();
134  if (!comms)
135  return;
136 
137  array<AIAgent> agents = {};
138  foreach (SCR_AIGroupFireteamLock ft : m_aFireteamsCover)
139  {
140  ft.GetFireteam().GetMembers(agents);
141  foreach (AIAgent agent : agents)
142  {
143  if (!agent)
144  continue;
145 
146  if (SCR_AICompartmentHandling.IsInCompartment(agent))
147  continue;
148 
149  SCR_AIMessage_AttackCluster msg = SCR_AIMessage_AttackCluster.Create(m_ClusterState, false);
150  msg.m_RelatedGroupActivity = this;
151  msg.SetReceiver(agent);
152  comms.RequestBroadcast(msg, agent);
153  }
154  }
155 
156  foreach (SCR_AIGroupFireteamLock ft : m_aFireteamsAttack)
157  {
158  ft.GetFireteam().GetMembers(agents);
159  foreach (AIAgent agent : agents)
160  {
161  if (!agent)
162  continue;
163 
164  if (SCR_AICompartmentHandling.IsInCompartment(agent))
165  continue;
166 
167  SCR_AIMessage_AttackCluster msg = SCR_AIMessage_AttackCluster.Create(m_ClusterState, true); // Attacking fireteam is allowed to investigate
168  msg.m_RelatedGroupActivity = this;
169  msg.SetReceiver(agent);
170  comms.RequestBroadcast(msg, agent);
171  }
172  }
173  }
174 
175  //------------------------------------------------------------------------------------
176  void SendCancelMessages()
177  {
178  AICommunicationComponent comms = m_Utility.m_Owner.GetCommunicationComponent();
179  if (!comms)
180  return;
181 
182  array<AIAgent> agents = {};
183  foreach (SCR_AIGroupFireteamLock ft : m_aAssignedFireteams) // Send to all fireteams
184  {
185  ft.GetFireteam().GetMembers(agents);
186  foreach (AIAgent agent : agents)
187  {
188  if (!agent)
189  continue;
190 
192  msg.m_RelatedGroupActivity = this;
193  msg.SetReceiver(agent);
194  comms.RequestBroadcast(msg, agent);
195 
196  SCR_AIMessage_Cancel msgCancel = SCR_AIMessage_Cancel.Create(this);
197  msgCancel.SetReceiver(agent);
198  comms.RequestBroadcast(msgCancel, agent);
199  }
200  }
201  }
202 
203  //------------------------------------------------------------------------------------------------
204  override string GetDebugPanelText()
205  {
206  // List all assigned fireteams
207  string str = "FTs: (";
208  foreach (SCR_AIGroupFireteamLock ftLock : m_aFireteamsAttack)
209  str = str + string.Format("%1, ", m_Utility.m_FireteamMgr.GetFireteamId(ftLock.GetFireteam()));
210  str = str + "| ";
211  foreach (SCR_AIGroupFireteamLock ftLock : m_aFireteamsCover)
212  str = str + string.Format("%1, ", m_Utility.m_FireteamMgr.GetFireteamId(ftLock.GetFireteam()));
213 
214  str = str + string.Format(") => C: %1", m_Utility.m_Perception.GetTargetClusterStateId(m_ClusterState));
215 
216  return str;
217  }
218 }
SCR_AIMessage_Cancel
Definition: SCR_AIMessage.c:263
SCR_AIMessage_AttackCluster
Definition: SCR_AIMessage.c:305
SCR_AIGroupFireteam
Definition: SCR_AIGroupFireteam.c:1
SCR_AITalkRequest
void SCR_AITalkRequest(ECommunicationType type, IEntity entity, vector pos, int enumSignal, bool transmitIfNoReceivers, bool transmitIfPassenger, SCR_EAITalkRequestPreset preset)
Definition: SCR_AITalkRequest.c:37
SCR_ChimeraAIAgent
Definition: SCR_ChimeraAIAgent.c:5
SCR_AIFireteamsClusterActivity
Definition: SCR_AIFireteamsClusterActivity.c:6
SCR_AIAttackClusterActivity
Definition: SCR_AIAttackClusterActivity.c:1
TFireteamLockArray
array< SCR_AIGroupFireteamLock > TFireteamLockArray
Definition: SCR_AIGroupFireteamLock.c:7
TFireteamLockRefArray
array< ref SCR_AIGroupFireteamLock > TFireteamLockRefArray
Definition: SCR_AIGroupFireteamLock.c:6
ECommunicationType
ECommunicationType
Definition: SCR_AISoundHandling.c:1
SCR_AIGroupFireteamLock
Definition: SCR_AIGroupFireteamLock.c:9
SCR_AICommsHandler
Definition: SCR_AICommsHandler.c:19
SCR_AITargetClusterState
void SCR_AITargetClusterState(SCR_AIGroupTargetCluster cluster)
Definition: SCR_AITargetClusterState.c:38
SCR_AIMessage_AttackClusterDone
SCR_AIMessage_AttackCluster SCR_AIMessageGoal SCR_AIMessage_AttackClusterDone()
Definition: SCR_AIMessage.c:326
SCR_AICompartmentHandling
Definition: SCR_AIUtils.c:76