Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ResourceContainerQueue.c
Go to the documentation of this file.
3{
4 static const int FIRST_CONTAINER_INDEX = 0;
5 static const int INVALID_CONTAINER_INDEX = -1;
6 static const int INVALID_CONTAINER_COUNT = -1;
7
8 protected SCR_ResourceComponent m_ResourceComponent;
9 protected ref array<SCR_ResourceContainer> m_aRegisteredContainers = new array<SCR_ResourceContainer>();
12
13 //------------------------------------------------------------------------------------------------
21 {
22 #ifdef SANDBOX_RESOURCES_DEBUG
23 if (m_fAggregatedResourceValue < SCR_ResourceActor.RESOURCES_LOWER_LIMIT)
24 {
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.");
26
27 return SCR_ResourceActor.RESOURCES_LOWER_LIMIT;
28 }
29
31 #else
33 #endif
34 }
35
36 //------------------------------------------------------------------------------------------------
44 {
45 #ifdef SANDBOX_RESOURCES_DEBUG
46 if (m_fAggregatedMaxResourceValue < SCR_ResourceActor.RESOURCES_LOWER_LIMIT)
47 {
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.");
49
50 return SCR_ResourceActor.RESOURCES_LOWER_LIMIT;
51 }
52
54 #else
56 #endif
57 }
58
59 //------------------------------------------------------------------------------------------------
70 {
71 #ifdef SANDBOX_RESOURCES_DEBUG
73 {
74 Debug.Error2("SCR_ResourceContainerQueueBase::m_aRegisteredContainers is null.", "The array of registered containers has to be present.");
75
76 return null;
77 }
78
79 if (m_aRegisteredContainers.IsEmpty())
80 {
81 Debug.Error2("SCR_ResourceContainerQueueBase::m_aRegisteredContainers is empty.", "The method should not be called if the array of registered containers is empty.");
82
83 return null;
84 }
85
87
88 if (!container)
89 {
90 Debug.Error2("SCR_ResourceContainerQueueBase::GetFirstContainer found null instead of a resource container.", "There should never be null values in the registered containers array.");
91
92 return null;
93 }
94
95 return container;
96 #else
97 return m_aRegisteredContainers[SCR_ResourceContainerQueueBase.FIRST_CONTAINER_INDEX];
98 #endif
99 }
100
101 //------------------------------------------------------------------------------------------------
105 void CopyContainers(inout notnull set<SCR_ResourceContainer> containers)
106 {
108 {
109 containers.Insert(container);
110 }
111 }
112
113 //------------------------------------------------------------------------------------------------
117 void CopyContainers(inout notnull array<SCR_ResourceContainer> containers)
118 {
119 containers.Copy(m_aRegisteredContainers);
120 }
121
122 //------------------------------------------------------------------------------------------------
132 {
133 #ifdef SANDBOX_RESOURCES_DEBUG
135 {
136 Debug.Error2("SCR_ResourceContainerQueueBase::m_aRegisteredContainers is null.", "The array of registered containers has to be present.");
137
138 return null;
139 }
140
141 if (m_aRegisteredContainers.IsEmpty())
142 {
143 Debug.Error2("SCR_ResourceContainerQueueBase::m_aRegisteredContainers is empty.", "The method should not be called if the array of registered containers is empty.");
144
145 return null;
146 }
147
148 if (!m_aRegisteredContainers.IsIndexValid(index))
149 {
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.");
151
152 return null;
153 }
154
156
157 if (!container)
158 {
159 Debug.Error2("SCR_ResourceContainerQueueBase::GetContainerAt found null instead of a resource container.", "There should never be null values in the registered containers array.");
160
161 return null;
162 }
163
164 return container;
165 #else
167 #endif
168 }
169
170 //------------------------------------------------------------------------------------------------
177 {
178 #ifdef SANDBOX_RESOURCES_DEBUG
180 {
181 Debug.Error2("SCR_ResourceContainerQueueBase::m_aRegisteredContainers is null.", "The array of registered containers has to be present.");
182
183 return SCR_ResourceContainerQueueBase.INVALID_CONTAINER_COUNT;
184 }
185
186 return m_aRegisteredContainers.Count();
187 #else
188 return m_aRegisteredContainers.Count();
189 #endif
190 }
191
192 //------------------------------------------------------------------------------------------------
202 {
203 #ifdef SANDBOX_RESOURCES_DEBUG
204
206 {
207 Debug.Error2("SCR_ResourceContainerQueueBase::m_aRegisteredContainers is null.", "The array of registered containers has to be present.");
208
209 return SCR_ResourceContainerQueueBase.INVALID_CONTAINER_INDEX;
210 }
211
212 if (m_aRegisteredContainers.Contains(container))
213 {
214 Debug.Error2("SCR_ResourceContainerQueueBase::RegisterContainer tried to register an already registered resource container.", "A resource container should not be registered more than once.");
215
216 return SCR_ResourceContainerQueueBase.INVALID_CONTAINER_INDEX;
217 }
218
219 return m_aRegisteredContainers.Insert(container);
220 #else
221 return m_aRegisteredContainers.Insert(container);
222 #endif
223 }
224
225 //------------------------------------------------------------------------------------------------
234 {
235 #ifdef SANDBOX_RESOURCES_DEBUG
237 {
238 Debug.Error2("SCR_ResourceContainerQueueBase::m_aRegisteredContainers is null.", "The array of registered containers has to be present.");
239
240 return SCR_ResourceContainerQueueBase.INVALID_CONTAINER_INDEX;
241 }
242
243 return m_aRegisteredContainers.Find(container);
244 #else
245 return m_aRegisteredContainers.Find(container);
246 #endif
247 }
248
249 //------------------------------------------------------------------------------------------------
257 {
258 #ifdef SANDBOX_RESOURCES_DEBUG
260 {
261 Debug.Error2("SCR_ResourceContainerQueueBase::m_aRegisteredContainers is null.", "The array of registered containers has to be present.");
262
263 return null;
264 }
265
266 if (m_aRegisteredContainers.IsEmpty())
267 {
268 Debug.Error2("SCR_ResourceContainerQueueBase::m_aRegisteredContainers is empty.", "The method should not be called if the array of registered containers is empty.");
269
270 return null;
271 }
272
274
275 m_aRegisteredContainers.RemoveOrdered(SCR_ResourceContainerQueueBase.FIRST_CONTAINER_INDEX);
276
277 return container;
278 #else
280
281 m_aRegisteredContainers.RemoveOrdered(SCR_ResourceContainerQueueBase.FIRST_CONTAINER_INDEX);
282
283 return container;
284 #endif
285 }
286
287 //------------------------------------------------------------------------------------------------
297 {
298 #ifdef SANDBOX_RESOURCES_DEBUG
300 {
301 Debug.Error2("SCR_ResourceContainerQueueBase::m_aRegisteredContainers is null.", "The array of registered containers has to be present.");
302
303 return null;
304 }
305
306 if (m_aRegisteredContainers.IsEmpty())
307 {
308 Debug.Error2("SCR_ResourceContainerQueueBase::m_aRegisteredContainers is empty.", "The method should not be called if the array of registered containers is empty.");
309
310 return null;
311 }
312
313 if (!m_aRegisteredContainers.IsIndexValid(index))
314 {
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.");
316
317 return null;
318 }
319
321
322 if (!container)
323 {
324 Debug.Error2("SCR_ResourceContainerQueueBase::PopContainerAt found null instead of a resource container.", "There should never be null values in the registered containers array.");
325
326 return null;
327 }
328
329 m_aRegisteredContainers.RemoveOrdered(index);
330
331 return container;
332 #else
333 if (!m_aRegisteredContainers.IsIndexValid(index))
334 return null;
335
337
338 m_aRegisteredContainers.RemoveOrdered(index);
339
340 return container;
341 #endif
342 }
343
344 //------------------------------------------------------------------------------------------------
353 {
354 #ifdef SANDBOX_RESOURCES_DEBUG
355 if (value < SCR_ResourceActor.RESOURCES_LOWER_LIMIT)
356 {
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.");
358
359 return;
360 }
361
363 {
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.");
365
366 return;
367 }
368
370 #else
372 #endif
373 }
374
375 //------------------------------------------------------------------------------------------------
385 {
386 #ifdef SANDBOX_RESOURCES_DEBUG
387 if (value < SCR_ResourceActor.RESOURCES_LOWER_LIMIT)
388 {
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.");
390
391 return;
392 }
393
394 if (value < m_fAggregatedResourceValue)
395 {
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.");
397
398 return;
399 }
400
402 #else
404 #endif
405 }
406
407 //------------------------------------------------------------------------------------------------
417 {
418 #ifdef SANDBOX_RESOURCES_DEBUG
419 if (increment < 0)
420 {
421 Debug.Error2("SCR_ResourceContainerQueueBase::IncreaseAggregatedResourceValue The increment is lower than 0.0.", "The increment has to be a positive number.");
422
423 return;
424 }
425
427 #else
428 m_fAggregatedResourceValue += increment;
429 #endif
430 }
431
432 //------------------------------------------------------------------------------------------------
442 {
443 #ifdef SANDBOX_RESOURCES_DEBUG
444 if (decrement < 0)
445 {
446 Debug.Error2("SCR_ResourceContainerQueueBase::DecreaseAggregatedResourceValue The decrement is lower than 0.0.", "The decrement has to be a positive number.");
447
448 return;
449 }
450
452 #else
453 m_fAggregatedResourceValue -= decrement;
454 #endif
455
456 }
457
458 //------------------------------------------------------------------------------------------------
468 {
469 #ifdef SANDBOX_RESOURCES_DEBUG
470 if (increment < 0)
471 {
472 Debug.Error2("SCR_ResourceContainerQueueBase::IncreaseAggregatedMaxResourceValue The increment is lower than 0.0.", "The increment has to be a positive number.");
473
474 return;
475 }
476
478 #else
480 #endif
481 }
482
483 //------------------------------------------------------------------------------------------------
493 {
494 #ifdef SANDBOX_RESOURCES_DEBUG
495 if (decrement < 0)
496 {
497 Debug.Error2("SCR_ResourceContainerQueueBase::DecreaseAggregatedMaxResourceValue The decrement is lower than 0.0.", "The decrement has to be a positive number.");
498
499 return;
500 }
501
503 #else
505 #endif
506 }
507
508 //------------------------------------------------------------------------------------------------
512 array<SCR_ResourceContainer> Clear()
513 {
514 #ifdef SANDBOX_RESOURCES_DEBUG
515 array<SCR_ResourceContainer> clearedContainers = {};
516
518 {
519 Debug.Error2("SCR_ResourceContainerQueueBase::m_aRegisteredContainers is null.", "The array of registered containers has to be present.");
520
521 return clearedContainers;
522 }
523
524 for (int index = m_aRegisteredContainers.Count() - 1; index >= 0; --index)
525 {
527 {
528 Debug.Error2("SCR_ResourceContainerQueueBase::Clear found null instead of a resource container.", "There should never be null values in the registered containers array.");
529
530 return clearedContainers;
531 }
532
534 clearedContainers.Insert(PopContainerAt(index));
535 }
536
538 SetAggregatedResourceValue(SCR_ResourceActor.RESOURCES_LOWER_LIMIT);
540
541 return clearedContainers;
542 #else
543 array<SCR_ResourceContainer> clearedContainers = {};
544
545 for (int index = m_aRegisteredContainers.Count() - 1; index >= 0; --index)
546 {
548 clearedContainers.Insert(PopContainerAt(index));
549 }
550
552
553 m_fAggregatedResourceValue = SCR_ResourceActor.RESOURCES_LOWER_LIMIT;
554 m_fAggregatedMaxResourceValue = SCR_ResourceActor.RESOURCES_LOWER_LIMIT;
555
556 return clearedContainers;
557 #endif
558 }
559
560 //------------------------------------------------------------------------------------------------
562
563 //------------------------------------------------------------------------------------------------
564 void Initialize(notnull SCR_ResourceInteractor interactor)
565 {
566
567 }
568
569 //------------------------------------------------------------------------------------------------
571 {
572
573 }
574
575 //------------------------------------------------------------------------------------------------
576 float UpdateContainerResourceValue(float currentValue, float previousValue)
577 {
578
579 }
580
581 //------------------------------------------------------------------------------------------------
582 float UpdateContainerMaxResourceValue(float currentValue, float previousValue)
583 {
584
585 }
586
587 //------------------------------------------------------------------------------------------------
590 {
591
592 }
593
594 //------------------------------------------------------------------------------------------------
597 {
598 Clear();
599 }
600}
601
603class SCR_ResourceContainerQueue : SCR_ResourceContainerQueueBase
604{
606 protected SCR_ResourceInteractor m_Interactor;
607
608 [Attribute(uiwidget: UIWidgets.Object)]
609 protected ref array<ref SCR_ResourceStoragePolicyBase> m_StoragePolicies;
610
611 //------------------------------------------------------------------------------------------------
613 protected int GetStoragePolicyCount()
614 {
615 return m_StoragePolicies.Count();
616 }
617
618 //------------------------------------------------------------------------------------------------
621 int GetStorageTypeCount(EResourceContainerStorageType storageType)
622 {
623 foreach (SCR_ResourceStoragePolicyBase policy : m_StoragePolicies)
624 {
625 if (policy.IsStorageTypeValid(storageType))
626 return policy.GetStorageQueue().GetContainerCount();
627 }
628
629 return 0;
630 }
631
632 //------------------------------------------------------------------------------------------------
636 override int RegisterContainer(notnull SCR_ResourceContainer container)
637 {
638 int position = SCR_ResourceContainerQueueBase.INVALID_CONTAINER_INDEX;
639 float resourceValue;
640 bool shouldIncrementOffset;
641 SCR_ResourceContainerStorageQueue storageQueue;
642
643 EResourceContainerStorageType storageType = container.GetStorageType();
644
645 foreach (SCR_ResourceStoragePolicyBase policy: m_StoragePolicies)
646 {
647 storageQueue = policy.GetStorageQueue();
648
649 if (shouldIncrementOffset)
650 {
651 storageQueue.IncrementOffset(1);
652 continue;
653 }
654
655 resourceValue = container.GetResourceValue();
656
657 if (!policy.IsStorageTypeValid(storageType))
658 continue;
659
660 m_fAggregatedResourceValue += resourceValue;
661 m_fAggregatedMaxResourceValue += container.GetMaxResourceValue();
662
663 shouldIncrementOffset = true;
664 position = storageQueue.RegisterContainer(container, m_Interactor);
665 }
666
667 return position;
668 }
669
670 //------------------------------------------------------------------------------------------------
671 override SCR_ResourceContainer PopFirstContainer()
672 {
673 bool shouldDecrementOffset;
674 SCR_ResourceContainerStorageQueue storageQueue;
675 SCR_ResourceContainer container;
676
677 foreach (SCR_ResourceStoragePolicyBase policy: m_StoragePolicies)
678 {
679 storageQueue = policy.GetStorageQueue();
680
681 if (storageQueue.IsEmpty())
682 continue;
683
684 if (shouldDecrementOffset)
685 {
686 storageQueue.DecrementOffset(1);
687 continue;
688 }
689
690 container = m_aRegisteredContainers[0];
691 shouldDecrementOffset = true;
692
693 if (container)
694 {
695 m_fAggregatedResourceValue -= container.GetResourceValue();
696 m_fAggregatedMaxResourceValue -= container.GetMaxResourceValue();
697
698 m_Interactor.OnContainerUnregistered(container);
699 }
700
701 storageQueue.UnregisterFirstContainer();
702 }
703
704 return container;
705 }
706
707 //------------------------------------------------------------------------------------------------
708 override SCR_ResourceContainer PopContainerAt(int index)
709 {
710 if (!m_aRegisteredContainers.IsIndexValid(index))
711 return null;
712
713 int offsetPosition;
714 bool shouldDecrementOffset;
715 SCR_ResourceContainerStorageQueue storageQueue;
716 SCR_ResourceContainer container;
717
718 foreach (SCR_ResourceStoragePolicyBase policy: m_StoragePolicies)
719 {
720 storageQueue = policy.GetStorageQueue();
721
722 if (storageQueue.IsEmpty())
723 continue;
724
725 if (shouldDecrementOffset)
726 {
727 storageQueue.DecrementOffset(1);
728 continue;
729 }
730
731 offsetPosition = storageQueue.GetOffsetPosition();
732
733 if (index < offsetPosition || index > offsetPosition + storageQueue.GetContainerCount())
734 continue;
735
736 container = m_aRegisteredContainers[index];
737 shouldDecrementOffset = true;
738
739 storageQueue.UnregisterContainerAt(index - offsetPosition);
740
741 if (container)
742 {
743 m_fAggregatedResourceValue -= container.GetResourceValue();
744 m_fAggregatedMaxResourceValue -= container.GetMaxResourceValue();
745
746 m_Interactor.OnContainerUnregistered(container);
747 }
748 }
749
750 return container;
751 }
752
753 override void PerformSorting()
754 {
755 array<SCR_ResourceContainer> registeredContainers = Clear();
756
757 foreach (SCR_ResourceContainer container: registeredContainers)
758 {
759 if (!container)
760 continue;
761
762 m_Interactor.RegisterContainer(container);
763 }
764 }
765
766 //------------------------------------------------------------------------------------------------
768 override array<SCR_ResourceContainer> Clear()
769 {
770 array<SCR_ResourceContainer> clearedContainers = {};
771 clearedContainers.Copy(m_aRegisteredContainers);
772
773 for (int index = m_aRegisteredContainers.Count() - 1; index >= 0; --index)
774 {
775 m_Interactor.UnregisterContainer(index);
776 }
777
778 m_aRegisteredContainers.Clear();
779
780 m_fAggregatedResourceValue = SCR_ResourceActor.RESOURCES_LOWER_LIMIT;
781 m_fAggregatedMaxResourceValue = SCR_ResourceActor.RESOURCES_LOWER_LIMIT;
782
783 foreach (SCR_ResourceStoragePolicyBase policy: m_StoragePolicies)
784 {
785 policy.ResetStorageQueue();
786 }
787
788 return clearedContainers;
789 }
790
791 //------------------------------------------------------------------------------------------------
792 override void Initialize(notnull SCR_ResourceInteractor interactor)
793 {
794 SCR_ResourceContainerStorageQueue storageQueue;
795 m_Interactor = interactor;
796
797 foreach (int idx, SCR_ResourceStoragePolicyBase policy: m_StoragePolicies)
798 {
799 storageQueue = policy.GetStorageQueue();
800
801 if (!storageQueue)
802 {
803 // TODO: Do proper default behavior or just block progress perhaps?.
804 storageQueue = new SCR_ResourceContainerStorageQueue();
805
806 policy.SetStorageQueue(storageQueue);
807
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);
809 }
810
811 storageQueue.Initialize(m_aRegisteredContainers);
812 }
813 }
814
815 //------------------------------------------------------------------------------------------------
816 override float UpdateContainerResourceValue(float currentValue, float previousValue)
817 {
818 float previousAggregatedValue = m_fAggregatedResourceValue;
819 m_fAggregatedResourceValue += currentValue - previousValue;
820
821 return previousAggregatedValue;
822 }
823
824 //------------------------------------------------------------------------------------------------
825 override float UpdateContainerMaxResourceValue(float currentValue, float previousValue)
826 {
827 float previousAggregatedMaxValue = m_fAggregatedMaxResourceValue;
828 m_fAggregatedMaxResourceValue += currentValue - previousValue;
829
830 return previousAggregatedMaxValue;
831 }
832};
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
vector position
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
EResourceContainerStorageType
int Type
Definition Debug.c:13
float UpdateContainerMaxResourceValue(float currentValue, float previousValue)
SCR_ResourceContainer GetContainerAt(int index)
void DecreaseAggregatedResourceValue(float decrement)
void CopyContainers(inout notnull array< SCR_ResourceContainer > containers)
array< SCR_ResourceContainer > Clear()
void Initialize(notnull SCR_ResourceInteractor interactor)
SCR_ResourceContainer PopContainerAt(int index)
void DecreaseAggregatedMaxResourceValue(float decrement)
void IncreaseAggregatedMaxResourceValue(float increment)
int RegisterContainer(notnull SCR_ResourceContainer container)
void CopyContainers(inout notnull set< SCR_ResourceContainer > containers)
int FindContainer(notnull SCR_ResourceContainer container)
ref array< SCR_ResourceContainer > m_aRegisteredContainers
void IncreaseAggregatedResourceValue(float increment)
float UpdateContainerResourceValue(float currentValue, float previousValue)
void Initialize(array< SCR_ResourceContainer > containers)
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.
Definition LogLevel.c:14
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.