Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ScenarioFrameworkLayerBase.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/ScenarioFramework/Layer", description: "")]
4}
5
6// SCR_ScenarioFrameworkLayerBase Invoker
9typedef ScriptInvokerBase<ScriptInvokerScenarioFrameworkLayerMethod> ScriptInvokerScenarioFrameworkLayer;
10
18
20{
21 [Attribute(defvalue: "0", UIWidgets.ComboBox, desc: "Spawn all children, only random one or random multiple ones?", "", ParamEnumArray.FromEnum(SCR_EScenarioFrameworkSpawnChildrenType), category: "Children")]
23
24 [Attribute(desc: "Faction key that corresponds with the SCR_Faction set in FactionManager", category: "Asset")]
26
27 [Attribute(defvalue: "100", desc: "If the RANDOM_MULTIPLE option is selected, what's the percentage? ", UIWidgets.Graph, "0 100 1", category: "Children")]
29
30 [Attribute(desc: "When enabled, it will repeatedly spawn childern according to other parameters set", category: "Children")]
32
33 [Attribute(defvalue: "-1", desc: "If Repeated Spawn is enabled, how many times can children be spawned? If set to -1, it is unlimited", params: "-1 inf 1", category: "Children")]
35
36 [Attribute(defvalue: "-1", UIWidgets.Slider, desc: "If Repeated Spawn is enabled, how frequently it will spawn next wave of children? Value -1 means disabled, thus children won't be spawned by the elapsed time.", params: "-1 86400 1", category: "Children")]
38
39 [Attribute(desc: "Show the debug shapes during runtime", category: "Debug")]
41
42 [Attribute(desc: "Show the debug shapes in Workbench", category: "Debug")]
44
45 [Attribute("0", uiwidget: UIWidgets.ComboBox, "", "", ParamEnumArray.FromEnum(SCR_ScenarioFrameworkEActivationType), category: "Activation")]
47
48 [Attribute(desc: "Conditions that will be checked upon init and based on the result it will let this to finish init or not", category: "Activation")]
49 ref array<ref SCR_ScenarioFrameworkActivationConditionBase> m_aActivationConditions;
50
51 [Attribute(defvalue: SCR_EScenarioFrameworkLogicOperators.AND.ToString(), UIWidgets.ComboBox, "Which Boolean Logic will be used for Activation Conditions", "", enums: SCR_EScenarioFrameworkLogicOperatorHelper.GetParamInfo(), category: "Activation")]
53
54 [Attribute(desc: "Actions that will be activated on initalization.", category: "OnInit")]
55 ref array<ref SCR_ScenarioFrameworkActionBase> m_aActivationActions;
56
57 [Attribute(desc: "Should the dynamic Spawn/Despawn based on distance from observer cameras be enabled?", category: "Activation")]
59
60 [Attribute(defvalue: "750", params: "0 inf", desc: "How close at least one observer camera must be in order to trigger spawn", category: "Activation")]
62
63 [Attribute(desc: "", category: "Activation")]
65
66 [Attribute(UIWidgets.Auto, category: "Plugins")]
67 ref array<ref SCR_ScenarioFrameworkPlugin> m_aPlugins;
68
69 ref array<SCR_ScenarioFrameworkLayerBase> m_aChildren = {};
70 ref array<SCR_ScenarioFrameworkLayerBase> m_aRandomlySpawnedChildren = {};
71 ref array<SCR_ScenarioFrameworkLogic> m_aLogic = {};
72
73 ref ScriptInvokerBase<ScriptInvokerScenarioFrameworkLayerMethod> m_OnAllChildrenSpawned;
74 ref array<IEntity> m_aSpawnedEntities = {};
78 float m_fDebugShapeRadius = 0.25;
81 int m_iDebugShapeColor = ARGB(32, 255, 255, 255);
86 bool m_bIsTerminated; //Marks if this was terminated - either by death or deletion
87
88 //Default values we need to store
91
92 static const int SPAWN_DELAY = 200;
93
94 //------------------------------------------------------------------------------------------------
96 string GetName()
97 {
98 return GetOwner().GetName();
99 }
100
101 //------------------------------------------------------------------------------------------------
103 void SetEntity(IEntity entity)
104 {
105 m_Entity = entity;
106 }
107
108 //------------------------------------------------------------------------------------------------
111 {
112 return m_bIsTerminated;
113 }
114
115 //------------------------------------------------------------------------------------------------
117 void SetIsTerminated(bool state)
118 {
119 m_bIsTerminated = state;
120 }
121
122 //------------------------------------------------------------------------------------------------
124 void SetRandomlySpawnedChildren(array<string> randomlySpawnedChildren)
125 {
126 IEntity entity;
129 foreach (string child : randomlySpawnedChildren)
130 {
131 entity = GetGame().GetWorld().FindEntityByName(child);
132 if (!entity)
133 continue;
134
136 if (!layer)
137 continue;
138
140 }
141 }
142
143 //------------------------------------------------------------------------------------------------
147 {
148 if (child && !m_aRandomlySpawnedChildren.Contains(child))
149 m_aRandomlySpawnedChildren.Insert(child);
150 }
151
152 //------------------------------------------------------------------------------------------------
154 array<SCR_ScenarioFrameworkLayerBase> GetRandomlySpawnedChildren()
155 {
157 }
158
159 //------------------------------------------------------------------------------------------------
163 int GetPlayersCount(FactionKey factionName = "")
164 {
165 if (factionName.IsEmpty())
166 return GetGame().GetPlayerManager().GetPlayerCount();
167
168 FactionManager factionManager = GetGame().GetFactionManager();
169 if (!factionManager)
170 return -1;
171
172 int iCnt = 0;
173 array<int> aPlayerIDs = {};
174 SCR_PlayerController playerController;
175 GetGame().GetPlayerManager().GetPlayers(aPlayerIDs);
176 foreach (int iPlayerID : aPlayerIDs)
177 {
178 playerController = SCR_PlayerController.Cast(GetGame().GetPlayerManager().GetPlayerController(iPlayerID));
179 if (!playerController)
180 continue;
181
182 if (playerController.GetLocalControlledEntityFaction() == factionManager.GetFactionByKey(factionName))
183 iCnt++;
184 }
185 return iCnt;
186 }
187
188 //---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
189 //------------------------------------------------------------------------------------------------
194 {
195 //TODO: separate players by faction (attackers / defenders)
196 SCR_MissionHeader header = SCR_MissionHeader.Cast(GetGame().GetMissionHeader());
197
198 if (!header)
199 return 4; //TODO: make a constant
200
201 return header.m_iPlayerCount;
202 }
203 //---- REFACTOR NOTE END ----
204
205 //------------------------------------------------------------------------------------------------
208 {
209 if (m_Area)
210 return m_Area;
211
212 IEntity entity = GetOwner().GetParent();
213 while (entity)
214 {
216 if (m_Area)
217 return m_Area;
218
219 entity = entity.GetParent();
220 }
221
222 return null;
223 }
224
225 //------------------------------------------------------------------------------------------------
228 void GetAllLayers(out notnull array<SCR_ScenarioFrameworkLayerBase> layers)
229 {
230 layers.Clear();
231 array<SCR_ScenarioFrameworkLayerBase> aSiblingLayers = {};
233 IEntity child = GetOwner().GetChildren();
234 while (child)
235 {
237 if (layerBase)
238 {
239 layers.Insert(layerBase);
240
241 layerBase.GetAllLayers(aSiblingLayers);
242 layers.InsertAll(aSiblingLayers);
243 }
244
245 child = child.GetSibling();
246 }
247 }
248
249 //------------------------------------------------------------------------------------------------
253 void GetAllLayers(out notnull array<SCR_ScenarioFrameworkLayerBase> layers, SCR_ScenarioFrameworkEActivationType activationType)
254 {
255 layers.Clear();
256 array<SCR_ScenarioFrameworkLayerBase> aSiblingLayers = {};
258 IEntity child = GetOwner().GetChildren();
259 while (child)
260 {
262 if (layerBase)
263 {
264 if (layerBase.m_eActivationType == activationType)
265 layers.Insert(layerBase);
266
267 layerBase.GetAllLayers(aSiblingLayers, activationType);
268 layers.InsertAll(aSiblingLayers);
269 }
270
271 child = child.GetSibling();
272 }
273 }
274
275 //------------------------------------------------------------------------------------------------
278 void GetAllLayerTasks(out notnull array<SCR_ScenarioFrameworkLayerTask> layerTasks)
279 {
280 layerTasks.Clear();
281 array<SCR_ScenarioFrameworkLayerTask> aSiblingLayerTasks = {};
282 SCR_ScenarioFrameworkLayerTask layerTask;
284 IEntity child = GetOwner().GetChildren();
285 while (child)
286 {
288 if (layerBase)
289 {
290 layerTask = SCR_ScenarioFrameworkLayerTask.Cast(layerBase);
291 if (layerTask)
292 layerTasks.Insert(layerTask);
293
294 layerBase.GetAllLayerTasks(aSiblingLayerTasks);
295 layerTasks.InsertAll(aSiblingLayerTasks);
296 }
297
298 child = child.GetSibling();
299 }
300 }
301
302 //------------------------------------------------------------------------------------------------
305 void GetAllSlotTasks(out notnull array<SCR_ScenarioFrameworkSlotTask> slotTasks)
306 {
307 slotTasks.Clear();
308 array<SCR_ScenarioFrameworkSlotTask> aSiblingSlotTasks = {};
309 SCR_ScenarioFrameworkSlotTask slotTask;
311 IEntity child = GetOwner().GetChildren();
312 while (child)
313 {
315 if (layerBase)
316 {
317 slotTask = SCR_ScenarioFrameworkSlotTask.Cast(layerBase);
318 if (slotTask)
319 slotTasks.Insert(slotTask);
320
321 layerBase.GetAllSlotTasks(aSiblingSlotTasks);
322 slotTasks.InsertAll(aSiblingSlotTasks);
323 }
324
325 child = child.GetSibling();
326 }
327 }
328
329 //------------------------------------------------------------------------------------------------
331 SCR_ScenarioFrameworkLayerTask GetLayerTask()
332 {
333 SCR_ScenarioFrameworkLayerTask layer;
334 IEntity entity = GetOwner().GetParent();
335 while (entity)
336 {
337 layer = SCR_ScenarioFrameworkLayerTask.Cast(entity.FindComponent(SCR_ScenarioFrameworkLayerTask));
338 if (layer)
339 return layer;
340
341 entity = entity.GetParent();
342 }
343
344 return null;
345 }
346
347 //------------------------------------------------------------------------------------------------
351 SCR_ScenarioFrameworkSlotTask GetSlotTask(array<SCR_ScenarioFrameworkLayerBase> aLayers)
352 {
353 SCR_ScenarioFrameworkSlotTask slotTask;
354 foreach (SCR_ScenarioFrameworkLayerBase layer : aLayers)
355 {
356 IEntity child = layer.GetOwner();
357 slotTask = SCR_ScenarioFrameworkSlotTask.Cast(child.FindComponent(SCR_ScenarioFrameworkSlotTask));
358 if (slotTask)
359 return slotTask;
360
361 child = GetOwner().GetChildren();
362 while (child)
363 {
364 slotTask = SCR_ScenarioFrameworkSlotTask.Cast(child.FindComponent(SCR_ScenarioFrameworkSlotTask));
365 if (slotTask)
366 return slotTask;
367
368 child = child.GetSibling();
369 }
370 }
371
372 return null;
373 }
374
375 //------------------------------------------------------------------------------------------------
377 protected void SetFactionKey(FactionKey factionKey)
378 {
379 m_sFactionKey = factionKey;
380 }
381
382 //------------------------------------------------------------------------------------------------
385 {
386 return m_sFactionKey;
387 }
388
389 //------------------------------------------------------------------------------------------------
392 {
393 m_ParentLayer = parentLayer;
394 }
395
396 //------------------------------------------------------------------------------------------------
400 {
402 {
403 // Resolve Alias
404 SCR_FactionAliasComponent factionAliasComponent = SCR_FactionAliasComponent.GetFactionAliasComponentForWB();
405 if (!factionAliasComponent)
406 return GetFactionKey(); // If the mission creator didn't define SCR_FactionAliasComponent, then alias resolution is not needed.
407
408 return factionAliasComponent.ResolveFactionAlias(GetFactionKey());
409 }
410
411 IEntity parentEntity = GetOwner().GetParent();
412 if (!parentEntity)
413 return "";
414
416 if (!parentLayer)
417 return "";
418
419 FactionKey factionKey = parentLayer.GetParentFactionKeyRecursive();
420 return factionKey;
421
422 }
423
424 //------------------------------------------------------------------------------------------------
427 {
428 if (m_ParentLayer)
429 return m_ParentLayer;
430
431 IEntity entity = GetOwner().GetParent();
432 if (!entity)
433 return null;
434
436 return m_ParentLayer;
437 }
438
439 //------------------------------------------------------------------------------------------------
442 {
443 return m_SpawnChildren;
444 }
445
446 //------------------------------------------------------------------------------------------------
449 {
451 }
452
453 //------------------------------------------------------------------------------------------------
455 void SetEnableRepeatedSpawn(bool value)
456 {
458 }
459
460 //------------------------------------------------------------------------------------------------
466
467 //------------------------------------------------------------------------------------------------
470 {
471 m_eActivationType = activationType;
472 }
473
474 //------------------------------------------------------------------------------------------------
477 {
478 return m_bInitiated;
479 }
480
481 //------------------------------------------------------------------------------------------------
484 {
485 return m_bDynamicDespawn;
486 }
487
488 //------------------------------------------------------------------------------------------------
490 void SetDynamicDespawnEnabled(bool enabled)
491 {
492 m_bDynamicDespawn = enabled;
493 }
494
495 //------------------------------------------------------------------------------------------------
501
502 //------------------------------------------------------------------------------------------------
505 {
507 }
508
509 //------------------------------------------------------------------------------------------------
512 {
514 }
515
516 //------------------------------------------------------------------------------------------------
518 void SetDynamicDespawnExcluded(bool excluded)
519 {
521 }
522
523 //------------------------------------------------------------------------------------------------
525 array<IEntity> GetSpawnedEntities()
526 {
527 return m_aSpawnedEntities;
528 }
529
530 //------------------------------------------------------------------------------------------------
532 array<SCR_ScenarioFrameworkLayerBase> GetChildrenEntities()
533 {
534 return m_aChildren;
535 }
536
537 //------------------------------------------------------------------------------------------------
540 {
541 if (m_aChildren.IsEmpty())
542 return null;
543
544 array<SCR_ScenarioFrameworkLayerBase> suitableChildren = {};
546 {
547 if (child.GetDynamicDespawnEnabled())
548 continue;
549
550 suitableChildren.Insert(child);
551 }
552
553 return suitableChildren.GetRandomElement();
554 }
555
556 //------------------------------------------------------------------------------------------------
559 void GetChildren(out array<SCR_ScenarioFrameworkLayerBase> children)
560 {
561 children = {};
563 array<string> childrenStringsReversed = {};
565 IEntity child = GetOwner().GetChildren();
566 while (child)
567 {
569 if (layerBase)
570 {
571 childrenReversed.Insert(layerBase.GetName(), layerBase);
572 childrenStringsReversed.Insert(layerBase.GetName());
573 }
574
575 child = child.GetSibling();
576 }
577
578 childrenStringsReversed.Sort();
579 foreach (string name : childrenStringsReversed)
580 {
581 layerBase = childrenReversed.Get(name);
582
583 if (layerBase)
584 children.Insert(layerBase);
585 }
586 }
587
588 //------------------------------------------------------------------------------------------------
591 void GetChildren(out array<SCR_ScenarioFrameworkLayerBase> children, SCR_ScenarioFrameworkEActivationType activationType)
592 {
593 children = {};
595 array<string> childrenStringsReversed = {};
597 IEntity child = GetOwner().GetChildren();
598 while (child)
599 {
601 if (layerBase)
602 {
603 childrenReversed.Insert(layerBase.GetName(), layerBase);
604 childrenStringsReversed.Insert(layerBase.GetName());
605 }
606
607 child = child.GetSibling();
608 }
609
610 childrenStringsReversed.Sort();
611 foreach (string name : childrenStringsReversed)
612 {
613 layerBase = childrenReversed.Get(name);
614
615 if (layerBase && layerBase.m_eActivationType == activationType)
616 children.Insert(layerBase);
617 }
618 }
619
620 //------------------------------------------------------------------------------------------------
623 void GetLogics(out array<SCR_ScenarioFrameworkLogic> logics)
624 {
625 IEntity child = GetOwner().GetChildren();
626 SCR_ScenarioFrameworkLogic logic;
627 while (child)
628 {
629 logic = SCR_ScenarioFrameworkLogic.Cast(child);
630 if (logic && !logics.Contains(logic))
631 logics.Insert(logic);
632
633 child = child.GetSibling();
634 }
635 }
636
637 //------------------------------------------------------------------------------------------------
639 array<SCR_ScenarioFrameworkLogic> GetSpawnedLogics()
640 {
641 return m_aLogic;
642 }
643
644 //------------------------------------------------------------------------------------------------
646 array<ref SCR_ScenarioFrameworkPlugin> GetSpawnedPlugins()
647 {
648 return m_aPlugins;
649 }
650
651 //------------------------------------------------------------------------------------------------
654 {
656 }
657
658 //------------------------------------------------------------------------------------------------
660 void SetRepeatedSpawnNumber(int number)
661 {
662 m_iRepeatedSpawnNumber = number;
663 }
664
665 //------------------------------------------------------------------------------------------------
667 protected void RepeatedSpawn()
668 {
670 return;
671
672 //This calls the RepeatedSpawnCalled with set delay and is set in a way that it
673 //Can be both queued that way or called manually from different place (pseudo-looped CallLater)
675 }
676
677 //------------------------------------------------------------------------------------------------
679 protected void RepeatedSpawnCalled()
680 {
681 if (m_iRepeatedSpawnNumber != -1)
683
684 SpawnChildren(true);
685
687 return;
688
690 }
691
692 //------------------------------------------------------------------------------------------------
695 {
697 m_OnAllChildrenSpawned = new ScriptInvokerBase<ScriptInvokerScenarioFrameworkLayerMethod>();
698
700 }
701
702 //------------------------------------------------------------------------------------------------
705 {
707 m_OnAllChildrenSpawned.Invoke(this);
708 }
709
710 //------------------------------------------------------------------------------------------------
713 void CalculateSupposedSpawnedChildren(bool previouslyRandomized = false)
714 {
716 if (previouslyRandomized)
717 {
719 {
720 if (child.GetDynamicDespawnEnabled())
721 continue;
722
723 int activationType = child.GetActivationType();
724 if (activationType == SCR_ScenarioFrameworkEActivationType.ON_TRIGGER_ACTIVATION || activationType == SCR_ScenarioFrameworkEActivationType.ON_AREA_TRIGGER_ACTIVATION
725 || activationType == SCR_ScenarioFrameworkEActivationType.ON_TASKS_INIT)
726 continue;
727
728 if (child.GetIsTerminated())
729 continue;
730
731 if (!child.InitActivationConditions())
732 continue;
733
734 if (child.GetIsInitiated())
736
738 }
739 }
740 else
741 {
743 {
744 if (child.GetDynamicDespawnEnabled())
745 continue;
746
747 int activationType = child.GetActivationType();
748 if (activationType == SCR_ScenarioFrameworkEActivationType.ON_TRIGGER_ACTIVATION || activationType == SCR_ScenarioFrameworkEActivationType.ON_AREA_TRIGGER_ACTIVATION
749 || activationType == SCR_ScenarioFrameworkEActivationType.ON_TASKS_INIT)
750 continue;
751
752 if (child.GetIsTerminated())
753 continue;
754
755 if (!child.InitActivationConditions())
756 continue;
757
758 if (child.GetIsInitiated())
760
762 }
763 }
764 }
765
766 //------------------------------------------------------------------------------------------------
770 {
771 if (!layer && layer.GetDynamicDespawnEnabled())
772 return;
773
774 if (m_SpawnChildren == SCR_EScenarioFrameworkSpawnChildrenType.ALL)
775 {
778
781 }
782 else if (m_SpawnChildren == SCR_EScenarioFrameworkSpawnChildrenType.RANDOM_ONE)
783 {
785 }
786 else
787 {
790 {
791 if (child.GetDynamicDespawnEnabled())
792 continue;
793
794 int activationType = child.GetActivationType();
795 if (activationType == SCR_ScenarioFrameworkEActivationType.ON_TRIGGER_ACTIVATION || activationType == SCR_ScenarioFrameworkEActivationType.ON_AREA_TRIGGER_ACTIVATION)
796 continue;
797
798 if (child.GetIsTerminated())
799 continue;
800
801 if (!child.InitActivationConditions())
802 continue;
803
804 if (child.GetIsInitiated())
806 }
807
810 }
811 }
812
813 //------------------------------------------------------------------------------------------------
816 void SpawnChildren(bool previouslyRandomized = false)
817 {
818 if (m_aChildren.IsEmpty())
819 {
821 return;
822 }
823
824 if (!previouslyRandomized && !m_aRandomlySpawnedChildren.IsEmpty())
825 previouslyRandomized = true;
826
827 const bool isWorldLoadInit = SCR_ScenarioFrameworkSystem.IsWorldLoadInit();
828
829 if (m_SpawnChildren == SCR_EScenarioFrameworkSpawnChildrenType.ALL)
830 {
831 int slotCount;
833 {
834 if (child.GetDynamicDespawnEnabled())
835 {
836 if (m_aChildren.Count() == 1)
838
839 continue;
840 }
841
842 if (SCR_ScenarioFrameworkSlotBase.Cast(child))
843 {
844 if (isWorldLoadInit || SCR_ScenarioFrameworkSlotMarker.Cast(child) || SCR_ScenarioFrameworkSlotWaypoint.Cast(child))
845 {
846 InitChild(child);
847 }
848 else
849 {
850 SCR_ScenarioFrameworkCallQueueSystem.GetCallQueueNonPausable().CallLater(InitChild, SPAWN_DELAY * slotCount, false, child);
851 slotCount++;
852 }
853 }
854 else
855 {
856 InitChild(child);
857 }
858 }
859 }
860 else if (m_SpawnChildren == SCR_EScenarioFrameworkSpawnChildrenType.RANDOM_ONE)
861 {
862 SpawnRandomOneChild(previouslyRandomized);
863 }
864 else
865 {
866 SpawnRandomMultipleChildren(previouslyRandomized);
867 }
868 }
869
870 //------------------------------------------------------------------------------------------------
873 {
875
876 const bool isWorldLoadInit = SCR_ScenarioFrameworkSystem.IsWorldLoadInit();
878 {
879 if (isWorldLoadInit)
880 {
881 InitChild(child);
882 continue;
883 }
884
886 }
887 }
888
889 //------------------------------------------------------------------------------------------------
892 void SpawnRandomOneChild(bool previouslyRandomized = false)
893 {
894 if (previouslyRandomized)
896 else
897 {
899 m_aRandomlySpawnedChildren.Insert(child);
900 InitChild(child);
901 }
902 }
903
904 //------------------------------------------------------------------------------------------------
907 void SpawnRandomMultipleChildren(bool previouslyRandomized = false)
908 {
909 if (previouslyRandomized)
911 else
912 {
913 array<SCR_ScenarioFrameworkLayerBase> suitableChildren = {};
915 {
916 if (child.GetDynamicDespawnEnabled())
917 continue;
918
919 suitableChildren.Insert(child);
920 }
921
922 if (suitableChildren.IsEmpty())
923 return;
924
925 if (m_SpawnChildren == SCR_EScenarioFrameworkSpawnChildrenType.RANDOM_BASED_ON_PLAYERS_COUNT)
927
928 m_iSupposedSpawnedChildren = Math.Round(suitableChildren.Count() * 0.01 * m_iRandomPercent);
930 for (int i = 1; i <= m_iSupposedSpawnedChildren; i++)
931 {
932 child = suitableChildren.GetRandomElement();
933 m_aRandomlySpawnedChildren.Insert(child);
934 InitChild(child);
935 suitableChildren.RemoveItem(child);
936 }
937 }
938 }
939
940 //------------------------------------------------------------------------------------------------
944 {
945 if (!child)
946 return;
947
948 child.SetParentLayer(this);
949 child.Init(GetParentArea(), SCR_ScenarioFrameworkEActivationType.SAME_AS_PARENT);
950 }
951
952 //------------------------------------------------------------------------------------------------
955 {
956 return m_Entity;
957 }
958
959 //------------------------------------------------------------------------------------------------
961 protected void ActivateLogic()
962 {
964 foreach (SCR_ScenarioFrameworkLogic logic : m_aLogic)
965 {
966 logic.Init();
967 }
968 }
969
970 //------------------------------------------------------------------------------------------------
975 void RestoreToDefault(bool includeChildren = false, bool reinitAfterRestoration = false, bool affectRandomization = true, bool deleteSpawnedEntities = true)
976 {
977 m_Entity = null;
980 m_bInitiated = false;
982 m_bIsTerminated = false;
983
985
986 if (includeChildren)
987 {
988 if (m_aChildren.IsEmpty())
990
992 {
993 child.RestoreToDefault(includeChildren, false);
994 }
995 }
996
997 m_aChildren.Clear();
998 if (affectRandomization)
1000
1001 if (deleteSpawnedEntities)
1002 {
1003 foreach (IEntity entity : m_aSpawnedEntities)
1004 {
1005 SCR_EntityHelper.DeleteEntityAndChildren(entity);
1006 }
1007 }
1008
1009 m_aSpawnedEntities.Clear();
1010
1011 foreach (SCR_ScenarioFrameworkLogic logic : m_aLogic)
1012 {
1013 logic.RestoreToDefault();
1014 }
1015
1016 if (reinitAfterRestoration)
1017 Init(m_Area);
1018 }
1019
1020 //------------------------------------------------------------------------------------------------
1024 {
1026 if (!m_bInitiated)
1027 {
1029 return;
1030 }
1031
1033 return;
1034
1035 m_bInitiated = false;
1037 m_aChildren.RemoveItem(null);
1039 {
1040 // Check if the child has its own Dynamic Despawn in place that is managed by the parent area and not the parent layer
1041 if (!child.m_bDynamicDespawn)
1042 child.DynamicDespawn(this);
1043 }
1044
1045 m_aChildren.Clear();
1046
1047 foreach (IEntity entity : m_aSpawnedEntities)
1048 {
1049 SCR_EntityHelper.DeleteEntityAndChildren(entity);
1050 }
1051
1052 m_aSpawnedEntities.Clear();
1053 }
1054
1055 //------------------------------------------------------------------------------------------------
1058 {
1060 }
1061
1062 //------------------------------------------------------------------------------------------------
1066 {
1067 return m_bInitiated;
1068 }
1069
1070 //------------------------------------------------------------------------------------------------
1074 {
1075 if (m_ParentLayer)
1076 return true;
1077
1079 return (m_ParentLayer != null);
1080 }
1081
1082 //------------------------------------------------------------------------------------------------
1086 {
1087 if (!m_bIsTerminated)
1088 return true;
1089
1090 if (m_ParentLayer)
1091 m_ParentLayer.CheckAllChildrenSpawned(this);
1092
1093 return false;
1094 }
1095
1096 //------------------------------------------------------------------------------------------------
1101 {
1102 if (!m_bDynamicallyDespawned && activation != m_eActivationType)
1103 {
1104 if (m_ParentLayer)
1105 m_ParentLayer.CheckAllChildrenSpawned(this);
1106
1107 return false;
1108 }
1109
1110 return true;
1111 }
1112
1113 //------------------------------------------------------------------------------------------------
1116 bool InitActivationConditions(bool calledFromInit = false)
1117 {
1118 if (m_aActivationConditions.IsEmpty())
1119 return true;
1120
1121 IEntity owner = GetOwner();
1122 bool conditionStatus = SCR_ScenarioFrameworkActivationConditionBase.EvaluateEmptyOrConditions(m_eActivationConditionLogic, m_aActivationConditions, owner);
1123 if (!conditionStatus && m_ParentLayer && calledFromInit)
1124 m_ParentLayer.CheckAllChildrenSpawned(this);
1125
1126 return conditionStatus;
1127 }
1128
1129 //------------------------------------------------------------------------------------------------
1134 {
1135 if (area)
1136 {
1137 m_Area = area;
1138 return true;
1139 }
1140
1142 if (!m_Area)
1143 {
1144 if (m_ParentLayer)
1145 m_ParentLayer.CheckAllChildrenSpawned(this);
1146
1147 return false;
1148 }
1149
1150 return true;
1151 }
1152
1153 //------------------------------------------------------------------------------------------------
1156 {
1158 {
1159 // Try Inherit
1160 if (!m_ParentLayer)
1161 return true;
1162
1163 FactionKey parentFactionKey = m_ParentLayer.GetFactionKey();
1164 if (!SCR_StringHelper.IsEmptyOrWhiteSpace(parentFactionKey))
1165 SetFactionKey(parentFactionKey);
1166 return true;
1167 }
1168
1169 // Resolve Alias
1170 SCR_FactionAliasComponent factionAliasComponent = SCR_FactionAliasComponent.Cast(GetGame().GetFactionManager().FindComponent(SCR_FactionAliasComponent));
1171 if (factionAliasComponent)
1172 SetFactionKey(factionAliasComponent.ResolveFactionAlias(GetFactionKey()));
1173 // Its not a mistake if the mission creator didn't define SCR_FactionAliasComponent. It just means that alias resolution is not needed.
1174 return true;
1175 }
1176
1177 //------------------------------------------------------------------------------------------------
1180 {
1181 return true;
1182 }
1183
1184 //------------------------------------------------------------------------------------------------
1190
1191 //------------------------------------------------------------------------------------------------
1194 {
1197 SpawnChildren();
1198 }
1199
1200 //------------------------------------------------------------------------------------------------
1205 {
1206 if (InitAlreadyHappened())
1207 return;
1208
1209 if (!InitParentLayer())
1210 return;
1211
1212 if (!InitFactionSettings())
1213 return;
1214
1215 if (!InitNotTerminated())
1216 return;
1217
1218 if (!InitDynDespawnAndActivation(activation))
1219 return;
1220
1221 if (!InitActivationConditions(true))
1222 return;
1223
1224 if (!InitArea(area))
1225 return;
1226
1227 if (!InitOtherThings())
1228 return;
1229
1230 FinishInit();
1231 }
1232
1233 //------------------------------------------------------------------------------------------------
1237 {
1238 m_bInitiated = true;
1239
1240 ActivateLogic();
1241 foreach (SCR_ScenarioFrameworkPlugin plugin : m_aPlugins)
1242 {
1243 plugin.Init(this);
1244 }
1245
1247
1248 if (m_ParentLayer)
1249 m_ParentLayer.CheckAllChildrenSpawned(this);
1250
1252
1253 if (m_fRepeatedSpawnTimer >= 0)
1254 RepeatedSpawn();
1255 }
1256
1257 //------------------------------------------------------------------------------------------------
1261 override void EOnFrame(IEntity owner, float timeSlice)
1262 {
1263 super.EOnFrame(owner, timeSlice);
1264
1266 DrawDebugShape(true);
1267 }
1268
1269 //------------------------------------------------------------------------------------------------
1271 override void OnPostInit(IEntity owner)
1272 {
1273 super.OnPostInit(owner);
1275 {
1276 //TODO: deactivate once the slots are not needed (after entity was spawned)
1277 SetEventMask(owner, EntityEvent.INIT | EntityEvent.FRAME);
1278
1279 if (SCR_Global.IsEditMode())
1280 return;
1281
1282 BaseGameMode gameMode = GetGame().GetGameMode();
1283 if (!gameMode)
1284 return;
1285
1287 if (!scenarioFrameworkSystem)
1288 return;
1289
1291 }
1292 }
1293
1294 //------------------------------------------------------------------------------------------------
1296 void SetDebugShapeSize(float fSize)
1297 {
1298 m_fDebugShapeRadius = fSize;
1299 }
1300
1301 //------------------------------------------------------------------------------------------------
1304 protected void DrawDebugShape(bool draw)
1305 {
1306 Shape dbgShape = null;
1307 if (!draw)
1308 return;
1309
1310 dbgShape = Shape.CreateSphere(
1312 ShapeFlags.TRANSP | ShapeFlags.DOUBLESIDE | ShapeFlags.NOZWRITE | ShapeFlags.ONCE | ShapeFlags.NOOUTLINE,
1313 GetOwner().GetOrigin(),
1315 );
1316 }
1317
1318 //------------------------------------------------------------------------------------------------
1319 protected void InitActivationActions()
1320 {
1321 const IEntity owner = GetOwner();
1322
1323 foreach (SCR_ScenarioFrameworkActionBase activationAction : m_aActivationActions)
1324 {
1325 activationAction.Init(owner);
1326 }
1327 }
1328
1329 //------------------------------------------------------------------------------------------------
1331 {
1332 foreach (SCR_ScenarioFrameworkActionBase activationAction : m_aActivationActions)
1333 {
1334 activationAction.RestoreToDefault();
1335 }
1336 }
1337
1338 //------------------------------------------------------------------------------------------------
1339 array<ref SCR_ScenarioFrameworkActionBase> GetActivationActions()
1340 {
1341 return m_aActivationActions;
1342 }
1343
1344#ifdef WORKBENCH
1345
1346 //------------------------------------------------------------------------------------------------
1347 override int _WB_GetAfterWorldUpdateSpecs(IEntity owner, IEntitySource src)
1348 {
1349 return EEntityFrameUpdateSpecs.CALL_WHEN_ENTITY_VISIBLE;
1350 }
1351
1352 //------------------------------------------------------------------------------------------------
1356 override void _WB_AfterWorldUpdate(IEntity owner, float timeSlice)
1357 {
1359 }
1360
1361 //------------------------------------------------------------------------------------------------
1365 override void _WB_OnCreate(IEntity owner, IEntitySource src)
1366 {
1367 RenameOwnerEntity(owner);
1368
1369 IEntity child = GetOwner().GetChildren();
1370 while (child)
1371 {
1372 RenameOwnerEntity(child);
1373 child = child.GetSibling();
1374 }
1375 }
1376
1377 //------------------------------------------------------------------------------------------------
1385 override bool _WB_OnKeyChanged(IEntity owner, BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
1386 {
1387 if (key == "m_bShowDebugShapesInWorkbench")
1389
1390 return false;
1391 }
1392
1393 //------------------------------------------------------------------------------------------------
1396 void RenameOwnerEntity(IEntity owner)
1397 {
1398 GenericEntity genericEntity = GenericEntity.Cast(owner);
1399
1400 WorldEditorAPI api = genericEntity._WB_GetEditorAPI();
1401 if (!api.UndoOrRedoIsRestoring())
1402 api.RenameEntity(api.EntityToSource(owner), api.GenerateDefaultEntityName(api.EntityToSource(owner)));
1403 }
1404#endif
1405
1406 //------------------------------------------------------------------------------------------------
1407 // constructor
1412 {
1415
1416 m_iDebugShapeColor = ARGB(32, 255, 255, 255);
1417#ifdef WORKBENCH
1418 foreach (SCR_ScenarioFrameworkPlugin plugin : m_aPlugins)
1419 {
1420 plugin.OnWBKeyChanged(this);
1421 }
1422#endif
1423 }
1424
1425 //------------------------------------------------------------------------------------------------
1428 {
1429 if (SCR_Global.IsEditMode())
1430 return;
1431
1432 DynamicDespawn(this);
1433 }
1434}
override void Init()
ArmaReforgerScripted GetGame()
Definition game.c:1398
LayerPresets layer
override string GetID(string fileName, string varName, array< BaseContainer > objects, array< int > indexes)
enum EAITargetInfoCategory m_Entity
vector GetOrigin()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
override bool _WB_OnKeyChanged(IEntity owner, BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
Any property value has been changed. You can use editor API here and do some additional edit actions ...
override void EOnFrame(IEntity owner, float timeSlice)
void SetEntity(IEntity entity)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
bool m_bShowDebugShapesInWorkbench
float m_fRepeatedSpawnTimer
SCR_ScenarioFrameworkEActivationType m_eActivationTypeDefault
void SetRepeatedSpawnNumber(int number)
bool InitDynDespawnAndActivation(SCR_ScenarioFrameworkEActivationType activation)
void AddRandomlySpawnedChild(SCR_ScenarioFrameworkLayerBase child)
ref array< IEntity > m_aSpawnedEntities
void SpawnRandomMultipleChildren(bool previouslyRandomized=false)
array< IEntity > GetSpawnedEntities()
SCR_ScenarioFrameworkEActivationType m_eActivationType
void SetEnableRepeatedSpawn(bool value)
int GetDynamicDespawnRange()
bool m_bEnableRepeatedSpawn
void RepeatedSpawn()
Repetitive spawning with timer.
WorldTimestamp m_fRepeatSpawnTimeEnd
FactionKey m_sFactionKey
void GetChildren(out array< SCR_ScenarioFrameworkLayerBase > children)
SCR_EScenarioFrameworkSpawnChildrenType
void SetDynamicDespawnExcluded(bool excluded)
bool GetEnableRepeatedSpawn()
SCR_ScenarioFrameworkLayerBase GetRandomChildren()
int GetRepeatedSpawnNumber()
IEntity GetSpawnedEntity()
array< SCR_ScenarioFrameworkLogic > GetSpawnedLogics()
void GetLogics(out array< SCR_ScenarioFrameworkLogic > logics)
ref array< ref SCR_ScenarioFrameworkActivationConditionBase > m_aActivationConditions
void SetDynamicDespawnEnabled(bool enabled)
void DynamicReinit()
Reinitializes this layer.
bool InitFactionSettings()
Handles inheritance of faction settings from parents.
bool GetDynamicDespawnEnabled()
int m_iCurrentlySpawnedChildren
ref array< SCR_ScenarioFrameworkLogic > m_aLogic
FactionKey GetFactionKey()
int m_iRepeatedSpawnNumberDefault
void SetParentLayer(SCR_ScenarioFrameworkLayerBase parentLayer)
void SpawnPreviouslyRandomizedChildren()
Spawns children with delay based on their index.
void InitChild(SCR_ScenarioFrameworkLayerBase child)
void SpawnChildren(bool previouslyRandomized=false)
void SetDynamicDespawnRange(int range)
ref array< SCR_ScenarioFrameworkLayerBase > m_aChildren
SCR_ScenarioFrameworkLayerBase GetParentLayer()
func ScriptInvokerScenarioFrameworkLayerMethod
void InvokeAllChildrenSpawned()
Spawns all children and triggers invoker on completion.
SCR_ScenarioFrameworkEActivationType GetActivationType()
SCR_ScenarioFrameworkLayerBase m_ParentLayer
bool GetDynamicDespawnExcluded()
array< ref SCR_ScenarioFrameworkActionBase > GetActivationActions()
ScriptInvokerScenarioFrameworkLayer GetOnAllChildrenSpawned()
void SpawnRandomOneChild(bool previouslyRandomized=false)
void FinishInitChildrenInsert()
For situations where some other logic is needed to be performed before or after this Insert.
SCR_EScenarioFrameworkLogicOperators m_eActivationConditionLogic
int m_iSupposedSpawnedChildren
bool m_bExcludeFromDynamicDespawn
void SetFactionKey(FactionKey factionKey)
FactionKey GetParentFactionKeyRecursive()
void FinishInit()
Initializes children, retrieves them, and spawns them.
SCR_ScenarioFrameworkArea GetParentArea()
SCR_EScenarioFrameworkSpawnChildrenType GetSpawnChildrenType()
bool m_bShowDebugShapesDuringRuntime
WorldTimestamp m_fRepeatSpawnTimeStart
ref array< SCR_ScenarioFrameworkLayerBase > m_aRandomlySpawnedChildren
void SetDebugShapeSize(float fSize)
void GetAllSlotTasks(out notnull array< SCR_ScenarioFrameworkSlotTask > slotTasks)
array< SCR_ScenarioFrameworkLayerBase > GetChildrenEntities()
void SetIsTerminated(bool state)
ref ScriptInvokerBase< ScriptInvokerScenarioFrameworkLayerMethod > m_OnAllChildrenSpawned
void CheckAllChildrenSpawned(SCR_ScenarioFrameworkLayerBase layer=null)
void InitActivationActions()
void GetAllLayerTasks(out notnull array< SCR_ScenarioFrameworkLayerTask > layerTasks)
array< SCR_ScenarioFrameworkLayerBase > GetRandomlySpawnedChildren()
bool InitArea(SCR_ScenarioFrameworkArea area)
void AfterAllChildrenSpawned(SCR_ScenarioFrameworkLayerBase layer)
void SetActivationType(SCR_ScenarioFrameworkEActivationType activationType)
void CalculateSupposedSpawnedChildren(bool previouslyRandomized=false)
bool InitActivationConditions(bool calledFromInit=false)
void SCR_ScenarioFrameworkLayerBase(IEntityComponentSource src, IEntity ent, IEntity parent)
array< ref SCR_ScenarioFrameworkPlugin > GetSpawnedPlugins()
void DrawDebugShape(bool draw)
void ActivateLogic()
Initializes all logic components.
ref array< ref SCR_ScenarioFrameworkPlugin > m_aPlugins
int GetMaxPlayersForGameMode(FactionKey factionName="")
void RepeatedSpawnCalled()
Repetitive spawning logic with countdown and condition checks.
SCR_ScenarioFrameworkLayerTask GetLayerTask()
void DynamicDespawn(SCR_ScenarioFrameworkLayerBase layer)
bool m_bDynamicallyDespawned
ref array< ref SCR_ScenarioFrameworkActionBase > m_aActivationActions
void SetRandomlySpawnedChildren(array< string > randomlySpawnedChildren)
bool InitOtherThings()
For situations where some other logic is to be appended in these checks and is to be performed before...
ScriptInvokerBase< ScriptInvokerScenarioFrameworkLayerMethod > ScriptInvokerScenarioFrameworkLayer
float m_fDebugShapeRadius
SCR_ScenarioFrameworkArea m_Area
void ~SCR_ScenarioFrameworkLayerBase()
Removes object in edit mode or despawns it if not in edit mode.
void GetAllLayers(out notnull array< SCR_ScenarioFrameworkLayerBase > layers)
void RestoreActionsToDefault()
SCR_ScenarioFrameworkSlotTask GetSlotTask()
void RestoreToDefault()
void SCR_ScenarioFrameworkSlotBase(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_ScenarioFrameworkSlotWaypoint(IEntityComponentSource src, IEntity ent, IEntity parent)
enum EVehicleType IEntity
proto external WorldEditorAPI _WB_GetEditorAPI()
This returns world editor API, which is safe to use from editor events bellow.
proto external Managed FindComponent(typename typeName)
proto external IEntity GetChildren()
proto external BaseWorld GetWorld()
proto external IEntity GetParent()
proto external string GetName()
proto external IEntity GetSibling()
Definition Math.c:13
static bool IsEditMode()
Definition Functions.c:1566
static Faction GetLocalControlledEntityFaction()
static ScriptCallQueue GetCallQueuePausable()
static SCR_ScenarioFrameworkSystem GetInstance()
void ManageLayerDebugShape(EntityID id, bool draw, float radius, bool runtime)
static bool IsEmptyOrWhiteSpace(string input)
Instance of created debug visualizer.
Definition Shape.c:14
Definition Types.c:486
IEntity GetOwner()
Owner entity of the fuel tank.
ShapeFlags
Definition ShapeFlags.c:13
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
@ ALL
Everything except general switch.
Definition EntityEvent.c:37
proto external PlayerController GetPlayerController()
proto int ARGB(int a, int r, int g, int b)