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