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