Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BaseTaskManager.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Tasks", description: "Entity that takes care of managing tasks.", color: "0 0 255 255")]
2 class SCR_BaseTaskManagerClass: GenericEntityClass
3 {
4 };
5 
8 {
10 };
11 
12 //------------------------------------------------------------------------------------------------
14 {
22 };
23 
24 //------------------------------------------------------------------------------------------------
26 {
27 
28 #ifdef ENABLE_DIAG
29  protected bool m_bPrintedTasks = false;
30 #endif
31  static const float DEFAULT_ABANDON_WAITING_TIME = 15;
32 
33  //**************************//
34  //PROTECTED MEMBER VARIABLES//
35  //**************************//
36  protected ref array<SCR_BaseTaskSupportEntity> m_aSupportedTaskTypes = {};
37 
38  [RplProp()]
39  protected float m_fTimestamp = 0;
40  protected float m_fTimestampTimer = 0;
41  protected ref array<SCR_BaseTask> m_aTaskList = new array<SCR_BaseTask>();
42  protected ref array<SCR_BaseTask> m_aFinishedTaskList = {};
43  protected ref array<ref SCR_TaskAssignmentData> m_aCachedTaskAssignments = new array<ref SCR_TaskAssignmentData>();
44 
45  [Attribute("1")]
46  protected float m_fAssigneeCacheTimer;
47 
48  [Attribute("#AR-Tasks_TitleLocalRequest-UC")]
49  string m_sLocalRequestTitle;
50 
51  [Attribute("#AR-Tasks_ReassignPopup")]
52  string m_sReassignPopup;
53 
54  [Attribute("#AR-Tasks_AssignPopupGM")]
55  string m_sAssignPopupGM;
56 
57  protected float m_fAssigneeCacheCheckTimestamp;
58  protected ref map<SCR_BaseTaskExecutor, float> m_mAssigneesAbandoned = new map<SCR_BaseTaskExecutor, float>();
59 
60  protected bool m_bInitialized = false;
61 
62  protected RplComponent m_RplComponent;
63 
64  ref map<SCR_BaseTask, SCR_ETaskEventMask> m_mTaskEventMaskMap = new map<SCR_BaseTask, SCR_ETaskEventMask>();
65 
66  protected ref array<SCR_BaseTask> m_aTasksToDelete = {};
67 
68  //*****************************//
69  //PUBLIC STATIC SCRIPT INVOKERS//
70  //*****************************//
71 
72  static ref ScriptInvoker s_OnTaskUpdate = new ScriptInvoker();
73  static ref ScriptInvoker s_OnTaskFinished = new ScriptInvoker();
74  static ref ScriptInvoker s_OnTaskFailed = new ScriptInvoker();
75  static ref ScriptInvoker s_OnTaskRemoved = new ScriptInvoker();
76  static ref ScriptInvoker s_OnTaskCancelled = new ScriptInvoker();
77 
78  static ref ScriptInvoker s_OnTaskAssigned = new ScriptInvoker();
79  static ref ScriptInvoker s_OnTaskUnassigned = new ScriptInvoker();
80 
81  static ref ScriptInvoker s_OnTaskFactionAssigned = new ScriptInvoker();
82 
83  static ref ScriptInvoker s_OnTaskCreated = new ScriptInvoker();
84  static ref ScriptInvoker s_OnTaskDeleted = new ScriptInvoker();
85 
86  static ref ScriptInvoker s_OnPeriodicalCheck2Second = new ScriptInvoker();
87  static ref ScriptInvoker s_OnPeriodicalCheck5Second = new ScriptInvoker();
88  static ref ScriptInvoker s_OnPeriodicalCheck60Second = new ScriptInvoker();
89 
90  //***************************//
91  //PUBLIC EVENT MEMBER METHODS//
92  //***************************//
93 
94  //------------------------------------------------------------------------------------------------
97  void OnPlayerDisconnected(int id)
98  {
99 #ifdef ENABLE_DIAG
100  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EXECUTE_TASKS))
101  return;
102 #endif
103 
104  SCR_BaseTaskExecutor executor = SCR_BaseTaskExecutor.GetTaskExecutorByID(id);
105  SCR_BaseTask task = null;
106  if (executor)
107  task = executor.GetAssignedTask();
108 
109  SCR_BaseTaskSupportEntity supportEntity = SCR_BaseTaskSupportEntity.Cast(FindSupportEntity(SCR_BaseTaskSupportEntity));
110  if (!supportEntity)
111  return;
112 
113  if (task)
114  supportEntity.UnassignTask(task, executor, SCR_EUnassignReason.ASSIGNEE_DISCONNECT);
115 
116  task = FindRequestedTask(executor);
117 
118  if (!task)
119  return;
120 
121  supportEntity.CancelTask(task.GetTaskID());
122  }
123 
124  //------------------------------------------------------------------------------------------------
126  void OnTaskDeleted(SCR_BaseTask task)
127  {
128  if (m_aTaskList.Contains(task))
129  m_aTaskList.RemoveItem(task);
130  }
131 
132  //------------------------------------------------------------------------------------------------
134  void OnTaskCreated(SCR_BaseTask task)
135  {
136  s_OnTaskFactionAssigned.Insert(RefreshTaskList);
137 
138  SCR_EditorTask editorTask = SCR_EditorTask.Cast(task);
139  if (!editorTask)
140  return;
141 
142  SCR_EditableDescriptorComponent editableDescriptor = SCR_EditableDescriptorComponent.Cast(editorTask.FindComponent(SCR_EditableDescriptorComponent));
143  if (!editableDescriptor)
144  return;
145 
146  editableDescriptor.GetOnChange().Insert(RefreshTaskListCommentComponent);
147  editableDescriptor.GetOnUIRefresh().Insert(RefreshTaskListVoid);
148  }
149 
150  //------------------------------------------------------------------------------------------------
151  private void RefreshTaskListCommentComponent(SCR_EditableCommentComponent editableCommentComponent)
152  {
153  RefreshTaskList();
154  }
155 
156  //------------------------------------------------------------------------------------------------
157  private void RefreshTaskListVoid()
158  {
159  RefreshTaskList();
160  }
161 
162  //------------------------------------------------------------------------------------------------
164  void RefreshTaskList(SCR_BaseTask task = null)
165  {
166  s_OnTaskFactionAssigned.Remove(RefreshTaskList);
167 
168  SCR_UITaskManagerComponent UItaskManager = SCR_UITaskManagerComponent.GetInstance();
169  if (!UItaskManager || !UItaskManager.IsTaskListOpen())
170  return;
171 
172  if (task)
173  {
174  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
175  if (!factionManager)
176  return;
177 
178  Faction taskTargetFaction = task.GetTargetFaction();
179  Faction playerFaction = factionManager.GetLocalPlayerFaction();
180  if (taskTargetFaction != playerFaction)
181  return;
182  }
183 
184  SCR_MapEntity mapEntity = SCR_MapEntity.GetMapInstance();
185  if (!mapEntity)
186  return;
187 
188  SCR_MapTaskListUI taskListUI = SCR_MapTaskListUI.Cast(mapEntity.GetMapUIComponent(SCR_MapTaskListUI));
189  if (taskListUI)
190  taskListUI.RefreshTaskList();
191  }
192 
193  //------------------------------------------------------------------------------------------------
195  void OnTaskFinished(SCR_BaseTask task)
196  {
197  if (!m_aFinishedTaskList.Contains(task))
198  m_aFinishedTaskList.Insert(task);
199 
200  OnTaskDeleted(task);
201  }
202 
203  //------------------------------------------------------------------------------------------------
205  void OnTaskUpdate(SCR_BaseTask task, SCR_ETaskEventMask mask)
206  {
207  if (m_mTaskEventMaskMap.Contains(task))
208  {
209  SCR_ETaskEventMask tempMask;
210  tempMask = m_mTaskEventMaskMap.Get(task); // returns mask for the task
211  tempMask = tempMask | mask;
212  m_mTaskEventMaskMap.Set(task, tempMask);
213  }
214  else
215  {
216  m_mTaskEventMaskMap.Insert(task, mask);
217  }
218  }
219 
220  //************************//
221  //PROTECTED MEMBER METHODS//
222  //************************//
223 
224  //------------------------------------------------------------------------------------------------
225  protected void PeriodicalCheck2Second()
226  {
227  s_OnPeriodicalCheck2Second.Invoke();
228  }
229 
230  //------------------------------------------------------------------------------------------------
231  protected void PeriodicalCheck5Second()
232  {
233  s_OnPeriodicalCheck5Second.Invoke();
234  }
235 
236  //------------------------------------------------------------------------------------------------
237  protected void PeriodicalCheck60Second()
238  {
239  s_OnPeriodicalCheck60Second.Invoke();
240  }
241 
242  //------------------------------------------------------------------------------------------------
243  protected SCR_EvacuateTask CreateNewEvacuationTask(int requesterID)
244  {
245  SCR_BaseTaskSupportEntity supportClass = GetTaskManager().FindSupportEntity(SCR_EvacuateTaskSupportEntity);
246  if (!supportClass)
247  return null;
248 
249  SCR_EvacuateTask evacuateTask = SCR_EvacuateTask.Cast(GetGame().SpawnEntityPrefab(supportClass.GetTaskPrefab(), GetWorld()));
250  if (!evacuateTask)
251  return null;
252 
253  SCR_BaseTaskExecutor requester = SCR_BaseTaskExecutor.GetTaskExecutorByID(requesterID);
254 
255  evacuateTask.SetRequester(requester);
256 
257  return evacuateTask;
258  }
259 
260  //------------------------------------------------------------------------------------------------
262  protected void CheckAssigneeTimeout()
263  {
264  foreach (SCR_BaseTask task : m_aTaskList)
265  {
266  if (task && task.IsIndividual())
267  task.CheckAssigneeTimeout();
268  }
269  }
270 
271  //*********************//
272  //PUBLIC MEMBER METHODS//
273  //*********************//
274 
275  //------------------------------------------------------------------------------------------------
276  string GetReassignText()
277  {
278  return m_sReassignPopup;
279  }
280 
281  //------------------------------------------------------------------------------------------------
282  void AddAssigneeAbandoned(SCR_BaseTaskExecutor assignee)
283  {
284  if (m_mAssigneesAbandoned)
285  m_mAssigneesAbandoned.Set(assignee, m_fTimestamp + DEFAULT_ABANDON_WAITING_TIME);
286  }
287 
288  //------------------------------------------------------------------------------------------------
291  bool IsProxy()
292  {
293  return (m_RplComponent && m_RplComponent.IsProxy());
294  }
295 
296  //------------------------------------------------------------------------------------------------
297  void UnregisterSupportEntity(SCR_BaseTaskSupportEntity supportEntity)
298  {
299  m_aSupportedTaskTypes.RemoveItem(supportEntity);
300  }
301 
302  //------------------------------------------------------------------------------------------------
303  void RegisterSupportEntity(SCR_BaseTaskSupportEntity supportEntity)
304  {
305  m_aSupportedTaskTypes.Insert(supportEntity);
306  supportEntity.Initialize();
307  }
308 
309  //------------------------------------------------------------------------------------------------
311  SCR_BaseTask GetTask(int taskID)
312  {
313  if (taskID == -1)
314  return null;
315 
316  foreach (SCR_BaseTask task : m_aTaskList)
317  {
318  if (task.GetTaskID() == taskID)
319  {
320  return task;
321  }
322  }
323 
324  return null;
325  }
326 
327  //------------------------------------------------------------------------------------------------
329  void RegisterTask(SCR_BaseTask task)
330  {
331  if (task.GetTaskState() == SCR_TaskState.OPENED && !m_aTaskList.Contains(task))
332  m_aTaskList.Insert(task);
333 
334  if (task.GetTaskState() == SCR_TaskState.FINISHED && !m_aFinishedTaskList.Contains(task))
335  {
336  m_aFinishedTaskList.Insert(task);
337  m_aTaskList.RemoveItem(task);
338  }
339  }
340 
341  //------------------------------------------------------------------------------------------------
343  SCR_BaseTask GetFinishedTask(int taskID)
344  {
345  if (taskID == -1)
346  return null;
347 
348  foreach (SCR_BaseTask task : m_aFinishedTaskList)
349  {
350  if (task.GetTaskID() == taskID)
351  {
352  return task;
353  }
354  }
355 
356  return null;
357  }
358 
359  #ifdef ENABLE_DIAG
360  //------------------------------------------------------------------------------------------------
361  bool CheckMasterOnlyMethod(string methodName)
362  {
363  if (IsProxy())
364  {
365  Print("Master-only method (SCR_BaseTaskManager." + methodName + ") called on proxy, some functionality might be broken!", LogLevel.WARNING);
366  return false;
367  }
368 
369  return true;
370  }
371  #endif
372 
373  //------------------------------------------------------------------------------------------------
374  bool HasRequestedTask(int playerID)
375  {
376  SCR_BaseTaskExecutor executor = SCR_BaseTaskExecutor.GetTaskExecutorByID(playerID);
377  if (!executor)
378  return true;
379 
380  return GetTaskManager().FindRequestedTask(executor) != null;
381  }
382 
383  //------------------------------------------------------------------------------------------------
384  bool Initialized()
385  {
386  return m_bInitialized;
387  }
388 
389  //------------------------------------------------------------------------------------------------
390  void DeleteTask(SCR_BaseTask task)
391  {
392  if (m_aTasksToDelete.Contains(task))
393  return;
394 
395  m_aTasksToDelete.Insert(task);
396  task.OnDelete();
397  }
398 
399  //------------------------------------------------------------------------------------------------
400  SCR_BaseTaskSupportEntity FindSupportEntity(typename type)
401  {
402  if (!m_aSupportedTaskTypes)
403  return null;
404 
405  for (int i = m_aSupportedTaskTypes.Count() - 1; i >= 0; i--)
406  {
407  if (type == m_aSupportedTaskTypes[i].Type())
408  return m_aSupportedTaskTypes[i];
409  }
410 
411  return null;
412  }
413 
414  //------------------------------------------------------------------------------------------------
415  //Returns the list of all supported task types
416  //Used f.e. for request buttons in task list, which is temporarily disabled
417  array<SCR_BaseTaskSupportEntity> GetSupportedTasks()
418  {
419  return m_aSupportedTaskTypes;
420  }
421 
422  //------------------------------------------------------------------------------------------------
423  notnull SCR_BaseTaskExecutor LocalCreateTaskExecutor(int playerID)
424  {
425  SCR_BaseTaskExecutor executor = SCR_BaseTaskExecutor.FindTaskExecutorByID(playerID);
426  if (executor)
427  return executor;
428 
429  executor = SCR_BaseTaskExecutor.Cast(GetGame().SpawnEntity(SCR_BaseTaskExecutor, GetGame().GetWorld()));
430  executor.SetPlayerID(playerID);
431 
432  return executor;
433  }
434 
435  //------------------------------------------------------------------------------------------------
436  SCR_RequestedTask FindRequestedTask(SCR_BaseTaskExecutor requester)
437  {
438  for (int i = 0; i < m_aTaskList.Count(); i++)
439  {
440  SCR_RequestedTask requestedTask = SCR_RequestedTask.Cast(m_aTaskList[i]);
441  if (!requestedTask)
442  continue;
443 
444  SCR_BaseTaskExecutor taskRequester = requestedTask.GetRequester();
445  if (requester == taskRequester)
446  return requestedTask;
447  }
448 
449  return null;
450  }
451 
452  //------------------------------------------------------------------------------------------------
455  int GetFilteredTasks(notnull out array<SCR_BaseTask> tasks, Faction filterFaction = null)
456  {
457  int count = 0;
458  tasks.Clear();
459 
460  if (!filterFaction)
461  return GetTasks(tasks);
462 
463  Faction taskFaction;
464  foreach (SCR_BaseTask task : m_aTaskList)
465  {
466  taskFaction = task.GetTargetFaction();
467  if (!taskFaction || taskFaction == filterFaction)
468  {
469  tasks.Insert(task);
470  count++;
471  }
472  }
473 
474  return count;
475  }
476 
477  //------------------------------------------------------------------------------------------------
480  int GetFilteredFinishedTasks(notnull out array<SCR_BaseTask> tasks, Faction filterFaction = null)
481  {
482  int count = 0;
483  tasks.Clear();
484 
485  if (!filterFaction)
486  return GetTasks(tasks);
487 
488  Faction taskFaction;
489  foreach (SCR_BaseTask task : m_aFinishedTaskList)
490  {
491  taskFaction = task.GetTargetFaction();
492  if (!taskFaction || taskFaction == filterFaction)
493  {
494  tasks.Insert(task);
495  count++;
496  }
497  }
498 
499  return count;
500  }
501 
502  //------------------------------------------------------------------------------------------------
503  bool GetAssigneeAbandoned(SCR_BaseTaskExecutor assignee)
504  {
505  if (!m_mAssigneesAbandoned || !assignee)
506  return false;
507 
508  float timestamp = m_mAssigneesAbandoned.Get(assignee);
509 
510  if (m_fTimestamp < timestamp)
511  return true;
512 
513  return false;
514  }
515 
516  //------------------------------------------------------------------------------------------------
517  //This should only be called on the server!
518  void AbandonTask(int taskID, notnull SCR_BaseTaskExecutor assignee)
519  {
520  #ifdef ENABLE_DIAG
521  if (!CheckMasterOnlyMethod("AbandonTask()"))
522  return;
523  #endif
524 
525  SCR_BaseTask task = GetTask(taskID);
526 
527  if (!task)
528  return;
529 
530  if (task.NotifyUnassign())
531  task.DoNotifyUnassign(SCR_BaseTaskExecutor.GetTaskExecutorID(assignee));
532 
533  SCR_BaseTaskSupportEntity supportEntity = SCR_BaseTaskSupportEntity.Cast(FindSupportEntity(SCR_BaseTaskSupportEntity));
534  if (!supportEntity)
535  return;
536 
537  supportEntity.UnassignTask(task, assignee, SCR_EUnassignReason.ASSIGNEE_ABANDON);
538  }
539 
540  //------------------------------------------------------------------------------------------------
542  void RequestAssignment(int taskID, notnull SCR_BaseTaskExecutor assignee)
543  {
544  if (!assignee || IsProxy())
545  return;
546 
547  SCR_BaseTask task = GetTask(taskID);
548 
549  if (!task)
550  return;
551 
552  if (task.NotifyAssignment())
553  task.DoNotifyAssignment(SCR_BaseTaskExecutor.GetTaskExecutorID(assignee));
554 
556  if (!supportEntity)
557  return;
558 
559  supportEntity.AssignTask(task, assignee);
560  }
561 
562  //------------------------------------------------------------------------------------------------
563  void OnPlayerRegistered(int registeredPlayerID)
564  {
565  if (registeredPlayerID == SCR_PlayerController.GetLocalPlayerId())
566  CreateTaskExecutors();
567  else
568  LocalCreateTaskExecutor(registeredPlayerID);
569  }
570 
571  //------------------------------------------------------------------------------------------------
573  void CreateTaskExecutors()
574  {
575  array<int> players = new array<int>();
576  GetGame().GetPlayerManager().GetPlayers(players);
577 
578  foreach (int playerID : players)
579  {
580  if (SCR_BaseTaskExecutor.GetTaskExecutorByID(playerID))
581  continue;
582 
583  LocalCreateTaskExecutor(playerID);
584  }
585  }
586 
587  //------------------------------------------------------------------------------------------------
589  float GetTimestamp()
590  {
591  return m_fTimestamp;
592  }
593 
594  //------------------------------------------------------------------------------------------------
596  int GetTasks(notnull out array<SCR_BaseTask> tasks)
597  {
598  int count = 0;
599 
600  foreach (SCR_BaseTask task : m_aTaskList)
601  {
602  tasks.Insert(task);
603  count++;
604  }
605 
606  return count;
607  }
608 
609  //------------------------------------------------------------------------------------------------
611  int GetFinishedTasks(notnull out array<SCR_BaseTask> tasks)
612  {
613  int count = 0;
614 
615  foreach (SCR_BaseTask task : m_aFinishedTaskList)
616  {
617  tasks.Insert(task);
618  count++;
619  }
620 
621  return count;
622  }
623 
624  //------------------------------------------------------------------------------------------------
627  SCR_BaseTask LocalSpawnTask(ResourceName resourceName)
628  {
629  if (resourceName.IsEmpty())
630  return null;
631 
632  Resource resource = Resource.Load(resourceName);
633  if (!resource.IsValid())
634  return null;
635 
636  return SCR_BaseTask.Cast(GetGame().SpawnEntityPrefab(resource, GetWorld()));
637  }
638 
639  //------------------------------------------------------------------------------------------------
641  SCR_BaseTask SpawnTask(ResourceName resourceName)
642  {
643  SCR_BaseTask task = LocalSpawnTask(resourceName);
644  if (!task)
645  return null;
646 
647  Rpc(RPC_SpawnTask, resourceName, task.GetTaskID());
648 
649  return task;
650  }
651 
652  //***********//
653  //RPC METHODS//
654  //***********//
655 
656  //------------------------------------------------------------------------------------------------
659  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
660  protected void RPC_SpawnTask(ResourceName resourceName, int taskID)
661  {
662  SCR_BaseTask task = LocalSpawnTask(resourceName);
663  if (!task)
664  return;
665 
666  task.SetTaskID(taskID);
667  }
668 
669  //*************//
670  //ENTITY EVENTS//
671  //*************//
672 
673  //------------------------------------------------------------------------------------------------
674  protected override void EOnInit(IEntity owner)
675  {
676  m_bInitialized = true;
677 
679  if (gameMode)
680  gameMode.GetOnPlayerRegistered().Insert(OnPlayerRegistered);
681 
682  // If replicated make sure it never streams out
683  auto rplComponent = RplComponent.Cast(FindComponent(RplComponent));
684  if (rplComponent && rplComponent.IsSelfInserted())
685  {
686  auto ctx = new GameRplSchedulerInsertionCtx;
687  ctx.CanBeStreamed = false;
688  rplComponent.InsertToReplication(ctx);
689  }
690 
691  m_RplComponent = RplComponent.Cast(FindComponent(RplComponent));
692 
693  // This is for individual tasks, so they don't have to tick their own timers, but it's centralized on the task manager.
694  // This could be further improved for more custom timers, but for now it is sufficient as is.
695  GetGame().GetCallqueue().CallLater(PeriodicalCheck2Second, 2000, true);
696  GetGame().GetCallqueue().CallLater(PeriodicalCheck5Second, 5000, true);
697  GetGame().GetCallqueue().CallLater(PeriodicalCheck60Second, 60000, true);
698  }
699  //------------------------------------------------------------------------------------------------
700  void UpdateTasks()
701  {
702  SCR_BaseTask task;
703  SCR_ETaskEventMask mask;
704 
705  for (int i = m_mTaskEventMaskMap.Count() - 1; i >= 0; i--)
706  {
707  task = m_mTaskEventMaskMap.GetKey(i);
708  mask = m_mTaskEventMaskMap.Get(task);
709  s_OnTaskUpdate.Invoke(task, mask);
710  }
711 
712  m_mTaskEventMaskMap.Clear();
713 
714  foreach (SCR_BaseTask taskToDelete : m_aTasksToDelete)
715  {
716  if (!taskToDelete)
717  continue;
718 
719  IEntity taskChild = taskToDelete.GetChildren();
720  while (taskChild)
721  {
722  IEntity childToDelete = taskChild;
723  taskChild = taskChild.GetSibling();
724 
725  delete childToDelete;
726  }
727 
728  m_aTaskList.RemoveItem(taskToDelete);
729  delete taskToDelete;
730  }
731 
732  for (int i = m_aFinishedTaskList.Count() - 1; i >= 0; i--)
733  {
734  if (!m_aFinishedTaskList[i])
735  m_aFinishedTaskList.Remove(i);
736  }
737 
738  m_aTasksToDelete.Clear();
739  }
740  //------------------------------------------------------------------------------------------------
741  protected override void EOnFrame(IEntity owner, float timeSlice)
742  {
743  if (GetTaskManager() && GetTaskManager() != this)
744  {
745  delete this;
746  return;
747  }
748 
749  if (!m_mTaskEventMaskMap.IsEmpty())
750  UpdateTasks();
751 #ifdef ENABLE_DIAG
752  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_SHOW_ALL_TASKS))
753  {
754  if (!m_bPrintedTasks)
755  {
756  m_bPrintedTasks = true;
757  for (int i = m_aTaskList.Count() - 1; i >= 0; i--)
758  {
759  Print(m_aTaskList[i].GetDescription());
760  }
761  }
762  }
763  else
764  m_bPrintedTasks = false;
765 
766  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EXECUTE_TASKS))
767  return;
768 #endif
769 
770  m_fTimestamp += timeSlice;
771  m_fTimestampTimer -= timeSlice;
772  if (m_fTimestampTimer <= 0)
773  {
774  Replication.BumpMe();
775  m_fTimestampTimer = 1;
776  }
777 
778  if (!IsProxy() && m_fTimestamp > m_fAssigneeCacheCheckTimestamp)
779  {
780  m_fAssigneeCacheCheckTimestamp = m_fTimestamp + m_fAssigneeCacheTimer;
781  CheckAssigneeTimeout();
782  }
783  }
784 
785  //***********//
786  //JIP METHODS//
787  //***********//
788 
789  //------------------------------------------------------------------------------------------------
790  void SaveTasksForRpl(ScriptBitWriter writer, array<SCR_BaseTask> taskArray)
791  {
792  int count = taskArray.Count();
793  writer.WriteInt(count);
794 
795  for (int i = 0; i < count; i++)
796  {
797  SCR_BaseTask task = taskArray[i];
798  if (!task || task.FindComponent(RplComponent)) //--- Assume that tasks with their own replication will sync data themselves
799  {
800  writer.WriteBool(false);
801  continue;
802  }
803 
804  writer.WriteBool(true);
805 
806  EntityPrefabData prefabData = task.GetPrefabData();
807  ResourceName resourceName;
808  if (prefabData)
809  resourceName = prefabData.GetPrefabName();
810 
811  writer.WriteResourceName(prefabData.GetPrefabName()); //Write prefab, then read it in load & spawn correct task
812 
813  task.Serialize(writer);
814  }
815  }
816 
817  //------------------------------------------------------------------------------------------------
818  override bool RplSave(ScriptBitWriter writer)
819  {
820 
821  SaveTasksForRpl(writer, m_aTaskList);
822  SaveTasksForRpl(writer, m_aFinishedTaskList);
823 
824  return true;
825  }
826 
827  //------------------------------------------------------------------------------------------------
828  void LoadTasksForRpl(ScriptBitReader reader, int count)
829  {
830  reader.ReadInt(count);
831 
832  ResourceName resourceName;
833  Resource resource;
834  SCR_BaseTask task;
835  bool readTask;
836  for (int i = 0; i < count; i++)
837  {
838  reader.ReadBool(readTask);
839  if (!readTask)
840  continue;
841 
842  reader.ReadResourceName(resourceName);
843 
844  resource = Resource.Load(resourceName);
845  if (!resource.IsValid())
846  continue;
847 
848  task = SCR_BaseTask.Cast(GetGame().SpawnEntityPrefab(resource, GetWorld()));
849  if (!task)
850  continue;
851 
852  task.Deserialize(reader);
853  }
854  }
855 
856  //------------------------------------------------------------------------------------------------
857  override bool RplLoad(ScriptBitReader reader)
858  {
859  int count;
860  LoadTasksForRpl(reader, count);
861  LoadTasksForRpl(reader, count);
862 
863  //Let the game mode know, the tasks are ready
865  if (gamemode)
866  gamemode.HandleOnTasksInitialized();
867 
868  //AssignCachedTasks();
869 
870  return true;
871  }
872 
873  //************************//
874  //CONSTRUCTOR & DESTRUCTOR//
875  //************************//
876 
877  //------------------------------------------------------------------------------------------------
878  void SCR_BaseTaskManager(IEntitySource src, IEntity parent)
879  {
881  g_TaskManagerInstance = this;
882 
883 #ifdef ENABLE_DIAG
884  DiagMenu.RegisterMenu(SCR_DebugMenuID.DEBUGUI_TASKS_MENU, "Tasks", "");
885  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EXECUTE_TASKS, "", "Execute tasks", "Tasks", true);
886  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_SHOW_ALL_TASKS, "", "Print all tasks", "Tasks", false);
887 #endif
888  SetEventMask(EntityEvent.FRAME | EntityEvent.INIT);
889  SetFlags(EntityFlags.NO_LINK, false);
890 
891  //Register to Script Invokers
892  s_OnTaskCreated.Insert(OnTaskCreated);
893  s_OnTaskFinished.Insert(OnTaskFinished);
894  s_OnTaskDeleted.Insert(OnTaskDeleted);
895  }
896 
897  //------------------------------------------------------------------------------------------------
898  void ~SCR_BaseTaskManager()
899  {
900 
901  //Unregister from Script Invokers
902  s_OnTaskCreated.Remove(OnTaskCreated);
903  s_OnTaskFinished.Remove(OnTaskFinished);
904  s_OnTaskDeleted.Remove(OnTaskDeleted);
905  }
906 };
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
SpawnEntity
protected IEntity SpawnEntity(ResourceName entityResourceName, notnull IEntity slotOwner)
Definition: SCR_CatalogEntitySpawnerComponent.c:1008
SCR_PlayerController
Definition: SCR_PlayerController.c:31
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
TASK_PROPERTY_CHANGED
@ TASK_PROPERTY_CHANGED
Definition: SCR_BaseTaskManager.c:17
GameRplSchedulerInsertionCtx
Definition: GameRplScheduler.c:1
RplProp
SCR_RplTestEntityClass RplProp
Used for handling entity spawning requests for SCR_CatalogEntitySpawnerComponent and inherited classe...
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_BaseTask
A base class for tasks.
Definition: SCR_BaseTask.c:8
TASK_FINISHED
@ TASK_FINISHED
Definition: SCR_BaseTaskManager.c:19
SCR_EvacuateTask
Definition: SCR_EvacuateTask.c:7
SCR_UITaskManagerComponent
void SCR_UITaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_UITaskManagerComponent.c:1096
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
TASK_CREATED
@ TASK_CREATED
Definition: SCR_BaseTaskManager.c:15
g_TaskManagerInstance
SCR_BaseTaskManager g_TaskManagerInstance
Definition: SCR_BaseTaskManager.c:6
SCR_BaseTaskManagerClass
Definition: SCR_BaseTaskManager.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
TASK_FAILED
@ TASK_FAILED
Definition: SCR_BaseTaskManager.c:20
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
SCR_BaseTaskManager
Definition: SCR_BaseTaskManager.c:25
SCR_EditorTask
Definition: SCR_EditorTask.c:7
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
SCR_MapTaskListUI
Definition: SCR_MapTaskListUI.c:1
SCR_EvacuateTaskSupportEntity
Definition: SCR_EvacuateTaskSupportEntity.c:8
SCR_BaseTaskSupportEntity
Definition: SCR_BaseTaskSupportEntity.c:8
Faction
Definition: Faction.c:12
SCR_BaseTaskExecutor
Definition: SCR_BaseTaskExecutor.c:7
m_RplComponent
protected RplComponent m_RplComponent
Definition: SCR_CampaignBuildingManagerComponent.c:42
SCR_ETaskEventMask
SCR_ETaskEventMask
Definition: SCR_BaseTaskManager.c:13
m_fTimestamp
float m_fTimestamp
Definition: SCR_AITargetInfo.c:22
SCR_TaskState
SCR_TaskState
Definition: SCR_TaskState.c:2
TASK_ASSIGNEE_CHANGED
@ TASK_ASSIGNEE_CHANGED
Definition: SCR_BaseTaskManager.c:18
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
SCR_RequestedTask
Definition: SCR_RequestedTask.c:8
SCR_EditableDescriptorComponent
void SCR_EditableDescriptorComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_EditableDescriptorComponent.c:137
TASK_CANCELED
@ TASK_CANCELED
Definition: SCR_BaseTaskManager.c:16
TASK_REMOVED
@ TASK_REMOVED
Definition: SCR_BaseTaskManager.c:21
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
m_bInitialized
protected bool m_bInitialized
Definition: SCR_CampaignMilitaryBaseComponent.c:122
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180