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