DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
BoatWaterEffects.c
См. документацию.
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
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 {
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
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 {
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
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;
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
Определения BoatWaterEffects.c:2
@ SLOWEST
Определения BoatWaterEffects.c:4
@ SLOW
Определения BoatWaterEffects.c:5
@ UNSET
Определения BoatWaterEffects.c:3
@ FAST
Определения BoatWaterEffects.c:7
void EffectBoatWaterFront()
Определения BoatWaterEffects.c:14
void EffectBoatWaterSide()
Определения BoatWaterEffects.c:203
enum EBoatSpeed EMITORS_FAST
@ MEDIUM
Определения EStatLevels.c:5
bool IsPlaying()
Returns true when the Effect is playing, false otherwise.
Определения Effect.c:195
vector GetLocalPosition()
Get the local position of the Effect.
Определения Effect.c:488
Определения BoatScript.c:31
proto native float SurfaceGetSeaLevel()
void UpdateSpeedState(Particle ptc, float speed)
Определения BoatWaterEffects.c:130
void EffectBoatWaterBack()
Определения BoatWaterEffects.c:120
const int EMITORS_FAST
Определения BoatWaterEffects.c:118
override void Update(float timeSlice=0)
Определения BoatWaterEffects.c:166
vector m_MemPointPos
Определения BoatWaterEffects.c:283
BoatScript m_Boat
Определения BoatWaterEffects.c:282
void UpdatePosToSeaLevel(float timeSlice=0, float surfaceOffset=0)
Определения BoatWaterEffects.c:335
int m_EmitorCount
Определения BoatWaterEffects.c:275
EBoatSpeed m_SpeedState
Определения BoatWaterEffects.c:281
void UpdateSpeedState(Particle ptc, float speed)
Определения BoatWaterEffects.c:321
float m_PosUpdateTimer
Определения BoatWaterEffects.c:279
const float POS_UPDATE_THROTTLE
Определения BoatWaterEffects.c:273
int m_SpeedFast
Определения BoatWaterEffects.c:278
void EnableEmitor(Particle ptc, int id, bool enable)
Определения BoatWaterEffects.c:306
void SetParticleState(int state)
Определения BoatWaterEffects.c:292
int m_SpeedSlow
Определения BoatWaterEffects.c:276
void Update(float timeSlice=0)
Определения BoatWaterEffects.c:325
int m_SpeedMedium
Определения BoatWaterEffects.c:277
override void AttachTo(Object obj, vector local_pos="0 0 0", vector local_ori="0 0 0", bool force_rotation_to_world=false)
Определения BoatWaterEffects.c:285
override void Stop()
Stops all elements this effect consists of.
Определения EffectParticle.c:204
Particle GetParticle()
Gets the main particle which this Effect is managing.
Определения EffectParticle.c:162
override void Start()
Plays all elements this effect consists of.
Определения EffectParticle.c:181
void SetParticleID(int id)
Sets the id of the particle to be used.
Определения EffectParticle.c:303
void EffectParticle()
ctor
Определения EffectParticle.c:34
override void SetCurrentLocalPosition(vector pos, bool updateCached=true)
Set the current local position of the managed Particle.
Определения EffectParticle.c:411
Определения EnMath.c:7
Определения ObjectTyped.c:2
float GetParameterOriginal(int emitter, int parameter)
Определения Particle.c:663
void SetParticleParam(int parameter_id, float value)
Set the value of a parameter of all emitors in the particle.
Определения Particle.c:611
void SetParameter(int emitter, int parameter, float value)
Set the value of a parameter of an emitor in the particle.
Определения Particle.c:625
Legacy way of using particles in the game.
Определения Particle.c:7
static const int BOAT_WATER_SIDE
Определения ParticleList.c:286
static const int BOAT_WATER_FRONT
Определения ParticleList.c:284
static const int BOAT_WATER_BACK
Определения ParticleList.c:285
Определения ParticleList.c:12
proto float Normalize()
Normalizes vector. Returns length.
Определения EnConvert.c:106
proto native CGame GetGame()
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...
EmitorParam
Определения EnVisual.c:114
proto native vector dBodyGetVelocityAt(notnull IEntity body, vector globalpos)
proto native volatile void Update()
Определения PlayerSoundManager.c:125