Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignTaskSupportEntity.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 [EntityEditorProps(category: "GameScripted/Tasks", description: "Campaign task support entity.", color: "0 0 255 255")]
4 {
5 };
6 
7 //------------------------------------------------------------------------------------------------
9 {
10  protected bool m_bInitialTasksGenerated = false;
11  protected ref array<SCR_CampaignMilitaryBaseComponent> m_aCheckedBases = {};
12 
13  //------------------------------------------------------------------------------------------------
15  //TODO: Remove this method after no longer needed.
17  {
18  if (!GetTaskManager())
19  return null;
20 
21  array<SCR_BaseTask> tasks = {};
22  int count = GetTaskManager().GetTasks(tasks);
23 
24  for (int i = count - 1; i >= 0; i--)
25  {
26  SCR_CampaignTask castTask = SCR_CampaignTask.Cast(tasks[i]);
27 
28  if (!castTask)
29  continue;
30 
31  if (castTask.GetType() == type && castTask.GetTargetBase() == targetBase && castTask.GetTargetFaction() == targetFaction)
32  return castTask;
33  }
34  return null;
35  }
36 
37  //------------------------------------------------------------------------------------------------
41  void GenerateCaptureTasks(notnull IEntity entity)
42  {
43  if (!GetTaskManager())
44  return;
45 
47  array<SCR_CampaignMilitaryBaseComponent> bases = new array<SCR_CampaignMilitaryBaseComponent>();
48  SCR_CampaignFaction faction;
50 
51  if (capturedBase)
52  {
53  // It's a base
54  m_aCheckedBases.Insert(capturedBase);
55  GenerateRecaptureTask(capturedBase);
56  faction = capturedBase.GetCampaignFaction();
57 
58  if (!faction)
59  return;
60 
61  if (!capturedBase.IsHQRadioTrafficPossible(faction))
62  return;
63 
64  capturedBase.GetBasesInRange(SCR_ECampaignBaseType.BASE | SCR_ECampaignBaseType.RELAY, bases);
65 
66  foreach (SCR_CampaignMilitaryBaseComponent base: bases)
67  {
68  if (base.IsHQ())
69  continue;
70 
71  if (GetTask(base, faction, type))
72  continue;
73 
74  if (base.GetFaction() == faction)
75  {
76  if (m_aCheckedBases.Contains(base))
77  continue;
78 
79  GenerateCaptureTasks(base.GetOwner());
80  continue;
81  }
82 
83  CreateNewCampaignTask(type, base, faction, true);
84  }
85  }
86  else
87  {
88  // It's a mobile HQ
89  SCR_CampaignMobileAssemblyComponent comp = SCR_CampaignMobileAssemblyComponent.Cast(entity.FindComponent(SCR_CampaignMobileAssemblyComponent));
90 
91  if (!comp)
92  return;
93 
94  faction = comp.GetParentFaction();
95  comp.GetBasesInRange(bases);
96 
97  foreach (SCR_CampaignMilitaryBaseComponent base: bases)
98  {
99  if (GetTask(base, faction, type))
100  continue;
101 
102  if (base.IsHQ())
103  continue;
104 
105  if (base.GetFaction() == faction)
106  {
107  if (m_aCheckedBases.Contains(base))
108  continue;
109 
110  GenerateCaptureTasks(base.GetOwner());
111  continue;
112  }
113 
114  CreateNewCampaignTask(type, base, faction, true);
115  }
116  }
117  }
118 
119  //------------------------------------------------------------------------------------------------
120  protected void GenerateRecaptureTask(notnull SCR_CampaignMilitaryBaseComponent capturedBase)
121  {
122  if (capturedBase.IsHQ())
123  return;
124 
125  if (!GetTaskManager())
126  return;
127 
128  SCR_CampaignFactionManager factionManager = SCR_CampaignFactionManager.Cast(GetGame().GetFactionManager());
129  if (!factionManager)
130  return;
131 
132  SCR_CampaignFaction owningFaction = capturedBase.GetCampaignFaction();
133  if (!owningFaction)
134  return;
135 
136  SCR_CampaignFaction opposingFaction = factionManager.GetEnemyFaction(owningFaction);
137  if (!opposingFaction)
138  return;
139 
140  if (GetTask(capturedBase, opposingFaction, SCR_CampaignTaskType.CAPTURE))
141  return;
142 
143  if (!capturedBase.IsHQRadioTrafficPossible(opposingFaction))
144  return;
145 
146  CreateNewCampaignTask(SCR_CampaignTaskType.CAPTURE, capturedBase, opposingFaction, true);
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  protected void GenerateInitialTasksForAllBases()
151  {
152  if (!GetTaskManager() || !GetTaskManager().Initialized() || m_bInitialTasksGenerated)
153  return;
154 
155  m_bInitialTasksGenerated = true;
156 
157  //On proxy we don't create any tasks, we skip the creation
158  if (GetTaskManager().IsProxy())
159  return;
160 
161  //Get bases manager
162  SCR_MilitaryBaseSystem manager = SCR_MilitaryBaseSystem.GetInstance();
163 
164  //Get all bases
165  array<SCR_MilitaryBaseComponent> bases = {};
166  manager.GetBases(bases);
167 
168  //Create start tasks for each base
169  for (int i = bases.Count() - 1; i >= 0; i--)
170  {
172 
173  if (!campaignBase || !campaignBase.IsInitialized())
174  continue;
175 
176  // Create tasks for this base
177  if (campaignBase.GetFaction())
178  GenerateNewTask(campaignBase);
179  }
180 
181  //Let the game mode know, the tasks are ready
183  if (gamemode)
184  gamemode.HandleOnTasksInitialized();
185  }
186 
187  //------------------------------------------------------------------------------------------------
190  void GenerateNewTask(SCR_CampaignMilitaryBaseComponent capturedBase)
191  {
192 #ifdef ENABLE_DIAG
193  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EXECUTE_TASKS))
194  return;
195 #endif
196 
197  GenerateCaptureTasks(capturedBase.GetOwner());
198  }
199 
200  //------------------------------------------------------------------------------------------------
202  void OnBaseCaptured(notnull SCR_MilitaryBaseComponent capturedBase, Faction faction)
203  {
204 #ifdef ENABLE_DIAG
205  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EXECUTE_TASKS))
206  return;
207 #endif
208 
210 
211  if (!campaignBase)
212  return;
213 
214  m_aCheckedBases.Clear();
215 
216  if (!GetTaskManager().IsProxy())
217  GenerateNewTask(campaignBase);
218  }
219 
220  //------------------------------------------------------------------------------------------------
221  void OnBaseSignalChanged(notnull SCR_CampaignMilitaryBaseComponent base)
222  {
223  OnBaseCaptured(base, null);
224  }
225 
226  //------------------------------------------------------------------------------------------------
228  SCR_CampaignTask CreateNewCampaignTask(SCR_CampaignTaskType type, SCR_CampaignMilitaryBaseComponent base, Faction faction, bool newTask = false)
229  {
230  if (!GetTaskManager())
231  return null;
232 
233  if (!base || !faction)
234  return null;
235 
236  if (type == SCR_CampaignTaskType.CAPTURE && (base.IsHQ() || (base.CanBeHQ() && base.GetDisableWhenUnusedAsHQ())))
237  return null;
238 
239  if (base.GetFaction() == faction && type == SCR_CampaignTaskType.CAPTURE)
240  return null;
241 
243  if (!task)
244  return null;
245 
246  SetTargetFaction(task, faction); // Replicated internally
247  SetTargetBase(task, base); // Replicated internally
248  SetTaskType(task, type); // Replicated internally
249 
250  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
251  if (campaign && newTask && SCR_FactionManager.SGetLocalPlayerFaction() == faction)
252  {
253  string text = task.TASK_AVAILABLE_TEXT + " " + task.GetTitle();
254  string baseName;
255 
256  if (task.GetTargetBase())
257  baseName = task.GetTargetBase().GetBaseNameUpperCase();
258 
259  SCR_PopUpNotification.GetInstance().PopupMsg(text, prio: SCR_ECampaignPopupPriority.TASK_AVAILABLE, param1: baseName, text2: task.TASK_HINT_TEXT, text2param1: SCR_PopUpNotification.TASKS_KEY_IMAGE_FORMAT, sound: SCR_SoundEvent.TASK_CREATED);
260  }
261 
262  return task;
263  }
264 
265  //------------------------------------------------------------------------------------------------
266  void SetTaskType(notnull SCR_CampaignTask task, SCR_CampaignTaskType type)
267  {
268  if (!GetTaskManager())
269  return;
270 
271  int taskID = task.GetTaskID();
272 
273  Rpc(RPC_SetTaskType, taskID, type);
274  RPC_SetTaskType(taskID, type);
275  }
276 
277  //------------------------------------------------------------------------------------------------
278  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
279  void RPC_SetTaskType(int taskID, SCR_CampaignTaskType type)
280  {
281  if (!GetTaskManager())
282  return;
283 
284  SCR_CampaignTask task = SCR_CampaignTask.Cast(GetTaskManager().GetTask(taskID));
285  if (!task)
286  return;
287 
288  task.SetType(type);
289  }
290 
291  //------------------------------------------------------------------------------------------------
292  override void Initialize()
293  {
294  // Timeout added to allow for backend load process
295  GetGame().GetCallqueue().CallLater(GenerateInitialTasksForAllBases, 2000);
296  }
297 
298  //------------------------------------------------------------------------------------------------
299  void SCR_CampaignTaskSupportEntity(IEntitySource src, IEntity parent)
300  {
301  //Register to script invokers
302  SCR_MilitaryBaseSystem baseManager = SCR_MilitaryBaseSystem.GetInstance();
303 
304  if (baseManager)
305  baseManager.GetOnBaseFactionChanged().Insert(OnBaseCaptured);
306 
307  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
308 
309  if (!campaign)
310  return;
311 
312  campaign.GetBaseManager().GetOnSignalChanged().Insert(OnBaseSignalChanged);
313  }
314 
315  //------------------------------------------------------------------------------------------------
317  {
318  //Unregister from script invokers
319  SCR_MilitaryBaseSystem baseManager = SCR_MilitaryBaseSystem.GetInstance();
320 
321  if (baseManager)
322  baseManager.GetOnBaseFactionChanged().Remove(OnBaseCaptured);
323 
324  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
325 
326  if (!campaign)
327  return;
328 
329  campaign.GetBaseManager().GetOnSignalChanged().Remove(OnBaseSignalChanged);
330  }
331 };
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
SCR_CampaignBaseTaskSupportEntityClass
Definition: SCR_CampaignBaseTaskSupportEntity.c:3
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_CampaignTaskSupportEntity
Definition: SCR_CampaignTaskSupportEntity.c:8
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
SCR_CampaignBaseTaskSupportEntity
Definition: SCR_CampaignBaseTaskSupportEntity.c:8
SCR_CampaignTaskSupportEntityClass
Definition: SCR_CampaignTaskSupportEntity.c:3
SCR_MilitaryBaseSystem
Definition: SCR_MilitaryBaseSystem.c:11
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
SCR_PopUpNotification
Takes care of dynamic and static onscreen popups.
Definition: SCR_PopupNotification.c:24
SCR_ECampaignBaseType
SCR_ECampaignBaseType
Definition: SCR_CampaignMilitaryBaseComponent.c:2577
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
SCR_GameModeCampaign
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition: SCR_GameModeCampaign.c:1927
SCR_CampaignTask
Definition: SCR_CampaignTask.c:7
SCR_CampaignTaskType
SCR_CampaignTaskType
Definition: SCR_CampaignTaskType.c:2
IsProxy
protected bool IsProxy()
Definition: SCR_CampaignBuildingCompositionComponent.c:456
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
SCR_ECampaignPopupPriority
SCR_ECampaignPopupPriority
Popup message priorities sorted from lowest to highest.
Definition: SCR_CampaignFeedbackComponent.c:1419
Faction
Definition: Faction.c:12
SCR_CampaignFaction
Definition: SCR_CampaignFaction.c:2
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
CreateTask
protected bool CreateTask()
Definition: SCR_ScenarioFrameworkLayerTask.c:389
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
SCR_CampaignMilitaryBaseComponent
Definition: SCR_CampaignMilitaryBaseComponent.c:38
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180