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