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