Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BaseTaskExecutor.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Tasks", description: "This this entity to receive and complete tasks.", color: "0 0 255 255")]
2 class SCR_BaseTaskExecutorClass: GenericEntityClass
3 {
4 };
5 
6 //------------------------------------------------------------------------------------------------
8 {
9 
10  static const int INVALID_PLAYER_ID = -1;
11  protected static ref map<SCR_BaseTaskExecutor, int> s_mTaskExecutors = new map<SCR_BaseTaskExecutor, int>();
12  protected static SCR_BaseTaskExecutor s_LocalTaskExecutor = null;
13 
14  //**************************//
15  //PROTECTED MEMBER VARIALBES//
16  //**************************//
17 
18  protected SCR_BaseTask m_CurrentTask;
19 
20  //*********************//
21  //PUBLIC STATIC METHODS//
22  //*********************//
23 
24  //------------------------------------------------------------------------------------------------
25  static map<SCR_BaseTaskExecutor, int> GetTaskExecutorsMap()
26  {
27  return s_mTaskExecutors;
28  }
29 
30  //------------------------------------------------------------------------------------------------
31  static int GetTaskExecutorID(SCR_BaseTaskExecutor taskExecutor)
32  {
33  if (!taskExecutor)
34  return INVALID_PLAYER_ID;
35 
36  return s_mTaskExecutors.Get(taskExecutor);
37  }
38 
39  //------------------------------------------------------------------------------------------------
40  static int GetLocalExecutorID()
41  {
42  return GetTaskExecutorID(GetLocalExecutor());
43  }
44 
45  //------------------------------------------------------------------------------------------------
47  static SCR_BaseTaskExecutor GetLocalExecutor()
48  {
49  if (s_LocalTaskExecutor)
50  return s_LocalTaskExecutor;
51 
52  PlayerController playerController = GetGame().GetPlayerController();
53  if (!playerController)
54  return null;
55 
56  int playerID = playerController.GetPlayerId();
57 
58  SCR_BaseTaskExecutor taskExecutor = s_mTaskExecutors.GetKeyByValue(playerID);
59 
60  // Local task executor not found, create new one
61  if (!taskExecutor)
62  taskExecutor = GetTaskManager().LocalCreateTaskExecutor(GetGame().GetPlayerController().GetPlayerId());
63 
64  return taskExecutor;
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  static SCR_BaseTaskExecutor FindTaskExecutorByID(int playerID)
69  {
70  return s_mTaskExecutors.GetKeyByValue(playerID);
71  }
72 
73  //------------------------------------------------------------------------------------------------
75  static notnull SCR_BaseTaskExecutor GetTaskExecutorByID(int playerID)
76  {
77  SCR_BaseTaskExecutor taskExecutor = s_mTaskExecutors.GetKeyByValue(playerID);
78 
79  if (!taskExecutor)
80  {
81  taskExecutor = GetTaskManager().LocalCreateTaskExecutor(playerID);
82  }
83 
84  return taskExecutor;
85  }
86 
87  //*********************//
88  //PUBLIC MEMBER METHODS//
89  //*********************//
90 
91  //------------------------------------------------------------------------------------------------
92  IEntity GetControlledEntity()
93  {
94  return SCR_PossessingManagerComponent.GetPlayerMainEntity(s_mTaskExecutors.Get(this));
95  }
96 
97  //------------------------------------------------------------------------------------------------
99  SCR_BaseTask GetAssignedTask()
100  {
101  return m_CurrentTask;
102  }
103 
104  //------------------------------------------------------------------------------------------------
106  string GetPlayerName()
107  {
108  return GetGame().GetPlayerManager().GetPlayerName(GetTaskExecutorID(this));
109  }
110 
111  //------------------------------------------------------------------------------------------------
113  void SetPlayerID(int playerID)
114  {
115  if (!s_mTaskExecutors || playerID == INVALID_PLAYER_ID)
116  return;
117 
118  s_mTaskExecutors.Set(this, playerID);
119  }
120 
121  //------------------------------------------------------------------------------------------------
123  void AssignNewTask(SCR_BaseTask task)
124  {
125  if (task == m_CurrentTask)
126  return;
127 
128  OnNewTaskAssigned(m_CurrentTask, task);
129  m_CurrentTask = task;
130  }
131 
132  //***************************//
133  //PUBLIC EVENT MEMBER METHODS//
134  //***************************//
135 
136  //------------------------------------------------------------------------------------------------
138  void OnAssignedTaskRemoved()
139  {
140  m_CurrentTask = null;
141  }
142 
143  //------------------------------------------------------------------------------------------------
145  void OnAssignedTaskFailed()
146  {
147  m_CurrentTask = null;
148  }
149 
150  //------------------------------------------------------------------------------------------------
152  void OnAssignedTaskFinished()
153  {
154  m_CurrentTask = null;
155  }
156 
157  //******************************//
158  //PROTECTED MEMBER EVENT METHODS//
159  //******************************//
160 
161  //------------------------------------------------------------------------------------------------
163  protected void OnNewTaskAssigned(SCR_BaseTask oldTask, SCR_BaseTask newTask)
164  {
165 
166  }
167 
168  //************************//
169  //CONSTRUCTOR & DESTRUCTOR//
170  //************************//
171 
172  //------------------------------------------------------------------------------------------------
173  void SCR_BaseTaskExecutor(IEntitySource src, IEntity parent)
174  {
175  if (s_mTaskExecutors)
176  s_mTaskExecutors.Insert(this, INVALID_PLAYER_ID);
177  }
178 
179  //------------------------------------------------------------------------------------------------
180  void ~SCR_BaseTaskExecutor()
181  {
182  if (s_mTaskExecutors)
183  s_mTaskExecutors.Remove(this);
184  }
185 
186 };
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_BaseTask
A base class for tasks.
Definition: SCR_BaseTask.c:8
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
SCR_BaseTaskExecutorClass
Definition: SCR_BaseTaskExecutor.c:2
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
SCR_BaseTaskExecutor
Definition: SCR_BaseTaskExecutor.c:7
INVALID_PLAYER_ID
SCR_TaskNetworkComponentClass INVALID_PLAYER_ID
Takes care of tasks-specific server <> client communication and requests.
GetPlayerId
proto external int GetPlayerId()
Definition: SCR_SpawnRequestComponent.c:39
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180