Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_Enum.c
Go to the documentation of this file.
2{
3 //------------------------------------------------------------------------------------------------
8 static bool HasFlag(int flags, int condition)
9 {
10 return (flags & condition) == condition;
11 }
12
13 //------------------------------------------------------------------------------------------------
18 static bool HasPartialFlag(int flags, int condition)
19 {
20 return (condition & ~flags) != condition;
21 }
22
23 //------------------------------------------------------------------------------------------------
28 static int SetFlag(int flags, int flagToSet)
29 {
30 flags |= flagToSet;
31 return flags;
32 }
33
34 //------------------------------------------------------------------------------------------------
41 static int RemoveFlag(int flags, int flagToRemove)
42 {
43 flags &= ~flagToRemove;
44 return flags;
45 }
46
47 //------------------------------------------------------------------------------------------------
52 static int BitToIntArray(int bitValue, out notnull array<int> intValues)
53 {
54 intValues.Clear();
55 int count = 0;
56 int i = 1;
57 while (i > 0 && i < int.MAX)
58 {
59 if (bitValue & i)
60 {
61 intValues.Insert(i);
62 count++;
63 }
64 i *= 2;
65 }
66 return count;
67 }
68
69 //------------------------------------------------------------------------------------------------
73 static int IntToBitArray(notnull array<int> intValues)
74 {
75 int bitValue;
76 foreach (int intValue: intValues)
77 {
78 bitValue |= intValue;
79 }
80 return bitValue;
81 }
82
83 //------------------------------------------------------------------------------------------------
88 static string GetEnumName(typename enumType, int enumValue)
89 {
90 return typename.EnumToString(enumType, enumValue);
91 }
92
93 //------------------------------------------------------------------------------------------------
98 static int GetEnumNames(typename enumType, out notnull array<string> stringValues)
99 {
100 stringValues.Clear();
101 array<int> values = {};
102 GetEnumValues(enumType, values);
103 for (int i, count = values.Count(); i < count; i++)
104 {
105 stringValues.Insert(typename.EnumToString(enumType, values[i]));
106 }
107 return stringValues.Count();
108 }
109
110 //------------------------------------------------------------------------------------------------
115 static int GetEnumValues(typename enumType, out notnull array<int> intValues)
116 {
117 int val;
118 for (int i, count = enumType.GetVariableCount(); i < count; i++)
119 {
120 if (enumType.GetVariableValue(null, i, val))
121 intValues.Insert(val);
122 }
123 return intValues.Count();
124 }
125
126 //------------------------------------------------------------------------------------------------
131 static int GetPreviousEnumValue(typename enumType, int value)
132 {
133 int previousValue;
134 enumType.GetVariableValue(null, 0, previousValue);
135 if (previousValue == value)
136 return value;
137
138 array<int> intValues = {};
139 for (int i, count = GetEnumValues(enumType, intValues); i < count; i++)
140 {
141 if (intValues[i] > previousValue && intValues[i] < value)
142 previousValue = intValues[i];
143 }
144
145 return previousValue;
146 }
147
148 //------------------------------------------------------------------------------------------------
153 static int GetNextEnumValue(typename enumType, int value)
154 {
155 int count = enumType.GetVariableCount();
156 int nextValue;
157 enumType.GetVariableValue(null, count - 1, nextValue);
158 if (nextValue == value)
159 return value;
160
161 array<int> intValues = {};
162 GetEnumValues(enumType, intValues);
163 for (int i; i < count; i++)
164 {
165 if (intValues[i] > value && intValues[i] < nextValue)
166 nextValue = intValues[i];
167 }
168
169 return nextValue;
170 }
171
172 //------------------------------------------------------------------------------------------------
176 static int GetFlagValues(typename enumType)
177 {
178 int val, flags;
179 for (int i, count = enumType.GetVariableCount(); i < count; i++)
180 {
181 if (enumType.GetVariableValue(null, i, val))
182 flags |= val;
183 }
184 return flags;
185 }
186
187 //------------------------------------------------------------------------------------------------
193 static bool GetRange(typename enumType, out int min, out int max)
194 {
195 min = int.MAX;
196 max = int.MIN;
197 int val, count = enumType.GetVariableCount();
198 for (int i = 0; i < count; i++)
199 {
200 if (enumType.GetVariableValue(null, i, val))
201 {
202 min = Math.Min(min, val);
203 max = Math.Max(max, val);
204 }
205 }
206 return count > 0;
207 }
208
209 //------------------------------------------------------------------------------------------------
216 static ParamEnumArray GetList(typename e, ParamEnum customValue1 = null, ParamEnum customValue2 = null, ParamEnum customValue3 = null)
217 {
218 ParamEnumArray params = ParamEnumArray.FromEnum(e);
219
220 if (customValue3)
221 params.InsertAt(customValue3, 0);
222 if (customValue2)
223 params.InsertAt(customValue2, 0);
224 if (customValue1)
225 params.InsertAt(customValue1, 0);
226
227 return params;
228 }
229
230 //------------------------------------------------------------------------------------------------
234 static ParamEnumArray GetList(notnull array<string> names)
235 {
236 ParamEnumArray params = {};
237 for (int i, count = names.Count(); i < count; i++)
238 {
239 params.Insert(new ParamEnum(names[i], i.ToString()));
240 }
241 return params;
242 }
243
244 //------------------------------------------------------------------------------------------------
248 static ParamEnumArray GetFlags(notnull array<string> names)
249 {
250 ParamEnumArray params = {};
251 for (int i, count = names.Count(); i < count; i++)
252 {
253 params.Insert(new ParamEnum(names[i], Math.Pow(2, i).ToString()));
254 }
255 return params;
256 }
257
258 //------------------------------------------------------------------------------------------------
265 static string FlagsToString(typename e, int flags, string delimiter = ", ", string noValue = "N/A")
266 {
267 if (flags <= 0)
268 return noValue;
269
270 array<int> outValues = {};
271
272 int count = BitToIntArray(flags, outValues);
273 if (count == 0)
274 return string.Empty;
275
276 string result = typename.EnumToString(e, outValues[0]);
277 for (int i = 1; i < count; i++)
278 {
279 result += delimiter;
280 result += typename.EnumToString(e, outValues[i]);
281 }
282 return result;
283 }
284
285 //------------------------------------------------------------------------------------------------
289 static string GetDefault(int enumValue)
290 {
291 return string.Format("%1", enumValue);
292 }
293
294 //------------------------------------------------------------------------------------------------
298 static string GetDefault(typename enumType)
299 {
300 return GetDefault(GetFlagValues(enumType));
301 }
302}
SCR_EAIThreatSectorFlags flags
void ParamEnum(string key, string value, string desc="")
Definition attributes.c:25
Definition Math.c:13
@ MAX