Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ScenarioFrameworkWaypointCycle.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
4{
5 [Attribute(defvalue: "10", uiwidget: UIWidgets.Slider, 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 {
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())
88 m_iCurrentlySpawnedWaypoints++;
89 else
90 slotWaypointToProcess.GetOnAllChildrenSpawned().Insert(CheckWaypointsAfterInit);
91
92 if (waypointCount == m_iCurrentlySpawnedWaypoints)
93 ProcessWaypoints(null);
94 }
95 }
96
97 //------------------------------------------------------------------------------------------------
99 {
100 m_iCurrentlySpawnedWaypoints++;
101 if (m_iCurrentlySpawnedWaypoints == m_aSlotWaypoints.Count())
102 ProcessWaypoints(null);
103
104 layer.GetOnAllChildrenSpawned().Remove(CheckWaypointsAfterInit);
105 }
106
107 //------------------------------------------------------------------------------------------------
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 ShuffleWaypointArray(m_aWaypointsWithoutCycle);
126 }
127 }
128
129 m_CycleWaypoint.SetRerunCounter(m_iRerunCounter);
130 m_CycleWaypoint.SetWaypoints(m_aWaypointsWithoutCycle);
131 m_bInitiated = true;
133 }
134
135 //------------------------------------------------------------------------------------------------
136 protected void ShuffleWaypointArray(notnull array<AIWaypoint> arr)
137 {
138 int n = arr.Count();
139 for (int i = n - 1; i > 0; i--)
140 {
141 int j = Math.RandomInt(0, i + 1);
142
143 arr.SwapItems(i, j);
144 }
145 }
146
147 //------------------------------------------------------------------------------------------------
150 {
151 if (!m_OnAllWaypointsSpawned)
152 m_OnAllWaypointsSpawned = new ScriptInvokerBase<ScriptInvokerScenarioFrameworkLayerMethod>();
153
154 return m_OnAllWaypointsSpawned;
155 }
156
157 //------------------------------------------------------------------------------------------------
160 {
161 if (m_OnAllWaypointsSpawned && m_SlotWaypoint)
162 m_OnAllWaypointsSpawned.Invoke(m_SlotWaypoint);
163 }
164
165 //------------------------------------------------------------------------------------------------
166 override void SetWaypointCompletionRadius(float radius)
167 {
168 m_fCompletionRadius = radius;
169 }
170
171 //------------------------------------------------------------------------------------------------
173 {
174 return m_fCompletionRadius;
175 }
176
177 //------------------------------------------------------------------------------------------------
179 {
180 m_eAIWaypointCompletionType = type;
181 }
182
183 //------------------------------------------------------------------------------------------------
185 {
186 return m_eAIWaypointCompletionType;
187 }
188
189 //------------------------------------------------------------------------------------------------
190 override void SetWaypointPrefab(ResourceName prefab)
191 {
192 m_sWaypointPrefab = prefab;
193 }
194
195 //------------------------------------------------------------------------------------------------
197 {
198 return m_sWaypointPrefab;
199 }
200}
ArmaReforgerScripted GetGame()
Definition game.c:1398
LayerPresets layer
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
EDamageType type
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void SCR_ScenarioFrameworkLayerBase(IEntityComponentSource src, IEntity ent, IEntity parent)
ScriptInvokerBase< ScriptInvokerScenarioFrameworkLayerMethod > ScriptInvokerScenarioFrameworkLayer
void SCR_ScenarioFrameworkSlotWaypoint(IEntityComponentSource src, IEntity ent, IEntity parent)
proto external Managed FindComponent(typename typeName)
proto external BaseWorld GetWorld()
Definition Math.c:13
void CheckWaypointsAfterInit(SCR_ScenarioFrameworkLayerBase layer)
ScriptInvokerScenarioFrameworkLayer GetOnAllWaypointsSpawned()
override void SetWaypointPrefab(ResourceName prefab)
void ProcessWaypoints(SCR_ScenarioFrameworkLayerBase layer)
override void SetWaypointCompletionType(EAIWaypointCompletionType type)
override EAIWaypointCompletionType GetWaypointCompletionType()
void ShuffleWaypointArray(notnull array< AIWaypoint > arr)
SCR_FieldOfViewSettings Attribute