4 static const int FIRST_CONTAINER_INDEX = 0;
5 static const int INVALID_CONTAINER_INDEX = -1;
6 static const int INVALID_CONTAINER_COUNT = -1;
22 #ifdef SANDBOX_RESOURCES_DEBUG
25 Debug.Error2(
"SCR_ResourceContainerQueueBase::m_fAggregatedResourceValue is lower than SCR_ResourceActor.RESOURCES_LOWER_LIMIT.",
"The current aggregated resources can not be lower than SCR_ResourceActor.RESOURCES_LOWER_LIMIT.");
45 #ifdef SANDBOX_RESOURCES_DEBUG
48 Debug.Error2(
"SCR_ResourceContainerQueueBase::m_fAggregatedMaxResourceValue is lower than SCR_ResourceActor.RESOURCES_LOWER_LIMIT.",
"The current maximum aggregated resources can not be lower than SCR_ResourceActor.RESOURCES_LOWER_LIMIT.");
71 #ifdef SANDBOX_RESOURCES_DEBUG
74 Debug.Error2(
"SCR_ResourceContainerQueueBase::m_aRegisteredContainers is null.",
"The array of registered containers has to be present.");
81 Debug.Error2(
"SCR_ResourceContainerQueueBase::m_aRegisteredContainers is empty.",
"The method should not be called if the array of registered containers is empty.");
90 Debug.Error2(
"SCR_ResourceContainerQueueBase::GetFirstContainer found null instead of a resource container.",
"There should never be null values in the registered containers array.");
109 containers.Insert(container);
133 #ifdef SANDBOX_RESOURCES_DEBUG
136 Debug.Error2(
"SCR_ResourceContainerQueueBase::m_aRegisteredContainers is null.",
"The array of registered containers has to be present.");
143 Debug.Error2(
"SCR_ResourceContainerQueueBase::m_aRegisteredContainers is empty.",
"The method should not be called if the array of registered containers is empty.");
150 Debug.Error2(
"SCR_ResourceContainerQueueBase::m_aRegisteredContainers has no element at the provided index.",
"The method should not be called if the array of registered containers does not contain an element at the provided index.");
159 Debug.Error2(
"SCR_ResourceContainerQueueBase::GetContainerAt found null instead of a resource container.",
"There should never be null values in the registered containers array.");
178 #ifdef SANDBOX_RESOURCES_DEBUG
181 Debug.Error2(
"SCR_ResourceContainerQueueBase::m_aRegisteredContainers is null.",
"The array of registered containers has to be present.");
203 #ifdef SANDBOX_RESOURCES_DEBUG
207 Debug.Error2(
"SCR_ResourceContainerQueueBase::m_aRegisteredContainers is null.",
"The array of registered containers has to be present.");
214 Debug.Error2(
"SCR_ResourceContainerQueueBase::RegisterContainer tried to register an already registered resource container.",
"A resource container should not be registered more than once.");
235 #ifdef SANDBOX_RESOURCES_DEBUG
238 Debug.Error2(
"SCR_ResourceContainerQueueBase::m_aRegisteredContainers is null.",
"The array of registered containers has to be present.");
258 #ifdef SANDBOX_RESOURCES_DEBUG
261 Debug.Error2(
"SCR_ResourceContainerQueueBase::m_aRegisteredContainers is null.",
"The array of registered containers has to be present.");
268 Debug.Error2(
"SCR_ResourceContainerQueueBase::m_aRegisteredContainers is empty.",
"The method should not be called if the array of registered containers is empty.");
298 #ifdef SANDBOX_RESOURCES_DEBUG
301 Debug.Error2(
"SCR_ResourceContainerQueueBase::m_aRegisteredContainers is null.",
"The array of registered containers has to be present.");
308 Debug.Error2(
"SCR_ResourceContainerQueueBase::m_aRegisteredContainers is empty.",
"The method should not be called if the array of registered containers is empty.");
315 Debug.Error2(
"SCR_ResourceContainerQueueBase::m_aRegisteredContainers has no element at the provided index.",
"The method should not be called if the array of registered containers does not contain an element at the provided index.");
324 Debug.Error2(
"SCR_ResourceContainerQueueBase::PopContainerAt found null instead of a resource container.",
"There should never be null values in the registered containers array.");
354 #ifdef SANDBOX_RESOURCES_DEBUG
357 Debug.Error2(
"SCR_ResourceContainerQueueBase::SetAggregatedResourceValue The value is lower than SCR_ResourceActor.RESOURCES_LOWER_LIMIT.",
"The current aggregated resources can not be lower than SCR_ResourceActor.RESOURCES_LOWER_LIMIT.");
364 Debug.Error2(
"SCR_ResourceContainerQueueBase::SetAggregatedResourceValue The value is greater than the current maximum aggregated resources value.",
"The current aggregated resources can not be greater than than the current maximum aggregated resources value.");
386 #ifdef SANDBOX_RESOURCES_DEBUG
389 Debug.Error2(
"SCR_ResourceContainerQueueBase::SetAggregatedMaxResourceValue The value is lower than SCR_ResourceActor.RESOURCES_LOWER_LIMIT.",
"The current maximum aggregated resources can not be lower than SCR_ResourceActor.RESOURCES_LOWER_LIMIT.");
396 Debug.Error2(
"SCR_ResourceContainerQueueBase::SetAggregatedMaxResourceValue The value is lower than the current aggregated resources value.",
"The current maximum aggregated resources can not be lower than than the current aggregated resources value.");
418 #ifdef SANDBOX_RESOURCES_DEBUG
421 Debug.Error2(
"SCR_ResourceContainerQueueBase::IncreaseAggregatedResourceValue The increment is lower than 0.0.",
"The increment has to be a positive number.");
443 #ifdef SANDBOX_RESOURCES_DEBUG
446 Debug.Error2(
"SCR_ResourceContainerQueueBase::DecreaseAggregatedResourceValue The decrement is lower than 0.0.",
"The decrement has to be a positive number.");
469 #ifdef SANDBOX_RESOURCES_DEBUG
472 Debug.Error2(
"SCR_ResourceContainerQueueBase::IncreaseAggregatedMaxResourceValue The increment is lower than 0.0.",
"The increment has to be a positive number.");
494 #ifdef SANDBOX_RESOURCES_DEBUG
497 Debug.Error2(
"SCR_ResourceContainerQueueBase::DecreaseAggregatedMaxResourceValue The decrement is lower than 0.0.",
"The decrement has to be a positive number.");
512 array<SCR_ResourceContainer>
Clear()
514 #ifdef SANDBOX_RESOURCES_DEBUG
515 array<SCR_ResourceContainer> clearedContainers = {};
519 Debug.Error2(
"SCR_ResourceContainerQueueBase::m_aRegisteredContainers is null.",
"The array of registered containers has to be present.");
521 return clearedContainers;
528 Debug.Error2(
"SCR_ResourceContainerQueueBase::Clear found null instead of a resource container.",
"There should never be null values in the registered containers array.");
530 return clearedContainers;
541 return clearedContainers;
543 array<SCR_ResourceContainer> clearedContainers = {};
556 return clearedContainers;
606 protected SCR_ResourceInteractor m_Interactor;
609 protected ref array<ref SCR_ResourceStoragePolicyBase> m_StoragePolicies;
613 protected int GetStoragePolicyCount()
615 return m_StoragePolicies.Count();
623 foreach (SCR_ResourceStoragePolicyBase policy : m_StoragePolicies)
625 if (policy.IsStorageTypeValid(storageType))
626 return policy.GetStorageQueue().GetContainerCount();
636 override int RegisterContainer(notnull SCR_ResourceContainer container)
638 int position = SCR_ResourceContainerQueueBase.INVALID_CONTAINER_INDEX;
640 bool shouldIncrementOffset;
641 SCR_ResourceContainerStorageQueue storageQueue;
645 foreach (SCR_ResourceStoragePolicyBase policy: m_StoragePolicies)
647 storageQueue = policy.GetStorageQueue();
649 if (shouldIncrementOffset)
655 resourceValue = container.GetResourceValue();
657 if (!policy.IsStorageTypeValid(storageType))
660 m_fAggregatedResourceValue += resourceValue;
661 m_fAggregatedMaxResourceValue += container.GetMaxResourceValue();
663 shouldIncrementOffset =
true;
671 override SCR_ResourceContainer PopFirstContainer()
673 bool shouldDecrementOffset;
674 SCR_ResourceContainerStorageQueue storageQueue;
675 SCR_ResourceContainer container;
677 foreach (SCR_ResourceStoragePolicyBase policy: m_StoragePolicies)
679 storageQueue = policy.GetStorageQueue();
684 if (shouldDecrementOffset)
690 container = m_aRegisteredContainers[0];
691 shouldDecrementOffset =
true;
698 m_Interactor.OnContainerUnregistered(container);
708 override SCR_ResourceContainer PopContainerAt(
int index)
710 if (!m_aRegisteredContainers.IsIndexValid(
index))
714 bool shouldDecrementOffset;
715 SCR_ResourceContainerStorageQueue storageQueue;
716 SCR_ResourceContainer container;
718 foreach (SCR_ResourceStoragePolicyBase policy: m_StoragePolicies)
720 storageQueue = policy.GetStorageQueue();
725 if (shouldDecrementOffset)
731 offsetPosition = storageQueue.GetOffsetPosition();
736 container = m_aRegisteredContainers[
index];
737 shouldDecrementOffset =
true;
746 m_Interactor.OnContainerUnregistered(container);
753 override void PerformSorting()
755 array<SCR_ResourceContainer> registeredContainers =
Clear();
757 foreach (SCR_ResourceContainer container: registeredContainers)
762 m_Interactor.RegisterContainer(container);
768 override array<SCR_ResourceContainer>
Clear()
770 array<SCR_ResourceContainer> clearedContainers = {};
771 clearedContainers.Copy(m_aRegisteredContainers);
773 for (
int index = m_aRegisteredContainers.Count() - 1;
index >= 0; --
index)
775 m_Interactor.UnregisterContainer(
index);
778 m_aRegisteredContainers.Clear();
780 m_fAggregatedResourceValue = SCR_ResourceActor.RESOURCES_LOWER_LIMIT;
781 m_fAggregatedMaxResourceValue = SCR_ResourceActor.RESOURCES_LOWER_LIMIT;
783 foreach (SCR_ResourceStoragePolicyBase policy: m_StoragePolicies)
785 policy.ResetStorageQueue();
788 return clearedContainers;
792 override void Initialize(notnull SCR_ResourceInteractor interactor)
794 SCR_ResourceContainerStorageQueue storageQueue;
795 m_Interactor = interactor;
797 foreach (
int idx, SCR_ResourceStoragePolicyBase policy: m_StoragePolicies)
799 storageQueue = policy.GetStorageQueue();
804 storageQueue =
new SCR_ResourceContainerStorageQueue();
806 policy.SetStorageQueue(storageQueue);
808 Print(
string.Format(
"%1:\n\tPolicy at index %2 does not have a defined storage queue.\n\tUsing default storage queue instead.",
Type().
ToString(),
idx),
LogLevel.WARNING);
811 storageQueue.
Initialize(m_aRegisteredContainers);
816 override float UpdateContainerResourceValue(
float currentValue,
float previousValue)
818 float previousAggregatedValue = m_fAggregatedResourceValue;
819 m_fAggregatedResourceValue += currentValue - previousValue;
821 return previousAggregatedValue;
825 override float UpdateContainerMaxResourceValue(
float currentValue,
float previousValue)
827 float previousAggregatedMaxValue = m_fAggregatedMaxResourceValue;
828 m_fAggregatedMaxResourceValue += currentValue - previousValue;
830 return previousAggregatedMaxValue;
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
EResourceContainerStorageType
float GetMaxResourceValue()
float UpdateContainerMaxResourceValue(float currentValue, float previousValue)
SCR_ResourceContainer GetContainerAt(int index)
SCR_ResourceComponent m_ResourceComponent
void ~SCR_ResourceContainerQueueBase()
Destructor.
float m_fAggregatedResourceValue
void DecreaseAggregatedResourceValue(float decrement)
SCR_ResourceContainer PopFirstContainer()
void SCR_ResourceContainerQueueBase()
Constructor.
void CopyContainers(inout notnull array< SCR_ResourceContainer > containers)
array< SCR_ResourceContainer > Clear()
void SetAggregatedMaxResourceValue(float value)
void Initialize(notnull SCR_ResourceInteractor interactor)
SCR_ResourceContainer PopContainerAt(int index)
void DecreaseAggregatedMaxResourceValue(float decrement)
void IncreaseAggregatedMaxResourceValue(float increment)
float GetAggregatedResourceValue()
int RegisterContainer(notnull SCR_ResourceContainer container)
void CopyContainers(inout notnull set< SCR_ResourceContainer > containers)
int FindContainer(notnull SCR_ResourceContainer container)
SCR_ResourceContainer GetFirstContainer()
void SetAggregatedResourceValue(float value)
float m_fAggregatedMaxResourceValue
ref array< SCR_ResourceContainer > m_aRegisteredContainers
void IncreaseAggregatedResourceValue(float increment)
float GetAggregatedMaxResourceValue()
float UpdateContainerResourceValue(float currentValue, float previousValue)
void IncrementOffset(int increment)
void Initialize(array< SCR_ResourceContainer > containers)
void DecrementOffset(int decrement)
void UnregisterFirstContainer()
Unegisters the first container in the queue.
int RegisterContainer(notnull SCR_ResourceContainer container, notnull SCR_ResourceInteractor actor)
void UnregisterContainerAt(int position)
Unegisters the container at a specific position in the queue.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
SCR_FieldOfViewSettings Attribute
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.
proto native void Clear()
Remove all calls from list.