Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ScenarioFrameworkWaypointCycle.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
4 {
5  [Attribute(defvalue: "10", desc: "Radius in m")]
6  float m_fCompletionRadius;
7 
8  [Attribute(defvalue: EAIWaypointCompletionType.All.ToString(), UIWidgets.ComboBox, "AI Waypoint Completion Type", "", ParamEnumArray.FromEnum(EAIWaypointCompletionType))]
9  EAIWaypointCompletionType m_eAIWaypointCompletionType;
10 
11  [Attribute("0", UIWidgets.SpinBox, "Waypoint priority level", "0 2000 1000")]
12  float m_fPriorityLevel;
13 
14  [Attribute(defvalue: "{35BD6541CBB8AC08}Prefabs/AI/Waypoints/AIWaypoint_Cycle.et", desc: "In Default, it will use specific prefab for each class, but here you can change it if you know what you are doing")]
15  ResourceName m_sWaypointPrefab;
16 
17  [Attribute(defvalue: "", UIWidgets.EditComboBox, desc: "From this list, layers will be used and their waypoints processed")]
18  ref array<string> m_aLayersWithWaypointsToCycle;
19 
20  [Attribute(defvalue: "-1", desc: "Decides how many times the cycled waypoint will run for specific group. -1 means infinite. ", UIWidgets.Graph, "-1 inf 1")]
21  int m_iRerunCounter;
22 
23  [Attribute("Use random order")]
24  bool m_bUseRandomOrder;
25 
26  ref ScriptInvokerBase<ScriptInvokerScenarioFrameworkLayerMethod> m_OnAllWaypointsSpawned;
27  ref array<AIWaypoint> m_aWaypointsWithoutCycle = {};
28  ref array<SCR_ScenarioFrameworkSlotWaypoint> m_aSlotWaypoints = {};
29  AIWaypointCycle m_CycleWaypoint;
30  int m_iCurrentlySpawnedWaypoints;
31  bool m_bInitiated;
32 
33  //------------------------------------------------------------------------------------------------
34  override void SetupWaypoint(IEntity waypointEntity)
35  {
36  super.SetupWaypoint(waypointEntity);
37 
38  m_CycleWaypoint = AIWaypointCycle.Cast(waypointEntity);
39  if (!m_CycleWaypoint)
40  return;
41 
42  array<AIWaypoint> waypointsWithoutCycle = {};
43  array<SCR_ScenarioFrameworkLayerBase> layerBases = {};
44  array<SCR_ScenarioFrameworkLayerBase> layerChildren = {};
46 
47  // If no layer or slot is specified, it will assume that it is in the layer with other waypoints and will attempt to fetch them from there
48  // It is intentionally designed that way to make whole setup easier
49  if (m_aLayersWithWaypointsToCycle.IsEmpty())
50  {
51  SCR_ScenarioFrameworkLayerBase layerBase = m_SlotWaypoint.GetParentLayer();
52  if (layerBase)
53  m_aLayersWithWaypointsToCycle.Insert(layerBase.GetName());
54  }
55 
56  foreach (string waypointSetLayer : m_aLayersWithWaypointsToCycle)
57  {
58  IEntity layerEntity = GetGame().GetWorld().FindEntityByName(waypointSetLayer);
59  if (!layerEntity)
60  continue;
61 
63  if (layerBase && !SCR_ScenarioFrameworkSlotWaypoint.Cast(layerBase))
64  {
65  if (layerBases.Contains(layerBase))
66  continue;
67 
68  layerChildren = layerBase.GetChildrenEntities();
69  foreach (SCR_ScenarioFrameworkLayerBase child : layerChildren)
70  {
71  slotWaypoint = SCR_ScenarioFrameworkSlotWaypoint.Cast(child);
72  if (slotWaypoint && !m_aSlotWaypoints.Contains(slotWaypoint))
73  m_aSlotWaypoints.Insert(slotWaypoint);
74  }
75  }
76  else
77  {
78  slotWaypoint = SCR_ScenarioFrameworkSlotWaypoint.Cast(layerEntity.FindComponent(SCR_ScenarioFrameworkSlotWaypoint));
79  if (slotWaypoint && !m_aSlotWaypoints.Contains(slotWaypoint))
80  m_aSlotWaypoints.Insert(slotWaypoint);
81  }
82  }
83 
84  int waypointCount = m_aSlotWaypoints.Count();
85  foreach (SCR_ScenarioFrameworkSlotWaypoint slotWaypointToProcess : m_aSlotWaypoints)
86  {
87  if (slotWaypointToProcess.GetIsInitiated())
89  else
90  slotWaypointToProcess.GetOnAllChildrenSpawned().Insert(CheckWaypointsAfterInit);
91 
92  if (waypointCount == m_iCurrentlySpawnedWaypoints)
93  ProcessWaypoints(null);
94  }
95  }
96 
97  //------------------------------------------------------------------------------------------------
98  protected void CheckWaypointsAfterInit(SCR_ScenarioFrameworkLayerBase layer)
99  {
102  ProcessWaypoints(null);
103 
104  layer.GetOnAllChildrenSpawned().Remove(CheckWaypointsAfterInit);
105  }
106 
107  //------------------------------------------------------------------------------------------------
110  void ProcessWaypoints(SCR_ScenarioFrameworkLayerBase layer)
111  {
112  AIWaypoint waypoint;
113  foreach (SCR_ScenarioFrameworkSlotWaypoint slotWaypoint : m_aSlotWaypoints)
114  {
115  waypoint = AIWaypoint.Cast(slotWaypoint.GetSpawnedEntity());
116  if (waypoint && !AIWaypointCycle.Cast(waypoint))
117  m_aWaypointsWithoutCycle.Insert(waypoint);
118  }
119 
120  int wpCount = m_aWaypointsWithoutCycle.Count();
121  if (m_bUseRandomOrder && wpCount > 1)
122  {
123  foreach (AIWaypoint wp : m_aWaypointsWithoutCycle)
124  {
125  Math.Randomize(-1);
126  m_aWaypointsWithoutCycle.SwapItems(Math.RandomInt(0, Math.Floor(wpCount * 0.5)), Math.RandomInt(Math.Ceil(wpCount * 0.5), wpCount));
127  }
128  }
129 
130  m_CycleWaypoint.SetRerunCounter(m_iRerunCounter);
131  m_CycleWaypoint.SetWaypoints(m_aWaypointsWithoutCycle);
132  m_bInitiated = true;
133  InvokeAllWaypointsSpawned();
134  }
135 
136  //------------------------------------------------------------------------------------------------
138  ScriptInvokerScenarioFrameworkLayer GetOnAllWaypointsSpawned()
139  {
140  if (!m_OnAllWaypointsSpawned)
141  m_OnAllWaypointsSpawned = new ScriptInvokerBase<ScriptInvokerScenarioFrameworkLayerMethod>();
142 
143  return m_OnAllWaypointsSpawned;
144  }
145 
146  //------------------------------------------------------------------------------------------------
148  void InvokeAllWaypointsSpawned()
149  {
150  if (m_OnAllWaypointsSpawned && m_SlotWaypoint)
151  m_OnAllWaypointsSpawned.Invoke(m_SlotWaypoint);
152  }
153 
154  //------------------------------------------------------------------------------------------------
155  override void SetWaypointCompletionRadius(float radius)
156  {
157  m_fCompletionRadius = radius;
158  }
159 
160  //------------------------------------------------------------------------------------------------
161  override float GetWaypointCompletionRadius()
162  {
163  return m_fCompletionRadius;
164  }
165 
166  //------------------------------------------------------------------------------------------------
167  override void SetWaypointCompletionType(EAIWaypointCompletionType type)
168  {
169  m_eAIWaypointCompletionType = type;
170  }
171 
172  //------------------------------------------------------------------------------------------------
173  override EAIWaypointCompletionType GetWaypointCompletionType()
174  {
175  return m_eAIWaypointCompletionType;
176  }
177 
178  //------------------------------------------------------------------------------------------------
179  override void SetWaypointPrefab(ResourceName prefab)
180  {
181  m_sWaypointPrefab = prefab;
182  }
183 
184  //------------------------------------------------------------------------------------------------
185  override ResourceName GetWaypointPrefab()
186  {
187  return m_sWaypointPrefab;
188  }
189 }
m_bInitiated
protected bool m_bInitiated
Definition: SCR_ScenarioFrameworkLayerBase.c:72
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
ScriptInvokerScenarioFrameworkLayer
ScriptInvokerBase< ScriptInvokerScenarioFrameworkLayerMethod > ScriptInvokerScenarioFrameworkLayer
Definition: SCR_ScenarioFrameworkLayerBase.c:9
SCR_ScenarioFrameworkSlotWaypoint
void SCR_ScenarioFrameworkSlotWaypoint(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_ScenarioFrameworkSlotWaypoint.c:142
SCR_ScenarioFrameworkWaypointCycle
Definition: SCR_ScenarioFrameworkWaypointCycle.c:3
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_ScenarioFrameworkWaypoint
Definition: SCR_ScenarioFrameworkWaypoint.c:3
m_aSlotWaypoints
ref array< SCR_ScenarioFrameworkSlotWaypoint > m_aSlotWaypoints
Definition: SCR_ScenarioFrameworkSlotAI.c:51
SCR_ScenarioFrameworkLayerBase
void SCR_ScenarioFrameworkLayerBase(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_ScenarioFrameworkLayerBase.c:875
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
m_iCurrentlySpawnedWaypoints
int m_iCurrentlySpawnedWaypoints
Definition: SCR_ScenarioFrameworkSlotAI.c:52
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468