Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ResourceSystemHelper.c
Go to the documentation of this file.
2 {
3  //~ How many decimals are displayed when showing supplies. Use SCR_ResourceSystemHelper.SuppliesToString(supplies) to ignore any decimals ending in 0
4  static const int DECIMALS_SUPPLIES = 1;
5 
6  //------------------------------------------------------------------------------------------------
9  static bool IsGlobalResourceTypeEnabled(EResourceType resourceType = EResourceType.SUPPLIES)
10  {
11  SCR_BaseGameMode baseGameMode = SCR_BaseGameMode.Cast(GetGame().GetGameMode());
12  if (!baseGameMode)
13  return true;
14 
15  return baseGameMode.IsResourceTypeEnabled(resourceType);
16  }
17 
18  //------------------------------------------------------------------------------------------------
26  static bool GetStoredResources(notnull SCR_ResourceComponent resourceComponent, out float storedRescources, EResourceType resourceType = EResourceType.SUPPLIES)
27  {
28  SCR_ResourceConsumer consumer;
29  storedRescources = 0;
30 
31  if (resourceComponent.GetConsumer(EResourceGeneratorID.VEHICLE_UNLOAD, resourceType, consumer))
32  {
33  storedRescources = consumer.GetAggregatedResourceValue();
34  return true;
35  }
36 
37 
38  if (resourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT_STORAGE, resourceType, consumer))
39  {
40  storedRescources = consumer.GetAggregatedResourceValue();
41  return true;
42  }
43 
44  SCR_ResourceGenerator generator;
45  if (resourceComponent.GetGenerator(EResourceGeneratorID.VEHICLE_LOAD, resourceType, generator))
46  {
47  storedRescources = generator.GetAggregatedResourceValue();
48  return true;
49  }
50 
51  return false;
52  }
53 
54  //------------------------------------------------------------------------------------------------
60  static string SuppliesToString(float supplies)
61  {
62  return SCR_FormatHelper.FloatToStringNoZeroDecimalEndings(supplies, DECIMALS_SUPPLIES);
63  }
64 
65  //------------------------------------------------------------------------------------------------
74  static bool GetStoredAndMaxResources(notnull SCR_ResourceComponent resourceComponent, out float totalResources, out float maxResources, EResourceType resourceType = EResourceType.SUPPLIES)
75  {
76  SCR_ResourceConsumer consumer;
77 
78  totalResources = 0;
79  maxResources = 0;
80 
81  if (resourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT_STORAGE, resourceType, consumer))
82  {
83  maxResources = consumer.GetAggregatedMaxResourceValue();
84  totalResources = consumer.GetAggregatedResourceValue();
85 
86  if (maxResources > 0)
87  return true;
88  }
89 
90  if (resourceComponent.GetConsumer(EResourceGeneratorID.VEHICLE_UNLOAD, resourceType, consumer))
91  {
92  maxResources = consumer.GetAggregatedMaxResourceValue();
93  totalResources = consumer.GetAggregatedResourceValue();
94 
95  if (maxResources > 0)
96  return true;
97  }
98 
99  SCR_ResourceGenerator generator;
100  if (resourceComponent.GetGenerator(EResourceGeneratorID.VEHICLE_LOAD, resourceType, generator))
101  {
102  maxResources = generator.GetAggregatedMaxResourceValue();
103  totalResources = generator.GetAggregatedResourceValue();
104 
105  if (maxResources > 0)
106  return true;
107  }
108 
109  //~ Reset again
110  totalResources = 0;
111  maxResources = 0;
112 
113  return false;
114  }
115 
116  //------------------------------------------------------------------------------------------------
125  static bool GetAvailableResources(notnull SCR_ResourceComponent resourceComponent, out float availableResources, EResourceGeneratorID resourceID = EResourceGeneratorID.DEFAULT, EResourceType resourceType = EResourceType.SUPPLIES)
126  {
127  SCR_ResourceConsumer consumer;
128  availableResources = 0;
129 
130  if (resourceComponent.GetConsumer(resourceID, resourceType, consumer))
131  {
132  availableResources = consumer.GetAggregatedResourceValue();
133  return true;
134  }
135 
136 
137  return false;
138  }
139 
140  //------------------------------------------------------------------------------------------------
147  static SCR_ResourceConsumer GetStorageConsumer(notnull SCR_ResourceComponent resourceComponent, EResourceType resourceType = EResourceType.SUPPLIES)
148  {
149  SCR_ResourceConsumer consumer = resourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT_STORAGE, resourceType);
150  if (consumer)
151  return consumer;
152 
153  consumer = resourceComponent.GetConsumer(EResourceGeneratorID.VEHICLE_UNLOAD, resourceType);
154  if (consumer)
155  return consumer;
156 
157  return null;
158  }
159 
160  //------------------------------------------------------------------------------------------------
167  static SCR_ResourceConsumer GetAvailableResourceConsumer(notnull SCR_ResourceComponent resourceComponent, EResourceType resourceType = EResourceType.SUPPLIES)
168  {
169  return resourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, resourceType);
170  }
171 
172  //------------------------------------------------------------------------------------------------
179  static SCR_ResourceConsumer GetFirstValidConsumer(notnull SCR_ResourceComponent resourceComponent, EResourceType resourceType = EResourceType.SUPPLIES)
180  {
181  SCR_ResourceConsumer consumer = resourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT_STORAGE, resourceType);
182  if (consumer)
183  return consumer;
184 
185  consumer = resourceComponent.GetConsumer(EResourceGeneratorID.VEHICLE_UNLOAD, resourceType);
186  if (consumer)
187  return consumer;
188 
189  consumer = resourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, resourceType);
190  if (consumer)
191  return consumer;
192 
193  return null;
194  }
195 
196  //------------------------------------------------------------------------------------------------
203  static SCR_ResourceGenerator GetFirstValidGenerator(notnull SCR_ResourceComponent resourceComponent, EResourceType resourceType = EResourceType.SUPPLIES)
204  {
205  SCR_ResourceGenerator generator = resourceComponent.GetGenerator(EResourceGeneratorID.DEFAULT_STORAGE, resourceType);
206  if (generator)
207  return generator;
208 
209  generator = resourceComponent.GetGenerator(EResourceGeneratorID.VEHICLE_LOAD, resourceType);
210  if (generator)
211  return generator;
212 
213  generator = resourceComponent.GetGenerator(EResourceGeneratorID.DEFAULT, resourceType);
214  if (generator)
215  return generator;
216 
217  return null;
218  }
219 
220  //------------------------------------------------------------------------------------------------
223  static float RoundRefundSupplyAmount(float refundCost)
224  {
225  return Math.Ceil(refundCost);
226  }
227 }
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
SCR_ResourceSystemHelper
Definition: SCR_ResourceSystemHelper.c:1
SCR_FormatHelper
Definition: SCR_FormatHelper.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
EResourceType
EResourceType
Definition: SCR_ResourceContainer.c:1
SCR_ResourceGenerator
Definition: SCR_ResourceGenerator.c:79
EResourceGeneratorID
EResourceGeneratorID
Definition: SCR_ResourceGenerator.c:1