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