Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ScenarioFrameworkStruct.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
4 {
5  protected int m_iHours = -1;
6  protected int m_iMinutes = -1;
7  protected int m_iSeconds = -1;
8  protected bool m_bMatchOver;
9  protected string m_sWeatherState;
10  protected EGameOverTypes m_eGameOverType = EGameOverTypes.COMBATPATROL_DRAW;
11  protected ref array<ref SCR_ScenarioFrameworkAreaStruct> m_aAreasStructs = {};
12 
13  //------------------------------------------------------------------------------------------------
14  override bool Serialize()
15  {
16  SCR_GameModeSFManager manager = SCR_GameModeSFManager.Cast(GetGame().GetGameMode().FindComponent(SCR_GameModeSFManager));
17  if (!manager)
18  return false;
19 
20  m_bMatchOver = manager.GetIsMatchOver();
21 
22  m_aAreasStructs.Clear();
23 
24  ChimeraWorld world = GetGame().GetWorld();
25  TimeAndWeatherManagerEntity timeManager = world.GetTimeAndWeatherManager();
26 
27  if (timeManager)
28  {
29  timeManager.GetHoursMinutesSeconds(m_iHours, m_iMinutes, m_iSeconds);
30  WeatherStateTransitionManager transitionManager = timeManager.GetTransitionManager();
31 
32  if (transitionManager)
33  m_sWeatherState = transitionManager.GetCurrentState().GetStateName();
34  }
35 
36  m_eGameOverType = manager.m_eGameOverType;
37  StoreAreaStates(manager, m_aAreasStructs);
38  ClearEmptyAreaStructs(m_aAreasStructs);
39 
40  return true;
41  }
42 
43  //------------------------------------------------------------------------------------------------
44  override bool Deserialize()
45  {
46  if (m_aAreasStructs.IsEmpty())
47  return false;
48 
49  SCR_GameModeSFManager manager = SCR_GameModeSFManager.Cast(GetGame().GetGameMode().FindComponent(SCR_GameModeSFManager));
50  if (!manager)
51  return false;
52 
53  // Game was saved after match was over, don't load
54  if (m_bMatchOver)
55  return false;
56 
57  SCR_TimeAndWeatherHandlerComponent timeHandler = SCR_TimeAndWeatherHandlerComponent.GetInstance();
58 
59  // Weather has to be changed after init
60  if (timeHandler && m_iHours >= 0 && m_iMinutes >= 0)
61  {
62  GetGame().GetCallqueue().Remove(timeHandler.SetupDaytimeAndWeather);
63  GetGame().GetCallqueue().CallLater(timeHandler.SetupDaytimeAndWeather, 500, false, m_iHours, m_iMinutes, m_iSeconds, m_sWeatherState, true);
64  }
65 
66  manager.m_eGameOverType = m_eGameOverType;
67  LoadAreaStates(manager, m_aAreasStructs);
68 
69  return true;
70  }
71 
72  //------------------------------------------------------------------------------------------------
75  void StoreAreaStates(notnull SCR_GameModeSFManager manager, out notnull array<ref SCR_ScenarioFrameworkAreaStruct> outEntries)
76  {
77  if (!manager.m_aAreas)
78  return;
79 
81  for (int i = manager.m_aAreas.Count() - 1; i >= 0; i--)
82  {
83  struct = new SCR_ScenarioFrameworkAreaStruct();
84  struct.StoreState(manager.m_aAreas[i], struct);
85  outEntries.Insert(struct);
86  }
87  }
88 
89  //------------------------------------------------------------------------------------------------
92  void LoadAreaStates(notnull SCR_GameModeSFManager manager, notnull array<ref SCR_ScenarioFrameworkAreaStruct> loadedAreaStruct)
93  {
94  IEntity entity;
96  foreach (SCR_ScenarioFrameworkAreaStruct areaStruct : loadedAreaStruct)
97  {
98  entity = GetGame().GetWorld().FindEntityByName(areaStruct.GetName());
99  if (!entity)
100  continue;
101 
102  area = SCR_ScenarioFrameworkArea.Cast(entity.FindComponent(SCR_ScenarioFrameworkArea));
103  if (!area)
104  continue;
105 
106  LoadAreaStructs(manager, area, areaStruct);
107  LoadNestedAreaStructs(areaStruct);
108  }
109  }
110 
111  //------------------------------------------------------------------------------------------------
112  protected void LoadAreaStructs(notnull SCR_GameModeSFManager manager, notnull SCR_ScenarioFrameworkArea area, notnull SCR_ScenarioFrameworkAreaStruct areaStruct)
113  {
114  if (areaStruct.GetAreaSelected())
115  {
116  manager.m_aAreasTasksToSpawn.Insert(areaStruct.GetName());
117  manager.m_aLayersTaskToSpawn.Insert(areaStruct.GetLayerTaskname());
118  }
119 
120  if (areaStruct.GetDeliveryPointNameForItem())
121  area.StoreDeliveryPoint(areaStruct.GetDeliveryPointNameForItem());
122 
123  if (areaStruct.GetRandomlySpawnedChildren())
124  area.SetRandomlySpawnedChildren(areaStruct.GetRandomlySpawnedChildren());
125 
126  LoadRepeatedSpawnAreaStructs(area, areaStruct);
127 
128  }
129 
130  //------------------------------------------------------------------------------------------------
131  protected void LoadRepeatedSpawnAreaStructs(notnull SCR_ScenarioFrameworkArea area, notnull SCR_ScenarioFrameworkAreaStruct areaStruct)
132  {
133  if (areaStruct.GetEnableRepeatedSpawn())
134  {
135  area.SetEnableRepeatedSpawn(areaStruct.GetEnableRepeatedSpawn());
136  if (areaStruct.GetRepeatedSpawnNumber())
137  area.SetRepeatedSpawnNumber(areaStruct.GetRepeatedSpawnNumber());
138  }
139  }
140 
141  //------------------------------------------------------------------------------------------------
142  protected void LoadNestedAreaStructs(notnull SCR_ScenarioFrameworkAreaStruct areaStruct)
143  {
144  if (areaStruct.GetLayerStructs())
145  LoadLayer(areaStruct.GetLayerStructs());
146 
147  if (areaStruct.GetLogicStructs())
148  LoadLogic(areaStruct.GetLogicStructs());
149  }
150 
151  //------------------------------------------------------------------------------------------------
152  protected void LoadLayer(notnull array<ref SCR_ScenarioFrameworkLayerStruct> loadedLayerStruct)
153  {
154  IEntity entity;
156  BaseWorld world = GetGame().GetWorld();
157  foreach (SCR_ScenarioFrameworkLayerStruct layerStruct : loadedLayerStruct)
158  {
159  entity = world.FindEntityByName(layerStruct.GetName());
160  if (!entity)
161  continue;
162 
163  layer = SCR_ScenarioFrameworkLayerBase.Cast(entity.FindComponent(SCR_ScenarioFrameworkLayerBase));
164  if (!layer)
165  continue;
166 
167  LoadLayerStructs(layer, layerStruct);
168  LoadNestedLayerStructs(layerStruct);
169  }
170  }
171 
172  //------------------------------------------------------------------------------------------------
173  protected void LoadLayerStructs(notnull SCR_ScenarioFrameworkLayerBase layer, notnull SCR_ScenarioFrameworkLayerStruct layerStruct)
174  {
175  if (layerStruct.GetActivationType() != -1)
176  layer.SetActivationType(layerStruct.GetActivationType());
177 
178  if (layerStruct.GetIsTerminated())
179  {
180  layer.SetIsTerminated(layerStruct.GetIsTerminated());
181  return;
182  }
183 
184  LoadRepeatedSpawnLayerStructs(layer, layerStruct);
185  LoadLayerStructSlots(layer, layerStruct);
186 
187  //Layer task handling
188  SCR_ScenarioFrameworkLayerTask layerTask = SCR_ScenarioFrameworkLayerTask.Cast(layer);
189  if (layerTask)
190  layerTask.SetLayerTaskState(layerStruct.GetLayerTaskState());
191 
192  if (layerStruct.GetRandomlySpawnedChildren())
193  layer.SetRandomlySpawnedChildren(layerStruct.GetRandomlySpawnedChildren());
194 
195  LoadNestedLayerStructs(layerStruct);
196  }
197 
198  //------------------------------------------------------------------------------------------------
199  protected void LoadRepeatedSpawnLayerStructs(notnull SCR_ScenarioFrameworkLayerBase layer, notnull SCR_ScenarioFrameworkLayerStruct layerStruct)
200  {
201  if (!layerStruct.GetEnableRepeatedSpawn())
202  return;
203 
204  layer.SetEnableRepeatedSpawn(true);
205  layer.SetRepeatedSpawnNumber(layerStruct.GetRepeatedSpawnNumber());
206  }
207 
208  //------------------------------------------------------------------------------------------------
209  protected void LoadLayerStructSlots(notnull SCR_ScenarioFrameworkLayerBase layer, notnull SCR_ScenarioFrameworkLayerStruct layerStruct)
210  {
213  slot = SCR_ScenarioFrameworkSlotBase.Cast(layer.FindComponent(SCR_ScenarioFrameworkSlotBase));
214  if (slot)
215  {
216  slotAI = SCR_ScenarioFrameworkSlotAI.Cast(slot.FindComponent(SCR_ScenarioFrameworkSlotAI));
217  if (slotAI)
218  {
219  if (layerStruct.GetAIPrefabsForRemoval())
220  slotAI.SetAIPrefabsForRemoval(layerStruct.GetAIPrefabsForRemoval());
221  }
222 
223  if (layerStruct.GetRandomlySpawnedObject())
224  slot.SetRandomlySpawnedObject(layerStruct.GetRandomlySpawnedObject());
225  }
226  }
227 
228  //------------------------------------------------------------------------------------------------
229  protected void LoadNestedLayerStructs(notnull SCR_ScenarioFrameworkLayerStruct layerStruct)
230  {
231  if (layerStruct.GetLayerStructs())
232  LoadLayer(layerStruct.GetLayerStructs());
233 
234  if (layerStruct.GetLogicStructs())
235  LoadLogic(layerStruct.GetLogicStructs());
236  }
237 
238  //------------------------------------------------------------------------------------------------
239  protected void LoadLogic(notnull array<ref SCR_ScenarioFrameworkLogicStruct> entries)
240  {
241  IEntity entity;
242  BaseWorld world = GetGame().GetWorld();
243  SCR_ScenarioFrameworkLogic logic;
244  SCR_ScenarioFrameworkLogicCounter logicCounter;
245  foreach (SCR_ScenarioFrameworkLogicStruct logicInfo : entries)
246  {
247  entity = world.FindEntityByName(logicInfo.GetName());
248  if (!entity)
249  continue;
250 
251  logic = SCR_ScenarioFrameworkLogic.Cast(entity);
252  if (!logic)
253  continue;
254 
255  if (logicInfo.GetIsTerminated())
256  {
257  logic.SetIsTerminated(logicInfo.GetIsTerminated());
258  continue;
259  }
260 
261  logicCounter = SCR_ScenarioFrameworkLogicCounter.Cast(entity);
262  if (!logicCounter)
263  continue;
264 
265  logicCounter.SetCounterValue(logicInfo.GetCounterValue());
266  }
267  }
268 
269  //------------------------------------------------------------------------------------------------
270  protected void ClearEmptyAreaStructs(notnull array<ref SCR_ScenarioFrameworkAreaStruct> areaStructsToClear)
271  {
272  array<ref SCR_ScenarioFrameworkAreaStruct> areasStructsCopy = {};
273  foreach (SCR_ScenarioFrameworkAreaStruct areaStructToCopy : areaStructsToClear)
274  {
275  areasStructsCopy.Insert(areaStructToCopy);
276  }
277 
278  foreach (SCR_ScenarioFrameworkAreaStruct areaStruct : areasStructsCopy)
279  {
280  if (areaStruct.GetStructVarCount() < 1)
281  {
282  areaStructsToClear.RemoveItem(areaStruct);
283  }
284  }
285  }
286 
287  //------------------------------------------------------------------------------------------------
289  {
290  RegV("m_iHours");
291  RegV("m_iMinutes");
292  RegV("m_iSeconds");
293  RegV("m_bMatchOver");
294  RegV("m_sWeatherState");
295  RegV("m_eGameOverType");
296  RegV("m_aAreasStructs");
297  }
298 };
299 
300 //------------------------------------------------------------------------------------------------
302 {
303  protected bool m_bAreaSelected;
304  protected string m_sItemDeliveryPointName;
305  protected string m_sLayerTaskName;
306 
307  //------------------------------------------------------------------------------------------------
310  void StoreState(notnull SCR_ScenarioFrameworkArea area, out notnull SCR_ScenarioFrameworkAreaStruct areaStruct)
311  {
312  //Checks if area is named. If it is not, we cannot use it for serialization
313  if (area.GetName().IsEmpty())
314  {
315  delete areaStruct;
316  return;
317  }
318 
319  areaStruct.SetName(area.GetName());
320 
321  StoreSelectedArea(area, areaStruct);
322  StoreDeliveryPoint(area, areaStruct);
323 
324  StoreActivationTypeStatus(area, areaStruct);
325  StoreTerminationStatus(area, areaStruct);
326  StoreRepeatedSpawn(area, areaStruct);
327  StoreLayerTask(area, areaStruct);
328 
329  StoreChildren(area, areaStruct);
330  StoreLogic(area, areaStruct);
331 
332  CleanEmptyStoredLayers(areaStruct);
333  CleanEmptyStoredLogic(areaStruct);
334  CleanAreaStructs(areaStruct);
335  }
336 
337  //------------------------------------------------------------------------------------------------
339  protected void StoreSelectedArea(notnull SCR_ScenarioFrameworkArea area, notnull SCR_ScenarioFrameworkAreaStruct areaStruct)
340  {
341  if (area.m_bAreaSelected)
342  {
343  areaStruct.IncreaseStructVarCount();
344  areaStruct.SetAreaSelected(1);
345  }
346  else
347  {
348  areaStruct.UnregV("m_bAreaSelected");
349  }
350  }
351 
352  //------------------------------------------------------------------------------------------------
354  protected void StoreDeliveryPoint(notnull SCR_ScenarioFrameworkArea area, notnull SCR_ScenarioFrameworkAreaStruct areaStruct)
355  {
356  if (!area.m_sItemDeliveryPointName.IsEmpty())
357  {
358  areaStruct.IncreaseStructVarCount();
359  areaStruct.SetDeliveryPointNameForItem(area.GetDeliveryPointName());
360  }
361  else
362  {
363  areaStruct.UnregV("m_sItemDeliveryPointName");
364  }
365  }
366 
367  //------------------------------------------------------------------------------------------------
369  void StoreActivationTypeStatus(notnull SCR_ScenarioFrameworkArea area, notnull SCR_ScenarioFrameworkAreaStruct areaStruct)
370  {
371  if (area.GetActivationType() != area.GetActivationType())
372  {
373  areaStruct.SetActivationType(area.GetActivationType());
374  areaStruct.IncreaseStructVarCount();
375  }
376  else
377  {
378  areaStruct.UnregV("m_eActivationType");
379  }
380  }
381 
382  //------------------------------------------------------------------------------------------------
384  protected void StoreTerminationStatus(notnull SCR_ScenarioFrameworkArea area, notnull SCR_ScenarioFrameworkAreaStruct areaStruct)
385  {
386  if (area.GetIsTerminated())
387  {
388  areaStruct.IncreaseStructVarCount();
389  areaStruct.SetIsTerminated(true);
390  }
391  else
392  {
393  areaStruct.UnregV("m_bIsTerminated");
394  }
395  }
396 
397  //------------------------------------------------------------------------------------------------
399  protected void StoreRepeatedSpawn(notnull SCR_ScenarioFrameworkArea area, notnull SCR_ScenarioFrameworkAreaStruct areaStruct)
400  {
401  if (area.GetEnableRepeatedSpawn())
402  {
403  areaStruct.IncreaseStructVarCount();
404  areaStruct.SetEnableRepeatedSpawn(area.GetEnableRepeatedSpawn());
405  if (area.GetRepeatedSpawnNumber() != -1)
406  {
407  areaStruct.IncreaseStructVarCount();
408  areaStruct.SetRepeatedSpawnNumber(area.GetRepeatedSpawnNumber());
409  }
410  else
411  {
412  areaStruct.UnregV("m_iRepeatedSpawnNumber");
413  }
414  }
415  else
416  {
417  areaStruct.UnregV("m_bEnableRepeatedSpawn");
418  areaStruct.UnregV("m_iRepeatedSpawnNumber");
419  }
420  }
421 
422  //------------------------------------------------------------------------------------------------
424  protected void StoreLayerTask(notnull SCR_ScenarioFrameworkArea area, notnull SCR_ScenarioFrameworkAreaStruct areaStruct)
425  {
426  if (area.m_LayerTask)
427  {
428  areaStruct.SetLayerTaskName(area.GetLayerTaskName());
429  areaStruct.IncreaseStructVarCount();
430  }
431  else
432  {
433  areaStruct.UnregV("m_sLayerTaskName");
434  }
435  }
436 
437  //------------------------------------------------------------------------------------------------
439  protected void StoreChildren(notnull SCR_ScenarioFrameworkArea area, notnull SCR_ScenarioFrameworkAreaStruct areaStruct)
440  {
441  array<SCR_ScenarioFrameworkLayerBase> children = {};
442  area.GetChildren(children);
443 
444  if (children.IsEmpty())
445  {
446  areaStruct.UnregV("m_aLayersStructs");
447  return;
448  }
449 
450  if (area.GetSpawnChildrenType() != SCR_EScenarioFrameworkSpawnChildrenType.ALL)
451  {
452  array<SCR_ScenarioFrameworkLayerBase> m_aRandomlySpawnedChildrenLayerBases = area.GetRandomlySpawnedChildren();
453  foreach (SCR_ScenarioFrameworkLayerBase child : m_aRandomlySpawnedChildrenLayerBases)
454  {
455  areaStruct.InsertRandomlySpawnedChildren(child.GetName());
456  }
457  if (!m_aRandomlySpawnedChildrenLayerBases.IsEmpty())
458  areaStruct.IncreaseStructVarCount();
459  }
460  else
461  {
462  areaStruct.UnregV("m_aRandomlySpawnedChildren");
463  }
464 
465  foreach (SCR_ScenarioFrameworkLayerBase layer : children)
466  {
467  areaStruct.StoreLayerState(layer);
468  }
469 
470  foreach (SCR_ScenarioFrameworkLayerStruct childLayerStruct : m_aLayersStructs)
471  {
472  if (childLayerStruct.GetStructVarCount() >= 1)
473  {
474  areaStruct.IncreaseStructVarCount();
475  return;
476  }
477  }
478  }
479 
480  //------------------------------------------------------------------------------------------------
482  protected void StoreLogic(notnull SCR_ScenarioFrameworkArea area, notnull SCR_ScenarioFrameworkAreaStruct areaStruct)
483  {
484  array<SCR_ScenarioFrameworkLogic> logics = {};
485  area.GetLogics(logics);
486 
487  if (logics.IsEmpty())
488  {
489  areaStruct.UnregV("m_aLogicStructs");
490  }
491  else
492  {
493  foreach (SCR_ScenarioFrameworkLogic logic : logics)
494  {
495  areaStruct.StoreLogicState(logic);
496  }
497 
498  if (!m_aLogic.IsEmpty())
499  areaStruct.IncreaseStructVarCount();
500  }
501  }
502 
503  //------------------------------------------------------------------------------------------------
505  protected void CleanEmptyStoredLayers(notnull SCR_ScenarioFrameworkAreaStruct areaStruct)
506  {
507  if (areaStruct.GetLayerStructs())
508  {
509  if (areaStruct.GetLayerStructs().IsEmpty())
510  areaStruct.UnregV("m_aLayersStructs");
511  }
512  else
513  {
514  areaStruct.UnregV("m_aLayersStructs");
515  }
516  }
517 
518  //------------------------------------------------------------------------------------------------
520  protected void CleanEmptyStoredLogic(notnull SCR_ScenarioFrameworkAreaStruct areaStruct)
521  {
522  if (areaStruct.GetLogicStructs())
523  {
524  if (areaStruct.GetLogicStructs().IsEmpty())
525  areaStruct.UnregV("m_aLogicStructs");
526  }
527  else
528  {
529  areaStruct.UnregV("m_aLogicStructs");
530  }
531  }
532 
533  //------------------------------------------------------------------------------------------------
535  protected void CleanAreaStructs(notnull SCR_ScenarioFrameworkAreaStruct areaStruct)
536  {
537  areaStruct.ClearEmptyLayerStructs(areaStruct.GetLayerStructs());
538  areaStruct.ClearEmptyLogicStructs(areaStruct.GetLogicStructs());
539 
540  areaStruct.UnregV("m_aAIPrefabsForRemoval");
541  areaStruct.UnregV("m_sRandomlySpawnedObject");
542  areaStruct.UnregV("m_iLayerTaskState");
543  }
544 
545  //------------------------------------------------------------------------------------------------
546  bool GetAreaSelected()
547  {
548  return m_bAreaSelected;
549  }
550 
551  //------------------------------------------------------------------------------------------------
552  string GetDeliveryPointNameForItem()
553  {
554  return m_sItemDeliveryPointName;
555  }
556 
557  //------------------------------------------------------------------------------------------------
558  string GetLayerTaskname()
559  {
560  return m_sLayerTaskName;
561  }
562 
563  //------------------------------------------------------------------------------------------------
564  void SetAreaSelected(bool selected)
565  {
566  m_bAreaSelected = selected;
567  }
568 
569  //------------------------------------------------------------------------------------------------
570  void SetDeliveryPointNameForItem(string name)
571  {
572  m_sItemDeliveryPointName = name;
573  }
574 
575  //------------------------------------------------------------------------------------------------
576  void SetLayerTaskName(string layerTaskName)
577  {
578  m_sLayerTaskName = layerTaskName;
579  }
580 
581  //------------------------------------------------------------------------------------------------
583  {
584  RegV("m_bAreaSelected");
585  RegV("m_sLayerTaskName");
586  RegV("m_sItemDeliveryPointName");
587  }
588 };
589 
590 //------------------------------------------------------------------------------------------------
592 {
593  protected string m_sName;
594  protected ResourceName m_sRandomlySpawnedObject;
595  protected ref array<ref SCR_ScenarioFrameworkLayerStruct> m_aLayersStructs = {};
596  protected ref array<ref SCR_ScenarioFrameworkLogicStruct> m_aLogicStructs = {};
597  protected ref array<SCR_ScenarioFrameworkLayerBase> m_aChildren = {};
598  protected ref array<SCR_ScenarioFrameworkLogic> m_aLogic = {};
599  protected ref array<ResourceName> m_aAIPrefabsForRemoval = {};
600  protected ref array<string> m_aRandomlySpawnedChildren = {};
601  protected int m_iLayerTaskState;
602  protected SCR_ScenarioFrameworkEActivationType m_eActivationType = -1; // We put default value as -1 here because 0 has other implications down the line
603  protected bool m_bIsTerminated; //Marks if this was terminated - either by death or deletion
604  protected int m_iRepeatedSpawnNumber;
605  protected bool m_bEnableRepeatedSpawn;
606  protected int m_iStructVarCount;
607 
608  //------------------------------------------------------------------------------------------------
609  void StoreLayerState(notnull SCR_ScenarioFrameworkLayerBase layer)
610  {
612 
613  //Checks if layer is named. If it is not, we cannot use it for serialization
614  if (layer.GetName().IsEmpty())
615  {
616  delete layerStruct;
617  return;
618  }
619 
620  layerStruct.SetName(layer.GetName());
621 
622  StoreActivationTypeStatus(layer, layerStruct);
623  StoreTerminationStatus(layer, layerStruct);
624  StoreRepeatedSpawn(layer, layerStruct);
625  StoreLayerTask(layer, layerStruct);
626 
627  StoreChildren(layer, layerStruct);
628  StoreLogic(layer, layerStruct);
629 
630  StoreSlotAndRandomObject(layer, layerStruct);
631 
632  CleanEmptyStoredLayers(layer, layerStruct);
633  CleanEmptyStoredLogic(layer, layerStruct);
634 
635  //Final insertion
636  if (layerStruct && layerStruct.GetStructVarCount() > 0)
637  m_aLayersStructs.Insert(layerStruct);
638 
639  CleanEmptyStructs();
640  }
641 
642  //------------------------------------------------------------------------------------------------
644  void StoreActivationTypeStatus(notnull SCR_ScenarioFrameworkLayerBase layer, notnull SCR_ScenarioFrameworkLayerStruct layerStruct)
645  {
646  if (layer.GetActivationType() != layer.GetActivationType())
647  {
648  layerStruct.SetActivationType(layer.GetActivationType());
649  layerStruct.IncreaseStructVarCount();
650  }
651  else
652  {
653  layerStruct.UnregV("m_eActivationType");
654  }
655  }
656 
657  //------------------------------------------------------------------------------------------------
659  void StoreTerminationStatus(notnull SCR_ScenarioFrameworkLayerBase layer, notnull SCR_ScenarioFrameworkLayerStruct layerStruct)
660  {
661  if (layer.GetIsTerminated())
662  {
663  layerStruct.SetIsTerminated(true);
664  layerStruct.IncreaseStructVarCount();
665  }
666  else
667  {
668  layerStruct.UnregV("m_bIsTerminated");
669  }
670  }
671 
672  //------------------------------------------------------------------------------------------------
674  void StoreRepeatedSpawn(notnull SCR_ScenarioFrameworkLayerBase layer, notnull SCR_ScenarioFrameworkLayerStruct layerStruct)
675  {
676  if (layer.GetEnableRepeatedSpawn())
677  {
678  layerStruct.SetEnableRepeatedSpawn(layer.GetEnableRepeatedSpawn());
679  layerStruct.IncreaseStructVarCount();
680  if (layer.GetRepeatedSpawnNumber() != -1)
681  {
682  layerStruct.IncreaseStructVarCount();
683  layerStruct.SetRepeatedSpawnNumber(layer.GetRepeatedSpawnNumber());
684  }
685  else
686  {
687  layerStruct.UnregV("m_iRepeatedSpawnNumber");
688  }
689  }
690  else
691  {
692  layerStruct.UnregV("m_bEnableRepeatedSpawn");
693  layerStruct.UnregV("m_iRepeatedSpawnNumber");
694  }
695  }
696 
697  //------------------------------------------------------------------------------------------------
699  void StoreLayerTask(notnull SCR_ScenarioFrameworkLayerBase layer, notnull SCR_ScenarioFrameworkLayerStruct layerStruct)
700  {
701  SCR_ScenarioFrameworkLayerTask layerTask = SCR_ScenarioFrameworkLayerTask.Cast(layer);
702  if (layerTask && layerTask.GetLayerTaskState() != 0)
703  {
704  layerStruct.SetLayerTaskState(layerTask.GetLayerTaskState());
705  layerStruct.IncreaseStructVarCount();
706  }
707  else
708  {
709  layerStruct.UnregV("m_iLayerTaskState");
710  }
711  }
712 
713  //------------------------------------------------------------------------------------------------
715  void StoreChildren(notnull SCR_ScenarioFrameworkLayerBase layer, notnull SCR_ScenarioFrameworkLayerStruct layerStruct)
716  {
717  layer.GetChildren(m_aChildren);
718  if (m_aChildren.IsEmpty())
719  {
720  layerStruct.UnregV("m_aLayersStructs");
721  return;
722  }
723 
724  if (layer.GetSpawnChildrenType() != SCR_EScenarioFrameworkSpawnChildrenType.ALL)
725  {
726  array <SCR_ScenarioFrameworkLayerBase> m_aRandomlySpawnedChildrenLayerBases = layer.GetRandomlySpawnedChildren();
727  foreach (SCR_ScenarioFrameworkLayerBase child : m_aRandomlySpawnedChildrenLayerBases)
728  {
729  layerStruct.InsertRandomlySpawnedChildren(child.GetName());
730  }
731 
732  if (!m_aRandomlySpawnedChildrenLayerBases.IsEmpty())
733  layerStruct.IncreaseStructVarCount();
734  }
735  else
736  layerStruct.UnregV("m_aRandomlySpawnedChildren");
737 
738  foreach (SCR_ScenarioFrameworkLayerBase layerToCycle : m_aChildren)
739  {
740  layerStruct.StoreLayerState(layerToCycle);
741  }
742 
743  foreach (SCR_ScenarioFrameworkLayerStruct childLayerStruct : m_aLayersStructs)
744  {
745  // We need to check if just one child layer struct has something saved
746  if (childLayerStruct.GetStructVarCount() >= 1)
747  {
748  // Then we can increase this layer struct and return it
749  layerStruct.IncreaseStructVarCount();
750  return;
751  }
752  }
753  }
754 
755  //------------------------------------------------------------------------------------------------
757  void StoreLogic(notnull SCR_ScenarioFrameworkLayerBase layer, notnull SCR_ScenarioFrameworkLayerStruct layerStruct)
758  {
759  layer.GetLogics(m_aLogic);
760  if (m_aLogic.IsEmpty())
761  {
762  layerStruct.UnregV("m_aLogicStructs");
763  }
764  else
765  {
766  foreach (SCR_ScenarioFrameworkLogic logic : m_aLogic)
767  {
768  layerStruct.StoreLogicState(logic);
769  }
770 
771  if (!m_aLogic.IsEmpty())
772  layerStruct.IncreaseStructVarCount();
773  }
774  }
775 
776  //------------------------------------------------------------------------------------------------
778  void StoreSlotAndRandomObject(notnull SCR_ScenarioFrameworkLayerBase layer, notnull SCR_ScenarioFrameworkLayerStruct layerStruct)
779  {
781  if (slot)
782  {
784  if (slotAI && !slotAI.GetAIPrefabsForRemoval().IsEmpty() && !slotAI.GetIsTerminated())
785  {
786  layerStruct.SetAIPrefabsForRemoval(slotAI.GetAIPrefabsForRemoval());
787  layerStruct.IncreaseStructVarCount();
788  }
789  else
790  {
791  layerStruct.UnregV("m_aAIPrefabsForRemoval");
792  }
793 
794  if (slot.GetRandomlySpawnedObject())
795  {
796  layerStruct.SetRandomlySpawnedObject(slot.GetRandomlySpawnedObject());
797  layerStruct.IncreaseStructVarCount();
798  }
799  else
800  {
801  layerStruct.UnregV("m_sRandomlySpawnedObject");
802  }
803  }
804  else
805  {
806  layerStruct.UnregV("m_aAIPrefabsForRemoval");
807  layerStruct.UnregV("m_sRandomlySpawnedObject");
808  }
809  }
810 
811  //------------------------------------------------------------------------------------------------
813  void CleanEmptyStoredLayers(notnull SCR_ScenarioFrameworkLayerBase layer, notnull SCR_ScenarioFrameworkLayerStruct layerStruct)
814  {
815  if (layerStruct.GetLayerStructs())
816  {
817  if (layerStruct.GetLayerStructs().IsEmpty())
818  layerStruct.UnregV("m_aLayersStructs");
819  }
820  else
821  {
822  layerStruct.UnregV("m_aLayersStructs");
823  }
824  }
825 
826  //------------------------------------------------------------------------------------------------
828  void CleanEmptyStoredLogic(notnull SCR_ScenarioFrameworkLayerBase layer, notnull SCR_ScenarioFrameworkLayerStruct layerStruct)
829  {
830  if (layerStruct.GetLogicStructs())
831  {
832  if (layerStruct.GetLogicStructs().IsEmpty())
833  layerStruct.UnregV("m_aLogicStructs");
834  }
835  else
836  {
837  layerStruct.UnregV("m_aLogicStructs");
838  }
839  }
840 
841  //------------------------------------------------------------------------------------------------
842  void CleanEmptyStructs()
843  {
844  //Clears empty layer structs which are unnecessary to be saved
845  ClearEmptyLayerStructs(m_aLayersStructs);
846 
847  //Clears empty logic structs which are unnecessary to be saved
848  ClearEmptyLogicStructs(m_aLogicStructs);
849 
850  }
851 
852  //------------------------------------------------------------------------------------------------
853  void StoreLogicState(notnull SCR_ScenarioFrameworkLogic logic)
854  {
856 
857  SCR_ScenarioFrameworkLogicCounter logicCounter = SCR_ScenarioFrameworkLogicCounter.Cast(logic);
858  if (logicCounter)
859  {
860  //Checks if layer is named. If it is not, we cannot use it for serialization
861  if (logicCounter.GetName())
862  {
863  logicStruct.IncreaseStructVarCount();
864  logicStruct.SetName(logicCounter.GetName());
865  }
866  else
867  {
868  delete logicStruct;
869  return;
870  }
871 
872  StoreLogicCounterValue(logicCounter, logicStruct);
873  StoreLogicCounterTermination(logicCounter, logicStruct);
874 
875  if (logicStruct && logicStruct.GetStructVarCount() > 1)
876  {
877  m_aLogicStructs.Insert(logicStruct);
878  return;
879  }
880  }
881 
882  delete logicStruct;
883  }
884 
885  //------------------------------------------------------------------------------------------------
887  void StoreLogicCounterValue(notnull SCR_ScenarioFrameworkLogicCounter logicCounter, notnull SCR_ScenarioFrameworkLogicStruct logicStruct)
888  {
889  if (logicCounter.GetCounterValue() == 0)
890  {
891  logicStruct.UnregV("m_iCounterValue");
892  }
893  else
894  {
895  logicStruct.IncreaseStructVarCount();
896  logicStruct.SetCounterValue(logicCounter.GetCounterValue());
897  }
898  }
899 
900  //------------------------------------------------------------------------------------------------
902  void StoreLogicCounterTermination(notnull SCR_ScenarioFrameworkLogicCounter logicCounter, notnull SCR_ScenarioFrameworkLogicStruct logicStruct)
903  {
904  if (logicCounter.GetIsTerminated())
905  {
906  logicStruct.IncreaseStructVarCount();
907  logicStruct.SetIsTerminated(true);
908  }
909  else
910  {
911  logicStruct.UnregV("m_bIsTerminated");
912  }
913  }
914 
915  //------------------------------------------------------------------------------------------------
916  void ClearEmptyLayerStructs(notnull array<ref SCR_ScenarioFrameworkLayerStruct> layerStructsToClear)
917  {
918  array<ref SCR_ScenarioFrameworkLayerStruct> layersStructsCopy = {};
919  foreach (SCR_ScenarioFrameworkLayerStruct layerStructToCopy : layerStructsToClear)
920  {
921  layersStructsCopy.Insert(layerStructToCopy);
922  }
923 
924  foreach (SCR_ScenarioFrameworkLayerStruct layerStruct : layersStructsCopy)
925  {
926  if (layerStruct.GetStructVarCount() < 1)
927  layerStructsToClear.RemoveItem(layerStruct);
928  else
929  ClearEmptyLayerStructs(layerStruct.GetLayerStructs());
930  }
931  }
932 
933  //------------------------------------------------------------------------------------------------
934  void ClearEmptyLogicStructs(notnull array<ref SCR_ScenarioFrameworkLogicStruct> logicStructsToClear)
935  {
936  array<ref SCR_ScenarioFrameworkLogicStruct> logicsStructsCopy = {};
937  foreach (SCR_ScenarioFrameworkLogicStruct logicStructToCopy : logicStructsToClear)
938  {
939  logicsStructsCopy.Insert(logicStructToCopy);
940  }
941 
942  foreach (SCR_ScenarioFrameworkLogicStruct logicStruct : logicsStructsCopy)
943  {
944  if (logicStruct.GetStructVarCount() <= 1)
945  logicStructsToClear.RemoveItem(logicStruct);
946  }
947  }
948 
949  //------------------------------------------------------------------------------------------------
950  void IncreaseStructVarCount()
951  {
952  m_iStructVarCount += 1;
953  }
954 
955  //------------------------------------------------------------------------------------------------
956  void DecreaseStructVarCount()
957  {
958  m_iStructVarCount -= 1;
959  }
960 
961  //------------------------------------------------------------------------------------------------
962  array<ref SCR_ScenarioFrameworkLayerStruct> GetLayerStructs()
963  {
964  return m_aLayersStructs;
965  }
966 
967  //------------------------------------------------------------------------------------------------
968  array<ref SCR_ScenarioFrameworkLogicStruct> GetLogicStructs()
969  {
970  return m_aLogicStructs;
971  }
972 
973  //------------------------------------------------------------------------------------------------
974  array<string> GetRandomlySpawnedChildren()
975  {
977  }
978 
979  //------------------------------------------------------------------------------------------------
980  int GetStructVarCount()
981  {
982  return m_iStructVarCount;
983  }
984 
985  //------------------------------------------------------------------------------------------------
986  SCR_ScenarioFrameworkEActivationType GetActivationType()
987  {
988  return m_eActivationType;
989  }
990 
991  //------------------------------------------------------------------------------------------------
992  bool GetIsTerminated()
993  {
994  return m_bIsTerminated;
995  }
996 
997  //------------------------------------------------------------------------------------------------
998  ref array<ResourceName> GetAIPrefabsForRemoval()
999  {
1000  return m_aAIPrefabsForRemoval;
1001  }
1002 
1003  //------------------------------------------------------------------------------------------------
1004  string GetName()
1005  {
1006  return m_sName;
1007  }
1008 
1009  //------------------------------------------------------------------------------------------------
1010  int GetLayerTaskState()
1011  {
1012  return m_iLayerTaskState;
1013  }
1014 
1015  //------------------------------------------------------------------------------------------------
1016  ResourceName GetRandomlySpawnedObject()
1017  {
1018  return m_sRandomlySpawnedObject;
1019  }
1020 
1021  //------------------------------------------------------------------------------------------------
1022  int GetRepeatedSpawnNumber()
1023  {
1024  return m_iRepeatedSpawnNumber;
1025  }
1026 
1027  //------------------------------------------------------------------------------------------------
1028  bool GetEnableRepeatedSpawn()
1029  {
1030  return m_bEnableRepeatedSpawn;
1031  }
1032 
1033  //--------------------- Setters:
1034 
1035  //------------------------------------------------------------------------------------------------
1036  void InsertRandomlySpawnedChildren(string child)
1037  {
1038  m_aRandomlySpawnedChildren.Insert(child);
1039  }
1040 
1041  //------------------------------------------------------------------------------------------------
1042  void SetActivationType(SCR_ScenarioFrameworkEActivationType type)
1043  {
1045  }
1046 
1047  //------------------------------------------------------------------------------------------------
1048  void SetIsTerminated(bool state)
1049  {
1050  m_bIsTerminated = state;
1051  }
1052 
1053  //------------------------------------------------------------------------------------------------
1054  void SetName(string name)
1055  {
1056  m_sName = name;
1057  }
1058 
1059  //------------------------------------------------------------------------------------------------
1060  void SetLayerTaskState(int state)
1061  {
1062  m_iLayerTaskState = state;
1063  }
1064 
1065  //------------------------------------------------------------------------------------------------
1066  void SetAIPrefabsForRemoval(array<ResourceName> arrayForRemoval)
1067  {
1068  m_aAIPrefabsForRemoval = arrayForRemoval;
1069  }
1070 
1071  //------------------------------------------------------------------------------------------------
1072  void SetRandomlySpawnedObject(ResourceName name)
1073  {
1074  m_sRandomlySpawnedObject = name;
1075  }
1076 
1077  //------------------------------------------------------------------------------------------------
1078  void SetRepeatedSpawnNumber(int number)
1079  {
1080  m_iRepeatedSpawnNumber = number;
1081  }
1082 
1083  //------------------------------------------------------------------------------------------------
1084  void SetEnableRepeatedSpawn(bool value)
1085  {
1086  m_bEnableRepeatedSpawn = value;
1087  }
1088 
1089  //------------------------------------------------------------------------------------------------
1091  {
1092  RegV("m_sName");
1093  RegV("m_sRandomlySpawnedObject");
1094  RegV("m_eActivationType");
1095  RegV("m_bIsTerminated");
1096  RegV("m_aLayersStructs");
1097  RegV("m_aLogicStructs");
1098  RegV("m_iRepeatedSpawnNumber");
1099  RegV("m_aAIPrefabsForRemoval");
1100  RegV("m_bEnableRepeatedSpawn");
1101  RegV("m_aRandomlySpawnedChildren");
1102  RegV("m_iLayerTaskState");
1103  }
1104 };
1105 
1106 //------------------------------------------------------------------------------------------------
1108 {
1109  protected string m_sName;
1110  protected int m_iCounterValue;
1111  protected bool m_bIsTerminated; //Marks if this was terminated - either by death or deletion
1112 
1113  protected int m_iStructVarCount;
1114 
1115  //------------------------------------------------------------------------------------------------
1116  void IncreaseStructVarCount()
1117  {
1118  m_iStructVarCount += 1;
1119  }
1120 
1121  //------------------------------------------------------------------------------------------------
1122  int GetStructVarCount()
1123  {
1124  return m_iStructVarCount;
1125  }
1126 
1127  //------------------------------------------------------------------------------------------------
1128  bool GetIsTerminated()
1129  {
1130  return m_bIsTerminated;
1131  }
1132 
1133  //------------------------------------------------------------------------------------------------
1134  string GetName()
1135  {
1136  return m_sName;
1137  }
1138 
1139  //------------------------------------------------------------------------------------------------
1140  int GetCounterValue()
1141  {
1142  return m_iCounterValue;
1143  }
1144 
1145  //--------------------- Setters:
1146 
1147  //------------------------------------------------------------------------------------------------
1148  void SetIsTerminated(bool state)
1149  {
1150  m_bIsTerminated = state;
1151  }
1152 
1153  //------------------------------------------------------------------------------------------------
1154  void SetName(string name)
1155  {
1156  m_sName = name;
1157  }
1158 
1159  //------------------------------------------------------------------------------------------------
1160  void SetCounterValue(int value)
1161  {
1162  m_iCounterValue = value;
1163  }
1164 
1165  //------------------------------------------------------------------------------------------------
1167  {
1168  RegV("m_sName");
1169  RegV("m_bIsTerminated");
1170  RegV("m_iCounterValue");
1171  }
1172 };
WeatherStateTransitionManager
Definition: WeatherStateTransitionManager.c:7
ChimeraWorld
Definition: ChimeraWorld.c:12
SCR_ScenarioFrameworkLogicStruct
Definition: SCR_ScenarioFrameworkStruct.c:1107
m_eActivationType
protected SCR_ScenarioFrameworkEActivationType m_eActivationType
Definition: SCR_ScenarioFrameworkLayerBase.c:43
m_iHours
protected int m_iHours
Definition: SCR_WristwatchComponent.c:51
m_eGameOverType
EGameOverTypes m_eGameOverType
Definition: SCR_GameModeSFManager.c:63
m_aAIPrefabsForRemoval
ref array< ResourceName > m_aAIPrefabsForRemoval
Definition: SCR_ScenarioFrameworkSlotAI.c:49
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_bEnableRepeatedSpawn
protected bool m_bEnableRepeatedSpawn
Definition: SCR_ScenarioFrameworkLayerBase.c:31
m_aRandomlySpawnedChildren
protected ref array< SCR_ScenarioFrameworkLayerBase > m_aRandomlySpawnedChildren
Definition: SCR_ScenarioFrameworkLayerBase.c:58
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
EGameOverTypes
EGameOverTypes
Definition: EGameOverTypes.c:1
m_iRepeatedSpawnNumber
protected int m_iRepeatedSpawnNumber
Definition: SCR_ScenarioFrameworkLayerBase.c:34
SCR_ScenarioFrameworkSlotBase
void SCR_ScenarioFrameworkSlotBase(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_ScenarioFrameworkSlotBase.c:661
m_bMatchOver
protected bool m_bMatchOver
Definition: SCR_GameModeCampaign.c:102
SCR_ScenarioFrameworkArea
Definition: SCR_ScenarioFrameworkArea.c:24
m_aChildren
protected ref array< SCR_ScenarioFrameworkLayerBase > m_aChildren
Definition: SCR_ScenarioFrameworkLayerBase.c:57
SCR_ScenarioFrameworkStruct
Definition: SCR_ScenarioFrameworkStruct.c:3
m_iSeconds
SCR_WristwatchComponentClass m_iSeconds
SCR_ScenarioFrameworkSlotAI
void SCR_ScenarioFrameworkSlotAI(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_ScenarioFrameworkSlotAI.c:558
SCR_ScenarioFrameworkAreaStruct
Definition: SCR_ScenarioFrameworkStruct.c:301
BaseContainerProps
SCR_ScenarioFrameworkStruct BaseContainerProps
SCR_ScenarioFrameworkLayerStruct
Definition: SCR_ScenarioFrameworkStruct.c:591
m_bIsTerminated
protected bool m_bIsTerminated
Definition: SCR_ScenarioFrameworkLayerBase.c:75
m_iMinutes
protected int m_iMinutes
Definition: SCR_WristwatchComponent.c:50
SCR_EScenarioFrameworkSpawnChildrenType
SCR_EScenarioFrameworkSpawnChildrenType
Definition: SCR_ScenarioFrameworkLayerBase.c:11
SCR_ScenarioFrameworkLayerBase
void SCR_ScenarioFrameworkLayerBase(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_ScenarioFrameworkLayerBase.c:875
m_aLogic
protected ref array< SCR_ScenarioFrameworkLogic > m_aLogic
Definition: SCR_ScenarioFrameworkLayerBase.c:59
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
SCR_JsonApiStruct
Definition: SCR_JsonApiStruct.c:5
m_sName
protected LocalizedString m_sName
Definition: SCR_GroupIdentityComponent.c:19