Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
boatwatereffects.c
Go to the documentation of this file.
9
11{
12 protected const int EMITORS_FAST = 9; // emitors below this ID only play when fast enough
13
15 {
16 m_EmitorCount = 13;
17 m_SpeedSlow = 5;
18 m_SpeedMedium = 20;
19 m_SpeedFast = 40;
20
21 SetParticleState( ParticleList.BOAT_WATER_FRONT );
22 }
23
24 override protected void UpdateSpeedState(Particle ptc, float speed)
25 {
26 EBoatSpeed speedStatePast = m_SpeedState;
27
28 if (speed > m_SpeedFast)
29 m_SpeedState = EBoatSpeed.FAST;
30 else if (speed > m_SpeedMedium)
31 m_SpeedState = EBoatSpeed.MEDIUM;
32 else if (speed > m_SpeedSlow)
33 m_SpeedState = EBoatSpeed.SLOW;
34 else
35 m_SpeedState = EBoatSpeed.SLOWEST;
36
37 if (m_SpeedState == speedStatePast)
38 return;
39
40 for (int i = 0; i < m_EmitorCount; i++)
41 {
42 if (i == 5 || i == 6)
43 {
44 if (m_SpeedState <= EBoatSpeed.MEDIUM) // fast drops
45 EnableEmitor(ptc, i, false);
46 else
47 EnableEmitor(ptc, i, true);
48 }
49 else if (i == 9 || i == 10) // slow drops
50 {
51 if (m_SpeedState != EBoatSpeed.MEDIUM)
52 EnableEmitor(ptc, i, false);
53 else
54 EnableEmitor(ptc, i, true);
55 }
56 else if (i < 5 || i == 7 || i == 8) // rest of front ptc
57 {
58 if (m_SpeedState <= EBoatSpeed.SLOW)
59 EnableEmitor(ptc, i, false);
60 else
61 EnableEmitor(ptc, i, true);
62 }
63 }
64 }
65
66 override void Update(float timeSlice = 0)
67 {
68 if (m_Boat.GetCurrentGear() == 0)
69 {
70 if (IsPlaying())
71 {
72 GetParticle().SetParticleParam(EmitorParam.BIRTH_RATE, 0);
73 GetParticle().SetParticleParam(EmitorParam.BIRTH_RATE_RND, 0);
74 Stop();
75 }
76
77 return;
78 }
79
80 super.Update(timeSlice);
81
82 Particle ptc = GetParticle();
83 float lerp1, lerp2;
84
85 vector velocity = dBodyGetVelocityAt(m_Boat, m_Boat.CoordToParent(GetLocalPosition()));
86 float speed = velocity.Normalize() * 3.6; // to km/h
87 UpdateSpeedState(ptc, speed);
88
89 UpdatePosToSeaLevel(timeSlice, -0.2);
90
91 lerp1 = Math.InverseLerp(0, m_SpeedFast, speed);
92 lerp2 = Math.InverseLerp(m_SpeedMedium - 5, m_SpeedFast + 10, speed);
93
94 for (int i = 0; i < m_EmitorCount; i++)
95 {
96 if (i == 11 || i == 12) // waves
97 {
98 ptc.SetParameter(i, EmitorParam.VELOCITY, ptc.GetParameterOriginal(i, EmitorParam.VELOCITY) * lerp1);
99 }
100 else if (i < 5 || i == 7 || i == 8) // splashes
101 {
102 if (m_SpeedState > EBoatSpeed.SLOW)
103 {
104 if (GetGame().GetWaterDepth(m_Boat.CoordToParent(m_MemPointPos)) < -0.1) // when the front of the boat is above water, disable the emitor
105 EnableEmitor(ptc, i, false);
106 else
107 EnableEmitor(ptc, i, true);
108
109 ptc.SetParameter(i, EmitorParam.SIZE, ptc.GetParameterOriginal(i, EmitorParam.SIZE) * lerp2);
110 }
111 }
112 }
113 }
114}
115
117{
118 protected const int EMITORS_FAST = 5; // emitors below this ID only play when fast enough
119
121 {
122 m_EmitorCount = 10;
123 m_SpeedSlow = 25;
124 m_SpeedMedium = 50;
125 m_SpeedFast = 150;
126
127 SetParticleState( ParticleList.BOAT_WATER_BACK );
128 }
129
130 override protected void UpdateSpeedState(Particle ptc, float speed)
131 {
132 EBoatSpeed speedStatePast = m_SpeedState;
133
134 if (speed > m_SpeedFast)
136 else if (speed > m_SpeedMedium)
137 m_SpeedState = EBoatSpeed.MEDIUM;
138 else if (speed > m_SpeedSlow)
140 else
141 m_SpeedState = EBoatSpeed.SLOWEST;
142
143 if (m_SpeedState == speedStatePast)
144 return;
145
146 for (int i = 0; i < m_EmitorCount; i++)
147 {
148 if (i < EMITORS_FAST) // big splash
149 {
150 if (m_SpeedState <= EBoatSpeed.SLOW)
151 EnableEmitor(ptc, i, false);
152 else
153 EnableEmitor(ptc, i, true);
154 }
155
156 if (i >= EMITORS_FAST && i != 9)
157 {
158 if (m_SpeedState == EBoatSpeed.SLOWEST)
159 EnableEmitor(ptc, i, false);
160 else
161 EnableEmitor(ptc, i, true);
162 }
163 }
164 }
165
166 override void Update(float timeSlice = 0)
167 {
168 if (m_Boat.GetCurrentGear() == 0)
169 {
170 if (IsPlaying())
171 {
172 GetParticle().SetParticleParam(EmitorParam.BIRTH_RATE, 0);
173 GetParticle().SetParticleParam(EmitorParam.BIRTH_RATE_RND, 0);
174 Stop();
175 };
176
177 return;
178 }
179
180 super.Update(timeSlice);
181 Particle ptc = GetParticle();
182
183 float speed = m_Boat.PropellerGetAngularVelocity();
184 UpdateSpeedState(ptc, speed);
185
186 float lerp = Math.InverseLerp(0, m_SpeedFast, speed);
187
188 for (int i = 0; i < m_EmitorCount; i++)
189 {
190 if (i < EMITORS_FAST && m_SpeedState > EBoatSpeed.SLOW)
191 {
192 ptc.SetParameter(i, EmitorParam.SIZE, ptc.GetParameterOriginal(i, EmitorParam.SIZE) * lerp);
193 ptc.SetParameter(i, EmitorParam.BIRTH_RATE, ptc.GetParameterOriginal(i, EmitorParam.BIRTH_RATE) * lerp);
194 }
195 }
196 }
197}
198
200{
201 protected const int EMITORS_FAST = 3; // emitors below this ID only play when fast enough
202
204 {
205 m_EmitorCount = 5;
206 m_SpeedSlow = 5;
207 m_SpeedMedium = 20;
208 m_SpeedFast = 40;
209
210 SetParticleState( ParticleList.BOAT_WATER_SIDE );
211 }
212
213 override protected void UpdateSpeedState(Particle ptc, float speed)
214 {
215 EBoatSpeed speedStatePast = m_SpeedState;
216
217 if (speed > m_SpeedFast)
218 m_SpeedState = EBoatSpeed.FAST;
219 else if (speed > m_SpeedMedium)
220 m_SpeedState = EBoatSpeed.MEDIUM;
221 else if (speed > m_SpeedSlow)
222 m_SpeedState = EBoatSpeed.SLOW;
223 else
224 m_SpeedState = EBoatSpeed.SLOWEST;
225
226 if (m_SpeedState == speedStatePast)
227 return;
228
229 for (int i = 0; i < m_EmitorCount; i++)
230 {
231 if (i < EMITORS_FAST) // splashes
232 {
233 if (m_SpeedState <= EBoatSpeed.SLOW)
234 EnableEmitor(ptc, i, false);
235 else
236 EnableEmitor(ptc, i, true);
237 }
238 }
239 }
240
241 override void Update(float timeSlice = 0)
242 {
243 super.Update(timeSlice);
244
245 Particle ptc = GetParticle();
246
247 vector velocity = dBodyGetVelocityAt(m_Boat, m_Boat.CoordToParent(GetLocalPosition()));
248 float speed = velocity.Normalize() * 3.6; // to km/h
249 UpdateSpeedState(ptc, speed);
250
251 UpdatePosToSeaLevel(timeSlice, -0.2);
252
253 float lerp = Math.InverseLerp(0, m_SpeedFast, speed);
254
255 for (int i = 0; i < m_EmitorCount; i++)
256 {
257 if (i < EMITORS_FAST) // splashes
258 {
259 if (m_SpeedState > EBoatSpeed.SLOW)
260 ptc.SetParameter(i, EmitorParam.SIZE, ptc.GetParameterOriginal(i, EmitorParam.SIZE) * lerp);
261 }
262 else // waves
263 {
264 ptc.SetParameter(i, EmitorParam.SIZE, ptc.GetParameterOriginal(i, EmitorParam.SIZE) * lerp);
265 ptc.SetParameter(i, EmitorParam.VELOCITY, ptc.GetParameterOriginal(i, EmitorParam.VELOCITY) * lerp);
266 }
267 }
268 }
269}
270
272{
273 const float POS_UPDATE_THROTTLE = 0.2; // seconds, controls how often can boat update somewhat expensive particle local reposition
274
275 protected int m_EmitorCount;
276 protected int m_SpeedSlow;
277 protected int m_SpeedMedium;
278 protected int m_SpeedFast;
279 protected float m_PosUpdateTimer;
280
284
285 override void AttachTo(Object obj, vector local_pos = "0 0 0", vector local_ori = "0 0 0", bool force_rotation_to_world = false)
286 {
287 m_Boat = BoatScript.Cast(obj);
288 m_MemPointPos = local_pos;
289 super.AttachTo(obj, local_pos, local_ori, force_rotation_to_world);
290 }
291
292 void SetParticleState(int state)
293 {
294 bool was_playing = IsPlaying();
295
296 Stop();
297
298 SetParticleID(state);
299
300 if (was_playing)
301 {
302 Start(); // resume effect
303 }
304 }
305
306 protected void EnableEmitor(Particle ptc, int id, bool enable)
307 {
308 if (enable)
309 {
310 ptc.SetParameter(id, EmitorParam.BIRTH_RATE, ptc.GetParameterOriginal(id, EmitorParam.BIRTH_RATE));
311 ptc.SetParameter(id, EmitorParam.BIRTH_RATE_RND, ptc.GetParameterOriginal(id, EmitorParam.BIRTH_RATE_RND));
312 }
313 else
314 {
315 ptc.SetParameter(id, EmitorParam.BIRTH_RATE, 0);
316 ptc.SetParameter(id, EmitorParam.BIRTH_RATE_RND, 0);
317 }
318 }
319
320 // Update on state change
321 protected void UpdateSpeedState(Particle ptc, float speed)
322 {}
323
324 // Update runs every frame
325 void Update(float timeSlice = 0)
326 {
327 if (!IsPlaying())
328 {
329 m_SpeedState = EBoatSpeed.UNSET; // reinit
330 Start();
331 }
332 };
333
334 // Adjust position to sea level
335 protected void UpdatePosToSeaLevel(float timeSlice = 0, float surfaceOffset = 0)
336 {
337 m_PosUpdateTimer += timeSlice;
338 if (m_PosUpdateTimer > POS_UPDATE_THROTTLE)
339 {
341
342 vector posAdjusted = m_Boat.CoordToParent(m_MemPointPos);
343 posAdjusted[1] = GetGame().SurfaceGetSeaLevel() + surfaceOffset;
344 posAdjusted = m_Boat.CoordToLocal(posAdjusted);
345 SetCurrentLocalPosition(posAdjusted);
346 }
347 }
348}
EBoatSpeed
@ MEDIUM
@ SLOWEST
@ SLOW
@ UNSET
@ FAST
void EffectBoatWaterFront()
void EffectBoatWaterSide()
enum EBoatSpeed EMITORS_FAST
proto native float SurfaceGetSeaLevel()
void UpdateSpeedState(Particle ptc, float speed)
override void Update(float timeSlice=0)
void UpdatePosToSeaLevel(float timeSlice=0, float surfaceOffset=0)
void UpdateSpeedState(Particle ptc, float speed)
void EnableEmitor(Particle ptc, int id, bool enable)
void SetParticleState(int state)
void Update(float timeSlice=0)
override void AttachTo(Object obj, vector local_pos="0 0 0", vector local_ori="0 0 0", bool force_rotation_to_world=false)
Wrapper class for managing particles through SEffectManager.
override void Stop()
Stops all elements this effect consists of.
Particle GetParticle()
Gets the main particle which this Effect is managing.
override void Start()
Plays all elements this effect consists of.
void SetParticleID(int id)
Sets the id of the particle to be used.
override void SetCurrentLocalPosition(vector pos, bool updateCached=true)
Set the current local position of the managed Particle.
Definition enmath.c:7
Legacy way of using particles in the game.
Definition particle.c:7
bool IsPlaying()
Returns true when the Effect is playing, false otherwise.
Definition effect.c:197
vector GetLocalPosition()
Get the local position of the Effect.
Definition effect.c:513
proto native CGame GetGame()
EmitorParam
Definition envisual.c:114
proto native vector dBodyGetVelocityAt(notnull IEntity body, vector globalpos)