Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ResourceContainer.c
Go to the documentation of this file.
7
16
25
32
35{
36 // This is for the debugging visualization of containers
37 protected ref set<SCR_ResourceInteractor> m_aInteractors = new set<SCR_ResourceInteractor>();
38 float debugControlOffset = 0.25;
39
40 [Attribute(defvalue: EResourceContainerStorageType.ORPHAN.ToString(), uiwidget: UIWidgets.ComboBox, desc: "Resource consumption source order.", enums: ParamEnumArray.FromEnum(EResourceContainerStorageType),category: "Debugging")]
42
43 [Attribute(uiwidget: UIWidgets.SpinBox, params: string.Format("0.0 %1 1.0", float.MAX))]
44 protected float m_fResourceValueCurrent;
45
46 [Attribute(uiwidget: UIWidgets.SpinBox, params: string.Format("0.0 %1 1.0", float.MAX))]
47 protected float m_fResourceValueMax;
48
49 [Attribute(uiwidget: UIWidgets.CheckBox)]
50 protected bool m_bEnableResourceGain;
51
52 [Attribute(uiwidget: UIWidgets.SpinBox, params: string.Format("0.0 %1 1.0", float.MAX))]
53 protected float m_fResourceGain;
54
55 [Attribute(uiwidget: UIWidgets.SpinBox, params: string.Format("0.0 %1 1.0", float.MAX))]
56 protected float m_fResourceGainTickrate;
57
58 [Attribute(uiwidget: UIWidgets.SpinBox, params: string.Format("0.0 %1 1.0", float.MAX))]
59 protected float m_fResourceGainTimeout;
60
61 [Attribute(uiwidget: UIWidgets.CheckBox)]
62 protected bool m_bEnableResourceDecay;
63
64 [Attribute(uiwidget: UIWidgets.SpinBox, params: "0.0 inf 1.0")]
65 protected float m_fResourceDecay;
66
67 [Attribute(uiwidget: UIWidgets.SpinBox, params: string.Format("0.0 %1 1.0", float.MAX))]
68 protected float m_fResourceDecayTickrate;
69
70 [Attribute(uiwidget: UIWidgets.SpinBox, params: string.Format("0.0 %1 1.0", float.MAX))]
71 protected float m_fResourceDecayTimeout;
72
73 [Attribute(defvalue: EResourceContainerOnEmptyBehavior.NONE.ToString(), uiwidget: UIWidgets.ComboBox, desc: "Sets the behavior of when the container resource value reaches 0.", enums: ParamEnumArray.FromEnum(EResourceContainerOnEmptyBehavior))]
75
76 protected bool m_bIsEncapsulated;
77
81 protected float m_fWeightMultiplier;
82
91
93
94 //------------------------------------------------------------------------------------------------
96 {
98 }
99
100 //------------------------------------------------------------------------------------------------
102 {
103 return m_fResourceValueMax;
104 }
105
106 //------------------------------------------------------------------------------------------------
108 {
109 return m_fWeightMultiplier;
110 }
111
112 //------------------------------------------------------------------------------------------------
114 {
115 return m_fResourceGain;
116 }
117
118 //------------------------------------------------------------------------------------------------
120 {
121 return m_fResourceDecay;
122 }
123
124 //------------------------------------------------------------------------------------------------
126 {
128 }
129
130 //------------------------------------------------------------------------------------------------
132 {
134 }
135
136 //------------------------------------------------------------------------------------------------
137 void GetBoundingVolume(inout vector mins, inout vector maxs)
138 {
139 if (m_Owner)
140 m_Owner.GetBounds(mins, maxs);
141 }
142
143 //------------------------------------------------------------------------------------------------
144 void GetAxisAlignedBoundingVolume(inout vector mins, inout vector maxs)
145 {
146 if (!m_Owner)
147 return;
148
149 m_Owner.GetWorldBounds(mins, maxs);
150 mins -= m_Owner.GetOrigin();
151 maxs -= m_Owner.GetOrigin();
152 }
153
154 //------------------------------------------------------------------------------------------------
159
160 //------------------------------------------------------------------------------------------------
165
166 //------------------------------------------------------------------------------------------------
171
172 //------------------------------------------------------------------------------------------------
177
178 //------------------------------------------------------------------------------------------------
179 set<SCR_ResourceInteractor> GetLinkedInteractors()
180 {
181 return m_aInteractors;
182 }
183
184 //------------------------------------------------------------------------------------------------
185 array<SCR_ResourceInteractor> GetLinkedInteractorsCopy()
186 {
187 array<SCR_ResourceInteractor> result = new array<SCR_ResourceInteractor>();
188
189 foreach (SCR_ResourceInteractor interactor: m_aInteractors)
190 {
191 result.Insert(interactor);
192 }
193
194 return result;
195 }
196
197 //------------------------------------------------------------------------------------------------
199 {
200 return m_aInteractors.Count();
201 }
202
203 //------------------------------------------------------------------------------------------------
204 SCR_ResourceInteractor GetLinkedInteractorAt(int index)
205 {
206 return m_aInteractors[index];
207 }
208
209 //------------------------------------------------------------------------------------------------
210 int GetLinkedInteractorIndex(notnull SCR_ResourceInteractor interactor)
211 {
212 return m_aInteractors.Find(interactor);
213 }
214
215 //------------------------------------------------------------------------------------------------
221
222 //------------------------------------------------------------------------------------------------
223 bool IsInteractorLinked(notnull SCR_ResourceInteractor interactor)
224 {
225 return m_aInteractors.Contains(interactor);
226 }
227
228 //------------------------------------------------------------------------------------------------
229 bool IsAllowed(notnull SCR_ResourceInteractor interactor)
230 {
231 if (interactor.GetResourceType() != m_eResourceType)
232 return false;
233
234 switch (m_eResourceRights)
235 {
236 case EResourceRights.NONE:
237 return false;
238 case EResourceRights.SELF:
239 return m_Owner == interactor.GetOwner();
240 case EResourceRights.SQUAD:
241 // TODO: Logic for detecting the squad.
242 return false;
243 case EResourceRights.FACTION:
244 FactionAffiliationComponent interactorFactionComponent = interactor.GetComponent().GetFactionAffiliationComponent();
245
246 if (!interactorFactionComponent)
247 return true;
248
249 FactionAffiliationComponent containerFactionComponent = m_ResourceComponent.GetFactionAffiliationComponent();
250
251 if (!containerFactionComponent)
252 return true;
253
254 Faction interactorFaction = interactorFactionComponent.GetAffiliatedFaction();
255 Faction containerFaction = containerFactionComponent.GetAffiliatedFaction();
256
257 if (!interactorFaction || !containerFaction)
258 return true;
259
260 return interactorFaction == containerFaction || interactorFaction.IsFactionFriendly(containerFaction);
261 case EResourceRights.ALL:
262 return true;
263 }
264
265 return true;
266 }
267
268 //------------------------------------------------------------------------------------------------
269 override bool IsIsolated()
270 {
271 return m_bIsEncapsulated || super.IsIsolated();
272 }
273
274 //------------------------------------------------------------------------------------------------
275 bool IsInRange(vector origin, float range)
276 {
277 vector mins, maxs;
278
279 m_Owner.GetBounds(mins, maxs);
280
281 return Math3D.IntersectionSphereAABB(origin - m_Owner.GetOrigin(), range, mins, maxs);
282 }
283
284 //------------------------------------------------------------------------------------------------
286 {
288 }
289
290 //------------------------------------------------------------------------------------------------
292 {
294 }
295
296 //------------------------------------------------------------------------------------------------
298 {
299 return m_bIsEncapsulated;
300 }
301
302 //------------------------------------------------------------------------------------------------
303 override bool ShouldUpdate()
304 {
305 return super.ShouldUpdate() || m_bEnableResourceGain || m_bEnableResourceDecay;
306 }
307
308 //------------------------------------------------------------------------------------------------
313
314 //------------------------------------------------------------------------------------------------
320
321 //------------------------------------------------------------------------------------------------
329
330 //------------------------------------------------------------------------------------------------
338
339 //------------------------------------------------------------------------------------------------
347
348 //------------------------------------------------------------------------------------------------
356
357 //------------------------------------------------------------------------------------------------
365
366 //------------------------------------------------------------------------------------------------
374
375 //------------------------------------------------------------------------------------------------
383
384 //------------------------------------------------------------------------------------------------
392
393
394 //------------------------------------------------------------------------------------------------
399 {
400 m_LastUpdateTimestamp = timestamp;
401 }
402
403 //------------------------------------------------------------------------------------------------
411 bool SetResourceValue(float value, bool notifyChange = true)
412 {
414 return SetResourceValueUnsafe(value, notifyChange);
415
416 float previousValue = m_fResourceValueCurrent;
417 float newValue = Math.Clamp(value, 0.0, m_fResourceValueMax);
418
419 if (newValue > previousValue)
420 m_ResourceEncapsulator.RequestGeneration(newValue - previousValue, notifyChange);
421 else if (newValue < previousValue)
422 m_ResourceEncapsulator.RequestConsumtion(previousValue - newValue, notifyChange);
423 else
424 return false;
425
426 return true;
427 }
428
429 //------------------------------------------------------------------------------------------------
439 bool SetResourceValueUnsafe(float value, bool notifyChange = true)
440 {
441 float previousValue = m_fResourceValueCurrent;
443
444 if (previousValue == m_fResourceValueCurrent)
445 return false;
446
447 if (notifyChange)
448 OnResourcesChanged(previousValue);
449
450 return true;
451 }
452
453 //------------------------------------------------------------------------------------------------
454 bool SetMaxResourceValue(float value, bool notifyChange = true)
455 {
456 float previousValue = m_fResourceValueMax;
457 m_fResourceValueMax = Math.Max(value, 0.0);
458
459 if (previousValue == m_fResourceValueMax)
460 return false;
461
462 if (notifyChange)
463 OnMaxResourcesChanged(previousValue);
464
465 return true;
466 }
467
468 //------------------------------------------------------------------------------------------------
469 bool SetResourceGain(float value, bool notifyChange = true)
470 {
471 float previousValue = m_fResourceGain;
472 m_fResourceGain = Math.Clamp(value, 0.0, m_fResourceValueMax);
473
474 if (previousValue == m_fResourceGain)
475 return false;
476
477 if (notifyChange)
478 OnGainChanged(previousValue);
479
480 return true;
481 }
482
483 //------------------------------------------------------------------------------------------------
484 bool SetResourceDecay(float value, bool notifyChange = true)
485 {
486 float previousValue = m_fResourceDecay;
487 m_fResourceDecay = Math.Clamp(value, 0.0, m_fResourceValueMax);
488
489 if (previousValue == m_fResourceDecay)
490 return false;
491
492 if (notifyChange)
493 OnDecayChanged(previousValue);
494
495 return true;
496 }
497
498 //------------------------------------------------------------------------------------------------
499 void SetResourceGainTickrate(float tickrate)
500 {
501 m_fResourceGainTickrate = tickrate;
502 }
503
504 //------------------------------------------------------------------------------------------------
505 void SetResourceDecayTickrate(float tickrate)
506 {
507 m_fResourceDecayTickrate = tickrate;
508 }
509
510 //------------------------------------------------------------------------------------------------
511 void SetResourceGainTimeout(float timeout)
512 {
513 m_fResourceGainTimeout = timeout;
514 }
515
516 //------------------------------------------------------------------------------------------------
517 void SetResourceDecayTimeout(float timeout)
518 {
519 m_fResourceDecayTimeout = timeout;
520 }
521
522 //------------------------------------------------------------------------------------------------
524 {
525 m_ResourceEncapsulator = encapsulator;
526 }
527
528 //------------------------------------------------------------------------------------------------
529 bool IncreaseResourceValue(float value, bool notifyChange = true)
530 {
531 return SetResourceValue(m_fResourceValueCurrent + value, notifyChange);
532 }
533
534 //------------------------------------------------------------------------------------------------
535 bool DecreaseResourceValue(float value, bool notifyChange = true)
536 {
537 return SetResourceValue(m_fResourceValueCurrent - value, notifyChange);
538 }
539
540 //------------------------------------------------------------------------------------------------
541 bool MaxOutResourceValue(bool notifyChange = true)
542 {
543 return SetResourceValue(m_fResourceValueMax, notifyChange);
544 }
545
546 //------------------------------------------------------------------------------------------------
547 bool DepleteResourceValue(bool notifyChange = true)
548 {
549 return SetResourceValue(0.0, notifyChange);
550 }
551
552 //------------------------------------------------------------------------------------------------
557
558 //------------------------------------------------------------------------------------------------
559 bool LinkInteractor(notnull SCR_ResourceInteractor interactor)
560 {
561 return m_aInteractors.Insert(interactor);
562 }
563
564 //------------------------------------------------------------------------------------------------
565 bool UnlinkInteractor(notnull SCR_ResourceInteractor interactor)
566 {
567 return m_aInteractors.RemoveItem(interactor);
568 }
569
570 //------------------------------------------------------------------------------------------------
572 {
573 m_aInteractors.Clear();
574 }
575
576 //------------------------------------------------------------------------------------------------
577 bool EnableGain(bool shouldEnable, bool notifyChange = true)
578 {
579 bool previousValue = m_bEnableResourceGain;
580 m_bEnableResourceGain = shouldEnable;
581
582 if (previousValue == m_bEnableResourceGain)
583 return false;
584
586
587 if (notifyChange)
588 OnGainEnabledChanged(previousValue);
589
590 ChimeraWorld world = ChimeraWorld.CastFrom(GetGame().GetWorld());
591
592 if (!world)
593 return true;
594
595 SCR_ResourceSystem updateSystem = SCR_ResourceSystem.Cast(world.FindSystem(SCR_ResourceSystem));
596
597 if (!updateSystem)
598 return true;
599
601 updateSystem.RegisterContainer(this);
602 else
603 updateSystem.UnregisterContainer(this);
604
605 return true;
606 }
607
608 //------------------------------------------------------------------------------------------------
609 bool EnableDecay(bool shouldEnable, bool notifyChange = true)
610 {
611 bool previousValue = m_bEnableResourceDecay;
612 m_bEnableResourceDecay = shouldEnable;
613
614 if (previousValue == m_bEnableResourceDecay)
615 return false;
616
618
619 if (notifyChange)
620 OnDecayEnabledChanged(previousValue);
621
622 ChimeraWorld world = ChimeraWorld.CastFrom(GetGame().GetWorld());
623
624 if (!world)
625 return true;
626
627 SCR_ResourceSystem updateSystem = SCR_ResourceSystem.Cast(world.FindSystem(SCR_ResourceSystem));
628
629 if (!updateSystem)
630 return true;
631
633 updateSystem.RegisterContainer(this);
634 else
635 updateSystem.UnregisterContainer(this);
636
637 return true;
638 }
639
640 //------------------------------------------------------------------------------------------------
641 void SetIsEncapsulated(bool shouldEnable)
642 {
643 m_bIsEncapsulated = shouldEnable;
644
646 return;
647
648 SCR_ResourceInteractor interactor;
649
650 for (int index = m_aInteractors.Count() - 1; index >= 0; --index)
651 {
652 interactor = m_aInteractors[index];
653
654 if (SCR_ResourceEncapsulator.Cast(interactor))
655 continue;
656
657 interactor.UnregisterContainer(this);
658 }
659
661 return;
662
663 m_ResourceComponent.DeleteQueryInteractors();
664 m_ResourceComponent.UnflagForProcessing();
665 }
666
667 //------------------------------------------------------------------------------------------------
675
676 //------------------------------------------------------------------------------------------------
677 void DebugDraw(bool shouldShowRange = true)
678 {
679 if (!m_Owner)
680 return;
681
682 string decaying;
683 string gaining;
684
686 decaying = string.Format("\n Decaying %1 every %2s ", m_fResourceDecay, m_fResourceDecayTickrate);
687
689 gaining = string.Format("\n Gaining %1 every %2s ", m_fResourceGain, m_fResourceGainTickrate);
690
691 string infoText = string.Format(" Cur: %1 Max: %2 \n Storage: %3%4%5", GetResourceValue(), GetMaxResourceValue(), SCR_Enum.GetEnumName(EResourceContainerStorageType, m_eStorageType), decaying, gaining);
692 vector origin = m_Owner.GetOrigin();
693
694 int textColor = 0xFFFFFFFF;
695
697 textColor = 0xFF2222FF;
698
699 // If empty, then the text color is red.
700 if (m_fResourceValueCurrent == 0.0)
701 textColor = 0xFFFF2222;
702
703 DebugTextWorldSpace.Create(GetGame().GetWorld(), infoText, DebugTextFlags.CENTER | DebugTextFlags.FACE_CAMERA | DebugTextFlags.ONCE, origin[0], origin[1], origin[2], 10, textColor, 0xFF000000);
704 }
705
706 //------------------------------------------------------------------------------------------------
707 override void Update(WorldTimestamp timestamp)
708 {
709 float resourceValue;
710 const float timeslice = timestamp.DiffSeconds(m_LastUpdateTimestamp);
711 m_LastUpdateTimestamp = timestamp;
712
714 ComputeResourceGain(timeslice, resourceValue);
715
717 ComputeResourceDecay(timeslice, resourceValue);
718
719 if (m_ResourceComponent && resourceValue != 0.0 && SetResourceValue(m_fResourceValueCurrent + resourceValue))
720 m_ResourceComponent.Replicate();
721 }
722
723 //------------------------------------------------------------------------------------------------
728
729 //------------------------------------------------------------------------------------------------
730 protected void ComputeResourceGain(float timeslice, out float resourceValue)
731 {
732 m_fResourceGainElapsedTime += timeslice;
733
734 const float resourceGainElapsedTimeRelative = m_fResourceGainElapsedTime - m_fResourceGainTimeout;
735
737 || resourceGainElapsedTimeRelative < m_fResourceGainTickrate
738 || m_fResourceGainTickrate <= 0.0)
739 return;
740
741 resourceValue += m_fResourceGain * (int)(resourceGainElapsedTimeRelative / m_fResourceGainTickrate);
743 }
744
745 //------------------------------------------------------------------------------------------------
746 protected void ComputeResourceDecay(float timeslice, out float resourceValue)
747 {
748 m_fResourceDecayElapsedTime += timeslice;
749
750 const float resourceDecayElapsedTimeRelative = m_fResourceDecayElapsedTime - m_fResourceDecayTimeout;
751
753 || resourceDecayElapsedTimeRelative < m_fResourceDecayTickrate
754 || m_fResourceDecayTickrate <= 0.0)
755 return;
756
757 resourceValue -= m_fResourceDecay * (int)(resourceDecayElapsedTimeRelative / m_fResourceDecayTickrate);
759 }
760
761 //------------------------------------------------------------------------------------------------
762 protected void OnResourcesChanged(float previousValue)
763 {
765
767 m_OnResourcesChangedInvoker.Invoke(this, previousValue);
768
769 foreach (SCR_ResourceInteractor interactor: m_aInteractors)
770 {
771 if (interactor && interactor != m_ResourceEncapsulator)
772 interactor.UpdateContainerResourceValue(this, previousValue);
773 }
774
775 if (previousValue < m_fResourceValueCurrent)
776 OnResourcesIncreased(previousValue);
777 else
778 OnResourcesDecreased(previousValue);
779
780 // Gameplay actions not marking for saving hotfix.
781 // Decouple this from Resources after 1.0 and move it to Editor
782 if (!m_Owner)
783 return;
784
786 if (!editableEntity)
787 return;
788
789 editableEntity.SetHierarchyAsDirtyInParents();
790 }
791
792 //------------------------------------------------------------------------------------------------
793 protected void OnResourcesIncreased(float previousValue)
794 {
795 // TODO: Perhaps add an invoker here as well?.
797 OnResourcesMaxedOut(previousValue);
798
799 if (previousValue != 0.0)
800 return;
801
802 switch (m_eOnEmptyBehavior)
803 {
805 break;
808 m_ResourceComponent.SetIsVisible(true);
809
810 break;
812 break;
813 default:
814 break;
815 }
816 }
817
818 //------------------------------------------------------------------------------------------------
819 protected void OnResourcesDecreased(float previousValue)
820 {
821 // TODO: Perhaps add an invoker here as well?.
822 if (m_fResourceValueCurrent == 0.0)
823 OnResourcesDepleted(previousValue);
824 }
825
826 //------------------------------------------------------------------------------------------------
827 protected void OnResourcesDepleted(float previousValue)
828 {
830 m_OnResourcesDepletedInvoker.Invoke(this, previousValue);
831
832 switch (m_eOnEmptyBehavior)
833 {
835 break;
838 m_ResourceComponent.SetIsVisible(false);
839
840 break;
842 RplComponent.DeleteRplEntity(m_Owner, false);
843
844 break;
845 default:
846 break;
847 }
848 }
849
850 //------------------------------------------------------------------------------------------------
851 protected void OnResourcesMaxedOut(float previousValue)
852 {
854 m_OnResourcesMaxedOutInvoker.Invoke(this, previousValue);
855 }
856
857 //------------------------------------------------------------------------------------------------
858 protected void OnMaxResourcesChanged(float previousValue)
859 {
861
863 m_OnMaxResourcesChangedInvoker.Invoke(this, previousValue);
864
865 foreach (SCR_ResourceInteractor interactor: m_aInteractors)
866 {
867 if (interactor)
868 interactor.UpdateContainerMaxResourceValue(this, previousValue);
869 }
870 }
871
872 //------------------------------------------------------------------------------------------------
873 protected void OnGainChanged(float previousValue)
874 {
876 m_OnGainChangedInvoker.Invoke(this, previousValue);
877 }
878
879 //------------------------------------------------------------------------------------------------
880 protected void OnDecayChanged(float previousValue)
881 {
883 m_OnDecayChangedInvoker.Invoke(this, previousValue);
884 }
885
886 //------------------------------------------------------------------------------------------------
887 protected void OnGainEnabledChanged(float previousValue)
888 {
890 m_OnGainEnabledChangedInvoker.Invoke(this, previousValue);
891 }
892
893 //------------------------------------------------------------------------------------------------
894 protected void OnDecayEnabledChanged(float previousValue)
895 {
897 m_OnDecayEnabledChangedInvoker.Invoke(this, previousValue);
898 }
899
900 //------------------------------------------------------------------------------------------------
902 {
903 m_sDebugName = container.m_sDebugName;
904 m_eResourceRights = container.m_eResourceRights;
905 m_eResourceType = container.m_eResourceType;
906 m_eStorageType = container.m_eStorageType;
907 m_fResourceValueCurrent = container.m_fResourceValueCurrent;
908 m_fResourceValueMax = container.m_fResourceValueMax;
909 m_bEnableResourceGain = container.m_bEnableResourceGain;
910 m_fResourceGain = container.m_fResourceGain;
911 m_fResourceGainTickrate = container.m_fResourceGainTickrate;
912 m_fResourceGainTimeout = container.m_fResourceGainTimeout;
913 m_bEnableResourceDecay = container.m_bEnableResourceDecay;
914 m_fResourceDecay = container.m_fResourceDecay;
915 m_fResourceDecayTickrate = container.m_fResourceDecayTickrate;
916 m_fResourceDecayTimeout = container.m_fResourceDecayTimeout;
917 m_eOnEmptyBehavior = container.m_eOnEmptyBehavior;
918 }
919
920 //------------------------------------------------------------------------------------------------
921 void Initialize(notnull IEntity owner, notnull SCR_ResourceContainer container)
922 {
923 m_Owner = owner;
924 m_ResourceComponent = SCR_ResourceComponent.Cast(owner.FindComponent(SCR_ResourceComponent));
925 IEntity parentEntity = m_Owner.GetParent();
926
927 CopyFromContainer(container);
928
929 SCR_ResourceEncapsulator encapsulator;
930 SCR_ResourceComponent parentResourceComponent;
931
937 while (parentEntity)
938 {
939 if (!encapsulator)
940 {
941 parentResourceComponent = SCR_ResourceComponent.Cast(parentEntity.FindComponent(SCR_ResourceComponent));
942
943 if (parentResourceComponent)
944 encapsulator = parentResourceComponent.GetEncapsulator(m_eResourceType);
945
946 if (encapsulator)
947 encapsulator.RegisterContainer(this);
948 }
949
950 parentEntity = parentEntity.GetParent();
951 }
952
953 ChimeraWorld world = ChimeraWorld.CastFrom(GetGame().GetWorld());
954
955 if (!world)
956 return;
957
958 if (m_fResourceValueCurrent == 0.0 && !world.IsEditMode() && m_eOnEmptyBehavior == EResourceContainerOnEmptyBehavior.HIDE)
959 m_ResourceComponent.SetIsVisible(false);
960
961 if (!m_ResourceComponent.GetReplicationComponent() || m_ResourceComponent.GetReplicationComponent().IsProxy())
962 return;
963
964 SCR_ResourceSystem updateSystem = SCR_ResourceSystem.Cast(world.FindSystem(SCR_ResourceSystem));
965
966 if (!updateSystem)
967 return;
968
970 updateSystem.RegisterContainer(this);
971 else
972 updateSystem.UnregisterContainer(this);
973
974 if (!IsIsolated())
975 m_ResourceComponent.FlagForProcessing();
976 }
977
978 //------------------------------------------------------------------------------------------------
979 override void Clear()
980 {
981 super.Clear();
982
983 // Reverse iter needed due to self delete operations during UnregisterContainer
984 for (int index = m_aInteractors.Count() - 1; index >= 0; --index)
985 {
986 SCR_ResourceInteractor interactor = m_aInteractors[index];
987 if (interactor)
988 interactor.UnregisterContainer(this);
989 }
990
991 ChimeraWorld world = ChimeraWorld.CastFrom(GetGame().GetWorld());
992 if (!world)
993 return;
994
995 SCR_ResourceSystem updateSystem = SCR_ResourceSystem.Cast(world.FindSystem(SCR_ResourceSystem));
996 if (updateSystem)
997 updateSystem.UnregisterContainer(this);
998 }
999}
@ SQUAD
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
EResourceContainerStorageType
@ CARGO_VEHICLE
@ CARGO_CHARACTER
@ ELECTRICITY
EResourceContainerOnEmptyBehavior
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external Managed FindComponent(typename typeName)
proto external IEntity GetParent()
Definition Math.c:13
SCR_ResourceComponent m_ResourceComponent
EResourceType m_eResourceType
EResourceRights m_eResourceRights
array< SCR_ResourceInteractor > GetLinkedInteractorsCopy()
SCR_ResourceEncapsulator m_ResourceEncapsulator
void OnResourcesDepleted(float previousValue)
override void Update(WorldTimestamp timestamp)
ref ScriptInvoker m_OnMaxResourcesChangedInvoker
void CopyFromContainer(notnull SCR_ResourceContainer container)
void ComputeResourceGain(float timeslice, out float resourceValue)
WorldTimestamp GetLastUpdateTimestamp()
Returns the timestamp that is aimed to be used for the computation of gain and decay.
void OnResourcesChanged(float previousValue)
void OnResourcesDecreased(float previousValue)
void OnGainEnabledChanged(float previousValue)
bool EnableDecay(bool shouldEnable, bool notifyChange=true)
bool SetResourceDecay(float value, bool notifyChange=true)
bool SetResourceValue(float value, bool notifyChange=true)
bool IsAllowed(notnull SCR_ResourceInteractor interactor)
bool IsInRange(vector origin, float range)
SCR_ResourceEncapsulator GetResourceEncapsulator()
void OnDecayChanged(float previousValue)
void SetResourceGainTickrate(float tickrate)
void DebugDraw(bool shouldShowRange=true)
SCR_ResourceInteractor GetLinkedInteractorAt(int index)
ref ScriptInvoker m_OnResourcesDepletedInvoker
bool DecreaseResourceValue(float value, bool notifyChange=true)
void SetResourceGainTimeout(float timeout)
ref ScriptInvoker m_OnGainChangedInvoker
bool SetResourceGain(float value, bool notifyChange=true)
ref set< SCR_ResourceInteractor > m_aInteractors
bool MaxOutResourceValue(bool notifyChange=true)
ref ScriptInvoker m_OnResourcesMaxedOutInvoker
ScriptInvoker GetOnGainEnabledChanged()
ScriptInvoker GetOnResourcesDepleted()
bool UnlinkInteractor(notnull SCR_ResourceInteractor interactor)
EResourceContainerOnEmptyBehavior m_eOnEmptyBehavior
ref ScriptInvoker m_OnDecayEnabledChangedInvoker
void ComputeResourceDecay(float timeslice, out float resourceValue)
ref ScriptInvoker m_OnGainEnabledChangedInvoker
int GetLinkedInteractorIndex(notnull SCR_ResourceInteractor interactor)
void OnMaxResourcesChanged(float previousValue)
void OnDecayEnabledChanged(float previousValue)
ScriptInvoker GetOnDecayEnabledChanged()
bool SetMaxResourceValue(float value, bool notifyChange=true)
void SetResourceEncapsulator(SCR_ResourceEncapsulator encapsulator)
ScriptInvoker GetOnMaxResourcesChanged()
void OnResourcesMaxedOut(float previousValue)
void SetOnEmptyBehavior(EResourceContainerOnEmptyBehavior behavior)
void OnGainChanged(float previousValue)
ref ScriptInvoker m_OnResourcesChangedInvoker
void OnResourcesIncreased(float previousValue)
bool LinkInteractor(notnull SCR_ResourceInteractor interactor)
bool SetResourceValueUnsafe(float value, bool notifyChange=true)
bool EnableGain(bool shouldEnable, bool notifyChange=true)
bool DepleteResourceValue(bool notifyChange=true)
ScriptInvoker GetOnResourcesChanged()
void SetResourceDecayTimeout(float timeout)
void GetBoundingVolume(inout vector mins, inout vector maxs)
void Initialize(notnull IEntity owner, notnull SCR_ResourceContainer container)
EResourceContainerStorageType m_eStorageType
EResourceContainerOnEmptyBehavior GetOnEmptyBehavior()
set< SCR_ResourceInteractor > GetLinkedInteractors()
WorldTimestamp m_LastUpdateTimestamp
void SetResourceDecayTickrate(float tickrate)
void SetIsEncapsulated(bool shouldEnable)
void GetAxisAlignedBoundingVolume(inout vector mins, inout vector maxs)
bool IncreaseResourceValue(float value, bool notifyChange=true)
bool IsInteractorLinked(notnull SCR_ResourceInteractor interactor)
EResourceContainerStorageType GetStorageType()
ScriptInvoker GetOnResourcesMaxedOut()
void SetLastUpdateTimestamp(WorldTimestamp timestamp)
ref ScriptInvoker m_OnDecayChangedInvoker
override bool RegisterContainer(notnull SCR_ResourceContainer container)
void UnregisterContainer(notnull SCR_ResourceContainer container)
void RegisterContainer(notnull SCR_ResourceContainer container)
Definition int.c:13
DebugTextFlags
@ NONE
When Shape is created and not initialized yet.
Definition ShapeType.c:15
SCR_FieldOfViewSettings Attribute
@ DELETE
Further load on the instance is aborted and is deleted immediately.
@ ALL
Everything except general switch.
Definition EntityEvent.c:37
@ INVALID
Missing components, or obstruction test was not possible.
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134