Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
bulletimpactbase.c
Go to the documentation of this file.
2{
3 static const int SURVIVOR_HEAD = 0; // Head component
4 static const int INFECTED_HEAD = 3; // Head component
5 static float DEFAULT_PROJECTILE_WEIGHT = 0.015;
6
7 float MIN_SCALING_PARAM = 0.1;
8
9 Object m_DirectHit;
10 float m_StoppingForce;
11 float m_Weight; // projectile weight in kg
12 int m_ImpactType;
13 int m_ComponentIndex;
14 vector m_Pos;
15 vector m_SurfNormal;
16 vector m_ExitPos;
17 vector m_InSpeed;
18 vector m_OutSpeed;
19 string m_AmmoType;
20
21 static vector INVALID = "0 0 0";
22
23 // Particle Effects
24 int m_ParticleEnter = -1;
25 int m_ParticleExit = -1;
26 int m_ParticleRicochet = -1;
27
28 // Calculations
29 float m_EnterSplashCoef = 0.003;
30 float m_ExitSplashCoef = 0.002;
31 float m_RicochetSplashCoef = 0.002;
32 float m_EnterAngledSplashCoef = 0.01;
33 float m_AngledEnter = 0.40;
34
36 {
37
38 }
39
40 override void OnCheckUpdate()
41 {
42 //DbgUI.Text( m_ammoType );
43 }
44
45 void SetEnterParticle(int id)
46 {
47 m_ParticleEnter = id;
48 }
49
50 void SetExitParticle(int id)
51 {
52 m_ParticleExit = id;
53 }
54
55 void SetRicochetParticle(int id)
56 {
57 m_ParticleRicochet = id;
58 }
59
60 void SetSingleParticle(int id)
61 {
62 SetEnterParticle(id);
63 SetExitParticle(id);
64 SetRicochetParticle(id);
65 }
66
67 void SetAngledEnterValue(float f)
68 {
69 m_AngledEnter = f;
70 }
71
72 void EvaluateEffect(Object directHit, int componentIndex, vector pos, int impact_type, vector surfNormal, vector exitPos, vector inSpeed, vector outSpeed, string ammoType)
73 {
74 m_DirectHit = directHit;
75 m_Pos = pos;
76 m_ImpactType = impact_type;
77 m_ComponentIndex = componentIndex;
78 m_SurfNormal = surfNormal;
79 m_ExitPos = exitPos;
80 m_InSpeed = inSpeed;
81 m_OutSpeed = outSpeed;
82 m_AmmoType = ammoType;
83 m_Weight = GetGame().ConfigGetFloat("CfgAmmo " + ammoType + " weight");
84
85 m_StoppingForce = CalculateStoppingForce(m_InSpeed.Length(), m_OutSpeed.Length(), ammoType, m_Weight);
86 }
87
88 float CalculateStoppingForce(float in_speedf, float out_speedf, string ammoType, float weight)
89 {
90 if ( m_ImpactType == ImpactTypes.MELEE )
91 {
92 return Math.RandomFloat(50, 100);
93 }
94
95 float projectile_weight_coef = weight / DEFAULT_PROJECTILE_WEIGHT;
96
97 float stopping_force = (in_speedf - out_speedf) * projectile_weight_coef;
98
99 return stopping_force;
100 }
101
102 void OnEnterCalculations( Particle p )
103 {
104 // All values represent scale
105 float velocity_min = (m_StoppingForce * m_EnterSplashCoef);
106 float velocity_max = (m_StoppingForce * m_EnterSplashCoef);
107 float size = (m_StoppingForce * m_EnterSplashCoef);
108 float birth_rate = (m_StoppingForce * m_EnterSplashCoef);
109 float air_resistance = velocity_min;
110 float lifetime = (m_StoppingForce * m_EnterSplashCoef);
111 float lifetime_rnd = (m_StoppingForce * m_EnterSplashCoef);
112
113 if ( m_AmmoType == "Bullet_12GaugePellets" )
114 {
115 birth_rate *= 0.5;
116 velocity_min *= 2;
117 velocity_max *= 2;
118 }
119
120
121 if (velocity_min < 0.75)
122 velocity_min = 0.75;
123
124 if (size < 0.75)
125 size = 0.75;
126
127 if (lifetime < 0.5)
128 lifetime = 0.5;
129
130 if (lifetime_rnd < 0.5)
131 lifetime_rnd = 0.5;
132
133 if (velocity_max < 1)
134 velocity_max = 1;
135
136 /*Print("===============");
137 Print(velocity_min);
138 Print(velocity_max);
139 Print(size);
140 Print(birth_rate);
141 Print(air_resistance);
142 Print(lifetime);
143 Print(lifetime_rnd);*/
144
145 p.ScaleParticleParam(EmitorParam.VELOCITY, velocity_min);
146 p.ScaleParticleParam(EmitorParam.VELOCITY_RND, velocity_max);
147 p.ScaleParticleParam(EmitorParam.SIZE, size);
148 p.ScaleParticleParam(EmitorParam.BIRTH_RATE, birth_rate);
149 p.ScaleParticleParam(EmitorParam.AIR_RESISTANCE, air_resistance);
150 p.ScaleParticleParam(EmitorParam.AIR_RESISTANCE_RND, air_resistance);
151 p.ScaleParticleParam(EmitorParam.LIFETIME, lifetime);
152 p.ScaleParticleParam(EmitorParam.LIFETIME_RND, lifetime_rnd);
153 }
154
155 void OnExitCalculations(Particle p, float outSpeedf)
156 {
157 float velocity_min = 1 + (outSpeedf * m_ExitSplashCoef);
158 float velocity_max = 1 + (outSpeedf * m_ExitSplashCoef);
159 float size = 1 + ( outSpeedf * m_ExitSplashCoef);
160 float birth_rate = 1 + (outSpeedf * m_ExitSplashCoef);
161
162 if (velocity_min < MIN_SCALING_PARAM)
163 velocity_min = MIN_SCALING_PARAM;
164
165 if (size < MIN_SCALING_PARAM)
166 size = MIN_SCALING_PARAM;
167
168 if (birth_rate < MIN_SCALING_PARAM)
169 birth_rate = MIN_SCALING_PARAM;
170
171 p.ScaleParticleParam(EmitorParam.VELOCITY, velocity_min);
172 p.ScaleParticleParam(EmitorParam.VELOCITY_RND, velocity_max);
173 p.ScaleParticleParam(EmitorParam.SIZE, size);
174 p.ScaleParticleParam(EmitorParam.BIRTH_RATE, birth_rate);
175 }
176
177 void OnRicochetCalculations(Particle p, float outspeedf)
178 {
179 float velocity_min = MIN_SCALING_PARAM + (m_StoppingForce * m_RicochetSplashCoef);
180 float velocity_max = MIN_SCALING_PARAM + (m_StoppingForce * m_RicochetSplashCoef);
181 float size = MIN_SCALING_PARAM + ( m_StoppingForce * m_RicochetSplashCoef);
182 float birth_rate = MIN_SCALING_PARAM + (m_StoppingForce * m_RicochetSplashCoef);
183
184 if (velocity_min < MIN_SCALING_PARAM)
185 velocity_min = MIN_SCALING_PARAM;
186
187 if (size < MIN_SCALING_PARAM)
188 size = MIN_SCALING_PARAM;
189
190 if (birth_rate < MIN_SCALING_PARAM)
191 birth_rate = MIN_SCALING_PARAM;
192
193 p.ScaleParticleParam(EmitorParam.VELOCITY, velocity_min);
194 p.ScaleParticleParam(EmitorParam.VELOCITY_RND, velocity_max);
195 p.ScaleParticleParam(EmitorParam.SIZE, size);
196 p.ScaleParticleParam(EmitorParam.BIRTH_RATE, birth_rate);
197 }
198
199 void OnEnterAngledCalculations(Particle p)
200 {
201 float velocity_min = MIN_SCALING_PARAM + (m_StoppingForce * m_EnterAngledSplashCoef);
202 float velocity_max = MIN_SCALING_PARAM + (m_StoppingForce * m_EnterAngledSplashCoef);
203 float size = MIN_SCALING_PARAM + (m_StoppingForce * m_EnterAngledSplashCoef);
204 float birth_rate = MIN_SCALING_PARAM + (m_StoppingForce * m_EnterAngledSplashCoef);
205
206 if (velocity_min < MIN_SCALING_PARAM)
207 velocity_min = MIN_SCALING_PARAM;
208
209 if (size < MIN_SCALING_PARAM)
210 size = MIN_SCALING_PARAM;
211
212 if (birth_rate < MIN_SCALING_PARAM)
213 birth_rate = MIN_SCALING_PARAM;
214
215 p.ScaleParticleParam(EmitorParam.VELOCITY, velocity_min);
216 p.ScaleParticleParam(EmitorParam.VELOCITY_RND, velocity_max);
217 p.ScaleParticleParam(EmitorParam.SIZE, size);
218 p.ScaleParticleParam(EmitorParam.BIRTH_RATE, birth_rate);
219 }
220
221 override void Event_OnStarted()
222 {
223 Particle p;
224 vector particle_orientation;
225 float outSpeedf = m_OutSpeed.Length();
226
227 ParticleManager gPM = ParticleManager.GetInstance();
228
229 if ( m_ImpactType == ImpactTypes.RICOCHET )
230 {
231 p = gPM.PlayInWorld(m_ParticleRicochet, m_Pos);
232
233 if (p)
234 {
235 particle_orientation = m_OutSpeed.VectorToAngles();
236 particle_orientation = particle_orientation + "0 -90 0";
237 p.SetOrientation(particle_orientation);
238
239 OnRicochetCalculations(p, outSpeedf);
240 }
241 }
242 else
243 {
244 p = gPM.PlayInWorld(m_ParticleEnter, m_Pos );
245
246 if (p)
247 {
248 if (m_SurfNormal != INVALID)
249 {
250 particle_orientation = m_SurfNormal.VectorToAngles();
251 particle_orientation = particle_orientation + "0 270 0";
252 }
253 else
254 {
255 particle_orientation = "0 0 0"; // This vector is in angles
256 }
257
258 p.SetOrientation(particle_orientation);
259
260 OnEnterCalculations(p);
261 }
262
263 if (outSpeedf > 0 && m_SurfNormal != INVALID)
264 {
265 p = gPM.PlayInWorld(m_ParticleExit, m_ExitPos);
266
267 if (p)
268 {
269 particle_orientation = m_OutSpeed.VectorToAngles();
270 particle_orientation = particle_orientation + "0 -90 0";
271 p.SetOrientation(particle_orientation);
272
273 OnExitCalculations(p, outSpeedf);
274 }
275 }
276 else
277 {
278 if (m_SurfNormal != INVALID)
279 {
280 vector surfNormalN = m_SurfNormal.Normalized();
281 vector inSpeedN = m_InSpeed.Normalized();
282 vector bounce_ori = surfNormalN + inSpeedN;
283
284 float dot = vector.Dot(bounce_ori, surfNormalN);
285
286 if ( dot > m_AngledEnter )
287 {
288 p = gPM.PlayInWorld(m_ParticleRicochet, m_Pos);
289
290 if (p)
291 {
292 particle_orientation = bounce_ori.VectorToAngles();
293 particle_orientation = particle_orientation + "0 -90 0";
294 p.SetOrientation(particle_orientation);
295
296 OnEnterAngledCalculations(p);
297 }
298 }
299 }
300 }
301 }
302
303 if (p)
304 {
305 SetParticle(p);
306 }
307
308
309 // Additional impact particle over long ranges. It shows players where their bullets land
310
311 if ( Type() != Hit_MeatBones )
312 {
313 vector camera_pos = GetGame().GetCurrentCameraPosition();
314 float distance = vector.Distance(camera_pos, m_Pos);
315
316 // Additional size increase by distance from camera
317 float scaling_by_distance = distance * 0.01;
318
319 // Now scale down the above size increase by player's zoom-in value
320 float current_FOV = Camera.GetCurrentFOV();
321 float config_FOV = GetDayZGame().GetUserFOVFromConfig();
322 float FOV_scale = current_FOV / config_FOV;
323 scaling_by_distance = 1 + scaling_by_distance * FOV_scale;
324
325 if (scaling_by_distance > 1.1)
326 {
327 Particle p_distant = gPM.PlayInWorld(ParticleList.IMPACT_DISTANT_DUST, m_Pos);
328
329 particle_orientation = m_SurfNormal.VectorToAngles();
330 particle_orientation[1] = particle_orientation[1] + 270;
331 p_distant.SetOrientation(particle_orientation);
332
333 p_distant.ScaleParticleParam(EmitorParam.SIZE, scaling_by_distance - 0.5);
334 p_distant.ScaleParticleParam(EmitorParam.BIRTH_RATE, scaling_by_distance * 0.1);
335 p_distant.ScaleParticleParam(EmitorParam.BIRTH_RATE_RND, scaling_by_distance * 0.1);
336 p_distant.ScaleParticleParam(EmitorParam.LIFETIME, scaling_by_distance * 0.3);
337 p_distant.ScaleParticleParam(EmitorParam.LIFETIME_RND, scaling_by_distance * 0.3);
338 }
339 }
340 }
341}
Wrapper class for managing particles through SEffectManager.
void SetParticle(Particle p)
Sets the main particle which this Effect will manage.
Definition enmath.c:7
Legacy way of using particles in the game.
Definition particle.c:7
static Particle PlayInWorld(int particle_id, vector global_pos)
Creates a particle emitter on the given position and activates it.
Definition particle.c:174
DayZGame GetDayZGame()
Definition dayzgame.c:3870
proto native CGame GetGame()
@ INVALID
Invalid file.
Definition ensystem.c:510
EmitorParam
Definition envisual.c:114
int m_ImpactType
enum ImpactTypes m_DirectHit
vector m_InSpeed
vector m_OutSpeed
string m_AmmoType
int m_ComponentIndex
ImpactTypes
string Type
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
vector m_Pos