15 protected float m_fAvailableResourceSpace;
16 protected float m_fResourceMultiplier;
17 protected float m_fRange;
23 m_fAvailableResourceSpace = availableResourceSpace;
30 float GetAvailableResourceSpace()
32 return m_fAvailableResourceSpace;
36 float GetResourceMultiplier()
54 void SetAvailableResourceSpace(
float availableResourceSpace)
56 m_fAvailableResourceSpace = availableResourceSpace;
60 void SetResourceMultiplier(
float resourceMultiplier)
66 void SetRange(
float range)
84 [
Attribute(defvalue:
"1.0", uiwidget: UIWidgets.SpinBox,
params:
string.Format(
"0.0 %1 1.0",
float.MAX))]
85 protected float m_fResourceMultiplier;
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;
91 protected bool m_bIsIgnoringItself;
97 protected ref array<ref SCR_ResourceGeneratorActionBase> m_aActions;
100 override float GetResourceGridRange()
102 return m_fStorageRange;
106 float GetStorageRange()
108 return m_fStorageRange;
112 float GetResourceMultiplier()
120 return m_eIdentifier;
124 override float GetAggregatedResourceValue()
126 if (!m_ContainerQueue)
127 return m_fAggregatedResourceValue;
129 return m_ContainerQueue.GetAggregatedResourceValue();
133 override float GetAggregatedMaxResourceValue()
135 if (!m_ContainerQueue)
136 return m_fAggregatedMaxResourceValue;
138 return m_ContainerQueue.GetAggregatedMaxResourceValue();
142 override int GetContainerCount()
144 if (!m_ContainerQueue)
147 return m_ContainerQueue.GetContainerCount();
153 return m_ContainerQueue;
157 bool IsIgnoringItself()
159 return m_bIsIgnoringItself;
165 return (!m_bIsIgnoringItself || container.GetOwner() !=
m_Owner) && super.CanInteractWith(container);
171 if (!m_ContainerQueue)
172 return super.FindContainer(container);
174 return m_ContainerQueue.FindContainer(container);
180 if (CanInteractWith(container)
184 OnContainerRegistered(container);
197 OnContainerRegistered(container);
206 override bool UnregisterContainer(
int containerIndex)
208 return m_ContainerQueue && m_ContainerQueue.PopContainerAt(containerIndex);
214 return m_ContainerQueue && m_ContainerQueue.PopContainerAt(m_ContainerQueue.FindContainer(container));
220 GetGame().GetResourceGrid().UpdateInteractor(
this);
224 if (resourceAmount > response.GetAvailableResourceSpace())
231 if (response.GetAvailableResourceSpace() == 0)
246 m_ContainerQueue.PerformSorting();
248 int containerCount = m_ContainerQueue.GetContainerCount();
252 if (resourceAmount <= 0)
255 for (
int i = 0; i < containerCount; i++)
257 action.PerformAction(m_ContainerQueue.GetContainerAt(i), resourceAmount);
259 if (m_ContainerQueue.GetContainerCount() != containerCount)
279 vector origin = GetOwnerOrigin();
285 color2.Lerp(Color.FromInt(Color.WHITE), 0.5);
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());
290 if (m_ContainerQueue)
291 m_ContainerQueue.DebugDraw();
298 m_ContainerQueue.UpdateContainerResourceValue(container.GetResourceValue(), previousValue)
305 OnMaxResourcesChanged(
306 m_ContainerQueue.UpdateContainerMaxResourceValue(container.GetMaxResourceValue(), previousValue)
311 override void Initialize(notnull IEntity owner)
313 super.Initialize(owner);
317 if (container && container.IsEncapsulated())
320 if (m_ContainerQueue)
321 m_ContainerQueue.Initialize(
this);
324 RegisterContainer(container);
328 override void Clear()
332 if (m_ContainerQueue)
333 m_ContainerQueue.Clear();
335 GetGame().GetResourceSystemSubscriptionManager().OnResourceInteractorDeleted(
this);
339 protected bool PropCompareNetworkedVariables(SSnapSerializerBase snapshot, ScriptCtx hint)
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);
353 protected bool ExtractNetworkedVariables(SSnapSerializerBase snapshot, ScriptCtx hint)
355 float aggregatedResourceValue = GetAggregatedResourceValue();
356 float aggregatedMaxResourceValue = GetAggregatedMaxResourceValue();
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);
372 protected bool InjectNetworkedVariables(SSnapSerializerBase snapshot, ScriptCtx hint)
374 RplId componentRplId;
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);
395 static void Encode(SSnapSerializerBase snapshot, ScriptCtx ctx, ScriptBitSerializer packet)
401 static bool Decode(ScriptBitSerializer packet, ScriptCtx ctx, SSnapSerializerBase snapshot)
407 static bool SnapCompare(SSnapSerializerBase lhs, SSnapSerializerBase rhs , ScriptCtx ctx)
415 return instance.PropCompareNetworkedVariables(snapshot, ctx);
421 return instance.ExtractNetworkedVariables(snapshot, ctx);
427 return instance.InjectNetworkedVariables(snapshot, ctx);