Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ResourceEncapsulator.c
Go to the documentation of this file.
1 class SCR_ResourceEncapsulator : SCR_ResourceInteractor
2 {
3  protected SCR_ResourceContainer m_ContainerRepresentative;
4 
5  [Attribute(uiwidget: UIWidgets.Object)]
6  protected ref SCR_ResourceEncapsulatorContainerQueue m_ContainerQueue;
7 
8  [Attribute(uiwidget: UIWidgets.Object)]
9  protected ref array<ref SCR_ResourceEncapsulatorActionBase> m_aActions;
10 
11  //------------------------------------------------------------------------------------------------
12  override float GetAggregatedResourceValue()
13  {
14  if (!m_ContainerQueue)
15  return m_fAggregatedResourceValue;
16 
17  return m_ContainerQueue.GetAggregatedResourceValue();
18  }
19 
20  //------------------------------------------------------------------------------------------------
21  override float GetAggregatedMaxResourceValue()
22  {
23  if (!m_ContainerQueue)
24  return m_fAggregatedMaxResourceValue;
25 
26  return m_ContainerQueue.GetAggregatedMaxResourceValue();
27  }
28 
29  //------------------------------------------------------------------------------------------------
30  override int GetContainerCount()
31  {
32  if (!m_ContainerQueue)
33  return 0.0;
34 
35  return m_ContainerQueue.GetContainerCount();
36  }
37 
38  //------------------------------------------------------------------------------------------------
39  override SCR_ResourceContainerQueueBase GetContainerQueue()
40  {
41  return m_ContainerQueue;
42  }
43 
44  //------------------------------------------------------------------------------------------------
45  SCR_ResourceContainer GetContainerRepresentative()
46  {
47  return m_ContainerRepresentative;
48  }
49 
50  //------------------------------------------------------------------------------------------------
51  array<ref SCR_ResourceEncapsulatorActionBase> GetActions()
52  {
53  return m_aActions;
54  }
55 
56  //------------------------------------------------------------------------------------------------
57  override bool IsAllowed(notnull SCR_ResourceContainer container)
58  {
59  return container.GetResourceType() == m_eResourceType;
60  }
61 
62  //------------------------------------------------------------------------------------------------
63  bool IsContainerRepresentative(notnull SCR_ResourceContainer container)
64  {
65  return container == m_ContainerRepresentative;
66  }
67 
68  //------------------------------------------------------------------------------------------------
69  override bool ShouldUpdate()
70  {
71  return false;
72  }
73 
74  //------------------------------------------------------------------------------------------------
75  override int FindContainer(notnull SCR_ResourceContainer container)
76  {
77  if (!m_ContainerQueue)
78  return super.FindContainer(container);
79 
80  return m_ContainerQueue.FindContainer(container);
81  }
82 
83  //------------------------------------------------------------------------------------------------
84  void SetContainerRepresentative(notnull SCR_ResourceContainer container)
85  {
86  m_ContainerRepresentative = container;
87 
88  if (m_ContainerRepresentative)
89  m_ContainerRepresentative.SetResourceEncapsulator(this);
90  }
91 
92  //------------------------------------------------------------------------------------------------
93  override bool RegisterContainer(notnull SCR_ResourceContainer container)
94  {
95  if (CanInteractWith(container)
96  && m_ContainerQueue
97  && m_ContainerQueue.RegisterContainer(container) != SCR_ResourceContainerQueueBase.INVALID_CONTAINER_INDEX)
98  {
99  OnContainerRegistered(container);
100 
101  return true;
102  }
103 
104  return false;
105  }
106 
107  //------------------------------------------------------------------------------------------------
108  override bool RegisterContainerForced(notnull SCR_ResourceContainer container)
109  {
110  if (m_ContainerQueue && m_ContainerQueue.RegisterContainer(container) != SCR_ResourceContainerQueueBase.INVALID_CONTAINER_INDEX)
111  {
112  OnContainerRegistered(container);
113 
114  return true;
115  }
116 
117  return false;
118  }
119 
120  //------------------------------------------------------------------------------------------------
121  override bool UnregisterContainer(int containerIndex)
122  {
123  return m_ContainerQueue && m_ContainerQueue.PopContainerAt(containerIndex);
124  }
125 
126  //------------------------------------------------------------------------------------------------
127  override bool UnregisterContainer(notnull SCR_ResourceContainer container)
128  {
129  return m_ContainerQueue && m_ContainerQueue.PopContainerAt(m_ContainerQueue.FindContainer(container));
130  }
131 
132  //------------------------------------------------------------------------------------------------
133  void RequestConsumtion(float resourceCost, bool notifyChange = true)
134  {
135  float resourceUsed;
136  SCR_ResourceContainer container;
137 
138  for (int i = m_ContainerQueue.GetContainerCount() - 1; i >= 0 && resourceCost > 0.0; --i)
139  {
140  container = m_ContainerQueue.GetContainerAt(i);
141  resourceUsed = Math.Min(resourceCost, container.GetResourceValue());
142 
143  if (container.GetOnEmptyBehavior() == EResourceContainerOnEmptyBehavior.DELETE && resourceUsed < resourceCost)
144  i--;
145 
146  resourceCost -= resourceUsed;
147 
148  container.DecreaseResourceValue(resourceUsed, notifyChange);
149  }
150 
152  m_ResourceComponent.Replicate();
153  }
154 
155  //------------------------------------------------------------------------------------------------
156  void RequestGeneration(float resourceAmount, bool notifyChange = true)
157  {
158  float resourceUsed
159  SCR_ResourceContainer container;
160  int containerCount = m_ContainerQueue.GetContainerCount();
161 
162  for (int i = 0; i < containerCount && resourceAmount > 0.0; ++i)
163  {
164  container = m_ContainerQueue.GetContainerAt(i);
165  resourceUsed = Math.Min(container.ComputeResourceDifference(), resourceAmount);
166 
167  if (resourceUsed <= SCR_ResourceActor.RESOURCES_LOWER_LIMIT)
168  continue;
169 
170  resourceAmount -= resourceUsed;
171 
172  container.IncreaseResourceValue(resourceUsed, notifyChange);
173  }
174 
176  m_ResourceComponent.Replicate();
177  }
178 
179  //------------------------------------------------------------------------------------------------
180  void DebugDraw()
181  {
182  vector origin = GetOwnerOrigin();
183  Color color = m_ResourceComponent.GetDebugColor();
184 
185  color.Scale(0.2);
186  color.SetA(1.0);
187  //Shape.CreateSphere(m_ResourceComponent.GetDebugColor().PackToInt(), ShapeFlags.TRANSP | ShapeFlags.ONCE | ShapeFlags.DOUBLESIDE | ShapeFlags.NOZWRITE, origin, 15.0);
188  DebugTextWorldSpace.Create(GetGame().GetWorld(), string.Format(" %1 \n %2 containers \n %3 / %4 resources \n %5 m ", m_sDebugName, GetContainerCount(), GetAggregatedResourceValue(), GetAggregatedMaxResourceValue(), 15.0), DebugTextFlags.ONCE | DebugTextFlags.CENTER | DebugTextFlags.FACE_CAMERA, origin[0], origin[1] + 3, origin[2], 10.0, 0xFFFFFFFF, color.PackToInt());
189 
190  if (m_ContainerQueue)
191  m_ContainerQueue.DebugDraw();
192  }
193 
194  //------------------------------------------------------------------------------------------------
195  override void UpdateContainerResourceValue(SCR_ResourceContainer container, float previousValue)
196  {
197  OnResourcesChanged(
198  m_ContainerQueue.UpdateContainerResourceValue(container.GetResourceValue(), previousValue)
199  );
200  }
201 
202  //------------------------------------------------------------------------------------------------
203  override void UpdateContainerMaxResourceValue(SCR_ResourceContainer container, float previousValue)
204  {
205  OnMaxResourcesChanged(
206  m_ContainerQueue.UpdateContainerMaxResourceValue(container.GetMaxResourceValue(), previousValue)
207  );
208  }
209 
210  //------------------------------------------------------------------------------------------------
211  override void Initialize(notnull IEntity owner)
212  {
213  super.Initialize(owner);
214 
215  SetContainerRepresentative(m_ResourceComponent.GetContainer(m_eResourceType));
216 
217  if (m_ContainerQueue)
218  m_ContainerQueue.Initialize(this);
219  }
220 
221  //------------------------------------------------------------------------------------------------
222  override void Clear()
223  {
224  super.Clear();
225 
226  if (m_ContainerQueue)
227  m_ContainerQueue.Clear();
228  }
229 
230  //------------------------------------------------------------------------------------------------
231  override void OnResourcesChanged(float previousValue)
232  {
233  super.OnResourcesChanged(previousValue);
234 
235  if (!m_ContainerRepresentative)
236  return;
237 
238  m_ContainerRepresentative.SetResourceValueUnsafe(GetAggregatedResourceValue());
239 
240  }
241 
242  //------------------------------------------------------------------------------------------------
243  override void OnMaxResourcesChanged(float previousValue)
244  {
245  super.OnResourcesChanged(previousValue);
246 
247  if (!m_ContainerRepresentative)
248  return;
249 
250  m_ContainerRepresentative.SetMaxResourceValue(GetAggregatedMaxResourceValue());
251  }
252 
253  //------------------------------------------------------------------------------------------------
254  override void OnContainerRegistered(notnull SCR_ResourceContainer container)
255  {
256  super.OnContainerRegistered(container);
257 
258  container.SetIsEncapsulated(true);
259 
260  if (!m_ContainerRepresentative)
261  return;
262 
263  m_ContainerRepresentative.SetMaxResourceValue(GetAggregatedMaxResourceValue());
264  m_ContainerRepresentative.SetResourceValueUnsafe(GetAggregatedResourceValue());
265  }
266 
267  //------------------------------------------------------------------------------------------------
268  override void OnContainerUnregistered(notnull SCR_ResourceContainer container)
269  {
270  super.OnContainerUnregistered(container);
271 
272  container.SetIsEncapsulated(false);
273 
274  if (!m_ContainerRepresentative)
275  return;
276 
277  m_ContainerRepresentative.SetMaxResourceValue(GetAggregatedMaxResourceValue());
278  m_ContainerRepresentative.SetResourceValueUnsafe(GetAggregatedResourceValue());
279  }
280 }
281 
282 class SCR_ResourceEncapsulatorAssimilated : SCR_ResourceEncapsulator
283 {
284 
285 }
286 
287 class SCR_ResourceEncapsulatorDelegated : SCR_ResourceEncapsulator
288 {
289 
290 }
m_aActions
ref SCR_SortedArray< SCR_BaseEditorAction > m_aActions
Definition: SCR_BaseActionsEditorComponent.c:8
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_ResourceContainerQueueBase
Definition: SCR_ResourceContainerQueue.c:2
SCR_ResourceActor
Definition: SCR_ResourceConsumer.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_ResourceComponent
protected SCR_ResourceComponent m_ResourceComponent
Definition: SCR_CampaignBuildingProviderComponent.c:51
SCR_ResourceContainer
Definition: SCR_ResourceContainer.c:34
SCR_ResourceEncapsulatorContainerQueue
Definition: SCR_ResourceEncapsulatorContainerQueue.c:2
SCR_ResourceEncapsulator
Definition: SCR_ResourceEncapsulator.c:1
EResourceContainerOnEmptyBehavior
EResourceContainerOnEmptyBehavior
Definition: SCR_ResourceContainer.c:26