Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
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
//
6
//SCR_BaseTaskManager g_TaskManagerInstance;
7
//SCR_BaseTaskManager GetTaskManager()
8
//{
9
// return g_TaskManagerInstance;
10
//};
11
//
13
//enum SCR_ETaskEventMask
14
//{
15
// TASK_CREATED = 1,
16
// TASK_CANCELED = 2,
17
// TASK_PROPERTY_CHANGED = 4,
18
// TASK_ASSIGNEE_CHANGED = 8,
19
// TASK_FINISHED = 16,
20
// TASK_FAILED = 32,
21
// TASK_REMOVED = 64,
22
//};
23
//
25
//class SCR_BaseTaskManager : GenericEntity
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_Task> m_aTaskList = new array<SCR_Task>();
42
// protected ref array<SCR_Task> 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
// //------------------------------------------------------------------------------------------------
95
// //! An event called when a player disconnects
96
// //! Server only
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 = 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
// //------------------------------------------------------------------------------------------------
125
// //! An event called when a task is deleted.
126
// void OnTaskDeleted(SCR_Task task)
127
// {
128
// if (m_aTaskList.Contains(task))
129
// m_aTaskList.RemoveItem(task);
130
// }
131
//
132
// //------------------------------------------------------------------------------------------------
133
// //! An event called when a new task is created.
134
// void OnTaskCreated(SCR_Task 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
// //------------------------------------------------------------------------------------------------
163
// //! Refresh task list.
164
// [Obsolete("Use new SCR_TaskManagerUIComponent methods instead")]
165
// void RefreshTaskList(SCR_BaseTask task = null)
166
// {
167
// s_OnTaskFactionAssigned.Remove(RefreshTaskList);
168
//
169
// SCR_TaskManagerUIComponent UItaskManager = SCR_TaskManagerUIComponent.GetInstance();
170
// if (!UItaskManager || !UItaskManager.IsTaskListOpen())
171
// return;
172
//
173
// if (task)
174
// {
175
// SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
176
// if (!factionManager)
177
// return;
178
//
179
// Faction taskTargetFaction = task.GetTargetFaction();
180
// Faction playerFaction = factionManager.GetLocalPlayerFaction();
181
// if (taskTargetFaction != playerFaction)
182
// return;
183
// }
184
//
185
// /*
186
// SCR_MapEntity mapEntity = SCR_MapEntity.GetMapInstance();
187
// if (!mapEntity)
188
// return;
189
//
190
// SCR_MapTaskListUI taskListUI = SCR_MapTaskListUI.Cast(mapEntity.GetMapUIComponent(SCR_MapTaskListUI));
191
// if (taskListUI)
192
// taskListUI.RefreshTaskList();
193
// */
194
// }
195
//
196
// //------------------------------------------------------------------------------------------------
197
// //! An event called when a task is finished.
198
// void OnTaskFinished(SCR_Task task)
199
// {
200
// if (!m_aFinishedTaskList.Contains(task))
201
// m_aFinishedTaskList.Insert(task);
202
//
203
// OnTaskDeleted(task);
204
// }
205
//
206
// //------------------------------------------------------------------------------------------------
207
// //! An event called whenever any task has been changed, updated, created.
208
// void OnTaskUpdate(SCR_Task task, SCR_ETaskEventMask mask)
209
// {
210
// if (m_mTaskEventMaskMap.Contains(task))
211
// {
212
// SCR_ETaskEventMask tempMask;
213
// tempMask = m_mTaskEventMaskMap.Get(task); // returns mask for the task
214
// tempMask = tempMask | mask;
215
// m_mTaskEventMaskMap.Set(task, tempMask);
216
// }
217
// else
218
// {
219
// m_mTaskEventMaskMap.Insert(task, mask);
220
// }
221
// }
222
//
223
// //************************//
224
// //PROTECTED MEMBER METHODS//
225
// //************************//
226
//
227
// //------------------------------------------------------------------------------------------------
228
// protected void PeriodicalCheck2Second()
229
// {
230
// s_OnPeriodicalCheck2Second.Invoke();
231
// }
232
//
233
// //------------------------------------------------------------------------------------------------
234
// protected void PeriodicalCheck5Second()
235
// {
236
// s_OnPeriodicalCheck5Second.Invoke();
237
// }
238
//
239
// //------------------------------------------------------------------------------------------------
240
// protected void PeriodicalCheck60Second()
241
// {
242
// s_OnPeriodicalCheck60Second.Invoke();
243
// }
244
//
245
// //------------------------------------------------------------------------------------------------
246
// protected SCR_EvacuateTask CreateNewEvacuationTask(int requesterID)
247
// {
248
// SCR_BaseTaskSupportEntity supportClass = GetTaskManager().FindSupportEntity(SCR_EvacuateTaskSupportEntity);
249
// if (!supportClass)
250
// return null;
251
//
252
// SCR_EvacuateTask evacuateTask = SCR_EvacuateTask.Cast(GetGame().SpawnEntityPrefab(supportClass.GetTaskPrefab(), GetWorld()));
253
// if (!evacuateTask)
254
// return null;
255
//
256
// SCR_BaseTaskExecutor requester = SCR_BaseTaskExecutor.GetTaskExecutorByID(requesterID);
257
//
258
// evacuateTask.SetRequester(requester);
259
//
260
// return evacuateTask;
261
// }
262
//
263
// //------------------------------------------------------------------------------------------------
264
// //! Checks every task for assignee timeout
265
// protected void CheckAssigneeTimeout()
266
// {
267
// foreach (SCR_BaseTask task : m_aTaskList)
268
// {
269
// if (task && task.IsIndividual())
270
// task.CheckAssigneeTimeout();
271
// }
272
// }
273
//
274
// //*********************//
275
// //PUBLIC MEMBER METHODS//
276
// //*********************//
277
//
278
// //------------------------------------------------------------------------------------------------
279
// string GetReassignText()
280
// {
281
// return m_sReassignPopup;
282
// }
283
//
284
// //------------------------------------------------------------------------------------------------
285
// void AddAssigneeAbandoned(SCR_BaseTaskExecutor assignee)
286
// {
287
// if (m_mAssigneesAbandoned)
288
// m_mAssigneesAbandoned.Set(assignee, m_fTimestamp + DEFAULT_ABANDON_WAITING_TIME);
289
// }
290
//
291
// //------------------------------------------------------------------------------------------------
292
// //! Checks if this entity is locally owned
293
// //! Public because it's also used by tasks as they don't have any RplComponents themselves
294
// bool IsProxy()
295
// {
296
// return (m_RplComponent && m_RplComponent.IsProxy());
297
// }
298
//
299
// //------------------------------------------------------------------------------------------------
300
// void UnregisterSupportEntity(SCR_BaseTaskSupportEntity supportEntity)
301
// {
302
// m_aSupportedTaskTypes.RemoveItem(supportEntity);
303
// }
304
//
305
// //------------------------------------------------------------------------------------------------
306
// void RegisterSupportEntity(SCR_BaseTaskSupportEntity supportEntity)
307
// {
308
// m_aSupportedTaskTypes.Insert(supportEntity);
309
// supportEntity.Initialize();
310
// }
311
//
312
// //------------------------------------------------------------------------------------------------
313
// //! Returns the found task if it exists.
314
// SCR_BaseTask GetTask(int taskID)
315
// {
316
// if (taskID == -1)
317
// return null;
318
//
319
// foreach (SCR_BaseTask task : m_aTaskList)
320
// {
321
// if (task.GetTaskID() == taskID)
322
// return task;
323
// }
324
//
325
// foreach (SCR_BaseTask finishedTask : m_aFinishedTaskList)
326
// {
327
// if (finishedTask.GetTaskID() == taskID)
328
// return finishedTask;
329
// }
330
//
331
// return null;
332
// }
333
//
334
// //------------------------------------------------------------------------------------------------
335
// //! Registers Tasks and based on their State it inserts them to proper list.
336
// void RegisterTask(SCR_BaseTask task)
337
// {
338
// if (task.GetTaskState() == SCR_TaskState.OPENED && !m_aTaskList.Contains(task))
339
// m_aTaskList.Insert(task);
340
//
341
// if (task.GetTaskState() == SCR_TaskState.FINISHED && !m_aFinishedTaskList.Contains(task))
342
// {
343
// m_aFinishedTaskList.Insert(task);
344
// m_aTaskList.RemoveItem(task);
345
// }
346
// }
347
//
348
// //------------------------------------------------------------------------------------------------
349
// //! Returns the found finished task if it exists.
350
// SCR_BaseTask GetFinishedTask(int taskID)
351
// {
352
// if (taskID == -1)
353
// return null;
354
//
355
// foreach (SCR_BaseTask task : m_aFinishedTaskList)
356
// {
357
// if (task.GetTaskID() == taskID)
358
// {
359
// return task;
360
// }
361
// }
362
//
363
// return null;
364
// }
365
//
366
// #ifdef ENABLE_DIAG
367
// //------------------------------------------------------------------------------------------------
368
// bool CheckMasterOnlyMethod(string methodName)
369
// {
370
// if (IsProxy())
371
// {
372
// Print("Master-only method (SCR_BaseTaskManager." + methodName + ") called on proxy, some functionality might be broken!", LogLevel.WARNING);
373
// return false;
374
// }
375
//
376
// return true;
377
// }
378
// #endif
379
//
380
// //------------------------------------------------------------------------------------------------
381
// bool HasRequestedTask(int playerID)
382
// {
383
// SCR_BaseTaskExecutor executor = SCR_BaseTaskExecutor.GetTaskExecutorByID(playerID);
384
// if (!executor)
385
// return true;
386
//
387
// return GetTaskManager().FindRequestedTask(executor) != null;
388
// }
389
//
390
// //------------------------------------------------------------------------------------------------
391
// bool Initialized()
392
// {
393
// return m_bInitialized;
394
// }
395
//
396
// //------------------------------------------------------------------------------------------------
397
// void DeleteTask(SCR_BaseTask task)
398
// {
399
// if (m_aTasksToDelete.Contains(task))
400
// return;
401
//
402
// m_aTasksToDelete.Insert(task);
403
// task.OnDelete();
404
// }
405
//
406
// //------------------------------------------------------------------------------------------------
407
// SCR_BaseTaskSupportEntity FindSupportEntity(typename type)
408
// {
409
// if (!m_aSupportedTaskTypes)
410
// return null;
411
//
412
// for (int i = m_aSupportedTaskTypes.Count() - 1; i >= 0; i--)
413
// {
414
// if (type == m_aSupportedTaskTypes[i].Type())
415
// return m_aSupportedTaskTypes[i];
416
// }
417
//
418
// return null;
419
// }
420
//
421
// //------------------------------------------------------------------------------------------------
422
// //Returns the list of all supported task types
423
// //Used f.e. for request buttons in task list, which is temporarily disabled
424
// array<SCR_BaseTaskSupportEntity> GetSupportedTasks()
425
// {
426
// return m_aSupportedTaskTypes;
427
// }
428
//
429
// //------------------------------------------------------------------------------------------------
430
// notnull SCR_BaseTaskExecutor LocalCreateTaskExecutor(int playerID)
431
// {
432
// SCR_BaseTaskExecutor executor = SCR_BaseTaskExecutor.FindTaskExecutorByID(playerID);
433
// if (executor)
434
// return executor;
435
//
436
// executor = SCR_BaseTaskExecutor.Cast(GetGame().SpawnEntity(SCR_BaseTaskExecutor, GetGame().GetWorld()));
437
// executor.SetPlayerID(playerID);
438
//
439
// return executor;
440
// }
441
//
442
// //------------------------------------------------------------------------------------------------
443
// SCR_RequestedTask FindRequestedTask(SCR_BaseTaskExecutor requester)
444
// {
445
// for (int i = 0; i < m_aTaskList.Count(); i++)
446
// {
447
// SCR_RequestedTask requestedTask = SCR_RequestedTask.Cast(m_aTaskList[i]);
448
// if (!requestedTask)
449
// continue;
450
//
451
// SCR_BaseTaskExecutor taskRequester = requestedTask.GetRequester();
452
// if (requester == taskRequester)
453
// return requestedTask;
454
// }
455
//
456
// return null;
457
// }
458
//
459
// //------------------------------------------------------------------------------------------------
460
// //! Outs an array of tasks filtered by faction.
461
// //! filterFaction param is the allowed faction!
462
// int GetFilteredTasks(notnull out array<SCR_BaseTask> tasks, Faction filterFaction = null)
463
// {
464
// int count = 0;
465
// tasks.Clear();
466
//
467
// if (!filterFaction)
468
// return GetTasks(tasks);
469
//
470
// Faction taskFaction;
471
// foreach (SCR_BaseTask task : m_aTaskList)
472
// {
473
// if (!task) //--- TODO: this runs before the task is deleted, should not
474
// continue;
475
//
476
// taskFaction = task.GetTargetFaction();
477
// if (!taskFaction || taskFaction == filterFaction)
478
// {
479
// tasks.Insert(task);
480
// count++;
481
// }
482
// }
483
//
484
// return count;
485
// }
486
//
487
// //------------------------------------------------------------------------------------------------
488
// //! Outs an array of tasks filtered by faction.
489
// //! filterFaction param is the allowed faction!
490
// int GetFilteredFinishedTasks(notnull out array<SCR_BaseTask> tasks, Faction filterFaction = null)
491
// {
492
// int count = 0;
493
// tasks.Clear();
494
//
495
// if (!filterFaction)
496
// return GetTasks(tasks);
497
//
498
// Faction taskFaction;
499
// foreach (SCR_BaseTask task : m_aFinishedTaskList)
500
// {
501
// taskFaction = task.GetTargetFaction();
502
// if (!taskFaction || taskFaction == filterFaction)
503
// {
504
// tasks.Insert(task);
505
// count++;
506
// }
507
// }
508
//
509
// return count;
510
// }
511
//
512
// //------------------------------------------------------------------------------------------------
513
// bool GetAssigneeAbandoned(SCR_BaseTaskExecutor assignee)
514
// {
515
// if (!m_mAssigneesAbandoned || !assignee)
516
// return false;
517
//
518
// float timestamp = m_mAssigneesAbandoned.Get(assignee);
519
//
520
// if (m_fTimestamp < timestamp)
521
// return true;
522
//
523
// return false;
524
// }
525
//
526
// //------------------------------------------------------------------------------------------------
527
// //This should only be called on the server!
528
// void AbandonTask(int taskID, notnull SCR_BaseTaskExecutor assignee)
529
// {
530
// #ifdef ENABLE_DIAG
531
// if (!CheckMasterOnlyMethod("AbandonTask()"))
532
// return;
533
// #endif
534
//
535
// SCR_BaseTask task = GetTask(taskID);
536
//
537
// if (!task)
538
// return;
539
//
540
// if (task.NotifyUnassign())
541
// task.DoNotifyUnassign(SCR_BaseTaskExecutor.GetTaskExecutorID(assignee));
542
//
543
// SCR_BaseTaskSupportEntity supportEntity = FindSupportEntity(SCR_BaseTaskSupportEntity);
544
// if (!supportEntity)
545
// return;
546
//
547
// supportEntity.UnassignTask(task, assignee, SCR_EUnassignReason.ASSIGNEE_ABANDON);
548
// }
549
//
550
// //------------------------------------------------------------------------------------------------
551
// //! Used for assigning the task with given task ID to the assignee in parameter
552
// void RequestAssignment(int taskID, notnull SCR_BaseTaskExecutor assignee)
553
// {
554
// if (!assignee || IsProxy())
555
// return;
556
//
557
// SCR_BaseTask task = GetTask(taskID);
558
//
559
// if (!task)
560
// return;
561
//
562
// if (task.NotifyAssignment())
563
// task.DoNotifyAssignment(SCR_BaseTaskExecutor.GetTaskExecutorID(assignee));
564
//
565
// SCR_BaseTaskSupportEntity supportEntity = GetTaskManager().FindSupportEntity(SCR_BaseTaskSupportEntity);
566
// if (!supportEntity)
567
// return;
568
//
569
// supportEntity.AssignTask(task, assignee);
570
// }
571
//
572
// //------------------------------------------------------------------------------------------------
573
// void OnPlayerRegistered(int registeredPlayerID)
574
// {
575
// if (registeredPlayerID == SCR_PlayerController.GetLocalPlayerId())
576
// CreateTaskExecutors();
577
// else
578
// LocalCreateTaskExecutor(registeredPlayerID);
579
// }
580
//
581
// //------------------------------------------------------------------------------------------------
582
// //! Creates a task executor for each connected player
583
// void CreateTaskExecutors()
584
// {
585
// array<int> players = new array<int>();
586
// GetGame().GetPlayerManager().GetPlayers(players);
587
//
588
// foreach (int playerID : players)
589
// {
590
// if (SCR_BaseTaskExecutor.GetTaskExecutorByID(playerID))
591
// continue;
592
//
593
// LocalCreateTaskExecutor(playerID);
594
// }
595
// }
596
//
597
// //------------------------------------------------------------------------------------------------
598
// //! Returns the current timestamp
599
// float GetTimestamp()
600
// {
601
// return m_fTimestamp;
602
// }
603
//
604
// //------------------------------------------------------------------------------------------------
605
// //! Outs an array of all of the tasks.
606
// int GetTasks(notnull out array<SCR_BaseTask> tasks)
607
// {
608
// int count = 0;
609
//
610
// foreach (SCR_BaseTask task : m_aTaskList)
611
// {
612
// tasks.Insert(task);
613
// count++;
614
// }
615
//
616
// return count;
617
// }
618
//
619
// //------------------------------------------------------------------------------------------------
620
// //! Outs an array of all of the finished tasks.
621
// int GetFinishedTasks(notnull out array<SCR_BaseTask> tasks)
622
// {
623
// int count = 0;
624
//
625
// foreach (SCR_BaseTask task : m_aFinishedTaskList)
626
// {
627
// tasks.Insert(task);
628
// count++;
629
// }
630
//
631
// return count;
632
// }
633
//
634
// //------------------------------------------------------------------------------------------------
635
// //! Called from SpawnTask and RPC_SpawnTask methods
636
// //! Don't call directly!
637
// SCR_BaseTask LocalSpawnTask(ResourceName resourceName)
638
// {
639
// if (resourceName.IsEmpty())
640
// return null;
641
//
642
// Resource resource = Resource.Load(resourceName);
643
// if (!resource.IsValid())
644
// return null;
645
//
646
// return SCR_BaseTask.Cast(GetGame().SpawnEntityPrefab(resource, GetWorld()));
647
// }
648
//
649
// //------------------------------------------------------------------------------------------------
650
// //! Call this on the server only
651
// SCR_BaseTask SpawnTask(ResourceName resourceName)
652
// {
653
// SCR_BaseTask task = LocalSpawnTask(resourceName);
654
// if (!task)
655
// return null;
656
//
657
// Rpc(RPC_SpawnTask, resourceName, task.GetTaskID());
658
//
659
// return task;
660
// }
661
//
662
// //***********//
663
// //RPC METHODS//
664
// //***********//
665
//
666
// //------------------------------------------------------------------------------------------------
667
// //! Called by SpawnTask()
668
// //! Don't call directly!
669
// [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
670
// protected void RPC_SpawnTask(ResourceName resourceName, int taskID)
671
// {
672
// SCR_BaseTask task = LocalSpawnTask(resourceName);
673
// if (!task)
674
// return;
675
//
676
// task.SetTaskID(taskID);
677
// }
678
//
679
// //*************//
680
// //ENTITY EVENTS//
681
// //*************//
682
//
683
// //------------------------------------------------------------------------------------------------
684
// protected override void EOnInit(IEntity owner)
685
// {
686
// m_bInitialized = true;
687
//
688
// SCR_BaseGameMode gameMode = SCR_BaseGameMode.Cast(GetGame().GetGameMode());
689
// if (gameMode)
690
// gameMode.GetOnPlayerRegistered().Insert(OnPlayerRegistered);
691
//
692
// // If replicated make sure it never streams out
693
// auto rplComponent = RplComponent.Cast(FindComponent(RplComponent));
694
// if (rplComponent && rplComponent.IsSelfInserted())
695
// {
696
// auto ctx = new GameRplSchedulerInsertionCtx;
697
// ctx.CanBeStreamed = false;
698
// rplComponent.InsertToReplication(ctx);
699
// }
700
//
701
// m_RplComponent = RplComponent.Cast(FindComponent(RplComponent));
702
//
703
// // This is for individual tasks, so they don't have to tick their own timers, but it's centralized on the task manager.
704
// // This could be further improved for more custom timers, but for now it is sufficient as is.
705
// GetGame().GetCallqueue().CallLater(PeriodicalCheck2Second, 2000, true);
706
// GetGame().GetCallqueue().CallLater(PeriodicalCheck5Second, 5000, true);
707
// GetGame().GetCallqueue().CallLater(PeriodicalCheck60Second, 60000, true);
708
// }
709
// //------------------------------------------------------------------------------------------------
710
// void UpdateTasks()
711
// {
712
// SCR_BaseTask task;
713
// SCR_ETaskEventMask mask;
714
//
715
// for (int i = m_mTaskEventMaskMap.Count() - 1; i >= 0; i--)
716
// {
717
// task = m_mTaskEventMaskMap.GetKey(i);
718
// mask = m_mTaskEventMaskMap.Get(task);
719
// s_OnTaskUpdate.Invoke(task, mask);
720
// }
721
//
722
// m_mTaskEventMaskMap.Clear();
723
//
724
// foreach (SCR_BaseTask taskToDelete : m_aTasksToDelete)
725
// {
726
// if (!taskToDelete)
727
// continue;
728
//
729
// IEntity taskChild = taskToDelete.GetChildren();
730
// while (taskChild)
731
// {
732
// IEntity childToDelete = taskChild;
733
// taskChild = taskChild.GetSibling();
734
//
735
// delete childToDelete;
736
// }
737
//
738
// m_aTaskList.RemoveItem(taskToDelete);
739
// delete taskToDelete;
740
// }
741
//
742
// for (int i = m_aFinishedTaskList.Count() - 1; i >= 0; i--)
743
// {
744
// if (!m_aFinishedTaskList[i])
745
// m_aFinishedTaskList.Remove(i);
746
// }
747
//
748
// m_aTasksToDelete.Clear();
749
// }
750
// //------------------------------------------------------------------------------------------------
751
// protected override void EOnFrame(IEntity owner, float timeSlice)
752
// {
753
// if (GetTaskManager() && GetTaskManager() != this)
754
// {
755
// delete this;
756
// return;
757
// }
758
//
759
// if (!m_mTaskEventMaskMap.IsEmpty())
760
// UpdateTasks();
761
//#ifdef ENABLE_DIAG
762
// /*if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_SHOW_ALL_TASKS))
763
// {
764
// if (!m_bPrintedTasks)
765
// {
766
// m_bPrintedTasks = true;
767
// for (int i = m_aTaskList.Count() - 1; i >= 0; i--)
768
// {
769
// Print(m_aTaskList[i].GetDescription());
770
// }
771
// }
772
// }
773
// else
774
// m_bPrintedTasks = false;
775
//
776
// if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EXECUTE_TASKS))
777
// return;*/
778
//#endif
779
//
780
// m_fTimestamp += timeSlice;
781
// m_fTimestampTimer -= timeSlice;
782
// if (m_fTimestampTimer <= 0)
783
// {
784
// Replication.BumpMe();
785
// m_fTimestampTimer = 1;
786
// }
787
//
788
// if (!IsProxy() && m_fTimestamp > m_fAssigneeCacheCheckTimestamp)
789
// {
790
// m_fAssigneeCacheCheckTimestamp = m_fTimestamp + m_fAssigneeCacheTimer;
791
// CheckAssigneeTimeout();
792
// }
793
// }
794
//
795
// //***********//
796
// //JIP METHODS//
797
// //***********//
798
//
799
// //------------------------------------------------------------------------------------------------
800
// void SaveTasksForRpl(ScriptBitWriter writer, array<SCR_BaseTask> taskArray)
801
// {
802
// int count = taskArray.Count();
803
// writer.WriteInt(count);
804
//
805
// for (int i = 0; i < count; i++)
806
// {
807
// SCR_BaseTask task = taskArray[i];
808
// if (!task || task.FindComponent(RplComponent)) //--- Assume that tasks with their own replication will sync data themselves
809
// {
810
// writer.WriteBool(false);
811
// continue;
812
// }
813
//
814
// EntityPrefabData prefabData = task.GetPrefabData();
815
// ResourceName resourceName;
816
// if (prefabData)
817
// resourceName = prefabData.GetPrefabName();
818
//
819
// Resource resource = Resource.Load(resourceName);
820
// if (!resource.IsValid())
821
// {
822
// // Invalid resouce name means we wouldn't be able to recreate the task on clients.
823
// // As a result, we would start reading from incorrect place in the serialized buffer
824
// // which is undefined behavior and could easily end-up crashing the game.
825
// writer.WriteBool(false);
826
// continue;
827
// }
828
//
829
// writer.WriteBool(true);
830
//
831
// writer.WriteResourceName(resourceName); //Write prefab, then read it in load & spawn correct task
832
//
833
// task.Serialize(writer);
834
// }
835
// }
836
//
837
// //------------------------------------------------------------------------------------------------
838
// override bool RplSave(ScriptBitWriter writer)
839
// {
840
//
841
// SaveTasksForRpl(writer, m_aTaskList);
842
// SaveTasksForRpl(writer, m_aFinishedTaskList);
843
//
844
// return true;
845
// }
846
//
847
// //------------------------------------------------------------------------------------------------
848
// bool LoadTasksForRpl(ScriptBitReader reader, int count)
849
// {
850
// reader.ReadInt(count);
851
//
852
// ResourceName resourceName;
853
// Resource resource;
854
// SCR_BaseTask task;
855
// bool readTask;
856
// for (int i = 0; i < count; i++)
857
// {
858
// reader.ReadBool(readTask);
859
// if (!readTask)
860
// continue;
861
//
862
// reader.ReadResourceName(resourceName);
863
//
864
// resource = Resource.Load(resourceName);
865
// if (!resource.IsValid())
866
// {
867
// // https://jira.bistudio.com/browse/ARMA4-62494
868
// // We have to return. This is a fatal failure and because these
869
// // tasks are not replicated by themselves the task that follows
870
// // wouldn't know where to read its data from. It would simply
871
// // read from wherewhere we left form and most likely cause a crash
872
// // during deserialization.
873
// Print("Invalid resource name for a task. Tasks can't be synchronized properly!", LogLevel.ERROR);
874
// return false; // DON'T CONTINUE
875
// }
876
//
877
// task = SCR_BaseTask.Cast(GetGame().SpawnEntityPrefab(resource, GetWorld()));
878
// if (!task)
879
// {
880
// // https://jira.bistudio.com/browse/ARMA4-62494
881
// // We have to return. This is a fatal failure and because these
882
// // tasks are not replicated by themselves the task that follows
883
// // wouldn't know where to read its data from. It would simply
884
// // read from wherewhere we left form and most likely cause a crash
885
// // during deserialization.
886
// Print(string.Format("Unable to spawn a task for resource name %1. Some tasks can't synchronized!", resourceName), LogLevel.ERROR);
887
// return false; // DON'T CONTINUE
888
// }
889
//
890
// task.Deserialize(reader);
891
// }
892
//
893
// return true;
894
// }
895
//
896
// //------------------------------------------------------------------------------------------------
897
// override bool RplLoad(ScriptBitReader reader)
898
// {
899
// // https://jira.bistudio.com/browse/ARMA4-62494
900
// // We keep reading only as long as valid tasks are present.
901
// // The first broken task would break deserialization and cause crashes.
902
// // Therefore, we won't even attempt reading further if an issue is detected
903
// // and we'll try to intialize at least the tasks we managed to extract.
904
// const int count; // TODO: check for good const usage
905
// if (LoadTasksForRpl(reader, count))
906
// LoadTasksForRpl(reader, count);
907
//
908
// //Let the game mode know, the tasks are ready
909
// SCR_BaseGameMode gamemode = SCR_BaseGameMode.Cast(GetGame().GetGameMode());
910
// if (gamemode)
911
// gamemode.HandleOnTasksInitialized();
912
//
913
// //AssignCachedTasks();
914
//
915
// return true;
916
// }
917
//
918
// //************************//
919
// //CONSTRUCTOR & DESTRUCTOR//
920
// //************************//
921
//
922
// //------------------------------------------------------------------------------------------------
923
// void SCR_BaseTaskManager(IEntitySource src, IEntity parent)
924
// {
925
// if (!g_TaskManagerInstance)
926
// g_TaskManagerInstance = this;
927
//
928
//#ifdef ENABLE_DIAG
929
// /*DiagMenu.RegisterMenu(SCR_DebugMenuID.DEBUGUI_TASKS_MENU, "Tasks", "");
930
// DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EXECUTE_TASKS, "", "Execute tasks", "Tasks", true);
931
// DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_SHOW_ALL_TASKS, "", "Print all tasks", "Tasks", false);*/
932
//#endif
933
// SetEventMask(EntityEvent.FRAME | EntityEvent.INIT);
934
// SetFlags(EntityFlags.NO_LINK, false);
935
//
936
// //Register to Script Invokers
937
// s_OnTaskCreated.Insert(OnTaskCreated);
938
// s_OnTaskFinished.Insert(OnTaskFinished);
939
// s_OnTaskDeleted.Insert(OnTaskDeleted);
940
// }
941
//
942
// //------------------------------------------------------------------------------------------------
943
// void ~SCR_BaseTaskManager()
944
// {
945
//
946
// //Unregister from Script Invokers
947
// s_OnTaskCreated.Remove(OnTaskCreated);
948
// s_OnTaskFinished.Remove(OnTaskFinished);
949
// s_OnTaskDeleted.Remove(OnTaskDeleted);
950
// }
951
//};
scripts
Game
Tasks
SCR_BaseTaskManager.c
Generated by
1.17.0