Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BaseTask.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 class SCR_BaseTaskClass: GenericEntityClass
3 {
4 };
5 
6 //------------------------------------------------------------------------------------------------
9 {
10 
11  //****************//
12  //STATIC VARIABLES//
13  //****************//
14 
15  static const string TASK_AMOUNT_COMPLETED_TEXT = "#AR-Tasks_AmountCompleted";
16  static const string TASK_PROGRESS_TEXT = "#AR-Tasks_StatusProgress-UC";
17  static const string TASK_FINISHED_TEXT = "#AR-Tasks_StatusFinished-UC";
18  static const string TASK_AVAILABLE_TEXT = "#AR-Tasks_StatusNew-UC";
19  static const string TASK_HINT_TEXT = "#AR-Tasks_Hint";
20  static const string TASK_CANCELLED_TEXT = "#AR-Tasks_StatusCancelled-UC";
21  static const string TASK_COMPLETED_TEXT = "#AR-Tasks_StatusCompleted-UC";
22  static const string TASK_FAILED_TEXT = "#AR-Tasks_StatusFailed-UC";
23  static const float DEFAULT_ASSIGNEE_TIME_LIMIT = 1800;
24  static const float DEFAULT_ASSIGNEE_TIMEOUT_TIME = 60;
25  static const int INVALID_TIMESTAMP = -1;
26  static const int INVALID_TASK_ID = -1;
27  static int s_iCurrentTaskID = 0;
28 
29  //*****************//
30  //MEMBER ATTRIBUTES//
31  //*****************//
32 
33  [Attribute(defvalue: "Task name.", desc: "The task name visible to the player.")]
34  protected string m_sName;
35 
36  [Attribute(defvalue: "Task description.", desc: "The task description visible to the player.")]
37  protected string m_sDescription;
38 
39  [Attribute("1", desc: "Can this task be assigned?")]
40  protected bool m_bAssignable;
41 
42  [Attribute(desc: "Is this task supposed to be completed just by an individual?")]
43  protected bool m_bIndividualTask;
44 
45  [Attribute("Task_Seize")]
46  protected string m_sMapIconName;
47 
48  [Attribute("Icon_Seize")]
49  protected string m_sTaskListIconName;
50 
51  [Attribute("{EAB5D9841F081D07}UI/layouts/Campaign/TaskElementNew.layout")]
52  protected ResourceName m_sMapUIElementResourceName;
53 
54  [Attribute("{10C0A9A305E8B3A4}UI/Imagesets/Tasks/Task_Icons.imageset", category: "Task icon")]
55  protected ResourceName m_sIconImageset;
56 
57  [Attribute(SCR_ERadioMsg.CONFIRM.ToString(), UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(SCR_ERadioMsg))]
58  protected SCR_ERadioMsg m_eAssignMessage;
59 
60  [Attribute("0")]
61  protected bool m_bNotifyAssignment;
62 
63  [Attribute(SCR_ERadioMsg.TASK_UNASSIGN_EVAC.ToString(), UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(SCR_ERadioMsg))]
64  protected SCR_ERadioMsg m_eUnassignMessage;
65 
66  [Attribute("0")]
67  protected bool m_bNotifyUnassign;
68 
69  [Attribute("{6FE28246710CA6B1}UI/layouts/Tasks/TaskHUDIcon.layout")]
70  protected ResourceName m_sHUDIcon;
71 
72  //**************************//
73  //PROTECTED MEMBER VARIABLES//
74  //**************************//
75 
76  protected Faction m_TargetFaction = null;
77  protected int m_iTaskID = INVALID_TASK_ID;
78  protected float m_fAssigneeTimeLimit = DEFAULT_ASSIGNEE_TIME_LIMIT;
79  protected float m_fLastAssigneeAddedTimestamp = INVALID_TIMESTAMP;
80  protected ref array<SCR_BaseTaskExecutor> m_aAssignees = new array<SCR_BaseTaskExecutor>();
81  protected SCR_TaskState m_eState;
82  protected SCR_BaseTaskExecutor m_TimedOutAssignee = null;
83  protected float m_fAssigneeTimeoutTimestamp = INVALID_TIMESTAMP;
84  protected SCR_MapDescriptorComponent m_MapDescriptor;
85  protected ImageWidget m_wHUDIcon;
86  protected Widget m_wMapTaskIcon;
87  protected Widget m_wTaskListDescription;
88  protected bool m_bIsPriority;
89 
90  const string TASK_BG_M = "Icon_M_Task_BG";
91  const string TASK_O_M = "Icon_M_Task_Outline";
92  const string TASK_BG = "Icon_Task_BG";
93  const string TASK_O = "Icon_Task_Outline";
94  const string TASK_H = "Icon_M_Task_Hover";
95 
96  //***************************//
97  //PUBLIC MEMBER EVENT METHODS//
98  //***************************//
99 
100  //------------------------------------------------------------------------------------------------
101  void OnDelete()
102  {
103  }
104 
105  //*********************//
106  //PUBLIC MEMBER METHODS//
107  //*********************//
108 
109  //------------------------------------------------------------------------------------------------
110  bool NotifyAssignment()
111  {
112  return m_bNotifyAssignment;
113  }
114 
115  //------------------------------------------------------------------------------------------------
116  bool NotifyUnassign()
117  {
118  return m_bNotifyUnassign;
119  }
120 
121  //------------------------------------------------------------------------------------------------
122  void DoNotifyAssignment(int assigneeID)
123  {
124  SCR_CampaignNetworkComponent assigneeNetworkComponent = SCR_CampaignNetworkComponent.GetCampaignNetworkComponent(assigneeID);
125  if (!assigneeNetworkComponent)
126  return;
127 
128  assigneeNetworkComponent.SendPlayerMessage(GetAssignMessage());
129  }
130 
131  //------------------------------------------------------------------------------------------------
132  void DoNotifyUnassign(int assigneeID)
133  {
134  SCR_CampaignNetworkComponent assigneeNetworkComponent = SCR_CampaignNetworkComponent.GetCampaignNetworkComponent(assigneeID);
135  if (!assigneeNetworkComponent)
136  return;
137 
138  assigneeNetworkComponent.SendPlayerMessage(GetUnassignMessage());
139  }
140 
141  //------------------------------------------------------------------------------------------------
142  SCR_ERadioMsg GetAssignMessage()
143  {
144  return m_eAssignMessage;
145  }
146 
147  //------------------------------------------------------------------------------------------------
148  SCR_ERadioMsg GetUnassignMessage()
149  {
150  return m_eUnassignMessage;
151  }
152 
153  //------------------------------------------------------------------------------------------------
154  ResourceName GetMapUIElementResourceName()
155  {
156  return m_sMapUIElementResourceName;
157  }
158 
159  //------------------------------------------------------------------------------------------------
160  string GetMapDescriptorText()
161  {
162  return GetTaskListTaskText();
163  }
164 
165  //------------------------------------------------------------------------------------------------
166  void OnMapOpen(MapConfiguration config)
167  {
168  }
169 
170  //------------------------------------------------------------------------------------------------
171  void OnHoverItem(MapItem item)
172  {
173  }
174 
175  //------------------------------------------------------------------------------------------------
176  string GetTaskMapIconName()
177  {
178  return m_sMapIconName;
179  }
180 
181  //------------------------------------------------------------------------------------------------
182  string GetTaskListIconName()
183  {
184  return m_sTaskListIconName;
185  }
186 
187  //------------------------------------------------------------------------------------------------
188  string GetTaskListTaskTitle()
189  {
190  return GetTitle();
191  }
192 
193  //------------------------------------------------------------------------------------------------
194  //Description
195  string GetTaskListTaskText()
196  {
197  return GetDescription();
198  }
199 
200  //------------------------------------------------------------------------------------------------
201  Widget GetParentWidget(notnull Widget rootWidget)
202  {
203  return rootWidget.FindAnyWidget("Tasks");
204  }
205 
206  ResourceName GetIconImageset()
207  {
208  return m_sIconImageset;
209  }
210 
211  //------------------------------------------------------------------------------------------------
212  void SetHUDIcon()
213  {
214  SetWidgetIcon(m_wHUDIcon);
215  }
216 
217  //------------------------------------------------------------------------------------------------
218  void SetWidgetIcon(ImageWidget image)
219  {
220  if (!image)
221  return;
222 
223  image.LoadImageFromSet(0, m_sIconImageset, GetTaskListIconName() + GetIconSuffix());
224  UpdateMapTaskIcon();
225  }
226 
227  //------------------------------------------------------------------------------------------------
229  void ClearWidgetIcon()
230  {
231  if (m_wMapTaskIcon && m_wMapTaskIcon.GetParent())
232  m_wMapTaskIcon.GetParent().RemoveFromHierarchy();
233  }
234 
235  //------------------------------------------------------------------------------------------------
236  void UpdateMapTaskIcon()
237  {
238  if (!m_wMapTaskIcon)
239  return;
240 
241  m_wMapTaskIcon.SetColor(Color.FromInt(Color.WHITE));
242  if (m_TargetFaction && (IsAssignedToLocalPlayer() || SCR_EditorManagerEntity.IsOpenedInstance(false)))
243  m_wMapTaskIcon.SetColor(m_TargetFaction.GetFactionColor());
244 
245  ImageWidget outline = ImageWidget.Cast(m_wMapTaskIcon.GetParent().FindAnyWidget("TaskIconOutline"));
246  ImageWidget background = ImageWidget.Cast(m_wMapTaskIcon.GetParent().FindAnyWidget("TaskIconBackground"));
247  ImageWidget hover = ImageWidget.Cast(m_wMapTaskIcon.GetParent().FindAnyWidget("TaskIconHover"));
248 
249  if (!outline || !background || !hover)
250  return;
251 
252  if (m_bIsPriority)
253  {
254  background.LoadImageFromSet(0, m_sIconImageset,TASK_BG_M);
255  outline.LoadImageFromSet(0, m_sIconImageset,TASK_O_M);
256  hover.LoadImageFromSet(0,m_sIconImageset,TASK_H);
257  }
258  }
259 
260  //------------------------------------------------------------------------------------------------
261  bool AssignTaskToAI(AIAgent agent)
262  {
263  // Find entities in hierarchy - AIWaypoint type
264  // On agent add all waypoints
265  // Order matters! Check if it's deterministic
266  // Return false if no agent, no waypoint
267  // Return true at the end
268  }
269 
270  //------------------------------------------------------------------------------------------------
271  string GetIconName()
272  {
273  return GetTaskMapIconName() + GetIconSuffix();
274  }
275 
276  //------------------------------------------------------------------------------------------------
277  ResourceName GetImageSetName()
278  {
279  return GetMapUIElementResourceName();
280  }
281 
282  //------------------------------------------------------------------------------------------------
283  string GetIconSuffix()
284  {
285  return "";
286  }
287 
288  //------------------------------------------------------------------------------------------------
289  string GetTitleIconString()
290  {
291  return string.Format("<image set='%1' name='%2' />", GetMapUIElementResourceName(), GetIconName() + GetIconSuffix());
292  }
293 
294  //------------------------------------------------------------------------------------------------
295  void SetTitleWidgetText(notnull TextWidget textWidget, string taskText)
296  {
297  textWidget.SetTextFormat(taskText);
298  }
299 
300  //------------------------------------------------------------------------------------------------
301  string GetTitleText()
302  {
303  return m_sName; // todo(koudelkaluk): merge with GetTitle()
304  }
305 
306  //------------------------------------------------------------------------------------------------
307  void SetDescriptionWidgetText(notnull TextWidget textWidget, string taskText)
308  {
309  textWidget.SetTextFormat(taskText);
310  }
311 
312  //------------------------------------------------------------------------------------------------
313  Widget GenerateTaskDescriptionUI(notnull Widget rootWidget, array<Widget> widgets)
314  {
315  Widget parentWidget = GetParentWidget(rootWidget);
316  if (!parentWidget)
317  return null;
318 
319  WorkspaceWidget workspaceWidget = rootWidget.GetWorkspace();
320  if (!workspaceWidget)
321  return null;
322 
323  SCR_BaseTaskSupportEntity supportClass = GetTaskManager().FindSupportEntity(SCR_BaseTaskSupportEntity);
324  if (!supportClass)
325  return null;
326 
327  ResourceName taskDescriptionWidgetResourceName = supportClass.GetTaskDescriptionWidgetResource();
328  if (taskDescriptionWidgetResourceName == string.Empty)
329  return null;
330 
331  Widget taskDescriptionWidget = workspaceWidget.CreateWidgets(taskDescriptionWidgetResourceName, parentWidget);
332  widgets.Insert(taskDescriptionWidget);
333  VerticalLayoutSlot.SetPadding(taskDescriptionWidget, 4, 4, 4, 4);
334 
335  m_wTaskListDescription = taskDescriptionWidget;
336 
337  SCR_TaskListEntryHandler handler = SCR_TaskListEntryHandler.Cast(taskDescriptionWidget.FindHandler(SCR_TaskListEntryHandler));
338  if (handler)
339  {
340  handler.SetTask(this);
341  handler.UpdateTask(this);
342  }
343 
344  Widget doneLayout = taskDescriptionWidget.FindAnyWidget("DoneLayout");
345  if (doneLayout)
346  {
347  if (m_eState == SCR_TaskState.FINISHED)
348  doneLayout.SetOpacity(1);
349  else
350  doneLayout.SetOpacity(0);
351  }
352 
353  RichTextWidget textWidgetRich = RichTextWidget.Cast(taskDescriptionWidget.FindAnyWidget("TaskDescription"));
354  if (!textWidgetRich)
355  return taskDescriptionWidget;
356 
357  string taskText = GetTaskListTaskText();
358 
359  textWidgetRich.SetText(taskText);
360 
361  TextWidget textWidget = TextWidget.Cast(taskDescriptionWidget.FindAnyWidget("TaskTitle"));
362  if (!textWidget)
363  return taskDescriptionWidget;
364 
365  string taskTextTitle = GetTaskListTaskTitle();
366 
367  SetTitleWidgetText(textWidget, taskTextTitle);
368  SetWidgetIcon(ImageWidget.Cast(taskDescriptionWidget.FindAnyWidget("TaskIcon")));
369 
370  UpdateTaskListAssignee();
371 
372  return taskDescriptionWidget;
373  }
374 
375  //------------------------------------------------------------------------------------------------
376  void UpdateTaskListAssignee()
377  {
378  if (!m_wTaskListDescription)
379  return;
380 
381  TextWidget textWidget = TextWidget.Cast(m_wTaskListDescription.FindAnyWidget("TaskAssignee"));
382  if (!textWidget)
383  return;
384 
385  string assigneeNames = "";
386  if (IsAssigned())
387  assigneeNames = "#AR-DeployMenu_AssignedPlayers \n" + GetAllAssigneeNamesString();
388 
389  textWidget.SetTextFormat(assigneeNames);
390  }
391 
392  //------------------------------------------------------------------------------------------------
393  void OnAssigneeKilled()
394  {
395 
396  }
397 
398  //------------------------------------------------------------------------------------------------
399  void CreateMapUIIcon()
400  {
401 
402  }
403 
404  //------------------------------------------------------------------------------------------------
406  Faction GetTargetFaction()
407  {
408  return m_TargetFaction;
409  }
410 
411  //------------------------------------------------------------------------------------------------
413  void SetTargetFaction(Faction targetFaction)
414  {
415  m_TargetFaction = targetFaction;
416  SCR_BaseTaskManager.s_OnTaskFactionAssigned.Invoke(this);
417 
418  RegisterTaskUpdate(SCR_ETaskEventMask.TASK_PROPERTY_CHANGED);
419 
420  SetHUDIcon();
421  }
422 
423  //------------------------------------------------------------------------------------------------
425  string GetFinishText()
426  {
427  return TASK_FINISHED_TEXT;
428  }
429 
430  //------------------------------------------------------------------------------------------------
432  bool IsAssigned()
433  {
434  if (!m_aAssignees || m_aAssignees.Count() <= 0)
435  return false;
436 
437  return true;
438  }
439 
440  //------------------------------------------------------------------------------------------------
442  string GetAllAssigneeNamesString()
443  {
444  string names = "";
445  if (!IsAssigned())
446  return names;
447 
448  for (int i = 0, count = m_aAssignees.Count(); i < count; i++)
449  {
450  names += m_aAssignees[i].GetPlayerName();
451  if (i < count - 1)
452  names += ", ";
453  }
454 
455  return names;
456  }
457 
458  //------------------------------------------------------------------------------------------------
460  void CheckAssigneeTimeout()
461  {
462  if (!m_bIndividualTask || !m_aAssignees || !IsAssigned() || !GetTaskManager())
463  return;
464 
466  if (!supportEntity)
467  return;
468 
469  if (GetAssigneeTimeLeft() <= 0)
470  {
471  foreach (SCR_BaseTaskExecutor assignee : m_aAssignees)
472  {
473  if (!assignee)
474  continue;
475 
476  supportEntity.UnassignTask(this, assignee, SCR_EUnassignReason.ASSIGNEE_TIMEOUT);
477  }
478  }
479  }
480 
481  //------------------------------------------------------------------------------------------------
482  void SetLastAssigneeAddedTimestamp(float timestamp)
483  {
484  m_fLastAssigneeAddedTimestamp = timestamp;
485  }
486 
487  //------------------------------------------------------------------------------------------------
489  void SetIndividual(bool individual)
490  {
491  m_bIndividualTask = individual;
492  }
493 
494  //------------------------------------------------------------------------------------------------
496  bool IsIndividual()
497  {
498  return m_bIndividualTask;
499  }
500 
501  //------------------------------------------------------------------------------------------------
502  void SetIsPriority(bool isPrio)
503  {
504  m_bIsPriority = isPrio;
505  }
506 
507  //------------------------------------------------------------------------------------------------
508  bool IsPriority()
509  {
510  return m_bIsPriority;
511  }
512 
513  //------------------------------------------------------------------------------------------------
514  bool IsAssignable()
515  {
516  return m_bAssignable;
517  }
518 
519  //------------------------------------------------------------------------------------------------
522  bool CanBeAssigned(out SCR_ECannotAssignReasons reason, int playerID = -1)
523  {
524  SCR_BaseTaskExecutor executor = null;
525  SCR_BaseTaskExecutor localExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
526  if (!localExecutor)
527  return false;
528 
529  SCR_BaseTask localExecutorTask = localExecutor.GetAssignedTask();
530  if (localExecutorTask)
531  {
532  if (localExecutorTask != this)
533  reason = SCR_ECannotAssignReasons.LOCAL_EXECUTOR_IS_ASSIGNED;
534  else
535  reason = SCR_ECannotAssignReasons.TASK_IS_ASSIGNED_TO_LOCAL_EXECUTOR;
536 
537  return false;
538  }
539 
540  if (playerID == -1)
541  executor = localExecutor;
542  else
543  executor = SCR_BaseTaskExecutor.GetTaskExecutorByID(playerID);
544 
545  if (m_bAssignable && !m_bIndividualTask)
546  return true;
547 
548  if (m_bIndividualTask)
549  {
550  if (IsAssigned())
551  {
552  reason = SCR_ECannotAssignReasons.TASK_IS_ASSIGNED;
553  return false;
554  }
555 
556  if (m_TimedOutAssignee == executor && m_fAssigneeTimeoutTimestamp > GetTaskManager().GetTimestamp())
557  {
558  reason = SCR_ECannotAssignReasons.ASSIGNEE_TIMEOUT;
559  return false;
560  }
561 
562  if (GetTaskManager().GetAssigneeAbandoned(executor))
563  {
564  reason = SCR_ECannotAssignReasons.TASK_ABANDONED;
565  return false;
566  }
567 
568  // Is individual task, that is not assigned yet, can be assigned
569  return true;
570  }
571  else
572  {
573  // Cannot be assigned
574  reason = SCR_ECannotAssignReasons.TASK_NOT_ASSIGNABLE;
575  return false;
576  }
577 
578  // Is not individual task, can be assigned
579  reason = SCR_ECannotAssignReasons.TASK_NOT_ASSIGNABLE;
580  return true;
581  }
582 
583  //------------------------------------------------------------------------------------------------
585  float GetLastAssigneeAddedTimestamp()
586  {
587  return m_fLastAssigneeAddedTimestamp;
588  }
589 
590  //------------------------------------------------------------------------------------------------
592  float GetAssigneeTimeLeft()
593  {
594  float currentTimestamp = GetTaskManager().GetTimestamp();
595  float timeLeft = m_fAssigneeTimeLimit - (currentTimestamp - m_fLastAssigneeAddedTimestamp);
596 
597  return timeLeft;
598  }
599 
600  //------------------------------------------------------------------------------------------------
602  void SetTaskID(int taskID)
603  {
604  m_iTaskID = taskID;
605  }
606 
607  //------------------------------------------------------------------------------------------------
609  int GetTaskID()
610  {
611  return m_iTaskID;
612  }
613 
614  //------------------------------------------------------------------------------------------------
616  SCR_TaskState GetTaskState()
617  {
618  return m_eState;
619  }
620 
621  //------------------------------------------------------------------------------------------------
622  void SetTitle(string title)
623  {
624  m_sName = title;
625  RegisterTaskUpdate(SCR_ETaskEventMask.TASK_PROPERTY_CHANGED);
626  }
627 
628  //------------------------------------------------------------------------------------------------
630  string GetTitle()
631  {
632  return m_sName;
633  }
634 
635  //------------------------------------------------------------------------------------------------
636  void SetDescription(string description)
637  {
638  m_sDescription = description;
639  RegisterTaskUpdate(SCR_ETaskEventMask.TASK_PROPERTY_CHANGED);
640  }
641 
642  //------------------------------------------------------------------------------------------------
644  string GetDescription()
645  {
646  return m_sDescription;
647  }
648 
649  //------------------------------------------------------------------------------------------------
651  SCR_BaseTaskExecutor GetAssignee()
652  {
653  if (!m_aAssignees || m_aAssignees.Count() <= 0)
654  return null;
655 
656  return m_aAssignees[0];
657  }
658 
659  //------------------------------------------------------------------------------------------------
661  int GetAssignees(out array<SCR_BaseTaskExecutor> assignees)
662  {
663  return assignees.Copy(m_aAssignees);
664  }
665 
666  //------------------------------------------------------------------------------------------------
667  int GetAssigneeCount()
668  {
669  return m_aAssignees.Count();
670  }
671 
672  //------------------------------------------------------------------------------------------------
673  void Cancel(bool showMsg = true)
674  {
675  SetState(SCR_TaskState.CANCELLED);
676 
677  SCR_BaseTaskManager.s_OnTaskCancelled.Invoke(this);
678 
679  RegisterTaskUpdate(SCR_ETaskEventMask.TASK_CANCELED);
680  }
681 
682  //------------------------------------------------------------------------------------------------
684  void Remove()
685  {
686  SetState(SCR_TaskState.REMOVED);
687 
688  if (m_aAssignees)
689  {
690  foreach (SCR_BaseTaskExecutor assignee: m_aAssignees)
691  assignee.OnAssignedTaskRemoved();
692  }
693 
694  SCR_BaseTaskManager.s_OnTaskRemoved.Invoke(this);
695 
696  RegisterTaskUpdate(SCR_ETaskEventMask.TASK_REMOVED);
697  }
698 
699  //------------------------------------------------------------------------------------------------
701  void Create(bool showMsg = true)
702  {
703  }
704 
705  //------------------------------------------------------------------------------------------------
707  void Finish(bool showMsg = true)
708  {
709  SetState(SCR_TaskState.FINISHED);
710 
711  if (m_aAssignees)
712  {
713  foreach (SCR_BaseTaskExecutor assignee: m_aAssignees)
714  assignee.OnAssignedTaskFinished();
715  }
716 
717  SCR_BaseTaskManager.s_OnTaskFinished.Invoke(this);
718 
719  RegisterTaskUpdate(SCR_ETaskEventMask.TASK_FINISHED);
720  }
721 
722  //------------------------------------------------------------------------------------------------
724  void Fail(bool showMsg = true)
725  {
726  SetState(SCR_TaskState.CANCELLED);
727 
728  if (m_aAssignees)
729  {
730  foreach (SCR_BaseTaskExecutor assignee: m_aAssignees)
731  assignee.OnAssignedTaskFailed();
732  }
733 
734  SCR_BaseTaskManager.s_OnTaskFailed.Invoke(this);
735 
736  RegisterTaskUpdate(SCR_ETaskEventMask.TASK_FAILED);
737  }
738 
739  //------------------------------------------------------------------------------------------------
741  void RemoveAllAssignees()
742  {
743  if (!IsAssigned())
744  return;
745 
746  SCR_BaseTaskExecutor removedAssignee = null;
747 
748  for (int i = m_aAssignees.Count() - 1; i >= 0; i --)
749  {
750  removedAssignee = m_aAssignees[i];
751  m_aAssignees[i].OnAssignedTaskRemoved();
752  m_aAssignees.Remove(i);
753  }
754 
755  if (m_bIndividualTask)
756  {
757  // We automatically set timeout for the assignee, since we don't want them to be immediately able to assign the task to themselves again
758  m_fAssigneeTimeoutTimestamp = GetTaskManager().GetTimestamp() + DEFAULT_ASSIGNEE_TIMEOUT_TIME;
759  m_TimedOutAssignee = removedAssignee;
760 
761  ShowAvailableTask();
762  }
763 
764  SCR_BaseTaskManager.s_OnTaskUnassigned.Invoke(this);
765 
766  RegisterTaskUpdate(SCR_ETaskEventMask.TASK_ASSIGNEE_CHANGED);
767  }
768 
769  //------------------------------------------------------------------------------------------------
771  void RemoveAssignee(SCR_BaseTaskExecutor assignee, SCR_EUnassignReason reason)
772  {
773  if (!m_aAssignees || !assignee)
774  return;
775 
776  int index = m_aAssignees.Find(assignee);
777 
778  if (index == -1)
779  return;
780 
781  m_aAssignees.Remove(index);
782  if (assignee == SCR_BaseTaskExecutor.GetLocalExecutor())
783  ShowPopUpNotification("#AR-Tasks_UnassignPopup");
784 
785  OnAssigneeRemoved(assignee);
786 
787  if (m_bIndividualTask)
788  {
789  switch (reason)
790  {
791  case SCR_EUnassignReason.ASSIGNEE_TIMEOUT:
792  // We set timeout for the assignee, since we don't want them to be immediately able to assign the task to themselves again
793  m_fAssigneeTimeoutTimestamp = GetTaskManager().GetTimestamp() + DEFAULT_ASSIGNEE_TIMEOUT_TIME;
794  m_TimedOutAssignee = assignee;
795  break;
796  case SCR_EUnassignReason.ASSIGNEE_DISCONNECT:
797  break;
798  case SCR_EUnassignReason.ASSIGNEE_ABANDON:
799  break;
800  case SCR_EUnassignReason.GM_REASSIGN:
801  break;
802  }
803 
804  ShowAvailableTask(true);
805  }
806 
807  SCR_BaseTaskManager.s_OnTaskUnassigned.Invoke(this);
808 
809  RegisterTaskUpdate(SCR_ETaskEventMask.TASK_ASSIGNEE_CHANGED);
810  }
811 
812  //------------------------------------------------------------------------------------------------
814  void AddAssignee(SCR_BaseTaskExecutor assignee, float timestamp)
815  {
816  if (!m_aAssignees || !assignee)
817  return;
818 
819  IEntity assigneeEntity = assignee.GetControlledEntity();
820  if (assigneeEntity)
821  {
822  SCR_CharacterControllerComponent characterControllerComponent = SCR_CharacterControllerComponent.Cast(assigneeEntity.FindComponent(SCR_CharacterControllerComponent));
823  if (characterControllerComponent)
824  characterControllerComponent.GetOnPlayerDeath().Insert(OnAssigneeKilled);
825  }
826  else
827  {
829  if (!gameMode)
830  return;
831  gameMode.GetOnPlayerSpawned().Insert(InitOnSpawn);
832  }
833 
834  // Is this task for an individual & we already have someone assigned?
835  if (m_bIndividualTask && m_aAssignees.Count() > 0)
836  return;
837 
838  int index = m_aAssignees.Find(assignee);
839 
840  if (index != -1)
841  return;
842 
843  SetLastAssigneeAddedTimestamp(timestamp);
844 
845  m_aAssignees.Insert(assignee);
846  if (assignee == SCR_BaseTaskExecutor.GetLocalExecutor())
847  ShowPopUpNotification("#AR-Tasks_AssignPopup");
848 
849  OnAssigneeAdded(assignee);
850 
851  SCR_BaseTaskManager.s_OnTaskAssigned.Invoke(this);
852 
853  RegisterTaskUpdate(SCR_ETaskEventMask.TASK_ASSIGNEE_CHANGED);
854  }
855 
856  //------------------------------------------------------------------------------------------------
857  void InitOnSpawn(int pid, IEntity ent)
858  {
860  if (charCtrlComp)
861  charCtrlComp.GetOnPlayerDeath().Insert(OnAssigneeKilled);
863  if (gameMode)
864  gameMode.GetOnPlayerSpawned().Remove(InitOnSpawn);
865  }
866 
867  //------------------------------------------------------------------------------------------------
868  void ToggleHUDIcon(bool show, bool fade = true)
869  {
870  if (show)
871  {
872  AnimateWidget.StopAnimation(m_wHUDIcon, WidgetAnimationOpacity);
873  m_wHUDIcon.SetOpacity(1);
874  }
875  else
876  {
877  if (fade)
878  {
879  SCR_UITaskManagerComponent.GetInstance().KeepHUDIconUpdated(1000, this);
880  AnimateWidget.Opacity(m_wHUDIcon, 0, 1);
881  }
882  else
883  {
884  AnimateWidget.StopAnimation(m_wHUDIcon, WidgetAnimationOpacity);
885  m_wHUDIcon.SetOpacity(0);
886  }
887  }
888  }
889 
890  //------------------------------------------------------------------------------------------------
891  void UpdateHUDIcon()
892  {
893  vector pos = GetGame().GetWorkspace().ProjWorldToScreen(GetOrigin(), GetWorld());
894  if (pos[2] > 0)
895  {
896  if (!AnimateWidget.IsAnimating(m_wHUDIcon))
897  m_wHUDIcon.SetOpacity(1);
898  FrameSlot.SetPos(m_wHUDIcon, pos[0], pos[1]);
899  }
900  else
901  m_wHUDIcon.SetOpacity(0);
902  }
903 
904  //------------------------------------------------------------------------------------------------
905  Widget GetTaskIconkWidget()
906  {
907  return m_wMapTaskIcon;
908  }
909 
910  //------------------------------------------------------------------------------------------------
911  void SetTaskIconWidget(Widget w)
912  {
913  m_wMapTaskIcon = w;
914  }
915 
916  //************************//
917  //PROTECTED MEMBER METHODS//
918  //************************//
919 
920  protected void ShowPopUpNotification(string subtitle)
921  {
922  SCR_PopUpNotification.GetInstance().PopupMsg(GetTitleText(), text2: subtitle);
923  }
924 
925  //------------------------------------------------------------------------------------------------
926  protected void UpdateMapInfo()
927  {
928  }
929 
930  //------------------------------------------------------------------------------------------------
931  protected bool DoneByAssignee()
932  {
933  }
934 
935  //------------------------------------------------------------------------------------------------
936  protected void ShowTaskProgress(bool showMsg = true)
937  {
938  }
939 
940  //------------------------------------------------------------------------------------------------
942  protected void ShowAvailableTask(bool afterAssigneeRemoved = false)
943  {
944  }
945 
946  //------------------------------------------------------------------------------------------------
948  protected bool IsAssignedToLocalPlayer()
949  {
950  if (!IsAssigned())
951  return false;
952 
953  SCR_BaseTaskExecutor localExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
954  int localExecutorID = SCR_BaseTaskExecutor.GetTaskExecutorID(localExecutor);
955 
956  foreach (SCR_BaseTaskExecutor assignee : m_aAssignees)
957  {
958  int assigneeID = SCR_BaseTaskExecutor.GetTaskExecutorID(assignee);
959  if (assigneeID == localExecutorID)
960  return true;
961  }
962 
963  return false;
964  }
965 
966  //------------------------------------------------------------------------------------------------
969  void SetState(SCR_TaskState state)
970  {
971  if (state == m_eState)
972  return;
973 
974  // Let the script know that the state of this task has changed.
975  OnStateChanged(m_eState, state);
976 
977  m_eState = state;
978  }
979 
980  //******************************//
981  //PROTECTED MEMBER EVENT METHODS//
982  //******************************//
983 
984  //------------------------------------------------------------------------------------------------
986  protected void OnAssigneeRemoved(SCR_BaseTaskExecutor oldAssignee)
987  {
988  if (oldAssignee)
989  oldAssignee.AssignNewTask(null);
990 
991  if (m_aAssignees.Count() <= 0)
992  SetState(SCR_TaskState.OPENED);
993 
994  UpdateMapTaskIcon();
995  UpdateTaskListAssignee();
996  }
997 
998  //------------------------------------------------------------------------------------------------
1000  protected void OnAssigneeAdded(SCR_BaseTaskExecutor newAssignee)
1001  {
1002  if (newAssignee)
1003  newAssignee.AssignNewTask(this);
1004 
1005  UpdateMapTaskIcon();
1006  UpdateTaskListAssignee();
1007  }
1008 
1009  //------------------------------------------------------------------------------------------------
1011  protected void OnStateChanged(SCR_TaskState previousState, SCR_TaskState newState)
1012  {
1013  }
1014 
1015  //------------------------------------------------------------------------------------------------
1017  void RegisterTaskUpdate(SCR_ETaskEventMask TaskEventMask)
1018  {
1019  if (GetTaskManager())
1020  GetTaskManager().OnTaskUpdate(this, TaskEventMask);
1021  }
1022 
1023  //------------------------------------------------------------------------------------------------
1024  void Serialize(ScriptBitWriter writer)
1025  {
1026  FactionManager factionManager = GetGame().GetFactionManager();
1027  if (!factionManager)
1028  return;
1029 
1030  int factionIndex = factionManager.GetFactionIndex(m_TargetFaction);
1031  writer.Write(factionIndex, 4);
1032  writer.WriteInt(m_iTaskID);
1033  writer.WriteInt(GetTaskState());
1034  writer.WriteInt(GetTaskManager().m_mTaskEventMaskMap.Get(this));
1035  writer.WriteBool(m_bIndividualTask);
1036  writer.WriteFloat(GetLastAssigneeAddedTimestamp());
1037  writer.WriteString(GetTitle());
1038  writer.WriteString(GetDescription());
1039 
1040  int assigneesCount = m_aAssignees.Count();
1041  writer.Write(assigneesCount, 7);
1042 
1043  for (int i = 0; i < assigneesCount; i++)
1044  {
1045  int assigneeID = SCR_BaseTaskExecutor.GetTaskExecutorID(m_aAssignees[i]);
1046  writer.WriteInt(assigneeID);
1047  }
1048 
1049  writer.WriteVector(GetOrigin());
1050  }
1051 
1052  //------------------------------------------------------------------------------------------------
1053  void Deserialize(ScriptBitReader reader)
1054  {
1055  FactionManager factionManager = GetGame().GetFactionManager();
1056  if (!factionManager)
1057  return;
1058 
1059  // Reading factionIndex
1060  int factionIndex = 0;
1061  reader.Read(factionIndex, 4);
1062 
1063  SetTargetFaction(factionManager.GetFactionByIndex(factionIndex));
1064 
1065  // Reading m_iTaskID
1066  reader.ReadInt(m_iTaskID);
1067 
1068  // Reading Task State
1069  int taskState;
1070  reader.ReadInt(taskState);
1071  SetState(taskState);
1072 
1073  // Reading Task Mask
1074  int taskMask;
1075  reader.ReadInt(taskMask);
1076  GetTaskManager().m_mTaskEventMaskMap.Set(this, taskMask);
1077 
1078  // Reading m_bIndividualTask
1079  reader.ReadBool(m_bIndividualTask);
1080 
1081  // Reading m_fLastAssigneeAddedTimestamp
1082  reader.ReadFloat(m_fLastAssigneeAddedTimestamp);
1083 
1084  string text;
1085  // Reading title
1086  reader.ReadString(text);
1087  SetTitle(text);
1088 
1089  // Reading description
1090  reader.ReadString(text);
1091  SetDescription(text);
1092 
1093  // Reading target m_aAssignees.Count()
1094  int assigneesCount;
1095  reader.Read(assigneesCount, 7);
1096 
1097  int assigneeID;
1098  for (int i = 0; i < assigneesCount; i++)
1099  {
1100  // Reading assignee ID
1101  reader.ReadInt(assigneeID);
1102  SCR_BaseTaskExecutor assignee = SCR_BaseTaskExecutor.GetTaskExecutorByID(assigneeID);
1103  m_aAssignees.Insert(assignee);
1104  }
1105 
1106  // Reading position
1107  vector origin;
1108  reader.ReadVector(origin);
1109  SetOrigin(origin);
1110 
1111  GetTaskManager().RegisterTask(this);
1112  }
1113 
1114  //------------------------------------------------------------------------------------------------
1115  override void EOnInit(IEntity owner)
1116  {
1117  if (SCR_Global.IsEditMode(this) || !GetGame().GetGameMode())
1118  return;
1119 
1120  if (!GetTaskManager().IsProxy())
1121  {
1122  m_iTaskID = s_iCurrentTaskID;
1123  s_iCurrentTaskID++;
1124  }
1125 
1126  GetTaskManager().RegisterTask(this);
1127 
1128  SCR_BaseTaskManager.s_OnTaskCreated.Invoke(this);
1129 
1130  RegisterTaskUpdate(SCR_ETaskEventMask.TASK_CREATED);
1131 
1132  m_MapDescriptor = SCR_MapDescriptorComponent.Cast(FindComponent(SCR_MapDescriptorComponent));
1133 
1134  if (m_MapDescriptor)
1135  {
1136  SCR_MapEntity.GetOnMapOpen().Insert(OnMapOpen);
1137  SCR_MapEntity.GetOnHoverItem().Insert(OnHoverItem);
1138  }
1139  }
1140 
1141  //************************//
1142  //CONSTRUCTOR & DESTRUCTOR//
1143  //************************//
1144 
1145  //------------------------------------------------------------------------------------------------
1146  void SCR_BaseTask(IEntitySource src, IEntity parent)
1147  {
1148  SetEventMask(EntityEvent.INIT);
1149 
1150  CreateMapUIIcon();
1151 
1152  //HUD Icon setup
1153  Widget HUDIconRoot = GetGame().GetWorkspace().CreateWidgets(m_sHUDIcon);
1154  m_wHUDIcon = ImageWidget.Cast(HUDIconRoot.FindAnyWidget("TaskIcon"));
1155  m_wHUDIcon.SetOpacity(0);
1156  SetHUDIcon();
1157  //End of HUD Icon setup
1158  }
1159 
1160  //------------------------------------------------------------------------------------------------
1161  void ~SCR_BaseTask()
1162  {
1163  if (m_aAssignees)
1164  {
1165  m_aAssignees.Clear();
1166  m_aAssignees = null;
1167  }
1168 
1169  if (GetTaskManager())
1170  SCR_BaseTaskManager.s_OnTaskDeleted.Invoke(this);
1171  }
1172 };
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
SCR_BaseTaskClass
Definition: SCR_BaseTask.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_ERadioMsg
SCR_ERadioMsg
Definition: SCR_CampaignRadioMsg.c:138
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_TaskListEntryHandler
Definition: SCR_TaskListEntryHandler.c:2
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_PopUpNotification
Takes care of dynamic and static onscreen popups.
Definition: SCR_PopupNotification.c:24
SCR_BaseTask
A base class for tasks.
Definition: SCR_BaseTask.c:8
SCR_CharacterControllerComponent
Definition: SCR_CharacterControllerComponent.c:35
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
SCR_ECannotAssignReasons
SCR_ECannotAssignReasons
Definition: SCR_ECampaignTaskReasons.c:1
GetOrigin
vector GetOrigin()
Definition: SCR_AIUtilityComponent.c:279
IsProxy
protected bool IsProxy()
Definition: SCR_CampaignBuildingCompositionComponent.c:456
m_eState
EAITargetClusterState m_eState
Definition: SCR_AITargetClusterState.c:24
m_TargetFaction
protected Faction m_TargetFaction
Definition: SCR_EditableTaskComponent.c:22
Attribute
typedef Attribute
Post-process effect of scripted camera.
MapItem
Definition: MapItem.c:12
m_sDescription
string m_sDescription
Definition: SCR_FlashlightComponent.c:3
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
SCR_BaseTaskManager
Definition: SCR_BaseTaskManager.c:25
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
m_MapDescriptor
protected SCR_CampaignMilitaryBaseMapDescriptorComponent m_MapDescriptor
Definition: SCR_CampaignMilitaryBaseComponent.c:100
SCR_BaseTaskSupportEntity
Definition: SCR_BaseTaskSupportEntity.c:8
Faction
Definition: Faction.c:12
SCR_BaseTaskExecutor
Definition: SCR_BaseTaskExecutor.c:7
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_ETaskEventMask
SCR_ETaskEventMask
Definition: SCR_BaseTaskManager.c:13
SCR_Global
Definition: Functions.c:6
SCR_TaskState
SCR_TaskState
Definition: SCR_TaskState.c:2
m_sName
protected LocalizedString m_sName
Definition: SCR_GroupIdentityComponent.c:19
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26