Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_BIKIWeaponHelper.c
Go to the documentation of this file.
2{
3 //------------------------------------------------------------------------------------------------
6 static array<float> GetAttachmentMasses(notnull BaseContainer weaponContainer)
7 {
8 array<IEntityComponentSource> componentSources = {};
9 if (SCR_BaseContainerTools.FindComponentSourcesOfClass(weaponContainer, AttachmentSlotComponent, true, componentSources) < 1)
10 return {};
11
12 array<float> result = {};
13 Resource resource;
14 foreach (IEntityComponentSource componentSource : componentSources)
15 {
16 ResourceName attachmentPrefab;
17 if (!componentSource.GetObject("AttachmentSlot") || !componentSource.GetObject("AttachmentSlot").Get("Prefab", attachmentPrefab) || !attachmentPrefab)
18 continue;
19
20 resource = Resource.Load(attachmentPrefab);
21 if (!resource.IsValid())
22 continue;
23
24 result.Insert(SCR_BIKIGeneralHelper.GetMass(resource.GetResource().ToBaseContainer()));
25 }
26
27 return result;
28 }
29
30 //------------------------------------------------------------------------------------------------
33 static array<string> GetAttachmentNames(notnull BaseContainer weaponContainer)
34 {
35 array<IEntityComponentSource> componentSources = {};
36 if (SCR_BaseContainerTools.FindComponentSourcesOfClass(weaponContainer, AttachmentSlotComponent, true, componentSources) < 1)
37 return {};
38
39 array<string> result = {};
40 foreach (IEntityComponentSource componentSource : componentSources)
41 {
42 ResourceName attachmentPrefab;
43 if (!componentSource.GetObject("AttachmentSlot") || !componentSource.GetObject("AttachmentSlot").Get("Prefab", attachmentPrefab) || !attachmentPrefab) // IsEmpty()
44 continue;
45
46 string itemName = SCR_BIKIGeneralHelper.GetName(attachmentPrefab);
47 if (itemName)
48 result.Insert(itemName);
49 }
50
51 return result;
52 }
53
54 //------------------------------------------------------------------------------------------------
57 static float GetInitialSpeedCoefficient(notnull BaseContainer weaponContainer)
58 {
59 IEntityComponentSource muzzleComponentSource = GetMuzzleComponentSource(weaponContainer);
60 if (!muzzleComponentSource)
61 return 0;
62
63 float result;
64 muzzleComponentSource.Get("BulletInitSpeedCoef", result);
65 return result;
66 }
67
68 //------------------------------------------------------------------------------------------------
71 static float GetMass(notnull BaseContainer weaponContainer)
72 {
73 float result = SCR_BIKIGeneralHelper.GetMass(weaponContainer);
74 foreach (float mass : GetAttachmentMasses(weaponContainer))
75 {
76 if (mass > 0)
77 result += mass;
78 }
79
80 return result;
81 }
82
83 //------------------------------------------------------------------------------------------------
86 static float GetMaxRateOfFire(notnull BaseContainer weaponContainer)
87 {
88 IEntityComponentSource muzzleComponentSource = GetMuzzleComponentSource(weaponContainer);
89 if (!muzzleComponentSource)
90 return 0;
91
92 BaseContainerList baseContainerList = muzzleComponentSource.GetObjectArray("FireModes");
93 if (!baseContainerList)
94 return 0;
95
96 float result;
97 for (int i, count = baseContainerList.Count(); i < count; ++i)
98 {
99 float rpm;
100 if (baseContainerList.Get(i).Get("RoundsPerMinute", rpm) && result < rpm)
101 result = rpm;
102 }
103
104 return result;
105 }
106
107 //------------------------------------------------------------------------------------------------
110 static array<string> GetFireModes(notnull BaseContainer weaponContainer)
111 {
112 IEntityComponentSource muzzleComponentSource = GetMuzzleComponentSource(weaponContainer);
113 if (!muzzleComponentSource)
114 return {};
115
116 BaseContainerList baseContainerList = muzzleComponentSource.GetObjectArray("FireModes");
117 if (!baseContainerList)
118 return {};
119
120 array<string> result = {};
121
122 for (int i, count = baseContainerList.Count(); i < count; ++i)
123 {
124 weaponContainer = baseContainerList.Get(i); // variable reuse
125 string fireMode;
126 if (weaponContainer.Get("UIName", fireMode) && fireMode)
127 {
128 float maxBurst;
129 if (weaponContainer.Get("MaxBurst", maxBurst) && maxBurst > 1)
130 result.Insert(string.Format("%1 (%2)", fireMode, maxBurst));
131 else
132 result.Insert(fireMode);
133 }
134 }
135
136 return result;
137 }
138
139 //------------------------------------------------------------------------------------------------
142 static ResourceName GetDefaultMagazine(notnull BaseContainer weaponContainer)
143 {
144 IEntityComponentSource muzzleComponentSource = GetMuzzleComponentSource(weaponContainer);
145 if (!muzzleComponentSource)
146 return ResourceName.Empty;
147
148 ResourceName result;
149 muzzleComponentSource.Get("MagazineTemplate", result);
150 return result;
151 }
152
153 //------------------------------------------------------------------------------------------------
156 static typename GetMagazineWell(notnull BaseContainer weaponContainer)
157 {
158 IEntityComponentSource muzzleComponentSource = GetMuzzleComponentSource(weaponContainer);
159 if (!muzzleComponentSource)
160 return typename.Empty;
161
162 BaseContainer baseContainer = muzzleComponentSource.GetObject("MagazineWell");
163 if (!baseContainer)
164 return typename.Empty;
165
166 return baseContainer.GetClassName().ToType();
167 }
168
169 //------------------------------------------------------------------------------------------------
172 static ResourceName GetStaticWeaponWeapon(notnull BaseContainer weaponContainer)
173 {
174 IEntityComponentSource componentSource = SCR_BaseContainerTools.FindComponentSource(weaponContainer, WeaponSlotComponent);
175 if (!componentSource)
176 return ResourceName.Empty;
177
178 bool enabled;
179 if (!componentSource.Get("Enabled", enabled) || !enabled)
180 return ResourceName.Empty;
181
182 ResourceName result;
183 componentSource.Get("WeaponTemplate", result);
184 return result;
185 }
186
187 //------------------------------------------------------------------------------------------------
190 static array<float> GetStaticWeaponAngles(notnull BaseContainer weaponContainer)
191 {
192 IEntityComponentSource componentSource = SCR_BaseContainerTools.FindComponentSource(weaponContainer, SCR_TurretControllerComponent);
193 if (!componentSource)
194 return { 0, 0, 0, 0 };
195
196 array<float> result = { 0, 0, 0, 0 };
197 vector values;
198
199 componentSource.Get("LimitsHoriz", values);
200 result[0] = values[0];
201 result[1] = values[1];
202
203 componentSource.Get("LimitsVert", values);
204 result[2] = values[0];
205 result[3] = values[1];
206
207 return result;
208 }
209
210 //------------------------------------------------------------------------------------------------
213 static array<string> GetAllTurretNames(notnull BaseContainer vehicleContainer)
214 {
215 array<string> result = {};
216
217 array<IEntityComponentSource> componentSources = {};
218 if (SCR_BaseContainerTools.FindComponentSourcesOfClass(vehicleContainer, SlotManagerComponent, false, componentSources) > 0)
219 {
220 BaseContainerList baseContainerList;
221 BaseContainer baseContainer;
222 Resource resource;
223 foreach (IEntityComponentSource componentSource : componentSources)
224 {
225 baseContainerList = componentSource.GetObjectArray("Slots");
226 if (!baseContainerList)
227 continue;
228
229 for (int i, count = baseContainerList.Count(); i < count; ++i)
230 {
231 baseContainer = baseContainerList.Get(i);
232 if (!baseContainer)
233 continue;
234
235 bool enabled;
236 if (!baseContainer.Get("Enabled", enabled) || !enabled)
237 continue;
238
240 if (baseContainer.Get("Prefab", resourceName) && resourceName)
241 {
242 resource = Resource.Load(resourceName);
243 if (resource.IsValid())
244 result.InsertAll(GetAllTurretNames(resource.GetResource().ToBaseContainer()));
245 }
246 }
247 }
248 }
249
250 if (SCR_BaseContainerTools.FindComponentSourcesOfClass(vehicleContainer, WeaponSlotComponent, false, componentSources) > 0)
251 {
252 Resource resource;
253 foreach (IEntityComponentSource componentSource : componentSources)
254 {
256 if (componentSource.Get("WeaponTemplate", resourceName) && resourceName)
257 {
258 resource = Resource.Load(resourceName);
259 if (resource.IsValid())
260 {
261 array<string> turrets = GetAllTurretNames(resource.GetResource().ToBaseContainer());
262 if (turrets.IsEmpty())
263 {
264 string name = SCR_BIKIGeneralHelper.GetName(vehicleContainer);
265 if (name)
266 result.Insert(name);
267 }
268 else
269 {
270 result.InsertAll(turrets);
271 }
272 }
273 }
274 }
275 }
276
277 return result;
278 }
279
280 //------------------------------------------------------------------------------------------------
281 // PROTECTED METHODS (helper's helpers)
282 //------------------------------------------------------------------------------------------------
283
284 //------------------------------------------------------------------------------------------------
285 protected static IEntityComponentSource GetMuzzleComponentSource(notnull BaseContainer weaponContainer)
286 {
287 array<IEntityComponentSource> componentSources = {};
288 if (SCR_BaseContainerTools.FindComponentSourcesOfClass(weaponContainer, MuzzleComponent, true, componentSources) < 1)
289 return null;
290
291 return componentSources[0];
292 }
293}
ResourceName resourceName
Definition SCR_AIGroup.c:66
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
static IEntityComponentSource GetMuzzleComponentSource(notnull BaseContainer weaponContainer)