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