Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ResourceGenerator.c
Go to the documentation of this file.
2 {
3  INVALID = -1,
4  DEFAULT = 0,
8  SELF,
11 };
12 
14 {
15  protected float m_fAvailableResourceSpace;
16  protected float m_fResourceMultiplier;
17  protected float m_fRange;
18  protected EResourceReason m_eReason;
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  //------------------------------------------------------------------------------------------------
30  float GetAvailableResourceSpace()
31  {
32  return m_fAvailableResourceSpace;
33  }
34 
35  //------------------------------------------------------------------------------------------------
36  float GetResourceMultiplier()
37  {
38  return m_fResourceMultiplier;
39  }
40 
41  //------------------------------------------------------------------------------------------------
42  float GetRange()
43  {
44  return m_fRange;
45  }
46 
47  //------------------------------------------------------------------------------------------------
48  EResourceReason GetReason()
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)]
79 class 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)]
94  protected ref SCR_ResourceGeneratorContainerQueue m_ContainerQueue;
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  //------------------------------------------------------------------------------------------------
106  float GetStorageRange()
107  {
108  return m_fStorageRange;
109  }
110 
111  //------------------------------------------------------------------------------------------------
112  float GetResourceMultiplier()
113  {
114  return m_fResourceMultiplier;
115  }
116 
117  //------------------------------------------------------------------------------------------------
118  override EResourceGeneratorID GetIdentifier()
119  {
120  return m_eIdentifier;
121  }
122 
123  //------------------------------------------------------------------------------------------------
124  override float GetAggregatedResourceValue()
125  {
126  if (!m_ContainerQueue)
127  return m_fAggregatedResourceValue;
128 
129  return m_ContainerQueue.GetAggregatedResourceValue();
130  }
131 
132  //------------------------------------------------------------------------------------------------
133  override float GetAggregatedMaxResourceValue()
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  //------------------------------------------------------------------------------------------------
151  override SCR_ResourceContainerQueueBase GetContainerQueue()
152  {
153  return m_ContainerQueue;
154  }
155 
156  //------------------------------------------------------------------------------------------------
157  bool IsIgnoringItself()
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)
181  && m_ContainerQueue
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  //------------------------------------------------------------------------------------------------
218  SCR_ResourceGenerationResponse RequestAvailability(float resourceAmount)
219  {
220  GetGame().GetResourceGrid().UpdateInteractor(this);
221 
222  SCR_ResourceGenerationResponse response = new SCR_ResourceGenerationResponse(GetAggregatedMaxResourceValue() - GetAggregatedResourceValue(), m_fResourceMultiplier, m_fStorageRange, EResourceReason.SUFFICIENT);
223 
224  if (resourceAmount > response.GetAvailableResourceSpace())
225  {
226  response.SetReason(EResourceReason.INSUFICIENT);
227 
228  return response;
229  }
230 
231  if (response.GetAvailableResourceSpace() == 0)
232  {
233  response.SetReason(EResourceReason.UNAVAILABLE);
234 
235  return response;
236  }
237 
238  return response;
239  }
240 
241  //------------------------------------------------------------------------------------------------
242  SCR_ResourceGenerationResponse RequestGeneration(float resourceAmount, SCR_ResourceGenerator generator = null)
243  {
244  SCR_ResourceGenerationResponse response = RequestAvailability(resourceAmount);
245 
246  m_ContainerQueue.PerformSorting();
247 
248  int containerCount = m_ContainerQueue.GetContainerCount();
249 
251  {
252  if (resourceAmount <= 0)
253  break;
254 
255  for (int i = 0; i < containerCount; i++)
256  {
257  action.PerformAction(m_ContainerQueue.GetContainerAt(i), resourceAmount);
258 
259  if (m_ContainerQueue.GetContainerCount() != containerCount)
260  {
261  containerCount--;
262  i--;
263  }
264  }
265  }
266 
267  m_ResourceComponent.Replicate();
268 
269  return response;
270  }
271 
272  //------------------------------------------------------------------------------------------------
273  void DebugDraw()
274  {
275  // TODO: Make it so that the nullity of these never happen in the first place.
276  if (!m_Owner || !m_ResourceComponent)
277  return;
278 
279  vector origin = GetOwnerOrigin();
280  Color color = m_ResourceComponent.GetDebugColor();
281  Color color2 = m_ResourceComponent.GetDebugColor();
282 
283  color.Scale(0.2);
284  color.SetA(1.0);
285  color2.Lerp(Color.FromInt(Color.WHITE), 0.5);
286  color2.SetA(1.0);
287  Shape.CreateSphere(m_ResourceComponent.GetDebugColor().PackToInt(), ShapeFlags.ONCE | ShapeFlags.NOZWRITE | ShapeFlags.WIREFRAME, origin, m_fStorageRange);
288  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());
289 
290  if (m_ContainerQueue)
291  m_ContainerQueue.DebugDraw();
292  }
293 
294  //------------------------------------------------------------------------------------------------
295  override void UpdateContainerResourceValue(SCR_ResourceContainer container, float previousValue)
296  {
297  OnResourcesChanged(
298  m_ContainerQueue.UpdateContainerResourceValue(container.GetResourceValue(), previousValue)
299  );
300  }
301 
302  //------------------------------------------------------------------------------------------------
303  override void UpdateContainerMaxResourceValue(SCR_ResourceContainer container, float previousValue)
304  {
305  OnMaxResourcesChanged(
306  m_ContainerQueue.UpdateContainerMaxResourceValue(container.GetMaxResourceValue(), previousValue)
307  );
308  }
309 
310  //------------------------------------------------------------------------------------------------
311  override void Initialize(notnull IEntity owner)
312  {
313  super.Initialize(owner);
314 
315  SCR_ResourceContainer container = m_ResourceComponent.GetContainer(m_eResourceType);
316 
317  if (container && container.IsEncapsulated())
318  return;
319 
320  if (m_ContainerQueue)
321  m_ContainerQueue.Initialize(this);
322 
323  if (container)
324  RegisterContainer(container);
325  }
326 
327  //------------------------------------------------------------------------------------------------
328  override void Clear()
329  {
330  super.Clear();
331 
332  if (m_ContainerQueue)
333  m_ContainerQueue.Clear();
334 
335  GetGame().GetResourceSystemSubscriptionManager().OnResourceInteractorDeleted(this);
336  }
337 
338  //------------------------------------------------------------------------------------------------
339  protected bool PropCompareNetworkedVariables(SSnapSerializerBase snapshot, ScriptCtx hint)
340  {
341  RplId componentRplId = Replication.FindId(m_ResourceComponent);
342 
343  return snapshot.Compare(componentRplId, 4)
344  && snapshot.Compare(m_fStorageRange, 4)
345  && snapshot.Compare(m_fAggregatedResourceValue, 4)
346  && snapshot.Compare(m_fAggregatedMaxResourceValue, 4)
347  && snapshot.Compare(m_eResourceRights, 4)
348  && snapshot.Compare(m_eResourceType, 4)
349  && snapshot.Compare(m_eIdentifier, 4);
350  }
351 
352  //------------------------------------------------------------------------------------------------
353  protected bool ExtractNetworkedVariables(SSnapSerializerBase snapshot, ScriptCtx hint)
354  {
355  float aggregatedResourceValue = GetAggregatedResourceValue();
356  float aggregatedMaxResourceValue = GetAggregatedMaxResourceValue();
357  RplId componentRplId = Replication.FindId(m_ResourceComponent);
358 
359  snapshot.SerializeBytes(componentRplId, 4);
360  snapshot.SerializeBytes(m_fStorageRange, 4);
361  snapshot.SerializeBytes(aggregatedResourceValue, 4);
362  snapshot.SerializeBytes(aggregatedMaxResourceValue, 4);
363  snapshot.SerializeBytes(m_eResourceRights, 4);
364  snapshot.SerializeBytes(m_eResourceType, 4);
365  snapshot.SerializeBytes(m_eIdentifier, 4);
366 
367  return true;
368  }
369 
370 
371  //------------------------------------------------------------------------------------------------
372  protected bool InjectNetworkedVariables(SSnapSerializerBase snapshot, ScriptCtx hint)
373  {
374  RplId componentRplId;
375 
376  snapshot.SerializeBytes(componentRplId, 4);
377  snapshot.SerializeBytes(m_fStorageRange, 4);
378  snapshot.SerializeBytes(m_fAggregatedResourceValue, 4);
379  snapshot.SerializeBytes(m_fAggregatedMaxResourceValue, 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 
386  if (!m_ResourceComponent)
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  //------------------------------------------------------------------------------------------------
407  static bool SnapCompare(SSnapSerializerBase lhs, SSnapSerializerBase rhs , ScriptCtx ctx)
408  {
409  return lhs.CompareSnapshots(rhs, SCR_ResourceGenerator.CODEC_GENERATOR_PACKET_BYTESIZE);
410  }
411 
412  //------------------------------------------------------------------------------------------------
413  static bool PropCompare(SCR_ResourceGenerator instance, SSnapSerializerBase snapshot, ScriptCtx ctx)
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 }
DUMMY_1
@ DUMMY_1
Definition: SCR_ResourceGenerator.c:9
DEFAULT_STORAGE
@ DEFAULT_STORAGE
Definition: SCR_ResourceGenerator.c:5
m_aActions
ref SCR_SortedArray< SCR_BaseEditorAction > m_aActions
Definition: SCR_BaseActionsEditorComponent.c:8
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
INVALID
@ INVALID
Definition: SCR_ResourceGenerator.c:3
EResourceReason
EResourceReason
Definition: SCR_ResourceConsumtionResponse.c:1
m_fRange
protected float m_fRange
Definition: SCR_BaseSupportStationComponent.c:94
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_ResourceContainerQueueBase
Definition: SCR_ResourceContainerQueue.c:2
SCR_ResourceGeneratorContainerQueue
Definition: SCR_ResourceGeneratorContainerQueue.c:2
DUMMY_2
@ DUMMY_2
Definition: SCR_ResourceGenerator.c:10
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_fResourceMultiplier
protected float m_fResourceMultiplier
Definition: SCR_ResourceConsumtionResponse.c:12
m_ResourceComponent
protected SCR_ResourceComponent m_ResourceComponent
Definition: SCR_CampaignBuildingProviderComponent.c:51
m_eReason
protected EResourceReason m_eReason
Definition: SCR_ResourceConsumtionResponse.c:14
VEHICLE_LOAD
@ VEHICLE_LOAD
Definition: SCR_ResourceGenerator.c:7
SELF
@ SELF
Definition: SCR_ResourceGenerator.c:8
SCR_ResourceGenerationResponse
Definition: SCR_ResourceGenerator.c:13
SCR_ResourceContainer
Definition: SCR_ResourceContainer.c:34
DEFAULT
@ DEFAULT
Definition: SCR_ResourceGenerator.c:4
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
VEHICLE_UNLOAD
@ VEHICLE_UNLOAD
Definition: SCR_ResourceGenerator.c:6
SCR_ResourceGeneratorActionBase
Definition: SCR_ResourceGeneratorActionBase.c:2
m_Owner
SCR_AIGroupUtilityComponentClass m_Owner
SCR_ResourceGenerator
Definition: SCR_ResourceGenerator.c:79
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
EResourceGeneratorID
EResourceGeneratorID
Definition: SCR_ResourceGenerator.c:1