Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_BaseBallisticConfig.c
Go to the documentation of this file.
2{
3 [Attribute(uiwidget: UIWidgets.ResourcePickerThumbnail, desc: "Prefab from which system will extrapolate the ballistic data", params: "et class=Projectile")]
5
6 [Attribute(desc: "Static text that will be shown for this config")]
7 protected string m_sDisplayedText;
8
9 [Attribute(desc: "Resolution of generated ballistic data - smaller value == highier resolution == more memory consumed", params: "1 inf")]
10 protected int m_iRangeStep;
11
12 [Attribute("1", desc: "Coeficient of the initial projectile speed", params: "0.1 inf")]
14
15 [Attribute("0", desc: "Average dispersion", params: "0 inf")]
16 protected float m_fStandardDispersion;
17
18 [Attribute(SCR_Enum.GetDefault(SCR_EOpticsAngleUnits.MILS_NATO), uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(SCR_EOpticsAngleUnits))]
19 protected string m_sUnitType;
20
21 [Attribute(desc: "Is this config is for direct or indirect fire mode")]
22 protected bool m_bDirectFireMode;
23
24 [Attribute("0", desc: "Minimal allowed angle at which this projectile can be fired [deg]", params: "0 inf")]
25 protected float m_fMinFireAngle;
26
27 [Attribute("85", desc: "Max allowed angle at which this projectile can be fired [deg]", params: "0 inf")]
28 protected float m_fMaxFireAngle;
29
30 [Attribute("{A37CF52DBA874559}UI/Imagesets/WeaponInfo/WeaponInfo_Ammo.imageset", UIWidgets.ResourceNamePicker, "Set of images that contain ammo type icon", ".imageset", category: "Layouts")]
32
33 [Attribute(desc: "Quad name from the {A37CF52DBA874559}UI/Imagesets/WeaponInfo/WeaponInfo_Ammo.imageset", category: "Layouts")]
34 protected string m_sAmmoTypeQuadName;
35
36 [Attribute("32", desc: "Size of the ammo type image", params: "1 inf", category: "Layouts")]
37 protected int m_iAmmoTypeImageSize;
38
40 protected int m_iBallisticDataId = -1;
41
42 //------------------------------------------------------------------------------------------------
47
48 //------------------------------------------------------------------------------------------------
50 {
51 return m_sDisplayedText;
52 }
53
54 //------------------------------------------------------------------------------------------------
56 {
57 return m_iRangeStep;
58 }
59
60 //------------------------------------------------------------------------------------------------
65
66 //------------------------------------------------------------------------------------------------
68 {
70 }
71
72 //------------------------------------------------------------------------------------------------
74 {
75 return m_iBallisticDataId > -1;
76 }
77
78 //------------------------------------------------------------------------------------------------
80 {
81 return m_bDirectFireMode;
82 }
83
84 //------------------------------------------------------------------------------------------------
89
90 //------------------------------------------------------------------------------------------------
92 {
94 }
95
96 //------------------------------------------------------------------------------------------------
98 {
100 }
101
102 //------------------------------------------------------------------------------------------------
104 {
105 return m_iBallisticDataId;
106 }
107
108 //------------------------------------------------------------------------------------------------
110 {
111 if (m_eUnitType < 0)
112 m_eUnitType = typename.StringToEnum(SCR_EOpticsAngleUnits, m_sUnitType);
113
114 return m_eUnitType;
115 }
116
117 //------------------------------------------------------------------------------------------------
121 {
122 if (!GetGame().InPlayMode())
123 return false;
124
125 GetUnitType();
127
129 return true;
130
131 if (m_iRangeStep < 1)
132 return false;
133
134 Resource resource = Resource.Load(m_sProjectilePrefab);
135 if (!resource.IsValid())
136 return false;
137
138 BaseResourceObject resourceObj = resource.GetResource();
139 if (!resourceObj)
140 return false;
141
142 IEntitySource entitySrc = resourceObj.ToEntitySource();
143 if (!entitySrc)
144 return false;
145
146 float distance, travelTime, aimHeight, angle;
147 array<ref array<float>> ballisticValues = {};
148 int numberOfFailedAttempts = 10;
149 while (numberOfFailedAttempts > 0)
150 {
152
153 aimHeight = BallisticTable.GetHeightFromProjectileSource(distance, travelTime, entitySrc, m_fProjectileInitSpeedCoef, m_bDirectFireMode);
154 angle = Math.Atan2(aimHeight, distance); //radians
155
156 if (travelTime <= 0 || angle <= 0)
157 {
158 numberOfFailedAttempts--;
159 continue;
160 }
161
162 angle = Math.Round(SCR_Math.ConvertFromRadians(angle, m_eUnitType));
163 travelTime = travelTime.ToString(0,1).ToFloat();
164
165 ballisticValues.Insert({distance, angle, travelTime});
166 }
167
168 float edgeAngle, edgeAngleRad;
170 {
171 edgeAngleRad = SCR_Math.ConvertToRadians(45.5, SCR_EOpticsAngleUnits.DEGREES);
172 edgeAngle = Math.Round(SCR_Math.ConvertFromRadians(edgeAngleRad, m_eUnitType));
173 }
174
175 if (ballisticValues.IsEmpty())
176 return false;
177
178 int edgeElementId;
179 float cutoffRadAngle = SCR_Math.ConvertToRadians(ballisticValues[edgeElementId][1], m_eUnitType);
180 vector edgeValue = GenerateEdgeValues(entitySrc, cutoffRadAngle);
181 if (edgeValue != vector.One * -1)
182 {
183 float distanceDiff = Math.AbsFloat(edgeValue[0] - ballisticValues[edgeElementId][0]);
184 if (distanceDiff <= m_iRangeStep && distanceDiff > m_iRangeStep * 0.2)
185 ballisticValues.InsertAt({edgeValue[0], edgeValue[1], edgeValue[2]}, 0);
186 }
187
188 edgeElementId = ballisticValues.Count() - 1;
189
190 cutoffRadAngle = SCR_Math.ConvertToRadians(ballisticValues[edgeElementId][1], m_eUnitType);
191 edgeValue = GenerateEdgeValues(entitySrc, cutoffRadAngle, true);
192 if (edgeValue != vector.One * -1)
193 {
194 float distanceDiff = Math.AbsFloat(edgeValue[0] - ballisticValues[edgeElementId][0]);
195 if (distanceDiff <= m_iRangeStep && distanceDiff > m_iRangeStep * 0.2)
196 ballisticValues.Insert({edgeValue[0], edgeValue[1], edgeValue[2]});
197 }
198
200 if (!SCR_BallisticData.s_aBallistics)
201 SCR_BallisticData.s_aBallistics = {};
202
203 SCR_BallisticData.s_aBallistics.Insert(ballisticData);
204 m_iBallisticDataId = SCR_BallisticData.s_aBallistics.Count() - 1;
205
206 return true;
207 }
208
209 //------------------------------------------------------------------------------------------------
210 protected vector GenerateEdgeValues(notnull IEntitySource entitySrc, float cutoffRadAngle, bool upper = false)
211 {
212 float angleRad;
214 {
215 if (upper)
216 angleRad = SCR_Math.ConvertToRadians(m_fMaxFireAngle, SCR_EOpticsAngleUnits.DEGREES);
217 else
218 angleRad = SCR_Math.ConvertToRadians(m_fMinFireAngle, SCR_EOpticsAngleUnits.DEGREES);
219 }
220 else
221 {
222 if (!upper)
223 angleRad = SCR_Math.ConvertToRadians(m_fMaxFireAngle, SCR_EOpticsAngleUnits.DEGREES);
224 else
225 angleRad = SCR_Math.ConvertToRadians(m_fMinFireAngle, SCR_EOpticsAngleUnits.DEGREES);
226 }
227
228 float distance, angle, travelTime;
229 for (float f = angleRad; f < cutoffRadAngle;)
230 {
231 distance = BallisticTable.GetDistanceOfProjectileSource(f, travelTime, entitySrc, m_fProjectileInitSpeedCoef, m_bDirectFireMode);
232
233 if (distance > 0 && travelTime > 0)
234 {
235 distance = Math.Floor(distance) * 10;
236 angle = Math.Round(SCR_Math.ConvertFromRadians(f, m_eUnitType));
237 travelTime = Math.Floor(travelTime * 10) * 0.1;
238 return {distance, angle, travelTime};
239 }
240
241 if (float.AlmostEqual(f, cutoffRadAngle))
242 break;
243
244 f = Math.Lerp(f, cutoffRadAngle, 0.1);
245 }
246
247 return vector.One * -1;
248 }
249
250 //------------------------------------------------------------------------------------------------
254 bool VerifyDataExistence(inout int id = -1)
255 {
256 if (!SCR_BallisticData.s_aBallistics)
257 return false;
258
259 if (id >= 0 && SCR_BallisticData.s_aBallistics.IsIndexValid(id))
260 {
261 SCR_BallisticData ballisticData = SCR_BallisticData.s_aBallistics[id];
262 if (ballisticData.IsForDirectFireMode() == m_bDirectFireMode
263 && ballisticData.GetRangeStep() == m_iRangeStep
264 && ballisticData.GetProjectileName() == m_sProjectilePrefab)
265 return true;
266
267 id = -1;
268 }
269
270 foreach (int i, SCR_BallisticData ballisticData : SCR_BallisticData.s_aBallistics)
271 {
272 if (ballisticData.IsForDirectFireMode() != m_bDirectFireMode)
273 continue;
274
275 if (ballisticData.GetRangeStep() != m_iRangeStep)
276 continue;
277
279 continue;
280
281 if (ballisticData.GetProjectileName() != m_sProjectilePrefab)
282 continue;
283
284 id = i;
285 return true;
286 }
287
288 return false;
289 }
290}
AddonBuildInfoTool id
ArmaReforgerScripted GetGame()
Definition game.c:1398
float distance
SCR_EOpticsAngleUnits
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition Math.c:13
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
ResourceName GetProjectileName()
static void SubscribeToGameEndEvent()
bool VerifyDataExistence(inout int id=-1)
vector GenerateEdgeValues(notnull IEntitySource entitySrc, float cutoffRadAngle, bool upper=false)
SCR_EOpticsAngleUnits m_eUnitType
SCR_EOpticsAngleUnits GetUnitType()
static float ConvertFromRadians(float radianAngleFrom, SCR_EOpticsAngleUnits toUnitType)
Definition SCR_Math.c:290
static float ConvertToRadians(float angleFrom, SCR_EOpticsAngleUnits fromUnitType)
Definition SCR_Math.c:323
SCR_FieldOfViewSettings Attribute