Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ResourceGenerator.c
Go to the documentation of this file.
12
14{
16 protected float m_fResourceMultiplier;
17 protected float m_fRange;
19
20 //------------------------------------------------------------------------------------------------
21 void SCR_ResourceGenerationResponse(float availableResourceSpace = 0, float resourceMultiplier = 0, float range = 0, EResourceReason reasonCode = EResourceReason.UNAVAILABLE)
22 {
23 m_fAvailableResourceSpace = availableResourceSpace;
24 m_fResourceMultiplier = resourceMultiplier;
25 m_fRange = range;
26 m_eReason = reasonCode;
27 }
28
29 //------------------------------------------------------------------------------------------------
34
35 //------------------------------------------------------------------------------------------------
37 {
39 }
40
41 //------------------------------------------------------------------------------------------------
42 float GetRange()
43 {
44 return m_fRange;
45 }
46
47 //------------------------------------------------------------------------------------------------
49 {
50 return m_eReason;
51 }
52
53 //------------------------------------------------------------------------------------------------
54 void SetAvailableResourceSpace(float availableResourceSpace)
55 {
56 m_fAvailableResourceSpace = availableResourceSpace;
57 }
58
59 //------------------------------------------------------------------------------------------------
60 void SetResourceMultiplier(float resourceMultiplier)
61 {
62 m_fResourceMultiplier = resourceMultiplier;
63 }
64
65 //------------------------------------------------------------------------------------------------
66 void SetRange(float range)
67 {
68 m_fRange = range;
69 }
70
71 //------------------------------------------------------------------------------------------------
72 void SetReason(EResourceReason reasonCode)
73 {
74 m_eReason = reasonCode;
75 }
76};
77
78[BaseContainerProps(configRoot: true)]
79class SCR_ResourceGenerator : SCR_ResourceInteractor
80{
81 [Attribute(defvalue: EResourceGeneratorID.DEFAULT.ToString(), uiwidget: UIWidgets.ComboBox, desc: "Identifier for the generator", enums: ParamEnumArray.FromEnum(EResourceGeneratorID))]
82 EResourceGeneratorID m_eIdentifier;
83
84 [Attribute(defvalue: "1.0", uiwidget: UIWidgets.SpinBox, params: string.Format("0.0 %1 1.0", float.MAX))]
85 protected float m_fResourceMultiplier;
86
87 [Attribute(uiwidget: UIWidgets.SpinBox, desc: "Sets the range in meters on which the stored resource looks for a Storage point to merge with.",params: "0.0 10000.0 1.0")]
88 protected float m_fStorageRange;
89
90 [Attribute(uiwidget: UIWidgets.CheckBox)]
91 protected bool m_bIsIgnoringItself;
92
93 [Attribute(uiwidget: UIWidgets.Object)]
95
96 [Attribute(uiwidget: UIWidgets.Object)]
97 protected ref array<ref SCR_ResourceGeneratorActionBase> m_aActions;
98
99 //------------------------------------------------------------------------------------------------
100 override float GetResourceGridRange()
101 {
102 return m_fStorageRange;
103 }
104
105 //------------------------------------------------------------------------------------------------
107 {
108 return m_fStorageRange;
109 }
110
111 //------------------------------------------------------------------------------------------------
113 {
115 }
116
117 //------------------------------------------------------------------------------------------------
119 {
120 return m_eIdentifier;
121 }
122
123 //------------------------------------------------------------------------------------------------
125 {
126 if (!m_ContainerQueue)
127 return m_fAggregatedResourceValue;
128
129 return m_ContainerQueue.GetAggregatedResourceValue();
130 }
131
132 //------------------------------------------------------------------------------------------------
134 {
135 if (!m_ContainerQueue)
136 return m_fAggregatedMaxResourceValue;
137
138 return m_ContainerQueue.GetAggregatedMaxResourceValue();
139 }
140
141 //------------------------------------------------------------------------------------------------
142 override int GetContainerCount()
143 {
144 if (!m_ContainerQueue)
145 return 0.0;
146
147 return m_ContainerQueue.GetContainerCount();
148 }
149
150 //------------------------------------------------------------------------------------------------
155
156 //------------------------------------------------------------------------------------------------
158 {
159 return m_bIsIgnoringItself;
160 }
161
162 //------------------------------------------------------------------------------------------------
163 override bool CanInteractWith(notnull SCR_ResourceContainer container)
164 {
165 return (!m_bIsIgnoringItself || container.GetOwner() != m_Owner) && super.CanInteractWith(container);
166 }
167
168 //------------------------------------------------------------------------------------------------
169 override int FindContainer(notnull SCR_ResourceContainer container)
170 {
171 if (!m_ContainerQueue)
172 return super.FindContainer(container);
173
174 return m_ContainerQueue.FindContainer(container);
175 }
176
177 //------------------------------------------------------------------------------------------------
178 override bool RegisterContainer(notnull SCR_ResourceContainer container)
179 {
180 if (CanInteractWith(container)
182 && m_ContainerQueue.RegisterContainer(container) != SCR_ResourceContainerQueueBase.INVALID_CONTAINER_INDEX)
183 {
184 OnContainerRegistered(container);
185
186 return true;
187 }
188
189 return false;
190 }
191
192 //------------------------------------------------------------------------------------------------
193 override bool RegisterContainerForced(notnull SCR_ResourceContainer container)
194 {
195 if (m_ContainerQueue && m_ContainerQueue.RegisterContainer(container) != SCR_ResourceContainerQueueBase.INVALID_CONTAINER_INDEX)
196 {
197 OnContainerRegistered(container);
198
199 return true;
200 }
201
202 return false;
203 }
204
205 //------------------------------------------------------------------------------------------------
206 override bool UnregisterContainer(int containerIndex)
207 {
208 return m_ContainerQueue && m_ContainerQueue.PopContainerAt(containerIndex);
209 }
210
211 //------------------------------------------------------------------------------------------------
212 override bool UnregisterContainer(notnull SCR_ResourceContainer container)
213 {
214 return m_ContainerQueue && m_ContainerQueue.PopContainerAt(m_ContainerQueue.FindContainer(container));
215 }
216
217 //------------------------------------------------------------------------------------------------
219 {
220 GetGame().GetResourceGrid().UpdateInteractor(this);
221
223
224 if (response.GetAvailableResourceSpace() == 0)
225 {
226 response.SetReason(EResourceReason.UNAVAILABLE);
227
228 return response;
229 }
230
232 {
233 resourceAmount -= action.ComputeGeneratedResources(this, resourceAmount);
234
235 if (resourceAmount <= 0)
236 return response;
237 }
238
239 response.SetReason(EResourceReason.INSUFICIENT);
240
241 return response;
242 }
243
244 //------------------------------------------------------------------------------------------------
246 {
247 SCR_ResourceGenerationResponse response = RequestAvailability(resourceAmount);
248
249 if (response.GetReason() != EResourceReason.SUFFICIENT)
250 return response;
251
252 m_ContainerQueue.PerformSorting();
253
254 int containerCount = m_ContainerQueue.GetContainerCount();
255
257 {
258 if (resourceAmount <= 0)
259 break;
260
261 action.PerformAction(this, resourceAmount);
262 }
263
264 m_ResourceComponent.Replicate();
265
266 return response;
267 }
268
269 //------------------------------------------------------------------------------------------------
271 {
272 // TODO: Make it so that the nullity of these never happen in the first place.
274 return;
275
276 vector origin = GetOwnerOrigin();
277 Color color = m_ResourceComponent.GetDebugColor();
278 Color color2 = m_ResourceComponent.GetDebugColor();
279
280 color.Scale(0.2);
281 color.SetA(1.0);
282 color2.Lerp(Color.FromInt(Color.WHITE), 0.5);
283 color2.SetA(1.0);
284 Shape.CreateSphere(m_ResourceComponent.GetDebugColor().PackToInt(), ShapeFlags.ONCE | ShapeFlags.NOZWRITE | ShapeFlags.WIREFRAME, origin, m_fStorageRange);
285 DebugTextWorldSpace.Create(GetGame().GetWorld(), string.Format(" %1 \n %2 containers \n %3 / %4 resources \n %5 m ", m_sDebugName, GetContainerCount(), GetAggregatedResourceValue(), GetAggregatedMaxResourceValue(), m_fStorageRange), DebugTextFlags.ONCE | DebugTextFlags.CENTER | DebugTextFlags.FACE_CAMERA, origin[0], origin[1] + m_fStorageRange, origin[2], 10.0, color.PackToInt(), color2.PackToInt());
286
288 m_ContainerQueue.DebugDraw();
289 }
290
291 //------------------------------------------------------------------------------------------------
292 override void UpdateContainerResourceValue(SCR_ResourceContainer container, float previousValue)
293 {
295 m_ContainerQueue.UpdateContainerResourceValue(container.GetResourceValue(), previousValue)
296 );
297 }
298
299 //------------------------------------------------------------------------------------------------
300 override void UpdateContainerMaxResourceValue(SCR_ResourceContainer container, float previousValue)
301 {
302 OnMaxResourcesChanged(
303 m_ContainerQueue.UpdateContainerMaxResourceValue(container.GetMaxResourceValue(), previousValue)
304 );
305 }
306
307 //------------------------------------------------------------------------------------------------
308 override void Initialize(notnull IEntity owner)
309 {
310 super.Initialize(owner);
311
313
314 if (container && container.IsEncapsulated())
315 return;
316
318 m_ContainerQueue.Initialize(this);
319
320 if (container)
321 RegisterContainer(container);
322 }
323
324 //------------------------------------------------------------------------------------------------
325 override void Clear()
326 {
327 super.Clear();
328
330 m_ContainerQueue.Clear();
331
332 GetGame().GetResourceSystemSubscriptionManager().OnResourceInteractorDeleted(this);
333 }
334
335 //------------------------------------------------------------------------------------------------
337 {
338 RplId componentRplId = Replication.FindItemId(m_ResourceComponent);
339
340 return snapshot.Compare(componentRplId, 4)
341 && snapshot.Compare(m_fStorageRange, 4)
342 && snapshot.Compare(m_fAggregatedResourceValue, 4)
343 && snapshot.Compare(m_fAggregatedMaxResourceValue, 4)
344 && snapshot.Compare(m_fResourceMultiplier, 4)
345 && snapshot.Compare(m_eResourceRights, 4)
346 && snapshot.Compare(m_eResourceType, 4)
347 && snapshot.Compare(m_eIdentifier, 4);
348 }
349
350 //------------------------------------------------------------------------------------------------
352 {
353 float aggregatedResourceValue = GetAggregatedResourceValue();
354 float aggregatedMaxResourceValue = GetAggregatedMaxResourceValue();
355 RplId componentRplId = Replication.FindItemId(m_ResourceComponent);
356
357 snapshot.SerializeBytes(componentRplId, 4);
358 snapshot.SerializeBytes(m_fStorageRange, 4);
359 snapshot.SerializeBytes(aggregatedResourceValue, 4);
360 snapshot.SerializeBytes(aggregatedMaxResourceValue, 4);
361 snapshot.SerializeBytes(m_fResourceMultiplier, 4);
362 snapshot.SerializeBytes(m_eResourceRights, 4);
363 snapshot.SerializeBytes(m_eResourceType, 4);
364 snapshot.SerializeBytes(m_eIdentifier, 4);
365
366 return true;
367 }
368
369
370 //------------------------------------------------------------------------------------------------
372 {
373 RplId componentRplId;
374
375 snapshot.SerializeBytes(componentRplId, 4);
376 snapshot.SerializeBytes(m_fStorageRange, 4);
377 snapshot.SerializeBytes(m_fAggregatedResourceValue, 4);
378 snapshot.SerializeBytes(m_fAggregatedMaxResourceValue, 4);
379 snapshot.SerializeBytes(m_fResourceMultiplier, 4);
380 snapshot.SerializeBytes(m_eResourceRights, 4);
381 snapshot.SerializeBytes(m_eResourceType, 4);
382 snapshot.SerializeBytes(m_eIdentifier, 4);
383
384 m_ResourceComponent = SCR_ResourceComponent.Cast(Replication.FindItem(componentRplId));
385
387 return false;
388
389 m_Owner = m_ResourceComponent.GetOwner();
390
391 return true;
392 }
393
394 //------------------------------------------------------------------------------------------------
395 static void Encode(SSnapSerializerBase snapshot, ScriptCtx ctx, ScriptBitSerializer packet)
396 {
397 snapshot.Serialize(packet, SCR_ResourceGenerator.CODEC_GENERATOR_PACKET_BYTESIZE);
398 }
399
400 //------------------------------------------------------------------------------------------------
401 static bool Decode(ScriptBitSerializer packet, ScriptCtx ctx, SSnapSerializerBase snapshot)
402 {
403 return snapshot.Serialize(packet, SCR_ResourceGenerator.CODEC_GENERATOR_PACKET_BYTESIZE);
404 }
405
406 //------------------------------------------------------------------------------------------------
408 {
409 return lhs.CompareSnapshots(rhs, SCR_ResourceGenerator.CODEC_GENERATOR_PACKET_BYTESIZE);
410 }
411
412 //------------------------------------------------------------------------------------------------
414 {
415 return instance.PropCompareNetworkedVariables(snapshot, ctx);
416 }
417
418 //------------------------------------------------------------------------------------------------
419 static bool Extract(SCR_ResourceGenerator instance, ScriptCtx ctx, SSnapSerializerBase snapshot)
420 {
421 return instance.ExtractNetworkedVariables(snapshot, ctx);
422 }
423
424 //------------------------------------------------------------------------------------------------
425 static bool Inject(SSnapSerializerBase snapshot, ScriptCtx ctx, SCR_ResourceGenerator instance)
426 {
427 return instance.InjectNetworkedVariables(snapshot, ctx);
428 }
429}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
EResourceType m_eResourceType
EResourceGeneratorID
@ DEFAULT_STORAGE
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void OnResourcesChanged(SCR_ResourceInteractor interactor, float previousSupplies)
SCR_ResourceComponent m_ResourceComponent
Definition Color.c:13
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
void SetReason(EResourceReason reasonCode)
void SetResourceMultiplier(float resourceMultiplier)
void SCR_ResourceGenerationResponse(float availableResourceSpace=0, float resourceMultiplier=0, float range=0, EResourceReason reasonCode=EResourceReason.UNAVAILABLE)
void SetAvailableResourceSpace(float availableResourceSpace)
override float GetResourceGridRange()
override float GetAggregatedResourceValue()
override bool CanInteractWith(notnull SCR_ResourceContainer container)
static bool Extract(SCR_ResourceGenerator instance, ScriptCtx ctx, SSnapSerializerBase snapshot)
override bool UnregisterContainer(int containerIndex)
static bool PropCompare(SCR_ResourceGenerator instance, SSnapSerializerBase snapshot, ScriptCtx ctx)
override bool RegisterContainer(notnull SCR_ResourceContainer container)
override bool UnregisterContainer(notnull SCR_ResourceContainer container)
static bool SnapCompare(SSnapSerializerBase lhs, SSnapSerializerBase rhs, ScriptCtx ctx)
override void UpdateContainerResourceValue(SCR_ResourceContainer container, float previousValue)
override void UpdateContainerMaxResourceValue(SCR_ResourceContainer container, float previousValue)
override bool RegisterContainerForced(notnull SCR_ResourceContainer container)
bool InjectNetworkedVariables(SSnapSerializerBase snapshot, ScriptCtx hint)
static bool Inject(SSnapSerializerBase snapshot, ScriptCtx ctx, SCR_ResourceGenerator instance)
static bool Decode(ScriptBitSerializer packet, ScriptCtx ctx, SSnapSerializerBase snapshot)
bool ExtractNetworkedVariables(SSnapSerializerBase snapshot, ScriptCtx hint)
ref array< ref SCR_ResourceGeneratorActionBase > m_aActions
override void Initialize(notnull IEntity owner)
ref SCR_ResourceGeneratorContainerQueue m_ContainerQueue
override int FindContainer(notnull SCR_ResourceContainer container)
override SCR_ResourceContainerQueueBase GetContainerQueue()
static void Encode(SSnapSerializerBase snapshot, ScriptCtx ctx, ScriptBitSerializer packet)
SCR_ResourceGenerationResponse RequestAvailability(float resourceAmount)
SCR_ResourceGenerationResponse RequestGeneration(float resourceAmount, SCR_ResourceGenerator generator=null)
bool PropCompareNetworkedVariables(SSnapSerializerBase snapshot, ScriptCtx hint)
override float GetAggregatedMaxResourceValue()
override EResourceGeneratorID GetIdentifier()
Instance of created debug visualizer.
Definition Shape.c:14
DebugTextFlags
ShapeFlags
Definition ShapeFlags.c:13
@ DEFAULT
Use currently set main RT format (based on game options).
SCR_FieldOfViewSettings Attribute
@ INVALID
Missing components, or obstruction test was not possible.