9 protected ref array<ref SCR_ResourceEncapsulatorActionBase> m_aActions;
12 override float GetAggregatedResourceValue()
14 if (!m_ContainerQueue)
15 return m_fAggregatedResourceValue;
17 return m_ContainerQueue.GetAggregatedResourceValue();
21 override float GetAggregatedMaxResourceValue()
23 if (!m_ContainerQueue)
24 return m_fAggregatedMaxResourceValue;
26 return m_ContainerQueue.GetAggregatedMaxResourceValue();
30 override int GetContainerCount()
32 if (!m_ContainerQueue)
35 return m_ContainerQueue.GetContainerCount();
41 return m_ContainerQueue;
47 return m_ContainerRepresentative;
51 array<ref SCR_ResourceEncapsulatorActionBase> GetActions()
59 return container.GetResourceType() == m_eResourceType;
65 return container == m_ContainerRepresentative;
69 override bool ShouldUpdate()
77 if (!m_ContainerQueue)
78 return super.FindContainer(container);
80 return m_ContainerQueue.FindContainer(container);
86 m_ContainerRepresentative = container;
88 if (m_ContainerRepresentative)
89 m_ContainerRepresentative.SetResourceEncapsulator(
this);
95 if (CanInteractWith(container)
99 OnContainerRegistered(container);
112 OnContainerRegistered(container);
121 override bool UnregisterContainer(
int containerIndex)
123 return m_ContainerQueue && m_ContainerQueue.PopContainerAt(containerIndex);
129 return m_ContainerQueue && m_ContainerQueue.PopContainerAt(m_ContainerQueue.FindContainer(container));
133 void RequestConsumtion(
float resourceCost,
bool notifyChange =
true)
138 for (
int i = m_ContainerQueue.GetContainerCount() - 1; i >= 0 && resourceCost > 0.0; --i)
140 container = m_ContainerQueue.GetContainerAt(i);
141 resourceUsed = Math.Min(resourceCost, container.GetResourceValue());
146 resourceCost -= resourceUsed;
148 container.DecreaseResourceValue(resourceUsed, notifyChange);
156 void RequestGeneration(
float resourceAmount,
bool notifyChange =
true)
160 int containerCount = m_ContainerQueue.GetContainerCount();
162 for (
int i = 0; i < containerCount && resourceAmount > 0.0; ++i)
164 container = m_ContainerQueue.GetContainerAt(i);
165 resourceUsed = Math.Min(container.ComputeResourceDifference(), resourceAmount);
170 resourceAmount -= resourceUsed;
172 container.IncreaseResourceValue(resourceUsed, notifyChange);
182 vector origin = GetOwnerOrigin();
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());
190 if (m_ContainerQueue)
191 m_ContainerQueue.DebugDraw();
198 m_ContainerQueue.UpdateContainerResourceValue(container.GetResourceValue(), previousValue)
205 OnMaxResourcesChanged(
206 m_ContainerQueue.UpdateContainerMaxResourceValue(container.GetMaxResourceValue(), previousValue)
211 override void Initialize(notnull IEntity owner)
213 super.Initialize(owner);
217 if (m_ContainerQueue)
218 m_ContainerQueue.Initialize(
this);
222 override void Clear()
226 if (m_ContainerQueue)
227 m_ContainerQueue.Clear();
231 override void OnResourcesChanged(
float previousValue)
233 super.OnResourcesChanged(previousValue);
235 if (!m_ContainerRepresentative)
238 m_ContainerRepresentative.SetResourceValueUnsafe(GetAggregatedResourceValue());
243 override void OnMaxResourcesChanged(
float previousValue)
245 super.OnResourcesChanged(previousValue);
247 if (!m_ContainerRepresentative)
250 m_ContainerRepresentative.SetMaxResourceValue(GetAggregatedMaxResourceValue());
256 super.OnContainerRegistered(container);
258 container.SetIsEncapsulated(
true);
260 if (!m_ContainerRepresentative)
263 m_ContainerRepresentative.SetMaxResourceValue(GetAggregatedMaxResourceValue());
264 m_ContainerRepresentative.SetResourceValueUnsafe(GetAggregatedResourceValue());
270 super.OnContainerUnregistered(container);
272 container.SetIsEncapsulated(
false);
274 if (!m_ContainerRepresentative)
277 m_ContainerRepresentative.SetMaxResourceValue(GetAggregatedMaxResourceValue());
278 m_ContainerRepresentative.SetResourceValueUnsafe(GetAggregatedResourceValue());