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