author | truebrain |
Mon, 30 Jun 2008 13:36:06 +0000 | |
branch | noai |
changeset 11100 | b960288098b9 |
parent 10829 | 8a0ec0f0f928 |
permissions | -rw-r--r-- |
10294 | 1 |
/* $Id$ */ |
2 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10294
diff
changeset
|
3 |
/** @file effectvehicle.cpp Implementation of everything generic to vehicles. */ |
10294 | 4 |
|
5 |
#include "stdafx.h" |
|
6 |
#include "openttd.h" |
|
7 |
#include "road_map.h" |
|
8 |
#include "roadveh.h" |
|
9 |
#include "ship.h" |
|
10 |
#include "spritecache.h" |
|
11 |
#include "tile_cmd.h" |
|
12 |
#include "landscape.h" |
|
13 |
#include "timetable.h" |
|
14 |
#include "viewport_func.h" |
|
15 |
#include "gfx_func.h" |
|
16 |
#include "news_func.h" |
|
17 |
#include "command_func.h" |
|
18 |
#include "saveload.h" |
|
19 |
#include "player_func.h" |
|
20 |
#include "debug.h" |
|
21 |
#include "vehicle_gui.h" |
|
22 |
#include "rail_type.h" |
|
23 |
#include "train.h" |
|
24 |
#include "aircraft.h" |
|
25 |
#include "industry_map.h" |
|
26 |
#include "station_map.h" |
|
27 |
#include "water_map.h" |
|
28 |
#include "yapf/yapf.h" |
|
29 |
#include "newgrf_callbacks.h" |
|
30 |
#include "newgrf_engine.h" |
|
31 |
#include "newgrf_sound.h" |
|
32 |
#include "group.h" |
|
33 |
#include "order_func.h" |
|
34 |
#include "strings_func.h" |
|
35 |
#include "zoom_func.h" |
|
36 |
#include "functions.h" |
|
37 |
#include "date_func.h" |
|
38 |
#include "window_func.h" |
|
39 |
#include "vehicle_func.h" |
|
40 |
#include "signal_func.h" |
|
41 |
#include "sound_func.h" |
|
42 |
#include "variables.h" |
|
43 |
#include "autoreplace_func.h" |
|
44 |
#include "autoreplace_gui.h" |
|
45 |
#include "string_func.h" |
|
46 |
#include "settings_type.h" |
|
47 |
#include "oldpool_func.h" |
|
48 |
#include "depot_map.h" |
|
49 |
#include "animated_tile_func.h" |
|
50 |
#include "effectvehicle_base.h" |
|
51 |
#include "effectvehicle_func.h" |
|
52 |
||
53 |
#include "table/sprites.h" |
|
54 |
#include "table/strings.h" |
|
55 |
||
56 |
static void ChimneySmokeInit(Vehicle *v) |
|
57 |
{ |
|
58 |
uint32 r = Random(); |
|
59 |
v->cur_image = SPR_CHIMNEY_SMOKE_0 + GB(r, 0, 3); |
|
60 |
v->progress = GB(r, 16, 3); |
|
61 |
} |
|
62 |
||
63 |
static void ChimneySmokeTick(Vehicle *v) |
|
64 |
{ |
|
65 |
if (v->progress > 0) { |
|
66 |
v->progress--; |
|
67 |
} else { |
|
68 |
BeginVehicleMove(v); |
|
69 |
||
70 |
TileIndex tile = TileVirtXY(v->x_pos, v->y_pos); |
|
71 |
if (!IsTileType(tile, MP_INDUSTRY)) { |
|
72 |
EndVehicleMove(v); |
|
73 |
delete v; |
|
74 |
return; |
|
75 |
} |
|
76 |
||
77 |
if (v->cur_image != SPR_CHIMNEY_SMOKE_7) { |
|
78 |
v->cur_image++; |
|
79 |
} else { |
|
80 |
v->cur_image = SPR_CHIMNEY_SMOKE_0; |
|
81 |
} |
|
82 |
v->progress = 7; |
|
83 |
VehiclePositionChanged(v); |
|
84 |
EndVehicleMove(v); |
|
85 |
} |
|
86 |
} |
|
87 |
||
88 |
static void SteamSmokeInit(Vehicle *v) |
|
89 |
{ |
|
90 |
v->cur_image = SPR_STEAM_SMOKE_0; |
|
91 |
v->progress = 12; |
|
92 |
} |
|
93 |
||
94 |
static void SteamSmokeTick(Vehicle *v) |
|
95 |
{ |
|
96 |
bool moved = false; |
|
97 |
||
98 |
BeginVehicleMove(v); |
|
99 |
||
100 |
v->progress++; |
|
101 |
||
102 |
if ((v->progress & 7) == 0) { |
|
103 |
v->z_pos++; |
|
104 |
moved = true; |
|
105 |
} |
|
106 |
||
107 |
if ((v->progress & 0xF) == 4) { |
|
108 |
if (v->cur_image != SPR_STEAM_SMOKE_4) { |
|
109 |
v->cur_image++; |
|
110 |
} else { |
|
111 |
EndVehicleMove(v); |
|
112 |
delete v; |
|
113 |
return; |
|
114 |
} |
|
115 |
moved = true; |
|
116 |
} |
|
117 |
||
118 |
if (moved) { |
|
119 |
VehiclePositionChanged(v); |
|
120 |
EndVehicleMove(v); |
|
121 |
} |
|
122 |
} |
|
123 |
||
124 |
static void DieselSmokeInit(Vehicle *v) |
|
125 |
{ |
|
126 |
v->cur_image = SPR_DIESEL_SMOKE_0; |
|
127 |
v->progress = 0; |
|
128 |
} |
|
129 |
||
130 |
static void DieselSmokeTick(Vehicle *v) |
|
131 |
{ |
|
132 |
v->progress++; |
|
133 |
||
134 |
if ((v->progress & 3) == 0) { |
|
135 |
BeginVehicleMove(v); |
|
136 |
v->z_pos++; |
|
137 |
VehiclePositionChanged(v); |
|
138 |
EndVehicleMove(v); |
|
139 |
} else if ((v->progress & 7) == 1) { |
|
140 |
BeginVehicleMove(v); |
|
141 |
if (v->cur_image != SPR_DIESEL_SMOKE_5) { |
|
142 |
v->cur_image++; |
|
143 |
VehiclePositionChanged(v); |
|
144 |
EndVehicleMove(v); |
|
145 |
} else { |
|
146 |
EndVehicleMove(v); |
|
147 |
delete v; |
|
148 |
} |
|
149 |
} |
|
150 |
} |
|
151 |
||
152 |
static void ElectricSparkInit(Vehicle *v) |
|
153 |
{ |
|
154 |
v->cur_image = SPR_ELECTRIC_SPARK_0; |
|
155 |
v->progress = 1; |
|
156 |
} |
|
157 |
||
158 |
static void ElectricSparkTick(Vehicle *v) |
|
159 |
{ |
|
160 |
if (v->progress < 2) { |
|
161 |
v->progress++; |
|
162 |
} else { |
|
163 |
v->progress = 0; |
|
164 |
BeginVehicleMove(v); |
|
165 |
if (v->cur_image != SPR_ELECTRIC_SPARK_5) { |
|
166 |
v->cur_image++; |
|
167 |
VehiclePositionChanged(v); |
|
168 |
EndVehicleMove(v); |
|
169 |
} else { |
|
170 |
EndVehicleMove(v); |
|
171 |
delete v; |
|
172 |
} |
|
173 |
} |
|
174 |
} |
|
175 |
||
176 |
static void SmokeInit(Vehicle *v) |
|
177 |
{ |
|
178 |
v->cur_image = SPR_SMOKE_0; |
|
179 |
v->progress = 12; |
|
180 |
} |
|
181 |
||
182 |
static void SmokeTick(Vehicle *v) |
|
183 |
{ |
|
184 |
bool moved = false; |
|
185 |
||
186 |
BeginVehicleMove(v); |
|
187 |
||
188 |
v->progress++; |
|
189 |
||
190 |
if ((v->progress & 3) == 0) { |
|
191 |
v->z_pos++; |
|
192 |
moved = true; |
|
193 |
} |
|
194 |
||
195 |
if ((v->progress & 0xF) == 4) { |
|
196 |
if (v->cur_image != SPR_SMOKE_4) { |
|
197 |
v->cur_image++; |
|
198 |
} else { |
|
199 |
EndVehicleMove(v); |
|
200 |
delete v; |
|
201 |
return; |
|
202 |
} |
|
203 |
moved = true; |
|
204 |
} |
|
205 |
||
206 |
if (moved) { |
|
207 |
VehiclePositionChanged(v); |
|
208 |
EndVehicleMove(v); |
|
209 |
} |
|
210 |
} |
|
211 |
||
212 |
static void ExplosionLargeInit(Vehicle *v) |
|
213 |
{ |
|
214 |
v->cur_image = SPR_EXPLOSION_LARGE_0; |
|
215 |
v->progress = 0; |
|
216 |
} |
|
217 |
||
218 |
static void ExplosionLargeTick(Vehicle *v) |
|
219 |
{ |
|
220 |
v->progress++; |
|
221 |
if ((v->progress & 3) == 0) { |
|
222 |
BeginVehicleMove(v); |
|
223 |
if (v->cur_image != SPR_EXPLOSION_LARGE_F) { |
|
224 |
v->cur_image++; |
|
225 |
VehiclePositionChanged(v); |
|
226 |
EndVehicleMove(v); |
|
227 |
} else { |
|
228 |
EndVehicleMove(v); |
|
229 |
delete v; |
|
230 |
} |
|
231 |
} |
|
232 |
} |
|
233 |
||
234 |
static void BreakdownSmokeInit(Vehicle *v) |
|
235 |
{ |
|
236 |
v->cur_image = SPR_BREAKDOWN_SMOKE_0; |
|
237 |
v->progress = 0; |
|
238 |
} |
|
239 |
||
240 |
static void BreakdownSmokeTick(Vehicle *v) |
|
241 |
{ |
|
242 |
v->progress++; |
|
243 |
if ((v->progress & 7) == 0) { |
|
244 |
BeginVehicleMove(v); |
|
245 |
if (v->cur_image != SPR_BREAKDOWN_SMOKE_3) { |
|
246 |
v->cur_image++; |
|
247 |
} else { |
|
248 |
v->cur_image = SPR_BREAKDOWN_SMOKE_0; |
|
249 |
} |
|
250 |
VehiclePositionChanged(v); |
|
251 |
EndVehicleMove(v); |
|
252 |
} |
|
253 |
||
254 |
v->u.effect.animation_state--; |
|
255 |
if (v->u.effect.animation_state == 0) { |
|
256 |
BeginVehicleMove(v); |
|
257 |
EndVehicleMove(v); |
|
258 |
delete v; |
|
259 |
} |
|
260 |
} |
|
261 |
||
262 |
static void ExplosionSmallInit(Vehicle *v) |
|
263 |
{ |
|
264 |
v->cur_image = SPR_EXPLOSION_SMALL_0; |
|
265 |
v->progress = 0; |
|
266 |
} |
|
267 |
||
268 |
static void ExplosionSmallTick(Vehicle *v) |
|
269 |
{ |
|
270 |
v->progress++; |
|
271 |
if ((v->progress & 3) == 0) { |
|
272 |
BeginVehicleMove(v); |
|
273 |
if (v->cur_image != SPR_EXPLOSION_SMALL_B) { |
|
274 |
v->cur_image++; |
|
275 |
VehiclePositionChanged(v); |
|
276 |
EndVehicleMove(v); |
|
277 |
} else { |
|
278 |
EndVehicleMove(v); |
|
279 |
delete v; |
|
280 |
} |
|
281 |
} |
|
282 |
} |
|
283 |
||
284 |
static void BulldozerInit(Vehicle *v) |
|
285 |
{ |
|
286 |
v->cur_image = SPR_BULLDOZER_NE; |
|
287 |
v->progress = 0; |
|
288 |
v->u.effect.animation_state = 0; |
|
289 |
v->u.effect.animation_substate = 0; |
|
290 |
} |
|
291 |
||
292 |
struct BulldozerMovement { |
|
293 |
byte direction:2; |
|
294 |
byte image:2; |
|
295 |
byte duration:3; |
|
296 |
}; |
|
297 |
||
298 |
static const BulldozerMovement _bulldozer_movement[] = { |
|
299 |
{ 0, 0, 4 }, |
|
300 |
{ 3, 3, 4 }, |
|
301 |
{ 2, 2, 7 }, |
|
302 |
{ 0, 2, 7 }, |
|
303 |
{ 1, 1, 3 }, |
|
304 |
{ 2, 2, 7 }, |
|
305 |
{ 0, 2, 7 }, |
|
306 |
{ 1, 1, 3 }, |
|
307 |
{ 2, 2, 7 }, |
|
308 |
{ 0, 2, 7 }, |
|
309 |
{ 3, 3, 6 }, |
|
310 |
{ 2, 2, 6 }, |
|
311 |
{ 1, 1, 7 }, |
|
312 |
{ 3, 1, 7 }, |
|
313 |
{ 0, 0, 3 }, |
|
314 |
{ 1, 1, 7 }, |
|
315 |
{ 3, 1, 7 }, |
|
316 |
{ 0, 0, 3 }, |
|
317 |
{ 1, 1, 7 }, |
|
318 |
{ 3, 1, 7 } |
|
319 |
}; |
|
320 |
||
321 |
static const struct { |
|
322 |
int8 x; |
|
323 |
int8 y; |
|
324 |
} _inc_by_dir[] = { |
|
325 |
{ -1, 0 }, |
|
326 |
{ 0, 1 }, |
|
327 |
{ 1, 0 }, |
|
328 |
{ 0, -1 } |
|
329 |
}; |
|
330 |
||
331 |
static void BulldozerTick(Vehicle *v) |
|
332 |
{ |
|
333 |
v->progress++; |
|
334 |
if ((v->progress & 7) == 0) { |
|
335 |
const BulldozerMovement* b = &_bulldozer_movement[v->u.effect.animation_state]; |
|
336 |
||
337 |
BeginVehicleMove(v); |
|
338 |
||
339 |
v->cur_image = SPR_BULLDOZER_NE + b->image; |
|
340 |
||
341 |
v->x_pos += _inc_by_dir[b->direction].x; |
|
342 |
v->y_pos += _inc_by_dir[b->direction].y; |
|
343 |
||
344 |
v->u.effect.animation_substate++; |
|
345 |
if (v->u.effect.animation_substate >= b->duration) { |
|
346 |
v->u.effect.animation_substate = 0; |
|
347 |
v->u.effect.animation_state++; |
|
348 |
if (v->u.effect.animation_state == lengthof(_bulldozer_movement)) { |
|
349 |
EndVehicleMove(v); |
|
350 |
delete v; |
|
351 |
return; |
|
352 |
} |
|
353 |
} |
|
354 |
VehiclePositionChanged(v); |
|
355 |
EndVehicleMove(v); |
|
356 |
} |
|
357 |
} |
|
358 |
||
359 |
static void BubbleInit(Vehicle *v) |
|
360 |
{ |
|
361 |
v->cur_image = SPR_BUBBLE_GENERATE_0; |
|
362 |
v->spritenum = 0; |
|
363 |
v->progress = 0; |
|
364 |
} |
|
365 |
||
366 |
struct BubbleMovement { |
|
367 |
int8 x:4; |
|
368 |
int8 y:4; |
|
369 |
int8 z:4; |
|
370 |
byte image:4; |
|
371 |
}; |
|
372 |
||
373 |
#define MK(x, y, z, i) { x, y, z, i } |
|
374 |
#define ME(i) { i, 4, 0, 0 } |
|
375 |
||
376 |
static const BubbleMovement _bubble_float_sw[] = { |
|
377 |
MK(0, 0, 1, 0), |
|
378 |
MK(1, 0, 1, 1), |
|
379 |
MK(0, 0, 1, 0), |
|
380 |
MK(1, 0, 1, 2), |
|
381 |
ME(1) |
|
382 |
}; |
|
383 |
||
384 |
||
385 |
static const BubbleMovement _bubble_float_ne[] = { |
|
386 |
MK( 0, 0, 1, 0), |
|
387 |
MK(-1, 0, 1, 1), |
|
388 |
MK( 0, 0, 1, 0), |
|
389 |
MK(-1, 0, 1, 2), |
|
390 |
ME(1) |
|
391 |
}; |
|
392 |
||
393 |
static const BubbleMovement _bubble_float_se[] = { |
|
394 |
MK(0, 0, 1, 0), |
|
395 |
MK(0, 1, 1, 1), |
|
396 |
MK(0, 0, 1, 0), |
|
397 |
MK(0, 1, 1, 2), |
|
398 |
ME(1) |
|
399 |
}; |
|
400 |
||
401 |
static const BubbleMovement _bubble_float_nw[] = { |
|
402 |
MK(0, 0, 1, 0), |
|
403 |
MK(0, -1, 1, 1), |
|
404 |
MK(0, 0, 1, 0), |
|
405 |
MK(0, -1, 1, 2), |
|
406 |
ME(1) |
|
407 |
}; |
|
408 |
||
409 |
static const BubbleMovement _bubble_burst[] = { |
|
410 |
MK(0, 0, 1, 2), |
|
411 |
MK(0, 0, 1, 7), |
|
412 |
MK(0, 0, 1, 8), |
|
413 |
MK(0, 0, 1, 9), |
|
414 |
ME(0) |
|
415 |
}; |
|
416 |
||
417 |
static const BubbleMovement _bubble_absorb[] = { |
|
418 |
MK(0, 0, 1, 0), |
|
419 |
MK(0, 0, 1, 1), |
|
420 |
MK(0, 0, 1, 0), |
|
421 |
MK(0, 0, 1, 2), |
|
422 |
MK(0, 0, 1, 0), |
|
423 |
MK(0, 0, 1, 1), |
|
424 |
MK(0, 0, 1, 0), |
|
425 |
MK(0, 0, 1, 2), |
|
426 |
MK(0, 0, 1, 0), |
|
427 |
MK(0, 0, 1, 1), |
|
428 |
MK(0, 0, 1, 0), |
|
429 |
MK(0, 0, 1, 2), |
|
430 |
MK(0, 0, 1, 0), |
|
431 |
MK(0, 0, 1, 1), |
|
432 |
MK(0, 0, 1, 0), |
|
433 |
MK(0, 0, 1, 2), |
|
434 |
MK(0, 0, 1, 0), |
|
435 |
MK(0, 0, 1, 1), |
|
436 |
MK(0, 0, 1, 0), |
|
437 |
MK(0, 0, 1, 2), |
|
438 |
MK(0, 0, 1, 0), |
|
439 |
MK(0, 0, 1, 1), |
|
440 |
MK(0, 0, 1, 0), |
|
441 |
MK(0, 0, 1, 2), |
|
442 |
MK(0, 0, 1, 0), |
|
443 |
MK(0, 0, 1, 1), |
|
444 |
MK(0, 0, 1, 0), |
|
445 |
MK(0, 0, 1, 2), |
|
446 |
MK(0, 0, 1, 0), |
|
447 |
MK(0, 0, 1, 1), |
|
448 |
MK(0, 0, 1, 0), |
|
449 |
MK(0, 0, 1, 2), |
|
450 |
MK(0, 0, 1, 0), |
|
451 |
MK(0, 0, 1, 1), |
|
452 |
MK(0, 0, 1, 0), |
|
453 |
MK(0, 0, 1, 2), |
|
454 |
MK(0, 0, 1, 0), |
|
455 |
MK(0, 0, 1, 1), |
|
456 |
MK(0, 0, 1, 0), |
|
457 |
MK(0, 0, 1, 2), |
|
458 |
MK(0, 0, 1, 0), |
|
459 |
MK(0, 0, 1, 1), |
|
460 |
MK(0, 0, 1, 0), |
|
461 |
MK(0, 0, 1, 2), |
|
462 |
MK(0, 0, 1, 0), |
|
463 |
MK(0, 0, 1, 1), |
|
464 |
MK(0, 0, 1, 0), |
|
465 |
MK(0, 0, 1, 2), |
|
466 |
MK(0, 0, 1, 0), |
|
467 |
MK(0, 0, 1, 1), |
|
468 |
MK(0, 0, 1, 0), |
|
469 |
MK(0, 0, 1, 2), |
|
470 |
MK(0, 0, 1, 0), |
|
471 |
MK(0, 0, 1, 1), |
|
472 |
MK(0, 0, 1, 0), |
|
473 |
MK(0, 0, 1, 2), |
|
474 |
MK(0, 0, 1, 0), |
|
475 |
MK(0, 0, 1, 1), |
|
476 |
MK(0, 0, 1, 0), |
|
477 |
MK(0, 0, 1, 2), |
|
478 |
MK(0, 0, 1, 0), |
|
479 |
MK(0, 0, 1, 1), |
|
480 |
MK(2, 1, 3, 0), |
|
481 |
MK(1, 1, 3, 1), |
|
482 |
MK(2, 1, 3, 0), |
|
483 |
MK(1, 1, 3, 2), |
|
484 |
MK(2, 1, 3, 0), |
|
485 |
MK(1, 1, 3, 1), |
|
486 |
MK(2, 1, 3, 0), |
|
487 |
MK(1, 0, 1, 2), |
|
488 |
MK(0, 0, 1, 0), |
|
489 |
MK(1, 0, 1, 1), |
|
490 |
MK(0, 0, 1, 0), |
|
491 |
MK(1, 0, 1, 2), |
|
492 |
MK(0, 0, 1, 0), |
|
493 |
MK(1, 0, 1, 1), |
|
494 |
MK(0, 0, 1, 0), |
|
495 |
MK(1, 0, 1, 2), |
|
496 |
ME(2), |
|
497 |
MK(0, 0, 0, 0xA), |
|
498 |
MK(0, 0, 0, 0xB), |
|
499 |
MK(0, 0, 0, 0xC), |
|
500 |
MK(0, 0, 0, 0xD), |
|
501 |
MK(0, 0, 0, 0xE), |
|
502 |
ME(0) |
|
503 |
}; |
|
504 |
#undef ME |
|
505 |
#undef MK |
|
506 |
||
507 |
static const BubbleMovement * const _bubble_movement[] = { |
|
508 |
_bubble_float_sw, |
|
509 |
_bubble_float_ne, |
|
510 |
_bubble_float_se, |
|
511 |
_bubble_float_nw, |
|
512 |
_bubble_burst, |
|
513 |
_bubble_absorb, |
|
514 |
}; |
|
515 |
||
516 |
static void BubbleTick(Vehicle *v) |
|
517 |
{ |
|
518 |
/* |
|
519 |
* Warning: those effects can NOT use Random(), and have to use |
|
520 |
* InteractiveRandom(), because somehow someone forgot to save |
|
521 |
* spritenum to the savegame, and so it will cause desyncs in |
|
522 |
* multiplayer!! (that is: in ToyLand) |
|
523 |
*/ |
|
524 |
uint et; |
|
525 |
||
526 |
v->progress++; |
|
527 |
if ((v->progress & 3) != 0) return; |
|
528 |
||
529 |
BeginVehicleMove(v); |
|
530 |
||
531 |
if (v->spritenum == 0) { |
|
532 |
v->cur_image++; |
|
533 |
if (v->cur_image < SPR_BUBBLE_GENERATE_3) { |
|
534 |
VehiclePositionChanged(v); |
|
535 |
EndVehicleMove(v); |
|
536 |
return; |
|
537 |
} |
|
538 |
if (v->u.effect.animation_substate != 0) { |
|
539 |
v->spritenum = GB(InteractiveRandom(), 0, 2) + 1; |
|
540 |
} else { |
|
541 |
v->spritenum = 6; |
|
542 |
} |
|
543 |
et = 0; |
|
544 |
} else { |
|
545 |
et = v->engine_type + 1; |
|
546 |
} |
|
547 |
||
548 |
const BubbleMovement *b = &_bubble_movement[v->spritenum - 1][et]; |
|
549 |
||
550 |
if (b->y == 4 && b->x == 0) { |
|
551 |
EndVehicleMove(v); |
|
552 |
delete v; |
|
553 |
return; |
|
554 |
} |
|
555 |
||
556 |
if (b->y == 4 && b->x == 1) { |
|
557 |
if (v->z_pos > 180 || Chance16I(1, 96, InteractiveRandom())) { |
|
558 |
v->spritenum = 5; |
|
559 |
SndPlayVehicleFx(SND_2F_POP, v); |
|
560 |
} |
|
561 |
et = 0; |
|
562 |
} |
|
563 |
||
564 |
if (b->y == 4 && b->x == 2) { |
|
565 |
TileIndex tile; |
|
566 |
||
567 |
et++; |
|
568 |
SndPlayVehicleFx(SND_31_EXTRACT, v); |
|
569 |
||
570 |
tile = TileVirtXY(v->x_pos, v->y_pos); |
|
571 |
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryGfx(tile) == GFX_BUBBLE_CATCHER) AddAnimatedTile(tile); |
|
572 |
} |
|
573 |
||
574 |
v->engine_type = et; |
|
575 |
b = &_bubble_movement[v->spritenum - 1][et]; |
|
576 |
||
577 |
v->x_pos += b->x; |
|
578 |
v->y_pos += b->y; |
|
579 |
v->z_pos += b->z; |
|
580 |
v->cur_image = SPR_BUBBLE_0 + b->image; |
|
581 |
||
582 |
VehiclePositionChanged(v); |
|
583 |
EndVehicleMove(v); |
|
584 |
} |
|
585 |
||
586 |
||
587 |
typedef void EffectInitProc(Vehicle *v); |
|
588 |
typedef void EffectTickProc(Vehicle *v); |
|
589 |
||
590 |
static EffectInitProc * const _effect_init_procs[] = { |
|
591 |
ChimneySmokeInit, |
|
592 |
SteamSmokeInit, |
|
593 |
DieselSmokeInit, |
|
594 |
ElectricSparkInit, |
|
595 |
SmokeInit, |
|
596 |
ExplosionLargeInit, |
|
597 |
BreakdownSmokeInit, |
|
598 |
ExplosionSmallInit, |
|
599 |
BulldozerInit, |
|
600 |
BubbleInit, |
|
601 |
}; |
|
602 |
||
603 |
static EffectTickProc * const _effect_tick_procs[] = { |
|
604 |
ChimneySmokeTick, |
|
605 |
SteamSmokeTick, |
|
606 |
DieselSmokeTick, |
|
607 |
ElectricSparkTick, |
|
608 |
SmokeTick, |
|
609 |
ExplosionLargeTick, |
|
610 |
BreakdownSmokeTick, |
|
611 |
ExplosionSmallTick, |
|
612 |
BulldozerTick, |
|
613 |
BubbleTick, |
|
614 |
}; |
|
615 |
||
616 |
||
617 |
Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicleType type) |
|
618 |
{ |
|
619 |
Vehicle *v = new EffectVehicle(); |
|
620 |
if (v != NULL) { |
|
621 |
v->subtype = type; |
|
622 |
v->x_pos = x; |
|
623 |
v->y_pos = y; |
|
624 |
v->z_pos = z; |
|
625 |
v->tile = 0; |
|
626 |
v->UpdateDeltaXY(INVALID_DIR); |
|
627 |
v->vehstatus = VS_UNCLICKABLE; |
|
628 |
||
629 |
_effect_init_procs[type](v); |
|
630 |
||
631 |
VehiclePositionChanged(v); |
|
632 |
BeginVehicleMove(v); |
|
633 |
EndVehicleMove(v); |
|
634 |
} |
|
635 |
return v; |
|
636 |
} |
|
637 |
||
638 |
Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type) |
|
639 |
{ |
|
640 |
int safe_x = Clamp(x, 0, MapMaxX() * TILE_SIZE); |
|
641 |
int safe_y = Clamp(y, 0, MapMaxY() * TILE_SIZE); |
|
642 |
return CreateEffectVehicle(x, y, GetSlopeZ(safe_x, safe_y) + z, type); |
|
643 |
} |
|
644 |
||
645 |
Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type) |
|
646 |
{ |
|
647 |
return CreateEffectVehicle(v->x_pos + x, v->y_pos + y, v->z_pos + z, type); |
|
648 |
} |
|
649 |
||
650 |
void EffectVehicle::Tick() |
|
651 |
{ |
|
652 |
_effect_tick_procs[this->subtype](this); |
|
653 |
} |
|
654 |
||
655 |
void EffectVehicle::UpdateDeltaXY(Direction direction) |
|
656 |
{ |
|
657 |
this->x_offs = 0; |
|
658 |
this->y_offs = 0; |
|
659 |
this->x_extent = 1; |
|
660 |
this->y_extent = 1; |
|
661 |
this->z_extent = 1; |
|
662 |
} |