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