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