fixed handling of fake acid for EM engine
[rocksndiamonds.git] / src / game_em / logic.c
1 /* 2008-09-24 23:20:29
2  *
3  * David Tritscher
4  *
5  * my own version of the emerald mine engine
6  */
7
8 #include "main_em.h"
9
10
11 #define SPRING_ROLL     /* spring rolling off round things continues to roll */
12 #define USE_CHANGED_ACID_STUFF
13
14 #define RANDOM_RAW      (seed = seed << 31 | seed >> 1)
15 #define RANDOM(x)       (RANDOM_RAW & (x - 1))
16
17 static short **cave, **next, **boom;
18 static unsigned int seed;
19 static int score;
20
21 static void Lboom_generic(int x, int y, int element, int element_middle)
22 {
23   boom[x-1][y-1] = element;
24   boom[x][y-1]   = element;
25   boom[x+1][y-1] = element;
26   boom[x-1][y]   = element;
27   boom[x][y]     = element_middle;
28   boom[x+1][y]   = element;
29   boom[x-1][y+1] = element;
30   boom[x][y+1]   = element;
31   boom[x+1][y+1] = element;
32 }
33
34 static void Lboom_bug(int x, int y, int by_element)
35 {
36   next[x][y] = Znormal;
37
38   Lboom_generic(x, y, Xemerald, Xdiamond);
39
40 #if PLAY_ELEMENT_SOUND
41   play_element_sound(x, y, SOUND_boom, by_element);
42 #endif
43 }
44
45 static void Lboom_tank(int x, int y, int by_element)
46 {
47   next[x][y] = Znormal;
48
49   Lboom_generic(x, y, Xblank, Xblank);
50
51 #if PLAY_ELEMENT_SOUND
52   play_element_sound(x, y, SOUND_boom, by_element);
53 #endif
54 }
55
56 static void Lboom_eater(int x, int y, int by_element)
57 {
58   next[x][y] = Znormal;
59
60   boom[x-1][y-1] = lev.eater_array[lev.eater_pos][0];
61   boom[x][y-1]   = lev.eater_array[lev.eater_pos][1];
62   boom[x+1][y-1] = lev.eater_array[lev.eater_pos][2];
63   boom[x-1][y]   = lev.eater_array[lev.eater_pos][3];
64   boom[x][y]     = lev.eater_array[lev.eater_pos][4];
65   boom[x+1][y]   = lev.eater_array[lev.eater_pos][5];
66   boom[x-1][y+1] = lev.eater_array[lev.eater_pos][6];
67   boom[x][y+1]   = lev.eater_array[lev.eater_pos][7];
68   boom[x+1][y+1] = lev.eater_array[lev.eater_pos][8];
69
70   lev.eater_pos = (lev.eater_pos + 1) & 7;
71
72 #if PLAY_ELEMENT_SOUND
73   play_element_sound(x, y, SOUND_boom, by_element);
74 #endif
75 }
76
77 static boolean player_killed(struct PLAYER *ply)
78 {
79   int x = ply->x;
80   int y = ply->y;
81
82   if (!ply->alive)
83     return FALSE;
84
85   if (lev.killed_out_of_time && setup.time_limit)
86     return TRUE;
87
88   switch (cave[x][y-1])
89   {
90     case Xbug_1_n:
91     case Xbug_1_e:
92     case Xbug_1_s:
93     case Xbug_1_w:
94     case Xbug_2_n:
95     case Xbug_2_e:
96     case Xbug_2_s:
97     case Xbug_2_w:
98     case Xtank_1_n:
99     case Xtank_1_e:
100     case Xtank_1_s:
101     case Xtank_1_w:
102     case Xtank_2_n:
103     case Xtank_2_e:
104     case Xtank_2_s:
105     case Xtank_2_w:
106       return TRUE;
107   }
108
109   switch (cave[x+1][y])
110   {
111     case Xbug_1_n:
112     case Xbug_1_e:
113     case Xbug_1_s:
114     case Xbug_1_w:
115     case Xbug_2_n:
116     case Xbug_2_e:
117     case Xbug_2_s:
118     case Xbug_2_w:
119     case Xtank_1_n:
120     case Xtank_1_e:
121     case Xtank_1_s:
122     case Xtank_1_w:
123     case Xtank_2_n:
124     case Xtank_2_e:
125     case Xtank_2_s:
126     case Xtank_2_w:
127       return TRUE;
128   }
129
130   switch (cave[x][y+1])
131   {
132     case Xbug_1_n:
133     case Xbug_1_e:
134     case Xbug_1_s:
135     case Xbug_1_w:
136     case Xbug_2_n:
137     case Xbug_2_e:
138     case Xbug_2_s:
139     case Xbug_2_w:
140     case Xtank_1_n:
141     case Xtank_1_e:
142     case Xtank_1_s:
143     case Xtank_1_w:
144     case Xtank_2_n:
145     case Xtank_2_e:
146     case Xtank_2_s:
147     case Xtank_2_w:
148       return TRUE;
149   }
150
151   switch (cave[x-1][y])
152   {
153     case Xbug_1_n:
154     case Xbug_1_e:
155     case Xbug_1_s:
156     case Xbug_1_w:
157     case Xbug_2_n:
158     case Xbug_2_e:
159     case Xbug_2_s:
160     case Xbug_2_w:
161     case Xtank_1_n:
162     case Xtank_1_e:
163     case Xtank_1_s:
164     case Xtank_1_w:
165     case Xtank_2_n:
166     case Xtank_2_e:
167     case Xtank_2_s:
168     case Xtank_2_w:
169       return TRUE;
170   }
171
172   switch (cave[x][y])
173   {
174     case Xblank:
175     case Xacid_splash_e:
176     case Xacid_splash_w:
177 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
178     case Xfake_acid_1:
179     case Xfake_acid_2:
180     case Xfake_acid_3:
181     case Xfake_acid_4:
182     case Xfake_acid_5:
183     case Xfake_acid_6:
184     case Xfake_acid_7:
185     case Xfake_acid_8:
186 #endif
187     case Zplayer:
188     case Xdynamite_1:
189     case Xdynamite_2:
190     case Xdynamite_3:
191     case Xdynamite_4:
192       return FALSE;
193   }
194
195   return TRUE;
196 }
197
198 static void kill_player(struct PLAYER *ply)
199 {
200   int x = ply->x;
201   int y = ply->y;
202
203   ply->alive = 0;
204
205   switch (cave[x][y-1])
206   {
207     case Xbug_1_n:
208     case Xbug_1_e:
209     case Xbug_1_s:
210     case Xbug_1_w:
211     case Xbug_2_n:
212     case Xbug_2_e:
213     case Xbug_2_s:
214     case Xbug_2_w:
215       cave[x][y-1] = Xboom_bug;
216       break;
217
218     case Xtank_1_n:
219     case Xtank_1_e:
220     case Xtank_1_s:
221     case Xtank_1_w:
222     case Xtank_2_n:
223     case Xtank_2_e:
224     case Xtank_2_s:
225     case Xtank_2_w:
226       cave[x][y-1] = Xboom_bomb;
227       break;
228   }
229
230   switch (cave[x+1][y])
231   {
232     case Xbug_1_n:
233     case Xbug_1_e:
234     case Xbug_1_s:
235     case Xbug_1_w:
236     case Xbug_2_n:
237     case Xbug_2_e:
238     case Xbug_2_s:
239     case Xbug_2_w:
240       cave[x+1][y] = Xboom_bug;
241       break;
242
243     case Xtank_1_n:
244     case Xtank_1_e:
245     case Xtank_1_s:
246     case Xtank_1_w:
247     case Xtank_2_n:
248     case Xtank_2_e:
249     case Xtank_2_s:
250     case Xtank_2_w:
251       cave[x+1][y] = Xboom_bomb;
252       break;
253   }
254
255   switch (cave[x][y+1])
256   {
257     case Xbug_1_n:
258     case Xbug_1_e:
259     case Xbug_1_s:
260     case Xbug_1_w:
261     case Xbug_2_n:
262     case Xbug_2_e:
263     case Xbug_2_s:
264     case Xbug_2_w:
265       cave[x][y+1] = Xboom_bug;
266       break;
267
268     case Xtank_1_n:
269     case Xtank_1_e:
270     case Xtank_1_s:
271     case Xtank_1_w:
272     case Xtank_2_n:
273     case Xtank_2_e:
274     case Xtank_2_s:
275     case Xtank_2_w:
276       cave[x][y+1] = Xboom_bomb;
277       break;
278   }
279
280   switch (cave[x-1][y])
281   {
282     case Xbug_1_n:
283     case Xbug_1_e:
284     case Xbug_1_s:
285     case Xbug_1_w:
286     case Xbug_2_n:
287     case Xbug_2_e:
288     case Xbug_2_s:
289     case Xbug_2_w:
290       cave[x-1][y] = Xboom_bug;
291       break;
292
293     case Xtank_1_n:
294     case Xtank_1_e:
295     case Xtank_1_s:
296     case Xtank_1_w:
297     case Xtank_2_n:
298     case Xtank_2_e:
299     case Xtank_2_s:
300     case Xtank_2_w:
301       cave[x-1][y] = Xboom_bomb;
302       break;
303   }
304
305   switch (cave[x][y])
306   {
307     case Xexit_1:
308     case Xexit_2:
309     case Xexit_3:
310       lev.exit_x = x;
311       lev.exit_y = y;
312       play_element_sound(x, y, SOUND_exit_leave, Xexit_1);
313       break;
314
315     default:
316       play_element_sound(x, y, SOUND_die, Zplayer);
317       break;
318   }
319
320   switch (cave[x][y])
321   {
322 #ifdef USE_CHANGED_ACID_STUFF
323     case Xacid_1:
324     case Xacid_2:
325     case Xacid_3:
326     case Xacid_4:
327     case Xacid_5:
328     case Xacid_6:
329     case Xacid_7:
330     case Xacid_8:
331       break;
332 #endif
333
334     default:
335       cave[x][y] = Xboom_1;
336       boom[x][y] = Xblank;
337       break;
338   }
339 }
340
341 static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
342 {
343   int anim = (dx < 0 ? 3 : dx > 0 ? 1 : dy < 0 ? 0 : dy > 0 ? 2 : 2);
344   int oldx = ply->x;
345   int oldy = ply->y;
346   int x = oldx + dx;
347   int y = oldy + dy;
348   boolean result = TRUE;
349
350   if (!dx && !dy)                       /* no direction specified */
351     return FALSE;
352
353   if (dx && dy && ply->joy_snap)        /* more than one direction specified */
354     return FALSE;
355
356   if (ply->joy_snap == 0)               /* player wants to move */
357   {
358     int element = cave[x][y];
359
360     switch (cave[x][y])
361     {
362       /* fire is released */
363       case Xblank:
364       case Xacid_splash_e:
365       case Xacid_splash_w:
366         cave[x][y] = Zplayer;
367         next[x][y] = Zplayer;
368 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
369       case Xfake_acid_1:
370       case Xfake_acid_2:
371       case Xfake_acid_3:
372       case Xfake_acid_4:
373       case Xfake_acid_5:
374       case Xfake_acid_6:
375       case Xfake_acid_7:
376       case Xfake_acid_8:
377 #endif
378         play_element_sound(x, y, SOUND_blank, Xblank);
379         ply->anim = PLY_walk_n + anim;
380         ply->x = x;
381         ply->y = y;
382         break;
383
384 #ifdef USE_CHANGED_ACID_STUFF
385       case Xacid_1:
386       case Xacid_2:
387       case Xacid_3:
388       case Xacid_4:
389       case Xacid_5:
390       case Xacid_6:
391       case Xacid_7:
392       case Xacid_8:
393         if (cave[x+1][y-1] == Xblank)
394           cave[x+1][y-1] = Xacid_splash_e;
395         if (cave[x-1][y-1] == Xblank)
396           cave[x-1][y-1] = Xacid_splash_w;
397         play_element_sound(x, y, SOUND_acid, Xacid_1);
398 #endif
399
400       case Xboom_android:
401       case Xboom_1:
402       case Xbug_1_n:
403       case Xbug_1_e:
404       case Xbug_1_s:
405       case Xbug_1_w:
406       case Xbug_2_n:
407       case Xbug_2_e:
408       case Xbug_2_s:
409       case Xbug_2_w:
410       case Xtank_1_n:
411       case Xtank_1_e:
412       case Xtank_1_s:
413       case Xtank_1_w:
414       case Xtank_2_n:
415       case Xtank_2_e:
416       case Xtank_2_s:
417       case Xtank_2_w:
418
419 #ifndef USE_CHANGED_ACID_STUFF
420       case Xacid_1:
421       case Xacid_2:
422       case Xacid_3:
423       case Xacid_4:
424       case Xacid_5:
425       case Xacid_6:
426       case Xacid_7:
427       case Xacid_8:
428 #endif
429         ply->anim = PLY_walk_n + anim;
430         ply->x = x;
431         ply->y = y;
432         break;
433
434       case Xgrass:
435         cave[x][y] = (dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) :
436                       (dx > 0 ? Ygrass_eB : Ygrass_wB));
437         next[x][y] = Zplayer;
438         play_element_sound(x, y, SOUND_dirt, Xgrass);
439         ply->anim = PLY_walk_n + anim;
440         ply->x = x;
441         ply->y = y;
442         break;
443
444       case Xdirt:
445         cave[x][y] = (dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) :
446                       (dx > 0 ? Ydirt_eB : Ydirt_wB));
447         next[x][y] = Zplayer;
448         play_element_sound(x, y, SOUND_dirt, Xdirt);
449         ply->anim = PLY_walk_n + anim;
450         ply->x = x;
451         ply->y = y;
452         break;
453
454       case Xdiamond:
455       case Xdiamond_pause:
456         cave[x][y] = Ydiamond_blank;
457         next[x][y] = Zplayer;
458         play_element_sound(x, y, SOUND_collect, element);
459         lev.score += lev.diamond_score;
460         lev.required = lev.required < 3 ? 0 : lev.required - 3;
461         game.snapshot.collected_item = TRUE;
462         ply->anim = PLY_walk_n + anim;
463         ply->x = x;
464         ply->y = y;
465         break;
466
467       case Xemerald:
468       case Xemerald_pause:
469         cave[x][y] = Yemerald_blank;
470         next[x][y] = Zplayer;
471         play_element_sound(x, y, SOUND_collect, element);
472         lev.score += lev.emerald_score;
473         lev.required = lev.required < 1 ? 0 : lev.required - 1;
474         game.snapshot.collected_item = TRUE;
475         ply->anim = PLY_walk_n + anim;
476         ply->x = x;
477         ply->y = y;
478         break;
479
480       case Xdynamite:
481         cave[x][y] = Ydynamite_blank;
482         next[x][y] = Zplayer;
483         play_element_sound(x, y, SOUND_collect, element);
484         lev.score += lev.dynamite_score;
485         ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
486         ply->anim = PLY_walk_n + anim;
487         ply->x = x;
488         ply->y = y;
489         break;
490
491       case Xkey_1:
492         ply->keys |= 0x01;
493         cave[x][y] = Ykey_1_blank;
494         goto key_walk;
495
496       case Xkey_2:
497         ply->keys |= 0x02;
498         cave[x][y] = Ykey_2_blank;
499         goto key_walk;
500
501       case Xkey_3:
502         ply->keys |= 0x04;
503         cave[x][y] = Ykey_3_blank;
504         goto key_walk;
505
506       case Xkey_4:
507         ply->keys |= 0x08;
508         cave[x][y] = Ykey_4_blank;
509         goto key_walk;
510
511       case Xkey_5:
512         ply->keys |= 0x10;
513         cave[x][y] = Ykey_5_blank;
514         goto key_walk;
515
516       case Xkey_6:
517         ply->keys |= 0x20;
518         cave[x][y] = Ykey_6_blank;
519         goto key_walk;
520
521       case Xkey_7:
522         ply->keys |= 0x40;
523         cave[x][y] = Ykey_7_blank;
524         goto key_walk;
525
526       case Xkey_8:
527         ply->keys |= 0x80;
528         cave[x][y] = Ykey_8_blank;
529         goto key_walk;
530
531       key_walk:
532
533         next[x][y] = Zplayer;
534         play_element_sound(x, y, SOUND_collect, element);
535         lev.score += lev.key_score;
536         ply->anim = PLY_walk_n + anim;
537         ply->x = x;
538         ply->y = y;
539         break;
540
541       case Xlenses:
542         cave[x][y] = Ylenses_blank;
543         next[x][y] = Zplayer;
544         play_element_sound(x, y, SOUND_collect, element);
545         lev.score += lev.lenses_score;
546         lev.lenses_cnt = lev.lenses_time;
547         ply->anim = PLY_walk_n + anim;
548         ply->x = x;
549         ply->y = y;
550         break;
551
552       case Xmagnify:
553         cave[x][y] = Ymagnify_blank;
554         next[x][y] = Zplayer;
555         play_element_sound(x, y, SOUND_collect, element);
556         lev.score += lev.magnify_score;
557         lev.magnify_cnt = lev.magnify_time;
558         ply->anim = PLY_walk_n + anim;
559         ply->x = x;
560         ply->y = y;
561         break;
562
563       case Xstone:
564         if (dy)
565           break;
566
567         switch (cave[x+dx][y])
568         {
569           case Xblank:
570           case Xacid_splash_e:
571           case Xacid_splash_w:
572 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
573           case Xfake_acid_1:
574           case Xfake_acid_2:
575           case Xfake_acid_3:
576           case Xfake_acid_4:
577           case Xfake_acid_5:
578           case Xfake_acid_6:
579           case Xfake_acid_7:
580           case Xfake_acid_8:
581 #endif
582             cave[x+dx][y] = dx > 0 ? Ystone_e : Ystone_w;
583             next[x+dx][y] = Xstone_pause;
584             goto stone_walk;
585
586           case Xacid_1:
587           case Xacid_2:
588           case Xacid_3:
589           case Xacid_4:
590           case Xacid_5:
591           case Xacid_6:
592           case Xacid_7:
593           case Xacid_8:
594             if (cave[x+dx+1][y-1] == Xblank)
595               cave[x+dx+1][y-1] = Xacid_splash_e;
596             if (cave[x+dx-1][y-1] == Xblank)
597               cave[x+dx-1][y-1] = Xacid_splash_w;
598             play_element_sound(x, y, SOUND_acid, Xacid_1);
599
600           stone_walk:
601
602             cave[x][y] = dx > 0 ? Ystone_eB : Ystone_wB;
603             next[x][y] = Zplayer;
604             play_element_sound(x, y, SOUND_roll, Xstone);
605             ply->x = x;
606             break;
607         }
608
609         ply->anim = PLY_push_n + anim;
610         break;
611
612       case Xbomb:
613         if (dy)
614           break;
615
616         switch (cave[x+dx][y])
617         {
618           case Xblank:
619           case Xacid_splash_e:
620           case Xacid_splash_w:
621 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
622           case Xfake_acid_1:
623           case Xfake_acid_2:
624           case Xfake_acid_3:
625           case Xfake_acid_4:
626           case Xfake_acid_5:
627           case Xfake_acid_6:
628           case Xfake_acid_7:
629           case Xfake_acid_8:
630 #endif
631             cave[x+dx][y] = dx > 0 ? Ybomb_e : Ybomb_w;
632             next[x+dx][y] = Xbomb_pause;
633             goto bomb_walk;
634
635           case Xacid_1:
636           case Xacid_2:
637           case Xacid_3:
638           case Xacid_4:
639           case Xacid_5:
640           case Xacid_6:
641           case Xacid_7:
642           case Xacid_8:
643             if (cave[x+dx+1][y-1] == Xblank)
644               cave[x+dx+1][y-1] = Xacid_splash_e;
645             if (cave[x+dx-1][y-1] == Xblank)
646               cave[x+dx-1][y-1] = Xacid_splash_w;
647             play_element_sound(x, y, SOUND_acid, Xacid_1);
648
649           bomb_walk:
650
651             cave[x][y] = dx > 0 ? Ybomb_eB : Ybomb_wB;
652             next[x][y] = Zplayer;
653             play_element_sound(x, y, SOUND_roll, Xbomb);
654             ply->x = x;
655             break;
656         }
657
658         ply->anim = PLY_push_n + anim;
659         break;
660
661       case Xnut:
662         if (dy)
663           break;
664
665         switch (cave[x+dx][y])
666         {
667           case Xblank:
668           case Xacid_splash_e:
669           case Xacid_splash_w:
670 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
671           case Xfake_acid_1:
672           case Xfake_acid_2:
673           case Xfake_acid_3:
674           case Xfake_acid_4:
675           case Xfake_acid_5:
676           case Xfake_acid_6:
677           case Xfake_acid_7:
678           case Xfake_acid_8:
679 #endif
680             cave[x+dx][y] = dx > 0 ? Ynut_e : Ynut_w;
681             next[x+dx][y] = Xnut_pause;
682             goto nut_walk;
683
684           case Xacid_1:
685           case Xacid_2:
686           case Xacid_3:
687           case Xacid_4:
688           case Xacid_5:
689           case Xacid_6:
690           case Xacid_7:
691           case Xacid_8:
692             if (cave[x+dx+1][y-1] == Xblank)
693               cave[x+dx+1][y-1] = Xacid_splash_e;
694             if (cave[x+dx-1][y-1] == Xblank)
695               cave[x+dx-1][y-1] = Xacid_splash_w;
696             play_element_sound(x, y, SOUND_acid, Xacid_1);
697
698           nut_walk:
699
700             cave[x][y] = dx > 0 ? Ynut_eB : Ynut_wB;
701             next[x][y] = Zplayer;
702             play_element_sound(x, y, SOUND_roll, Xnut);
703             ply->x = x;
704             break;
705         }
706
707         ply->anim = PLY_push_n + anim;
708         break;
709
710       case Xspring:
711         if (dy)
712           break;
713
714         switch (cave[x+dx][y])
715         {
716           case Xblank:
717           case Xacid_splash_e:
718           case Xacid_splash_w:
719 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
720           case Xfake_acid_1:
721           case Xfake_acid_2:
722           case Xfake_acid_3:
723           case Xfake_acid_4:
724           case Xfake_acid_5:
725           case Xfake_acid_6:
726           case Xfake_acid_7:
727           case Xfake_acid_8:
728 #endif
729             cave[x+dx][y] = dx > 0 ? Yspring_e : Yspring_w;
730             next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
731             goto spring_walk;
732
733           case Xacid_1:
734           case Xacid_2:
735           case Xacid_3:
736           case Xacid_4:
737           case Xacid_5:
738           case Xacid_6:
739           case Xacid_7:
740           case Xacid_8:
741             if (cave[x+dx+1][y-1] == Xblank)
742               cave[x+dx+1][y-1] = Xacid_splash_e;
743             if (cave[x+dx-1][y-1] == Xblank)
744               cave[x+dx-1][y-1] = Xacid_splash_w;
745             play_element_sound(x, y, SOUND_acid, Xacid_1);
746
747           spring_walk:
748
749             cave[x][y] = dx > 0 ? Yspring_eB : Yspring_wB;
750             next[x][y] = Zplayer;
751             play_element_sound(x, y, SOUND_roll, Xspring);
752             ply->x = x;
753             break;
754
755           case Xalien:
756           case Xalien_pause:
757             cave[x][y] = dx > 0 ? Yspring_alien_eB : Yspring_alien_wB;
758             cave[x+dx][y] = dx > 0 ? Yspring_alien_e : Yspring_alien_w;
759             next[x][y] = Zplayer;
760             next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
761             play_element_sound(x, y, SOUND_slurp, Xalien);
762             lev.score += lev.slurp_score;
763             ply->x = x;
764             break;
765         }
766
767         ply->anim = PLY_push_n + anim;
768         break;
769
770       case Xspring_pause:
771       case Xstone_pause:
772       case Xbomb_pause:
773       case Xnut_pause:
774       case Xsand_stonein_1:
775       case Xsand_stonein_2:
776       case Xsand_stonein_3:
777       case Xsand_stonein_4:
778         if (dy)
779           break;
780
781         ply->anim = PLY_push_n + anim;
782         break;
783
784       case Xballoon:
785         switch (cave[x+dx][y+dy])
786         {
787           case Xblank:
788           case Xacid_splash_e:
789           case Xacid_splash_w:
790 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
791           case Xfake_acid_1:
792           case Xfake_acid_2:
793           case Xfake_acid_3:
794           case Xfake_acid_4:
795           case Xfake_acid_5:
796           case Xfake_acid_6:
797           case Xfake_acid_7:
798           case Xfake_acid_8:
799 #endif
800             cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
801                                 (dx > 0 ? Yballoon_e : Yballoon_w));
802             next[x+dx][y+dy] = Xballoon;
803             goto balloon_walk;
804
805           case Xacid_1:
806           case Xacid_2:
807           case Xacid_3:
808           case Xacid_4:
809           case Xacid_5:
810           case Xacid_6:
811           case Xacid_7:
812           case Xacid_8:
813             if (cave[x+dx+1][y+dy-1] == Xblank)
814               cave[x+dx+1][y+dy-1] = Xacid_splash_e;
815             if (cave[x+dx-1][y+dy-1] == Xblank)
816               cave[x+dx-1][y+dy-1] = Xacid_splash_w;
817             play_element_sound(x, y, SOUND_acid, Xacid_1);
818
819           balloon_walk:
820
821             cave[x][y] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
822                           (dx > 0 ? Yballoon_eB : Yballoon_wB));
823             next[x][y] = Zplayer;
824             play_element_sound(x, y, SOUND_push, Xballoon);
825             ply->x = x;
826             ply->y = y;
827             break;
828         }
829
830         ply->anim = PLY_push_n + anim;
831         break;
832
833       case Xandroid:
834       case Xandroid_1_n:
835       case Xandroid_2_n:
836       case Xandroid_1_e:
837       case Xandroid_2_e:
838       case Xandroid_1_s:
839       case Xandroid_2_s:
840       case Xandroid_1_w:
841       case Xandroid_2_w:
842         switch (cave[x+dx][y+dy])
843         {
844           case Xblank:
845           case Xacid_splash_e:
846           case Xacid_splash_w:
847 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
848           case Xfake_acid_1:
849           case Xfake_acid_2:
850           case Xfake_acid_3:
851           case Xfake_acid_4:
852           case Xfake_acid_5:
853           case Xfake_acid_6:
854           case Xfake_acid_7:
855           case Xfake_acid_8:
856 #endif
857             cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
858                                 (dx > 0 ? Yandroid_e : Yandroid_w));
859             next[x+dx][y+dy] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
860                                 (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
861             goto android_walk;
862
863           case Xacid_1:
864           case Xacid_2:
865           case Xacid_3:
866           case Xacid_4:
867           case Xacid_5:
868           case Xacid_6:
869           case Xacid_7:
870           case Xacid_8:
871             if (cave[x+dx+1][y+dy-1] == Xblank)
872               cave[x+dx+1][y+dy-1] = Xacid_splash_e;
873             if (cave[x+dx-1][y+dy-1] == Xblank)
874               cave[x+dx-1][y+dy-1] = Xacid_splash_w;
875             play_element_sound(x, y, SOUND_acid, Xacid_1);
876
877           android_walk:
878
879             cave[x][y] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
880                           (dx > 0 ? Yandroid_eB : Yandroid_wB));
881             next[x][y] = Zplayer;
882             play_element_sound(x, y, SOUND_push, Xandroid);
883             ply->x = x;
884             ply->y = y;
885             break;
886         }
887
888         ply->anim = PLY_push_n + anim;
889         break;
890
891       case Xdoor_1:
892       case Xfake_door_1:
893         if (ply->keys & 0x01)
894           goto door_walk;
895         else
896           break;
897
898       case Xdoor_2:
899       case Xfake_door_2:
900         if (ply->keys & 0x02)
901           goto door_walk;
902         else
903           break;
904
905       case Xdoor_3:
906       case Xfake_door_3:
907         if (ply->keys & 0x04)
908           goto door_walk;
909         else
910           break;
911
912       case Xdoor_4:
913       case Xfake_door_4:
914         if (ply->keys & 0x08)
915           goto door_walk;
916         else
917           break;
918
919       case Xdoor_5:
920       case Xfake_door_5:
921         if (ply->keys & 0x10)
922           goto door_walk;
923         else
924           break;
925
926       case Xdoor_6:
927       case Xfake_door_6:
928         if (ply->keys & 0x20)
929           goto door_walk;
930         else
931           break;
932
933       case Xdoor_7:
934       case Xfake_door_7:
935         if (ply->keys & 0x40)
936           goto door_walk;
937         else
938           break;
939
940       case Xdoor_8:
941       case Xfake_door_8:
942         if (ply->keys & 0x80)
943           goto door_walk;
944         else
945           break;
946
947       door_walk:
948
949         if (!tab_blank[cave[x+dx][y+dy]])
950           break;
951
952         if (!tab_fake_acid[cave[x+dx][y+dy]])
953         {
954           cave[x+dx][y+dy] = Zplayer;
955           next[x+dx][y+dy] = Zplayer;
956         }
957
958         play_element_sound(x, y, SOUND_door, element);
959         ply->anim = PLY_walk_n + anim;
960         ply->x = x + dx;
961         ply->y = y + dy;
962         break;
963
964       case Xwheel:
965         play_element_sound(x, y, SOUND_press, element);
966         lev.wheel_cnt = lev.wheel_time;
967         lev.wheel_x = x;
968         lev.wheel_y = y;
969         break;
970
971       case Xwind_n:
972         lev.wind_direction = 0;
973         goto wind_walk;
974
975       case Xwind_e:
976         lev.wind_direction = 1;
977         goto wind_walk;
978
979       case Xwind_s:
980         lev.wind_direction = 2;
981         goto wind_walk;
982
983       case Xwind_w:
984         lev.wind_direction = 3;
985         goto wind_walk;
986
987       case Xwind_any:
988         lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3);
989         goto wind_walk;
990
991       wind_walk:
992
993         play_element_sound(x, y, SOUND_press, element);
994         lev.wind_cnt = lev.wind_time;
995         break;
996
997       case Xwind_stop:
998         play_element_sound(x, y, SOUND_press, element);
999         lev.wind_cnt = 0;
1000         break;
1001
1002       case Xswitch:
1003         play_element_sound(x, y, SOUND_press, element);
1004         lev.ball_cnt = lev.ball_time;
1005         lev.ball_state = !lev.ball_state;
1006         break;
1007
1008       case Xplant:
1009         cave[x][y] = Yplant;
1010         next[x][y] = Xplant;
1011         play_element_sound(x, y, SOUND_blank, Xplant);
1012         ply->anim = PLY_walk_n + anim;
1013         ply->x = x;
1014         ply->y = y;
1015         break;
1016
1017       case Xexit_1:
1018       case Xexit_2:
1019       case Xexit_3:
1020         lev.home--;
1021
1022         if (lev.home == 0)
1023           game_em.level_solved = TRUE;
1024
1025         ply->anim = PLY_walk_n + anim;
1026         ply->x = x;
1027         ply->y = y;
1028
1029         break;
1030     }
1031
1032     if (ply->x == oldx && ply->y == oldy)       /* no movement */
1033       result = FALSE;
1034   }
1035   else                                  /* player wants to snap */
1036   {
1037     int element = cave[x][y];
1038
1039     switch (cave[x][y])
1040     {
1041       /* fire is pressed */
1042
1043       case Xgrass:
1044         cave[x][y] = Ygrass_blank;
1045         next[x][y] = Xblank;
1046         play_element_sound(x, y, SOUND_dirt, element);
1047         ply->anim = PLY_shoot_n + anim;
1048         break;
1049
1050       case Xdirt:
1051         cave[x][y] = Ydirt_blank;
1052         next[x][y] = Xblank;
1053         play_element_sound(x, y, SOUND_dirt, element);
1054         ply->anim = PLY_shoot_n + anim;
1055         break;
1056
1057       case Xdiamond:
1058       case Xdiamond_pause:
1059         cave[x][y] = Ydiamond_blank;
1060         next[x][y] = Xblank;
1061         play_element_sound(x, y, SOUND_collect, element);
1062         lev.score += lev.diamond_score;
1063         lev.required = lev.required < 3 ? 0 : lev.required - 3;
1064         game.snapshot.collected_item = TRUE;
1065         ply->anim = PLY_walk_n + anim;
1066         break;
1067
1068       case Xemerald:
1069       case Xemerald_pause:
1070         cave[x][y] = Yemerald_blank;
1071         next[x][y] = Xblank;
1072         play_element_sound(x, y, SOUND_collect, element);
1073         lev.score += lev.emerald_score;
1074         lev.required = lev.required < 1 ? 0 : lev.required - 1;
1075         game.snapshot.collected_item = TRUE;
1076         ply->anim = PLY_walk_n + anim;
1077         break;
1078
1079       case Xdynamite:
1080         cave[x][y] = Ydynamite_blank;
1081         next[x][y] = Xblank;
1082         play_element_sound(x, y, SOUND_collect, element);
1083         lev.score += lev.dynamite_score;
1084         ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1085         ply->anim = PLY_walk_n + anim;
1086         break;
1087
1088       case Xkey_1:
1089         ply->keys |= 0x01;
1090         cave[x][y] = Ykey_1_blank;
1091         goto key_shoot;
1092
1093       case Xkey_2:
1094         ply->keys |= 0x02;
1095         cave[x][y] = Ykey_2_blank;
1096         goto key_shoot;
1097
1098       case Xkey_3:
1099         ply->keys |= 0x04;
1100         cave[x][y] = Ykey_3_blank;
1101         goto key_shoot;
1102
1103       case Xkey_4:
1104         ply->keys |= 0x08;
1105         cave[x][y] = Ykey_4_blank;
1106         goto key_shoot;
1107
1108       case Xkey_5:
1109         ply->keys |= 0x10;
1110         cave[x][y] = Ykey_5_blank;
1111         goto key_shoot;
1112
1113       case Xkey_6:
1114         ply->keys |= 0x20;
1115         cave[x][y] = Ykey_6_blank;
1116         goto key_shoot;
1117
1118       case Xkey_7:
1119         ply->keys |= 0x40;
1120         cave[x][y] = Ykey_7_blank;
1121         goto key_shoot;
1122
1123       case Xkey_8:
1124         ply->keys |= 0x80;
1125         cave[x][y] = Ykey_8_blank;
1126         goto key_shoot;
1127
1128       key_shoot:
1129
1130         next[x][y] = Xblank;
1131         play_element_sound(x, y, SOUND_collect, element);
1132         lev.score += lev.key_score;
1133         ply->anim = PLY_walk_n + anim;
1134         break;
1135
1136       case Xlenses:
1137         cave[x][y] = Ylenses_blank;
1138         next[x][y] = Xblank;
1139         play_element_sound(x, y, SOUND_collect, element);
1140         lev.score += lev.lenses_score;
1141         lev.lenses_cnt = lev.lenses_time;
1142         ply->anim = PLY_walk_n + anim;
1143         break;
1144
1145       case Xmagnify:
1146         cave[x][y] = Ymagnify_blank;
1147         next[x][y] = Xblank;
1148         play_element_sound(x, y, SOUND_collect, element);
1149         lev.score += lev.magnify_score;
1150         lev.magnify_cnt = lev.magnify_time;
1151         ply->anim = PLY_walk_n + anim;
1152         break;
1153
1154       default:
1155         result = FALSE;
1156     }
1157   }
1158
1159   return result;
1160 }
1161
1162 static void check_player(struct PLAYER *ply)
1163 {
1164   int oldx = ply->x;
1165   int oldy = ply->y;
1166   int x = oldx;
1167   int y = oldy;
1168   int dx = 0, dy = 0;
1169
1170   game_em.last_player_direction[ply->num] = MV_NONE;
1171
1172   if (ply->joy_w)               /* west */
1173   {
1174     x--;
1175     dx = -1;
1176   }
1177   else if (ply->joy_e)          /* east */
1178   {
1179     x++;
1180     dx = 1;
1181   }
1182
1183   if (ply->joy_n)               /* north */
1184   {
1185     y--;
1186     dy = -1;
1187   }
1188   else if (ply->joy_s)          /* south */
1189   {
1190     y++;
1191     dy = 1;
1192   }
1193
1194   if (dx || dy)
1195   {
1196     int oldx = ply->x;
1197     int oldy = ply->y;
1198     int x = oldx + dx;
1199     int y = oldy + dy;
1200     boolean players_visible_before_move;
1201     boolean players_visible_after_move;
1202     boolean can_move;
1203
1204     players_visible_before_move = checkIfAllPlayersFitToScreen();
1205
1206     ply->x = x;
1207     ply->y = y;
1208
1209     players_visible_after_move = checkIfAllPlayersFitToScreen();
1210
1211     /*
1212       player is allowed to move only in the following cases:
1213       - it is not needed to display all players (not focussed to all players)
1214       - all players are (still or again) visible after the move
1215       - some players were already outside visible screen area before the move
1216     */
1217     can_move = (game.centered_player_nr != -1 ||
1218                 players_visible_after_move ||
1219                 !players_visible_before_move);
1220
1221     ply->x = oldx;
1222     ply->y = oldy;
1223
1224     if (!can_move)
1225     {
1226       ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
1227
1228       return;
1229     }
1230   }
1231
1232   if (dx == 0 && dy == 0)
1233   {
1234     ply->joy_stick = 0;
1235
1236     if (ply->joy_drop)
1237     {
1238       if (++ply->dynamite_cnt == 5 && ply->dynamite)
1239       {
1240         cave[x][y] = Xdynamite_1;
1241         play_element_sound(x, y, SOUND_dynamite, Xdynamite_1);
1242         ply->dynamite--;
1243       }
1244     }
1245     else
1246     {
1247       ply->dynamite_cnt = 0;
1248     }
1249
1250     RandomEM += 7;      /* be a bit more random if the player doesn't move */
1251
1252     return;
1253   }
1254
1255   ply->joy_stick = 1;
1256   ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
1257   ply->dynamite_cnt = 0;        /* reset dynamite timer if we move */
1258   ply->joy_spin = !ply->joy_spin;
1259
1260   if (ply->joy_snap == 0)               /* player wants to move */
1261   {
1262     boolean moved = FALSE;
1263
1264     if (ply->last_move_dir & MV_HORIZONTAL)
1265     {
1266       if (!(moved = player_digfield(ply, 0, dy)))
1267         moved = player_digfield(ply, dx, 0);
1268     }
1269     else
1270     {
1271       if (!(moved = player_digfield(ply, dx, 0)))
1272         moved = player_digfield(ply, 0, dy);
1273     }
1274
1275     if (moved)
1276     {
1277       if (oldx != ply->x)
1278         ply->last_move_dir = (dx < 0 ? MV_LEFT : MV_RIGHT);
1279       else if (oldy != ply->y)
1280         ply->last_move_dir = (dy < 0 ? MV_UP : MV_DOWN);
1281
1282       game_em.any_player_moving = TRUE;
1283       game_em.last_moving_player = ply->num;
1284       game_em.last_player_direction[ply->num] = ply->last_move_dir;
1285     }
1286   }
1287   else                                  /* player wants to snap */
1288   {
1289     game_em.any_player_snapping = player_digfield(ply, dx, dy);
1290   }
1291 }
1292
1293 static void set_nearest_player_xy(int x, int y, int *dx, int *dy)
1294 {
1295   int distance, distance_shortest = CAVE_WIDTH + CAVE_HEIGHT;
1296   int i;
1297
1298   /* default values if no players are alive anymore */
1299   *dx = 0;
1300   *dy = 0;
1301
1302   for (i = 0; i < MAX_PLAYERS; i++)
1303   {
1304     if (!ply[i].alive)
1305       continue;
1306
1307     distance = ABS(ply[i].x - x) + ABS(ply[i].y - y);
1308
1309     if (distance < distance_shortest)
1310     {
1311       *dx = ply[i].x;
1312       *dy = ply[i].y;
1313
1314       distance_shortest = distance;
1315     }
1316   }
1317 }
1318
1319 static void Lacid_1(int x, int y)
1320 {
1321   next[x][y] = Xacid_2;
1322 }
1323
1324 static void Lacid_2(int x, int y)
1325 {
1326   next[x][y] = Xacid_3;
1327 }
1328
1329 static void Lacid_3(int x, int y)
1330 {
1331   next[x][y] = Xacid_4;
1332 }
1333
1334 static void Lacid_4(int x, int y)
1335 {
1336   next[x][y] = Xacid_5;
1337 }
1338
1339 static void Lacid_5(int x, int y)
1340 {
1341   next[x][y] = Xacid_6;
1342 }
1343
1344 static void Lacid_6(int x, int y)
1345 {
1346   next[x][y] = Xacid_7;
1347 }
1348
1349 static void Lacid_7(int x, int y)
1350 {
1351   next[x][y] = Xacid_8;
1352 }
1353
1354 static void Lacid_8(int x, int y)
1355 {
1356   next[x][y] = Xacid_1;
1357 }
1358
1359 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
1360 static void Lfake_acid_1(int x, int y)
1361 {
1362   next[x][y] = Xfake_acid_2;
1363 }
1364
1365 static void Lfake_acid_2(int x, int y)
1366 {
1367   next[x][y] = Xfake_acid_3;
1368 }
1369
1370 static void Lfake_acid_3(int x, int y)
1371 {
1372   next[x][y] = Xfake_acid_4;
1373 }
1374
1375 static void Lfake_acid_4(int x, int y)
1376 {
1377   next[x][y] = Xfake_acid_5;
1378 }
1379
1380 static void Lfake_acid_5(int x, int y)
1381 {
1382   next[x][y] = Xfake_acid_6;
1383 }
1384
1385 static void Lfake_acid_6(int x, int y)
1386 {
1387   next[x][y] = Xfake_acid_7;
1388 }
1389
1390 static void Lfake_acid_7(int x, int y)
1391 {
1392   next[x][y] = Xfake_acid_8;
1393 }
1394
1395 static void Lfake_acid_8(int x, int y)
1396 {
1397   next[x][y] = Xfake_acid_1;
1398 }
1399 #endif
1400
1401 static void Landroid(int x, int y)
1402 {
1403   int dx, dy, temp;
1404
1405   if (lev.android_clone_cnt == 0)
1406   {
1407     if (cave[x-1][y-1] != Xblank &&
1408         cave[x][y-1]   != Xblank &&
1409         cave[x+1][y-1] != Xblank &&
1410         cave[x-1][y]   != Xblank &&
1411         cave[x+1][y]   != Xblank &&
1412         cave[x-1][y+1] != Xblank &&
1413         cave[x][y+1]   != Xblank &&
1414         cave[x+1][y+1] != Xblank)
1415       goto android_move;
1416
1417     switch (RANDOM(8))
1418     {
1419       /* randomly find an object to clone */
1420
1421       case 0: /* S,NE,W,NW,SE,E,SW,N */
1422         temp = lev.android_array[cave[x][y+1]];   if (temp != Xblank) break;
1423         temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1424         temp = lev.android_array[cave[x-1][y]];   if (temp != Xblank) break;
1425         temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1426         temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1427         temp = lev.android_array[cave[x+1][y]];   if (temp != Xblank) break;
1428         temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1429         temp = lev.android_array[cave[x][y-1]];   if (temp != Xblank) break;
1430         goto android_move;
1431
1432       case 1: /* NW,SE,N,S,NE,SW,E,W */
1433         temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1434         temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1435         temp = lev.android_array[cave[x][y-1]];   if (temp != Xblank) break;
1436         temp = lev.android_array[cave[x][y+1]];   if (temp != Xblank) break;
1437         temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1438         temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1439         temp = lev.android_array[cave[x+1][y]];   if (temp != Xblank) break;
1440         temp = lev.android_array[cave[x-1][y]];   if (temp != Xblank) break;
1441         goto android_move;
1442
1443       case 2: /* SW,E,S,W,N,NW,SE,NE */
1444         temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1445         temp = lev.android_array[cave[x+1][y]];   if (temp != Xblank) break;
1446         temp = lev.android_array[cave[x][y+1]];   if (temp != Xblank) break;
1447         temp = lev.android_array[cave[x-1][y]];   if (temp != Xblank) break;
1448         temp = lev.android_array[cave[x][y-1]];   if (temp != Xblank) break;
1449         temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1450         temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1451         temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1452         goto android_move;
1453
1454       case 3: /* N,SE,NE,E,W,S,NW,SW */
1455         temp = lev.android_array[cave[x][y-1]];   if (temp != Xblank) break;
1456         temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1457         temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1458         temp = lev.android_array[cave[x+1][y]];   if (temp != Xblank) break;
1459         temp = lev.android_array[cave[x-1][y]];   if (temp != Xblank) break;
1460         temp = lev.android_array[cave[x][y+1]];   if (temp != Xblank) break;
1461         temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1462         temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1463         goto android_move;
1464
1465       case 4: /* SE,NW,E,NE,SW,W,N,S */
1466         temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1467         temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1468         temp = lev.android_array[cave[x+1][y]];   if (temp != Xblank) break;
1469         temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1470         temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1471         temp = lev.android_array[cave[x-1][y]];   if (temp != Xblank) break;
1472         temp = lev.android_array[cave[x][y-1]];   if (temp != Xblank) break;
1473         temp = lev.android_array[cave[x][y+1]];   if (temp != Xblank) break;
1474         goto android_move;
1475
1476       case 5: /* NE,W,SE,SW,S,N,E,NW */
1477         temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1478         temp = lev.android_array[cave[x-1][y]];   if (temp != Xblank) break;
1479         temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1480         temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1481         temp = lev.android_array[cave[x][y+1]];   if (temp != Xblank) break;
1482         temp = lev.android_array[cave[x][y-1]];   if (temp != Xblank) break;
1483         temp = lev.android_array[cave[x+1][y]];   if (temp != Xblank) break;
1484         temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1485         goto android_move;
1486
1487       case 6: /* E,N,SW,S,NW,NE,SE,W */
1488         temp = lev.android_array[cave[x+1][y]];   if (temp != Xblank) break;
1489         temp = lev.android_array[cave[x][y-1]];   if (temp != Xblank) break;
1490         temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1491         temp = lev.android_array[cave[x][y+1]];   if (temp != Xblank) break;
1492         temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1493         temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1494         temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1495         temp = lev.android_array[cave[x-1][y]];   if (temp != Xblank) break;
1496         goto android_move;
1497
1498       case 7: /* W,SW,NW,N,E,SE,NE,S */
1499         temp = lev.android_array[cave[x-1][y]];   if (temp != Xblank) break;
1500         temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1501         temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1502         temp = lev.android_array[cave[x][y-1]];   if (temp != Xblank) break;
1503         temp = lev.android_array[cave[x+1][y]];   if (temp != Xblank) break;
1504         temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1505         temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1506         temp = lev.android_array[cave[x][y+1]];   if (temp != Xblank) break;
1507         goto android_move;
1508     }
1509
1510     next[x][y] = temp;  /* the item we chose to clone */
1511     play_element_sound(x, y, SOUND_android_clone, temp);
1512
1513     switch (RANDOM(8))
1514     {
1515       /* randomly find a direction to move */
1516
1517       case 0: /* S,NE,W,NW,SE,E,SW,N */
1518         if (cave[x][y+1] == Xblank)   goto android_s;
1519         if (cave[x+1][y-1] == Xblank) goto android_ne;
1520         if (cave[x-1][y] == Xblank)   goto android_w;
1521         if (cave[x-1][y-1] == Xblank) goto android_nw;
1522         if (cave[x+1][y+1] == Xblank) goto android_se;
1523         if (cave[x+1][y] == Xblank)   goto android_e;
1524         if (cave[x-1][y+1] == Xblank) goto android_sw;
1525         if (cave[x][y-1] == Xblank)   goto android_n;
1526         goto android_move;
1527
1528       case 1: /* NW,SE,N,S,NE,SW,E,W */
1529         if (cave[x-1][y-1] == Xblank) goto android_nw;
1530         if (cave[x+1][y+1] == Xblank) goto android_se;
1531         if (cave[x][y-1] == Xblank)   goto android_n;
1532         if (cave[x][y+1] == Xblank)   goto android_s;
1533         if (cave[x+1][y-1] == Xblank) goto android_ne;
1534         if (cave[x-1][y+1] == Xblank) goto android_sw;
1535         if (cave[x+1][y] == Xblank)   goto android_e;
1536         if (cave[x-1][y] == Xblank)   goto android_w;
1537         goto android_move;
1538
1539       case 2: /* SW,E,S,W,N,NW,SE,NE */
1540         if (cave[x-1][y+1] == Xblank) goto android_sw;
1541         if (cave[x+1][y] == Xblank)   goto android_e;
1542         if (cave[x][y+1] == Xblank)   goto android_s;
1543         if (cave[x-1][y] == Xblank)   goto android_w;
1544         if (cave[x][y-1] == Xblank)   goto android_n;
1545         if (cave[x-1][y-1] == Xblank) goto android_nw;
1546         if (cave[x+1][y+1] == Xblank) goto android_se;
1547         if (cave[x+1][y-1] == Xblank) goto android_ne;
1548         goto android_move;
1549
1550       case 3: /* N,SE,NE,E,W,S,NW,SW */
1551         if (cave[x][y-1] == Xblank)   goto android_n;
1552         if (cave[x+1][y+1] == Xblank) goto android_se;
1553         if (cave[x+1][y-1] == Xblank) goto android_ne;
1554         if (cave[x+1][y] == Xblank)   goto android_e;
1555         if (cave[x-1][y] == Xblank)   goto android_w;
1556         if (cave[x][y+1] == Xblank)   goto android_s;
1557         if (cave[x-1][y-1] == Xblank) goto android_nw;
1558         if (cave[x-1][y+1] == Xblank) goto android_sw;
1559         goto android_move;
1560
1561       case 4: /* SE,NW,E,NE,SW,W,N,S */
1562         if (cave[x+1][y+1] == Xblank) goto android_se;
1563         if (cave[x-1][y-1] == Xblank) goto android_nw;
1564         if (cave[x+1][y] == Xblank)   goto android_e;
1565         if (cave[x+1][y-1] == Xblank) goto android_ne;
1566         if (cave[x-1][y+1] == Xblank) goto android_sw;
1567         if (cave[x-1][y] == Xblank)   goto android_w;
1568         if (cave[x][y-1] == Xblank)   goto android_n;
1569         if (cave[x][y+1] == Xblank)   goto android_s;
1570         goto android_move;
1571
1572       case 5: /* NE,W,SE,SW,S,N,E,NW */
1573         if (cave[x+1][y-1] == Xblank) goto android_ne;
1574         if (cave[x-1][y] == Xblank)   goto android_w;
1575         if (cave[x+1][y+1] == Xblank) goto android_se;
1576         if (cave[x-1][y+1] == Xblank) goto android_sw;
1577         if (cave[x][y+1] == Xblank)   goto android_s;
1578         if (cave[x][y-1] == Xblank)   goto android_n;
1579         if (cave[x+1][y] == Xblank)   goto android_e;
1580         if (cave[x-1][y-1] == Xblank) goto android_nw;
1581         goto android_move;
1582
1583       case 6: /* E,N,SW,S,NW,NE,SE,W */
1584         if (cave[x+1][y] == Xblank)   goto android_e;
1585         if (cave[x][y-1] == Xblank)   goto android_n;
1586         if (cave[x-1][y+1] == Xblank) goto android_sw;
1587         if (cave[x][y+1] == Xblank)   goto android_s;
1588         if (cave[x-1][y-1] == Xblank) goto android_nw;
1589         if (cave[x+1][y-1] == Xblank) goto android_ne;
1590         if (cave[x+1][y+1] == Xblank) goto android_se;
1591         if (cave[x-1][y] == Xblank)   goto android_w;
1592         goto android_move;
1593
1594       case 7: /* W,SW,NW,N,E,SE,NE,S */
1595         if (cave[x-1][y] == Xblank)   goto android_w;
1596         if (cave[x-1][y+1] == Xblank) goto android_sw;
1597         if (cave[x-1][y-1] == Xblank) goto android_nw;
1598         if (cave[x][y-1] == Xblank)   goto android_n;
1599         if (cave[x+1][y] == Xblank)   goto android_e;
1600         if (cave[x+1][y+1] == Xblank) goto android_se;
1601         if (cave[x+1][y-1] == Xblank) goto android_ne;
1602         if (cave[x][y+1] == Xblank)   goto android_s;
1603         goto android_move;
1604     }
1605   }
1606
1607  android_move:
1608   if (lev.android_move_cnt == 0)
1609   {
1610     if (cave[x-1][y-1] == Zplayer ||
1611         cave[x][y-1]   == Zplayer ||
1612         cave[x+1][y-1] == Zplayer ||
1613         cave[x-1][y]   == Zplayer ||
1614         cave[x+1][y]   == Zplayer ||
1615         cave[x-1][y+1] == Zplayer ||
1616         cave[x][y+1]   == Zplayer ||
1617         cave[x+1][y+1] == Zplayer)
1618       goto android_still;
1619
1620     set_nearest_player_xy(x, y, &dx, &dy);
1621
1622     next[x][y] = Xblank;        /* assume we will move */
1623     temp = ((x < dx) + 1 - (x > dx)) + ((y < dy) + 1 - (y > dy)) * 3;
1624
1625     if (RANDOM(2))
1626     {
1627       switch (temp)
1628       {
1629         /* attempt clockwise move first if direct path is blocked */
1630
1631         case 0: /* north west */
1632           if (tab_android_move[cave[x-1][y-1]]) goto android_nw;
1633           if (tab_android_move[cave[x][y-1]])   goto android_n;
1634           if (tab_android_move[cave[x-1][y]])   goto android_w;
1635           break;
1636
1637         case 1: /* north */
1638           if (tab_android_move[cave[x][y-1]])   goto android_n;
1639           if (tab_android_move[cave[x+1][y-1]]) goto android_ne;
1640           if (tab_android_move[cave[x-1][y-1]]) goto android_nw;
1641           break;
1642
1643         case 2: /* north east */
1644           if (tab_android_move[cave[x+1][y-1]]) goto android_ne;
1645           if (tab_android_move[cave[x+1][y]])   goto android_e;
1646           if (tab_android_move[cave[x][y-1]])   goto android_n;
1647           break;
1648
1649         case 3: /* west */
1650           if (tab_android_move[cave[x-1][y]])   goto android_w;
1651           if (tab_android_move[cave[x-1][y-1]]) goto android_nw;
1652           if (tab_android_move[cave[x-1][y+1]]) goto android_sw;
1653           break;
1654
1655         case 4: /* nowhere */
1656           break;
1657
1658         case 5: /* east */
1659           if (tab_android_move[cave[x+1][y]])   goto android_e;
1660           if (tab_android_move[cave[x+1][y+1]]) goto android_se;
1661           if (tab_android_move[cave[x+1][y-1]]) goto android_ne;
1662           break;
1663
1664         case 6: /* south west */
1665           if (tab_android_move[cave[x-1][y+1]]) goto android_sw;
1666           if (tab_android_move[cave[x-1][y]])   goto android_w;
1667           if (tab_android_move[cave[x][y+1]])   goto android_s;
1668           break;
1669
1670         case 7: /* south */
1671           if (tab_android_move[cave[x][y+1]])   goto android_s;
1672           if (tab_android_move[cave[x-1][y+1]]) goto android_sw;
1673           if (tab_android_move[cave[x+1][y+1]]) goto android_se;
1674           break;
1675
1676         case 8: /* south east */
1677           if (tab_android_move[cave[x+1][y+1]]) goto android_se;
1678           if (tab_android_move[cave[x][y+1]])   goto android_s;
1679           if (tab_android_move[cave[x+1][y]])   goto android_e;
1680           break;
1681       }
1682     }
1683     else
1684     {
1685       switch (temp)
1686       {
1687         /* attempt counterclockwise move first if direct path is blocked */
1688
1689         case 0: /* north west */
1690           if (tab_android_move[cave[x-1][y-1]]) goto android_nw;
1691           if (tab_android_move[cave[x-1][y]])   goto android_w;
1692           if (tab_android_move[cave[x][y-1]])   goto android_n;
1693           break;
1694
1695         case 1: /* north */
1696           if (tab_android_move[cave[x][y-1]])   goto android_n;
1697           if (tab_android_move[cave[x-1][y-1]]) goto android_nw;
1698           if (tab_android_move[cave[x+1][y-1]]) goto android_ne;
1699           break;
1700
1701         case 2: /* north east */
1702           if (tab_android_move[cave[x+1][y-1]]) goto android_ne;
1703           if (tab_android_move[cave[x][y-1]])   goto android_n;
1704           if (tab_android_move[cave[x+1][y]])   goto android_e;
1705           break;
1706
1707         case 3: /* west */
1708           if (tab_android_move[cave[x-1][y]])   goto android_w;
1709           if (tab_android_move[cave[x-1][y+1]]) goto android_sw;
1710           if (tab_android_move[cave[x-1][y-1]]) goto android_nw;
1711           break;
1712
1713         case 4: /* nowhere */
1714           break;
1715
1716         case 5: /* east */
1717           if (tab_android_move[cave[x+1][y]])   goto android_e;
1718           if (tab_android_move[cave[x+1][y-1]]) goto android_ne;
1719           if (tab_android_move[cave[x+1][y+1]]) goto android_se;
1720           break;
1721
1722         case 6: /* south west */
1723           if (tab_android_move[cave[x-1][y+1]]) goto android_sw;
1724           if (tab_android_move[cave[x][y+1]])   goto android_s;
1725           if (tab_android_move[cave[x-1][y]])   goto android_w;
1726           break;
1727
1728         case 7: /* south */
1729           if (tab_android_move[cave[x][y+1]])   goto android_s;
1730           if (tab_android_move[cave[x+1][y+1]]) goto android_se;
1731           if (tab_android_move[cave[x-1][y+1]]) goto android_sw;
1732           break;
1733
1734         case 8: /* south east */
1735           if (tab_android_move[cave[x+1][y+1]]) goto android_se;
1736           if (tab_android_move[cave[x+1][y]])   goto android_e;
1737           if (tab_android_move[cave[x][y+1]])   goto android_s;
1738           break;
1739       }
1740     }
1741   }
1742
1743  android_still:
1744   next[x][y] = Xandroid;
1745   return;
1746
1747  android_n:
1748   cave[x][y] = Yandroid_nB;
1749   cave[x][y-1] = Yandroid_n;
1750   next[x][y-1] = Xandroid;
1751   play_element_sound(x, y, SOUND_android_move, Xandroid);
1752   return;
1753
1754  android_ne:
1755   cave[x][y] = Yandroid_neB;
1756   cave[x+1][y-1] = Yandroid_ne;
1757   next[x+1][y-1] = Xandroid;
1758   play_element_sound(x, y, SOUND_android_move, Xandroid);
1759   return;
1760
1761  android_e:
1762   cave[x][y] = Yandroid_eB;
1763   cave[x+1][y] = Yandroid_e;
1764   next[x+1][y] = Xandroid;
1765   play_element_sound(x, y, SOUND_android_move, Xandroid);
1766   return;
1767
1768  android_se:
1769   cave[x][y] = Yandroid_seB;
1770   cave[x+1][y+1] = Yandroid_se;
1771   next[x+1][y+1] = Xandroid;
1772   play_element_sound(x, y, SOUND_android_move, Xandroid);
1773   return;
1774
1775  android_s:
1776   cave[x][y] = Yandroid_sB;
1777   cave[x][y+1] = Yandroid_s;
1778   next[x][y+1] = Xandroid;
1779   play_element_sound(x, y, SOUND_android_move, Xandroid);
1780   return;
1781
1782  android_sw:
1783   cave[x][y] = Yandroid_swB;
1784   cave[x-1][y+1] = Yandroid_sw;
1785   next[x-1][y+1] = Xandroid;
1786   play_element_sound(x, y, SOUND_android_move, Xandroid);
1787   return;
1788
1789  android_w:
1790   cave[x][y] = Yandroid_wB;
1791   cave[x-1][y] = Yandroid_w;
1792   next[x-1][y] = Xandroid;
1793   play_element_sound(x, y, SOUND_android_move, Xandroid);
1794   return;
1795
1796  android_nw:
1797   cave[x][y] = Yandroid_nwB;
1798   cave[x-1][y-1] = Yandroid_nw;
1799   next[x-1][y-1] = Xandroid;
1800   play_element_sound(x, y, SOUND_android_move, Xandroid);
1801   return;
1802 }
1803
1804 static void Landroid_1_n(int x, int y)
1805 {
1806   switch (cave[x][y-1])
1807   {
1808     case Xblank:
1809     case Xacid_splash_e:
1810     case Xacid_splash_w:
1811 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
1812     case Xfake_acid_1:
1813     case Xfake_acid_2:
1814     case Xfake_acid_3:
1815     case Xfake_acid_4:
1816     case Xfake_acid_5:
1817     case Xfake_acid_6:
1818     case Xfake_acid_7:
1819     case Xfake_acid_8:
1820 #endif
1821       cave[x][y] = Yandroid_nB;
1822       next[x][y] = Xblank;
1823       cave[x][y-1] = Yandroid_n;
1824       next[x][y-1] = Xandroid;
1825       play_element_sound(x, y, SOUND_android_move, Xandroid_1_n);
1826       return;
1827
1828     case Xacid_1:
1829     case Xacid_2:
1830     case Xacid_3:
1831     case Xacid_4:
1832     case Xacid_5:
1833     case Xacid_6:
1834     case Xacid_7:
1835     case Xacid_8:
1836       cave[x][y] = Yandroid_nB;
1837       next[x][y] = Xblank;
1838       if (cave[x+1][y-2] == Xblank)
1839         cave[x+1][y-2] = Xacid_splash_e;
1840       if (cave[x-1][y-2] == Xblank)
1841         cave[x-1][y-2] = Xacid_splash_w;
1842       play_element_sound(x, y, SOUND_acid, Xacid_1);
1843       return;
1844
1845     default:
1846       Landroid(x, y);
1847       return;
1848   }
1849 }
1850
1851 static void Landroid_2_n(int x, int y)
1852 {
1853   switch (cave[x][y-1])
1854   {
1855     case Xblank:
1856     case Xacid_splash_e:
1857     case Xacid_splash_w:
1858 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
1859     case Xfake_acid_1:
1860     case Xfake_acid_2:
1861     case Xfake_acid_3:
1862     case Xfake_acid_4:
1863     case Xfake_acid_5:
1864     case Xfake_acid_6:
1865     case Xfake_acid_7:
1866     case Xfake_acid_8:
1867 #endif
1868       cave[x][y] = Yandroid_nB;
1869       next[x][y] = Xblank;
1870       cave[x][y-1] = Yandroid_n;
1871       next[x][y-1] = Xandroid_1_n;
1872       play_element_sound(x, y, SOUND_android_move, Xandroid_2_n);
1873       return;
1874
1875     case Xacid_1:
1876     case Xacid_2:
1877     case Xacid_3:
1878     case Xacid_4:
1879     case Xacid_5:
1880     case Xacid_6:
1881     case Xacid_7:
1882     case Xacid_8:
1883       cave[x][y] = Yandroid_nB;
1884       next[x][y] = Xblank;
1885       if (cave[x+1][y-2] == Xblank)
1886         cave[x+1][y-2] = Xacid_splash_e;
1887       if (cave[x-1][y-2] == Xblank)
1888         cave[x-1][y-2] = Xacid_splash_w;
1889       play_element_sound(x, y, SOUND_acid, Xacid_1);
1890       return;
1891
1892     default:
1893       Landroid(x, y);
1894       return;
1895   }
1896 }
1897
1898 static void Landroid_1_e(int x, int y)
1899 {
1900   switch (cave[x+1][y])
1901   {
1902     case Xblank:
1903     case Xacid_splash_e:
1904     case Xacid_splash_w:
1905 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
1906     case Xfake_acid_1:
1907     case Xfake_acid_2:
1908     case Xfake_acid_3:
1909     case Xfake_acid_4:
1910     case Xfake_acid_5:
1911     case Xfake_acid_6:
1912     case Xfake_acid_7:
1913     case Xfake_acid_8:
1914 #endif
1915       cave[x][y] = Yandroid_eB;
1916       next[x][y] = Xblank;
1917       cave[x+1][y] = Yandroid_e;
1918       next[x+1][y] = Xandroid;
1919       play_element_sound(x, y, SOUND_android_move, Xandroid_1_e);
1920       return;
1921
1922     case Xacid_1:
1923     case Xacid_2:
1924     case Xacid_3:
1925     case Xacid_4:
1926     case Xacid_5:
1927     case Xacid_6:
1928     case Xacid_7:
1929     case Xacid_8:
1930       cave[x][y] = Yandroid_eB;
1931       next[x][y] = Xblank;
1932       if (cave[x+2][y-1] == Xblank)
1933         cave[x+2][y-1] = Xacid_splash_e;
1934       if (cave[x][y-1] == Xblank)
1935         cave[x][y-1] = Xacid_splash_w;
1936       play_element_sound(x, y, SOUND_acid, Xacid_1);
1937       return;
1938
1939     default:
1940       Landroid(x, y);
1941       return;
1942   }
1943 }
1944
1945 static void Landroid_2_e(int x, int y)
1946 {
1947   switch (cave[x+1][y])
1948   {
1949     case Xblank:
1950     case Xacid_splash_e:
1951     case Xacid_splash_w:
1952 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
1953     case Xfake_acid_1:
1954     case Xfake_acid_2:
1955     case Xfake_acid_3:
1956     case Xfake_acid_4:
1957     case Xfake_acid_5:
1958     case Xfake_acid_6:
1959     case Xfake_acid_7:
1960     case Xfake_acid_8:
1961 #endif
1962       cave[x][y] = Yandroid_eB;
1963       next[x][y] = Xblank;
1964       cave[x+1][y] = Yandroid_e;
1965       next[x+1][y] = Xandroid_1_e;
1966       play_element_sound(x, y, SOUND_android_move, Xandroid_2_e);
1967       return;
1968
1969     case Xacid_1:
1970     case Xacid_2:
1971     case Xacid_3:
1972     case Xacid_4:
1973     case Xacid_5:
1974     case Xacid_6:
1975     case Xacid_7:
1976     case Xacid_8:
1977       cave[x][y] = Yandroid_eB;
1978       next[x][y] = Xblank;
1979       if (cave[x+2][y-1] == Xblank)
1980         cave[x+2][y-1] = Xacid_splash_e;
1981       if (cave[x][y-1] == Xblank)
1982         cave[x][y-1] = Xacid_splash_w;
1983       play_element_sound(x, y, SOUND_acid, Xacid_1);
1984       return;
1985
1986     default:
1987       Landroid(x, y);
1988       return;
1989   }
1990 }
1991
1992 static void Landroid_1_s(int x, int y)
1993 {
1994   switch (cave[x][y+1])
1995   {
1996     case Xblank:
1997     case Xacid_splash_e:
1998     case Xacid_splash_w:
1999 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2000     case Xfake_acid_1:
2001     case Xfake_acid_2:
2002     case Xfake_acid_3:
2003     case Xfake_acid_4:
2004     case Xfake_acid_5:
2005     case Xfake_acid_6:
2006     case Xfake_acid_7:
2007     case Xfake_acid_8:
2008 #endif
2009       cave[x][y] = Yandroid_sB;
2010       next[x][y] = Xblank;
2011       cave[x][y+1] = Yandroid_s;
2012       next[x][y+1] = Xandroid;
2013       play_element_sound(x, y, SOUND_android_move, Xandroid_1_s);
2014       return;
2015
2016     case Xacid_1:
2017     case Xacid_2:
2018     case Xacid_3:
2019     case Xacid_4:
2020     case Xacid_5:
2021     case Xacid_6:
2022     case Xacid_7:
2023     case Xacid_8:
2024       cave[x][y] = Yandroid_sB;
2025       next[x][y] = Xblank;
2026       if (cave[x+1][y] == Xblank)
2027         cave[x+1][y] = Xacid_splash_e;
2028       if (cave[x-1][y] == Xblank)
2029         cave[x-1][y] = Xacid_splash_w;
2030       play_element_sound(x, y, SOUND_acid, Xacid_1);
2031       return;
2032
2033     default:
2034       Landroid(x, y);
2035       return;
2036   }
2037 }
2038
2039 static void Landroid_2_s(int x, int y)
2040 {
2041   switch (cave[x][y+1])
2042   {
2043     case Xblank:
2044     case Xacid_splash_e:
2045     case Xacid_splash_w:
2046 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2047     case Xfake_acid_1:
2048     case Xfake_acid_2:
2049     case Xfake_acid_3:
2050     case Xfake_acid_4:
2051     case Xfake_acid_5:
2052     case Xfake_acid_6:
2053     case Xfake_acid_7:
2054     case Xfake_acid_8:
2055 #endif
2056       cave[x][y] = Yandroid_sB;
2057       next[x][y] = Xblank;
2058       cave[x][y+1] = Yandroid_s;
2059       next[x][y+1] = Xandroid_1_s;
2060       play_element_sound(x, y, SOUND_android_move, Xandroid_2_s);
2061       return;
2062
2063     case Xacid_1:
2064     case Xacid_2:
2065     case Xacid_3:
2066     case Xacid_4:
2067     case Xacid_5:
2068     case Xacid_6:
2069     case Xacid_7:
2070     case Xacid_8:
2071       cave[x][y] = Yandroid_sB;
2072       next[x][y] = Xblank;
2073       if (cave[x+1][y] == Xblank)
2074         cave[x+1][y] = Xacid_splash_e;
2075       if (cave[x-1][y] == Xblank)
2076         cave[x-1][y] = Xacid_splash_w;
2077       play_element_sound(x, y, SOUND_acid, Xacid_1);
2078       return;
2079
2080     default:
2081       Landroid(x, y);
2082       return;
2083   }
2084 }
2085
2086 static void Landroid_1_w(int x, int y)
2087 {
2088   switch (cave[x-1][y])
2089   {
2090     case Xblank:
2091     case Xacid_splash_e:
2092     case Xacid_splash_w:
2093 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2094     case Xfake_acid_1:
2095     case Xfake_acid_2:
2096     case Xfake_acid_3:
2097     case Xfake_acid_4:
2098     case Xfake_acid_5:
2099     case Xfake_acid_6:
2100     case Xfake_acid_7:
2101     case Xfake_acid_8:
2102 #endif
2103       cave[x][y] = Yandroid_wB;
2104       next[x][y] = Xblank;
2105       cave[x-1][y] = Yandroid_w;
2106       next[x-1][y] = Xandroid;
2107       play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
2108       return;
2109
2110     case Xacid_1:
2111     case Xacid_2:
2112     case Xacid_3:
2113     case Xacid_4:
2114     case Xacid_5:
2115     case Xacid_6:
2116     case Xacid_7:
2117     case Xacid_8:
2118       cave[x][y] = Yandroid_wB;
2119       next[x][y] = Xblank;
2120       if (cave[x][y-1] == Xblank)
2121         cave[x][y-1] = Xacid_splash_e;
2122       if (cave[x-2][y-1] == Xblank)
2123         cave[x-2][y-1] = Xacid_splash_w;
2124       play_element_sound(x, y, SOUND_acid, Xacid_1);
2125       return;
2126
2127     default:
2128       Landroid(x, y);
2129       return;
2130   }
2131 }
2132
2133 static void Landroid_2_w(int x, int y)
2134 {
2135   switch (cave[x-1][y])
2136   {
2137     case Xblank:
2138     case Xacid_splash_e:
2139     case Xacid_splash_w:
2140 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2141     case Xfake_acid_1:
2142     case Xfake_acid_2:
2143     case Xfake_acid_3:
2144     case Xfake_acid_4:
2145     case Xfake_acid_5:
2146     case Xfake_acid_6:
2147     case Xfake_acid_7:
2148     case Xfake_acid_8:
2149 #endif
2150       cave[x][y] = Yandroid_wB;
2151       next[x][y] = Xblank;
2152       cave[x-1][y] = Yandroid_w;
2153       next[x-1][y] = Xandroid_1_w;
2154       play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
2155       return;
2156
2157     case Xacid_1:
2158     case Xacid_2:
2159     case Xacid_3:
2160     case Xacid_4:
2161     case Xacid_5:
2162     case Xacid_6:
2163     case Xacid_7:
2164     case Xacid_8:
2165       cave[x][y] = Yandroid_wB;
2166       next[x][y] = Xblank;
2167       if (cave[x][y-1] == Xblank)
2168         cave[x][y-1] = Xacid_splash_e;
2169       if (cave[x-2][y-1] == Xblank)
2170         cave[x-2][y-1] = Xacid_splash_w;
2171       play_element_sound(x, y, SOUND_acid, Xacid_1);
2172       return;
2173
2174     default:
2175       Landroid(x, y);
2176       return;
2177   }
2178 }
2179
2180 static void Leater_n(int x, int y)
2181 {
2182   if (cave[x+1][y] == Xdiamond)
2183   {
2184     cave[x+1][y] = Ydiamond_blank;
2185     next[x+1][y] = Xblank;
2186     play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2187     return;
2188   }
2189
2190   if (cave[x][y+1] == Xdiamond)
2191   {
2192     cave[x][y+1] = Ydiamond_blank;
2193     next[x][y+1] = Xblank;
2194     play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2195     return;
2196   }
2197
2198   if (cave[x-1][y] == Xdiamond)
2199   {
2200     cave[x-1][y] = Ydiamond_blank;
2201     next[x-1][y] = Xblank;
2202     play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2203     return;
2204   }
2205
2206   if (cave[x][y-1] == Xdiamond)
2207   {
2208     cave[x][y-1] = Ydiamond_blank;
2209     next[x][y-1] = Xblank;
2210     play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2211     return;
2212   }
2213
2214   switch (cave[x][y-1])
2215   {
2216     case Xblank:
2217     case Xacid_splash_e:
2218     case Xacid_splash_w:
2219 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2220     case Xfake_acid_1:
2221     case Xfake_acid_2:
2222     case Xfake_acid_3:
2223     case Xfake_acid_4:
2224     case Xfake_acid_5:
2225     case Xfake_acid_6:
2226     case Xfake_acid_7:
2227     case Xfake_acid_8:
2228 #endif
2229     case Xplant:
2230     case Yplant:
2231     case Zplayer:
2232       cave[x][y] = Yeater_nB;
2233       next[x][y] = Xblank;
2234       cave[x][y-1] = Yeater_n;
2235       next[x][y-1] = Xeater_n;
2236       return;
2237
2238     case Xacid_1:
2239     case Xacid_2:
2240     case Xacid_3:
2241     case Xacid_4:
2242     case Xacid_5:
2243     case Xacid_6:
2244     case Xacid_7:
2245     case Xacid_8:
2246       cave[x][y] = Yeater_nB;
2247       next[x][y] = Xblank;
2248       if (cave[x+1][y-2] == Xblank)
2249         cave[x+1][y-2] = Xacid_splash_e;
2250       if (cave[x-1][y-2] == Xblank)
2251         cave[x-1][y-2] = Xacid_splash_w;
2252       play_element_sound(x, y, SOUND_acid, Xacid_1);
2253       return;
2254
2255     default:
2256       next[x][y] = RANDOM(2) ? Xeater_e : Xeater_w;
2257       play_element_sound(x, y, SOUND_eater, Xeater_n);
2258       return;
2259   }
2260 }
2261
2262 static void Leater_e(int x, int y)
2263 {
2264   if (cave[x][y+1] == Xdiamond)
2265   {
2266     cave[x][y+1] = Ydiamond_blank;
2267     next[x][y+1] = Xblank;
2268     play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2269     return;
2270   }
2271
2272   if (cave[x-1][y] == Xdiamond)
2273   {
2274     cave[x-1][y] = Ydiamond_blank;
2275     next[x-1][y] = Xblank;
2276     play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2277     return;
2278   }
2279
2280   if (cave[x][y-1] == Xdiamond)
2281   {
2282     cave[x][y-1] = Ydiamond_blank;
2283     next[x][y-1] = Xblank;
2284     play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2285     return;
2286   }
2287
2288   if (cave[x+1][y] == Xdiamond)
2289   {
2290     cave[x+1][y] = Ydiamond_blank;
2291     next[x+1][y] = Xblank;
2292     play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2293     return;
2294   }
2295
2296   switch (cave[x+1][y])
2297   {
2298     case Xblank:
2299     case Xacid_splash_e:
2300     case Xacid_splash_w:
2301 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2302     case Xfake_acid_1:
2303     case Xfake_acid_2:
2304     case Xfake_acid_3:
2305     case Xfake_acid_4:
2306     case Xfake_acid_5:
2307     case Xfake_acid_6:
2308     case Xfake_acid_7:
2309     case Xfake_acid_8:
2310 #endif
2311     case Xplant:
2312     case Yplant:
2313     case Zplayer:
2314       cave[x][y] = Yeater_eB;
2315       next[x][y] = Xblank;
2316       cave[x+1][y] = Yeater_e;
2317       next[x+1][y] = Xeater_e;
2318       return;
2319
2320     case Xacid_1:
2321     case Xacid_2:
2322     case Xacid_3:
2323     case Xacid_4:
2324     case Xacid_5:
2325     case Xacid_6:
2326     case Xacid_7:
2327     case Xacid_8:
2328       cave[x][y] = Yeater_eB;
2329       next[x][y] = Xblank;
2330       if (cave[x+2][y-1] == Xblank)
2331         cave[x+2][y-1] = Xacid_splash_e;
2332       if (cave[x][y-1] == Xblank)
2333         cave[x][y-1] = Xacid_splash_w;
2334       play_element_sound(x, y, SOUND_acid, Xacid_1);
2335       return;
2336
2337     default:
2338       next[x][y] = RANDOM(2) ? Xeater_n : Xeater_s;
2339       play_element_sound(x, y, SOUND_eater, Xeater_e);
2340       return;
2341   }
2342 }
2343
2344 static void Leater_s(int x, int y)
2345 {
2346   if (cave[x-1][y] == Xdiamond)
2347   {
2348     cave[x-1][y] = Ydiamond_blank;
2349     next[x-1][y] = Xblank;
2350     play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2351     return;
2352   }
2353
2354   if (cave[x][y-1] == Xdiamond)
2355   {
2356     cave[x][y-1] = Ydiamond_blank;
2357     next[x][y-1] = Xblank;
2358     play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2359     return;
2360   }
2361
2362   if (cave[x+1][y] == Xdiamond)
2363   {
2364     cave[x+1][y] = Ydiamond_blank;
2365     next[x+1][y] = Xblank;
2366     play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2367     return;
2368   }
2369
2370   if (cave[x][y+1] == Xdiamond)
2371   {
2372     cave[x][y+1] = Ydiamond_blank;
2373     next[x][y+1] = Xblank;
2374     play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2375     return;
2376   }
2377
2378   switch (cave[x][y+1])
2379   {
2380     case Xblank:
2381     case Xacid_splash_e:
2382     case Xacid_splash_w:
2383 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2384     case Xfake_acid_1:
2385     case Xfake_acid_2:
2386     case Xfake_acid_3:
2387     case Xfake_acid_4:
2388     case Xfake_acid_5:
2389     case Xfake_acid_6:
2390     case Xfake_acid_7:
2391     case Xfake_acid_8:
2392 #endif
2393     case Xplant:
2394     case Yplant:
2395     case Zplayer:
2396       cave[x][y] = Yeater_sB;
2397       next[x][y] = Xblank;
2398       cave[x][y+1] = Yeater_s;
2399       next[x][y+1] = Xeater_s;
2400       return;
2401
2402     case Xacid_1:
2403     case Xacid_2:
2404     case Xacid_3:
2405     case Xacid_4:
2406     case Xacid_5:
2407     case Xacid_6:
2408     case Xacid_7:
2409     case Xacid_8:
2410       cave[x][y] = Yeater_sB;
2411       next[x][y] = Xblank;
2412       if (cave[x+1][y] == Xblank)
2413         cave[x+1][y] = Xacid_splash_e;
2414       if (cave[x-1][y] == Xblank)
2415         cave[x-1][y] = Xacid_splash_w;
2416       play_element_sound(x, y, SOUND_acid, Xacid_1);
2417       return;
2418
2419     default:
2420       next[x][y] = RANDOM(2) ? Xeater_e : Xeater_w;
2421       play_element_sound(x, y, SOUND_eater, Xeater_s);
2422       return;
2423   }
2424 }
2425
2426 static void Leater_w(int x, int y)
2427 {
2428   if (cave[x][y-1] == Xdiamond)
2429   {
2430     cave[x][y-1] = Ydiamond_blank;
2431     next[x][y-1] = Xblank;
2432     play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2433     return;
2434   }
2435
2436   if (cave[x+1][y] == Xdiamond)
2437   {
2438     cave[x+1][y] = Ydiamond_blank;
2439     next[x+1][y] = Xblank;
2440     play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2441     return;
2442   }
2443
2444   if (cave[x][y+1] == Xdiamond)
2445   {
2446     cave[x][y+1] = Ydiamond_blank;
2447     next[x][y+1] = Xblank;
2448     play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2449     return;
2450   }
2451
2452   if (cave[x-1][y] == Xdiamond)
2453   {
2454     cave[x-1][y] = Ydiamond_blank;
2455     next[x-1][y] = Xblank;
2456     play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2457     return;
2458   }
2459
2460   switch (cave[x-1][y])
2461   {
2462     case Xblank:
2463     case Xacid_splash_e:
2464     case Xacid_splash_w:
2465 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2466     case Xfake_acid_1:
2467     case Xfake_acid_2:
2468     case Xfake_acid_3:
2469     case Xfake_acid_4:
2470     case Xfake_acid_5:
2471     case Xfake_acid_6:
2472     case Xfake_acid_7:
2473     case Xfake_acid_8:
2474 #endif
2475     case Xplant:
2476     case Yplant:
2477     case Zplayer:
2478       cave[x][y] = Yeater_wB;
2479       next[x][y] = Xblank;
2480       cave[x-1][y] = Yeater_w;
2481       next[x-1][y] = Xeater_w;
2482       return;
2483
2484     case Xacid_1:
2485     case Xacid_2:
2486     case Xacid_3:
2487     case Xacid_4:
2488     case Xacid_5:
2489     case Xacid_6:
2490     case Xacid_7:
2491     case Xacid_8:
2492       cave[x][y] = Yeater_wB;
2493       next[x][y] = Xblank;
2494       if (cave[x][y-1] == Xblank)
2495         cave[x][y-1] = Xacid_splash_e;
2496       if (cave[x-2][y-1] == Xblank)
2497         cave[x-2][y-1] = Xacid_splash_w;
2498       play_element_sound(x, y, SOUND_acid, Xacid_1);
2499       return;
2500
2501     default:
2502       next[x][y] = RANDOM(2) ? Xeater_n : Xeater_s;
2503       play_element_sound(x, y, SOUND_eater, Xeater_w);
2504       return;
2505   }
2506 }
2507
2508 static void Lalien(int x, int y)
2509 {
2510   int dx, dy;
2511
2512   if (lev.wheel_cnt)
2513   {
2514     dx = lev.wheel_x;
2515     dy = lev.wheel_y;
2516   }
2517   else
2518   {
2519     set_nearest_player_xy(x, y, &dx, &dy);
2520   }
2521
2522   if (RANDOM(2))
2523   {
2524     if (y > dy)
2525     {
2526       switch (cave[x][y-1])
2527       {
2528         case Xblank:
2529         case Xacid_splash_e:
2530         case Xacid_splash_w:
2531 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2532         case Xfake_acid_1:
2533         case Xfake_acid_2:
2534         case Xfake_acid_3:
2535         case Xfake_acid_4:
2536         case Xfake_acid_5:
2537         case Xfake_acid_6:
2538         case Xfake_acid_7:
2539         case Xfake_acid_8:
2540 #endif
2541         case Xplant:
2542         case Yplant:
2543         case Zplayer:
2544           cave[x][y] = Yalien_nB;
2545           next[x][y] = Xblank;
2546           cave[x][y-1] = Yalien_n;
2547           next[x][y-1] = Xalien_pause;
2548           play_element_sound(x, y, SOUND_alien, Xalien);
2549           return;
2550
2551         case Xacid_1:
2552         case Xacid_2:
2553         case Xacid_3:
2554         case Xacid_4:
2555         case Xacid_5:
2556         case Xacid_6:
2557         case Xacid_7:
2558         case Xacid_8:
2559           cave[x][y] = Yalien_nB;
2560           next[x][y] = Xblank;
2561           if (cave[x+1][y-2] == Xblank)
2562             cave[x+1][y-2] = Xacid_splash_e;
2563           if (cave[x-1][y-2] == Xblank)
2564             cave[x-1][y-2] = Xacid_splash_w;
2565           play_element_sound(x, y, SOUND_acid, Xacid_1);
2566           return;
2567       }
2568     }
2569     else if (y < dy)
2570     {
2571       switch (cave[x][y+1])
2572       {
2573         case Xblank:
2574         case Xacid_splash_e:
2575         case Xacid_splash_w:
2576 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2577         case Xfake_acid_1:
2578         case Xfake_acid_2:
2579         case Xfake_acid_3:
2580         case Xfake_acid_4:
2581         case Xfake_acid_5:
2582         case Xfake_acid_6:
2583         case Xfake_acid_7:
2584         case Xfake_acid_8:
2585 #endif
2586         case Xplant:
2587         case Yplant:
2588         case Zplayer:
2589           cave[x][y] = Yalien_sB;
2590           next[x][y] = Xblank;
2591           cave[x][y+1] = Yalien_s;
2592           next[x][y+1] = Xalien_pause;
2593           play_element_sound(x, y, SOUND_alien, Xalien);
2594           return;
2595
2596         case Xacid_1:
2597         case Xacid_2:
2598         case Xacid_3:
2599         case Xacid_4:
2600         case Xacid_5:
2601         case Xacid_6:
2602         case Xacid_7:
2603         case Xacid_8:
2604           cave[x][y] = Yalien_sB;
2605           next[x][y] = Xblank;
2606           if (cave[x+1][y] == Xblank)
2607             cave[x+1][y] = Xacid_splash_e;
2608           if (cave[x-1][y] == Xblank)
2609             cave[x-1][y] = Xacid_splash_w;
2610           play_element_sound(x, y, SOUND_acid, Xacid_1);
2611           return;
2612       }
2613     }
2614   }
2615   else
2616   {
2617     if (x < dx)
2618     {
2619       switch (cave[x+1][y])
2620       {
2621         case Xblank:
2622         case Xacid_splash_e:
2623         case Xacid_splash_w:
2624 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2625         case Xfake_acid_1:
2626         case Xfake_acid_2:
2627         case Xfake_acid_3:
2628         case Xfake_acid_4:
2629         case Xfake_acid_5:
2630         case Xfake_acid_6:
2631         case Xfake_acid_7:
2632         case Xfake_acid_8:
2633 #endif
2634         case Xplant:
2635         case Yplant:
2636         case Zplayer:
2637           cave[x][y] = Yalien_eB;
2638           next[x][y] = Xblank;
2639           cave[x+1][y] = Yalien_e;
2640           next[x+1][y] = Xalien_pause;
2641           play_element_sound(x, y, SOUND_alien, Xalien);
2642           return;
2643
2644         case Xacid_1:
2645         case Xacid_2:
2646         case Xacid_3:
2647         case Xacid_4:
2648         case Xacid_5:
2649         case Xacid_6:
2650         case Xacid_7:
2651         case Xacid_8:
2652           cave[x][y] = Yalien_eB;
2653           next[x][y] = Xblank;
2654           if (cave[x+2][y-1] == Xblank)
2655             cave[x+2][y-1] = Xacid_splash_e;
2656           if (cave[x][y-1] == Xblank)
2657             cave[x][y-1] = Xacid_splash_w;
2658           play_element_sound(x, y, SOUND_acid, Xacid_1);
2659           return;
2660       }
2661     }
2662     else if (x > dx)
2663     {
2664       switch (cave[x-1][y])
2665       {
2666         case Xblank:
2667         case Xacid_splash_e:
2668         case Xacid_splash_w:
2669 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2670         case Xfake_acid_1:
2671         case Xfake_acid_2:
2672         case Xfake_acid_3:
2673         case Xfake_acid_4:
2674         case Xfake_acid_5:
2675         case Xfake_acid_6:
2676         case Xfake_acid_7:
2677         case Xfake_acid_8:
2678 #endif
2679         case Xplant:
2680         case Yplant:
2681         case Zplayer:
2682           cave[x][y] = Yalien_wB;
2683           next[x][y] = Xblank;
2684           cave[x-1][y] = Yalien_w;
2685           next[x-1][y] = Xalien_pause;
2686           play_element_sound(x, y, SOUND_alien, Xalien);
2687           return;
2688
2689         case Xacid_1:
2690         case Xacid_2:
2691         case Xacid_3:
2692         case Xacid_4:
2693         case Xacid_5:
2694         case Xacid_6:
2695         case Xacid_7:
2696         case Xacid_8:
2697           cave[x][y] = Yalien_wB;
2698           next[x][y] = Xblank;
2699           if (cave[x][y-1] == Xblank)
2700             cave[x][y-1] = Xacid_splash_e;
2701           if (cave[x-2][y-1] == Xblank)
2702             cave[x-2][y-1] = Xacid_splash_w;
2703           play_element_sound(x, y, SOUND_acid, Xacid_1);
2704           return;
2705       }
2706     }
2707   }
2708 }
2709
2710 static void Lalien_pause(int x, int y)
2711 {
2712   next[x][y] = Xalien;
2713 }
2714
2715 static void Lbug_n(int x, int y)
2716 {
2717   switch (cave[x][y-1])
2718   {
2719     case Xblank:
2720     case Xacid_splash_e:
2721     case Xacid_splash_w:
2722 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2723     case Xfake_acid_1:
2724     case Xfake_acid_2:
2725     case Xfake_acid_3:
2726     case Xfake_acid_4:
2727     case Xfake_acid_5:
2728     case Xfake_acid_6:
2729     case Xfake_acid_7:
2730     case Xfake_acid_8:
2731 #endif
2732     case Xplant:
2733     case Yplant:
2734     case Zplayer:
2735       cave[x][y] = Ybug_nB;
2736       next[x][y] = Xblank;
2737       cave[x][y-1] = Ybug_n;
2738       next[x][y-1] = Xbug_1_n;
2739       play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2740       return;
2741
2742     case Xacid_1:
2743     case Xacid_2:
2744     case Xacid_3:
2745     case Xacid_4:
2746     case Xacid_5:
2747     case Xacid_6:
2748     case Xacid_7:
2749     case Xacid_8:
2750       cave[x][y] = Ybug_nB;
2751       next[x][y] = Xblank;
2752       if (cave[x+1][y-2] == Xblank)
2753         cave[x+1][y-2] = Xacid_splash_e;
2754       if (cave[x-1][y-2] == Xblank)
2755         cave[x-1][y-2] = Xacid_splash_w;
2756       play_element_sound(x, y, SOUND_acid, Xacid_1);
2757       return;
2758
2759     default:
2760       cave[x][y] = Ybug_n_w;
2761       next[x][y] = Xbug_2_w;
2762       play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2763       return;
2764   }
2765 }
2766
2767 static void Lbug_1_n(int x, int y)
2768 {
2769   if (tab_amoeba[cave[x][y-1]] ||
2770       tab_amoeba[cave[x+1][y]] ||
2771       tab_amoeba[cave[x][y+1]] ||
2772       tab_amoeba[cave[x-1][y]])
2773   {
2774     Lboom_bug(x, y, Xbug_1_n);
2775
2776     return;
2777   }
2778
2779   switch (cave[x+1][y])
2780   {
2781     case Xblank:
2782     case Xacid_splash_e:
2783     case Xacid_splash_w:
2784 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2785     case Xfake_acid_1:
2786     case Xfake_acid_2:
2787     case Xfake_acid_3:
2788     case Xfake_acid_4:
2789     case Xfake_acid_5:
2790     case Xfake_acid_6:
2791     case Xfake_acid_7:
2792     case Xfake_acid_8:
2793 #endif
2794     case Xplant:
2795     case Yplant:
2796     case Xacid_1:
2797     case Xacid_2:
2798     case Xacid_3:
2799     case Xacid_4:
2800     case Xacid_5:
2801     case Xacid_6:
2802     case Xacid_7:
2803     case Xacid_8:
2804     case Zplayer:
2805       cave[x][y] = Ybug_n_e;
2806       next[x][y] = Xbug_2_e;
2807       play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2808       return;
2809
2810     default:
2811       Lbug_n(x, y);
2812       return;
2813   }
2814 }
2815
2816 static void Lbug_2_n(int x, int y)
2817 {
2818   if (tab_amoeba[cave[x][y-1]] ||
2819       tab_amoeba[cave[x+1][y]] ||
2820       tab_amoeba[cave[x][y+1]] ||
2821       tab_amoeba[cave[x-1][y]])
2822   {
2823     Lboom_bug(x, y, Xbug_2_n);
2824
2825     return;
2826   }
2827
2828   Lbug_n(x, y);
2829 }
2830
2831 static void Lbug_e(int x, int y)
2832 {
2833   switch (cave[x+1][y])
2834   {
2835     case Xblank:
2836     case Xacid_splash_e:
2837     case Xacid_splash_w:
2838 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2839     case Xfake_acid_1:
2840     case Xfake_acid_2:
2841     case Xfake_acid_3:
2842     case Xfake_acid_4:
2843     case Xfake_acid_5:
2844     case Xfake_acid_6:
2845     case Xfake_acid_7:
2846     case Xfake_acid_8:
2847 #endif
2848     case Xplant:
2849     case Yplant:
2850     case Zplayer:
2851       cave[x][y] = Ybug_eB;
2852       next[x][y] = Xblank;
2853       cave[x+1][y] = Ybug_e;
2854       next[x+1][y] = Xbug_1_e;
2855       play_element_sound(x, y, SOUND_bug, Xbug_1_e);
2856       return;
2857
2858     case Xacid_1:
2859     case Xacid_2:
2860     case Xacid_3:
2861     case Xacid_4:
2862     case Xacid_5:
2863     case Xacid_6:
2864     case Xacid_7:
2865     case Xacid_8:
2866       cave[x][y] = Ybug_eB;
2867       next[x][y] = Xblank;
2868       if (cave[x+2][y-1] == Xblank)
2869         cave[x+2][y-1] = Xacid_splash_e;
2870       if (cave[x][y-1] == Xblank)
2871         cave[x][y-1] = Xacid_splash_w;
2872       play_element_sound(x, y, SOUND_acid, Xacid_1);
2873       return;
2874
2875     default:
2876       cave[x][y] = Ybug_e_n;
2877       next[x][y] = Xbug_2_n;
2878       play_element_sound(x, y, SOUND_bug, Xbug_1_e);
2879       return;
2880   }
2881 }
2882
2883 static void Lbug_1_e(int x, int y)
2884 {
2885   if (tab_amoeba[cave[x][y-1]] ||
2886       tab_amoeba[cave[x+1][y]] ||
2887       tab_amoeba[cave[x][y+1]] ||
2888       tab_amoeba[cave[x-1][y]])
2889   {
2890     Lboom_bug(x, y, Xbug_1_e);
2891
2892     return;
2893   }
2894
2895   switch (cave[x][y+1])
2896   {
2897     case Xblank:
2898     case Xacid_splash_e:
2899     case Xacid_splash_w:
2900 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2901     case Xfake_acid_1:
2902     case Xfake_acid_2:
2903     case Xfake_acid_3:
2904     case Xfake_acid_4:
2905     case Xfake_acid_5:
2906     case Xfake_acid_6:
2907     case Xfake_acid_7:
2908     case Xfake_acid_8:
2909 #endif
2910     case Xplant:
2911     case Yplant:
2912     case Xacid_1:
2913     case Xacid_2:
2914     case Xacid_3:
2915     case Xacid_4:
2916     case Xacid_5:
2917     case Xacid_6:
2918     case Xacid_7:
2919     case Xacid_8:
2920     case Zplayer:
2921       cave[x][y] = Ybug_e_s;
2922       next[x][y] = Xbug_2_s;
2923       play_element_sound(x, y, SOUND_bug, Xbug_1_e);
2924       return;
2925
2926     default:
2927       Lbug_e(x, y);
2928       return;
2929   }
2930 }
2931
2932 static void Lbug_2_e(int x, int y)
2933 {
2934   if (tab_amoeba[cave[x][y-1]] ||
2935       tab_amoeba[cave[x+1][y]] ||
2936       tab_amoeba[cave[x][y+1]] ||
2937       tab_amoeba[cave[x-1][y]])
2938   {
2939     Lboom_bug(x, y, Xbug_2_e);
2940
2941     return;
2942   }
2943
2944   Lbug_e(x, y);
2945 }
2946
2947 static void Lbug_s(int x, int y)
2948 {
2949   switch (cave[x][y+1])
2950   {
2951     case Xblank:
2952     case Xacid_splash_e:
2953     case Xacid_splash_w:
2954 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
2955     case Xfake_acid_1:
2956     case Xfake_acid_2:
2957     case Xfake_acid_3:
2958     case Xfake_acid_4:
2959     case Xfake_acid_5:
2960     case Xfake_acid_6:
2961     case Xfake_acid_7:
2962     case Xfake_acid_8:
2963 #endif
2964     case Xplant:
2965     case Yplant:
2966     case Zplayer:
2967       cave[x][y] = Ybug_sB;
2968       next[x][y] = Xblank;
2969       cave[x][y+1] = Ybug_s;
2970       next[x][y+1] = Xbug_1_s;
2971       play_element_sound(x, y, SOUND_bug, Xbug_1_s);
2972       return;
2973
2974     case Xacid_1:
2975     case Xacid_2:
2976     case Xacid_3:
2977     case Xacid_4:
2978     case Xacid_5:
2979     case Xacid_6:
2980     case Xacid_7:
2981     case Xacid_8:
2982       cave[x][y] = Ybug_sB;
2983       next[x][y] = Xblank;
2984       if (cave[x+1][y] == Xblank)
2985         cave[x+1][y] = Xacid_splash_e;
2986       if (cave[x-1][y] == Xblank)
2987         cave[x-1][y] = Xacid_splash_w;
2988       play_element_sound(x, y, SOUND_acid, Xacid_1);
2989       return;
2990
2991     default:
2992       cave[x][y] = Ybug_s_e;
2993       next[x][y] = Xbug_2_e;
2994       play_element_sound(x, y, SOUND_bug, Xbug_1_s);
2995       return;
2996   }
2997 }
2998
2999 static void Lbug_1_s(int x, int y)
3000 {
3001   if (tab_amoeba[cave[x][y-1]] ||
3002       tab_amoeba[cave[x+1][y]] ||
3003       tab_amoeba[cave[x][y+1]] ||
3004       tab_amoeba[cave[x-1][y]])
3005   {
3006     Lboom_bug(x, y, Xbug_1_s);
3007
3008     return;
3009   }
3010
3011   switch (cave[x-1][y])
3012   {
3013     case Xblank:
3014     case Xacid_splash_e:
3015     case Xacid_splash_w:
3016 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
3017     case Xfake_acid_1:
3018     case Xfake_acid_2:
3019     case Xfake_acid_3:
3020     case Xfake_acid_4:
3021     case Xfake_acid_5:
3022     case Xfake_acid_6:
3023     case Xfake_acid_7:
3024     case Xfake_acid_8:
3025 #endif
3026     case Xplant:
3027     case Yplant:
3028     case Xacid_1:
3029     case Xacid_2:
3030     case Xacid_3:
3031     case Xacid_4:
3032     case Xacid_5:
3033     case Xacid_6:
3034     case Xacid_7:
3035     case Xacid_8:
3036     case Zplayer:
3037       cave[x][y] = Ybug_s_w;
3038       next[x][y] = Xbug_2_w;
3039       play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3040       return;
3041
3042     default:
3043       Lbug_s(x, y);
3044       return;
3045   }
3046 }
3047
3048 static void Lbug_2_s(int x, int y)
3049 {
3050   if (tab_amoeba[cave[x][y-1]] ||
3051       tab_amoeba[cave[x+1][y]] ||
3052       tab_amoeba[cave[x][y+1]] ||
3053       tab_amoeba[cave[x-1][y]])
3054   {
3055     Lboom_bug(x, y, Xbug_2_s);
3056
3057     return;
3058   }
3059
3060   Lbug_s(x, y);
3061 }
3062
3063 static void Lbug_w(int x, int y)
3064 {
3065   switch (cave[x-1][y])
3066   {
3067     case Xblank:
3068     case Xacid_splash_e:
3069     case Xacid_splash_w:
3070 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
3071     case Xfake_acid_1:
3072     case Xfake_acid_2:
3073     case Xfake_acid_3:
3074     case Xfake_acid_4:
3075     case Xfake_acid_5:
3076     case Xfake_acid_6:
3077     case Xfake_acid_7:
3078     case Xfake_acid_8:
3079 #endif
3080     case Xplant:
3081     case Yplant:
3082     case Zplayer:
3083       cave[x][y] = Ybug_wB;
3084       next[x][y] = Xblank;
3085       cave[x-1][y] = Ybug_w;
3086       next[x-1][y] = Xbug_1_w;
3087       play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3088       return;
3089
3090     case Xacid_1:
3091     case Xacid_2:
3092     case Xacid_3:
3093     case Xacid_4:
3094     case Xacid_5:
3095     case Xacid_6:
3096     case Xacid_7:
3097     case Xacid_8:
3098       cave[x][y] = Ybug_wB;
3099       next[x][y] = Xblank;
3100       if (cave[x][y-1] == Xblank)
3101         cave[x][y-1] = Xacid_splash_e;
3102       if (cave[x-2][y-1] == Xblank)
3103         cave[x-2][y-1] = Xacid_splash_w;
3104       play_element_sound(x, y, SOUND_acid, Xacid_1);
3105       return;
3106
3107     default:
3108       cave[x][y] = Ybug_w_s;
3109       next[x][y] = Xbug_2_s;
3110       play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3111       return;
3112   }
3113 }
3114
3115 static void Lbug_1_w(int x, int y)
3116 {
3117   if (tab_amoeba[cave[x][y-1]] ||
3118       tab_amoeba[cave[x+1][y]] ||
3119       tab_amoeba[cave[x][y+1]] ||
3120       tab_amoeba[cave[x-1][y]])
3121   {
3122     Lboom_bug(x, y, Xbug_1_w);
3123
3124     return;
3125   }
3126
3127   switch (cave[x][y-1])
3128   {
3129     case Xblank:
3130     case Xacid_splash_e:
3131     case Xacid_splash_w:
3132 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
3133     case Xfake_acid_1:
3134     case Xfake_acid_2:
3135     case Xfake_acid_3:
3136     case Xfake_acid_4:
3137     case Xfake_acid_5:
3138     case Xfake_acid_6:
3139     case Xfake_acid_7:
3140     case Xfake_acid_8:
3141 #endif
3142     case Xplant:
3143     case Yplant:
3144     case Xacid_1:
3145     case Xacid_2:
3146     case Xacid_3:
3147     case Xacid_4:
3148     case Xacid_5:
3149     case Xacid_6:
3150     case Xacid_7:
3151     case Xacid_8:
3152     case Zplayer:
3153       cave[x][y] = Ybug_w_n;
3154       next[x][y] = Xbug_2_n;
3155       play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3156       return;
3157
3158     default:
3159       Lbug_w(x, y);
3160       return;
3161   }
3162 }
3163
3164 static void Lbug_2_w(int x, int y)
3165 {
3166   if (tab_amoeba[cave[x][y-1]] ||
3167       tab_amoeba[cave[x+1][y]] ||
3168       tab_amoeba[cave[x][y+1]] ||
3169       tab_amoeba[cave[x-1][y]])
3170   {
3171     Lboom_bug(x, y, Xbug_2_w);
3172
3173     return;
3174   }
3175
3176   Lbug_w(x, y);
3177 }
3178
3179 static void Ltank_n(int x, int y)
3180 {
3181   switch (cave[x][y-1])
3182   {
3183     case Xblank:
3184     case Xacid_splash_e:
3185     case Xacid_splash_w:
3186 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
3187     case Xfake_acid_1:
3188     case Xfake_acid_2:
3189     case Xfake_acid_3:
3190     case Xfake_acid_4:
3191     case Xfake_acid_5:
3192     case Xfake_acid_6:
3193     case Xfake_acid_7:
3194     case Xfake_acid_8:
3195 #endif
3196     case Xplant:
3197     case Yplant:
3198     case Zplayer:
3199       cave[x][y] = Ytank_nB;
3200       next[x][y] = Xblank;
3201       cave[x][y-1] = Ytank_n;
3202       next[x][y-1] = Xtank_1_n;
3203       play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3204       return;
3205
3206     case Xacid_1:
3207     case Xacid_2:
3208     case Xacid_3:
3209     case Xacid_4:
3210     case Xacid_5:
3211     case Xacid_6:
3212     case Xacid_7:
3213     case Xacid_8:
3214       cave[x][y] = Ytank_nB;
3215       next[x][y] = Xblank;
3216       if (cave[x+1][y-2] == Xblank)
3217         cave[x+1][y-2] = Xacid_splash_e;
3218       if (cave[x-1][y-2] == Xblank)
3219         cave[x-1][y-2] = Xacid_splash_w;
3220       play_element_sound(x, y, SOUND_acid, Xacid_1);
3221       return;
3222
3223     default:
3224       cave[x][y] = Ytank_n_e;
3225       next[x][y] = Xtank_2_e;
3226       play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3227       return;
3228   }
3229 }
3230
3231 static void Ltank_1_n(int x, int y)
3232 {
3233   if (tab_amoeba[cave[x][y-1]] ||
3234       tab_amoeba[cave[x+1][y]] ||
3235       tab_amoeba[cave[x][y+1]] ||
3236       tab_amoeba[cave[x-1][y]])
3237   {
3238     Lboom_tank(x, y, Xtank_1_n);
3239
3240     return;
3241   }
3242
3243   switch (cave[x-1][y])
3244   {
3245     case Xblank:
3246     case Xacid_splash_e:
3247     case Xacid_splash_w:
3248 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
3249     case Xfake_acid_1:
3250     case Xfake_acid_2:
3251     case Xfake_acid_3:
3252     case Xfake_acid_4:
3253     case Xfake_acid_5:
3254     case Xfake_acid_6:
3255     case Xfake_acid_7:
3256     case Xfake_acid_8:
3257 #endif
3258     case Xplant:
3259     case Yplant:
3260     case Xacid_1:
3261     case Xacid_2:
3262     case Xacid_3:
3263     case Xacid_4:
3264     case Xacid_5:
3265     case Xacid_6:
3266     case Xacid_7:
3267     case Xacid_8:
3268     case Zplayer:
3269       cave[x][y] = Ytank_n_w;
3270       next[x][y] = Xtank_2_w;
3271       play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3272       return;
3273
3274     default:
3275       Ltank_n(x, y);
3276       return;
3277   }
3278 }
3279
3280 static void Ltank_2_n(int x, int y)
3281 {
3282   if (tab_amoeba[cave[x][y-1]] ||
3283       tab_amoeba[cave[x+1][y]] ||
3284       tab_amoeba[cave[x][y+1]] ||
3285       tab_amoeba[cave[x-1][y]])
3286   {
3287     Lboom_tank(x, y, Xtank_2_n);
3288
3289     return;
3290   }
3291
3292   Ltank_n(x, y);
3293 }
3294
3295 static void Ltank_e(int x, int y)
3296 {
3297   switch (cave[x+1][y])
3298   {
3299     case Xblank:
3300     case Xacid_splash_e:
3301     case Xacid_splash_w:
3302 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
3303     case Xfake_acid_1:
3304     case Xfake_acid_2:
3305     case Xfake_acid_3:
3306     case Xfake_acid_4:
3307     case Xfake_acid_5:
3308     case Xfake_acid_6:
3309     case Xfake_acid_7:
3310     case Xfake_acid_8:
3311 #endif
3312     case Xplant:
3313     case Yplant:
3314     case Zplayer:
3315       cave[x][y] = Ytank_eB;
3316       next[x][y] = Xblank;
3317       cave[x+1][y] = Ytank_e;
3318       next[x+1][y] = Xtank_1_e;
3319       play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3320       return;
3321
3322     case Xacid_1:
3323     case Xacid_2:
3324     case Xacid_3:
3325     case Xacid_4:
3326     case Xacid_5:
3327     case Xacid_6:
3328     case Xacid_7:
3329     case Xacid_8:
3330       cave[x][y] = Ytank_eB;
3331       next[x][y] = Xblank;
3332       if (cave[x+2][y-1] == Xblank)
3333         cave[x+2][y-1] = Xacid_splash_e;
3334       if (cave[x][y-1] == Xblank)
3335         cave[x][y-1] = Xacid_splash_w;
3336       play_element_sound(x, y, SOUND_acid, Xacid_1);
3337       return;
3338
3339     default:
3340       cave[x][y] = Ytank_e_s;
3341       next[x][y] = Xtank_2_s;
3342       play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3343       return;
3344   }
3345 }
3346
3347 static void Ltank_1_e(int x, int y)
3348 {
3349   if (tab_amoeba[cave[x][y-1]] ||
3350       tab_amoeba[cave[x+1][y]] ||
3351       tab_amoeba[cave[x][y+1]] ||
3352       tab_amoeba[cave[x-1][y]])
3353   {
3354     Lboom_tank(x, y, Xtank_1_e);
3355
3356     return;
3357   }
3358
3359   switch (cave[x][y-1])
3360   {
3361     case Xblank:
3362     case Xacid_splash_e:
3363     case Xacid_splash_w:
3364 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
3365     case Xfake_acid_1:
3366     case Xfake_acid_2:
3367     case Xfake_acid_3:
3368     case Xfake_acid_4:
3369     case Xfake_acid_5:
3370     case Xfake_acid_6:
3371     case Xfake_acid_7:
3372     case Xfake_acid_8:
3373 #endif
3374     case Xplant:
3375     case Yplant:
3376     case Xacid_1:
3377     case Xacid_2:
3378     case Xacid_3:
3379     case Xacid_4:
3380     case Xacid_5:
3381     case Xacid_6:
3382     case Xacid_7:
3383     case Xacid_8:
3384     case Zplayer:
3385       cave[x][y] = Ytank_e_n;
3386       next[x][y] = Xtank_2_n;
3387       play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3388       return;
3389
3390     default:
3391       Ltank_e(x, y);
3392       return;
3393   }
3394 }
3395
3396 static void Ltank_2_e(int x, int y)
3397 {
3398   if (tab_amoeba[cave[x][y-1]] ||
3399       tab_amoeba[cave[x+1][y]] ||
3400       tab_amoeba[cave[x][y+1]] ||
3401       tab_amoeba[cave[x-1][y]])
3402   {
3403     Lboom_tank(x, y, Xtank_2_e);
3404
3405     return;
3406   }
3407
3408   Ltank_e(x, y);
3409 }
3410
3411 static void Ltank_s(int x, int y)
3412 {
3413   switch (cave[x][y+1])
3414   {
3415     case Xblank:
3416     case Xacid_splash_e:
3417     case Xacid_splash_w:
3418 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
3419     case Xfake_acid_1:
3420     case Xfake_acid_2:
3421     case Xfake_acid_3:
3422     case Xfake_acid_4:
3423     case Xfake_acid_5:
3424     case Xfake_acid_6:
3425     case Xfake_acid_7:
3426     case Xfake_acid_8:
3427 #endif
3428     case Xplant:
3429     case Yplant:
3430     case Zplayer:
3431       cave[x][y] = Ytank_sB;
3432       next[x][y] = Xblank;
3433       cave[x][y+1] = Ytank_s;
3434       next[x][y+1] = Xtank_1_s;
3435       play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3436       return;
3437
3438     case Xacid_1:
3439     case Xacid_2:
3440     case Xacid_3:
3441     case Xacid_4:
3442     case Xacid_5:
3443     case Xacid_6:
3444     case Xacid_7:
3445     case Xacid_8:
3446       cave[x][y] = Ytank_sB;
3447       next[x][y] = Xblank;
3448       if (cave[x+1][y] == Xblank)
3449         cave[x+1][y] = Xacid_splash_e;
3450       if (cave[x-1][y] == Xblank)
3451         cave[x-1][y] = Xacid_splash_w;
3452       play_element_sound(x, y, SOUND_acid, Xacid_1);
3453       return;
3454
3455     default:
3456       cave[x][y] = Ytank_s_w;
3457       next[x][y] = Xtank_2_w;
3458       play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3459       return;
3460   }
3461 }
3462
3463 static void Ltank_1_s(int x, int y)
3464 {
3465   if (tab_amoeba[cave[x][y-1]] ||
3466       tab_amoeba[cave[x+1][y]] ||
3467       tab_amoeba[cave[x][y+1]] ||
3468       tab_amoeba[cave[x-1][y]])
3469   {
3470     Lboom_tank(x, y, Xtank_1_s);
3471
3472     return;
3473   }
3474
3475   switch (cave[x+1][y])
3476   {
3477     case Xblank:
3478     case Xacid_splash_e:
3479     case Xacid_splash_w:
3480 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
3481     case Xfake_acid_1:
3482     case Xfake_acid_2:
3483     case Xfake_acid_3:
3484     case Xfake_acid_4:
3485     case Xfake_acid_5:
3486     case Xfake_acid_6:
3487     case Xfake_acid_7:
3488     case Xfake_acid_8:
3489 #endif
3490     case Xplant:
3491     case Yplant:
3492     case Xacid_1:
3493     case Xacid_2:
3494     case Xacid_3:
3495     case Xacid_4:
3496     case Xacid_5:
3497     case Xacid_6:
3498     case Xacid_7:
3499     case Xacid_8:
3500     case Zplayer:
3501       cave[x][y] = Ytank_s_e;
3502       next[x][y] = Xtank_2_e;
3503       play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3504       return;
3505
3506     default:
3507       Ltank_s(x, y);
3508       return;
3509   }
3510 }
3511
3512 static void Ltank_2_s(int x, int y)
3513 {
3514   if (tab_amoeba[cave[x][y-1]] ||
3515       tab_amoeba[cave[x+1][y]] ||
3516       tab_amoeba[cave[x][y+1]] ||
3517       tab_amoeba[cave[x-1][y]])
3518   {
3519     Lboom_tank(x, y, Xtank_2_s);
3520
3521     return;
3522   }
3523
3524   Ltank_s(x, y);
3525 }
3526
3527 static void Ltank_w(int x, int y)
3528 {
3529   switch (cave[x-1][y])
3530   {
3531     case Xblank:
3532     case Xacid_splash_e:
3533     case Xacid_splash_w:
3534 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
3535     case Xfake_acid_1:
3536     case Xfake_acid_2:
3537     case Xfake_acid_3:
3538     case Xfake_acid_4:
3539     case Xfake_acid_5:
3540     case Xfake_acid_6:
3541     case Xfake_acid_7:
3542     case Xfake_acid_8:
3543 #endif
3544     case Xplant:
3545     case Yplant:
3546     case Zplayer:
3547       cave[x][y] = Ytank_wB;
3548       next[x][y] = Xblank;
3549       cave[x-1][y] = Ytank_w;
3550       next[x-1][y] = Xtank_1_w;
3551       play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3552       return;
3553
3554     case Xacid_1:
3555     case Xacid_2:
3556     case Xacid_3:
3557     case Xacid_4:
3558     case Xacid_5:
3559     case Xacid_6:
3560     case Xacid_7:
3561     case Xacid_8:
3562       cave[x][y] = Ytank_wB;
3563       next[x][y] = Xblank;
3564       if (cave[x][y-1] == Xblank)
3565         cave[x][y-1] = Xacid_splash_e;
3566       if (cave[x-2][y-1] == Xblank)
3567         cave[x-2][y-1] = Xacid_splash_w;
3568       play_element_sound(x, y, SOUND_acid, Xacid_1);
3569       return;
3570
3571     default:
3572       cave[x][y] = Ytank_w_n;
3573       next[x][y] = Xtank_2_n;
3574       play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3575       return;
3576   }
3577 }
3578
3579 static void Ltank_1_w(int x, int y)
3580 {
3581   if (tab_amoeba[cave[x][y-1]] ||
3582       tab_amoeba[cave[x+1][y]] ||
3583       tab_amoeba[cave[x][y+1]] ||
3584       tab_amoeba[cave[x-1][y]])
3585   {
3586     Lboom_tank(x, y, Xtank_1_w);
3587
3588     return;
3589   }
3590
3591   switch (cave[x][y+1])
3592   {
3593     case Xblank:
3594     case Xacid_splash_e:
3595     case Xacid_splash_w:
3596 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
3597     case Xfake_acid_1:
3598     case Xfake_acid_2:
3599     case Xfake_acid_3:
3600     case Xfake_acid_4:
3601     case Xfake_acid_5:
3602     case Xfake_acid_6:
3603     case Xfake_acid_7:
3604     case Xfake_acid_8:
3605 #endif
3606     case Xplant:
3607     case Yplant:
3608     case Xacid_1:
3609     case Xacid_2:
3610     case Xacid_3:
3611     case Xacid_4:
3612     case Xacid_5:
3613     case Xacid_6:
3614     case Xacid_7:
3615     case Xacid_8:
3616     case Zplayer:
3617       cave[x][y] = Ytank_w_s;
3618       next[x][y] = Xtank_2_s;
3619       play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3620       return;
3621
3622     default:
3623       Ltank_w(x, y);
3624       return;
3625   }
3626 }
3627
3628 static void Ltank_2_w(int x, int y)
3629 {
3630   if (tab_amoeba[cave[x][y-1]] ||
3631       tab_amoeba[cave[x+1][y]] ||
3632       tab_amoeba[cave[x][y+1]] ||
3633       tab_amoeba[cave[x-1][y]])
3634   {
3635     Lboom_tank(x, y, Xtank_2_w);
3636
3637     return;
3638   }
3639
3640   Ltank_w(x, y);
3641 }
3642
3643 static void Lemerald(int x, int y)
3644 {
3645   switch (cave[x][y+1])
3646   {
3647     case Xblank:
3648     case Xacid_splash_e:
3649     case Xacid_splash_w:
3650 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
3651     case Xfake_acid_1:
3652     case Xfake_acid_2:
3653     case Xfake_acid_3:
3654     case Xfake_acid_4:
3655     case Xfake_acid_5:
3656     case Xfake_acid_6:
3657     case Xfake_acid_7:
3658     case Xfake_acid_8:
3659 #endif
3660       cave[x][y] = Yemerald_sB;
3661       next[x][y] = Xblank;
3662       cave[x][y+1] = Yemerald_s;
3663       next[x][y+1] = Xemerald_fall;
3664       return;
3665
3666     case Xacid_1:
3667     case Xacid_2:
3668     case Xacid_3:
3669     case Xacid_4:
3670     case Xacid_5:
3671     case Xacid_6:
3672     case Xacid_7:
3673     case Xacid_8:
3674       cave[x][y] = Yemerald_sB;
3675       next[x][y] = Xblank;
3676       if (cave[x+1][y] == Xblank)
3677         cave[x+1][y] = Xacid_splash_e;
3678       if (cave[x-1][y] == Xblank)
3679         cave[x-1][y] = Xacid_splash_w;
3680       play_element_sound(x, y, SOUND_acid, Xacid_1);
3681       return;
3682
3683     case Xspring:
3684     case Xspring_pause:
3685     case Xspring_e:
3686     case Xspring_w:
3687     case Xandroid:
3688     case Xandroid_1_n:
3689     case Xandroid_2_n:
3690     case Xandroid_1_e:
3691     case Xandroid_2_e:
3692     case Xandroid_1_s:
3693     case Xandroid_2_s:
3694     case Xandroid_1_w:
3695     case Xandroid_2_w:
3696     case Xstone:
3697     case Xstone_pause:
3698     case Xemerald:
3699     case Xemerald_pause:
3700     case Xdiamond:
3701     case Xdiamond_pause:
3702     case Xbomb:
3703     case Xbomb_pause:
3704     case Xballoon:
3705     case Xacid_ne:
3706     case Xacid_nw:
3707     case Xball_1:
3708     case Xball_2:
3709     case Xnut:
3710     case Xnut_pause:
3711     case Xslidewall_ns:
3712     case Xslidewall_ew:
3713     case Xwonderwall:
3714     case Xkey_1:
3715     case Xkey_2:
3716     case Xkey_3:
3717     case Xkey_4:
3718     case Xkey_5:
3719     case Xkey_6:
3720     case Xkey_7:
3721     case Xkey_8:
3722     case Xbumper:
3723     case Xswitch:
3724     case Xsteel_1:
3725     case Xsteel_2:
3726     case Xsteel_3:
3727     case Xsteel_4:
3728     case Xwall_1:
3729     case Xwall_2:
3730     case Xwall_3:
3731     case Xwall_4:
3732     case Xroundwall_1:
3733     case Xroundwall_2:
3734     case Xroundwall_3:
3735     case Xroundwall_4:
3736       if (RANDOM(2))
3737       {
3738         if (tab_blank[cave[x+1][y]] && tab_acid[cave[x+1][y+1]])
3739         {
3740           cave[x][y] = Yemerald_eB;
3741           next[x][y] = Xblank;
3742           cave[x+1][y] = Yemerald_e;
3743           next[x+1][y] = Xemerald_pause;
3744           return;
3745         }
3746
3747         if (tab_blank[cave[x-1][y]] && tab_acid[cave[x-1][y+1]])
3748         {
3749           cave[x][y] = Yemerald_wB;
3750           next[x][y] = Xblank;
3751           cave[x-1][y] = Yemerald_w;
3752           next[x-1][y] = Xemerald_pause;
3753           return;
3754         }
3755       }
3756       else
3757       {
3758         if (tab_blank[cave[x-1][y]] && tab_acid[cave[x-1][y+1]])
3759         {
3760           cave[x][y] = Yemerald_wB;
3761           next[x][y] = Xblank;
3762           cave[x-1][y] = Yemerald_w;
3763           next[x-1][y] = Xemerald_pause;
3764           return;
3765         }
3766
3767         if (tab_blank[cave[x+1][y]] && tab_acid[cave[x+1][y+1]])
3768         {
3769           cave[x][y] = Yemerald_eB;
3770           next[x][y] = Xblank;
3771           cave[x+1][y] = Yemerald_e;
3772           next[x+1][y] = Xemerald_pause;
3773           return;
3774         }
3775       }
3776
3777     default:
3778       if (++lev.shine_cnt > 50)
3779       {
3780         lev.shine_cnt = RANDOM(8);
3781         cave[x][y] = Xemerald_shine;
3782       }
3783
3784       return;
3785   }
3786 }
3787
3788 static void Lemerald_pause(int x, int y)
3789 {
3790   switch (cave[x][y+1])
3791   {
3792     case Xblank:
3793     case Xacid_splash_e:
3794     case Xacid_splash_w:
3795 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
3796     case Xfake_acid_1:
3797     case Xfake_acid_2:
3798     case Xfake_acid_3:
3799     case Xfake_acid_4:
3800     case Xfake_acid_5:
3801     case Xfake_acid_6:
3802     case Xfake_acid_7:
3803     case Xfake_acid_8:
3804 #endif
3805       cave[x][y] = Yemerald_sB;
3806       next[x][y] = Xblank;
3807       cave[x][y+1] = Yemerald_s;
3808       next[x][y+1] = Xemerald_fall;
3809       return;
3810
3811     case Xacid_1:
3812     case Xacid_2:
3813     case Xacid_3:
3814     case Xacid_4:
3815     case Xacid_5:
3816     case Xacid_6:
3817     case Xacid_7:
3818     case Xacid_8:
3819       cave[x][y] = Yemerald_sB;
3820       next[x][y] = Xblank;
3821       if (cave[x+1][y] == Xblank)
3822         cave[x+1][y] = Xacid_splash_e;
3823       if (cave[x-1][y] == Xblank)
3824         cave[x-1][y] = Xacid_splash_w;
3825       play_element_sound(x, y, SOUND_acid, Xacid_1);
3826       return;
3827
3828     default:
3829       cave[x][y] = Xemerald;
3830       next[x][y] = Xemerald;
3831       return;
3832   }
3833 }
3834
3835 static void Lemerald_fall(int x, int y)
3836 {
3837   switch (cave[x][y+1])
3838   {
3839     case Xblank:
3840     case Xacid_splash_e:
3841     case Xacid_splash_w:
3842 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
3843     case Xfake_acid_1:
3844     case Xfake_acid_2:
3845     case Xfake_acid_3:
3846     case Xfake_acid_4:
3847     case Xfake_acid_5:
3848     case Xfake_acid_6:
3849     case Xfake_acid_7:
3850     case Xfake_acid_8:
3851 #endif
3852     case Zplayer:
3853       cave[x][y] = Yemerald_sB;
3854       next[x][y] = Xblank;
3855       cave[x][y+1] = Yemerald_s;
3856       next[x][y+1] = Xemerald_fall;
3857       return;
3858
3859     case Xacid_1:
3860     case Xacid_2:
3861     case Xacid_3:
3862     case Xacid_4:
3863     case Xacid_5:
3864     case Xacid_6:
3865     case Xacid_7:
3866     case Xacid_8:
3867       cave[x][y] = Yemerald_sB;
3868       next[x][y] = Xblank;
3869       if (cave[x+1][y] == Xblank)
3870         cave[x+1][y] = Xacid_splash_e;
3871       if (cave[x-1][y] == Xblank)
3872         cave[x-1][y] = Xacid_splash_w;
3873       play_element_sound(x, y, SOUND_acid, Xacid_1);
3874       return;
3875
3876     case Xwonderwall:
3877       if (lev.wonderwall_time)
3878       {
3879         lev.wonderwall_state = 1;
3880         cave[x][y] = Yemerald_sB;
3881         if (tab_blank[cave[x][y+2]])
3882         {
3883           cave[x][y+2] = Ydiamond_s;
3884           next[x][y+2] = Xdiamond_fall;
3885         }
3886
3887         next[x][y] = Xblank;
3888         play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
3889         return;
3890       }
3891
3892     default:
3893       cave[x][y] = Xemerald;
3894       next[x][y] = Xemerald;
3895       play_element_sound(x, y, SOUND_diamond, Xemerald);
3896       return;
3897   }
3898 }
3899
3900 static void Ldiamond(int x, int y)
3901 {
3902   switch (cave[x][y+1])
3903   {
3904     case Xblank:
3905     case Xacid_splash_e:
3906     case Xacid_splash_w:
3907 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
3908     case Xfake_acid_1:
3909     case Xfake_acid_2:
3910     case Xfake_acid_3:
3911     case Xfake_acid_4:
3912     case Xfake_acid_5:
3913     case Xfake_acid_6:
3914     case Xfake_acid_7:
3915     case Xfake_acid_8:
3916 #endif
3917       cave[x][y] = Ydiamond_sB;
3918       next[x][y] = Xblank;
3919       cave[x][y+1] = Ydiamond_s;
3920       next[x][y+1] = Xdiamond_fall;
3921       return;
3922
3923     case Xacid_1:
3924     case Xacid_2:
3925     case Xacid_3:
3926     case Xacid_4:
3927     case Xacid_5:
3928     case Xacid_6:
3929     case Xacid_7:
3930     case Xacid_8:
3931       cave[x][y] = Ydiamond_sB;
3932       next[x][y] = Xblank;
3933       if (cave[x+1][y] == Xblank)
3934         cave[x+1][y] = Xacid_splash_e;
3935       if (cave[x-1][y] == Xblank)
3936         cave[x-1][y] = Xacid_splash_w;
3937       play_element_sound(x, y, SOUND_acid, Xacid_1);
3938       return;
3939
3940     case Xspring:
3941     case Xspring_pause:
3942     case Xspring_e:
3943     case Xspring_w:
3944     case Xandroid:
3945     case Xandroid_1_n:
3946     case Xandroid_2_n:
3947     case Xandroid_1_e:
3948     case Xandroid_2_e:
3949     case Xandroid_1_s:
3950     case Xandroid_2_s:
3951     case Xandroid_1_w:
3952     case Xandroid_2_w:
3953     case Xstone:
3954     case Xstone_pause:
3955     case Xemerald:
3956     case Xemerald_pause:
3957     case Xdiamond:
3958     case Xdiamond_pause:
3959     case Xbomb:
3960     case Xbomb_pause:
3961     case Xballoon:
3962     case Xacid_ne:
3963     case Xacid_nw:
3964     case Xball_1:
3965     case Xball_2:
3966     case Xnut:
3967     case Xnut_pause:
3968     case Xslidewall_ns:
3969     case Xslidewall_ew:
3970     case Xwonderwall:
3971     case Xkey_1:
3972     case Xkey_2:
3973     case Xkey_3:
3974     case Xkey_4:
3975     case Xkey_5:
3976     case Xkey_6:
3977     case Xkey_7:
3978     case Xkey_8:
3979     case Xbumper:
3980     case Xswitch:
3981     case Xsteel_1:
3982     case Xsteel_2:
3983     case Xsteel_3:
3984     case Xsteel_4:
3985     case Xwall_1:
3986     case Xwall_2:
3987     case Xwall_3:
3988     case Xwall_4:
3989     case Xroundwall_1:
3990     case Xroundwall_2:
3991     case Xroundwall_3:
3992     case Xroundwall_4:
3993       if (RANDOM(2))
3994       {
3995         if (tab_blank[cave[x+1][y]] && tab_acid[cave[x+1][y+1]])
3996         {
3997           cave[x][y] = Ydiamond_eB;
3998           next[x][y] = Xblank;
3999           cave[x+1][y] = Ydiamond_e;
4000           next[x+1][y] = Xdiamond_pause;
4001           return;
4002         }
4003
4004         if (tab_blank[cave[x-1][y]] && tab_acid[cave[x-1][y+1]])
4005         {
4006           cave[x][y] = Ydiamond_wB;
4007           next[x][y] = Xblank;
4008           cave[x-1][y] = Ydiamond_w;
4009           next[x-1][y] = Xdiamond_pause;
4010           return;
4011         }
4012       }
4013       else
4014       {
4015         if (tab_blank[cave[x-1][y]] && tab_acid[cave[x-1][y+1]])
4016         {
4017           cave[x][y] = Ydiamond_wB;
4018           next[x][y] = Xblank;
4019           cave[x-1][y] = Ydiamond_w;
4020           next[x-1][y] = Xdiamond_pause;
4021           return;
4022         }
4023
4024         if (tab_blank[cave[x+1][y]] && tab_acid[cave[x+1][y+1]])
4025         {
4026           cave[x][y] = Ydiamond_eB;
4027           next[x][y] = Xblank;
4028           cave[x+1][y] = Ydiamond_e;
4029           next[x+1][y] = Xdiamond_pause;
4030           return;
4031         }
4032       }
4033
4034     default:
4035       if (++lev.shine_cnt > 50)
4036       {
4037         lev.shine_cnt = RANDOM(8);
4038         cave[x][y] = Xdiamond_shine;
4039       }
4040
4041       return;
4042   }
4043 }
4044
4045 static void Ldiamond_pause(int x, int y)
4046 {
4047   switch (cave[x][y+1])
4048   {
4049     case Xblank:
4050     case Xacid_splash_e:
4051     case Xacid_splash_w:
4052 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
4053     case Xfake_acid_1:
4054     case Xfake_acid_2:
4055     case Xfake_acid_3:
4056     case Xfake_acid_4:
4057     case Xfake_acid_5:
4058     case Xfake_acid_6:
4059     case Xfake_acid_7:
4060     case Xfake_acid_8:
4061 #endif
4062       cave[x][y] = Ydiamond_sB;
4063       next[x][y] = Xblank;
4064       cave[x][y+1] = Ydiamond_s;
4065       next[x][y+1] = Xdiamond_fall;
4066       return;
4067
4068     case Xacid_1:
4069     case Xacid_2:
4070     case Xacid_3:
4071     case Xacid_4:
4072     case Xacid_5:
4073     case Xacid_6:
4074     case Xacid_7:
4075     case Xacid_8:
4076       cave[x][y] = Ydiamond_sB;
4077       next[x][y] = Xblank;
4078       if (cave[x+1][y] == Xblank)
4079         cave[x+1][y] = Xacid_splash_e;
4080       if (cave[x-1][y] == Xblank)
4081         cave[x-1][y] = Xacid_splash_w;
4082       play_element_sound(x, y, SOUND_acid, Xacid_1);
4083       return;
4084
4085     default:
4086       cave[x][y] = Xdiamond;
4087       next[x][y] = Xdiamond;
4088       return;
4089   }
4090 }
4091
4092 static void Ldiamond_fall(int x, int y)
4093 {
4094   switch (cave[x][y+1])
4095   {
4096     case Xblank:
4097     case Xacid_splash_e:
4098     case Xacid_splash_w:
4099 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
4100     case Xfake_acid_1:
4101     case Xfake_acid_2:
4102     case Xfake_acid_3:
4103     case Xfake_acid_4:
4104     case Xfake_acid_5:
4105     case Xfake_acid_6:
4106     case Xfake_acid_7:
4107     case Xfake_acid_8:
4108 #endif
4109     case Zplayer:
4110       cave[x][y] = Ydiamond_sB;
4111       next[x][y] = Xblank;
4112       cave[x][y+1] = Ydiamond_s;
4113       next[x][y+1] = Xdiamond_fall;
4114       return;
4115
4116     case Xacid_1:
4117     case Xacid_2:
4118     case Xacid_3:
4119     case Xacid_4:
4120     case Xacid_5:
4121     case Xacid_6:
4122     case Xacid_7:
4123     case Xacid_8:
4124       cave[x][y] = Ydiamond_sB;
4125       next[x][y] = Xblank;
4126       if (cave[x+1][y] == Xblank)
4127         cave[x+1][y] = Xacid_splash_e;
4128       if (cave[x-1][y] == Xblank)
4129         cave[x-1][y] = Xacid_splash_w;
4130       play_element_sound(x, y, SOUND_acid, Xacid_1);
4131       return;
4132
4133     case Xwonderwall:
4134       if (lev.wonderwall_time)
4135       {
4136         lev.wonderwall_state = 1;
4137         cave[x][y] = Ydiamond_sB;
4138         if (tab_blank[cave[x][y+2]])
4139         {
4140           cave[x][y+2] = Ystone_s;
4141           next[x][y+2] = Xstone_fall;
4142         }
4143
4144         next[x][y] = Xblank;
4145         play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4146         return;
4147       }
4148
4149     default:
4150       cave[x][y] = Xdiamond;
4151       next[x][y] = Xdiamond;
4152       play_element_sound(x, y, SOUND_diamond, Xdiamond);
4153       return;
4154   }
4155 }
4156
4157 static void Lstone(int x, int y)
4158 {
4159   switch (cave[x][y+1])
4160   {
4161     case Xblank:
4162     case Xacid_splash_e:
4163     case Xacid_splash_w:
4164 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
4165     case Xfake_acid_1:
4166     case Xfake_acid_2:
4167     case Xfake_acid_3:
4168     case Xfake_acid_4:
4169     case Xfake_acid_5:
4170     case Xfake_acid_6:
4171     case Xfake_acid_7:
4172     case Xfake_acid_8:
4173 #endif
4174     case Xplant:
4175     case Yplant:
4176       cave[x][y] = Ystone_sB;
4177       next[x][y] = Xblank;
4178       cave[x][y+1] = Ystone_s;
4179       next[x][y+1] = Xstone_fall;
4180       return;
4181
4182     case Xacid_1:
4183     case Xacid_2:
4184     case Xacid_3:
4185     case Xacid_4:
4186     case Xacid_5:
4187     case Xacid_6:
4188     case Xacid_7:
4189     case Xacid_8:
4190       cave[x][y] = Ystone_sB;
4191       next[x][y] = Xblank;
4192       if (cave[x+1][y] == Xblank)
4193         cave[x+1][y] = Xacid_splash_e;
4194       if (cave[x-1][y] == Xblank)
4195         cave[x-1][y] = Xacid_splash_w;
4196       play_element_sound(x, y, SOUND_acid, Xacid_1);
4197       return;
4198
4199     case Xsand:
4200       cave[x][y] = Xsand_stonein_1;
4201       next[x][y] = Xsand_stonein_2;
4202       cave[x][y+1] = Xsand_sandstone_1;
4203       next[x][y+1] = Xsand_sandstone_2;
4204       return;
4205
4206     case Xspring:
4207     case Xspring_pause:
4208     case Xspring_e:
4209     case Xspring_w:
4210     case Xandroid:
4211     case Xandroid_1_n:
4212     case Xandroid_2_n:
4213     case Xandroid_1_e:
4214     case Xandroid_2_e:
4215     case Xandroid_1_s:
4216     case Xandroid_2_s:
4217     case Xandroid_1_w:
4218     case Xandroid_2_w:
4219     case Xstone:
4220     case Xstone_pause:
4221     case Xemerald:
4222     case Xemerald_pause:
4223     case Xdiamond:
4224     case Xdiamond_pause:
4225     case Xbomb:
4226     case Xbomb_pause:
4227     case Xballoon:
4228     case Xacid_ne:
4229     case Xacid_nw:
4230     case Xball_1:
4231     case Xball_2:
4232     case Xnut:
4233     case Xnut_pause:
4234     case Xslidewall_ns:
4235     case Xslidewall_ew:
4236     case Xkey_1:
4237     case Xkey_2:
4238     case Xkey_3:
4239     case Xkey_4:
4240     case Xkey_5:
4241     case Xkey_6:
4242     case Xkey_7:
4243     case Xkey_8:
4244     case Xbumper:
4245     case Xswitch:
4246     case Xlenses:
4247     case Xmagnify:
4248     case Xroundwall_1:
4249     case Xroundwall_2:
4250     case Xroundwall_3:
4251     case Xroundwall_4:
4252       if (RANDOM(2))
4253       {
4254         if (tab_blank[cave[x+1][y]] && tab_acid[cave[x+1][y+1]])
4255         {
4256           cave[x][y] = Ystone_eB;
4257           next[x][y] = Xblank;
4258           cave[x+1][y] = Ystone_e;
4259           next[x+1][y] = Xstone_pause;
4260           return;
4261         }
4262
4263         if (tab_blank[cave[x-1][y]] && tab_acid[cave[x-1][y+1]])
4264         {
4265           cave[x][y] = Ystone_wB;
4266           next[x][y] = Xblank;
4267           cave[x-1][y] = Ystone_w;
4268           next[x-1][y] = Xstone_pause;
4269           return;
4270         }
4271       }
4272       else
4273       {
4274         if (tab_blank[cave[x-1][y]] && tab_acid[cave[x-1][y+1]])
4275         {
4276           cave[x][y] = Ystone_wB;
4277           next[x][y] = Xblank;
4278           cave[x-1][y] = Ystone_w;
4279           next[x-1][y] = Xstone_pause;
4280           return;
4281         }
4282
4283         if (tab_blank[cave[x+1][y]] && tab_acid[cave[x+1][y+1]])
4284         {
4285           cave[x][y] = Ystone_eB;
4286           next[x][y] = Xblank;
4287           cave[x+1][y] = Ystone_e;
4288           next[x+1][y] = Xstone_pause;
4289           return;
4290         }
4291       }
4292   }
4293 }
4294
4295 static void Lstone_pause(int x, int y)
4296 {
4297   switch (cave[x][y+1])
4298   {
4299     case Xblank:
4300     case Xacid_splash_e:
4301     case Xacid_splash_w:
4302 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
4303     case Xfake_acid_1:
4304     case Xfake_acid_2:
4305     case Xfake_acid_3:
4306     case Xfake_acid_4:
4307     case Xfake_acid_5:
4308     case Xfake_acid_6:
4309     case Xfake_acid_7:
4310     case Xfake_acid_8:
4311 #endif
4312       cave[x][y] = Ystone_sB;
4313       next[x][y] = Xblank;
4314       cave[x][y+1] = Ystone_s;
4315       next[x][y+1] = Xstone_fall;
4316       return;
4317
4318     case Xacid_1:
4319     case Xacid_2:
4320     case Xacid_3:
4321     case Xacid_4:
4322     case Xacid_5:
4323     case Xacid_6:
4324     case Xacid_7:
4325     case Xacid_8:
4326       cave[x][y] = Ystone_sB;
4327       next[x][y] = Xblank;
4328       if (cave[x+1][y] == Xblank)
4329         cave[x+1][y] = Xacid_splash_e;
4330       if (cave[x-1][y] == Xblank)
4331         cave[x-1][y] = Xacid_splash_w;
4332       play_element_sound(x, y, SOUND_acid, Xacid_1);
4333       return;
4334
4335     default:
4336       cave[x][y] = Xstone;
4337       next[x][y] = Xstone;
4338       return;
4339   }
4340 }
4341
4342 static void Lstone_fall(int x, int y)
4343 {
4344   switch (cave[x][y+1])
4345   {
4346     case Xblank:
4347     case Xacid_splash_e:
4348     case Xacid_splash_w:
4349 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
4350     case Xfake_acid_1:
4351     case Xfake_acid_2:
4352     case Xfake_acid_3:
4353     case Xfake_acid_4:
4354     case Xfake_acid_5:
4355     case Xfake_acid_6:
4356     case Xfake_acid_7:
4357     case Xfake_acid_8:
4358 #endif
4359     case Zplayer:
4360       cave[x][y] = Ystone_sB;
4361       next[x][y] = Xblank;
4362       cave[x][y+1] = Ystone_s;
4363       next[x][y+1] = Xstone_fall;
4364       return;
4365
4366     case Xacid_1:
4367     case Xacid_2:
4368     case Xacid_3:
4369     case Xacid_4:
4370     case Xacid_5:
4371     case Xacid_6:
4372     case Xacid_7:
4373     case Xacid_8:
4374       cave[x][y] = Ystone_sB;
4375       next[x][y] = Xblank;
4376       if (cave[x+1][y] == Xblank)
4377         cave[x+1][y] = Xacid_splash_e;
4378       if (cave[x-1][y] == Xblank)
4379         cave[x-1][y] = Xacid_splash_w;
4380       play_element_sound(x, y, SOUND_acid, Xacid_1);
4381       return;
4382
4383     case Xnut:
4384     case Xnut_pause:
4385       next[x][y] = Xstone;
4386       cave[x][y+1] = Ynut_stone;
4387       next[x][y+1] = Xemerald;
4388       play_element_sound(x, y, SOUND_crack, Xnut);
4389       score += lev.nut_score;
4390       return;
4391
4392     case Xbug_1_n:
4393     case Xbug_1_e:
4394     case Xbug_1_s:
4395     case Xbug_1_w:
4396     case Xbug_2_n:
4397     case Xbug_2_e:
4398     case Xbug_2_s:
4399     case Xbug_2_w:
4400       cave[x][y] = Ystone_sB;
4401       cave[x][y+1] = Ybug_stone;
4402       Lboom_bug(x, y+1, Xstone_fall);
4403       score += lev.bug_score;
4404       return;
4405
4406     case Xtank_1_n:
4407     case Xtank_1_e:
4408     case Xtank_1_s:
4409     case Xtank_1_w:
4410     case Xtank_2_n:
4411     case Xtank_2_e:
4412     case Xtank_2_s:
4413     case Xtank_2_w:
4414       cave[x][y] = Ystone_sB;
4415       cave[x][y+1] = Ytank_stone;
4416       Lboom_tank(x, y+1, Xstone_fall);
4417       score += lev.tank_score;
4418       return;
4419
4420     case Xspring:
4421       if (RANDOM(2))
4422       {
4423         switch (cave[x+1][y+1])
4424         {
4425           case Xblank:
4426           case Xacid_splash_e:
4427           case Xacid_splash_w:
4428 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
4429           case Xfake_acid_1:
4430           case Xfake_acid_2:
4431           case Xfake_acid_3:
4432           case Xfake_acid_4:
4433           case Xfake_acid_5:
4434           case Xfake_acid_6:
4435           case Xfake_acid_7:
4436           case Xfake_acid_8:
4437 #endif
4438           case Xalien:
4439           case Xalien_pause:
4440             cave[x][y+1] = Xspring_e;
4441             break;
4442
4443           default:
4444             cave[x][y+1] = Xspring_w;
4445             break;
4446         }
4447       }
4448       else
4449       {
4450         switch (cave[x-1][y+1])
4451         {
4452           case Xblank:
4453           case Xacid_splash_e:
4454           case Xacid_splash_w:
4455 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
4456           case Xfake_acid_1:
4457           case Xfake_acid_2:
4458           case Xfake_acid_3:
4459           case Xfake_acid_4:
4460           case Xfake_acid_5:
4461           case Xfake_acid_6:
4462           case Xfake_acid_7:
4463           case Xfake_acid_8:
4464 #endif
4465           case Xalien:
4466           case Xalien_pause:
4467             cave[x][y+1] = Xspring_w;
4468             break;
4469           default:
4470             cave[x][y+1] = Xspring_e;
4471             break;
4472         }
4473       }
4474
4475       next[x][y] = Xstone;
4476       return;
4477
4478     case Xeater_n:
4479     case Xeater_e:
4480     case Xeater_s:
4481     case Xeater_w:
4482       cave[x][y] = Ystone_sB;
4483       cave[x][y+1] = Yeater_stone;
4484       Lboom_eater(x, y+1, Xstone_fall);
4485       score += lev.eater_score;
4486       return;
4487
4488     case Xalien:
4489     case Xalien_pause:
4490       cave[x][y] = Ystone_sB;
4491       cave[x][y+1] = Yalien_stone;
4492       Lboom_tank(x, y+1, Xstone_fall);
4493       score += lev.alien_score;
4494       return;
4495
4496     case Xdiamond:
4497     case Xdiamond_pause:
4498       switch (cave[x][y+2])
4499       {
4500         case Xblank:
4501         case Xacid_splash_e:
4502         case Xacid_splash_w:
4503 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
4504         case Xfake_acid_1:
4505         case Xfake_acid_2:
4506         case Xfake_acid_3:
4507         case Xfake_acid_4:
4508         case Xfake_acid_5:
4509         case Xfake_acid_6:
4510         case Xfake_acid_7:
4511         case Xfake_acid_8:
4512 #endif
4513         case Zplayer:
4514         case Xbug_1_n:
4515         case Xbug_1_e:
4516         case Xbug_1_s:
4517         case Xbug_1_w:
4518         case Xbug_2_n:
4519         case Xbug_2_e:
4520         case Xbug_2_s:
4521         case Xbug_2_w:
4522         case Xtank_1_n:
4523         case Xtank_1_e:
4524         case Xtank_1_s:
4525         case Xtank_1_w:
4526         case Xtank_2_n:
4527         case Xtank_2_e:
4528         case Xtank_2_s:
4529         case Xtank_2_w:
4530         case Xspring_fall:
4531         case Xandroid:
4532         case Xandroid_1_n:
4533         case Xandroid_2_n:
4534         case Xandroid_1_e:
4535         case Xandroid_2_e:
4536         case Xandroid_1_s:
4537         case Xandroid_2_s:
4538         case Xandroid_1_w:
4539         case Xandroid_2_w:
4540         case Xstone_fall:
4541         case Xemerald_fall:
4542         case Xdiamond_fall:
4543         case Xbomb_fall:
4544         case Xacid_s:
4545         case Xacid_1:
4546         case Xacid_2:
4547         case Xacid_3:
4548         case Xacid_4:
4549         case Xacid_5:
4550         case Xacid_6:
4551         case Xacid_7:
4552         case Xacid_8:
4553         case Xnut_fall:
4554         case Xplant:
4555         case Yplant:
4556           next[x][y] = Xstone;
4557           play_element_sound(x, y, SOUND_stone, Xstone);
4558           return;
4559       }
4560
4561       cave[x][y] = Ystone_sB;
4562       next[x][y] = Xblank;
4563       cave[x][y+1] = Ydiamond_stone;
4564       next[x][y+1] = Xstone_pause;
4565       play_element_sound(x, y, SOUND_squash, Xdiamond);
4566       return;
4567
4568     case Xbomb:
4569     case Xbomb_pause:
4570       cave[x][y+1] = Ybomb_blank;
4571       Lboom_tank(x, y+1, Xstone_fall);
4572       return;
4573
4574     case Xwonderwall:
4575       if (lev.wonderwall_time)
4576       {
4577         lev.wonderwall_state = 1;
4578         cave[x][y] = Ystone_sB;
4579
4580         if (tab_blank[cave[x][y+2]])
4581         {
4582           cave[x][y+2] = Yemerald_s;
4583           next[x][y+2] = Xemerald_fall;
4584         }
4585
4586         next[x][y] = Xblank;
4587         play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4588         return;
4589       }
4590
4591     default:
4592       cave[x][y] = Xstone;
4593       next[x][y] = Xstone;
4594       play_element_sound(x, y, SOUND_stone, Xstone);
4595       return;
4596   }
4597 }
4598
4599 static void Lbomb(int x, int y)
4600 {
4601   switch (cave[x][y+1])
4602   {
4603     case Xblank:
4604     case Xacid_splash_e:
4605     case Xacid_splash_w:
4606 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
4607     case Xfake_acid_1:
4608     case Xfake_acid_2:
4609     case Xfake_acid_3:
4610     case Xfake_acid_4:
4611     case Xfake_acid_5:
4612     case Xfake_acid_6:
4613     case Xfake_acid_7:
4614     case Xfake_acid_8:
4615 #endif
4616       cave[x][y] = Ybomb_sB;
4617       next[x][y] = Xblank;
4618       cave[x][y+1] = Ybomb_s;
4619       next[x][y+1] = Xbomb_fall;
4620       return;
4621
4622     case Xacid_1:
4623     case Xacid_2:
4624     case Xacid_3:
4625     case Xacid_4:
4626     case Xacid_5:
4627     case Xacid_6:
4628     case Xacid_7:
4629     case Xacid_8:
4630       cave[x][y] = Ybomb_sB;
4631       next[x][y] = Xblank;
4632       if (cave[x+1][y] == Xblank)
4633         cave[x+1][y] = Xacid_splash_e;
4634       if (cave[x-1][y] == Xblank)
4635         cave[x-1][y] = Xacid_splash_w;
4636       play_element_sound(x, y, SOUND_acid, Xacid_1);
4637       return;
4638
4639     case Xspring:
4640     case Xspring_pause:
4641     case Xspring_e:
4642     case Xspring_w:
4643     case Xandroid:
4644     case Xandroid_1_n:
4645     case Xandroid_2_n:
4646     case Xandroid_1_e:
4647     case Xandroid_2_e:
4648     case Xandroid_1_s:
4649     case Xandroid_2_s:
4650     case Xandroid_1_w:
4651     case Xandroid_2_w:
4652     case Xstone:
4653     case Xstone_pause:
4654     case Xemerald:
4655     case Xemerald_pause:
4656     case Xdiamond:
4657     case Xdiamond_pause:
4658     case Xbomb:
4659     case Xbomb_pause:
4660     case Xballoon:
4661     case Xacid_ne:
4662     case Xacid_nw:
4663     case Xball_1:
4664     case Xball_2:
4665     case Xnut:
4666     case Xnut_pause:
4667     case Xslidewall_ns:
4668     case Xslidewall_ew:
4669     case Xkey_1:
4670     case Xkey_2:
4671     case Xkey_3:
4672     case Xkey_4:
4673     case Xkey_5:
4674     case Xkey_6:
4675     case Xkey_7:
4676     case Xkey_8:
4677     case Xbumper:
4678     case Xswitch:
4679     case Xroundwall_1:
4680     case Xroundwall_2:
4681     case Xroundwall_3:
4682     case Xroundwall_4:
4683       if (RANDOM(2))
4684       {
4685         if (tab_blank[cave[x+1][y]] && tab_acid[cave[x+1][y+1]])
4686         {
4687           cave[x][y] = Ybomb_eB;
4688           next[x][y] = Xblank;
4689           cave[x+1][y] = Ybomb_e;
4690           next[x+1][y] = Xbomb_pause;
4691           return;
4692         }
4693
4694         if (tab_blank[cave[x-1][y]] && tab_acid[cave[x-1][y+1]])
4695         {
4696           cave[x][y] = Ybomb_wB;
4697           next[x][y] = Xblank;
4698           cave[x-1][y] = Ybomb_w;
4699           next[x-1][y] = Xbomb_pause;
4700           return;
4701         }
4702       }
4703       else
4704       {
4705         if (tab_blank[cave[x-1][y]] && tab_acid[cave[x-1][y+1]])
4706         {
4707           cave[x][y] = Ybomb_wB;
4708           next[x][y] = Xblank;
4709           cave[x-1][y] = Ybomb_w;
4710           next[x-1][y] = Xbomb_pause;
4711           return;
4712         }
4713
4714         if (tab_blank[cave[x+1][y]] && tab_acid[cave[x+1][y+1]])
4715         {
4716           cave[x][y] = Ybomb_eB;
4717           next[x][y] = Xblank;
4718           cave[x+1][y] = Ybomb_e;
4719           next[x+1][y] = Xbomb_pause;
4720           return;
4721         }
4722       }
4723   }
4724 }
4725
4726 static void Lbomb_pause(int x, int y)
4727 {
4728   switch (cave[x][y+1])
4729   {
4730     case Xblank:
4731     case Xacid_splash_e:
4732     case Xacid_splash_w:
4733 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
4734     case Xfake_acid_1:
4735     case Xfake_acid_2:
4736     case Xfake_acid_3:
4737     case Xfake_acid_4:
4738     case Xfake_acid_5:
4739     case Xfake_acid_6:
4740     case Xfake_acid_7:
4741     case Xfake_acid_8:
4742 #endif
4743       cave[x][y] = Ybomb_sB;
4744       next[x][y] = Xblank;
4745       cave[x][y+1] = Ybomb_s;
4746       next[x][y+1] = Xbomb_fall;
4747       return;
4748
4749     case Xacid_1:
4750     case Xacid_2:
4751     case Xacid_3:
4752     case Xacid_4:
4753     case Xacid_5:
4754     case Xacid_6:
4755     case Xacid_7:
4756     case Xacid_8:
4757       cave[x][y] = Ybomb_sB;
4758       next[x][y] = Xblank;
4759       if (cave[x+1][y] == Xblank)
4760         cave[x+1][y] = Xacid_splash_e;
4761       if (cave[x-1][y] == Xblank)
4762         cave[x-1][y] = Xacid_splash_w;
4763       play_element_sound(x, y, SOUND_acid, Xacid_1);
4764       return;
4765
4766     default:
4767       cave[x][y] = Xbomb;
4768       next[x][y] = Xbomb;
4769       return;
4770   }
4771 }
4772
4773 static void Lbomb_fall(int x, int y)
4774 {
4775   switch (cave[x][y+1])
4776   {
4777     case Xblank:
4778     case Xacid_splash_e:
4779     case Xacid_splash_w:
4780 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
4781     case Xfake_acid_1:
4782     case Xfake_acid_2:
4783     case Xfake_acid_3:
4784     case Xfake_acid_4:
4785     case Xfake_acid_5:
4786     case Xfake_acid_6:
4787     case Xfake_acid_7:
4788     case Xfake_acid_8:
4789 #endif
4790       cave[x][y] = Ybomb_sB;
4791       next[x][y] = Xblank;
4792       cave[x][y+1] = Ybomb_s;
4793       next[x][y+1] = Xbomb_fall;
4794       return;
4795
4796     case Xacid_1:
4797     case Xacid_2:
4798     case Xacid_3:
4799     case Xacid_4:
4800     case Xacid_5:
4801     case Xacid_6:
4802     case Xacid_7:
4803     case Xacid_8:
4804       cave[x][y] = Ybomb_sB;
4805       next[x][y] = Xblank;
4806       if (cave[x+1][y] == Xblank)
4807         cave[x+1][y] = Xacid_splash_e;
4808       if (cave[x-1][y] == Xblank)
4809         cave[x-1][y] = Xacid_splash_w;
4810       play_element_sound(x, y, SOUND_acid, Xacid_1);
4811       return;
4812
4813     default:
4814       cave[x][y] = Ybomb_blank;
4815       Lboom_tank(x, y, Xbomb_fall);
4816       return;
4817   }
4818 }
4819
4820 static void Lnut(int x, int y)
4821 {
4822   switch (cave[x][y+1])
4823   {
4824     case Xblank:
4825     case Xacid_splash_e:
4826     case Xacid_splash_w:
4827 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
4828     case Xfake_acid_1:
4829     case Xfake_acid_2:
4830     case Xfake_acid_3:
4831     case Xfake_acid_4:
4832     case Xfake_acid_5:
4833     case Xfake_acid_6:
4834     case Xfake_acid_7:
4835     case Xfake_acid_8:
4836 #endif
4837       cave[x][y] = Ynut_sB;
4838       next[x][y] = Xblank;
4839       cave[x][y+1] = Ynut_s;
4840       next[x][y+1] = Xnut_fall;
4841       return;
4842
4843     case Xacid_1:
4844     case Xacid_2:
4845     case Xacid_3:
4846     case Xacid_4:
4847     case Xacid_5:
4848     case Xacid_6:
4849     case Xacid_7:
4850     case Xacid_8:
4851       cave[x][y] = Ynut_sB;
4852       next[x][y] = Xblank;
4853       if (cave[x+1][y] == Xblank)
4854         cave[x+1][y] = Xacid_splash_e;
4855       if (cave[x-1][y] == Xblank)
4856         cave[x-1][y] = Xacid_splash_w;
4857       play_element_sound(x, y, SOUND_acid, Xacid_1);
4858       return;
4859
4860     case Xspring:
4861     case Xspring_pause:
4862     case Xspring_e:
4863     case Xspring_w:
4864     case Xandroid:
4865     case Xandroid_1_n:
4866     case Xandroid_2_n:
4867     case Xandroid_1_e:
4868     case Xandroid_2_e:
4869     case Xandroid_1_s:
4870     case Xandroid_2_s:
4871     case Xandroid_1_w:
4872     case Xandroid_2_w:
4873     case Xstone:
4874     case Xstone_pause:
4875     case Xemerald:
4876     case Xemerald_pause:
4877     case Xdiamond:
4878     case Xdiamond_pause:
4879     case Xbomb:
4880     case Xbomb_pause:
4881     case Xballoon:
4882     case Xacid_ne:
4883     case Xacid_nw:
4884     case Xball_1:
4885     case Xball_2:
4886     case Xnut:
4887     case Xnut_pause:
4888     case Xslidewall_ns:
4889     case Xslidewall_ew:
4890     case Xkey_1:
4891     case Xkey_2:
4892     case Xkey_3:
4893     case Xkey_4:
4894     case Xkey_5:
4895     case Xkey_6:
4896     case Xkey_7:
4897     case Xkey_8:
4898     case Xbumper:
4899     case Xswitch:
4900     case Xroundwall_1:
4901     case Xroundwall_2:
4902     case Xroundwall_3:
4903     case Xroundwall_4:
4904       if (RANDOM(2))
4905       {
4906         if (tab_blank[cave[x+1][y]] && tab_acid[cave[x+1][y+1]])
4907         {
4908           cave[x][y] = Ynut_eB;
4909           next[x][y] = Xblank;
4910           cave[x+1][y] = Ynut_e;
4911           next[x+1][y] = Xnut_pause;
4912           return;
4913         }
4914
4915         if (tab_blank[cave[x-1][y]] && tab_acid[cave[x-1][y+1]])
4916         {
4917           cave[x][y] = Ynut_wB;
4918           next[x][y] = Xblank;
4919           cave[x-1][y] = Ynut_w;
4920           next[x-1][y] = Xnut_pause;
4921           return;
4922         }
4923       }
4924       else
4925       {
4926         if (tab_blank[cave[x-1][y]] && tab_acid[cave[x-1][y+1]])
4927         {
4928           cave[x][y] = Ynut_wB;
4929           next[x][y] = Xblank;
4930           cave[x-1][y] = Ynut_w;
4931           next[x-1][y] = Xnut_pause;
4932           return;
4933         }
4934
4935         if (tab_blank[cave[x+1][y]] && tab_acid[cave[x+1][y+1]])
4936         {
4937           cave[x][y] = Ynut_eB;
4938           next[x][y] = Xblank;
4939           cave[x+1][y] = Ynut_e;
4940           next[x+1][y] = Xnut_pause;
4941           return;
4942         }
4943       }
4944   }
4945 }
4946
4947 static void Lnut_pause(int x, int y)
4948 {
4949   switch (cave[x][y+1])
4950   {
4951     case Xblank:
4952     case Xacid_splash_e:
4953     case Xacid_splash_w:
4954 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
4955     case Xfake_acid_1:
4956     case Xfake_acid_2:
4957     case Xfake_acid_3:
4958     case Xfake_acid_4:
4959     case Xfake_acid_5:
4960     case Xfake_acid_6:
4961     case Xfake_acid_7:
4962     case Xfake_acid_8:
4963 #endif
4964       cave[x][y] = Ynut_sB;
4965       next[x][y] = Xblank;
4966       cave[x][y+1] = Ynut_s;
4967       next[x][y+1] = Xnut_fall;
4968       return;
4969
4970     case Xacid_1:
4971     case Xacid_2:
4972     case Xacid_3:
4973     case Xacid_4:
4974     case Xacid_5:
4975     case Xacid_6:
4976     case Xacid_7:
4977     case Xacid_8:
4978       cave[x][y] = Ynut_sB;
4979       next[x][y] = Xblank;
4980       if (cave[x+1][y] == Xblank)
4981         cave[x+1][y] = Xacid_splash_e;
4982       if (cave[x-1][y] == Xblank)
4983         cave[x-1][y] = Xacid_splash_w;
4984       play_element_sound(x, y, SOUND_acid, Xacid_1);
4985       return;
4986
4987     default:
4988       cave[x][y] = Xnut;
4989       next[x][y] = Xnut;
4990       return;
4991   }
4992 }
4993
4994 static void Lnut_fall(int x, int y)
4995 {
4996   switch (cave[x][y+1])
4997   {
4998     case Xblank:
4999     case Xacid_splash_e:
5000     case Xacid_splash_w:
5001 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
5002     case Xfake_acid_1:
5003     case Xfake_acid_2:
5004     case Xfake_acid_3:
5005     case Xfake_acid_4:
5006     case Xfake_acid_5:
5007     case Xfake_acid_6:
5008     case Xfake_acid_7:
5009     case Xfake_acid_8:
5010 #endif
5011     case Zplayer:
5012       cave[x][y] = Ynut_sB;
5013       next[x][y] = Xblank;
5014       cave[x][y+1] = Ynut_s;
5015       next[x][y+1] = Xnut_fall;
5016       return;
5017
5018     case Xacid_1:
5019     case Xacid_2:
5020     case Xacid_3:
5021     case Xacid_4:
5022     case Xacid_5:
5023     case Xacid_6:
5024     case Xacid_7:
5025     case Xacid_8:
5026       cave[x][y] = Ynut_sB;
5027       next[x][y] = Xblank;
5028       if (cave[x+1][y] == Xblank)
5029         cave[x+1][y] = Xacid_splash_e;
5030       if (cave[x-1][y] == Xblank)
5031         cave[x-1][y] = Xacid_splash_w;
5032       play_element_sound(x, y, SOUND_acid, Xacid_1);
5033       return;
5034
5035     default:
5036       cave[x][y] = Xnut;
5037       next[x][y] = Xnut;
5038       play_element_sound(x, y, SOUND_nut, Xnut);
5039       return;
5040   }
5041 }
5042
5043 static void Lspring(int x, int y)
5044 {
5045   switch (cave[x][y+1])
5046   {
5047     case Xblank:
5048     case Xacid_splash_e:
5049     case Xacid_splash_w:
5050 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
5051     case Xfake_acid_1:
5052     case Xfake_acid_2:
5053     case Xfake_acid_3:
5054     case Xfake_acid_4:
5055     case Xfake_acid_5:
5056     case Xfake_acid_6:
5057     case Xfake_acid_7:
5058     case Xfake_acid_8:
5059 #endif
5060     case Xplant:
5061     case Yplant:
5062       cave[x][y] = Yspring_sB;
5063       next[x][y] = Xblank;
5064       cave[x][y+1] = Yspring_s;
5065       next[x][y+1] = Xspring_fall;
5066       return;
5067
5068     case Xacid_1:
5069     case Xacid_2:
5070     case Xacid_3:
5071     case Xacid_4:
5072     case Xacid_5:
5073     case Xacid_6:
5074     case Xacid_7:
5075     case Xacid_8:
5076       cave[x][y] = Yspring_sB;
5077       next[x][y] = Xblank;
5078       if (cave[x+1][y] == Xblank)
5079         cave[x+1][y] = Xacid_splash_e;
5080       if (cave[x-1][y] == Xblank)
5081         cave[x-1][y] = Xacid_splash_w;
5082       play_element_sound(x, y, SOUND_acid, Xacid_1);
5083       return;
5084
5085     case Xspring:
5086     case Xspring_pause:
5087     case Xspring_e:
5088     case Xspring_w:
5089     case Xandroid:
5090     case Xandroid_1_n:
5091     case Xandroid_2_n:
5092     case Xandroid_1_e:
5093     case Xandroid_2_e:
5094     case Xandroid_1_s:
5095     case Xandroid_2_s:
5096     case Xandroid_1_w:
5097     case Xandroid_2_w:
5098     case Xstone:
5099     case Xstone_pause:
5100     case Xemerald:
5101     case Xemerald_pause:
5102     case Xdiamond:
5103     case Xdiamond_pause:
5104     case Xbomb:
5105     case Xbomb_pause:
5106     case Xballoon:
5107     case Xacid_ne:
5108     case Xacid_nw:
5109     case Xball_1:
5110     case Xball_2:
5111     case Xnut:
5112     case Xnut_pause:
5113     case Xslidewall_ns:
5114     case Xslidewall_ew:
5115     case Xkey_1:
5116     case Xkey_2:
5117     case Xkey_3:
5118     case Xkey_4:
5119     case Xkey_5:
5120     case Xkey_6:
5121     case Xkey_7:
5122     case Xkey_8:
5123     case Xbumper:
5124     case Xswitch:
5125     case Xroundwall_1:
5126     case Xroundwall_2:
5127     case Xroundwall_3:
5128     case Xroundwall_4:
5129       if (RANDOM(2))
5130       {
5131         if (tab_blank[cave[x+1][y]] && tab_acid[cave[x+1][y+1]])
5132         {
5133           cave[x][y] = Yspring_eB;
5134           next[x][y] = Xblank;
5135           cave[x+1][y] = Yspring_e;
5136           if (cave[x][y+1] == Xbumper)
5137             cave[x][y+1] = XbumperB;
5138
5139 #ifdef SPRING_ROLL
5140           next[x+1][y] = Xspring_e;
5141 #else
5142           next[x+1][y] = Xspring_pause;
5143 #endif
5144           return;
5145         }
5146
5147         if (tab_blank[cave[x-1][y]] && tab_acid[cave[x-1][y+1]])
5148         {
5149           cave[x][y] = Yspring_wB;
5150           next[x][y] = Xblank;
5151           cave[x-1][y] = Yspring_w;
5152           if (cave[x][y+1] == Xbumper)
5153             cave[x][y+1] = XbumperB;
5154
5155 #ifdef SPRING_ROLL
5156           next[x-1][y] = Xspring_w;
5157 #else
5158           next[x-1][y] = Xspring_pause;
5159 #endif
5160           return;
5161         }
5162       }
5163       else
5164       {
5165         if (tab_blank[cave[x-1][y]] && tab_acid[cave[x-1][y+1]])
5166         {
5167           cave[x][y] = Yspring_wB;
5168           next[x][y] = Xblank;
5169           cave[x-1][y] = Yspring_w;
5170           if (cave[x][y+1] == Xbumper)
5171             cave[x][y+1] = XbumperB;
5172
5173 #ifdef SPRING_ROLL
5174           next[x-1][y] = Xspring_w;
5175 #else
5176           next[x-1][y] = Xspring_pause;
5177 #endif
5178           return;
5179         }
5180
5181         if (tab_blank[cave[x+1][y]] && tab_acid[cave[x+1][y+1]])
5182         {
5183           cave[x][y] = Yspring_eB;
5184           next[x][y] = Xblank;
5185           cave[x+1][y] = Yspring_e;
5186           if (cave[x][y+1] == Xbumper)
5187             cave[x][y+1] = XbumperB;
5188
5189 #ifdef SPRING_ROLL
5190           next[x+1][y] = Xspring_e;
5191 #else
5192           next[x+1][y] = Xspring_pause;
5193 #endif
5194           return;
5195         }
5196       }
5197   }
5198 }
5199
5200 static void Lspring_pause(int x, int y)
5201 {
5202   switch (cave[x][y+1])
5203   {
5204     case Xblank:
5205     case Xacid_splash_e:
5206     case Xacid_splash_w:
5207 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
5208     case Xfake_acid_1:
5209     case Xfake_acid_2:
5210     case Xfake_acid_3:
5211     case Xfake_acid_4:
5212     case Xfake_acid_5:
5213     case Xfake_acid_6:
5214     case Xfake_acid_7:
5215     case Xfake_acid_8:
5216 #endif
5217       cave[x][y] = Yspring_sB;
5218       next[x][y] = Xblank;
5219       cave[x][y+1] = Yspring_s;
5220       next[x][y+1] = Xspring_fall;
5221       return;
5222
5223     case Xacid_1:
5224     case Xacid_2:
5225     case Xacid_3:
5226     case Xacid_4:
5227     case Xacid_5:
5228     case Xacid_6:
5229     case Xacid_7:
5230     case Xacid_8:
5231       cave[x][y] = Yspring_sB;
5232       next[x][y] = Xblank;
5233       if (cave[x+1][y] == Xblank)
5234         cave[x+1][y] = Xacid_splash_e;
5235       if (cave[x-1][y] == Xblank)
5236         cave[x-1][y] = Xacid_splash_w;
5237       play_element_sound(x, y, SOUND_acid, Xacid_1);
5238       return;
5239
5240     default:
5241       cave[x][y] = Xspring;
5242       next[x][y] = Xspring;
5243       return;
5244   }
5245 }
5246
5247 static void Lspring_e(int x, int y)
5248 {
5249   switch (cave[x][y+1])
5250   {
5251     case Xblank:
5252     case Xacid_splash_e:
5253     case Xacid_splash_w:
5254 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
5255     case Xfake_acid_1:
5256     case Xfake_acid_2:
5257     case Xfake_acid_3:
5258     case Xfake_acid_4:
5259     case Xfake_acid_5:
5260     case Xfake_acid_6:
5261     case Xfake_acid_7:
5262     case Xfake_acid_8:
5263 #endif
5264       cave[x][y] = Yspring_sB;
5265       next[x][y] = Xblank;
5266       cave[x][y+1] = Yspring_s;
5267       next[x][y+1] = Xspring_fall;
5268       return;
5269
5270     case Xacid_1:
5271     case Xacid_2:
5272     case Xacid_3:
5273     case Xacid_4:
5274     case Xacid_5:
5275     case Xacid_6:
5276     case Xacid_7:
5277     case Xacid_8:
5278       cave[x][y] = Yspring_sB;
5279       next[x][y] = Xblank;
5280       if (cave[x+1][y] == Xblank)
5281         cave[x+1][y] = Xacid_splash_e;
5282       if (cave[x-1][y] == Xblank)
5283         cave[x-1][y] = Xacid_splash_w;
5284       play_element_sound(x, y, SOUND_acid, Xacid_1);
5285       return;
5286
5287     case Xbumper:
5288       cave[x][y+1] = XbumperB;
5289   }
5290
5291   switch (cave[x+1][y])
5292   {
5293     case Xblank:
5294     case Xacid_splash_e:
5295     case Xacid_splash_w:
5296 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
5297     case Xfake_acid_1:
5298     case Xfake_acid_2:
5299     case Xfake_acid_3:
5300     case Xfake_acid_4:
5301     case Xfake_acid_5:
5302     case Xfake_acid_6:
5303     case Xfake_acid_7:
5304     case Xfake_acid_8:
5305 #endif
5306     case Yalien_nB:
5307     case Yalien_eB:
5308     case Yalien_sB:
5309     case Yalien_wB:
5310       cave[x][y] = Yspring_eB;
5311       next[x][y] = Xblank;
5312       cave[x+1][y] = Yspring_e;
5313       next[x+1][y] = Xspring_e;
5314       return;
5315
5316     case Xacid_1:
5317     case Xacid_2:
5318     case Xacid_3:
5319     case Xacid_4:
5320     case Xacid_5:
5321     case Xacid_6:
5322     case Xacid_7:
5323     case Xacid_8:
5324       cave[x][y] = Yspring_eB;
5325       next[x][y] = Xblank;
5326       if (cave[x+2][y-1] == Xblank)
5327         cave[x+2][y-1] = Xacid_splash_e;
5328       if (cave[x][y-1] == Xblank)
5329         cave[x][y-1] = Xacid_splash_w;
5330       play_element_sound(x, y, SOUND_acid, Xacid_1);
5331       return;
5332
5333     case Xalien:
5334     case Xalien_pause:
5335     case Yalien_n:
5336     case Yalien_e:
5337     case Yalien_s:
5338     case Yalien_w:
5339       cave[x][y] = Yspring_alien_eB;
5340       next[x][y] = Xblank;
5341       cave[x+1][y] = Yspring_alien_e;
5342       next[x+1][y] = Xspring_e;
5343       play_element_sound(x, y, SOUND_slurp, Xalien);
5344       score += lev.slurp_score;
5345       return;
5346
5347     case Xbumper:
5348     case XbumperB:
5349       cave[x+1][y] = XbumperB;
5350       next[x][y] = Xspring_w;
5351       play_element_sound(x, y, SOUND_spring, Xspring);
5352       return;
5353
5354     default:
5355       cave[x][y] = Xspring;
5356       next[x][y] = Xspring;
5357       play_element_sound(x, y, SOUND_spring, Xspring);
5358       return;
5359   }
5360 }
5361
5362 static void Lspring_w(int x, int y)
5363 {
5364   switch (cave[x][y+1])
5365   {
5366     case Xblank:
5367     case Xacid_splash_e:
5368     case Xacid_splash_w:
5369 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
5370     case Xfake_acid_1:
5371     case Xfake_acid_2:
5372     case Xfake_acid_3:
5373     case Xfake_acid_4:
5374     case Xfake_acid_5:
5375     case Xfake_acid_6:
5376     case Xfake_acid_7:
5377     case Xfake_acid_8:
5378 #endif
5379       cave[x][y] = Yspring_sB;
5380       next[x][y] = Xblank;
5381       cave[x][y+1] = Yspring_s;
5382       next[x][y+1] = Xspring_fall;
5383       return;
5384
5385     case Xacid_1:
5386     case Xacid_2:
5387     case Xacid_3:
5388     case Xacid_4:
5389     case Xacid_5:
5390     case Xacid_6:
5391     case Xacid_7:
5392     case Xacid_8:
5393       cave[x][y] = Yspring_sB;
5394       next[x][y] = Xblank;
5395       if (cave[x+1][y] == Xblank)
5396         cave[x+1][y] = Xacid_splash_e;
5397       if (cave[x-1][y] == Xblank)
5398         cave[x-1][y] = Xacid_splash_w;
5399       play_element_sound(x, y, SOUND_acid, Xacid_1);
5400       return;
5401
5402     case Xbumper:
5403       cave[x][y+1] = XbumperB;
5404   }
5405
5406   switch (cave[x-1][y])
5407   {
5408     case Xblank:
5409     case Xacid_splash_e:
5410     case Xacid_splash_w:
5411 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
5412     case Xfake_acid_1:
5413     case Xfake_acid_2:
5414     case Xfake_acid_3:
5415     case Xfake_acid_4:
5416     case Xfake_acid_5:
5417     case Xfake_acid_6:
5418     case Xfake_acid_7:
5419     case Xfake_acid_8:
5420 #endif
5421     case Yalien_nB:
5422     case Yalien_eB:
5423     case Yalien_sB:
5424     case Yalien_wB:
5425       cave[x][y] = Yspring_wB;
5426       next[x][y] = Xblank;
5427       cave[x-1][y] = Yspring_w;
5428       next[x-1][y] = Xspring_w;
5429       return;
5430
5431     case Xacid_1:
5432     case Xacid_2:
5433     case Xacid_3:
5434     case Xacid_4:
5435     case Xacid_5:
5436     case Xacid_6:
5437     case Xacid_7:
5438     case Xacid_8:
5439       cave[x][y] = Yspring_wB;
5440       next[x][y] = Xblank;
5441       if (cave[x][y-1] == Xblank)
5442         cave[x][y-1] = Xacid_splash_e;
5443       if (cave[x-2][y-1] == Xblank)
5444         cave[x-2][y-1] = Xacid_splash_w;
5445       play_element_sound(x, y, SOUND_acid, Xacid_1);
5446       return;
5447
5448     case Xalien:
5449     case Xalien_pause:
5450     case Yalien_n:
5451     case Yalien_e:
5452     case Yalien_s:
5453     case Yalien_w:
5454       cave[x][y] = Yspring_alien_wB;
5455       next[x][y] = Xblank;
5456       cave[x-1][y] = Yspring_alien_w;
5457       next[x-1][y] = Xspring_w;
5458       play_element_sound(x, y, SOUND_slurp, Xalien);
5459       score += lev.slurp_score;
5460       return;
5461
5462     case Xbumper:
5463     case XbumperB:
5464       cave[x-1][y] = XbumperB;
5465       next[x][y] = Xspring_e;
5466       play_element_sound(x, y, SOUND_spring, Xspring);
5467       return;
5468
5469     default:
5470       cave[x][y] = Xspring;
5471       next[x][y] = Xspring;
5472       play_element_sound(x, y, SOUND_spring, Xspring);
5473       return;
5474   }
5475 }
5476
5477 static void Lspring_fall(int x, int y)
5478 {
5479   switch (cave[x][y+1])
5480   {
5481     case Xblank:
5482     case Xacid_splash_e:
5483     case Xacid_splash_w:
5484 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
5485     case Xfake_acid_1:
5486     case Xfake_acid_2:
5487     case Xfake_acid_3:
5488     case Xfake_acid_4:
5489     case Xfake_acid_5:
5490     case Xfake_acid_6:
5491     case Xfake_acid_7:
5492     case Xfake_acid_8:
5493 #endif
5494     case Zplayer:
5495       cave[x][y] = Yspring_sB;
5496       next[x][y] = Xblank;
5497       cave[x][y+1] = Yspring_s;
5498       next[x][y+1] = Xspring_fall;
5499       return;
5500
5501     case Xacid_1:
5502     case Xacid_2:
5503     case Xacid_3:
5504     case Xacid_4:
5505     case Xacid_5:
5506     case Xacid_6:
5507     case Xacid_7:
5508     case Xacid_8:
5509       cave[x][y] = Yspring_sB;
5510       next[x][y] = Xblank;
5511       if (cave[x+1][y] == Xblank)
5512         cave[x+1][y] = Xacid_splash_e;
5513       if (cave[x-1][y] == Xblank)
5514         cave[x-1][y] = Xacid_splash_w;
5515       play_element_sound(x, y, SOUND_acid, Xacid_1);
5516       return;
5517
5518     case Xbomb:
5519     case Xbomb_pause:
5520       cave[x][y+1] = Ybomb_blank;
5521       Lboom_tank(x, y+1, Xspring_fall);
5522       return;
5523
5524     case Xbug_1_n:
5525     case Xbug_1_e:
5526     case Xbug_1_s:
5527     case Xbug_1_w:
5528     case Xbug_2_n:
5529     case Xbug_2_e:
5530     case Xbug_2_s:
5531     case Xbug_2_w:
5532       cave[x][y] = Yspring_sB;
5533       cave[x][y+1] = Ybug_spring;
5534       Lboom_bug(x, y+1, Xspring_fall);
5535       score += lev.bug_score;
5536       return;
5537
5538     case Xtank_1_n:
5539     case Xtank_1_e:
5540     case Xtank_1_s:
5541     case Xtank_1_w:
5542     case Xtank_2_n:
5543     case Xtank_2_e:
5544     case Xtank_2_s:
5545     case Xtank_2_w:
5546       cave[x][y] = Yspring_sB;
5547       cave[x][y+1] = Ytank_spring;
5548       Lboom_tank(x, y+1, Xspring_fall);
5549       score += lev.tank_score;
5550       return;
5551
5552     case Xeater_n:
5553     case Xeater_e:
5554     case Xeater_s:
5555     case Xeater_w:
5556       cave[x][y] = Yspring_sB;
5557       cave[x][y+1] = Yeater_spring;
5558       Lboom_eater(x, y+1, Xspring_fall);
5559       score += lev.eater_score;
5560       return;
5561
5562     case Xalien:
5563     case Xalien_pause:
5564       cave[x][y] = Yspring_sB;
5565       cave[x][y+1] = Yalien_spring;
5566       Lboom_tank(x, y+1, Xspring_fall);
5567       score += lev.alien_score;
5568       return;
5569
5570     default:
5571       cave[x][y] = Xspring;
5572       next[x][y] = Xspring;
5573       play_element_sound(x, y, SOUND_spring, Xspring);
5574       return;
5575   }
5576 }
5577
5578 static void Lpush_emerald_e(int x, int y)
5579 {
5580   switch (cave[x+1][y])
5581   {
5582     case Zborder:
5583     case Znormal:
5584     case Zdynamite:
5585     case Xboom_bug:
5586     case Xboom_bomb:
5587     case Xboom_android:
5588     case Xboom_1:
5589     case Zplayer:
5590       cave[x][y] = Xemerald;
5591       next[x][y] = Xemerald;
5592       return;
5593
5594     default:
5595       cave[x][y] = Yemerald_eB;
5596       next[x][y] = Xblank;
5597       cave[x+1][y] = Yemerald_e;
5598       next[x+1][y] = Xemerald_pause;
5599       return;
5600   }
5601 }
5602
5603 static void Lpush_emerald_w(int x, int y)
5604 {
5605   switch (cave[x-1][y])
5606   {
5607     case Zborder:
5608     case Znormal:
5609     case Zdynamite:
5610     case Xboom_bug:
5611     case Xboom_bomb:
5612     case Xboom_android:
5613     case Xboom_1:
5614     case Zplayer:
5615       cave[x][y] = Xemerald;
5616       next[x][y] = Xemerald;
5617       return;
5618
5619     default:
5620       cave[x][y] = Yemerald_wB;
5621       next[x][y] = Xblank;
5622       cave[x-1][y] = Yemerald_w;
5623       next[x-1][y] = Xemerald_pause;
5624       return;
5625   }
5626 }
5627
5628 static void Lpush_diamond_e(int x, int y)
5629 {
5630   switch (cave[x+1][y])
5631   {
5632     case Zborder:
5633     case Znormal:
5634     case Zdynamite:
5635     case Xboom_bug:
5636     case Xboom_bomb:
5637     case Xboom_android:
5638     case Xboom_1:
5639     case Zplayer:
5640       cave[x][y] = Xdiamond;
5641       next[x][y] = Xdiamond;
5642       return;
5643
5644     default:
5645       cave[x][y] = Ydiamond_eB;
5646       next[x][y] = Xblank;
5647       cave[x+1][y] = Ydiamond_e;
5648       next[x+1][y] = Xdiamond_pause;
5649       return;
5650   }
5651 }
5652
5653 static void Lpush_diamond_w(int x, int y)
5654 {
5655   switch (cave[x-1][y])
5656   {
5657     case Zborder:
5658     case Znormal:
5659     case Zdynamite:
5660     case Xboom_bug:
5661     case Xboom_bomb:
5662     case Xboom_android:
5663     case Xboom_1:
5664     case Zplayer:
5665       cave[x][y] = Xdiamond;
5666       next[x][y] = Xdiamond;
5667       return;
5668
5669     default:
5670       cave[x][y] = Ydiamond_wB;
5671       next[x][y] = Xblank;
5672       cave[x-1][y] = Ydiamond_w;
5673       next[x-1][y] = Xdiamond_pause;
5674       return;
5675   }
5676 }
5677
5678 static void Lpush_stone_e(int x, int y)
5679 {
5680   switch (cave[x+1][y])
5681   {
5682     case Zborder:
5683     case Znormal:
5684     case Zdynamite:
5685     case Xboom_bug:
5686     case Xboom_bomb:
5687     case Xboom_android:
5688     case Xboom_1:
5689     case Zplayer:
5690       cave[x][y] = Xstone;
5691       next[x][y] = Xstone;
5692       return;
5693
5694     default:
5695       cave[x][y] = Ystone_eB;
5696       next[x][y] = Xblank;
5697       cave[x+1][y] = Ystone_e;
5698       next[x+1][y] = Xstone_pause;
5699       return;
5700   }
5701 }
5702
5703 static void Lpush_stone_w(int x, int y)
5704 {
5705   switch (cave[x-1][y])
5706   {
5707     case Zborder:
5708     case Znormal:
5709     case Zdynamite:
5710     case Xboom_bug:
5711     case Xboom_bomb:
5712     case Xboom_android:
5713     case Xboom_1:
5714     case Zplayer:
5715       cave[x][y] = Xstone;
5716       next[x][y] = Xstone;
5717       return;
5718
5719     default:
5720       cave[x][y] = Ystone_wB;
5721       next[x][y] = Xblank;
5722       cave[x-1][y] = Ystone_w;
5723       next[x-1][y] = Xstone_pause;
5724       return;
5725   }
5726 }
5727
5728 static void Lpush_bomb_e(int x, int y)
5729 {
5730   switch (cave[x+1][y])
5731   {
5732     case Zborder:
5733     case Znormal:
5734     case Zdynamite:
5735     case Xboom_bug:
5736     case Xboom_bomb:
5737     case Xboom_android:
5738     case Xboom_1:
5739     case Zplayer:
5740       cave[x][y] = Xbomb;
5741       next[x][y] = Xbomb;
5742       return;
5743
5744     default:
5745       cave[x][y] = Ybomb_eB;
5746       next[x][y] = Xblank;
5747       cave[x+1][y] = Ybomb_e;
5748       next[x+1][y] = Xbomb_pause;
5749       return;
5750   }
5751 }
5752
5753 static void Lpush_bomb_w(int x, int y)
5754 {
5755   switch (cave[x-1][y])
5756   {
5757     case Zborder:
5758     case Znormal:
5759     case Zdynamite:
5760     case Xboom_bug:
5761     case Xboom_bomb:
5762     case Xboom_android:
5763     case Xboom_1:
5764     case Zplayer:
5765       cave[x][y] = Xbomb;
5766       next[x][y] = Xbomb;
5767       return;
5768
5769     default:
5770       cave[x][y] = Ybomb_wB;
5771       next[x][y] = Xblank;
5772       cave[x-1][y] = Ybomb_w;
5773       next[x-1][y] = Xbomb_pause;
5774       return;
5775   }
5776 }
5777
5778 static void Lpush_nut_e(int x, int y)
5779 {
5780   switch (cave[x+1][y])
5781   {
5782     case Zborder:
5783     case Znormal:
5784     case Zdynamite:
5785     case Xboom_bug:
5786     case Xboom_bomb:
5787     case Xboom_android:
5788     case Xboom_1:
5789     case Zplayer:
5790       cave[x][y] = Xnut;
5791       next[x][y] = Xnut;
5792       return;
5793
5794     default:
5795       cave[x][y] = Ynut_eB;
5796       next[x][y] = Xblank;
5797       cave[x+1][y] = Ynut_e;
5798       next[x+1][y] = Xnut_pause;
5799       return;
5800   }
5801 }
5802
5803 static void Lpush_nut_w(int x, int y)
5804 {
5805   switch (cave[x-1][y])
5806   {
5807     case Zborder:
5808     case Znormal:
5809     case Zdynamite:
5810     case Xboom_bug:
5811     case Xboom_bomb:
5812     case Xboom_android:
5813     case Xboom_1:
5814     case Zplayer:
5815       cave[x][y] = Xnut;
5816       next[x][y] = Xnut;
5817       return;
5818
5819     default:
5820       cave[x][y] = Ynut_wB;
5821       next[x][y] = Xblank;
5822       cave[x-1][y] = Ynut_w;
5823       next[x-1][y] = Xnut_pause;
5824       return;
5825   }
5826 }
5827
5828 static void Lpush_spring_e(int x, int y)
5829 {
5830   switch (cave[x+1][y])
5831   {
5832     case Zborder:
5833     case Znormal:
5834     case Zdynamite:
5835     case Xboom_bug:
5836     case Xboom_bomb:
5837     case Xboom_android:
5838     case Xboom_1:
5839     case Zplayer:
5840       cave[x][y] = Xspring;
5841       next[x][y] = Xspring;
5842       return;
5843
5844     default:
5845       cave[x][y] = Yspring_eB;
5846       next[x][y] = Xblank;
5847       cave[x+1][y] = Yspring_e;
5848       next[x+1][y] = Xspring_e;
5849       return;
5850   }
5851 }
5852
5853 static void Lpush_spring_w(int x, int y)
5854 {
5855   switch (cave[x-1][y])
5856   {
5857     case Zborder:
5858     case Znormal:
5859     case Zdynamite:
5860     case Xboom_bug:
5861     case Xboom_bomb:
5862     case Xboom_android:
5863     case Xboom_1:
5864     case Zplayer:
5865       cave[x][y] = Xspring;
5866       next[x][y] = Xspring;
5867       return;
5868
5869     default:
5870       cave[x][y] = Yspring_wB;
5871       next[x][y] = Xblank;
5872       cave[x-1][y] = Yspring_w;
5873       next[x-1][y] = Xspring_w;
5874       return;
5875   }
5876 }
5877
5878 static void Ldynamite_1(int x, int y)
5879 {
5880   play_element_sound(x, y, SOUND_tick, Xdynamite_1);
5881   next[x][y] = Xdynamite_2;
5882 }
5883
5884 static void Ldynamite_2(int x, int y)
5885 {
5886   play_element_sound(x, y, SOUND_tick, Xdynamite_2);
5887   next[x][y] = Xdynamite_3;
5888 }
5889
5890 static void Ldynamite_3(int x, int y)
5891 {
5892   play_element_sound(x, y, SOUND_tick, Xdynamite_3);
5893   next[x][y] = Xdynamite_4;
5894 }
5895
5896 static void Ldynamite_4(int x, int y)
5897 {
5898   play_element_sound(x, y, SOUND_tick, Xdynamite_4);
5899   next[x][y] = Zdynamite;
5900
5901   Lboom_generic(x, y, Xblank, Xblank);
5902 }
5903
5904 static void Lfake_door_1(int x, int y)
5905 {
5906   if (lev.magnify_cnt)
5907     cave[x][y] = Xdoor_1;
5908 }
5909
5910 static void Lfake_door_2(int x, int y)
5911 {
5912   if (lev.magnify_cnt)
5913     cave[x][y] = Xdoor_2;
5914 }
5915
5916 static void Lfake_door_3(int x, int y)
5917 {
5918   if (lev.magnify_cnt)
5919     cave[x][y] = Xdoor_3;
5920 }
5921
5922 static void Lfake_door_4(int x, int y)
5923 {
5924   if (lev.magnify_cnt)
5925     cave[x][y] = Xdoor_4;
5926 }
5927
5928 static void Lfake_door_5(int x, int y)
5929 {
5930   if (lev.magnify_cnt)
5931     cave[x][y] = Xdoor_5;
5932 }
5933
5934 static void Lfake_door_6(int x, int y)
5935 {
5936   if (lev.magnify_cnt)
5937     cave[x][y] = Xdoor_6;
5938 }
5939
5940 static void Lfake_door_7(int x, int y)
5941 {
5942   if (lev.magnify_cnt)
5943     cave[x][y] = Xdoor_7;
5944 }
5945
5946 static void Lfake_door_8(int x, int y)
5947 {
5948   if (lev.magnify_cnt)
5949     cave[x][y] = Xdoor_8;
5950 }
5951
5952 static void Lballoon(int x, int y)
5953 {
5954   if (lev.wind_cnt == 0)
5955     return;
5956
5957   switch (lev.wind_direction)
5958   {
5959     case 0: /* north */
5960       switch (cave[x][y-1])
5961       {
5962         case Xblank:
5963         case Xacid_splash_e:
5964         case Xacid_splash_w:
5965 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
5966         case Xfake_acid_1:
5967         case Xfake_acid_2:
5968         case Xfake_acid_3:
5969         case Xfake_acid_4:
5970         case Xfake_acid_5:
5971         case Xfake_acid_6:
5972         case Xfake_acid_7:
5973         case Xfake_acid_8:
5974 #endif
5975           cave[x][y] = Yballoon_nB;
5976           next[x][y] = Xblank;
5977           cave[x][y-1] = Yballoon_n;
5978           next[x][y-1] = Xballoon;
5979           return;
5980
5981         case Xacid_1:
5982         case Xacid_2:
5983         case Xacid_3:
5984         case Xacid_4:
5985         case Xacid_5:
5986         case Xacid_6:
5987         case Xacid_7:
5988         case Xacid_8:
5989           cave[x][y] = Yballoon_nB;
5990           next[x][y] = Xblank;
5991           if (cave[x+1][y-2] == Xblank)
5992             cave[x+1][y-2] = Xacid_splash_e;
5993           if (cave[x-1][y-2] == Xblank)
5994             cave[x-1][y-2] = Xacid_splash_w;
5995           play_element_sound(x, y, SOUND_acid, Xacid_1);
5996           return;
5997       }
5998       break;
5999
6000     case 1: /* east */
6001       switch (cave[x+1][y])
6002       {
6003         case Xblank:
6004         case Xacid_splash_e:
6005         case Xacid_splash_w:
6006 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
6007         case Xfake_acid_1:
6008         case Xfake_acid_2:
6009         case Xfake_acid_3:
6010         case Xfake_acid_4:
6011         case Xfake_acid_5:
6012         case Xfake_acid_6:
6013         case Xfake_acid_7:
6014         case Xfake_acid_8:
6015 #endif
6016           cave[x][y] = Yballoon_eB;
6017           next[x][y] = Xblank;
6018           cave[x+1][y] = Yballoon_e;
6019           next[x+1][y] = Xballoon;
6020           return;
6021
6022         case Xacid_1:
6023         case Xacid_2:
6024         case Xacid_3:
6025         case Xacid_4:
6026         case Xacid_5:
6027         case Xacid_6:
6028         case Xacid_7:
6029         case Xacid_8:
6030           cave[x][y] = Yballoon_eB;
6031           next[x][y] = Xblank;
6032           if (cave[x+2][y-1] == Xblank)
6033             cave[x+2][y-1] = Xacid_splash_e;
6034           if (cave[x][y-1] == Xblank)
6035             cave[x][y-1] = Xacid_splash_w;
6036           play_element_sound(x, y, SOUND_acid, Xacid_1);
6037           return;
6038       }
6039       break;
6040
6041     case 2: /* south */
6042       switch (cave[x][y+1])
6043       {
6044         case Xblank:
6045         case Xacid_splash_e:
6046         case Xacid_splash_w:
6047 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
6048         case Xfake_acid_1:
6049         case Xfake_acid_2:
6050         case Xfake_acid_3:
6051         case Xfake_acid_4:
6052         case Xfake_acid_5:
6053         case Xfake_acid_6:
6054         case Xfake_acid_7:
6055         case Xfake_acid_8:
6056 #endif
6057           cave[x][y] = Yballoon_sB;
6058           next[x][y] = Xblank;
6059           cave[x][y+1] = Yballoon_s;
6060           next[x][y+1] = Xballoon;
6061           return;
6062
6063         case Xacid_1:
6064         case Xacid_2:
6065         case Xacid_3:
6066         case Xacid_4:
6067         case Xacid_5:
6068         case Xacid_6:
6069         case Xacid_7:
6070         case Xacid_8:
6071           cave[x][y] = Yballoon_sB;
6072           next[x][y] = Xblank;
6073           if (cave[x+1][y] == Xblank)
6074             cave[x+1][y] = Xacid_splash_e;
6075           if (cave[x-1][y] == Xblank)
6076             cave[x-1][y] = Xacid_splash_w;
6077           play_element_sound(x, y, SOUND_acid, Xacid_1);
6078           return;
6079       }
6080       break;
6081
6082     case 3: /* west */
6083       switch (cave[x-1][y])
6084       {
6085         case Xblank:
6086         case Xacid_splash_e:
6087         case Xacid_splash_w:
6088 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
6089         case Xfake_acid_1:
6090         case Xfake_acid_2:
6091         case Xfake_acid_3:
6092         case Xfake_acid_4:
6093         case Xfake_acid_5:
6094         case Xfake_acid_6:
6095         case Xfake_acid_7:
6096         case Xfake_acid_8:
6097 #endif
6098           cave[x][y] = Yballoon_wB;
6099           next[x][y] = Xblank;
6100           cave[x-1][y] = Yballoon_w;
6101           next[x-1][y] = Xballoon;
6102           return;
6103
6104         case Xacid_1:
6105         case Xacid_2:
6106         case Xacid_3:
6107         case Xacid_4:
6108         case Xacid_5:
6109         case Xacid_6:
6110         case Xacid_7:
6111         case Xacid_8:
6112           cave[x][y] = Yballoon_wB;
6113           next[x][y] = Xblank;
6114           if (cave[x][y-1] == Xblank)
6115             cave[x][y-1] = Xacid_splash_e;
6116           if (cave[x-2][y-1] == Xblank)
6117             cave[x-2][y-1] = Xacid_splash_w;
6118           play_element_sound(x, y, SOUND_acid, Xacid_1);
6119           return;
6120       }
6121       break;
6122   }
6123 }
6124
6125 static void Lball_common(int x, int y)
6126 {
6127   play_element_sound(x, y, SOUND_ball, Xball_1);
6128
6129   if (lev.ball_random)
6130   {
6131     switch (RANDOM(8))
6132     {
6133       case 0:
6134         if (lev.ball_array[lev.ball_pos][0] != Xblank &&
6135             tab_blank[cave[x-1][y-1]])
6136         {
6137           cave[x-1][y-1] = Yball_blank;
6138           next[x-1][y-1] = lev.ball_array[lev.ball_pos][0];
6139         }
6140         break;
6141
6142       case 1:
6143         if (lev.ball_array[lev.ball_pos][1] != Xblank &&
6144             tab_blank[cave[x][y-1]])
6145         {
6146           cave[x][y-1] = Yball_blank;
6147           next[x][y-1] = lev.ball_array[lev.ball_pos][1];
6148         }
6149         break;
6150
6151       case 2:
6152         if (lev.ball_array[lev.ball_pos][2] != Xblank &&
6153             tab_blank[cave[x+1][y-1]])
6154         {
6155           cave[x+1][y-1] = Yball_blank;
6156           next[x+1][y-1] = lev.ball_array[lev.ball_pos][2];
6157         }
6158         break;
6159
6160       case 3:
6161         if (lev.ball_array[lev.ball_pos][3] != Xblank &&
6162             tab_blank[cave[x-1][y]])
6163         {
6164           cave[x-1][y] = Yball_blank;
6165           next[x-1][y] = lev.ball_array[lev.ball_pos][3];
6166         }
6167         break;
6168
6169       case 4:
6170         if (lev.ball_array[lev.ball_pos][4] != Xblank &&
6171             tab_blank[cave[x+1][y]])
6172         {
6173           cave[x+1][y] = Yball_blank;
6174           next[x+1][y] = lev.ball_array[lev.ball_pos][4];
6175         }
6176         break;
6177
6178       case 5:
6179         if (lev.ball_array[lev.ball_pos][5] != Xblank &&
6180             tab_blank[cave[x-1][y+1]])
6181         {
6182           cave[x-1][y+1] = Yball_blank;
6183           next[x-1][y+1] = lev.ball_array[lev.ball_pos][5];
6184         }
6185         break;
6186
6187       case 6:
6188         if (lev.ball_array[lev.ball_pos][6] != Xblank &&
6189             tab_blank[cave[x][y+1]])
6190         {
6191           cave[x][y+1] = Yball_blank;
6192           next[x][y+1] = lev.ball_array[lev.ball_pos][6];
6193         }
6194         break;
6195
6196       case 7:
6197         if (lev.ball_array[lev.ball_pos][7] != Xblank &&
6198             tab_blank[cave[x+1][y+1]])
6199         {
6200           cave[x+1][y+1] = Yball_blank;
6201           next[x+1][y+1] = lev.ball_array[lev.ball_pos][7];
6202         }
6203         break;
6204     }
6205   }
6206   else
6207   {
6208     if (lev.ball_array[lev.ball_pos][0] != Xblank &&
6209         tab_blank[cave[x-1][y-1]])
6210     {
6211       cave[x-1][y-1] = Yball_blank;
6212       next[x-1][y-1] = lev.ball_array[lev.ball_pos][0];
6213     }
6214
6215     if (lev.ball_array[lev.ball_pos][1] != Xblank &&
6216         tab_blank[cave[x][y-1]])
6217     {
6218       cave[x][y-1] = Yball_blank;
6219       next[x][y-1] = lev.ball_array[lev.ball_pos][1];
6220     }
6221
6222     if (lev.ball_array[lev.ball_pos][2] != Xblank &&
6223         tab_blank[cave[x+1][y-1]])
6224     {
6225       cave[x+1][y-1] = Yball_blank;
6226       next[x+1][y-1] = lev.ball_array[lev.ball_pos][2];
6227     }
6228
6229     if (lev.ball_array[lev.ball_pos][3] != Xblank &&
6230         tab_blank[cave[x-1][y]])
6231     {
6232       cave[x-1][y] = Yball_blank;
6233       next[x-1][y] = lev.ball_array[lev.ball_pos][3];
6234     }
6235
6236     if (lev.ball_array[lev.ball_pos][4] != Xblank &&
6237         tab_blank[cave[x+1][y]])
6238     {
6239       cave[x+1][y] = Yball_blank;
6240       next[x+1][y] = lev.ball_array[lev.ball_pos][4];
6241     }
6242
6243     if (lev.ball_array[lev.ball_pos][5] != Xblank &&
6244         tab_blank[cave[x-1][y+1]])
6245     {
6246       cave[x-1][y+1] = Yball_blank;
6247       next[x-1][y+1] = lev.ball_array[lev.ball_pos][5];
6248     }
6249
6250     if (lev.ball_array[lev.ball_pos][6] != Xblank &&
6251         tab_blank[cave[x][y+1]])
6252     {
6253       cave[x][y+1] = Yball_blank;
6254       next[x][y+1] = lev.ball_array[lev.ball_pos][6];
6255     }
6256
6257     if (lev.ball_array[lev.ball_pos][7] != Xblank &&
6258         tab_blank[cave[x+1][y+1]])
6259     {
6260       cave[x+1][y+1] = Yball_blank;
6261       next[x+1][y+1] = lev.ball_array[lev.ball_pos][7];
6262     }
6263   }
6264
6265   lev.ball_pos = (lev.ball_pos + 1) % lev.num_ball_arrays;
6266 }
6267
6268 static void Lball_1(int x, int y)
6269 {
6270   if (lev.ball_state == 0)
6271     return;
6272
6273   cave[x][y] = Yball_1;
6274   next[x][y] = Xball_2;
6275   if (lev.ball_cnt)
6276     return;
6277
6278   Lball_common(x, y);
6279 }
6280
6281 static void Lball_2(int x, int y)
6282 {
6283   if (lev.ball_state == 0)
6284     return;
6285
6286   cave[x][y] = Yball_2;
6287   next[x][y] = Xball_1;
6288   if (lev.ball_cnt)
6289     return;
6290
6291   Lball_common(x, y);
6292 }
6293
6294 static void Ldrip(int x, int y)
6295 {
6296   next[x][y] = Xdrip_fall;
6297 }
6298
6299 static void Ldrip_fall(int x, int y)
6300 {
6301   int temp;
6302
6303   switch (cave[x][y+1])
6304   {
6305     case Xblank:
6306     case Xacid_splash_e:
6307     case Xacid_splash_w:
6308 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
6309     case Xfake_acid_1:
6310     case Xfake_acid_2:
6311     case Xfake_acid_3:
6312     case Xfake_acid_4:
6313     case Xfake_acid_5:
6314     case Xfake_acid_6:
6315     case Xfake_acid_7:
6316     case Xfake_acid_8:
6317 #endif
6318     case Xplant:
6319     case Yplant:
6320     case Zplayer:
6321       cave[x][y] = Ydrip_1_sB;
6322       next[x][y] = Xdrip_stretchB;
6323       cave[x][y+1] = Ydrip_1_s;
6324       next[x][y+1] = Xdrip_stretch;
6325       return;
6326
6327     case Xacid_1:
6328     case Xacid_2:
6329     case Xacid_3:
6330     case Xacid_4:
6331     case Xacid_5:
6332     case Xacid_6:
6333     case Xacid_7:
6334     case Xacid_8:
6335       cave[x][y] = Ydrip_1_sB;
6336       next[x][y] = Xdrip_stretchB;
6337       if (cave[x+1][y] == Xblank)
6338         cave[x+1][y] = Xacid_splash_e;
6339       if (cave[x-1][y] == Xblank)
6340         cave[x-1][y] = Xacid_splash_w;
6341       play_element_sound(x, y, SOUND_acid, Xacid_1);
6342       return;
6343
6344     default:
6345       switch (RANDOM(8))
6346       {
6347         case 0: temp = Xamoeba_1; break;
6348         case 1: temp = Xamoeba_2; break;
6349         case 2: temp = Xamoeba_3; break;
6350         case 3: temp = Xamoeba_4; break;
6351         case 4: temp = Xamoeba_5; break;
6352         case 5: temp = Xamoeba_6; break;
6353         case 6: temp = Xamoeba_7; break;
6354         case 7: temp = Xamoeba_8; break;
6355       }
6356
6357       cave[x][y] = temp;
6358       next[x][y] = temp;
6359       play_element_sound(x, y, SOUND_drip, Xdrip_fall);
6360       return;
6361   }
6362 }
6363
6364 static void Ldrip_stretch(int x, int y)
6365 {
6366   cave[x][y] = Ydrip_2_s;
6367   next[x][y] = Xdrip_fall;
6368 }
6369
6370 static void Ldrip_stretchB(int x, int y)
6371 {
6372   cave[x][y] = Ydrip_2_sB;
6373   next[x][y] = Xblank;
6374 }
6375
6376 static void Lwonderwall(int x, int y)
6377 {
6378   if (lev.wonderwall_time && lev.wonderwall_state)
6379   {
6380     cave[x][y] = XwonderwallB;
6381     play_element_sound(x, y, SOUND_wonder, Xwonderwall);
6382   }
6383 }
6384
6385 static void Lwheel(int x, int y)
6386 {
6387   if (lev.wheel_cnt && x == lev.wheel_x && y == lev.wheel_y)
6388     cave[x][y] = XwheelB;
6389 }
6390
6391 static void Lswitch(int x, int y)
6392 {
6393   if (lev.ball_state)
6394     cave[x][y] = XswitchB;
6395 }
6396
6397 static void Lfake_blank(int x, int y)
6398 {
6399   if (lev.lenses_cnt)
6400     cave[x][y] = Xfake_blankB;
6401 }
6402
6403 static void Lfake_grass(int x, int y)
6404 {
6405   if (lev.magnify_cnt)
6406     cave[x][y] = Xfake_grassB;
6407 }
6408
6409 static void Lfake_amoeba(int x, int y)
6410 {
6411   if (lev.lenses_cnt)
6412     cave[x][y] = Xfake_amoebaB;
6413 }
6414
6415 static void Lsand_stone(int x, int y)
6416 {
6417   switch (cave[x][y+1])
6418   {
6419     case Xblank:
6420     case Xacid_splash_e:
6421     case Xacid_splash_w:
6422 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
6423     case Xfake_acid_1:
6424     case Xfake_acid_2:
6425     case Xfake_acid_3:
6426     case Xfake_acid_4:
6427     case Xfake_acid_5:
6428     case Xfake_acid_6:
6429     case Xfake_acid_7:
6430     case Xfake_acid_8:
6431 #endif
6432       cave[x][y] = Xsand_stonesand_quickout_1;
6433       next[x][y] = Xsand_stonesand_quickout_2;
6434       cave[x][y+1] = Xsand_stoneout_1;
6435       next[x][y+1] = Xsand_stoneout_2;
6436       return;
6437
6438     case Xacid_1:
6439     case Xacid_2:
6440     case Xacid_3:
6441     case Xacid_4:
6442     case Xacid_5:
6443     case Xacid_6:
6444     case Xacid_7:
6445     case Xacid_8:
6446       cave[x][y] = Xsand_stonesand_quickout_1;
6447       next[x][y] = Xsand_stonesand_quickout_2;
6448       if (cave[x+1][y] == Xblank)
6449         cave[x+1][y] = Xacid_splash_e;
6450       if (cave[x-1][y] == Xblank)
6451         cave[x-1][y] = Xacid_splash_w;
6452       play_element_sound(x, y, SOUND_acid, Xacid_1);
6453       return;
6454
6455     case Xsand:
6456       cave[x][y] = Xsand_stonesand_1;
6457       next[x][y] = Xsand_stonesand_2;
6458       cave[x][y+1] = Xsand_sandstone_1;
6459       next[x][y+1] = Xsand_sandstone_2;
6460       return;
6461   }
6462 }
6463
6464 static void Lsand_stonein_1(int x, int y)
6465 {
6466   next[x][y] = Xsand_stonein_2;
6467 }
6468
6469 static void Lsand_stonein_2(int x, int y)
6470 {
6471   next[x][y] = Xsand_stonein_3;
6472 }
6473
6474 static void Lsand_stonein_3(int x, int y)
6475 {
6476   next[x][y] = Xsand_stonein_4;
6477 }
6478
6479 static void Lsand_stonein_4(int x, int y)
6480 {
6481   next[x][y] = Xblank;
6482 }
6483
6484 static void Lsand_sandstone_1(int x, int y)
6485 {
6486   next[x][y] = Xsand_sandstone_2;
6487 }
6488
6489 static void Lsand_sandstone_2(int x, int y)
6490 {
6491   next[x][y] = Xsand_sandstone_3;
6492 }
6493
6494 static void Lsand_sandstone_3(int x, int y)
6495 {
6496   next[x][y] = Xsand_sandstone_4;
6497 }
6498
6499 static void Lsand_sandstone_4(int x, int y)
6500 {
6501   next[x][y] = Xsand_stone;
6502 }
6503
6504 static void Lsand_stonesand_1(int x, int y)
6505 {
6506   next[x][y] = Xsand_stonesand_2;
6507 }
6508
6509 static void Lsand_stonesand_2(int x, int y)
6510 {
6511   next[x][y] = Xsand_stonesand_3;
6512 }
6513
6514 static void Lsand_stonesand_3(int x, int y)
6515 {
6516   next[x][y] = Xsand_stonesand_4;
6517 }
6518
6519 static void Lsand_stonesand_4(int x, int y)
6520 {
6521   next[x][y] = Xsand;
6522 }
6523
6524 static void Lsand_stoneout_1(int x, int y)
6525 {
6526   next[x][y] = Xsand_stoneout_2;
6527 }
6528
6529 static void Lsand_stoneout_2(int x, int y)
6530 {
6531   next[x][y] = Xstone_fall;
6532 }
6533
6534 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
6535 static void Lsand_stonesand_quickout_1(int x, int y)
6536 {
6537   next[x][y] = Xsand_stonesand_quickout_2;
6538 }
6539
6540 static void Lsand_stonesand_quickout_2(int x, int y)
6541 {
6542   next[x][y] = Xsand;
6543 }
6544 #endif
6545
6546 static void Lslidewall_ns(int x, int y)
6547 {
6548   if (tab_blank[cave[x][y-1]])
6549   {
6550     cave[x][y-1] = Yslidewall_ns_blank;
6551     next[x][y-1] = Xslidewall_ns;
6552     play_element_sound(x, y, SOUND_slidewall, Xslidewall_ns);
6553   }
6554
6555   if (tab_blank[cave[x][y+1]])
6556   {
6557     cave[x][y+1] = Yslidewall_ns_blank;
6558     next[x][y+1] = Xslidewall_ns;
6559     play_element_sound(x, y, SOUND_slidewall, Xslidewall_ns);
6560   }
6561 }
6562
6563 static void Lslidewall_ew(int x, int y)
6564 {
6565   if (tab_blank[cave[x+1][y]])
6566   {
6567     cave[x+1][y] = Yslidewall_ew_blank;
6568     next[x+1][y] = Xslidewall_ew;
6569     play_element_sound(x, y, SOUND_slidewall, Xslidewall_ew);
6570   }
6571
6572   if (tab_blank[cave[x-1][y]])
6573   {
6574     cave[x-1][y] = Yslidewall_ew_blank;
6575     next[x-1][y] = Xslidewall_ew;
6576     play_element_sound(x, y, SOUND_slidewall, Xslidewall_ew);
6577   }
6578 }
6579
6580 static void Lexit(int x, int y)
6581 {
6582   if (lev.required > 0)
6583     return;
6584
6585   switch (RANDOM(64) / 21)
6586   {
6587     case 0:
6588       cave[x][y] = Xexit_1;
6589       next[x][y] = Xexit_2;
6590       break;
6591
6592     case 1:
6593       cave[x][y] = Xexit_2;
6594       next[x][y] = Xexit_3;
6595       break;
6596
6597     default:
6598       cave[x][y] = Xexit_3;
6599       next[x][y] = Xexit_1;
6600       break;
6601   }
6602
6603   play_element_sound(x, y, SOUND_exit_open, Xexit);
6604 }
6605
6606 static void Lexit_1(int x, int y)
6607 {
6608   next[x][y] = Xexit_2;
6609 }
6610
6611 static void Lexit_2(int x, int y)
6612 {
6613   next[x][y] = Xexit_3;
6614 }
6615
6616 static void Lexit_3(int x, int y)
6617 {
6618   next[x][y] = Xexit_1;
6619 }
6620
6621 static void Lpause(int x, int y)
6622 {
6623   next[x][y] = Xblank;
6624 }
6625
6626 static void Lamoeba(int x, int y)
6627 {
6628   switch (cave[x][y])
6629   {
6630     case Xblank:
6631     case Xacid_splash_e:
6632     case Xacid_splash_w:
6633 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
6634     case Xfake_acid_1:
6635     case Xfake_acid_2:
6636     case Xfake_acid_3:
6637     case Xfake_acid_4:
6638     case Xfake_acid_5:
6639     case Xfake_acid_6:
6640     case Xfake_acid_7:
6641     case Xfake_acid_8:
6642 #endif
6643     case Xgrass:
6644     case Xdirt:
6645     case Xsand:
6646     case Xplant:
6647     case Yplant:
6648       if (tab_amoeba[cave[x][y-1]] ||
6649           tab_amoeba[cave[x+1][y]] ||
6650           tab_amoeba[cave[x][y+1]] ||
6651           tab_amoeba[cave[x-1][y]])
6652         cave[x][y] = Xdrip;
6653   }
6654 }
6655
6656 static void Lexplode(int x, int y)
6657 {
6658   switch (cave[x][y])
6659   {
6660     case Znormal:
6661       cave[x][y]     = Xboom_1;
6662       cave[x][y-1]   = tab_explode_normal[cave[x][y-1]];
6663       cave[x-1][y]   = tab_explode_normal[cave[x-1][y]];
6664       cave[x+1][y]   = tab_explode_normal[cave[x+1][y]];
6665       cave[x][y+1]   = tab_explode_normal[cave[x][y+1]];
6666       cave[x-1][y-1] = tab_explode_normal[cave[x-1][y-1]];
6667       cave[x+1][y-1] = tab_explode_normal[cave[x+1][y-1]];
6668       cave[x-1][y+1] = tab_explode_normal[cave[x-1][y+1]];
6669       cave[x+1][y+1] = tab_explode_normal[cave[x+1][y+1]];
6670       break;
6671
6672     case Zdynamite:
6673       cave[x][y]     = Xboom_1;
6674       cave[x][y-1]   = tab_explode_dynamite[cave[x][y-1]];
6675       cave[x-1][y]   = tab_explode_dynamite[cave[x-1][y]];
6676       cave[x+1][y]   = tab_explode_dynamite[cave[x+1][y]];
6677       cave[x][y+1]   = tab_explode_dynamite[cave[x][y+1]];
6678       cave[x-1][y-1] = tab_explode_dynamite[cave[x-1][y-1]];
6679       cave[x+1][y-1] = tab_explode_dynamite[cave[x+1][y-1]];
6680       cave[x-1][y+1] = tab_explode_dynamite[cave[x-1][y+1]];
6681       cave[x+1][y+1] = tab_explode_dynamite[cave[x+1][y+1]];
6682       break;
6683   }
6684 }
6685
6686 static void Lboom_1(int x, int y)
6687 {
6688   next[x][y] = Xboom_2;
6689 #if !PLAY_ELEMENT_SOUND
6690   if (x != lev.exit_x && y != lev.exit_y)
6691     play_sound(x, y, SOUND_boom);
6692   else
6693     lev.exit_x = lev.exit_y = -1;
6694 #endif
6695 }
6696
6697 static void Lboom_2(int x, int y)
6698 {
6699   next[x][y] = boom[x][y];
6700 }
6701
6702 static void Lboom_android(int x, int y)
6703 {
6704 #if PLAY_ELEMENT_SOUND
6705   play_element_sound(x, y, SOUND_boom, Xandroid);
6706 #endif
6707
6708   Lboom_1(x, y);
6709 }
6710
6711 static void handle_tile(int x, int y)
6712 {
6713   switch (cave[x][y])
6714   {
6715     case Xacid_1:               Lacid_1(x, y);                  break;
6716     case Xacid_2:               Lacid_2(x, y);                  break;
6717     case Xacid_3:               Lacid_3(x, y);                  break;
6718     case Xacid_4:               Lacid_4(x, y);                  break;
6719     case Xacid_5:               Lacid_5(x, y);                  break;
6720     case Xacid_6:               Lacid_6(x, y);                  break;
6721     case Xacid_7:               Lacid_7(x, y);                  break;
6722     case Xacid_8:               Lacid_8(x, y);                  break;
6723
6724 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
6725     case Xfake_acid_1:          Lfake_acid_1(x, y);             break;
6726     case Xfake_acid_2:          Lfake_acid_2(x, y);             break;
6727     case Xfake_acid_3:          Lfake_acid_3(x, y);             break;
6728     case Xfake_acid_4:          Lfake_acid_4(x, y);             break;
6729     case Xfake_acid_5:          Lfake_acid_5(x, y);             break;
6730     case Xfake_acid_6:          Lfake_acid_6(x, y);             break;
6731     case Xfake_acid_7:          Lfake_acid_7(x, y);             break;
6732     case Xfake_acid_8:          Lfake_acid_8(x, y);             break;
6733 #endif
6734
6735     case Xandroid:              Landroid(x, y);                 break;
6736     case Xandroid_1_n:          Landroid_1_n(x, y);             break;
6737     case Xandroid_2_n:          Landroid_2_n(x, y);             break;
6738     case Xandroid_1_e:          Landroid_1_e(x, y);             break;
6739     case Xandroid_2_e:          Landroid_2_e(x, y);             break;
6740     case Xandroid_1_s:          Landroid_1_s(x, y);             break;
6741     case Xandroid_2_s:          Landroid_2_s(x, y);             break;
6742     case Xandroid_1_w:          Landroid_1_w(x, y);             break;
6743     case Xandroid_2_w:          Landroid_2_w(x, y);             break;
6744
6745     case Xeater_n:              Leater_n(x, y);                 break;
6746     case Xeater_e:              Leater_e(x, y);                 break;
6747     case Xeater_s:              Leater_s(x, y);                 break;
6748     case Xeater_w:              Leater_w(x, y);                 break;
6749
6750     case Xalien:                Lalien(x, y);                   break;
6751     case Xalien_pause:          Lalien_pause(x, y);             break;
6752
6753     case Xbug_1_n:              Lbug_1_n(x, y);                 break;
6754     case Xbug_2_n:              Lbug_2_n(x, y);                 break;
6755     case Xbug_1_e:              Lbug_1_e(x, y);                 break;
6756     case Xbug_2_e:              Lbug_2_e(x, y);                 break;
6757     case Xbug_1_s:              Lbug_1_s(x, y);                 break;
6758     case Xbug_2_s:              Lbug_2_s(x, y);                 break;
6759     case Xbug_1_w:              Lbug_1_w(x, y);                 break;
6760     case Xbug_2_w:              Lbug_2_w(x, y);                 break;
6761
6762     case Xtank_1_n:             Ltank_1_n(x, y);                break;
6763     case Xtank_2_n:             Ltank_2_n(x, y);                break;
6764     case Xtank_1_e:             Ltank_1_e(x, y);                break;
6765     case Xtank_2_e:             Ltank_2_e(x, y);                break;
6766     case Xtank_1_s:             Ltank_1_s(x, y);                break;
6767     case Xtank_2_s:             Ltank_2_s(x, y);                break;
6768     case Xtank_1_w:             Ltank_1_w(x, y);                break;
6769     case Xtank_2_w:             Ltank_2_w(x, y);                break;
6770
6771     case Xemerald:              Lemerald(x, y);                 break;
6772     case Xemerald_pause:        Lemerald_pause(x, y);           break;
6773     case Xemerald_fall:         Lemerald_fall(x, y);            break;
6774
6775     case Xdiamond:              Ldiamond(x, y);                 break;
6776     case Xdiamond_pause:        Ldiamond_pause(x, y);           break;
6777     case Xdiamond_fall:         Ldiamond_fall(x, y);            break;
6778
6779     case Xstone:                Lstone(x, y);                   break;
6780     case Xstone_pause:          Lstone_pause(x, y);             break;
6781     case Xstone_fall:           Lstone_fall(x, y);              break;
6782
6783     case Xbomb:                 Lbomb(x, y);                    break;
6784     case Xbomb_pause:           Lbomb_pause(x, y);              break;
6785     case Xbomb_fall:            Lbomb_fall(x, y);               break;
6786
6787     case Xnut:                  Lnut(x, y);                     break;
6788     case Xnut_pause:            Lnut_pause(x, y);               break;
6789     case Xnut_fall:             Lnut_fall(x, y);                break;
6790
6791     case Xspring:               Lspring(x, y);                  break;
6792     case Xspring_pause:         Lspring_pause(x, y);            break;
6793     case Xspring_e:             Lspring_e(x, y);                break;
6794     case Xspring_w:             Lspring_w(x, y);                break;
6795     case Xspring_fall:          Lspring_fall(x, y);             break;
6796
6797     case Xpush_emerald_e:       Lpush_emerald_e(x, y);          break;
6798     case Xpush_emerald_w:       Lpush_emerald_w(x, y);          break;
6799     case Xpush_diamond_e:       Lpush_diamond_e(x, y);          break;
6800     case Xpush_diamond_w:       Lpush_diamond_w(x, y);          break;
6801     case Xpush_stone_e:         Lpush_stone_e(x, y);            break;
6802     case Xpush_stone_w:         Lpush_stone_w(x, y);            break;
6803     case Xpush_bomb_e:          Lpush_bomb_e(x, y);             break;
6804     case Xpush_bomb_w:          Lpush_bomb_w(x, y);             break;
6805     case Xpush_nut_e:           Lpush_nut_e(x, y);              break;
6806     case Xpush_nut_w:           Lpush_nut_w(x, y);              break;
6807     case Xpush_spring_e:        Lpush_spring_e(x, y);           break;
6808     case Xpush_spring_w:        Lpush_spring_w(x, y);           break;
6809
6810     case Xdynamite_1:           Ldynamite_1(x, y);              break;
6811     case Xdynamite_2:           Ldynamite_2(x, y);              break;
6812     case Xdynamite_3:           Ldynamite_3(x, y);              break;
6813     case Xdynamite_4:           Ldynamite_4(x, y);              break;
6814
6815     case Xfake_door_1:          Lfake_door_1(x, y);             break;
6816     case Xfake_door_2:          Lfake_door_2(x, y);             break;
6817     case Xfake_door_3:          Lfake_door_3(x, y);             break;
6818     case Xfake_door_4:          Lfake_door_4(x, y);             break;
6819     case Xfake_door_5:          Lfake_door_5(x, y);             break;
6820     case Xfake_door_6:          Lfake_door_6(x, y);             break;
6821     case Xfake_door_7:          Lfake_door_7(x, y);             break;
6822     case Xfake_door_8:          Lfake_door_8(x, y);             break;
6823
6824     case Xballoon:              Lballoon(x, y);                 break;
6825
6826     case Xball_1:               Lball_1(x, y);                  break;
6827     case Xball_2:               Lball_2(x, y);                  break;
6828
6829     case Xdrip:                 Ldrip(x, y);                    break;
6830     case Xdrip_fall:            Ldrip_fall(x, y);               break;
6831     case Xdrip_stretch:         Ldrip_stretch(x, y);            break;
6832     case Xdrip_stretchB:        Ldrip_stretchB(x, y);           break;
6833
6834     case Xwonderwall:           Lwonderwall(x, y);              break;
6835
6836     case Xwheel:                Lwheel(x, y);                   break;
6837
6838     case Xswitch:               Lswitch(x, y);                  break;
6839
6840     case Xfake_blank:           Lfake_blank(x, y);              break;
6841     case Xfake_grass:           Lfake_grass(x, y);              break;
6842     case Xfake_amoeba:          Lfake_amoeba(x, y);             break;
6843
6844     case Xsand_stone:           Lsand_stone(x, y);              break;
6845     case Xsand_stonein_1:       Lsand_stonein_1(x, y);          break;
6846     case Xsand_stonein_2:       Lsand_stonein_2(x, y);          break;
6847     case Xsand_stonein_3:       Lsand_stonein_3(x, y);          break;
6848     case Xsand_stonein_4:       Lsand_stonein_4(x, y);          break;
6849     case Xsand_sandstone_1:     Lsand_sandstone_1(x, y);        break;
6850     case Xsand_sandstone_2:     Lsand_sandstone_2(x, y);        break;
6851     case Xsand_sandstone_3:     Lsand_sandstone_3(x, y);        break;
6852     case Xsand_sandstone_4:     Lsand_sandstone_4(x, y);        break;
6853     case Xsand_stonesand_1:     Lsand_stonesand_1(x, y);        break;
6854     case Xsand_stonesand_2:     Lsand_stonesand_2(x, y);        break;
6855     case Xsand_stonesand_3:     Lsand_stonesand_3(x, y);        break;
6856     case Xsand_stonesand_4:     Lsand_stonesand_4(x, y);        break;
6857     case Xsand_stoneout_1:      Lsand_stoneout_1(x, y);         break;
6858     case Xsand_stoneout_2:      Lsand_stoneout_2(x, y);         break;
6859 #ifdef EM_ENGINE_USE_ADDITIONAL_ELEMENTS
6860     case Xsand_stonesand_quickout_1: Lsand_stonesand_quickout_1(x, y); break;
6861     case Xsand_stonesand_quickout_2: Lsand_stonesand_quickout_2(x, y); break;
6862 #endif
6863
6864     case Xslidewall_ns:         Lslidewall_ns(x, y);            break;
6865     case Xslidewall_ew:         Lslidewall_ew(x, y);            break;
6866
6867     case Xexit:                 Lexit(x, y);                    break;
6868     case Xexit_1:               Lexit_1(x, y);                  break;
6869     case Xexit_2:               Lexit_2(x, y);                  break;
6870     case Xexit_3:               Lexit_3(x, y);                  break;
6871
6872     case Xpause:                Lpause(x, y);                   break;
6873
6874     case Xboom_bug:             Lboom_bug(x, y, Xboom_bug);     break;
6875     case Xboom_bomb:            Lboom_tank(x, y, Xboom_bomb);   break;
6876     case Xboom_android:         Lboom_android(x, y);            break;
6877     case Xboom_1:               Lboom_1(x, y);                  break;
6878     case Xboom_2:               Lboom_2(x, y);                  break;
6879   }
6880 }
6881
6882 void logic_1(void)
6883 {
6884   int start_check_nr;
6885   int i;
6886
6887   cave = lev.cave;
6888   next = lev.next;
6889   boom = lev.boom;
6890
6891   game_em.any_player_moving = FALSE;
6892   game_em.any_player_snapping = FALSE;
6893
6894   /* must test for death and actually kill separately */
6895   for (i = 0; i < MAX_PLAYERS; i++)
6896   {
6897     boolean ply_kill = player_killed(&ply[i]);
6898
6899     if (ply[i].alive && ply_kill)
6900       kill_player(&ply[i]);
6901   }
6902
6903   for (i = 0; i < MAX_PLAYERS; i++)
6904   {
6905     /* check for wrap-around movement */
6906     if (ply[i].x < lev.left ||
6907         ply[i].x > lev.right - 1)
6908     {
6909       ply[i].x = (ply[i].x < lev.left ? lev.right - 1 : lev.left);
6910
6911       game.centered_player_nr_next = i;
6912       game.set_centered_player = TRUE;
6913       game.set_centered_player_fast = TRUE;
6914     }
6915
6916     ply[i].oldx = ply[i].x;
6917     ply[i].oldy = ply[i].y;
6918     ply[i].anim = PLY_still;
6919   }
6920
6921   start_check_nr = (RandomEM & 128 ? 0 : 1) * 2 + (RandomEM & 256 ? 0 : 1);
6922
6923   for (i = 0; i < MAX_PLAYERS; i++)
6924   {
6925     int check_nr = (start_check_nr + i) % MAX_PLAYERS;
6926
6927     if (ply[check_nr].alive)
6928       check_player(&ply[check_nr]);
6929   }
6930
6931   for (i = 0; i < MAX_PLAYERS; i++)
6932   {
6933     if (!ply[i].alive)
6934       continue;
6935
6936     if (cave[ply[i].oldx][ply[i].oldy] == Zplayer)
6937     {
6938       cave[ply[i].oldx][ply[i].oldy] = Xblank;
6939       next[ply[i].oldx][ply[i].oldy] = Xblank;
6940     }
6941
6942     if (cave[ply[i].x][ply[i].y] == Xblank)
6943     {
6944       cave[ply[i].x][ply[i].y] = Zplayer;
6945       next[ply[i].x][ply[i].y] = Zplayer;
6946     }
6947   }
6948 }
6949
6950 void logic_2(void)
6951 {
6952   int x, y;
6953
6954   cave = lev.cave;
6955   next = lev.next;
6956   boom = lev.boom;
6957
6958   seed = RandomEM;
6959   score = 0;
6960
6961   for (y = lev.top; y < lev.bottom; y++)
6962     for (x = lev.left; x < lev.right; x++)
6963       handle_tile(x, y);
6964
6965   if (ply[0].alive || ply[1].alive || ply[2].alive || ply[3].alive)
6966     lev.score += score;         /* only add a score if someone is alive */
6967   else
6968     game_em.game_over = TRUE;
6969
6970   RandomEM = seed;
6971
6972   /* triple buffering */
6973   void *temp = lev.cave;
6974   lev.cave = lev.next;
6975   lev.next = lev.draw;
6976   lev.draw = temp;
6977 }
6978
6979 void logic_3(void)
6980 {
6981   int x;
6982   int y;
6983   int count;
6984   unsigned int random;
6985
6986   cave = lev.cave;
6987   next = lev.next;
6988   boom = lev.boom;
6989
6990   /* update variables */
6991
6992   if (lev.score > 9999)
6993     lev.score = 9999;
6994
6995   if (lev.android_move_cnt-- == 0)
6996     lev.android_move_cnt = lev.android_move_time;
6997   if (lev.android_clone_cnt-- == 0)
6998     lev.android_clone_cnt = lev.android_clone_time;
6999   if (lev.ball_state)
7000     if (lev.ball_cnt-- == 0)
7001       lev.ball_cnt = lev.ball_time;
7002   if (lev.lenses_cnt)
7003     lev.lenses_cnt--;
7004   if (lev.magnify_cnt)
7005     lev.magnify_cnt--;
7006   if (lev.wheel_cnt)
7007     lev.wheel_cnt--;
7008   if (lev.wind_cnt)
7009     lev.wind_cnt--;
7010   if (lev.wonderwall_time && lev.wonderwall_state)
7011     lev.wonderwall_time--;
7012
7013   if (lev.wheel_cnt)
7014     play_element_sound(lev.wheel_x, lev.wheel_y, SOUND_wheel, Xwheel);
7015
7016   /* grow amoeba */
7017
7018   random = RandomEM;
7019
7020   for (count = lev.amoeba_time; count--;)
7021   {
7022     x = lev.left - 1 + (random >> 10) % (CAVE_WIDTH  + 2);
7023     y = lev.top  - 1 + (random >> 20) % (CAVE_HEIGHT + 2);
7024
7025     if (x >= lev.left && x < lev.right &&
7026         y >= lev.top  && y < lev.bottom)
7027       Lamoeba(x, y);
7028
7029     random = random * 129 + 1;
7030   }
7031
7032   RandomEM = random;
7033
7034   /* handle explosions */
7035
7036   for (y = lev.top; y < lev.bottom; y++)
7037     for (x = lev.left; x < lev.right; x++)
7038       Lexplode(x, y);
7039
7040   /* triple buffering */
7041
7042   for (y = lev.top; y < lev.bottom; y++)
7043     for (x = lev.left; x < lev.right; x++)
7044       next[x][y] = cave[x][y];
7045 }