Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ResourceContainer.c
Go to the documentation of this file.
2 {
3  INVALID = -1,
4  SUPPLIES = 0,
6 };
7 
9 {
15 };
16 
18 {
24 };
25 
27 {
28  NONE,
31 };
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")]
41  protected EResourceContainerStorageType m_eStorageType;
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))]
74  protected EResourceContainerOnEmptyBehavior m_eOnEmptyBehavior;
75 
76  protected bool m_bIsEncapsulated;
77 
78  protected float m_fResourceGainElapsedTime;
79  protected float m_fResourceDecayElapsedTime;
80  protected float m_fWeightMultiplier;
81 
82  protected ref ScriptInvoker m_OnResourcesChangedInvoker;
83  protected ref ScriptInvoker m_OnMaxResourcesChangedInvoker;
84  protected ref ScriptInvoker m_OnResourcesDepletedInvoker;
85  protected ref ScriptInvoker m_OnResourcesMaxedOutInvoker;
86  protected ref ScriptInvoker m_OnGainChangedInvoker;
87  protected ref ScriptInvoker m_OnDecayChangedInvoker;
88  protected ref ScriptInvoker m_OnGainEnabledChangedInvoker;
89  protected ref ScriptInvoker m_OnDecayEnabledChangedInvoker;
90 
91  protected SCR_ResourceEncapsulator m_ResourceEncapsulator;
92 
93  //------------------------------------------------------------------------------------------------
94  float GetResourceValue()
95  {
96  return m_fResourceValueCurrent;
97  }
98 
99  //------------------------------------------------------------------------------------------------
100  float GetMaxResourceValue()
101  {
102  return m_fResourceValueMax;
103  }
104 
105  //------------------------------------------------------------------------------------------------
106  float GetWeightMultiplier()
107  {
108  return m_fWeightMultiplier;
109  }
110 
111  //------------------------------------------------------------------------------------------------
112  float GetResourceGain()
113  {
114  return m_fResourceGain;
115  }
116 
117  //------------------------------------------------------------------------------------------------
118  float GetResourceDecay()
119  {
120  return m_fResourceDecay;
121  }
122 
123  //------------------------------------------------------------------------------------------------
124  float GetResourceGainTickrate()
125  {
126  return m_fResourceGainTickrate;
127  }
128 
129  //------------------------------------------------------------------------------------------------
130  float GetResourceDecayTickrate()
131  {
132  return m_fResourceDecayTickrate;
133  }
134 
135  //------------------------------------------------------------------------------------------------
136  void GetBoundingVolume(inout vector mins, inout vector maxs)
137  {
138  if (m_Owner)
139  m_Owner.GetBounds(mins, maxs);
140  }
141 
142  //------------------------------------------------------------------------------------------------
143  void GetAxisAlignedBoundingVolume(inout vector mins, inout vector maxs)
144  {
145  if (!m_Owner)
146  return;
147 
148  m_Owner.GetWorldBounds(mins, maxs);
149  mins -= m_Owner.GetOrigin();
150  maxs -= m_Owner.GetOrigin();
151  }
152 
153  //------------------------------------------------------------------------------------------------
154  EResourceContainerStorageType GetStorageType()
155  {
156  return m_eStorageType;
157  }
158 
159  //------------------------------------------------------------------------------------------------
160  EResourceType GetResourceType()
161  {
162  return m_eResourceType;
163  }
164 
165  //------------------------------------------------------------------------------------------------
166  EResourceContainerOnEmptyBehavior GetOnEmptyBehavior()
167  {
168  return m_eOnEmptyBehavior;
169  }
170 
171  //------------------------------------------------------------------------------------------------
172  SCR_ResourceEncapsulator GetResourceEncapsulator()
173  {
174  return m_ResourceEncapsulator;
175  }
176 
177  //------------------------------------------------------------------------------------------------
178  set<SCR_ResourceInteractor> GetLinkedInteractors()
179  {
180  return m_aInteractors;
181  }
182 
183  //------------------------------------------------------------------------------------------------
184  array<SCR_ResourceInteractor> GetLinkedInteractorsCopy()
185  {
186  array<SCR_ResourceInteractor> result = new array<SCR_ResourceInteractor>();
187 
188  foreach (SCR_ResourceInteractor interactor: m_aInteractors)
189  {
190  result.Insert(interactor);
191  }
192 
193  return result;
194  }
195 
196  //------------------------------------------------------------------------------------------------
197  int GetLinkedInteractorsCount()
198  {
199  return m_aInteractors.Count();
200  }
201 
202  //------------------------------------------------------------------------------------------------
203  SCR_ResourceInteractor GetLinkedInteractorAt(int index)
204  {
205  return m_aInteractors[index];
206  }
207 
208  //------------------------------------------------------------------------------------------------
209  int GetLinkedInteractorIndex(notnull SCR_ResourceInteractor interactor)
210  {
211  return m_aInteractors.Find(interactor);
212  }
213 
214  //------------------------------------------------------------------------------------------------
215  bool IsInteractorLinked(notnull SCR_ResourceInteractor interactor)
216  {
217  return m_aInteractors.Contains(interactor);
218  }
219 
220  //------------------------------------------------------------------------------------------------
221  bool IsAllowed(notnull SCR_ResourceInteractor interactor)
222  {
223  if (interactor.GetResourceType() != m_eResourceType)
224  return false;
225 
226  switch (m_eResourceRights)
227  {
228  case EResourceRights.NONE:
229  return false;
230  case EResourceRights.SELF:
231  return m_Owner == interactor.GetOwner();
232  case EResourceRights.SQUAD:
233  // TODO: Logic for detecting the squad.
234  return false;
235  case EResourceRights.FACTION:
236  FactionAffiliationComponent interactorFactionComponent = interactor.GetComponent().GetFactionAffiliationComponent();
237 
238  if (!interactorFactionComponent)
239  return false;
240 
241  FactionAffiliationComponent containerrFactionComponent = m_ResourceComponent.GetFactionAffiliationComponent();
242 
243  if (!containerrFactionComponent)
244  return false;
245 
246  return interactorFactionComponent.GetAffiliatedFaction() == containerrFactionComponent.GetAffiliatedFaction();
247  case EResourceRights.ALL:
248  return true;
249  }
250 
251  return true;
252  }
253 
254  //------------------------------------------------------------------------------------------------
255  override bool IsIsolated()
256  {
257  return m_bIsEncapsulated || super.IsIsolated();
258  }
259 
260  //------------------------------------------------------------------------------------------------
261  bool IsInRange(vector origin, float range)
262  {
263  vector mins, maxs;
264 
265  m_Owner.GetBounds(mins, maxs);
266 
267  return Math3D.IntersectionSphereAABB(origin - m_Owner.GetOrigin(), range, mins, maxs);
268  }
269 
270  //------------------------------------------------------------------------------------------------
271  bool IsResourceDecayEnabled()
272  {
273  return m_bEnableResourceDecay;
274  }
275 
276  //------------------------------------------------------------------------------------------------
277  bool IsResourceGainEnabled()
278  {
279  return m_bEnableResourceGain;
280  }
281 
282  //------------------------------------------------------------------------------------------------
283  bool IsEncapsulated()
284  {
285  return m_bIsEncapsulated;
286  }
287 
288  //------------------------------------------------------------------------------------------------
289  override bool ShouldUpdate()
290  {
291  return super.ShouldUpdate() || m_bEnableResourceGain || m_bEnableResourceDecay;
292  }
293 
294  //------------------------------------------------------------------------------------------------
295  bool IsAllowedToStoreResource()
296  {
297  return m_eStorageType == EResourceContainerStorageType.STORED;
298  }
299 
300  //------------------------------------------------------------------------------------------------
301  bool CanStoreResource()
302  {
303  return m_eStorageType == EResourceContainerStorageType.STORED
304  && (m_fResourceValueMax - m_fResourceValueCurrent);
305  }
306 
307  //------------------------------------------------------------------------------------------------
308  ScriptInvoker GetOnResourcesChanged()
309  {
310  if (!m_OnResourcesChangedInvoker)
311  m_OnResourcesChangedInvoker = new ScriptInvoker();
312 
313  return m_OnResourcesChangedInvoker;
314  }
315 
316  //------------------------------------------------------------------------------------------------
317  ScriptInvoker GetOnMaxResourcesChanged()
318  {
319  if (!m_OnMaxResourcesChangedInvoker)
320  m_OnMaxResourcesChangedInvoker = new ScriptInvoker();
321 
322  return m_OnMaxResourcesChangedInvoker;
323  }
324 
325  //------------------------------------------------------------------------------------------------
326  ScriptInvoker GetOnResourcesDepleted()
327  {
328  if (!m_OnResourcesDepletedInvoker)
329  m_OnResourcesDepletedInvoker = new ScriptInvoker();
330 
331  return m_OnResourcesDepletedInvoker;
332  }
333 
334  //------------------------------------------------------------------------------------------------
335  ScriptInvoker GetOnResourcesMaxedOut()
336  {
337  if (!m_OnResourcesMaxedOutInvoker)
338  m_OnResourcesMaxedOutInvoker = new ScriptInvoker();
339 
340  return m_OnResourcesMaxedOutInvoker;
341  }
342 
343  //------------------------------------------------------------------------------------------------
344  ScriptInvoker GetOnGainChanged()
345  {
346  if (!m_OnGainChangedInvoker)
347  m_OnGainChangedInvoker = new ScriptInvoker();
348 
349  return m_OnGainChangedInvoker;
350  }
351 
352  //------------------------------------------------------------------------------------------------
353  ScriptInvoker GetOnDecayChanged()
354  {
355  if (!m_OnDecayChangedInvoker)
356  m_OnDecayChangedInvoker = new ScriptInvoker();
357 
358  return m_OnDecayChangedInvoker;
359  }
360 
361  //------------------------------------------------------------------------------------------------
362  ScriptInvoker GetOnGainEnabledChanged()
363  {
364  if (!m_OnGainEnabledChangedInvoker)
365  m_OnGainEnabledChangedInvoker = new ScriptInvoker();
366 
367  return m_OnGainEnabledChangedInvoker;
368  }
369 
370  //------------------------------------------------------------------------------------------------
371  ScriptInvoker GetOnDecayEnabledChanged()
372  {
373  if (!m_OnDecayEnabledChangedInvoker)
374  m_OnDecayEnabledChangedInvoker = new ScriptInvoker();
375 
376  return m_OnDecayEnabledChangedInvoker;
377  }
378 
379  //------------------------------------------------------------------------------------------------
387  bool SetResourceValue(float value, bool notifyChange = true)
388  {
389  if (!m_ResourceEncapsulator)
390  return SetResourceValueUnsafe(value, notifyChange);
391 
392  float previousValue = m_fResourceValueCurrent;
393  float newValue = Math.Clamp(value, 0.0, m_fResourceValueMax);
394 
395  if (newValue > previousValue)
396  m_ResourceEncapsulator.RequestGeneration(newValue - previousValue, notifyChange);
397  else if (newValue < previousValue)
398  m_ResourceEncapsulator.RequestConsumtion(previousValue - newValue, notifyChange);
399  else
400  return false;
401 
402  if (notifyChange)
403  OnResourcesChanged(previousValue);
404 
405  return true;
406  }
407 
408  //------------------------------------------------------------------------------------------------
418  bool SetResourceValueUnsafe(float value, bool notifyChange = true)
419  {
420  float previousValue = m_fResourceValueCurrent;
421  m_fResourceValueCurrent = Math.Clamp(value, 0.0, m_fResourceValueMax);
422 
423  if (previousValue == m_fResourceValueCurrent)
424  return false;
425 
426  if (notifyChange)
427  OnResourcesChanged(previousValue);
428 
429  return true;
430  }
431 
432  //------------------------------------------------------------------------------------------------
433  bool SetMaxResourceValue(float value, bool notifyChange = true)
434  {
435  float previousValue = m_fResourceValueMax;
436  m_fResourceValueMax = Math.Max(value, 0.0);
437 
438  if (previousValue == m_fResourceValueMax)
439  return false;
440 
441  if (notifyChange)
442  OnMaxResourcesChanged(previousValue);
443 
444  return true;
445  }
446 
447  //------------------------------------------------------------------------------------------------
448  bool SetResourceGain(float value, bool notifyChange = true)
449  {
450  float previousValue = m_fResourceGain;
451  m_fResourceGain = Math.Clamp(value, 0.0, m_fResourceValueMax);
452 
453  if (previousValue == m_fResourceGain)
454  return false;
455 
456  if (notifyChange)
457  OnGainChanged(previousValue);
458 
459  return true;
460  }
461 
462  //------------------------------------------------------------------------------------------------
463  bool SetResourceDecay(float value, bool notifyChange = true)
464  {
465  float previousValue = m_fResourceDecay;
466  m_fResourceDecay = Math.Clamp(value, 0.0, m_fResourceValueMax);
467 
468  if (previousValue == m_fResourceDecay)
469  return false;
470 
471  if (notifyChange)
472  OnDecayChanged(previousValue);
473 
474  return true;
475  }
476 
477  //------------------------------------------------------------------------------------------------
478  void SetResourceGainTickrate(float tickrate)
479  {
480  m_fResourceGainTickrate = tickrate;
481  }
482 
483  //------------------------------------------------------------------------------------------------
484  void SetResourceDecayTickrate(float tickrate)
485  {
486  m_fResourceDecayTickrate = tickrate;
487  }
488 
489  //------------------------------------------------------------------------------------------------
490  void SetResourceGainTimeout(float timeout)
491  {
492  m_fResourceGainTimeout = timeout;
493  }
494 
495  //------------------------------------------------------------------------------------------------
496  void SetResourceDecayTimeout(float timeout)
497  {
498  m_fResourceDecayTimeout = timeout;
499  }
500 
501  //------------------------------------------------------------------------------------------------
502  void SetResourceEncapsulator(SCR_ResourceEncapsulator encapsulator)
503  {
504  m_ResourceEncapsulator = encapsulator;
505  }
506 
507  //------------------------------------------------------------------------------------------------
508  bool IncreaseResourceValue(float value, bool notifyChange = true)
509  {
510  return SetResourceValue(m_fResourceValueCurrent + value, notifyChange);
511  }
512 
513  //------------------------------------------------------------------------------------------------
514  bool DecreaseResourceValue(float value, bool notifyChange = true)
515  {
516  return SetResourceValue(m_fResourceValueCurrent - value, notifyChange);
517  }
518 
519  //------------------------------------------------------------------------------------------------
520  bool MaxOutResourceValue(bool notifyChange = true)
521  {
522  return SetResourceValue(m_fResourceValueMax, notifyChange);
523  }
524 
525  //------------------------------------------------------------------------------------------------
526  bool DepleteResourceValue(bool notifyChange = true)
527  {
528  return SetResourceValue(0.0, notifyChange);
529  }
530 
531  //------------------------------------------------------------------------------------------------
532  void SetOnEmptyBehavior(EResourceContainerOnEmptyBehavior behavior)
533  {
534  m_eOnEmptyBehavior = behavior;
535  }
536 
537  //------------------------------------------------------------------------------------------------
538  bool LinkInteractor(notnull SCR_ResourceInteractor interactor)
539  {
540  return m_aInteractors.Insert(interactor);
541  }
542 
543  //------------------------------------------------------------------------------------------------
544  bool UnlinkInteractor(notnull SCR_ResourceInteractor interactor)
545  {
546  return m_aInteractors.RemoveItem(interactor);
547  }
548 
549  //------------------------------------------------------------------------------------------------
550  void UnlinkEveryInteractor()
551  {
552  m_aInteractors.Clear();
553  }
554 
555  //------------------------------------------------------------------------------------------------
556  bool EnableGain(bool shouldEnable, bool notifyChange = true)
557  {
558  bool previousValue = m_bEnableResourceGain;
559  m_bEnableResourceGain = shouldEnable;
560 
561  if (previousValue == m_bEnableResourceGain)
562  return false;
563 
564  m_fResourceGainElapsedTime = 0.0;
565 
566  if (notifyChange)
567  OnGainEnabledChanged(previousValue);
568 
569  ChimeraWorld world = ChimeraWorld.CastFrom(GetGame().GetWorld());
570 
571  if (!world)
572  return true;
573 
574  SCR_ResourceSystem updateSystem = SCR_ResourceSystem.Cast(world.FindSystem(SCR_ResourceSystem));
575 
576  if (!updateSystem)
577  return true;
578 
579  if (m_bEnableResourceGain)
580  updateSystem.RegisterContainer(this);
581  else
582  updateSystem.UnregisterContainer(this);
583 
584  return true;
585  }
586 
587  //------------------------------------------------------------------------------------------------
588  bool EnableDecay(bool shouldEnable, bool notifyChange = true)
589  {
590  bool previousValue = m_bEnableResourceDecay;
591  m_bEnableResourceDecay = shouldEnable;
592 
593  if (previousValue == m_bEnableResourceDecay)
594  return false;
595 
596  m_fResourceDecayElapsedTime = 0.0;
597 
598  if (notifyChange)
599  OnDecayEnabledChanged(previousValue);
600 
601  ChimeraWorld world = ChimeraWorld.CastFrom(GetGame().GetWorld());
602 
603  if (!world)
604  return true;
605 
606  SCR_ResourceSystem updateSystem = SCR_ResourceSystem.Cast(world.FindSystem(SCR_ResourceSystem));
607 
608  if (!updateSystem)
609  return true;
610 
611  if (m_bEnableResourceDecay)
612  updateSystem.RegisterContainer(this);
613  else
614  updateSystem.UnregisterContainer(this);
615 
616  return true;
617  }
618 
619  //------------------------------------------------------------------------------------------------
620  void SetIsEncapsulated(bool shouldEnable)
621  {
622  m_bIsEncapsulated = shouldEnable;
623 
624  if (!m_bIsEncapsulated)
625  return;
626 
627  SCR_ResourceInteractor interactor;
628 
629  for (int index = m_aInteractors.Count() - 1; index >= 0; --index)
630  {
631  interactor = m_aInteractors[index];
632 
633  if (SCR_ResourceEncapsulator.Cast(interactor))
634  continue;
635 
636  interactor.UnregisterContainer(this);
637  }
638 
639  if (!m_ResourceComponent)
640  return;
641 
642  m_ResourceComponent.DeleteQueryInteractors();
643  m_ResourceComponent.UnflagForProcessing();
644  }
645 
646  //------------------------------------------------------------------------------------------------
647  void UpdateWeightMultiplier()
648  {
649  if (m_fResourceValueMax == 0.0)
650  return;
651 
652  m_fWeightMultiplier = m_fResourceValueCurrent / m_fResourceValueMax;
653  }
654 
655  //------------------------------------------------------------------------------------------------
656  void DebugDraw(bool shouldShowRange = true)
657  {
658  if (!m_Owner)
659  return;
660 
661  string decaying;
662  string gaining;
663 
664  if (m_bEnableResourceDecay)
665  decaying = string.Format("\n Decaying %1 every %2s ", m_fResourceDecay, m_fResourceDecayTickrate);
666 
667  if (m_bEnableResourceGain)
668  gaining = string.Format("\n Gaining %1 every %2s ", m_fResourceGain, m_fResourceGainTickrate);
669 
670  string infoText = string.Format(" Cur: %1 Max: %2 \n Storage: %3%4%5", GetResourceValue(), GetMaxResourceValue(), SCR_Enum.GetEnumName(EResourceContainerStorageType, m_eStorageType), decaying, gaining);
671  vector origin = m_Owner.GetOrigin();
672 
673  int textColor = 0xFFFFFFFF;
674 
675  if (m_bIsEncapsulated)
676  textColor = 0xFF2222FF;
677 
678  // If empty, then the text color is red.
679  if (m_fResourceValueCurrent == 0.0)
680  textColor = 0xFFFF2222;
681 
682  DebugTextWorldSpace.Create(GetGame().GetWorld(), infoText, DebugTextFlags.CENTER | DebugTextFlags.FACE_CAMERA | DebugTextFlags.ONCE, origin[0], origin[1], origin[2], 10, textColor, 0xFF000000);
683  }
684 
685  //------------------------------------------------------------------------------------------------
686  override void Update(float timeslice)
687  {
688  float resourceValue = 0.0;
689 
690  if (m_bEnableResourceGain)
691  ComputeResourceGain(timeslice, resourceValue);
692 
693  if (m_bEnableResourceDecay)
694  ComputeResourceDecay(timeslice, resourceValue);
695 
696  if (m_ResourceComponent && resourceValue != 0.0 && SetResourceValue(m_fResourceValueCurrent + resourceValue))
697  m_ResourceComponent.Replicate();;
698  }
699 
700  //------------------------------------------------------------------------------------------------
701  float ComputeResourceDifference()
702  {
703  return m_fResourceValueMax - m_fResourceValueCurrent;
704  }
705 
706  //------------------------------------------------------------------------------------------------
707  protected void ComputeResourceGain(float timeslice, out float resourceValue)
708  {
709  m_fResourceGainElapsedTime += timeslice;;
710 
711  float resourceGainElapsedTimeRelative = m_fResourceGainElapsedTime - m_fResourceGainTimeout;
712 
713  if (m_fResourceGainElapsedTime < m_fResourceGainTimeout
714  || resourceGainElapsedTimeRelative < m_fResourceGainTickrate
715  || m_fResourceGainTickrate <= 0.0)
716  return;
717 
718  resourceValue += m_fResourceGain * (int)(resourceGainElapsedTimeRelative / m_fResourceGainTickrate);
719  m_fResourceGainElapsedTime = m_fResourceGainTimeout;
720  }
721 
722  //------------------------------------------------------------------------------------------------
723  protected void ComputeResourceDecay(float timeslice, out float resourceValue)
724  {
725  m_fResourceDecayElapsedTime += timeslice;
726 
727  float resourceDecayElapsedTimeRelative = m_fResourceDecayElapsedTime - m_fResourceDecayTimeout;
728 
729  if (m_fResourceDecayElapsedTime < m_fResourceDecayTimeout
730  || resourceDecayElapsedTimeRelative < m_fResourceDecayTickrate
731  || m_fResourceDecayTickrate <= 0.0)
732  return;
733 
734  resourceValue -= m_fResourceDecay * (int)(resourceDecayElapsedTimeRelative / m_fResourceDecayTickrate);
735  m_fResourceDecayElapsedTime = m_fResourceDecayTimeout;
736  }
737 
738  //------------------------------------------------------------------------------------------------
739  protected void OnResourcesChanged(float previousValue)
740  {
741  UpdateWeightMultiplier();
742 
743  if (m_OnResourcesChangedInvoker)
744  m_OnResourcesChangedInvoker.Invoke(this, previousValue);
745 
746  foreach (SCR_ResourceInteractor interactor: m_aInteractors)
747  {
748  if (interactor && interactor != m_ResourceEncapsulator)
749  interactor.UpdateContainerResourceValue(this, previousValue);
750  }
751 
752  if (previousValue < m_fResourceValueCurrent)
753  OnResourcesIncreased(previousValue);
754  else
755  OnResourcesDecreased(previousValue);
756 
757  // Gameplay actions not marking for saving hotfix.
758  // Decouple this from Resources after 1.0 and move it to Editor
759  if (!m_Owner)
760  return;
761 
763  if (!editableEntity)
764  return;
765 
766  editableEntity.SetHierarchyAsDirtyInParents();
767  }
768 
769  //------------------------------------------------------------------------------------------------
770  protected void OnResourcesIncreased(float previousValue)
771  {
772  // TODO: Perhaps add an invoker here as well?.
773  if (m_fResourceValueCurrent == m_fResourceValueMax)
774  OnResourcesMaxedOut(previousValue);
775 
776  if (previousValue != 0.0)
777  return;
778 
779  switch (m_eOnEmptyBehavior)
780  {
782  break;
785  m_ResourceComponent.SetIsVisible(true);
786 
787  break;
789  break;
790  default:
791  break;
792  }
793  }
794 
795  //------------------------------------------------------------------------------------------------
796  protected void OnResourcesDecreased(float previousValue)
797  {
798  // TODO: Perhaps add an invoker here as well?.
799  if (m_fResourceValueCurrent == 0.0)
800  OnResourcesDepleted(previousValue);
801  }
802 
803  //------------------------------------------------------------------------------------------------
804  protected void OnResourcesDepleted(float previousValue)
805  {
806  if (m_OnResourcesDepletedInvoker)
807  m_OnResourcesDepletedInvoker.Invoke(this, previousValue);
808 
809  switch (m_eOnEmptyBehavior)
810  {
812  break;
815  m_ResourceComponent.SetIsVisible(false);
816 
817  break;
819  RplComponent.DeleteRplEntity(m_Owner, false);
820 
821  break;
822  default:
823  break;
824  }
825  }
826 
827  //------------------------------------------------------------------------------------------------
828  protected void OnResourcesMaxedOut(float previousValue)
829  {
830  if (m_OnResourcesMaxedOutInvoker)
831  m_OnResourcesMaxedOutInvoker.Invoke(this, previousValue);
832  }
833 
834  //------------------------------------------------------------------------------------------------
835  protected void OnMaxResourcesChanged(float previousValue)
836  {
837  UpdateWeightMultiplier();
838 
839  if (m_OnMaxResourcesChangedInvoker)
840  m_OnMaxResourcesChangedInvoker.Invoke(this, previousValue);
841 
842  foreach (SCR_ResourceInteractor interactor: m_aInteractors)
843  {
844  if (interactor)
845  interactor.UpdateContainerMaxResourceValue(this, previousValue);
846  }
847  }
848 
849  //------------------------------------------------------------------------------------------------
850  protected void OnGainChanged(float previousValue)
851  {
852  if (m_OnGainChangedInvoker)
853  m_OnGainChangedInvoker.Invoke(this, previousValue);
854  }
855 
856  //------------------------------------------------------------------------------------------------
857  protected void OnDecayChanged(float previousValue)
858  {
859  if (m_OnDecayChangedInvoker)
860  m_OnDecayChangedInvoker.Invoke(this, previousValue);
861  }
862 
863  //------------------------------------------------------------------------------------------------
864  protected void OnGainEnabledChanged(float previousValue)
865  {
866  if (m_OnGainEnabledChangedInvoker)
867  m_OnGainEnabledChangedInvoker.Invoke(this, previousValue);
868  }
869 
870  //------------------------------------------------------------------------------------------------
871  protected void OnDecayEnabledChanged(float previousValue)
872  {
873  if (m_OnDecayEnabledChangedInvoker)
874  m_OnDecayEnabledChangedInvoker.Invoke(this, previousValue);
875  }
876 
877  //------------------------------------------------------------------------------------------------
878  void CopyFromContainer(notnull SCR_ResourceContainer container)
879  {
880  m_sDebugName = container.m_sDebugName;
881  m_eStorageType = container.m_eStorageType;
882  m_fResourceValueCurrent = container.m_fResourceValueCurrent;
883  m_fResourceValueMax = container.m_fResourceValueMax;
884  m_bEnableResourceGain = container.m_bEnableResourceGain;
885  m_fResourceGain = container.m_fResourceGain;
886  m_fResourceGainTickrate = container.m_fResourceGainTickrate;
887  m_bEnableResourceDecay = container.m_bEnableResourceDecay;
888  m_fResourceDecay = container.m_fResourceDecay;
889  m_fResourceDecayTickrate = container.m_fResourceDecayTickrate;
890  m_eResourceRights = container.m_eResourceRights;
891  m_eResourceType = container.m_eResourceType;
892  m_eOnEmptyBehavior = container.m_eOnEmptyBehavior;
893  }
894 
895  //------------------------------------------------------------------------------------------------
896  void Initialize(notnull IEntity owner, notnull SCR_ResourceContainer container)
897  {
898  m_Owner = owner;
899  m_ResourceComponent = SCR_ResourceComponent.Cast(owner.FindComponent(SCR_ResourceComponent));
900  IEntity parentEntity = m_Owner.GetParent();
901 
902  CopyFromContainer(container);
903 
904  SCR_ResourceEncapsulator encapsulator;
905  SCR_ResourceComponent parentResourceComponent;
906 
912  while (parentEntity)
913  {
914  if (!encapsulator)
915  {
916  parentResourceComponent = SCR_ResourceComponent.Cast(parentEntity.FindComponent(SCR_ResourceComponent));
917 
918  if (parentResourceComponent)
919  encapsulator = parentResourceComponent.GetEncapsulator(m_eResourceType);
920 
921  if (encapsulator)
922  encapsulator.RegisterContainer(this);
923  }
924 
925  parentEntity = parentEntity.GetParent();
926  }
927 
928  ChimeraWorld world = ChimeraWorld.CastFrom(GetGame().GetWorld());
929 
930  if (!world)
931  return;
932 
933  if (m_fResourceValueCurrent == 0.0 && !world.IsEditMode() && m_eOnEmptyBehavior == EResourceContainerOnEmptyBehavior.HIDE)
934  m_ResourceComponent.SetIsVisible(false);
935 
936  if (!m_ResourceComponent.GetReplicationComponent() || m_ResourceComponent.GetReplicationComponent().IsProxy())
937  return;
938 
939  SCR_ResourceSystem updateSystem = SCR_ResourceSystem.Cast(world.FindSystem(SCR_ResourceSystem));
940 
941  if (!updateSystem)
942  return;
943 
944  if (m_bEnableResourceGain || m_bEnableResourceDecay)
945  updateSystem.RegisterContainer(this);
946  else
947  updateSystem.UnregisterContainer(this);
948 
949  if (!IsIsolated())
950  m_ResourceComponent.FlagForProcessing();
951  }
952 
953  //------------------------------------------------------------------------------------------------
954  override void Clear()
955  {
956  super.Clear();
957 
958  for (int index = m_aInteractors.Count() - 1; index >= 0; --index)
959  {
960  m_aInteractors[index].UnregisterContainer(this);
961  }
962 
963  ChimeraWorld world = ChimeraWorld.CastFrom(GetGame().GetWorld());
964 
965  if (!world)
966  return;
967 
968  SCR_ResourceSystem updateSystem = SCR_ResourceSystem.Cast(world.FindSystem(SCR_ResourceSystem));
969 
970  if (!updateSystem)
971  return;
972 
973  updateSystem.UnregisterContainer(this);
974  }
975 };
ChimeraWorld
Definition: ChimeraWorld.c:12
HIDE
@ HIDE
Definition: SCR_ResourceContainer.c:29
SCR_Enum
Definition: SCR_Enum.c:1
CARGO_PROP
@ CARGO_PROP
Definition: SCR_ResourceContainer.c:21
SQUAD
@ SQUAD
Definition: SCR_ResourceContainer.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
EResourceContainerStorageType
EResourceContainerStorageType
Definition: SCR_ResourceContainer.c:17
SUPPLIES
@ SUPPLIES
Definition: SCR_ResourceContainer.c:4
SELF
@ SELF
Definition: SCR_ResourceContainer.c:11
SCR_ResourceActor
Definition: SCR_ResourceConsumer.c:2
NONE
@ NONE
Definition: SCR_ResourceContainer.c:10
Attribute
typedef Attribute
Post-process effect of scripted camera.
ALL
@ ALL
Definition: SCR_ResourceContainer.c:14
EResourceType
EResourceType
Definition: SCR_ResourceContainer.c:1
STORED
@ STORED
Definition: SCR_ResourceContainer.c:20
m_ResourceComponent
protected SCR_ResourceComponent m_ResourceComponent
Definition: SCR_CampaignBuildingProviderComponent.c:51
CARGO_VEHICLE
@ CARGO_VEHICLE
Definition: SCR_ResourceContainer.c:22
ORPHAN
@ ORPHAN
Definition: SCR_ResourceContainer.c:19
DELETE
@ DELETE
Definition: SCR_ResourceContainer.c:30
EResourceRights
EResourceRights
Definition: SCR_ResourceContainer.c:8
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
INVALID
@ INVALID
Definition: SCR_ResourceContainer.c:3
SCR_ResourceSystem
Definition: SCR_ResourceSystem.c:1
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_ResourceContainer
Definition: SCR_ResourceContainer.c:34
ELECTRICITY
@ ELECTRICITY
Definition: SCR_ResourceContainer.c:5
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_ResourceEncapsulator
Definition: SCR_ResourceEncapsulator.c:1
FACTION
@ FACTION
Definition: SCR_ResourceContainer.c:13
int
SCR_PossessingManagerComponentClass int
m_Owner
SCR_AIGroupUtilityComponentClass m_Owner
EResourceContainerOnEmptyBehavior
EResourceContainerOnEmptyBehavior
Definition: SCR_ResourceContainer.c:26
CARGO_CHARACTER
@ CARGO_CHARACTER
Definition: SCR_ResourceContainer.c:23
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180