Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_BallisticData.c
Go to the documentation of this file.
2{
3 static ref array<ref SCR_BallisticData> s_aBallistics;
4 static bool s_bWaitingForEndOfTheGame;
5
16 protected ref array<ref array<float>> m_aBallisticValues;
18 protected bool m_bDirectFireMode;
19 protected int m_iRangeStep;
22
23 //------------------------------------------------------------------------------------------------
25 {
27 return 0;
28
29 return m_aBallisticValues.Count();
30 }
31
32 //------------------------------------------------------------------------------------------------
36 int GetValues(int id, out array<float> values)
37 {
38 if (!m_aBallisticValues.IsIndexValid(id))
39 return 0;
40
41 values = m_aBallisticValues[id];
42 return values.Count();
43 }
44
45
46 //------------------------------------------------------------------------------------------------
50 void SetValues(int id, notnull array<float> newValues)
51 {
52 if (!m_aBallisticValues.IsIndexValid(id))
53 return;
54
55 m_aBallisticValues[id] = newValues;
56 }
57
58 //------------------------------------------------------------------------------------------------
63 array<float> GetBallisticValuesForClosestRange(int range, out int id = -1)
64 {
65 if (m_iRangeStep == 0 || !m_aBallisticValues || m_aBallisticValues.IsEmpty())
66 return null;
67
68 range = Math.Round(range / m_iRangeStep) * m_iRangeStep;
69 if (m_mDistances.Contains(range))
70 return GetBallisticValuesForRange(range, id);
71
72 if (range <= m_aBallisticValues[0][0])
73 {
74 id = 0;
75 return m_aBallisticValues[0];
76 }
77
78 id = m_aBallisticValues.Count() - 1;
79 return m_aBallisticValues[id];
80 }
81
82 //------------------------------------------------------------------------------------------------
89 array<float> GetBallisticValuesForClosestAngle(float angle, out int id = -1, float epsilon = 0.1, float epsilonStep = 2, float maxEpsilon = 1000)
90 {
91 if (epsilon > maxEpsilon)
92 {
93 angle = -1;
94 id = -1;
95 return null;
96 }
97
98 foreach(int i, array<float> entry : m_aBallisticValues)
99 {
100 if (float.AlmostEqual(entry[1], angle, epsilon))
101 {
102 angle = entry[0];
103 id = i;
104 return entry;
105 }
106 }
107
108 return GetBallisticValuesForClosestAngle(angle, id, epsilon * epsilonStep, epsilonStep, maxEpsilon);
109 }
110
111 //------------------------------------------------------------------------------------------------
115 array<float> GetBallisticValuesForRange(int range, out int id = -1)
116 {
117 if (!m_mDistances.Contains(range))
118 return null;
119
120 id = m_mDistances.Get(range);
121 return m_aBallisticValues[id];
122 }
123
124 //------------------------------------------------------------------------------------------------
129
130 //------------------------------------------------------------------------------------------------
132 {
133 return m_iRangeStep;
134 }
135
136 //------------------------------------------------------------------------------------------------
141
142 //------------------------------------------------------------------------------------------------
144 {
145 return m_bDirectFireMode;
146 }
147
148 //------------------------------------------------------------------------------------------------
149 // constructor
154 void SCR_BallisticData(notnull array<ref array<float>> ballisticValues, string projectilePrefab, bool directFireMode, int rangeStep, float speedCoef)
155 {
156 m_aBallisticValues = ballisticValues;
157 if (!m_aBallisticValues && m_aBallisticValues.IsEmpty())
158 return;
159
161 foreach (int i, array<float> ballistics : m_aBallisticValues)
162 {
163 m_mDistances.Insert(ballistics[0], i);
164 }
165
166 m_sProjectilePrefabName = projectilePrefab;
167 m_bDirectFireMode = directFireMode;
168 m_iRangeStep = rangeStep;
169 m_fProjectileInitSpeedCoef = speedCoef;
171 }
172
173 //------------------------------------------------------------------------------------------------
175 {
176 if (s_bWaitingForEndOfTheGame)
177 return;
178
180 if (!gameMode)
181 return;
182
183 s_bWaitingForEndOfTheGame = true;
184 gameMode.GetOnGameEnd().Insert(ReleaseData);
185 }
186
187 //------------------------------------------------------------------------------------------------
189 protected static void ReleaseData()
190 {
191 s_aBallistics = null;
192 s_bWaitingForEndOfTheGame = false;
194 gameMode.GetOnGameEnd().Remove(ReleaseData);
195 }
196}
AddonBuildInfoTool id
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_BaseGameMode GetGameMode()
Definition Math.c:13
ref map< int, int > m_mDistances
array< float > GetBallisticValuesForClosestAngle(float angle, out int id=-1, float epsilon=0.1, float epsilonStep=2, float maxEpsilon=1000)
static void ReleaseData()
Clears static data to ensure that it doesnt persist over multiple sessions, and thus doesnt grow unex...
int GetValues(int id, out array< float > values)
ResourceName GetProjectileName()
ResourceName m_sProjectilePrefabName
void SCR_BallisticData(notnull array< ref array< float > > ballisticValues, string projectilePrefab, bool directFireMode, int rangeStep, float speedCoef)
ref array< ref array< float > > m_aBallisticValues
void SetValues(int id, notnull array< float > newValues)
static void SubscribeToGameEndEvent()
array< float > GetBallisticValuesForRange(int range, out int id=-1)
array< float > GetBallisticValuesForClosestRange(int range, out int id=-1)
ScriptInvoker GetOnGameEnd()
Definition Types.c:486