changed some EM engine game element names
[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.required = lev.required < 3 ? 0 : lev.required - 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.required = lev.required < 1 ? 0 : lev.required - 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.required = lev.required < 3 ? 0 : lev.required - 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.required = lev.required < 1 ? 0 : lev.required - 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 Xacid_ne:
3717     case Xacid_nw:
3718     case Xslide_ns:
3719     case Xslide_ew:
3720     case Xwall_1:
3721     case Xwall_2:
3722     case Xwall_3:
3723     case Xwall_4:
3724     case Xroundwall_1:
3725     case Xroundwall_2:
3726     case Xroundwall_3:
3727     case Xroundwall_4:
3728     case Xsteel_1:
3729     case Xsteel_2:
3730     case Xsteel_3:
3731     case Xsteel_4:
3732       if (RANDOM(2))
3733       {
3734         if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3735         {
3736           cave[x][y] = Yemerald_eB;
3737           next[x][y] = Xblank;
3738           cave[x+1][y] = Yemerald_e;
3739           next[x+1][y] = Xemerald_pause;
3740           return;
3741         }
3742
3743         if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
3744         {
3745           cave[x][y] = Yemerald_wB;
3746           next[x][y] = Xblank;
3747           cave[x-1][y] = Yemerald_w;
3748           next[x-1][y] = Xemerald_pause;
3749           return;
3750         }
3751       }
3752       else
3753       {
3754         if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
3755         {
3756           cave[x][y] = Yemerald_wB;
3757           next[x][y] = Xblank;
3758           cave[x-1][y] = Yemerald_w;
3759           next[x-1][y] = Xemerald_pause;
3760           return;
3761         }
3762
3763         if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3764         {
3765           cave[x][y] = Yemerald_eB;
3766           next[x][y] = Xblank;
3767           cave[x+1][y] = Yemerald_e;
3768           next[x+1][y] = Xemerald_pause;
3769           return;
3770         }
3771       }
3772
3773     default:
3774       if (++lev.shine_cnt > 50)
3775       {
3776         lev.shine_cnt = RANDOM(8);
3777         cave[x][y] = Xemerald_shine;
3778       }
3779
3780       return;
3781   }
3782 }
3783
3784 static void Lemerald_pause(int x, int y)
3785 {
3786   switch (cave[x][y+1])
3787   {
3788     case Xblank:
3789     case Xsplash_e:
3790     case Xsplash_w:
3791     case Xfake_acid_1:
3792     case Xfake_acid_2:
3793     case Xfake_acid_3:
3794     case Xfake_acid_4:
3795     case Xfake_acid_5:
3796     case Xfake_acid_6:
3797     case Xfake_acid_7:
3798     case Xfake_acid_8:
3799       cave[x][y] = Yemerald_sB;
3800       next[x][y] = Xblank;
3801       cave[x][y+1] = Yemerald_s;
3802       next[x][y+1] = Xemerald_fall;
3803       return;
3804
3805     case Xacid_1:
3806     case Xacid_2:
3807     case Xacid_3:
3808     case Xacid_4:
3809     case Xacid_5:
3810     case Xacid_6:
3811     case Xacid_7:
3812     case Xacid_8:
3813       cave[x][y] = Yemerald_sB;
3814       next[x][y] = Xblank;
3815       if (cave[x+1][y] == Xblank)
3816         cave[x+1][y] = Xsplash_e;
3817       if (cave[x-1][y] == Xblank)
3818         cave[x-1][y] = Xsplash_w;
3819       play_element_sound(x, y, SOUND_acid, Xacid_1);
3820       return;
3821
3822     default:
3823       cave[x][y] = Xemerald;
3824       next[x][y] = Xemerald;
3825       return;
3826   }
3827 }
3828
3829 static void Lemerald_fall(int x, int y)
3830 {
3831   switch (cave[x][y+1])
3832   {
3833     case Zplayer:
3834     case Xblank:
3835     case Xsplash_e:
3836     case Xsplash_w:
3837     case Xfake_acid_1:
3838     case Xfake_acid_2:
3839     case Xfake_acid_3:
3840     case Xfake_acid_4:
3841     case Xfake_acid_5:
3842     case Xfake_acid_6:
3843     case Xfake_acid_7:
3844     case Xfake_acid_8:
3845       cave[x][y] = Yemerald_sB;
3846       next[x][y] = Xblank;
3847       cave[x][y+1] = Yemerald_s;
3848       next[x][y+1] = Xemerald_fall;
3849       return;
3850
3851     case Xacid_1:
3852     case Xacid_2:
3853     case Xacid_3:
3854     case Xacid_4:
3855     case Xacid_5:
3856     case Xacid_6:
3857     case Xacid_7:
3858     case Xacid_8:
3859       cave[x][y] = Yemerald_sB;
3860       next[x][y] = Xblank;
3861       if (cave[x+1][y] == Xblank)
3862         cave[x+1][y] = Xsplash_e;
3863       if (cave[x-1][y] == Xblank)
3864         cave[x-1][y] = Xsplash_w;
3865       play_element_sound(x, y, SOUND_acid, Xacid_1);
3866       return;
3867
3868     case Xwonderwall:
3869       if (lev.wonderwall_time)
3870       {
3871         lev.wonderwall_state = 1;
3872         cave[x][y] = Yemerald_sB;
3873         next[x][y] = Xblank;
3874         if (is_blank[cave[x][y+2]])
3875         {
3876           cave[x][y+2] = Ydiamond_s;
3877           next[x][y+2] = Xdiamond_fall;
3878         }
3879         play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
3880         return;
3881       }
3882
3883     default:
3884       cave[x][y] = Xemerald;
3885       next[x][y] = Xemerald;
3886       play_element_sound(x, y, SOUND_diamond, Xemerald);
3887       return;
3888   }
3889 }
3890
3891 static void Ldiamond(int x, int y)
3892 {
3893   switch (cave[x][y+1])
3894   {
3895     case Xblank:
3896     case Xsplash_e:
3897     case Xsplash_w:
3898     case Xfake_acid_1:
3899     case Xfake_acid_2:
3900     case Xfake_acid_3:
3901     case Xfake_acid_4:
3902     case Xfake_acid_5:
3903     case Xfake_acid_6:
3904     case Xfake_acid_7:
3905     case Xfake_acid_8:
3906       cave[x][y] = Ydiamond_sB;
3907       next[x][y] = Xblank;
3908       cave[x][y+1] = Ydiamond_s;
3909       next[x][y+1] = Xdiamond_fall;
3910       return;
3911
3912     case Xacid_1:
3913     case Xacid_2:
3914     case Xacid_3:
3915     case Xacid_4:
3916     case Xacid_5:
3917     case Xacid_6:
3918     case Xacid_7:
3919     case Xacid_8:
3920       cave[x][y] = Ydiamond_sB;
3921       next[x][y] = Xblank;
3922       if (cave[x+1][y] == Xblank)
3923         cave[x+1][y] = Xsplash_e;
3924       if (cave[x-1][y] == Xblank)
3925         cave[x-1][y] = Xsplash_w;
3926       play_element_sound(x, y, SOUND_acid, Xacid_1);
3927       return;
3928
3929     case Xandroid:
3930     case Xandroid_1_n:
3931     case Xandroid_2_n:
3932     case Xandroid_1_e:
3933     case Xandroid_2_e:
3934     case Xandroid_1_s:
3935     case Xandroid_2_s:
3936     case Xandroid_1_w:
3937     case Xandroid_2_w:
3938     case Xemerald:
3939     case Xemerald_pause:
3940     case Xdiamond:
3941     case Xdiamond_pause:
3942     case Xstone:
3943     case Xstone_pause:
3944     case Xbomb:
3945     case Xbomb_pause:
3946     case Xnut:
3947     case Xnut_pause:
3948     case Xspring:
3949     case Xspring_pause:
3950     case Xspring_e:
3951     case Xspring_w:
3952     case Xkey_1:
3953     case Xkey_2:
3954     case Xkey_3:
3955     case Xkey_4:
3956     case Xkey_5:
3957     case Xkey_6:
3958     case Xkey_7:
3959     case Xkey_8:
3960     case Xballoon:
3961     case Xball_1:
3962     case Xball_2:
3963     case Xwonderwall:
3964     case Xswitch:
3965     case Xbumper:
3966     case Xacid_ne:
3967     case Xacid_nw:
3968     case Xslide_ns:
3969     case Xslide_ew:
3970     case Xwall_1:
3971     case Xwall_2:
3972     case Xwall_3:
3973     case Xwall_4:
3974     case Xroundwall_1:
3975     case Xroundwall_2:
3976     case Xroundwall_3:
3977     case Xroundwall_4:
3978     case Xsteel_1:
3979     case Xsteel_2:
3980     case Xsteel_3:
3981     case Xsteel_4:
3982       if (RANDOM(2))
3983       {
3984         if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3985         {
3986           cave[x][y] = Ydiamond_eB;
3987           next[x][y] = Xblank;
3988           cave[x+1][y] = Ydiamond_e;
3989           next[x+1][y] = Xdiamond_pause;
3990           return;
3991         }
3992
3993         if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
3994         {
3995           cave[x][y] = Ydiamond_wB;
3996           next[x][y] = Xblank;
3997           cave[x-1][y] = Ydiamond_w;
3998           next[x-1][y] = Xdiamond_pause;
3999           return;
4000         }
4001       }
4002       else
4003       {
4004         if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4005         {
4006           cave[x][y] = Ydiamond_wB;
4007           next[x][y] = Xblank;
4008           cave[x-1][y] = Ydiamond_w;
4009           next[x-1][y] = Xdiamond_pause;
4010           return;
4011         }
4012
4013         if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4014         {
4015           cave[x][y] = Ydiamond_eB;
4016           next[x][y] = Xblank;
4017           cave[x+1][y] = Ydiamond_e;
4018           next[x+1][y] = Xdiamond_pause;
4019           return;
4020         }
4021       }
4022
4023     default:
4024       if (++lev.shine_cnt > 50)
4025       {
4026         lev.shine_cnt = RANDOM(8);
4027         cave[x][y] = Xdiamond_shine;
4028       }
4029
4030       return;
4031   }
4032 }
4033
4034 static void Ldiamond_pause(int x, int y)
4035 {
4036   switch (cave[x][y+1])
4037   {
4038     case Xblank:
4039     case Xsplash_e:
4040     case Xsplash_w:
4041     case Xfake_acid_1:
4042     case Xfake_acid_2:
4043     case Xfake_acid_3:
4044     case Xfake_acid_4:
4045     case Xfake_acid_5:
4046     case Xfake_acid_6:
4047     case Xfake_acid_7:
4048     case Xfake_acid_8:
4049       cave[x][y] = Ydiamond_sB;
4050       next[x][y] = Xblank;
4051       cave[x][y+1] = Ydiamond_s;
4052       next[x][y+1] = Xdiamond_fall;
4053       return;
4054
4055     case Xacid_1:
4056     case Xacid_2:
4057     case Xacid_3:
4058     case Xacid_4:
4059     case Xacid_5:
4060     case Xacid_6:
4061     case Xacid_7:
4062     case Xacid_8:
4063       cave[x][y] = Ydiamond_sB;
4064       next[x][y] = Xblank;
4065       if (cave[x+1][y] == Xblank)
4066         cave[x+1][y] = Xsplash_e;
4067       if (cave[x-1][y] == Xblank)
4068         cave[x-1][y] = Xsplash_w;
4069       play_element_sound(x, y, SOUND_acid, Xacid_1);
4070       return;
4071
4072     default:
4073       cave[x][y] = Xdiamond;
4074       next[x][y] = Xdiamond;
4075       return;
4076   }
4077 }
4078
4079 static void Ldiamond_fall(int x, int y)
4080 {
4081   switch (cave[x][y+1])
4082   {
4083     case Zplayer:
4084     case Xblank:
4085     case Xsplash_e:
4086     case Xsplash_w:
4087     case Xfake_acid_1:
4088     case Xfake_acid_2:
4089     case Xfake_acid_3:
4090     case Xfake_acid_4:
4091     case Xfake_acid_5:
4092     case Xfake_acid_6:
4093     case Xfake_acid_7:
4094     case Xfake_acid_8:
4095       cave[x][y] = Ydiamond_sB;
4096       next[x][y] = Xblank;
4097       cave[x][y+1] = Ydiamond_s;
4098       next[x][y+1] = Xdiamond_fall;
4099       return;
4100
4101     case Xacid_1:
4102     case Xacid_2:
4103     case Xacid_3:
4104     case Xacid_4:
4105     case Xacid_5:
4106     case Xacid_6:
4107     case Xacid_7:
4108     case Xacid_8:
4109       cave[x][y] = Ydiamond_sB;
4110       next[x][y] = Xblank;
4111       if (cave[x+1][y] == Xblank)
4112         cave[x+1][y] = Xsplash_e;
4113       if (cave[x-1][y] == Xblank)
4114         cave[x-1][y] = Xsplash_w;
4115       play_element_sound(x, y, SOUND_acid, Xacid_1);
4116       return;
4117
4118     case Xwonderwall:
4119       if (lev.wonderwall_time)
4120       {
4121         lev.wonderwall_state = 1;
4122         cave[x][y] = Ydiamond_sB;
4123         next[x][y] = Xblank;
4124         if (is_blank[cave[x][y+2]])
4125         {
4126           cave[x][y+2] = Ystone_s;
4127           next[x][y+2] = Xstone_fall;
4128         }
4129         play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4130         return;
4131       }
4132
4133     default:
4134       cave[x][y] = Xdiamond;
4135       next[x][y] = Xdiamond;
4136       play_element_sound(x, y, SOUND_diamond, Xdiamond);
4137       return;
4138   }
4139 }
4140
4141 static void Lstone(int x, int y)
4142 {
4143   switch (cave[x][y+1])
4144   {
4145     case Xblank:
4146     case Xsplash_e:
4147     case Xsplash_w:
4148     case Xfake_acid_1:
4149     case Xfake_acid_2:
4150     case Xfake_acid_3:
4151     case Xfake_acid_4:
4152     case Xfake_acid_5:
4153     case Xfake_acid_6:
4154     case Xfake_acid_7:
4155     case Xfake_acid_8:
4156     case Xplant:
4157     case Yplant:
4158       cave[x][y] = Ystone_sB;
4159       next[x][y] = Xblank;
4160       cave[x][y+1] = Ystone_s;
4161       next[x][y+1] = Xstone_fall;
4162       return;
4163
4164     case Xacid_1:
4165     case Xacid_2:
4166     case Xacid_3:
4167     case Xacid_4:
4168     case Xacid_5:
4169     case Xacid_6:
4170     case Xacid_7:
4171     case Xacid_8:
4172       cave[x][y] = Ystone_sB;
4173       next[x][y] = Xblank;
4174       if (cave[x+1][y] == Xblank)
4175         cave[x+1][y] = Xsplash_e;
4176       if (cave[x-1][y] == Xblank)
4177         cave[x-1][y] = Xsplash_w;
4178       play_element_sound(x, y, SOUND_acid, Xacid_1);
4179       return;
4180
4181     case Xsand:
4182       cave[x][y] = Xsand_stonein_1;
4183       next[x][y] = Xsand_stonein_2;
4184       cave[x][y+1] = Xsand_sandstone_1;
4185       next[x][y+1] = Xsand_sandstone_2;
4186       return;
4187
4188     case Xandroid:
4189     case Xandroid_1_n:
4190     case Xandroid_2_n:
4191     case Xandroid_1_e:
4192     case Xandroid_2_e:
4193     case Xandroid_1_s:
4194     case Xandroid_2_s:
4195     case Xandroid_1_w:
4196     case Xandroid_2_w:
4197     case Xemerald:
4198     case Xemerald_pause:
4199     case Xdiamond:
4200     case Xdiamond_pause:
4201     case Xstone:
4202     case Xstone_pause:
4203     case Xbomb:
4204     case Xbomb_pause:
4205     case Xnut:
4206     case Xnut_pause:
4207     case Xspring:
4208     case Xspring_pause:
4209     case Xspring_e:
4210     case Xspring_w:
4211     case Xkey_1:
4212     case Xkey_2:
4213     case Xkey_3:
4214     case Xkey_4:
4215     case Xkey_5:
4216     case Xkey_6:
4217     case Xkey_7:
4218     case Xkey_8:
4219     case Xballoon:
4220     case Xball_1:
4221     case Xball_2:
4222     case Xswitch:
4223     case Xbumper:
4224     case Xacid_ne:
4225     case Xacid_nw:
4226     case Xlenses:
4227     case Xmagnify:
4228     case Xslide_ns:
4229     case Xslide_ew:
4230     case Xroundwall_1:
4231     case Xroundwall_2:
4232     case Xroundwall_3:
4233     case Xroundwall_4:
4234       if (RANDOM(2))
4235       {
4236         if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4237         {
4238           cave[x][y] = Ystone_eB;
4239           next[x][y] = Xblank;
4240           cave[x+1][y] = Ystone_e;
4241           next[x+1][y] = Xstone_pause;
4242           return;
4243         }
4244
4245         if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4246         {
4247           cave[x][y] = Ystone_wB;
4248           next[x][y] = Xblank;
4249           cave[x-1][y] = Ystone_w;
4250           next[x-1][y] = Xstone_pause;
4251           return;
4252         }
4253       }
4254       else
4255       {
4256         if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4257         {
4258           cave[x][y] = Ystone_wB;
4259           next[x][y] = Xblank;
4260           cave[x-1][y] = Ystone_w;
4261           next[x-1][y] = Xstone_pause;
4262           return;
4263         }
4264
4265         if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4266         {
4267           cave[x][y] = Ystone_eB;
4268           next[x][y] = Xblank;
4269           cave[x+1][y] = Ystone_e;
4270           next[x+1][y] = Xstone_pause;
4271           return;
4272         }
4273       }
4274   }
4275 }
4276
4277 static void Lstone_pause(int x, int y)
4278 {
4279   switch (cave[x][y+1])
4280   {
4281     case Xblank:
4282     case Xsplash_e:
4283     case Xsplash_w:
4284     case Xfake_acid_1:
4285     case Xfake_acid_2:
4286     case Xfake_acid_3:
4287     case Xfake_acid_4:
4288     case Xfake_acid_5:
4289     case Xfake_acid_6:
4290     case Xfake_acid_7:
4291     case Xfake_acid_8:
4292       cave[x][y] = Ystone_sB;
4293       next[x][y] = Xblank;
4294       cave[x][y+1] = Ystone_s;
4295       next[x][y+1] = Xstone_fall;
4296       return;
4297
4298     case Xacid_1:
4299     case Xacid_2:
4300     case Xacid_3:
4301     case Xacid_4:
4302     case Xacid_5:
4303     case Xacid_6:
4304     case Xacid_7:
4305     case Xacid_8:
4306       cave[x][y] = Ystone_sB;
4307       next[x][y] = Xblank;
4308       if (cave[x+1][y] == Xblank)
4309         cave[x+1][y] = Xsplash_e;
4310       if (cave[x-1][y] == Xblank)
4311         cave[x-1][y] = Xsplash_w;
4312       play_element_sound(x, y, SOUND_acid, Xacid_1);
4313       return;
4314
4315     default:
4316       cave[x][y] = Xstone;
4317       next[x][y] = Xstone;
4318       return;
4319   }
4320 }
4321
4322 static void Lstone_fall(int x, int y)
4323 {
4324   switch (cave[x][y+1])
4325   {
4326     case Zplayer:
4327     case Xblank:
4328     case Xsplash_e:
4329     case Xsplash_w:
4330     case Xfake_acid_1:
4331     case Xfake_acid_2:
4332     case Xfake_acid_3:
4333     case Xfake_acid_4:
4334     case Xfake_acid_5:
4335     case Xfake_acid_6:
4336     case Xfake_acid_7:
4337     case Xfake_acid_8:
4338       cave[x][y] = Ystone_sB;
4339       next[x][y] = Xblank;
4340       cave[x][y+1] = Ystone_s;
4341       next[x][y+1] = Xstone_fall;
4342       return;
4343
4344     case Xacid_1:
4345     case Xacid_2:
4346     case Xacid_3:
4347     case Xacid_4:
4348     case Xacid_5:
4349     case Xacid_6:
4350     case Xacid_7:
4351     case Xacid_8:
4352       cave[x][y] = Ystone_sB;
4353       next[x][y] = Xblank;
4354       if (cave[x+1][y] == Xblank)
4355         cave[x+1][y] = Xsplash_e;
4356       if (cave[x-1][y] == Xblank)
4357         cave[x-1][y] = Xsplash_w;
4358       play_element_sound(x, y, SOUND_acid, Xacid_1);
4359       return;
4360
4361     case Xeater_n:
4362     case Xeater_e:
4363     case Xeater_s:
4364     case Xeater_w:
4365       cave[x][y] = Ystone_sB;
4366       cave[x][y+1] = Yeater_stone;
4367       Lboom_eater(x, y+1, Xstone_fall);
4368       score += lev.eater_score;
4369       return;
4370
4371     case Xalien:
4372     case Xalien_pause:
4373       cave[x][y] = Ystone_sB;
4374       cave[x][y+1] = Yalien_stone;
4375       Lboom_tank(x, y+1, Xstone_fall);
4376       score += lev.alien_score;
4377       return;
4378
4379     case Xbug_1_n:
4380     case Xbug_1_e:
4381     case Xbug_1_s:
4382     case Xbug_1_w:
4383     case Xbug_2_n:
4384     case Xbug_2_e:
4385     case Xbug_2_s:
4386     case Xbug_2_w:
4387       cave[x][y] = Ystone_sB;
4388       cave[x][y+1] = Ybug_stone;
4389       Lboom_bug(x, y+1, Xstone_fall);
4390       score += lev.bug_score;
4391       return;
4392
4393     case Xtank_1_n:
4394     case Xtank_1_e:
4395     case Xtank_1_s:
4396     case Xtank_1_w:
4397     case Xtank_2_n:
4398     case Xtank_2_e:
4399     case Xtank_2_s:
4400     case Xtank_2_w:
4401       cave[x][y] = Ystone_sB;
4402       cave[x][y+1] = Ytank_stone;
4403       Lboom_tank(x, y+1, Xstone_fall);
4404       score += lev.tank_score;
4405       return;
4406
4407     case Xdiamond:
4408     case Xdiamond_pause:
4409       switch (cave[x][y+2])
4410       {
4411         case Zplayer:
4412         case Xblank:
4413         case Xsplash_e:
4414         case Xsplash_w:
4415         case Xfake_acid_1:
4416         case Xfake_acid_2:
4417         case Xfake_acid_3:
4418         case Xfake_acid_4:
4419         case Xfake_acid_5:
4420         case Xfake_acid_6:
4421         case Xfake_acid_7:
4422         case Xfake_acid_8:
4423         case Xplant:
4424         case Yplant:
4425         case Xacid_1:
4426         case Xacid_2:
4427         case Xacid_3:
4428         case Xacid_4:
4429         case Xacid_5:
4430         case Xacid_6:
4431         case Xacid_7:
4432         case Xacid_8:
4433         case Xandroid:
4434         case Xandroid_1_n:
4435         case Xandroid_2_n:
4436         case Xandroid_1_e:
4437         case Xandroid_2_e:
4438         case Xandroid_1_s:
4439         case Xandroid_2_s:
4440         case Xandroid_1_w:
4441         case Xandroid_2_w:
4442         case Xbug_1_n:
4443         case Xbug_1_e:
4444         case Xbug_1_s:
4445         case Xbug_1_w:
4446         case Xbug_2_n:
4447         case Xbug_2_e:
4448         case Xbug_2_s:
4449         case Xbug_2_w:
4450         case Xtank_1_n:
4451         case Xtank_1_e:
4452         case Xtank_1_s:
4453         case Xtank_1_w:
4454         case Xtank_2_n:
4455         case Xtank_2_e:
4456         case Xtank_2_s:
4457         case Xtank_2_w:
4458         case Xemerald_fall:
4459         case Xdiamond_fall:
4460         case Xstone_fall:
4461         case Xbomb_fall:
4462         case Xnut_fall:
4463         case Xspring_fall:
4464         case Xacid_s:
4465           next[x][y] = Xstone;
4466           play_element_sound(x, y, SOUND_stone, Xstone);
4467           return;
4468       }
4469
4470       cave[x][y] = Ystone_sB;
4471       next[x][y] = Xblank;
4472       cave[x][y+1] = Ydiamond_stone;
4473       next[x][y+1] = Xstone_pause;
4474       play_element_sound(x, y, SOUND_squash, Xdiamond);
4475       return;
4476
4477     case Xbomb:
4478     case Xbomb_pause:
4479       cave[x][y+1] = Ybomb_blank;
4480       Lboom_tank(x, y+1, Xstone_fall);
4481       return;
4482
4483     case Xnut:
4484     case Xnut_pause:
4485       next[x][y] = Xstone;
4486       cave[x][y+1] = Ynut_stone;
4487       next[x][y+1] = Xemerald;
4488       play_element_sound(x, y, SOUND_crack, Xnut);
4489       score += lev.nut_score;
4490       return;
4491
4492     case Xspring:
4493       if (RANDOM(2))
4494       {
4495         switch (cave[x+1][y+1])
4496         {
4497           case Xblank:
4498           case Xsplash_e:
4499           case Xsplash_w:
4500           case Xfake_acid_1:
4501           case Xfake_acid_2:
4502           case Xfake_acid_3:
4503           case Xfake_acid_4:
4504           case Xfake_acid_5:
4505           case Xfake_acid_6:
4506           case Xfake_acid_7:
4507           case Xfake_acid_8:
4508           case Xalien:
4509           case Xalien_pause:
4510             cave[x][y+1] = Xspring_e;
4511             break;
4512
4513           default:
4514             cave[x][y+1] = Xspring_w;
4515             break;
4516         }
4517       }
4518       else
4519       {
4520         switch (cave[x-1][y+1])
4521         {
4522           case Xblank:
4523           case Xsplash_e:
4524           case Xsplash_w:
4525           case Xfake_acid_1:
4526           case Xfake_acid_2:
4527           case Xfake_acid_3:
4528           case Xfake_acid_4:
4529           case Xfake_acid_5:
4530           case Xfake_acid_6:
4531           case Xfake_acid_7:
4532           case Xfake_acid_8:
4533           case Xalien:
4534           case Xalien_pause:
4535             cave[x][y+1] = Xspring_w;
4536             break;
4537           default:
4538             cave[x][y+1] = Xspring_e;
4539             break;
4540         }
4541       }
4542
4543       next[x][y] = Xstone;
4544       return;
4545
4546     case Xwonderwall:
4547       if (lev.wonderwall_time)
4548       {
4549         lev.wonderwall_state = 1;
4550         cave[x][y] = Ystone_sB;
4551         next[x][y] = Xblank;
4552         if (is_blank[cave[x][y+2]])
4553         {
4554           cave[x][y+2] = Yemerald_s;
4555           next[x][y+2] = Xemerald_fall;
4556         }
4557         play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4558         return;
4559       }
4560
4561     default:
4562       cave[x][y] = Xstone;
4563       next[x][y] = Xstone;
4564       play_element_sound(x, y, SOUND_stone, Xstone);
4565       return;
4566   }
4567 }
4568
4569 static void Lbomb(int x, int y)
4570 {
4571   switch (cave[x][y+1])
4572   {
4573     case Xblank:
4574     case Xsplash_e:
4575     case Xsplash_w:
4576     case Xfake_acid_1:
4577     case Xfake_acid_2:
4578     case Xfake_acid_3:
4579     case Xfake_acid_4:
4580     case Xfake_acid_5:
4581     case Xfake_acid_6:
4582     case Xfake_acid_7:
4583     case Xfake_acid_8:
4584       cave[x][y] = Ybomb_sB;
4585       next[x][y] = Xblank;
4586       cave[x][y+1] = Ybomb_s;
4587       next[x][y+1] = Xbomb_fall;
4588       return;
4589
4590     case Xacid_1:
4591     case Xacid_2:
4592     case Xacid_3:
4593     case Xacid_4:
4594     case Xacid_5:
4595     case Xacid_6:
4596     case Xacid_7:
4597     case Xacid_8:
4598       cave[x][y] = Ybomb_sB;
4599       next[x][y] = Xblank;
4600       if (cave[x+1][y] == Xblank)
4601         cave[x+1][y] = Xsplash_e;
4602       if (cave[x-1][y] == Xblank)
4603         cave[x-1][y] = Xsplash_w;
4604       play_element_sound(x, y, SOUND_acid, Xacid_1);
4605       return;
4606
4607     case Xandroid:
4608     case Xandroid_1_n:
4609     case Xandroid_2_n:
4610     case Xandroid_1_e:
4611     case Xandroid_2_e:
4612     case Xandroid_1_s:
4613     case Xandroid_2_s:
4614     case Xandroid_1_w:
4615     case Xandroid_2_w:
4616     case Xemerald:
4617     case Xemerald_pause:
4618     case Xdiamond:
4619     case Xdiamond_pause:
4620     case Xstone:
4621     case Xstone_pause:
4622     case Xbomb:
4623     case Xbomb_pause:
4624     case Xnut:
4625     case Xnut_pause:
4626     case Xspring:
4627     case Xspring_pause:
4628     case Xspring_e:
4629     case Xspring_w:
4630     case Xkey_1:
4631     case Xkey_2:
4632     case Xkey_3:
4633     case Xkey_4:
4634     case Xkey_5:
4635     case Xkey_6:
4636     case Xkey_7:
4637     case Xkey_8:
4638     case Xballoon:
4639     case Xball_1:
4640     case Xball_2:
4641     case Xswitch:
4642     case Xbumper:
4643     case Xacid_ne:
4644     case Xacid_nw:
4645     case Xslide_ns:
4646     case Xslide_ew:
4647     case Xroundwall_1:
4648     case Xroundwall_2:
4649     case Xroundwall_3:
4650     case Xroundwall_4:
4651       if (RANDOM(2))
4652       {
4653         if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4654         {
4655           cave[x][y] = Ybomb_eB;
4656           next[x][y] = Xblank;
4657           cave[x+1][y] = Ybomb_e;
4658           next[x+1][y] = Xbomb_pause;
4659           return;
4660         }
4661
4662         if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4663         {
4664           cave[x][y] = Ybomb_wB;
4665           next[x][y] = Xblank;
4666           cave[x-1][y] = Ybomb_w;
4667           next[x-1][y] = Xbomb_pause;
4668           return;
4669         }
4670       }
4671       else
4672       {
4673         if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4674         {
4675           cave[x][y] = Ybomb_wB;
4676           next[x][y] = Xblank;
4677           cave[x-1][y] = Ybomb_w;
4678           next[x-1][y] = Xbomb_pause;
4679           return;
4680         }
4681
4682         if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4683         {
4684           cave[x][y] = Ybomb_eB;
4685           next[x][y] = Xblank;
4686           cave[x+1][y] = Ybomb_e;
4687           next[x+1][y] = Xbomb_pause;
4688           return;
4689         }
4690       }
4691   }
4692 }
4693
4694 static void Lbomb_pause(int x, int y)
4695 {
4696   switch (cave[x][y+1])
4697   {
4698     case Xblank:
4699     case Xsplash_e:
4700     case Xsplash_w:
4701     case Xfake_acid_1:
4702     case Xfake_acid_2:
4703     case Xfake_acid_3:
4704     case Xfake_acid_4:
4705     case Xfake_acid_5:
4706     case Xfake_acid_6:
4707     case Xfake_acid_7:
4708     case Xfake_acid_8:
4709       cave[x][y] = Ybomb_sB;
4710       next[x][y] = Xblank;
4711       cave[x][y+1] = Ybomb_s;
4712       next[x][y+1] = Xbomb_fall;
4713       return;
4714
4715     case Xacid_1:
4716     case Xacid_2:
4717     case Xacid_3:
4718     case Xacid_4:
4719     case Xacid_5:
4720     case Xacid_6:
4721     case Xacid_7:
4722     case Xacid_8:
4723       cave[x][y] = Ybomb_sB;
4724       next[x][y] = Xblank;
4725       if (cave[x+1][y] == Xblank)
4726         cave[x+1][y] = Xsplash_e;
4727       if (cave[x-1][y] == Xblank)
4728         cave[x-1][y] = Xsplash_w;
4729       play_element_sound(x, y, SOUND_acid, Xacid_1);
4730       return;
4731
4732     default:
4733       cave[x][y] = Xbomb;
4734       next[x][y] = Xbomb;
4735       return;
4736   }
4737 }
4738
4739 static void Lbomb_fall(int x, int y)
4740 {
4741   switch (cave[x][y+1])
4742   {
4743     case Xblank:
4744     case Xsplash_e:
4745     case Xsplash_w:
4746     case Xfake_acid_1:
4747     case Xfake_acid_2:
4748     case Xfake_acid_3:
4749     case Xfake_acid_4:
4750     case Xfake_acid_5:
4751     case Xfake_acid_6:
4752     case Xfake_acid_7:
4753     case Xfake_acid_8:
4754       cave[x][y] = Ybomb_sB;
4755       next[x][y] = Xblank;
4756       cave[x][y+1] = Ybomb_s;
4757       next[x][y+1] = Xbomb_fall;
4758       return;
4759
4760     case Xacid_1:
4761     case Xacid_2:
4762     case Xacid_3:
4763     case Xacid_4:
4764     case Xacid_5:
4765     case Xacid_6:
4766     case Xacid_7:
4767     case Xacid_8:
4768       cave[x][y] = Ybomb_sB;
4769       next[x][y] = Xblank;
4770       if (cave[x+1][y] == Xblank)
4771         cave[x+1][y] = Xsplash_e;
4772       if (cave[x-1][y] == Xblank)
4773         cave[x-1][y] = Xsplash_w;
4774       play_element_sound(x, y, SOUND_acid, Xacid_1);
4775       return;
4776
4777     default:
4778       cave[x][y] = Ybomb_blank;
4779       Lboom_tank(x, y, Xbomb_fall);
4780       return;
4781   }
4782 }
4783
4784 static void Lnut(int x, int y)
4785 {
4786   switch (cave[x][y+1])
4787   {
4788     case Xblank:
4789     case Xsplash_e:
4790     case Xsplash_w:
4791     case Xfake_acid_1:
4792     case Xfake_acid_2:
4793     case Xfake_acid_3:
4794     case Xfake_acid_4:
4795     case Xfake_acid_5:
4796     case Xfake_acid_6:
4797     case Xfake_acid_7:
4798     case Xfake_acid_8:
4799       cave[x][y] = Ynut_sB;
4800       next[x][y] = Xblank;
4801       cave[x][y+1] = Ynut_s;
4802       next[x][y+1] = Xnut_fall;
4803       return;
4804
4805     case Xacid_1:
4806     case Xacid_2:
4807     case Xacid_3:
4808     case Xacid_4:
4809     case Xacid_5:
4810     case Xacid_6:
4811     case Xacid_7:
4812     case Xacid_8:
4813       cave[x][y] = Ynut_sB;
4814       next[x][y] = Xblank;
4815       if (cave[x+1][y] == Xblank)
4816         cave[x+1][y] = Xsplash_e;
4817       if (cave[x-1][y] == Xblank)
4818         cave[x-1][y] = Xsplash_w;
4819       play_element_sound(x, y, SOUND_acid, Xacid_1);
4820       return;
4821
4822     case Xandroid:
4823     case Xandroid_1_n:
4824     case Xandroid_2_n:
4825     case Xandroid_1_e:
4826     case Xandroid_2_e:
4827     case Xandroid_1_s:
4828     case Xandroid_2_s:
4829     case Xandroid_1_w:
4830     case Xandroid_2_w:
4831     case Xemerald:
4832     case Xemerald_pause:
4833     case Xdiamond:
4834     case Xdiamond_pause:
4835     case Xstone:
4836     case Xstone_pause:
4837     case Xbomb:
4838     case Xbomb_pause:
4839     case Xnut:
4840     case Xnut_pause:
4841     case Xspring:
4842     case Xspring_pause:
4843     case Xspring_e:
4844     case Xspring_w:
4845     case Xkey_1:
4846     case Xkey_2:
4847     case Xkey_3:
4848     case Xkey_4:
4849     case Xkey_5:
4850     case Xkey_6:
4851     case Xkey_7:
4852     case Xkey_8:
4853     case Xballoon:
4854     case Xball_1:
4855     case Xball_2:
4856     case Xswitch:
4857     case Xbumper:
4858     case Xacid_ne:
4859     case Xacid_nw:
4860     case Xslide_ns:
4861     case Xslide_ew:
4862     case Xroundwall_1:
4863     case Xroundwall_2:
4864     case Xroundwall_3:
4865     case Xroundwall_4:
4866       if (RANDOM(2))
4867       {
4868         if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4869         {
4870           cave[x][y] = Ynut_eB;
4871           next[x][y] = Xblank;
4872           cave[x+1][y] = Ynut_e;
4873           next[x+1][y] = Xnut_pause;
4874           return;
4875         }
4876
4877         if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4878         {
4879           cave[x][y] = Ynut_wB;
4880           next[x][y] = Xblank;
4881           cave[x-1][y] = Ynut_w;
4882           next[x-1][y] = Xnut_pause;
4883           return;
4884         }
4885       }
4886       else
4887       {
4888         if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4889         {
4890           cave[x][y] = Ynut_wB;
4891           next[x][y] = Xblank;
4892           cave[x-1][y] = Ynut_w;
4893           next[x-1][y] = Xnut_pause;
4894           return;
4895         }
4896
4897         if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4898         {
4899           cave[x][y] = Ynut_eB;
4900           next[x][y] = Xblank;
4901           cave[x+1][y] = Ynut_e;
4902           next[x+1][y] = Xnut_pause;
4903           return;
4904         }
4905       }
4906   }
4907 }
4908
4909 static void Lnut_pause(int x, int y)
4910 {
4911   switch (cave[x][y+1])
4912   {
4913     case Xblank:
4914     case Xsplash_e:
4915     case Xsplash_w:
4916     case Xfake_acid_1:
4917     case Xfake_acid_2:
4918     case Xfake_acid_3:
4919     case Xfake_acid_4:
4920     case Xfake_acid_5:
4921     case Xfake_acid_6:
4922     case Xfake_acid_7:
4923     case Xfake_acid_8:
4924       cave[x][y] = Ynut_sB;
4925       next[x][y] = Xblank;
4926       cave[x][y+1] = Ynut_s;
4927       next[x][y+1] = Xnut_fall;
4928       return;
4929
4930     case Xacid_1:
4931     case Xacid_2:
4932     case Xacid_3:
4933     case Xacid_4:
4934     case Xacid_5:
4935     case Xacid_6:
4936     case Xacid_7:
4937     case Xacid_8:
4938       cave[x][y] = Ynut_sB;
4939       next[x][y] = Xblank;
4940       if (cave[x+1][y] == Xblank)
4941         cave[x+1][y] = Xsplash_e;
4942       if (cave[x-1][y] == Xblank)
4943         cave[x-1][y] = Xsplash_w;
4944       play_element_sound(x, y, SOUND_acid, Xacid_1);
4945       return;
4946
4947     default:
4948       cave[x][y] = Xnut;
4949       next[x][y] = Xnut;
4950       return;
4951   }
4952 }
4953
4954 static void Lnut_fall(int x, int y)
4955 {
4956   switch (cave[x][y+1])
4957   {
4958     case Zplayer:
4959     case Xblank:
4960     case Xsplash_e:
4961     case Xsplash_w:
4962     case Xfake_acid_1:
4963     case Xfake_acid_2:
4964     case Xfake_acid_3:
4965     case Xfake_acid_4:
4966     case Xfake_acid_5:
4967     case Xfake_acid_6:
4968     case Xfake_acid_7:
4969     case Xfake_acid_8:
4970       cave[x][y] = Ynut_sB;
4971       next[x][y] = Xblank;
4972       cave[x][y+1] = Ynut_s;
4973       next[x][y+1] = Xnut_fall;
4974       return;
4975
4976     case Xacid_1:
4977     case Xacid_2:
4978     case Xacid_3:
4979     case Xacid_4:
4980     case Xacid_5:
4981     case Xacid_6:
4982     case Xacid_7:
4983     case Xacid_8:
4984       cave[x][y] = Ynut_sB;
4985       next[x][y] = Xblank;
4986       if (cave[x+1][y] == Xblank)
4987         cave[x+1][y] = Xsplash_e;
4988       if (cave[x-1][y] == Xblank)
4989         cave[x-1][y] = Xsplash_w;
4990       play_element_sound(x, y, SOUND_acid, Xacid_1);
4991       return;
4992
4993     default:
4994       cave[x][y] = Xnut;
4995       next[x][y] = Xnut;
4996       play_element_sound(x, y, SOUND_nut, Xnut);
4997       return;
4998   }
4999 }
5000
5001 static void Lspring(int x, int y)
5002 {
5003   switch (cave[x][y+1])
5004   {
5005     case Xblank:
5006     case Xsplash_e:
5007     case Xsplash_w:
5008     case Xfake_acid_1:
5009     case Xfake_acid_2:
5010     case Xfake_acid_3:
5011     case Xfake_acid_4:
5012     case Xfake_acid_5:
5013     case Xfake_acid_6:
5014     case Xfake_acid_7:
5015     case Xfake_acid_8:
5016     case Xplant:
5017     case Yplant:
5018       cave[x][y] = Yspring_sB;
5019       next[x][y] = Xblank;
5020       cave[x][y+1] = Yspring_s;
5021       next[x][y+1] = Xspring_fall;
5022       return;
5023
5024     case Xacid_1:
5025     case Xacid_2:
5026     case Xacid_3:
5027     case Xacid_4:
5028     case Xacid_5:
5029     case Xacid_6:
5030     case Xacid_7:
5031     case Xacid_8:
5032       cave[x][y] = Yspring_sB;
5033       next[x][y] = Xblank;
5034       if (cave[x+1][y] == Xblank)
5035         cave[x+1][y] = Xsplash_e;
5036       if (cave[x-1][y] == Xblank)
5037         cave[x-1][y] = Xsplash_w;
5038       play_element_sound(x, y, SOUND_acid, Xacid_1);
5039       return;
5040
5041     case Xandroid:
5042     case Xandroid_1_n:
5043     case Xandroid_2_n:
5044     case Xandroid_1_e:
5045     case Xandroid_2_e:
5046     case Xandroid_1_s:
5047     case Xandroid_2_s:
5048     case Xandroid_1_w:
5049     case Xandroid_2_w:
5050     case Xemerald:
5051     case Xemerald_pause:
5052     case Xdiamond:
5053     case Xdiamond_pause:
5054     case Xstone:
5055     case Xstone_pause:
5056     case Xbomb:
5057     case Xbomb_pause:
5058     case Xnut:
5059     case Xnut_pause:
5060     case Xspring:
5061     case Xspring_pause:
5062     case Xspring_e:
5063     case Xspring_w:
5064     case Xkey_1:
5065     case Xkey_2:
5066     case Xkey_3:
5067     case Xkey_4:
5068     case Xkey_5:
5069     case Xkey_6:
5070     case Xkey_7:
5071     case Xkey_8:
5072     case Xballoon:
5073     case Xball_1:
5074     case Xball_2:
5075     case Xswitch:
5076     case Xbumper:
5077     case Xacid_ne:
5078     case Xacid_nw:
5079     case Xslide_ns:
5080     case Xslide_ew:
5081     case Xroundwall_1:
5082     case Xroundwall_2:
5083     case Xroundwall_3:
5084     case Xroundwall_4:
5085       if (RANDOM(2))
5086       {
5087         if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5088         {
5089           cave[x][y] = Yspring_eB;
5090           next[x][y] = Xblank;
5091           cave[x+1][y] = Yspring_e;
5092           if (cave[x][y+1] == Xbumper)
5093             cave[x][y+1] = Ybumper;
5094
5095 #ifdef SPRING_ROLL
5096           next[x+1][y] = Xspring_e;
5097 #else
5098           next[x+1][y] = Xspring_pause;
5099 #endif
5100           return;
5101         }
5102
5103         if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5104         {
5105           cave[x][y] = Yspring_wB;
5106           next[x][y] = Xblank;
5107           cave[x-1][y] = Yspring_w;
5108           if (cave[x][y+1] == Xbumper)
5109             cave[x][y+1] = Ybumper;
5110
5111 #ifdef SPRING_ROLL
5112           next[x-1][y] = Xspring_w;
5113 #else
5114           next[x-1][y] = Xspring_pause;
5115 #endif
5116           return;
5117         }
5118       }
5119       else
5120       {
5121         if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5122         {
5123           cave[x][y] = Yspring_wB;
5124           next[x][y] = Xblank;
5125           cave[x-1][y] = Yspring_w;
5126           if (cave[x][y+1] == Xbumper)
5127             cave[x][y+1] = Ybumper;
5128
5129 #ifdef SPRING_ROLL
5130           next[x-1][y] = Xspring_w;
5131 #else
5132           next[x-1][y] = Xspring_pause;
5133 #endif
5134           return;
5135         }
5136
5137         if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5138         {
5139           cave[x][y] = Yspring_eB;
5140           next[x][y] = Xblank;
5141           cave[x+1][y] = Yspring_e;
5142           if (cave[x][y+1] == Xbumper)
5143             cave[x][y+1] = Ybumper;
5144
5145 #ifdef SPRING_ROLL
5146           next[x+1][y] = Xspring_e;
5147 #else
5148           next[x+1][y] = Xspring_pause;
5149 #endif
5150           return;
5151         }
5152       }
5153   }
5154 }
5155
5156 static void Lspring_pause(int x, int y)
5157 {
5158   switch (cave[x][y+1])
5159   {
5160     case Xblank:
5161     case Xsplash_e:
5162     case Xsplash_w:
5163     case Xfake_acid_1:
5164     case Xfake_acid_2:
5165     case Xfake_acid_3:
5166     case Xfake_acid_4:
5167     case Xfake_acid_5:
5168     case Xfake_acid_6:
5169     case Xfake_acid_7:
5170     case Xfake_acid_8:
5171       cave[x][y] = Yspring_sB;
5172       next[x][y] = Xblank;
5173       cave[x][y+1] = Yspring_s;
5174       next[x][y+1] = Xspring_fall;
5175       return;
5176
5177     case Xacid_1:
5178     case Xacid_2:
5179     case Xacid_3:
5180     case Xacid_4:
5181     case Xacid_5:
5182     case Xacid_6:
5183     case Xacid_7:
5184     case Xacid_8:
5185       cave[x][y] = Yspring_sB;
5186       next[x][y] = Xblank;
5187       if (cave[x+1][y] == Xblank)
5188         cave[x+1][y] = Xsplash_e;
5189       if (cave[x-1][y] == Xblank)
5190         cave[x-1][y] = Xsplash_w;
5191       play_element_sound(x, y, SOUND_acid, Xacid_1);
5192       return;
5193
5194     default:
5195       cave[x][y] = Xspring;
5196       next[x][y] = Xspring;
5197       return;
5198   }
5199 }
5200
5201 static void Lspring_e(int x, int y)
5202 {
5203   switch (cave[x][y+1])
5204   {
5205     case Xblank:
5206     case Xsplash_e:
5207     case Xsplash_w:
5208     case Xfake_acid_1:
5209     case Xfake_acid_2:
5210     case Xfake_acid_3:
5211     case Xfake_acid_4:
5212     case Xfake_acid_5:
5213     case Xfake_acid_6:
5214     case Xfake_acid_7:
5215     case Xfake_acid_8:
5216       cave[x][y] = Yspring_sB;
5217       next[x][y] = Xblank;
5218       cave[x][y+1] = Yspring_s;
5219       next[x][y+1] = Xspring_fall;
5220       return;
5221
5222     case Xacid_1:
5223     case Xacid_2:
5224     case Xacid_3:
5225     case Xacid_4:
5226     case Xacid_5:
5227     case Xacid_6:
5228     case Xacid_7:
5229     case Xacid_8:
5230       cave[x][y] = Yspring_sB;
5231       next[x][y] = Xblank;
5232       if (cave[x+1][y] == Xblank)
5233         cave[x+1][y] = Xsplash_e;
5234       if (cave[x-1][y] == Xblank)
5235         cave[x-1][y] = Xsplash_w;
5236       play_element_sound(x, y, SOUND_acid, Xacid_1);
5237       return;
5238
5239     case Xbumper:
5240       cave[x][y+1] = Ybumper;
5241   }
5242
5243   switch (cave[x+1][y])
5244   {
5245     case Xblank:
5246     case Xsplash_e:
5247     case Xsplash_w:
5248     case Xfake_acid_1:
5249     case Xfake_acid_2:
5250     case Xfake_acid_3:
5251     case Xfake_acid_4:
5252     case Xfake_acid_5:
5253     case Xfake_acid_6:
5254     case Xfake_acid_7:
5255     case Xfake_acid_8:
5256     case Yalien_nB:
5257     case Yalien_eB:
5258     case Yalien_sB:
5259     case Yalien_wB:
5260       cave[x][y] = Yspring_eB;
5261       next[x][y] = Xblank;
5262       cave[x+1][y] = Yspring_e;
5263       next[x+1][y] = Xspring_e;
5264       return;
5265
5266     case Xacid_1:
5267     case Xacid_2:
5268     case Xacid_3:
5269     case Xacid_4:
5270     case Xacid_5:
5271     case Xacid_6:
5272     case Xacid_7:
5273     case Xacid_8:
5274       cave[x][y] = Yspring_eB;
5275       next[x][y] = Xblank;
5276       if (cave[x+2][y-1] == Xblank)
5277         cave[x+2][y-1] = Xsplash_e;
5278       if (cave[x][y-1] == Xblank)
5279         cave[x][y-1] = Xsplash_w;
5280       play_element_sound(x, y, SOUND_acid, Xacid_1);
5281       return;
5282
5283     case Xalien:
5284     case Xalien_pause:
5285     case Yalien_n:
5286     case Yalien_e:
5287     case Yalien_s:
5288     case Yalien_w:
5289       cave[x][y] = Yspring_alien_eB;
5290       next[x][y] = Xblank;
5291       cave[x+1][y] = Yspring_alien_e;
5292       next[x+1][y] = Xspring_e;
5293       play_element_sound(x, y, SOUND_slurp, Xalien);
5294       score += lev.slurp_score;
5295       return;
5296
5297     case Xbumper:
5298     case Ybumper:
5299       cave[x+1][y] = Ybumper;
5300       next[x][y] = Xspring_w;
5301       play_element_sound(x, y, SOUND_spring, Xspring);
5302       return;
5303
5304     default:
5305       cave[x][y] = Xspring;
5306       next[x][y] = Xspring;
5307       play_element_sound(x, y, SOUND_spring, Xspring);
5308       return;
5309   }
5310 }
5311
5312 static void Lspring_w(int x, int y)
5313 {
5314   switch (cave[x][y+1])
5315   {
5316     case Xblank:
5317     case Xsplash_e:
5318     case Xsplash_w:
5319     case Xfake_acid_1:
5320     case Xfake_acid_2:
5321     case Xfake_acid_3:
5322     case Xfake_acid_4:
5323     case Xfake_acid_5:
5324     case Xfake_acid_6:
5325     case Xfake_acid_7:
5326     case Xfake_acid_8:
5327       cave[x][y] = Yspring_sB;
5328       next[x][y] = Xblank;
5329       cave[x][y+1] = Yspring_s;
5330       next[x][y+1] = Xspring_fall;
5331       return;
5332
5333     case Xacid_1:
5334     case Xacid_2:
5335     case Xacid_3:
5336     case Xacid_4:
5337     case Xacid_5:
5338     case Xacid_6:
5339     case Xacid_7:
5340     case Xacid_8:
5341       cave[x][y] = Yspring_sB;
5342       next[x][y] = Xblank;
5343       if (cave[x+1][y] == Xblank)
5344         cave[x+1][y] = Xsplash_e;
5345       if (cave[x-1][y] == Xblank)
5346         cave[x-1][y] = Xsplash_w;
5347       play_element_sound(x, y, SOUND_acid, Xacid_1);
5348       return;
5349
5350     case Xbumper:
5351       cave[x][y+1] = Ybumper;
5352   }
5353
5354   switch (cave[x-1][y])
5355   {
5356     case Xblank:
5357     case Xsplash_e:
5358     case Xsplash_w:
5359     case Xfake_acid_1:
5360     case Xfake_acid_2:
5361     case Xfake_acid_3:
5362     case Xfake_acid_4:
5363     case Xfake_acid_5:
5364     case Xfake_acid_6:
5365     case Xfake_acid_7:
5366     case Xfake_acid_8:
5367     case Yalien_nB:
5368     case Yalien_eB:
5369     case Yalien_sB:
5370     case Yalien_wB:
5371       cave[x][y] = Yspring_wB;
5372       next[x][y] = Xblank;
5373       cave[x-1][y] = Yspring_w;
5374       next[x-1][y] = Xspring_w;
5375       return;
5376
5377     case Xacid_1:
5378     case Xacid_2:
5379     case Xacid_3:
5380     case Xacid_4:
5381     case Xacid_5:
5382     case Xacid_6:
5383     case Xacid_7:
5384     case Xacid_8:
5385       cave[x][y] = Yspring_wB;
5386       next[x][y] = Xblank;
5387       if (cave[x][y-1] == Xblank)
5388         cave[x][y-1] = Xsplash_e;
5389       if (cave[x-2][y-1] == Xblank)
5390         cave[x-2][y-1] = Xsplash_w;
5391       play_element_sound(x, y, SOUND_acid, Xacid_1);
5392       return;
5393
5394     case Xalien:
5395     case Xalien_pause:
5396     case Yalien_n:
5397     case Yalien_e:
5398     case Yalien_s:
5399     case Yalien_w:
5400       cave[x][y] = Yspring_alien_wB;
5401       next[x][y] = Xblank;
5402       cave[x-1][y] = Yspring_alien_w;
5403       next[x-1][y] = Xspring_w;
5404       play_element_sound(x, y, SOUND_slurp, Xalien);
5405       score += lev.slurp_score;
5406       return;
5407
5408     case Xbumper:
5409     case Ybumper:
5410       cave[x-1][y] = Ybumper;
5411       next[x][y] = Xspring_e;
5412       play_element_sound(x, y, SOUND_spring, Xspring);
5413       return;
5414
5415     default:
5416       cave[x][y] = Xspring;
5417       next[x][y] = Xspring;
5418       play_element_sound(x, y, SOUND_spring, Xspring);
5419       return;
5420   }
5421 }
5422
5423 static void Lspring_fall(int x, int y)
5424 {
5425   switch (cave[x][y+1])
5426   {
5427     case Zplayer:
5428     case Xblank:
5429     case Xsplash_e:
5430     case Xsplash_w:
5431     case Xfake_acid_1:
5432     case Xfake_acid_2:
5433     case Xfake_acid_3:
5434     case Xfake_acid_4:
5435     case Xfake_acid_5:
5436     case Xfake_acid_6:
5437     case Xfake_acid_7:
5438     case Xfake_acid_8:
5439       cave[x][y] = Yspring_sB;
5440       next[x][y] = Xblank;
5441       cave[x][y+1] = Yspring_s;
5442       next[x][y+1] = Xspring_fall;
5443       return;
5444
5445     case Xacid_1:
5446     case Xacid_2:
5447     case Xacid_3:
5448     case Xacid_4:
5449     case Xacid_5:
5450     case Xacid_6:
5451     case Xacid_7:
5452     case Xacid_8:
5453       cave[x][y] = Yspring_sB;
5454       next[x][y] = Xblank;
5455       if (cave[x+1][y] == Xblank)
5456         cave[x+1][y] = Xsplash_e;
5457       if (cave[x-1][y] == Xblank)
5458         cave[x-1][y] = Xsplash_w;
5459       play_element_sound(x, y, SOUND_acid, Xacid_1);
5460       return;
5461
5462     case Xeater_n:
5463     case Xeater_e:
5464     case Xeater_s:
5465     case Xeater_w:
5466       cave[x][y] = Yspring_sB;
5467       cave[x][y+1] = Yeater_spring;
5468       Lboom_eater(x, y+1, Xspring_fall);
5469       score += lev.eater_score;
5470       return;
5471
5472     case Xalien:
5473     case Xalien_pause:
5474       cave[x][y] = Yspring_sB;
5475       cave[x][y+1] = Yalien_spring;
5476       Lboom_tank(x, y+1, Xspring_fall);
5477       score += lev.alien_score;
5478       return;
5479
5480     case Xbug_1_n:
5481     case Xbug_1_e:
5482     case Xbug_1_s:
5483     case Xbug_1_w:
5484     case Xbug_2_n:
5485     case Xbug_2_e:
5486     case Xbug_2_s:
5487     case Xbug_2_w:
5488       cave[x][y] = Yspring_sB;
5489       cave[x][y+1] = Ybug_spring;
5490       Lboom_bug(x, y+1, Xspring_fall);
5491       score += lev.bug_score;
5492       return;
5493
5494     case Xtank_1_n:
5495     case Xtank_1_e:
5496     case Xtank_1_s:
5497     case Xtank_1_w:
5498     case Xtank_2_n:
5499     case Xtank_2_e:
5500     case Xtank_2_s:
5501     case Xtank_2_w:
5502       cave[x][y] = Yspring_sB;
5503       cave[x][y+1] = Ytank_spring;
5504       Lboom_tank(x, y+1, Xspring_fall);
5505       score += lev.tank_score;
5506       return;
5507
5508     case Xbomb:
5509     case Xbomb_pause:
5510       cave[x][y+1] = Ybomb_blank;
5511       Lboom_tank(x, y+1, Xspring_fall);
5512       return;
5513
5514     default:
5515       cave[x][y] = Xspring;
5516       next[x][y] = Xspring;
5517       play_element_sound(x, y, SOUND_spring, Xspring);
5518       return;
5519   }
5520 }
5521
5522 static void Lpush_emerald_e(int x, int y)
5523 {
5524   switch (cave[x+1][y])
5525   {
5526     case Zplayer:
5527     case Zborder:
5528     case Znormal:
5529     case Zdynamite:
5530     case Xboom_bug:
5531     case Xboom_bomb:
5532     case Xboom_android:
5533     case Xboom_1:
5534       cave[x][y] = Xemerald;
5535       next[x][y] = Xemerald;
5536       return;
5537
5538     default:
5539       cave[x][y] = Yemerald_eB;
5540       next[x][y] = Xblank;
5541       cave[x+1][y] = Yemerald_e;
5542       next[x+1][y] = Xemerald_pause;
5543       return;
5544   }
5545 }
5546
5547 static void Lpush_emerald_w(int x, int y)
5548 {
5549   switch (cave[x-1][y])
5550   {
5551     case Zplayer:
5552     case Zborder:
5553     case Znormal:
5554     case Zdynamite:
5555     case Xboom_bug:
5556     case Xboom_bomb:
5557     case Xboom_android:
5558     case Xboom_1:
5559       cave[x][y] = Xemerald;
5560       next[x][y] = Xemerald;
5561       return;
5562
5563     default:
5564       cave[x][y] = Yemerald_wB;
5565       next[x][y] = Xblank;
5566       cave[x-1][y] = Yemerald_w;
5567       next[x-1][y] = Xemerald_pause;
5568       return;
5569   }
5570 }
5571
5572 static void Lpush_diamond_e(int x, int y)
5573 {
5574   switch (cave[x+1][y])
5575   {
5576     case Zplayer:
5577     case Zborder:
5578     case Znormal:
5579     case Zdynamite:
5580     case Xboom_bug:
5581     case Xboom_bomb:
5582     case Xboom_android:
5583     case Xboom_1:
5584       cave[x][y] = Xdiamond;
5585       next[x][y] = Xdiamond;
5586       return;
5587
5588     default:
5589       cave[x][y] = Ydiamond_eB;
5590       next[x][y] = Xblank;
5591       cave[x+1][y] = Ydiamond_e;
5592       next[x+1][y] = Xdiamond_pause;
5593       return;
5594   }
5595 }
5596
5597 static void Lpush_diamond_w(int x, int y)
5598 {
5599   switch (cave[x-1][y])
5600   {
5601     case Zplayer:
5602     case Zborder:
5603     case Znormal:
5604     case Zdynamite:
5605     case Xboom_bug:
5606     case Xboom_bomb:
5607     case Xboom_android:
5608     case Xboom_1:
5609       cave[x][y] = Xdiamond;
5610       next[x][y] = Xdiamond;
5611       return;
5612
5613     default:
5614       cave[x][y] = Ydiamond_wB;
5615       next[x][y] = Xblank;
5616       cave[x-1][y] = Ydiamond_w;
5617       next[x-1][y] = Xdiamond_pause;
5618       return;
5619   }
5620 }
5621
5622 static void Lpush_stone_e(int x, int y)
5623 {
5624   switch (cave[x+1][y])
5625   {
5626     case Zplayer:
5627     case Zborder:
5628     case Znormal:
5629     case Zdynamite:
5630     case Xboom_bug:
5631     case Xboom_bomb:
5632     case Xboom_android:
5633     case Xboom_1:
5634       cave[x][y] = Xstone;
5635       next[x][y] = Xstone;
5636       return;
5637
5638     default:
5639       cave[x][y] = Ystone_eB;
5640       next[x][y] = Xblank;
5641       cave[x+1][y] = Ystone_e;
5642       next[x+1][y] = Xstone_pause;
5643       return;
5644   }
5645 }
5646
5647 static void Lpush_stone_w(int x, int y)
5648 {
5649   switch (cave[x-1][y])
5650   {
5651     case Zplayer:
5652     case Zborder:
5653     case Znormal:
5654     case Zdynamite:
5655     case Xboom_bug:
5656     case Xboom_bomb:
5657     case Xboom_android:
5658     case Xboom_1:
5659       cave[x][y] = Xstone;
5660       next[x][y] = Xstone;
5661       return;
5662
5663     default:
5664       cave[x][y] = Ystone_wB;
5665       next[x][y] = Xblank;
5666       cave[x-1][y] = Ystone_w;
5667       next[x-1][y] = Xstone_pause;
5668       return;
5669   }
5670 }
5671
5672 static void Lpush_bomb_e(int x, int y)
5673 {
5674   switch (cave[x+1][y])
5675   {
5676     case Zplayer:
5677     case Zborder:
5678     case Znormal:
5679     case Zdynamite:
5680     case Xboom_bug:
5681     case Xboom_bomb:
5682     case Xboom_android:
5683     case Xboom_1:
5684       cave[x][y] = Xbomb;
5685       next[x][y] = Xbomb;
5686       return;
5687
5688     default:
5689       cave[x][y] = Ybomb_eB;
5690       next[x][y] = Xblank;
5691       cave[x+1][y] = Ybomb_e;
5692       next[x+1][y] = Xbomb_pause;
5693       return;
5694   }
5695 }
5696
5697 static void Lpush_bomb_w(int x, int y)
5698 {
5699   switch (cave[x-1][y])
5700   {
5701     case Zplayer:
5702     case Zborder:
5703     case Znormal:
5704     case Zdynamite:
5705     case Xboom_bug:
5706     case Xboom_bomb:
5707     case Xboom_android:
5708     case Xboom_1:
5709       cave[x][y] = Xbomb;
5710       next[x][y] = Xbomb;
5711       return;
5712
5713     default:
5714       cave[x][y] = Ybomb_wB;
5715       next[x][y] = Xblank;
5716       cave[x-1][y] = Ybomb_w;
5717       next[x-1][y] = Xbomb_pause;
5718       return;
5719   }
5720 }
5721
5722 static void Lpush_nut_e(int x, int y)
5723 {
5724   switch (cave[x+1][y])
5725   {
5726     case Zplayer:
5727     case Zborder:
5728     case Znormal:
5729     case Zdynamite:
5730     case Xboom_bug:
5731     case Xboom_bomb:
5732     case Xboom_android:
5733     case Xboom_1:
5734       cave[x][y] = Xnut;
5735       next[x][y] = Xnut;
5736       return;
5737
5738     default:
5739       cave[x][y] = Ynut_eB;
5740       next[x][y] = Xblank;
5741       cave[x+1][y] = Ynut_e;
5742       next[x+1][y] = Xnut_pause;
5743       return;
5744   }
5745 }
5746
5747 static void Lpush_nut_w(int x, int y)
5748 {
5749   switch (cave[x-1][y])
5750   {
5751     case Zplayer:
5752     case Zborder:
5753     case Znormal:
5754     case Zdynamite:
5755     case Xboom_bug:
5756     case Xboom_bomb:
5757     case Xboom_android:
5758     case Xboom_1:
5759       cave[x][y] = Xnut;
5760       next[x][y] = Xnut;
5761       return;
5762
5763     default:
5764       cave[x][y] = Ynut_wB;
5765       next[x][y] = Xblank;
5766       cave[x-1][y] = Ynut_w;
5767       next[x-1][y] = Xnut_pause;
5768       return;
5769   }
5770 }
5771
5772 static void Lpush_spring_e(int x, int y)
5773 {
5774   switch (cave[x+1][y])
5775   {
5776     case Zplayer:
5777     case Zborder:
5778     case Znormal:
5779     case Zdynamite:
5780     case Xboom_bug:
5781     case Xboom_bomb:
5782     case Xboom_android:
5783     case Xboom_1:
5784       cave[x][y] = Xspring;
5785       next[x][y] = Xspring;
5786       return;
5787
5788     default:
5789       cave[x][y] = Yspring_eB;
5790       next[x][y] = Xblank;
5791       cave[x+1][y] = Yspring_e;
5792       next[x+1][y] = Xspring_e;
5793       return;
5794   }
5795 }
5796
5797 static void Lpush_spring_w(int x, int y)
5798 {
5799   switch (cave[x-1][y])
5800   {
5801     case Zplayer:
5802     case Zborder:
5803     case Znormal:
5804     case Zdynamite:
5805     case Xboom_bug:
5806     case Xboom_bomb:
5807     case Xboom_android:
5808     case Xboom_1:
5809       cave[x][y] = Xspring;
5810       next[x][y] = Xspring;
5811       return;
5812
5813     default:
5814       cave[x][y] = Yspring_wB;
5815       next[x][y] = Xblank;
5816       cave[x-1][y] = Yspring_w;
5817       next[x-1][y] = Xspring_w;
5818       return;
5819   }
5820 }
5821
5822 static void Ldynamite_1(int x, int y)
5823 {
5824   play_element_sound(x, y, SOUND_tick, Xdynamite_1);
5825   next[x][y] = Xdynamite_2;
5826 }
5827
5828 static void Ldynamite_2(int x, int y)
5829 {
5830   play_element_sound(x, y, SOUND_tick, Xdynamite_2);
5831   next[x][y] = Xdynamite_3;
5832 }
5833
5834 static void Ldynamite_3(int x, int y)
5835 {
5836   play_element_sound(x, y, SOUND_tick, Xdynamite_3);
5837   next[x][y] = Xdynamite_4;
5838 }
5839
5840 static void Ldynamite_4(int x, int y)
5841 {
5842   play_element_sound(x, y, SOUND_tick, Xdynamite_4);
5843   next[x][y] = Zdynamite;
5844
5845   Lboom_generic(x, y, Xblank, Xblank);
5846 }
5847
5848 static void Lfake_door_1(int x, int y)
5849 {
5850   if (lev.magnify_cnt)
5851     cave[x][y] = Xdoor_1;
5852 }
5853
5854 static void Lfake_door_2(int x, int y)
5855 {
5856   if (lev.magnify_cnt)
5857     cave[x][y] = Xdoor_2;
5858 }
5859
5860 static void Lfake_door_3(int x, int y)
5861 {
5862   if (lev.magnify_cnt)
5863     cave[x][y] = Xdoor_3;
5864 }
5865
5866 static void Lfake_door_4(int x, int y)
5867 {
5868   if (lev.magnify_cnt)
5869     cave[x][y] = Xdoor_4;
5870 }
5871
5872 static void Lfake_door_5(int x, int y)
5873 {
5874   if (lev.magnify_cnt)
5875     cave[x][y] = Xdoor_5;
5876 }
5877
5878 static void Lfake_door_6(int x, int y)
5879 {
5880   if (lev.magnify_cnt)
5881     cave[x][y] = Xdoor_6;
5882 }
5883
5884 static void Lfake_door_7(int x, int y)
5885 {
5886   if (lev.magnify_cnt)
5887     cave[x][y] = Xdoor_7;
5888 }
5889
5890 static void Lfake_door_8(int x, int y)
5891 {
5892   if (lev.magnify_cnt)
5893     cave[x][y] = Xdoor_8;
5894 }
5895
5896 static void Lballoon(int x, int y)
5897 {
5898   if (lev.wind_cnt == 0)
5899     return;
5900
5901   switch (lev.wind_direction)
5902   {
5903     case 0: /* north */
5904       switch (cave[x][y-1])
5905       {
5906         case Xblank:
5907         case Xsplash_e:
5908         case Xsplash_w:
5909         case Xfake_acid_1:
5910         case Xfake_acid_2:
5911         case Xfake_acid_3:
5912         case Xfake_acid_4:
5913         case Xfake_acid_5:
5914         case Xfake_acid_6:
5915         case Xfake_acid_7:
5916         case Xfake_acid_8:
5917           cave[x][y] = Yballoon_nB;
5918           next[x][y] = Xblank;
5919           cave[x][y-1] = Yballoon_n;
5920           next[x][y-1] = Xballoon;
5921           return;
5922
5923         case Xacid_1:
5924         case Xacid_2:
5925         case Xacid_3:
5926         case Xacid_4:
5927         case Xacid_5:
5928         case Xacid_6:
5929         case Xacid_7:
5930         case Xacid_8:
5931           cave[x][y] = Yballoon_nB;
5932           next[x][y] = Xblank;
5933           if (cave[x+1][y-2] == Xblank)
5934             cave[x+1][y-2] = Xsplash_e;
5935           if (cave[x-1][y-2] == Xblank)
5936             cave[x-1][y-2] = Xsplash_w;
5937           play_element_sound(x, y, SOUND_acid, Xacid_1);
5938           return;
5939       }
5940       break;
5941
5942     case 1: /* east */
5943       switch (cave[x+1][y])
5944       {
5945         case Xblank:
5946         case Xsplash_e:
5947         case Xsplash_w:
5948         case Xfake_acid_1:
5949         case Xfake_acid_2:
5950         case Xfake_acid_3:
5951         case Xfake_acid_4:
5952         case Xfake_acid_5:
5953         case Xfake_acid_6:
5954         case Xfake_acid_7:
5955         case Xfake_acid_8:
5956           cave[x][y] = Yballoon_eB;
5957           next[x][y] = Xblank;
5958           cave[x+1][y] = Yballoon_e;
5959           next[x+1][y] = Xballoon;
5960           return;
5961
5962         case Xacid_1:
5963         case Xacid_2:
5964         case Xacid_3:
5965         case Xacid_4:
5966         case Xacid_5:
5967         case Xacid_6:
5968         case Xacid_7:
5969         case Xacid_8:
5970           cave[x][y] = Yballoon_eB;
5971           next[x][y] = Xblank;
5972           if (cave[x+2][y-1] == Xblank)
5973             cave[x+2][y-1] = Xsplash_e;
5974           if (cave[x][y-1] == Xblank)
5975             cave[x][y-1] = Xsplash_w;
5976           play_element_sound(x, y, SOUND_acid, Xacid_1);
5977           return;
5978       }
5979       break;
5980
5981     case 2: /* south */
5982       switch (cave[x][y+1])
5983       {
5984         case Xblank:
5985         case Xsplash_e:
5986         case Xsplash_w:
5987         case Xfake_acid_1:
5988         case Xfake_acid_2:
5989         case Xfake_acid_3:
5990         case Xfake_acid_4:
5991         case Xfake_acid_5:
5992         case Xfake_acid_6:
5993         case Xfake_acid_7:
5994         case Xfake_acid_8:
5995           cave[x][y] = Yballoon_sB;
5996           next[x][y] = Xblank;
5997           cave[x][y+1] = Yballoon_s;
5998           next[x][y+1] = Xballoon;
5999           return;
6000
6001         case Xacid_1:
6002         case Xacid_2:
6003         case Xacid_3:
6004         case Xacid_4:
6005         case Xacid_5:
6006         case Xacid_6:
6007         case Xacid_7:
6008         case Xacid_8:
6009           cave[x][y] = Yballoon_sB;
6010           next[x][y] = Xblank;
6011           if (cave[x+1][y] == Xblank)
6012             cave[x+1][y] = Xsplash_e;
6013           if (cave[x-1][y] == Xblank)
6014             cave[x-1][y] = Xsplash_w;
6015           play_element_sound(x, y, SOUND_acid, Xacid_1);
6016           return;
6017       }
6018       break;
6019
6020     case 3: /* west */
6021       switch (cave[x-1][y])
6022       {
6023         case Xblank:
6024         case Xsplash_e:
6025         case Xsplash_w:
6026         case Xfake_acid_1:
6027         case Xfake_acid_2:
6028         case Xfake_acid_3:
6029         case Xfake_acid_4:
6030         case Xfake_acid_5:
6031         case Xfake_acid_6:
6032         case Xfake_acid_7:
6033         case Xfake_acid_8:
6034           cave[x][y] = Yballoon_wB;
6035           next[x][y] = Xblank;
6036           cave[x-1][y] = Yballoon_w;
6037           next[x-1][y] = Xballoon;
6038           return;
6039
6040         case Xacid_1:
6041         case Xacid_2:
6042         case Xacid_3:
6043         case Xacid_4:
6044         case Xacid_5:
6045         case Xacid_6:
6046         case Xacid_7:
6047         case Xacid_8:
6048           cave[x][y] = Yballoon_wB;
6049           next[x][y] = Xblank;
6050           if (cave[x][y-1] == Xblank)
6051             cave[x][y-1] = Xsplash_e;
6052           if (cave[x-2][y-1] == Xblank)
6053             cave[x-2][y-1] = Xsplash_w;
6054           play_element_sound(x, y, SOUND_acid, Xacid_1);
6055           return;
6056       }
6057       break;
6058   }
6059 }
6060
6061 static void Lball_common(int x, int y)
6062 {
6063   play_element_sound(x, y, SOUND_ball, Xball_1);
6064
6065   if (lev.ball_random)
6066   {
6067     switch (RANDOM(8))
6068     {
6069       case 0:
6070         if (lev.ball_array[lev.ball_pos][0] != Xblank &&
6071             is_blank[cave[x-1][y-1]])
6072         {
6073           cave[x-1][y-1] = Yball_blank;
6074           next[x-1][y-1] = lev.ball_array[lev.ball_pos][0];
6075         }
6076         break;
6077
6078       case 1:
6079         if (lev.ball_array[lev.ball_pos][1] != Xblank &&
6080             is_blank[cave[x][y-1]])
6081         {
6082           cave[x][y-1] = Yball_blank;
6083           next[x][y-1] = lev.ball_array[lev.ball_pos][1];
6084         }
6085         break;
6086
6087       case 2:
6088         if (lev.ball_array[lev.ball_pos][2] != Xblank &&
6089             is_blank[cave[x+1][y-1]])
6090         {
6091           cave[x+1][y-1] = Yball_blank;
6092           next[x+1][y-1] = lev.ball_array[lev.ball_pos][2];
6093         }
6094         break;
6095
6096       case 3:
6097         if (lev.ball_array[lev.ball_pos][3] != Xblank &&
6098             is_blank[cave[x-1][y]])
6099         {
6100           cave[x-1][y] = Yball_blank;
6101           next[x-1][y] = lev.ball_array[lev.ball_pos][3];
6102         }
6103         break;
6104
6105       case 4:
6106         if (lev.ball_array[lev.ball_pos][4] != Xblank &&
6107             is_blank[cave[x+1][y]])
6108         {
6109           cave[x+1][y] = Yball_blank;
6110           next[x+1][y] = lev.ball_array[lev.ball_pos][4];
6111         }
6112         break;
6113
6114       case 5:
6115         if (lev.ball_array[lev.ball_pos][5] != Xblank &&
6116             is_blank[cave[x-1][y+1]])
6117         {
6118           cave[x-1][y+1] = Yball_blank;
6119           next[x-1][y+1] = lev.ball_array[lev.ball_pos][5];
6120         }
6121         break;
6122
6123       case 6:
6124         if (lev.ball_array[lev.ball_pos][6] != Xblank &&
6125             is_blank[cave[x][y+1]])
6126         {
6127           cave[x][y+1] = Yball_blank;
6128           next[x][y+1] = lev.ball_array[lev.ball_pos][6];
6129         }
6130         break;
6131
6132       case 7:
6133         if (lev.ball_array[lev.ball_pos][7] != Xblank &&
6134             is_blank[cave[x+1][y+1]])
6135         {
6136           cave[x+1][y+1] = Yball_blank;
6137           next[x+1][y+1] = lev.ball_array[lev.ball_pos][7];
6138         }
6139         break;
6140     }
6141   }
6142   else
6143   {
6144     if (lev.ball_array[lev.ball_pos][0] != Xblank &&
6145         is_blank[cave[x-1][y-1]])
6146     {
6147       cave[x-1][y-1] = Yball_blank;
6148       next[x-1][y-1] = lev.ball_array[lev.ball_pos][0];
6149     }
6150
6151     if (lev.ball_array[lev.ball_pos][1] != Xblank &&
6152         is_blank[cave[x][y-1]])
6153     {
6154       cave[x][y-1] = Yball_blank;
6155       next[x][y-1] = lev.ball_array[lev.ball_pos][1];
6156     }
6157
6158     if (lev.ball_array[lev.ball_pos][2] != Xblank &&
6159         is_blank[cave[x+1][y-1]])
6160     {
6161       cave[x+1][y-1] = Yball_blank;
6162       next[x+1][y-1] = lev.ball_array[lev.ball_pos][2];
6163     }
6164
6165     if (lev.ball_array[lev.ball_pos][3] != Xblank &&
6166         is_blank[cave[x-1][y]])
6167     {
6168       cave[x-1][y] = Yball_blank;
6169       next[x-1][y] = lev.ball_array[lev.ball_pos][3];
6170     }
6171
6172     if (lev.ball_array[lev.ball_pos][4] != Xblank &&
6173         is_blank[cave[x+1][y]])
6174     {
6175       cave[x+1][y] = Yball_blank;
6176       next[x+1][y] = lev.ball_array[lev.ball_pos][4];
6177     }
6178
6179     if (lev.ball_array[lev.ball_pos][5] != Xblank &&
6180         is_blank[cave[x-1][y+1]])
6181     {
6182       cave[x-1][y+1] = Yball_blank;
6183       next[x-1][y+1] = lev.ball_array[lev.ball_pos][5];
6184     }
6185
6186     if (lev.ball_array[lev.ball_pos][6] != Xblank &&
6187         is_blank[cave[x][y+1]])
6188     {
6189       cave[x][y+1] = Yball_blank;
6190       next[x][y+1] = lev.ball_array[lev.ball_pos][6];
6191     }
6192
6193     if (lev.ball_array[lev.ball_pos][7] != Xblank &&
6194         is_blank[cave[x+1][y+1]])
6195     {
6196       cave[x+1][y+1] = Yball_blank;
6197       next[x+1][y+1] = lev.ball_array[lev.ball_pos][7];
6198     }
6199   }
6200
6201   lev.ball_pos = (lev.ball_pos + 1) % lev.num_ball_arrays;
6202 }
6203
6204 static void Lball_1(int x, int y)
6205 {
6206   if (lev.ball_state == 0)
6207     return;
6208
6209   cave[x][y] = Yball_1;
6210   next[x][y] = Xball_2;
6211   if (lev.ball_cnt)
6212     return;
6213
6214   Lball_common(x, y);
6215 }
6216
6217 static void Lball_2(int x, int y)
6218 {
6219   if (lev.ball_state == 0)
6220     return;
6221
6222   cave[x][y] = Yball_2;
6223   next[x][y] = Xball_1;
6224   if (lev.ball_cnt)
6225     return;
6226
6227   Lball_common(x, y);
6228 }
6229
6230 static void Ldrip(int x, int y)
6231 {
6232   next[x][y] = Xdrip_fall;
6233 }
6234
6235 static void Ldrip_fall(int x, int y)
6236 {
6237   int temp;
6238
6239   switch (cave[x][y+1])
6240   {
6241     case Zplayer:
6242     case Xblank:
6243     case Xsplash_e:
6244     case Xsplash_w:
6245     case Xfake_acid_1:
6246     case Xfake_acid_2:
6247     case Xfake_acid_3:
6248     case Xfake_acid_4:
6249     case Xfake_acid_5:
6250     case Xfake_acid_6:
6251     case Xfake_acid_7:
6252     case Xfake_acid_8:
6253     case Xplant:
6254     case Yplant:
6255       cave[x][y] = Ydrip_1_sB;
6256       next[x][y] = Xdrip_stretchB;
6257       cave[x][y+1] = Ydrip_1_s;
6258       next[x][y+1] = Xdrip_stretch;
6259       return;
6260
6261     case Xacid_1:
6262     case Xacid_2:
6263     case Xacid_3:
6264     case Xacid_4:
6265     case Xacid_5:
6266     case Xacid_6:
6267     case Xacid_7:
6268     case Xacid_8:
6269       cave[x][y] = Ydrip_1_sB;
6270       next[x][y] = Xdrip_stretchB;
6271       if (cave[x+1][y] == Xblank)
6272         cave[x+1][y] = Xsplash_e;
6273       if (cave[x-1][y] == Xblank)
6274         cave[x-1][y] = Xsplash_w;
6275       play_element_sound(x, y, SOUND_acid, Xacid_1);
6276       return;
6277
6278     default:
6279       switch (RANDOM(8))
6280       {
6281         case 0: temp = Xamoeba_1; break;
6282         case 1: temp = Xamoeba_2; break;
6283         case 2: temp = Xamoeba_3; break;
6284         case 3: temp = Xamoeba_4; break;
6285         case 4: temp = Xamoeba_5; break;
6286         case 5: temp = Xamoeba_6; break;
6287         case 6: temp = Xamoeba_7; break;
6288         case 7: temp = Xamoeba_8; break;
6289       }
6290
6291       cave[x][y] = temp;
6292       next[x][y] = temp;
6293       play_element_sound(x, y, SOUND_drip, Xdrip_fall);
6294       return;
6295   }
6296 }
6297
6298 static void Ldrip_stretch(int x, int y)
6299 {
6300   cave[x][y] = Ydrip_2_s;
6301   next[x][y] = Xdrip_fall;
6302 }
6303
6304 static void Ldrip_stretchB(int x, int y)
6305 {
6306   cave[x][y] = Ydrip_2_sB;
6307   next[x][y] = Xblank;
6308 }
6309
6310 static void Lwonderwall(int x, int y)
6311 {
6312   if (lev.wonderwall_time && lev.wonderwall_state)
6313   {
6314     cave[x][y] = Ywonderwall;
6315     play_element_sound(x, y, SOUND_wonder, Xwonderwall);
6316   }
6317 }
6318
6319 static void Lwheel(int x, int y)
6320 {
6321   if (lev.wheel_cnt && x == lev.wheel_x && y == lev.wheel_y)
6322     cave[x][y] = Ywheel;
6323 }
6324
6325 static void Lswitch(int x, int y)
6326 {
6327   if (lev.ball_state)
6328     cave[x][y] = Yswitch;
6329 }
6330
6331 static void Lfake_blank(int x, int y)
6332 {
6333   if (lev.lenses_cnt)
6334     cave[x][y] = Yfake_blank;
6335 }
6336
6337 static void Lfake_grass(int x, int y)
6338 {
6339   if (lev.magnify_cnt)
6340     cave[x][y] = Yfake_grass;
6341 }
6342
6343 static void Lfake_amoeba(int x, int y)
6344 {
6345   if (lev.lenses_cnt)
6346     cave[x][y] = Yfake_amoeba;
6347 }
6348
6349 static void Lsand_stone(int x, int y)
6350 {
6351   switch (cave[x][y+1])
6352   {
6353     case Xblank:
6354     case Xsplash_e:
6355     case Xsplash_w:
6356     case Xfake_acid_1:
6357     case Xfake_acid_2:
6358     case Xfake_acid_3:
6359     case Xfake_acid_4:
6360     case Xfake_acid_5:
6361     case Xfake_acid_6:
6362     case Xfake_acid_7:
6363     case Xfake_acid_8:
6364       cave[x][y] = Xsand_stonesand_quickout_1;
6365       next[x][y] = Xsand_stonesand_quickout_2;
6366       cave[x][y+1] = Xsand_stoneout_1;
6367       next[x][y+1] = Xsand_stoneout_2;
6368       return;
6369
6370     case Xacid_1:
6371     case Xacid_2:
6372     case Xacid_3:
6373     case Xacid_4:
6374     case Xacid_5:
6375     case Xacid_6:
6376     case Xacid_7:
6377     case Xacid_8:
6378       cave[x][y] = Xsand_stonesand_quickout_1;
6379       next[x][y] = Xsand_stonesand_quickout_2;
6380       if (cave[x+1][y] == Xblank)
6381         cave[x+1][y] = Xsplash_e;
6382       if (cave[x-1][y] == Xblank)
6383         cave[x-1][y] = Xsplash_w;
6384       play_element_sound(x, y, SOUND_acid, Xacid_1);
6385       return;
6386
6387     case Xsand:
6388       cave[x][y] = Xsand_stonesand_1;
6389       next[x][y] = Xsand_stonesand_2;
6390       cave[x][y+1] = Xsand_sandstone_1;
6391       next[x][y+1] = Xsand_sandstone_2;
6392       return;
6393   }
6394 }
6395
6396 static void Lsand_stonein_1(int x, int y)
6397 {
6398   next[x][y] = Xsand_stonein_2;
6399 }
6400
6401 static void Lsand_stonein_2(int x, int y)
6402 {
6403   next[x][y] = Xsand_stonein_3;
6404 }
6405
6406 static void Lsand_stonein_3(int x, int y)
6407 {
6408   next[x][y] = Xsand_stonein_4;
6409 }
6410
6411 static void Lsand_stonein_4(int x, int y)
6412 {
6413   next[x][y] = Xblank;
6414 }
6415
6416 static void Lsand_sandstone_1(int x, int y)
6417 {
6418   next[x][y] = Xsand_sandstone_2;
6419 }
6420
6421 static void Lsand_sandstone_2(int x, int y)
6422 {
6423   next[x][y] = Xsand_sandstone_3;
6424 }
6425
6426 static void Lsand_sandstone_3(int x, int y)
6427 {
6428   next[x][y] = Xsand_sandstone_4;
6429 }
6430
6431 static void Lsand_sandstone_4(int x, int y)
6432 {
6433   next[x][y] = Xsand_stone;
6434 }
6435
6436 static void Lsand_stonesand_1(int x, int y)
6437 {
6438   next[x][y] = Xsand_stonesand_2;
6439 }
6440
6441 static void Lsand_stonesand_2(int x, int y)
6442 {
6443   next[x][y] = Xsand_stonesand_3;
6444 }
6445
6446 static void Lsand_stonesand_3(int x, int y)
6447 {
6448   next[x][y] = Xsand_stonesand_4;
6449 }
6450
6451 static void Lsand_stonesand_4(int x, int y)
6452 {
6453   next[x][y] = Xsand;
6454 }
6455
6456 static void Lsand_stoneout_1(int x, int y)
6457 {
6458   next[x][y] = Xsand_stoneout_2;
6459 }
6460
6461 static void Lsand_stoneout_2(int x, int y)
6462 {
6463   next[x][y] = Xstone_fall;
6464 }
6465
6466 static void Lsand_stonesand_quickout_1(int x, int y)
6467 {
6468   next[x][y] = Xsand_stonesand_quickout_2;
6469 }
6470
6471 static void Lsand_stonesand_quickout_2(int x, int y)
6472 {
6473   next[x][y] = Xsand;
6474 }
6475
6476 static void Lslide_ns(int x, int y)
6477 {
6478   if (is_blank[cave[x][y-1]])
6479   {
6480     cave[x][y-1] = Yslide_ns_blank;
6481     next[x][y-1] = Xslide_ns;
6482     play_element_sound(x, y, SOUND_slide, Xslide_ns);
6483   }
6484
6485   if (is_blank[cave[x][y+1]])
6486   {
6487     cave[x][y+1] = Yslide_ns_blank;
6488     next[x][y+1] = Xslide_ns;
6489     play_element_sound(x, y, SOUND_slide, Xslide_ns);
6490   }
6491 }
6492
6493 static void Lslide_ew(int x, int y)
6494 {
6495   if (is_blank[cave[x+1][y]])
6496   {
6497     cave[x+1][y] = Yslide_ew_blank;
6498     next[x+1][y] = Xslide_ew;
6499     play_element_sound(x, y, SOUND_slide, Xslide_ew);
6500   }
6501
6502   if (is_blank[cave[x-1][y]])
6503   {
6504     cave[x-1][y] = Yslide_ew_blank;
6505     next[x-1][y] = Xslide_ew;
6506     play_element_sound(x, y, SOUND_slide, Xslide_ew);
6507   }
6508 }
6509
6510 static void Lexit(int x, int y)
6511 {
6512   if (lev.required > 0)
6513     return;
6514
6515   switch (RANDOM(64) / 21)
6516   {
6517     case 0:
6518       cave[x][y] = Xexit_1;
6519       next[x][y] = Xexit_2;
6520       break;
6521
6522     case 1:
6523       cave[x][y] = Xexit_2;
6524       next[x][y] = Xexit_3;
6525       break;
6526
6527     default:
6528       cave[x][y] = Xexit_3;
6529       next[x][y] = Xexit_1;
6530       break;
6531   }
6532
6533   play_element_sound(x, y, SOUND_exit_open, Xexit);
6534 }
6535
6536 static void Lexit_1(int x, int y)
6537 {
6538   next[x][y] = Xexit_2;
6539 }
6540
6541 static void Lexit_2(int x, int y)
6542 {
6543   next[x][y] = Xexit_3;
6544 }
6545
6546 static void Lexit_3(int x, int y)
6547 {
6548   next[x][y] = Xexit_1;
6549 }
6550
6551 static void Lpause(int x, int y)
6552 {
6553   next[x][y] = Xblank;
6554 }
6555
6556 static void Lamoeba(int x, int y)
6557 {
6558   switch (cave[x][y])
6559   {
6560     case Xblank:
6561     case Xsplash_e:
6562     case Xsplash_w:
6563     case Xfake_acid_1:
6564     case Xfake_acid_2:
6565     case Xfake_acid_3:
6566     case Xfake_acid_4:
6567     case Xfake_acid_5:
6568     case Xfake_acid_6:
6569     case Xfake_acid_7:
6570     case Xfake_acid_8:
6571     case Xplant:
6572     case Yplant:
6573     case Xgrass:
6574     case Xdirt:
6575     case Xsand:
6576       if (is_amoeba[cave[x][y-1]] ||
6577           is_amoeba[cave[x+1][y]] ||
6578           is_amoeba[cave[x][y+1]] ||
6579           is_amoeba[cave[x-1][y]])
6580         cave[x][y] = Xdrip;
6581   }
6582 }
6583
6584 static void Lboom_one(int x, int y, boolean by_dynamite)
6585 {
6586   switch (cave[x][y])
6587   {
6588     case Zborder:
6589     case Znormal:
6590     case Zdynamite:
6591     case Xboom_bug:
6592     case Xboom_bomb:
6593     case Xboom_android:
6594     case Xacid_1:
6595     case Xacid_2:
6596     case Xacid_3:
6597     case Xacid_4:
6598     case Xacid_5:
6599     case Xacid_6:
6600     case Xacid_7:
6601     case Xacid_8:
6602     case Xplant:
6603     case Yplant:
6604     case Xdoor_1:
6605     case Xdoor_2:
6606     case Xdoor_3:
6607     case Xdoor_4:
6608     case Xdoor_5:
6609     case Xdoor_6:
6610     case Xdoor_7:
6611     case Xdoor_8:
6612     case Xfake_door_1:
6613     case Xfake_door_2:
6614     case Xfake_door_3:
6615     case Xfake_door_4:
6616     case Xfake_door_5:
6617     case Xfake_door_6:
6618     case Xfake_door_7:
6619     case Xfake_door_8:
6620     case Xacid_ne:
6621     case Xacid_nw:
6622     case Xacid_s:
6623     case Xacid_se:
6624     case Xacid_sw:
6625     case Xsteel_1:
6626     case Xsteel_2:
6627     case Xsteel_3:
6628     case Xsteel_4:
6629       return;
6630
6631     case Xandroid:
6632     case Xandroid_1_n:
6633     case Xandroid_2_n:
6634     case Xandroid_1_e:
6635     case Xandroid_2_e:
6636     case Xandroid_1_s:
6637     case Xandroid_2_s:
6638     case Xandroid_1_w:
6639     case Xandroid_2_w:
6640       if (by_dynamite)
6641         cave[x][y] = Xboom_android;
6642       return;
6643
6644     case Xbug_1_n:
6645     case Xbug_1_e:
6646     case Xbug_1_s:
6647     case Xbug_1_w:
6648     case Xbug_2_n:
6649     case Xbug_2_e:
6650     case Xbug_2_s:
6651     case Xbug_2_w:
6652       cave[x][y] = Xboom_bug;
6653       return;
6654
6655     case Xbomb:
6656     case Xbomb_pause:
6657     case Xbomb_fall:
6658       cave[x][y] = Xboom_bomb;
6659       return;
6660
6661     default:
6662       cave[x][y] = Xboom_1;
6663       return;
6664   }
6665 }
6666
6667 static void Lboom_nine(int x, int y, boolean by_dynamite)
6668 {
6669   Lboom_one(x,   y-1, by_dynamite);
6670   Lboom_one(x-1, y,   by_dynamite);
6671   Lboom_one(x+1, y,   by_dynamite);
6672   Lboom_one(x,   y+1, by_dynamite);
6673   Lboom_one(x-1, y-1, by_dynamite);
6674   Lboom_one(x+1, y-1, by_dynamite);
6675   Lboom_one(x-1, y+1, by_dynamite);
6676   Lboom_one(x+1, y+1, by_dynamite);
6677
6678   cave[x][y] = Xboom_1;
6679 }
6680
6681 static void Lexplode(int x, int y)
6682 {
6683   switch (cave[x][y])
6684   {
6685     case Znormal:
6686       Lboom_nine(x, y, FALSE);
6687       break;
6688
6689     case Zdynamite:
6690       Lboom_nine(x, y, TRUE);
6691       break;
6692   }
6693 }
6694
6695 static void Lboom_1(int x, int y)
6696 {
6697   next[x][y] = Xboom_2;
6698 #if !PLAY_ELEMENT_SOUND
6699   if (x != lev.exit_x && y != lev.exit_y)
6700     play_sound(x, y, SOUND_boom);
6701   else
6702     lev.exit_x = lev.exit_y = -1;
6703 #endif
6704 }
6705
6706 static void Lboom_2(int x, int y)
6707 {
6708   next[x][y] = boom[x][y];
6709 }
6710
6711 static void Lboom_android(int x, int y)
6712 {
6713 #if PLAY_ELEMENT_SOUND
6714   play_element_sound(x, y, SOUND_boom, Xandroid);
6715 #endif
6716
6717   Lboom_1(x, y);
6718 }
6719
6720 static void handle_tile(int x, int y)
6721 {
6722   switch (cave[x][y])
6723   {
6724     case Xacid_1:               Lacid_1(x, y);                  break;
6725     case Xacid_2:               Lacid_2(x, y);                  break;
6726     case Xacid_3:               Lacid_3(x, y);                  break;
6727     case Xacid_4:               Lacid_4(x, y);                  break;
6728     case Xacid_5:               Lacid_5(x, y);                  break;
6729     case Xacid_6:               Lacid_6(x, y);                  break;
6730     case Xacid_7:               Lacid_7(x, y);                  break;
6731     case Xacid_8:               Lacid_8(x, y);                  break;
6732
6733     case Xfake_acid_1:          Lfake_acid_1(x, y);             break;
6734     case Xfake_acid_2:          Lfake_acid_2(x, y);             break;
6735     case Xfake_acid_3:          Lfake_acid_3(x, y);             break;
6736     case Xfake_acid_4:          Lfake_acid_4(x, y);             break;
6737     case Xfake_acid_5:          Lfake_acid_5(x, y);             break;
6738     case Xfake_acid_6:          Lfake_acid_6(x, y);             break;
6739     case Xfake_acid_7:          Lfake_acid_7(x, y);             break;
6740     case Xfake_acid_8:          Lfake_acid_8(x, y);             break;
6741
6742     case Xandroid:              Landroid(x, y);                 break;
6743     case Xandroid_1_n:          Landroid_1_n(x, y);             break;
6744     case Xandroid_2_n:          Landroid_2_n(x, y);             break;
6745     case Xandroid_1_e:          Landroid_1_e(x, y);             break;
6746     case Xandroid_2_e:          Landroid_2_e(x, y);             break;
6747     case Xandroid_1_s:          Landroid_1_s(x, y);             break;
6748     case Xandroid_2_s:          Landroid_2_s(x, y);             break;
6749     case Xandroid_1_w:          Landroid_1_w(x, y);             break;
6750     case Xandroid_2_w:          Landroid_2_w(x, y);             break;
6751
6752     case Xeater_n:              Leater_n(x, y);                 break;
6753     case Xeater_e:              Leater_e(x, y);                 break;
6754     case Xeater_s:              Leater_s(x, y);                 break;
6755     case Xeater_w:              Leater_w(x, y);                 break;
6756
6757     case Xalien:                Lalien(x, y);                   break;
6758     case Xalien_pause:          Lalien_pause(x, y);             break;
6759
6760     case Xbug_1_n:              Lbug_1_n(x, y);                 break;
6761     case Xbug_2_n:              Lbug_2_n(x, y);                 break;
6762     case Xbug_1_e:              Lbug_1_e(x, y);                 break;
6763     case Xbug_2_e:              Lbug_2_e(x, y);                 break;
6764     case Xbug_1_s:              Lbug_1_s(x, y);                 break;
6765     case Xbug_2_s:              Lbug_2_s(x, y);                 break;
6766     case Xbug_1_w:              Lbug_1_w(x, y);                 break;
6767     case Xbug_2_w:              Lbug_2_w(x, y);                 break;
6768
6769     case Xtank_1_n:             Ltank_1_n(x, y);                break;
6770     case Xtank_2_n:             Ltank_2_n(x, y);                break;
6771     case Xtank_1_e:             Ltank_1_e(x, y);                break;
6772     case Xtank_2_e:             Ltank_2_e(x, y);                break;
6773     case Xtank_1_s:             Ltank_1_s(x, y);                break;
6774     case Xtank_2_s:             Ltank_2_s(x, y);                break;
6775     case Xtank_1_w:             Ltank_1_w(x, y);                break;
6776     case Xtank_2_w:             Ltank_2_w(x, y);                break;
6777
6778     case Xemerald:              Lemerald(x, y);                 break;
6779     case Xemerald_pause:        Lemerald_pause(x, y);           break;
6780     case Xemerald_fall:         Lemerald_fall(x, y);            break;
6781
6782     case Xdiamond:              Ldiamond(x, y);                 break;
6783     case Xdiamond_pause:        Ldiamond_pause(x, y);           break;
6784     case Xdiamond_fall:         Ldiamond_fall(x, y);            break;
6785
6786     case Xstone:                Lstone(x, y);                   break;
6787     case Xstone_pause:          Lstone_pause(x, y);             break;
6788     case Xstone_fall:           Lstone_fall(x, y);              break;
6789
6790     case Xbomb:                 Lbomb(x, y);                    break;
6791     case Xbomb_pause:           Lbomb_pause(x, y);              break;
6792     case Xbomb_fall:            Lbomb_fall(x, y);               break;
6793
6794     case Xnut:                  Lnut(x, y);                     break;
6795     case Xnut_pause:            Lnut_pause(x, y);               break;
6796     case Xnut_fall:             Lnut_fall(x, y);                break;
6797
6798     case Xspring:               Lspring(x, y);                  break;
6799     case Xspring_pause:         Lspring_pause(x, y);            break;
6800     case Xspring_e:             Lspring_e(x, y);                break;
6801     case Xspring_w:             Lspring_w(x, y);                break;
6802     case Xspring_fall:          Lspring_fall(x, y);             break;
6803
6804     case Xpush_emerald_e:       Lpush_emerald_e(x, y);          break;
6805     case Xpush_emerald_w:       Lpush_emerald_w(x, y);          break;
6806     case Xpush_diamond_e:       Lpush_diamond_e(x, y);          break;
6807     case Xpush_diamond_w:       Lpush_diamond_w(x, y);          break;
6808     case Xpush_stone_e:         Lpush_stone_e(x, y);            break;
6809     case Xpush_stone_w:         Lpush_stone_w(x, y);            break;
6810     case Xpush_bomb_e:          Lpush_bomb_e(x, y);             break;
6811     case Xpush_bomb_w:          Lpush_bomb_w(x, y);             break;
6812     case Xpush_nut_e:           Lpush_nut_e(x, y);              break;
6813     case Xpush_nut_w:           Lpush_nut_w(x, y);              break;
6814     case Xpush_spring_e:        Lpush_spring_e(x, y);           break;
6815     case Xpush_spring_w:        Lpush_spring_w(x, y);           break;
6816
6817     case Xdynamite_1:           Ldynamite_1(x, y);              break;
6818     case Xdynamite_2:           Ldynamite_2(x, y);              break;
6819     case Xdynamite_3:           Ldynamite_3(x, y);              break;
6820     case Xdynamite_4:           Ldynamite_4(x, y);              break;
6821
6822     case Xfake_door_1:          Lfake_door_1(x, y);             break;
6823     case Xfake_door_2:          Lfake_door_2(x, y);             break;
6824     case Xfake_door_3:          Lfake_door_3(x, y);             break;
6825     case Xfake_door_4:          Lfake_door_4(x, y);             break;
6826     case Xfake_door_5:          Lfake_door_5(x, y);             break;
6827     case Xfake_door_6:          Lfake_door_6(x, y);             break;
6828     case Xfake_door_7:          Lfake_door_7(x, y);             break;
6829     case Xfake_door_8:          Lfake_door_8(x, y);             break;
6830
6831     case Xballoon:              Lballoon(x, y);                 break;
6832
6833     case Xball_1:               Lball_1(x, y);                  break;
6834     case Xball_2:               Lball_2(x, y);                  break;
6835
6836     case Xdrip:                 Ldrip(x, y);                    break;
6837     case Xdrip_fall:            Ldrip_fall(x, y);               break;
6838     case Xdrip_stretch:         Ldrip_stretch(x, y);            break;
6839     case Xdrip_stretchB:        Ldrip_stretchB(x, y);           break;
6840
6841     case Xwonderwall:           Lwonderwall(x, y);              break;
6842
6843     case Xwheel:                Lwheel(x, y);                   break;
6844
6845     case Xswitch:               Lswitch(x, y);                  break;
6846
6847     case Xfake_blank:           Lfake_blank(x, y);              break;
6848     case Xfake_grass:           Lfake_grass(x, y);              break;
6849     case Xfake_amoeba:          Lfake_amoeba(x, y);             break;
6850
6851     case Xsand_stone:           Lsand_stone(x, y);              break;
6852     case Xsand_stonein_1:       Lsand_stonein_1(x, y);          break;
6853     case Xsand_stonein_2:       Lsand_stonein_2(x, y);          break;
6854     case Xsand_stonein_3:       Lsand_stonein_3(x, y);          break;
6855     case Xsand_stonein_4:       Lsand_stonein_4(x, y);          break;
6856     case Xsand_sandstone_1:     Lsand_sandstone_1(x, y);        break;
6857     case Xsand_sandstone_2:     Lsand_sandstone_2(x, y);        break;
6858     case Xsand_sandstone_3:     Lsand_sandstone_3(x, y);        break;
6859     case Xsand_sandstone_4:     Lsand_sandstone_4(x, y);        break;
6860     case Xsand_stonesand_1:     Lsand_stonesand_1(x, y);        break;
6861     case Xsand_stonesand_2:     Lsand_stonesand_2(x, y);        break;
6862     case Xsand_stonesand_3:     Lsand_stonesand_3(x, y);        break;
6863     case Xsand_stonesand_4:     Lsand_stonesand_4(x, y);        break;
6864     case Xsand_stoneout_1:      Lsand_stoneout_1(x, y);         break;
6865     case Xsand_stoneout_2:      Lsand_stoneout_2(x, y);         break;
6866     case Xsand_stonesand_quickout_1: Lsand_stonesand_quickout_1(x, y); break;
6867     case Xsand_stonesand_quickout_2: Lsand_stonesand_quickout_2(x, y); break;
6868
6869     case Xslide_ns:             Lslide_ns(x, y);                break;
6870     case Xslide_ew:             Lslide_ew(x, y);                break;
6871
6872     case Xexit:                 Lexit(x, y);                    break;
6873     case Xexit_1:               Lexit_1(x, y);                  break;
6874     case Xexit_2:               Lexit_2(x, y);                  break;
6875     case Xexit_3:               Lexit_3(x, y);                  break;
6876
6877     case Xpause:                Lpause(x, y);                   break;
6878
6879     case Xboom_bug:             Lboom_bug(x, y, Xboom_bug);     break;
6880     case Xboom_bomb:            Lboom_tank(x, y, Xboom_bomb);   break;
6881     case Xboom_android:         Lboom_android(x, y);            break;
6882     case Xboom_1:               Lboom_1(x, y);                  break;
6883     case Xboom_2:               Lboom_2(x, y);                  break;
6884   }
6885 }
6886
6887 void logic_players(void)
6888 {
6889   int start_check_nr;
6890   int i;
6891
6892   cave = lev.cave;
6893   next = lev.next;
6894   boom = lev.boom;
6895
6896   game_em.any_player_moving = FALSE;
6897   game_em.any_player_snapping = FALSE;
6898
6899   /* must test for death and actually kill separately */
6900   for (i = 0; i < MAX_PLAYERS; i++)
6901   {
6902     boolean ply_kill = player_killed(&ply[i]);
6903
6904     if (ply[i].alive && ply_kill)
6905       kill_player(&ply[i]);
6906   }
6907
6908   for (i = 0; i < MAX_PLAYERS; i++)
6909   {
6910     /* check for wrap-around movement */
6911     if (ply[i].x < lev.left ||
6912         ply[i].x > lev.right - 1)
6913     {
6914       ply[i].x = (ply[i].x < lev.left ? lev.right - 1 : lev.left);
6915
6916       game.centered_player_nr_next = i;
6917       game.set_centered_player = TRUE;
6918       game.set_centered_player_fast = TRUE;
6919     }
6920
6921     ply[i].oldx = ply[i].x;
6922     ply[i].oldy = ply[i].y;
6923     ply[i].anim = PLY_still;
6924   }
6925
6926   start_check_nr = (RandomEM & 128 ? 0 : 1) * 2 + (RandomEM & 256 ? 0 : 1);
6927
6928   for (i = 0; i < MAX_PLAYERS; i++)
6929   {
6930     int check_nr = (start_check_nr + i) % MAX_PLAYERS;
6931
6932     if (ply[check_nr].alive)
6933       check_player(&ply[check_nr]);
6934   }
6935
6936   for (i = 0; i < MAX_PLAYERS; i++)
6937   {
6938     if (!ply[i].alive)
6939       continue;
6940
6941     if (cave[ply[i].oldx][ply[i].oldy] == Zplayer)
6942     {
6943       cave[ply[i].oldx][ply[i].oldy] = Xblank;
6944       next[ply[i].oldx][ply[i].oldy] = Xblank;
6945     }
6946
6947     if (cave[ply[i].x][ply[i].y] == Xblank)
6948     {
6949       cave[ply[i].x][ply[i].y] = Zplayer;
6950       next[ply[i].x][ply[i].y] = Zplayer;
6951     }
6952   }
6953 }
6954
6955 void logic_objects(void)
6956 {
6957   int x, y;
6958
6959   cave = lev.cave;
6960   next = lev.next;
6961   boom = lev.boom;
6962
6963   seed = RandomEM;
6964   score = 0;
6965
6966   for (y = lev.top; y < lev.bottom; y++)
6967     for (x = lev.left; x < lev.right; x++)
6968       handle_tile(x, y);
6969
6970   if (ply[0].alive || ply[1].alive || ply[2].alive || ply[3].alive)
6971     lev.score += score;         /* only add a score if someone is alive */
6972   else
6973     game_em.game_over = TRUE;
6974
6975   RandomEM = seed;
6976
6977   /* triple buffering */
6978   void *temp = lev.cave;
6979   lev.cave = lev.next;
6980   lev.next = lev.draw;
6981   lev.draw = temp;
6982 }
6983
6984 void logic_globals(void)
6985 {
6986   int x;
6987   int y;
6988   int count;
6989   unsigned int random;
6990
6991   cave = lev.cave;
6992   next = lev.next;
6993   boom = lev.boom;
6994
6995   /* update variables */
6996
6997   if (lev.score > 9999)
6998     lev.score = 9999;
6999
7000   if (lev.android_move_cnt-- == 0)
7001     lev.android_move_cnt = lev.android_move_time;
7002   if (lev.android_clone_cnt-- == 0)
7003     lev.android_clone_cnt = lev.android_clone_time;
7004   if (lev.ball_state)
7005     if (lev.ball_cnt-- == 0)
7006       lev.ball_cnt = lev.ball_time;
7007   if (lev.lenses_cnt)
7008     lev.lenses_cnt--;
7009   if (lev.magnify_cnt)
7010     lev.magnify_cnt--;
7011   if (lev.wheel_cnt)
7012     lev.wheel_cnt--;
7013   if (lev.wind_cnt)
7014     lev.wind_cnt--;
7015   if (lev.wonderwall_time && lev.wonderwall_state)
7016     lev.wonderwall_time--;
7017
7018   if (lev.wheel_cnt)
7019     play_element_sound(lev.wheel_x, lev.wheel_y, SOUND_wheel, Xwheel);
7020
7021   /* grow amoeba */
7022
7023   random = RandomEM;
7024
7025   for (count = lev.amoeba_time; count--;)
7026   {
7027     x = lev.left - 1 + (random >> 10) % (CAVE_WIDTH  + 2);
7028     y = lev.top  - 1 + (random >> 20) % (CAVE_HEIGHT + 2);
7029
7030     if (x >= lev.left && x < lev.right &&
7031         y >= lev.top  && y < lev.bottom)
7032       Lamoeba(x, y);
7033
7034     random = random * 129 + 1;
7035   }
7036
7037   RandomEM = random;
7038
7039   /* handle explosions */
7040
7041   for (y = lev.top; y < lev.bottom; y++)
7042     for (x = lev.left; x < lev.right; x++)
7043       Lexplode(x, y);
7044
7045   /* triple buffering */
7046
7047   for (y = lev.top; y < lev.bottom; y++)
7048     for (x = lev.left; x < lev.right; x++)
7049       next[x][y] = cave[x][y];
7050 }