Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_TaskNotificationComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Tasks", description: "Task notification component")]
5
6class SCR_TaskNotificationComponent : ScriptComponent
7{
8 [Attribute(uiwidget: UIWidgets.ComboBox, enumType:SCR_ETaskNotification)]
9 protected SCR_ETaskNotification m_eTaskNotification;
10
13 protected RplComponent m_RplComponent;
14 protected SCR_Task m_Task;
19 protected int m_iGridX;
20 protected int m_iGridY;
21
22 protected const bool ALLOW_SEND_TO_EMPTY_GROUP = false;
23
24 //------------------------------------------------------------------------------------------------
27 {
28 if (!m_Task || !m_FactionManager)
29 return null;
30
31 SCR_CampaignFaction campaignFaction;
32 foreach (string factionKey : m_Task.GetTaskData().m_aOwnerFactionKeys)
33 {
34 if (factionKey.IsEmpty())
35 continue;
36
37 campaignFaction = SCR_CampaignFaction.Cast(m_FactionManager.GetFactionByKey(factionKey));
38 if (campaignFaction)
39 return campaignFaction;
40 }
41
42 return null;
43 }
44
45 //------------------------------------------------------------------------------------------------
46 protected bool HasGroupTask(SCR_TaskExecutor executor)
47 {
48 SCR_Task task = m_TaskSystem.GetTaskAssignedTo(executor);
49 return task != null;
50 }
51
52 //------------------------------------------------------------------------------------------------
53 protected string GetTaskName(SCR_Task task)
54 {
55 if (!task || !task.GetTaskData() || !task.GetTaskData().m_UIInfo)
56 {
57 Print("Task name cannot be fetched", LogLevel.WARNING);
58 return string.Empty;
59 }
60
61 return task.GetTaskData().m_UIInfo.GetTranslatedName();
62 }
63
64 //------------------------------------------------------------------------------------------------
65 protected bool IsPlayerGroupLeader(int playerID, notnull array<SCR_AIGroup> playableGroups)
66 {
67 foreach (SCR_AIGroup group : playableGroups)
68 {
69 if (group.IsPlayerLeader(playerID))
70 return true;
71 }
72
73 return false;
74 }
75
76 //------------------------------------------------------------------------------------------------
77 protected void SetGrid()
78 {
79 m_iGridX = 0;
80 m_iGridY = 0;
81 SCR_MapEntity.GetGridPos(m_Task.GetTaskPosition(), m_iGridX, m_iGridY);
82 }
83
84 //------------------------------------------------------------------------------------------------
85 protected void OnTaskCreated(SCR_Task task, int byPlayerID)
86 {
87 if (task != m_Task || !m_GroupsManager)
88 return;
89
91 if (!faction)
92 return;
93
94 array<SCR_AIGroup> playableGroups = m_GroupsManager.GetPlayableGroupsByFaction(faction);
95 if (!playableGroups)
96 return;
97
98 BaseTransceiver hqTransceiver = GetHQTransceiver(faction);
99 if (!hqTransceiver)
100 return;
101
102 int baseCallsign = SCR_MilitaryBaseComponent.INVALID_BASE_CALLSIGN;
103 SCR_CampaignMilitaryBaseTaskEntity baseTask = SCR_CampaignMilitaryBaseTaskEntity.Cast(GetOwner());
104 if (baseTask && baseTask.GetMilitaryBase())
105 baseCallsign = baseTask.GetMilitaryBase().GetCallsign();
106
107 SCR_TaskExecutorGroup groupExecutor;
108 foreach (SCR_AIGroup group : playableGroups)
109 {
110 if (!ALLOW_SEND_TO_EMPTY_GROUP && group.GetPlayerCount() == 0)
111 continue;
112
113 groupExecutor = SCR_TaskExecutorGroup.Cast(SCR_TaskExecutorGroup.FromGroup(group.GetGroupID()));
114 if (!groupExecutor)
115 continue;
116
117 if (m_TaskSystem.CanTaskBeAssignedTo(task, groupExecutor))
118 {
119 if (!task.IsTaskAssignedTo(groupExecutor))
120 {
121 if (HasGroupTask(groupExecutor))
122 SendMessageToGroup(m_eTaskNotification, SCR_ETaskNotificationMsg.MINOR_CREATION, 0, hqTransceiver, group, baseCallsign);
123 else
124 SendMessageToGroup(m_eTaskNotification, SCR_ETaskNotificationMsg.MAJOR_CREATION, 0, hqTransceiver, group, baseCallsign, 0, 0, m_iGridX, m_iGridY);
125 }
126 }
127 }
128 }
129
130 //------------------------------------------------------------------------------------------------
131 protected void OnTaskAssigneeAdded(SCR_Task task, SCR_TaskExecutor executor, int requesterID)
132 {
133 if (task != m_Task || !m_GroupsManager)
134 return;
135
137 if (!faction)
138 return;
139
140 array<SCR_AIGroup> playableGroups = m_GroupsManager.GetPlayableGroupsByFaction(faction);
141 if (!playableGroups)
142 return;
143
144 SCR_TaskExecutorGroup newAssignedGroupExecutor = SCR_TaskExecutorGroup.Cast(executor);
145 if (!newAssignedGroupExecutor)
146 return;
147
148 SCR_PlayerControllerGroupComponent playerGroupComponent = SCR_PlayerControllerGroupComponent.GetPlayerControllerComponent(requesterID);
149 if (!playerGroupComponent)
150 return;
151
152 int requesterGroupId = playerGroupComponent.GetGroupID();
153
154 SCR_AIGroup newAssignedGroup = m_GroupsManager.FindGroup(newAssignedGroupExecutor.GetGroupID());
155 if (!newAssignedGroup)
156 return;
157
158 BaseTransceiver playerTransceiver = GetPlayerTransceiver(requesterID);
159 if (!playerTransceiver)
160 return;
161
162 int baseCallsign = SCR_MilitaryBaseComponent.INVALID_BASE_CALLSIGN;
163 SCR_CampaignMilitaryBaseTaskEntity baseTask = SCR_CampaignMilitaryBaseTaskEntity.Cast(GetOwner());
164 if (baseTask && baseTask.GetMilitaryBase())
165 baseCallsign = baseTask.GetMilitaryBase().GetCallsign();
166
167 if (faction.IsPlayerCommander(requesterID))
168 {
169 // commander send msg to SL and SM
170 SendMessageToGroup(m_eTaskNotification, SCR_ETaskNotificationMsg.MAJOR_GROUP_ASSIGNED_TO_TASK, requesterID, playerTransceiver, newAssignedGroup, baseCallsign, requesterGroupId, newAssignedGroup.GetGroupID(), m_iGridX, m_iGridY);
171 }
172
173 SCR_TaskExecutorGroup groupExecutor;
174 foreach (SCR_AIGroup group : playableGroups)
175 {
176 if (!ALLOW_SEND_TO_EMPTY_GROUP && group.GetPlayerCount() == 0)
177 continue;
178
179 groupExecutor = SCR_TaskExecutorGroup.Cast(SCR_TaskExecutorGroup.FromGroup(group.GetGroupID()));
180 if (!groupExecutor)
181 continue;
182
183 if (group.GetGroupRole() == SCR_EGroupRole.COMMANDER)
184 {
185 SendMessageToGroup(m_eTaskNotification, SCR_ETaskNotificationMsg.MAJOR_ASSIGNED_BY_SL_TO_COMMANDER, requesterID, playerTransceiver, group, baseCallsign, requesterGroupId, newAssignedGroup.GetGroupID(), m_iGridX, m_iGridY);
186 }
187 else if (task.IsTaskAssignedTo(groupExecutor))
188 {
189 if (group.IsPlayerLeader(requesterID))
190 {
191 SendMessageToGroup(m_eTaskNotification, SCR_ETaskNotificationMsg.MAJOR_ASSIGNED_BY_SL_TO_SM, requesterID, playerTransceiver, group, baseCallsign, requesterGroupId, newAssignedGroup.GetGroupID(), m_iGridX, m_iGridY);
192 }
193 else if (newAssignedGroupExecutor.GetGroupID() != groupExecutor.GetGroupID())
194 {
195 // skip a current assigned group
196 SendMessageToGroup(m_eTaskNotification, SCR_ETaskNotificationMsg.MINOR_GROUP_ASSIGNED_TO_SAME_TASK, requesterID, playerTransceiver, group, baseCallsign, newAssignedGroup.GetGroupID(), groupExecutor.GetGroupID(), m_iGridX, m_iGridY);
197 }
198 }
199 }
200 }
201
202 //------------------------------------------------------------------------------------------------
204 {
205 if (task != m_Task || !m_GroupsManager)
206 return;
207
209 if (!faction)
210 return;
211
212 array<SCR_AIGroup> playableGroups = m_GroupsManager.GetPlayableGroupsByFaction(faction);
213 if (!playableGroups)
214 return;
215
216 BaseTransceiver hqTransceiver = GetHQTransceiver(faction);
217 if (!hqTransceiver)
218 return;
219
220 int baseCallsign = SCR_MilitaryBaseComponent.INVALID_BASE_CALLSIGN;
221 SCR_CampaignMilitaryBaseTaskEntity baseTask = SCR_CampaignMilitaryBaseTaskEntity.Cast(GetOwner());
222 if (baseTask && baseTask.GetMilitaryBase())
223 baseCallsign = baseTask.GetMilitaryBase().GetCallsign();
224
225 SCR_TaskExecutorGroup groupExecutor;
226 foreach (SCR_AIGroup group : playableGroups)
227 {
228 if (!ALLOW_SEND_TO_EMPTY_GROUP && group.GetPlayerCount() == 0)
229 continue;
230
231 groupExecutor = SCR_TaskExecutorGroup.Cast(SCR_TaskExecutorGroup.FromGroup(group.GetGroupID()));
232 if (!groupExecutor)
233 continue;
234
235 if (group.GetGroupRole() == SCR_EGroupRole.COMMANDER && newState == SCR_ETaskState.COMPLETED)
236 {
237 SCR_AIGroup firstAssignedGroup = GetFirstAssignedGroup(m_Task);
238 if (firstAssignedGroup)
239 SendMessageToGroup(m_eTaskNotification, SCR_ETaskNotificationMsg.MAJOR_TASK_FOR_COMMANDER_COMPLETED, 0, hqTransceiver, group, baseCallsign, firstAssignedGroup.GetGroupID(), 0, m_iGridX, m_iGridY);
240 }
241 else if (task.IsTaskAssignedTo(groupExecutor))
242 {
243 if (newState == SCR_ETaskState.COMPLETED)
244 {
245 SendMessageToGroup(m_eTaskNotification, SCR_ETaskNotificationMsg.MAJOR_TASK_ASSIGNED_TO_YOUR_GROUP_COMPLETED, 0, hqTransceiver, group, baseCallsign, group.GetGroupID(), 0, m_iGridX, m_iGridY);
246 }
247 else if (newState == SCR_ETaskState.FAILED)
248 {
249 SendMessageToGroup(m_eTaskNotification, SCR_ETaskNotificationMsg.MAJOR_TASK_ASSIGNED_TO_YOUR_GROUP_FAILED, 0, hqTransceiver, group, baseCallsign, group.GetGroupID(), 0, m_iGridX, m_iGridY);
250 }
251 else if (newState == SCR_ETaskState.CANCELLED)
252 {
253 SendMessageToGroup(m_eTaskNotification, SCR_ETaskNotificationMsg.MAJOR_TASK_ASSIGNED_TO_YOUR_GROUP_CANCELED, 0, hqTransceiver, group, baseCallsign, group.GetGroupID(), 0, m_iGridX, m_iGridY);
254 }
255 }
256 else if (m_TaskSystem.IsTaskVisibleFor(task, groupExecutor))
257 {
258 if (newState == SCR_ETaskState.COMPLETED)
259 {
260 SendMessageToGroup(m_eTaskNotification, SCR_ETaskNotificationMsg.MINOR_TASK_COMPLETED, 0, hqTransceiver, group, baseCallsign, group.GetGroupID(), 0, m_iGridX, m_iGridY);
261 }
262 else if (newState == SCR_ETaskState.FAILED)
263 {
264 SendMessageToGroup(m_eTaskNotification, SCR_ETaskNotificationMsg.MINOR_TASK_FAILED, 0, hqTransceiver, group, baseCallsign, group.GetGroupID(), 0, m_iGridX, m_iGridY);
265 }
266 else if (newState == SCR_ETaskState.CANCELLED)
267 {
268 SendMessageToGroup(m_eTaskNotification, SCR_ETaskNotificationMsg.MINOR_TASK_CANCELED, 0, hqTransceiver, group, baseCallsign, group.GetGroupID(), 0, m_iGridX, m_iGridY);
269 }
270 }
271 }
272 }
273
274 //------------------------------------------------------------------------------------------------
275 protected void OnGroupTaskSet(SCR_Task task, int byPlayerID)
276 {
277 if (task != m_Task)
278 return;
279
280 OnTaskCreated(task, byPlayerID);
281 }
282
283 //------------------------------------------------------------------------------------------------
285 {
286 SCR_CampaignMilitaryBaseComponent HQ = faction.GetMainBase();
287 if (!HQ)
288 return null;
289
290 BaseRadioComponent radio = BaseRadioComponent.Cast(HQ.GetOwner().FindComponent(BaseRadioComponent));
291 if (!radio || !radio.IsPowered())
292 return null;
293
294 return radio.GetTransceiver(0);
295 }
296
297 //------------------------------------------------------------------------------------------------
298 protected BaseTransceiver GetPlayerTransceiver(int playerId)
299 {
300 SCR_PlayerController playerController = SCR_PlayerController.Cast(GetGame().GetPlayerManager().GetPlayerController(playerId));
301 if (!playerController)
302 return null;
303
304 IEntity player = playerController.GetMainEntity();
305 if (!player)
306 return null;
307
309 if (!gadgetManager)
310 return null;
311
312 IEntity radioEnt = gadgetManager.GetGadgetByType(EGadgetType.RADIO);
313 if (!radioEnt)
314 return null;
315
316 BaseRadioComponent radio = BaseRadioComponent.Cast(radioEnt.FindComponent(BaseRadioComponent));
317 if (!radio || !radio.IsPowered())
318 return null;
319
320 return radio.GetTransceiver(0);
321 }
322
323 //------------------------------------------------------------------------------------------------
325 {
326 array<ref SCR_TaskExecutor> assignees = task.GetTaskAssignees();
327
328 if (!assignees.IsIndexValid(0))
329 return null;
330
331 SCR_TaskExecutorGroup assignedGroupExecutor = SCR_TaskExecutorGroup.Cast(assignees[0]);
332 if (!assignedGroupExecutor)
333 return null;
334
335 return m_GroupsManager.FindGroup(assignedGroupExecutor.GetGroupID());
336 }
337
338 //------------------------------------------------------------------------------------------------
339 protected void SendMessageToGroup(SCR_ETaskNotification notificationType, SCR_ETaskNotificationMsg msgType, int callerPlayerId, BaseTransceiver transmitter, SCR_AIGroup receiverGroup, int baseCallsign = SCR_MilitaryBaseComponent.INVALID_BASE_CALLSIGN, int callerGroupId = -1, int calledGroupId = -1, int gridX = -1, int gridY = -1)
340 {
341 if (!transmitter || !receiverGroup || !m_TaskNotificationManager || !m_FactionManager)
342 return;
343
345 if (!faction)
346 return;
347
348 SCR_BaseTaskNotificationData notificationData = m_TaskNotificationManager.GetTaskNotificationData(notificationType, msgType);
349 if (!notificationData || !notificationData.CanSendNotification(receiverGroup))
350 return;
351
352 int factionId = m_FactionManager.GetFactionIndex(faction);
353
355 msg.SetTaskNotification(notificationType, msgType);
356 msg.SetTaskNotificationData(notificationData);
357 msg.SetBaseCallsign(baseCallsign);
358 msg.SetFactionId(factionId);
359 msg.SetFaction(faction);
360 msg.SetGrid((gridX * 1000) + gridY);
361 msg.SetCallerGroupId(callerGroupId);
362 msg.SetCalledGroupId(calledGroupId);
363 msg.SetCallerPlayerId(callerPlayerId);
364 msg.SetEncryptionKey(transmitter.GetRadio().GetEncryptionKey());
365
366 if (m_Task)
367 msg.SetTaskPosition(m_Task.GetTaskPosition());
368
369 #ifdef TASK_NOTIFICATION_DEBUG
370 Print("[SCR_TaskNotificationComponent.SendMessageToGroup] notifType:"+SCR_Enum.GetEnumName(SCR_ETaskNotification, notificationType)+" msg:"+SCR_Enum.GetEnumName(SCR_ETaskNotificationMsg, msgType)+" to group:"+SCR_GroupHelperUI.GetTranslatedGroupNameAndRoleName(receiverGroup), LogLevel.DEBUG);
371 #endif
372
373 transmitter.BeginTransmissionFreq(msg, receiverGroup.GetRadioFrequency());
374 }
375
376 //------------------------------------------------------------------------------------------------
377 override void OnPostInit(IEntity owner)
378 {
379 SetEventMask(owner, EntityEvent.INIT);
380 }
381
382 //------------------------------------------------------------------------------------------------
383 override void EOnInit(IEntity owner)
384 {
385 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
386
387 if (!m_RplComponent || m_RplComponent.IsProxy())
388 return;
389
393 m_Task = SCR_Task.Cast(owner);
394 m_FactionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
396
397 if (!m_Campaign)
398 return;
399
400 SCR_Task.GetOnTaskAssigneeAdded().Insert(OnTaskAssigneeAdded);
401 SCR_Task.GetOnTaskStateChanged().Insert(OnTaskStateChanged);
402
403 m_TaskSystem = SCR_TaskSystem.GetInstance();
404
405 SetGrid();
406
408 m_GroupTaskManager.GetOnGroupTaskSet().Insert(OnGroupTaskSet);
409 }
410
411 //------------------------------------------------------------------------------------------------
412 override void OnDelete(IEntity owner)
413 {
414 SCR_Task.GetOnTaskAssigneeAdded().Remove(OnTaskAssigneeAdded);
415 SCR_Task.GetOnTaskStateChanged().Remove(OnTaskStateChanged);
416
418 m_GroupTaskManager.GetOnGroupTaskSet().Remove(OnGroupTaskSet);
419 }
420}
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_BaseGameMode GetGameMode()
RplComponent m_RplComponent
SCR_GameModeCampaign m_Campaign
void OnTaskStateChanged(SCR_Task task, SCR_ETaskState newState)
void OnTaskAssigneeAdded(SCR_Task task, SCR_TaskExecutor executor, int requesterID)
SCR_CampaignFaction GetFaction()
SCR_EGroupRole
Group roles.
SCR_ETaskNotification
Objective and request notifications types.
SCR_ETaskNotificationMsg
Various types of task notifications for different events and states.
void OnGroupTaskSet(SCR_Task task, int byPlayerID)
SCR_GroupTaskManagerComponent m_GroupTaskManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
void SCR_GroupTaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
SCR_FactionManager m_FactionManager
SCR_GroupsManagerComponent m_GroupsManager
SCR_RequestedTaskNotificationComponentClass SCR_TaskNotificationComponentClass OnTaskCreated(SCR_Task task, int byPlayerID)
void SCR_Task(IEntitySource src, IEntity parent)
Definition SCR_Task.c:1938
SCR_ETaskState
Definition SCR_Task.c:3
SCR_AIGroup GetFirstAssignedGroup(notnull SCR_Task task)
bool IsPlayerGroupLeader(int playerID, notnull array< SCR_AIGroup > playableGroups)
SCR_TaskSystem m_TaskSystem
SCR_TaskNotificationManagerComponent m_TaskNotificationManager
bool HasGroupTask(SCR_TaskExecutor executor)
void SendMessageToGroup(SCR_ETaskNotification notificationType, SCR_ETaskNotificationMsg msgType, int callerPlayerId, BaseTransceiver transmitter, SCR_AIGroup receiverGroup, int baseCallsign=SCR_MilitaryBaseComponent.INVALID_BASE_CALLSIGN, int callerGroupId=-1, int calledGroupId=-1, int gridX=-1, int gridY=-1)
string GetTaskName(SCR_Task task)
const bool ALLOW_SEND_TO_EMPTY_GROUP
BaseTransceiver GetPlayerTransceiver(int playerId)
BaseTransceiver GetHQTransceiver(notnull SCR_CampaignFaction faction)
void SCR_TaskNotificationManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external Managed FindComponent(typename typeName)
int GetRadioFrequency()
int GetGroupID()
bool CanSendNotification(notnull SCR_AIGroup receiverGroup)
IEntity GetGadgetByType(EGadgetType type)
static string GetTranslatedGroupNameAndRoleName(notnull SCR_AIGroup group)
static void GetGridPos(vector pos, out int gridX, out int gridZ, int resMin=2, int resMax=4)
void SetFaction(SCR_Faction faction)
void SetTaskPosition(vector taskPosition)
void SetFactionId(int factionId)
void SetTaskNotificationData(SCR_BaseTaskNotificationData data)
void SetTaskNotification(SCR_ETaskNotification type, SCR_ETaskNotificationMsg msg)
void SetBaseCallsign(int callsign)
void SetCalledGroupId(int groupId)
void SetGrid(int grid)
void SetCallerPlayerId(int callerPlayerId)
void SetCallerGroupId(int groupId)
proto external GenericEntity GetOwner()
Get owner entity.
void EOnInit(IEntity owner)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_EditableTaskComponentClass m_Task
Editable SCR_BaseTask.
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
proto external PlayerController GetPlayerController()