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