Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SuppliesTransportSystem.c
Go to the documentation of this file.
3typedef ScriptInvokerBase<OnTransportUnitChangedDelegate> OnTransportUnitChangedInvoker;
4
6{
7 [Attribute("5", desc: "How often will the Supplies transport system be updated [s].", params: "0 100 0.1")]
8 protected float m_fUpdateInterval;
9
10 protected float m_fTimer;
11
12 protected ref set<SCR_TransportUnitComponent> m_TransportUnits = new set<SCR_TransportUnitComponent>();
13
15
18
19 //------------------------------------------------------------------------------------------------
20 override static void InitInfo(WorldSystemInfo outInfo)
21 {
22 outInfo
23 .SetAbstract(false)
24 .AddPoint(ESystemPoint.FixedFrame);
25 }
26
27 //------------------------------------------------------------------------------------------------
30 {
31 World world = GetGame().GetWorld();
32 if (!world)
33 return null;
34
35 return SCR_SuppliesTransportSystem.Cast(world.FindSystem(SCR_SuppliesTransportSystem));
36 }
37
38 //------------------------------------------------------------------------------------------------
46
47 //------------------------------------------------------------------------------------------------
55
56 //------------------------------------------------------------------------------------------------
57 set<SCR_TransportUnitComponent> GetTransportUnits()
58 {
59 return m_TransportUnits;
60 }
61
62 //------------------------------------------------------------------------------------------------
63 int GetTransportUnits(out notnull array<SCR_TransportUnitComponent> transportUnits, Faction faction)
64 {
65 transportUnits.Clear();
66 int index;
67 foreach (SCR_TransportUnitComponent transportUnit : m_TransportUnits)
68 {
69 if (transportUnit.GetFaction() == faction)
70 {
71 transportUnits.Insert(transportUnit);
72 index++;
73 }
74 }
75
76 return index;
77 }
78
79 //------------------------------------------------------------------------------------------------
80 bool Register(notnull SCR_TransportUnitComponent transportUnit)
81 {
82 if (m_TransportUnits.Insert(transportUnit))
83 {
85 m_OnTransportUnitAdded.Invoke(transportUnit);
86
87 return true;
88 }
89
90 return false;
91 }
92
93 //------------------------------------------------------------------------------------------------
94 bool Unregister(notnull SCR_TransportUnitComponent transportUnit)
95 {
96 if (m_TransportUnits.RemoveItem(transportUnit))
97 {
99 m_OnTransportUnitRemoved.Invoke(transportUnit);
100
101 return true;
102 }
103
104 return false;
105 }
106
107 //------------------------------------------------------------------------------------------------
112 bool IsVehicleUsed(Vehicle vehicle, SCR_TransportUnitComponent ignoredTransportUnit = null)
113 {
114 foreach (SCR_TransportUnitComponent transportUnit : m_TransportUnits)
115 {
116 if (transportUnit == ignoredTransportUnit)
117 continue;
118
119 if (transportUnit.GetState() == SCR_ETransportUnitState.ON_TASK && transportUnit.GetVehicle() == vehicle)
120 return true;
121 }
122
123 return false;
124 }
125
126 //------------------------------------------------------------------------------------------------
131 bool IsVehicleSelected(Vehicle vehicle, SCR_TransportUnitComponent ignoredTransportUnit = null)
132 {
133 foreach (SCR_TransportUnitComponent transportUnit : m_TransportUnits)
134 {
135 if (transportUnit == ignoredTransportUnit)
136 continue;
137
138 if (transportUnit.GetVehicle() == vehicle)
139 return true;
140 }
141
142 return false;
143 }
144
145 //------------------------------------------------------------------------------------------------
150 bool IsVehicleBoarded(Vehicle vehicle, SCR_TransportUnitComponent ignoredTransportUnit = null)
151 {
152 foreach (SCR_TransportUnitComponent transportUnit : m_TransportUnits)
153 {
154 if (transportUnit == ignoredTransportUnit)
155 continue;
156
157 if (transportUnit.GetVehicle() != vehicle)
158 continue;
159
160 if (transportUnit.GetResupplyTaskSolverState() == SCR_EResupplyTaskSolverState.BOARDING_VEHICLE)
161 return true;
162 }
163
164 return false;
165 }
166
167 //------------------------------------------------------------------------------------------------
172 bool IsTaskSolved(SCR_Task task, SCR_TransportUnitComponent ignoredTransportUnit = null)
173 {
174 foreach (SCR_TransportUnitComponent transportUnit : m_TransportUnits)
175 {
176 if (transportUnit == ignoredTransportUnit)
177 continue;
178
179 if (transportUnit.GetState() == SCR_ETransportUnitState.ON_TASK && transportUnit.GetPreferableResupplyTask() == task)
180 return true;
181 }
182
183 return false;
184 }
185
186 //------------------------------------------------------------------------------------------------
187 override protected void OnUpdatePoint(WorldUpdatePointArgs args)
188 {
189 float timeSlice = args.GetTimeSliceSeconds();
190
191 m_fTimer += timeSlice;
192 if (m_fTimer < m_fUpdateInterval)
193 return;
194
195 m_fTimer = 0;
196
197 if (m_TransportUnits.IsEmpty())
198 return;
199
200 foreach (SCR_TransportUnitComponent transportUnit : m_TransportUnits)
201 {
202 transportUnit.Update(timeSlice);
203 }
204
206
207 foreach (SCR_TransportUnitComponent transportUnit : m_TransportUnits)
208 {
209 transportUnit.ReturnToSourceBaseIfNeeded();
210 }
211 }
212
213 //------------------------------------------------------------------------------------------------
215 {
217 foreach (SCR_TransportUnitComponent transportUnit : m_TransportUnits)
218 {
219 if (transportUnit.IsReadyForTaskSolving())
220 {
221 SCR_ResupplyCampaignMilitaryBaseTaskEntity task = transportUnit.GetPreferableResupplyTask();
222 if (!task || IsTaskSolved(task))
223 continue;
224
225 array<SCR_TransportUnitComponent> units = m_mResupplyTaskToTransportUnitsMap.Get(task);
226 if (units)
227 {
228 units.Insert(transportUnit);
229 }
230 else
231 {
232 units = {};
233 units.Insert(transportUnit);
235 }
236 }
237 }
238 }
239
240 //------------------------------------------------------------------------------------------------
241 protected void StartSolvingTaskByClosestUnit(SCR_ResupplyCampaignMilitaryBaseTaskEntity task, array<SCR_TransportUnitComponent> units)
242 {
243 float minSqDistance = float.MAX;
244 SCR_TransportUnitComponent closestTransportUnit;
245 foreach (SCR_TransportUnitComponent transportUnit : units)
246 {
247 float sqDistance = vector.DistanceSqXZ(task.GetOrigin(), transportUnit.GetOwner().GetOrigin());
248 if (sqDistance < minSqDistance)
249 {
250 minSqDistance = sqDistance;
251 closestTransportUnit = transportUnit;
252 }
253 }
254
255 if (closestTransportUnit)
256 {
257 closestTransportUnit.SelectForTaskSolving(task);
258 }
259 }
260
261 //------------------------------------------------------------------------------------------------
262 protected void EvaluateTransportUnits()
263 {
265
266 foreach (SCR_ResupplyCampaignMilitaryBaseTaskEntity task, array<SCR_TransportUnitComponent> units : m_mResupplyTaskToTransportUnitsMap)
267 {
269 }
270 }
271
272 //------------------------------------------------------------------------------------------------
273 override protected void OnInit()
274 {
275 super.OnInit();
276
277 if (GetNode().GetRole() == RplRole.Proxy)
278 Enable(false);
279 }
280
281 //------------------------------------------------------------------------------------------------
283 override protected void OnDiag(float timeSlice)
284 {
285 super.OnDiag(timeslice);
286
287 DrawDebug();
288 }
289
290 //------------------------------------------------------------------------------------------------
291 protected void DrawDebug()
292 {
293 DbgUI.Begin("SCR_SuppliesTransportSystem", 0, 100);
294
295 string time = SCR_FormatHelper.FormatTime(GetWorld().GetWorldTime() * 0.001);
296 DbgUI.Text(string.Format("Time: %1.", time));
297 foreach (SCR_TransportUnitComponent transportUnit : m_TransportUnits)
298 {
299 if (!transportUnit)
300 continue;
301
302 string sourceBaseName = "None";
303 SCR_CampaignMilitaryBaseComponent base = transportUnit.GetSourceBase();
304 if (base)
305 sourceBaseName = base.GetCallsignDisplayNameOnly();
306
307 string transportUnitState = SCR_Enum.GetEnumName(SCR_ETransportUnitState, transportUnit.GetState());
308
309 SCR_ResupplyTaskSolver resupplySolver = transportUnit.GetSolver();
310 string solverState = "No Solver";
311 string resupplySolverState = solverState;
312 if (resupplySolver)
313 {
314 solverState = SCR_Enum.GetEnumName(SCR_ETaskSolverState, resupplySolver.GetState());
315 resupplySolverState = SCR_Enum.GetEnumName(SCR_EResupplyTaskSolverState, resupplySolver.GetResupplyTaskSolverState());
316 }
317
318 string preferableTaskName = "None";
319 SCR_ResupplyCampaignMilitaryBaseTaskEntity resupplyTask = transportUnit.GetPreferableResupplyTask();
320 if (resupplyTask)
321 {
322 SCR_CampaignMilitaryBaseComponent suppliedBase = resupplyTask.GetMilitaryBase();
323 if (suppliedBase)
324 {
325 preferableTaskName = string.Format("Resupply %1 (%2)", suppliedBase.GetBaseNameUpperCase(), suppliedBase.GetCallsignDisplayNameOnlyUC());
326 }
327 }
328
329 string transportUnitName = transportUnit.GetName();
330
331 // Remove the hash from the string; otherwise, DbgUI.Text will throw a warning about a missing string ID.
332 if (transportUnitName.StartsWith("#"))
333 transportUnitName = transportUnitName.Substring(1, transportUnitName.Length() - 1);
334
335 DbgUI.Text(string.Format("%1 - state: %2, usable vehicle: %3, source base: %4, prefered task: %5, solver state: %6, resupply solver state: %7",
336 transportUnitName, transportUnitState, transportUnit.IsVehicleUsable(), sourceBaseName, preferableTaskName, solverState,
337 resupplySolverState));
338
339 Vehicle vehicle = transportUnit.GetVehicle();
340 if (!vehicle)
341 continue;
342
343 int lineColor = Color.DODGER_BLUE;
344 if (transportUnit.GetState() == SCR_ETransportUnitState.ON_TASK)
345 lineColor = Color.SPRING_GREEN;
346
347 Shape.Create(ShapeType.LINE, lineColor, ShapeFlags.ONCE | ShapeFlags.NOZBUFFER, transportUnit.GetOwner().GetOrigin(), vehicle.GetOrigin());
348 }
349
350 DbgUI.End();
351 }
352}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
SCR_ETaskSolverState
SCR_ETransportUnitState
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ScriptInvokerBase< OnTransportUnitChangedDelegate > OnTransportUnitChangedInvoker
func OnTransportUnitChangedDelegate
void SCR_Task(IEntitySource src, IEntity parent)
Definition SCR_Task.c:1938
Definition Color.c:13
Definition DbgUI.c:66
string GetBaseNameUpperCase()
Returns the upper-case name of this base.
SCR_EResupplyTaskSolverState GetResupplyTaskSolverState()
ref OnTransportUnitChangedInvoker m_OnTransportUnitRemoved
set< SCR_TransportUnitComponent > GetTransportUnits()
OnTransportUnitChangedInvoker GetOnTransportUnitRemoved()
bool IsTaskSolved(SCR_Task task, SCR_TransportUnitComponent ignoredTransportUnit=null)
ref OnTransportUnitChangedInvoker m_OnTransportUnitAdded
bool Register(notnull SCR_TransportUnitComponent transportUnit)
ref map< SCR_ResupplyCampaignMilitaryBaseTaskEntity, ref array< SCR_TransportUnitComponent > > m_mResupplyTaskToTransportUnitsMap
OnTransportUnitChangedInvoker GetOnTransportUnitAdded()
void StartSolvingTaskByClosestUnit(SCR_ResupplyCampaignMilitaryBaseTaskEntity task, array< SCR_TransportUnitComponent > units)
bool IsVehicleSelected(Vehicle vehicle, SCR_TransportUnitComponent ignoredTransportUnit=null)
bool Unregister(notnull SCR_TransportUnitComponent transportUnit)
bool IsVehicleBoarded(Vehicle vehicle, SCR_TransportUnitComponent ignoredTransportUnit=null)
static SCR_SuppliesTransportSystem GetInstance()
ref set< SCR_TransportUnitComponent > m_TransportUnits
bool IsVehicleUsed(Vehicle vehicle, SCR_TransportUnitComponent ignoredTransportUnit=null)
static override void InitInfo(WorldSystemInfo outInfo)
void OnUpdatePoint(WorldUpdatePointArgs args)
int GetTransportUnits(out notnull array< SCR_TransportUnitComponent > transportUnits, Faction faction)
void SelectForTaskSolving(SCR_ResupplyCampaignMilitaryBaseTaskEntity task)
Instance of created debug visualizer.
Definition Shape.c:14
Definition World.c:16
Structure holding world system meta-information required by the engine.
Structure holding extra data of WorldSystem update point.
Definition Types.c:486
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
WorldSystemPoint ESystemPoint
Definition gameLib.c:7
BaseRplComponentClass GenericComponentClass GetNode()
ShapeType
Definition ShapeType.c:13
ShapeFlags
Definition ShapeFlags.c:13
SCR_FieldOfViewSettings Attribute
RplRole
Role of replicated node (and all items in it) within the replication system.
Definition RplRole.c:14