removed options to prevent initial rolling objects in native EM levels
[rocksndiamonds.git] / src / game_em / synchro_2.c
1 /* second part of synchro.
2  *
3  * game logic for monsters.
4  *
5  * one giant switch statement to process everything.
6  *
7  * this whole thing is a major bottleneck. the compiler must use registers.
8  * compilers suck.
9  */
10
11 #include "main_em.h"
12
13
14 #define SPRING_ROLL     /* spring rolling off round things continues to roll */
15
16 #define RANDOM (random = random << 31 | random >> 1)
17
18 static void set_nearest_player_xy(int x, int y, int *dx, int *dy)
19 {
20   int distance, distance_shortest = EM_MAX_CAVE_WIDTH + EM_MAX_CAVE_HEIGHT;
21   int i;
22
23   /* default values if no players are alive anymore */
24   *dx = 0;
25   *dy = 0;
26
27   for (i = 0; i < MAX_PLAYERS; i++)
28   {
29     if (!ply[i].alive)
30       continue;
31
32     distance = ABS(ply[i].x - x) + ABS(ply[i].y - y);
33
34     if (distance < distance_shortest)
35     {
36       *dx = ply[i].x;
37       *dy = ply[i].y;
38
39       distance_shortest = distance;
40     }
41   }
42 }
43
44 void synchro_2(void)
45 {
46   int x = 0;
47   int y = 1;
48   unsigned int random = RandomEM;
49   short *cave_cache = Cave[y];  /* might be a win */
50   int score = 0;
51
52   int temp = 0;                 /* initialized to make compilers happy */
53   int dx;                       /* only needed to find closest player */
54   int dy;
55   int element;
56
57  loop:
58
59   element = cave_cache[++x];
60
61   switch (element)
62   {
63     default:
64       goto loop;
65
66     /* --------------------------------------------------------------------- */
67
68     case Xpush_stone_e:
69       switch (Cave[y][x+1])
70       {
71         case Zborder:
72         case Znormal:
73         case Zdynamite:
74         case Xboom_bug:
75         case Xboom_bomb:
76         case Xboom_android:
77         case Xboom_1:
78         case Zplayer:
79           Cave[y][x] = Xstone;
80           Next[y][x] = Xstone;
81           goto loop;
82
83         default:
84           Cave[y][x] = Ystone_eB;
85           Cave[y][x+1] = Ystone_e;
86           Next[y][x] = Xblank;
87           Next[y][x+1] = Xstone_pause;
88           goto loop;
89       }
90
91     case Xpush_stone_w:
92       switch (Cave[y][x-1])
93       {
94         case Zborder:
95         case Znormal:
96         case Zdynamite:
97         case Xboom_bug:
98         case Xboom_bomb:
99         case Xboom_android:
100         case Xboom_1:
101         case Zplayer:
102           Cave[y][x] = Xstone;
103           Next[y][x] = Xstone;
104           goto loop;
105
106         default:
107           Cave[y][x] = Ystone_wB;
108           Cave[y][x-1] = Ystone_w;
109           Next[y][x] = Xblank;
110           Next[y][x-1] = Xstone_pause;
111           goto loop;
112       }
113
114     case Xpush_nut_e:
115       switch (Cave[y][x+1])
116       {
117         case Zborder:
118         case Znormal:
119         case Zdynamite:
120         case Xboom_bug:
121         case Xboom_bomb:
122         case Xboom_android:
123         case Xboom_1:
124         case Zplayer:
125           Cave[y][x] = Xnut;
126           Next[y][x] = Xnut;
127           goto loop;
128
129         default:
130           Cave[y][x] = Ynut_eB;
131           Cave[y][x+1] = Ynut_e;
132           Next[y][x] = Xblank;
133           Next[y][x+1] = Xnut_pause;
134           goto loop;
135       }
136
137     case Xpush_nut_w:
138       switch (Cave[y][x-1])
139       {
140         case Zborder:
141         case Znormal:
142         case Zdynamite:
143         case Xboom_bug:
144         case Xboom_bomb:
145         case Xboom_android:
146         case Xboom_1:
147         case Zplayer:
148           Cave[y][x] = Xnut;
149           Next[y][x] = Xnut;
150           goto loop;
151
152         default:
153           Cave[y][x] = Ynut_wB;
154           Cave[y][x-1] = Ynut_w;
155           Next[y][x] = Xblank;
156           Next[y][x-1] = Xnut_pause;
157           goto loop;
158         }
159
160     case Xpush_spring_e:
161       switch (Cave[y][x+1])
162       {
163         case Zborder:
164         case Znormal:
165         case Zdynamite:
166         case Xboom_bug:
167         case Xboom_bomb:
168         case Xboom_android:
169         case Xboom_1:
170         case Zplayer:
171           Cave[y][x] = Xspring;
172           Next[y][x] = Xspring;
173           goto loop;
174
175         default:
176           Cave[y][x] = Yspring_eB;
177           Cave[y][x+1] = Yspring_e;
178           Next[y][x] = Xblank;
179           Next[y][x+1] = Xspring_e;
180
181           goto loop;
182       }
183
184     case Xpush_spring_w:
185       switch (Cave[y][x-1])
186       {
187         case Zborder:
188         case Znormal:
189         case Zdynamite:
190         case Xboom_bug:
191         case Xboom_bomb:
192         case Xboom_android:
193         case Xboom_1:
194         case Zplayer:
195           Cave[y][x] = Xspring;
196           Next[y][x] = Xspring;
197           goto loop;
198
199         default:
200           Cave[y][x] = Yspring_wB;
201           Cave[y][x-1] = Yspring_w;
202           Next[y][x] = Xblank;
203           Next[y][x-1] = Xspring_w;
204           goto loop;
205         }
206
207     case Xpush_emerald_e:
208       switch (Cave[y][x+1])
209       {
210         case Zborder:
211         case Znormal:
212         case Zdynamite:
213         case Xboom_bug:
214         case Xboom_bomb:
215         case Xboom_android:
216         case Xboom_1:
217         case Zplayer:
218           Cave[y][x] = Xemerald;
219           Next[y][x] = Xemerald;
220           goto loop;
221
222         default:
223           Cave[y][x] = Yemerald_eB;
224           Cave[y][x+1] = Yemerald_e;
225           Next[y][x] = Xblank;
226           Next[y][x+1] = Xemerald_pause;
227           goto loop;
228         }
229
230     case Xpush_emerald_w:
231       switch (Cave[y][x-1])
232       {
233         case Zborder:
234         case Znormal:
235         case Zdynamite:
236         case Xboom_bug:
237         case Xboom_bomb:
238         case Xboom_android:
239         case Xboom_1:
240         case Zplayer:
241           Cave[y][x] = Xemerald;
242           Next[y][x] = Xemerald;
243           goto loop;
244
245         default:
246           Cave[y][x] = Yemerald_wB;
247           Cave[y][x-1] = Yemerald_w;
248           Next[y][x] = Xblank;
249           Next[y][x-1] = Xemerald_pause;
250           goto loop;
251         }
252
253     case Xpush_diamond_e:
254       switch (Cave[y][x+1])
255       {
256         case Zborder:
257         case Znormal:
258         case Zdynamite:
259         case Xboom_bug:
260         case Xboom_bomb:
261         case Xboom_android:
262         case Xboom_1:
263         case Zplayer:
264           Cave[y][x] = Xdiamond;
265           Next[y][x] = Xdiamond;
266           goto loop;
267
268         default:
269           Cave[y][x] = Ydiamond_eB;
270           Cave[y][x+1] = Ydiamond_e;
271           Next[y][x] = Xblank;
272           Next[y][x+1] = Xdiamond_pause;
273           goto loop;
274         }
275
276     case Xpush_diamond_w:
277       switch (Cave[y][x-1])
278       {
279         case Zborder:
280         case Znormal:
281         case Zdynamite:
282         case Xboom_bug:
283         case Xboom_bomb:
284         case Xboom_android:
285         case Xboom_1:
286         case Zplayer:
287           Cave[y][x] = Xdiamond;
288           Next[y][x] = Xdiamond;
289           goto loop;
290
291         default:
292           Cave[y][x] = Ydiamond_wB;
293           Cave[y][x-1] = Ydiamond_w;
294           Next[y][x] = Xblank;
295           Next[y][x-1] = Xdiamond_pause;
296           goto loop;
297         }
298
299     case Xpush_bomb_e:
300       switch (Cave[y][x+1])
301       {
302         case Zborder:
303         case Znormal:
304         case Zdynamite:
305         case Xboom_bug:
306         case Xboom_bomb:
307         case Xboom_android:
308         case Xboom_1:
309         case Zplayer:
310           Cave[y][x] = Xbomb;
311           Next[y][x] = Xbomb;
312           goto loop;
313
314         default:
315           Cave[y][x] = Ybomb_eB;
316           Cave[y][x+1] = Ybomb_e;
317           Next[y][x] = Xblank;
318           Next[y][x+1] = Xbomb_pause;
319           goto loop;
320         }
321
322     case Xpush_bomb_w:
323       switch (Cave[y][x-1])
324       {
325         case Zborder:
326         case Znormal:
327         case Zdynamite:
328         case Xboom_bug:
329         case Xboom_bomb:
330         case Xboom_android:
331         case Xboom_1:
332         case Zplayer:
333           Cave[y][x] = Xbomb;
334           Next[y][x] = Xbomb;
335           goto loop;
336
337         default:
338           Cave[y][x] = Ybomb_wB;
339           Cave[y][x-1] = Ybomb_w;
340           Next[y][x] = Xblank;
341           Next[y][x-1] = Xbomb_pause;
342           goto loop;
343         }
344
345     /* --------------------------------------------------------------------- */
346
347     case Xstone:
348       switch (Cave[y+1][x])
349       {
350         case Xacid_1:
351         case Xacid_2:
352         case Xacid_3:
353         case Xacid_4:
354         case Xacid_5:
355         case Xacid_6:
356         case Xacid_7:
357         case Xacid_8:
358           Cave[y][x] = Ystone_sB;
359           if (Cave[y][x+1] == Xblank)
360             Cave[y][x+1] = Xacid_splash_e;
361           if (Cave[y][x-1] == Xblank)
362             Cave[y][x-1] = Xacid_splash_w;
363           Next[y][x] = Xblank;
364           play_element_sound(x, y, SOUND_acid, Xacid_1);
365           goto loop;
366
367         case Xblank:
368         case Xacid_splash_e:
369         case Xacid_splash_w:
370         case Xplant:
371         case Yplant:
372 #if 1
373         case Xfake_acid_1:
374         case Xfake_acid_2:
375         case Xfake_acid_3:
376         case Xfake_acid_4:
377         case Xfake_acid_5:
378         case Xfake_acid_6:
379         case Xfake_acid_7:
380         case Xfake_acid_8:
381 #endif
382           Cave[y][x] = Ystone_sB;
383           Cave[y+1][x] = Ystone_s;
384           Next[y][x] = Xblank;
385           Next[y+1][x] = Xstone_fall;
386           goto loop;
387
388         case Xsand:
389           Cave[y][x] = Xsand_stonein_1;
390           Cave[y+1][x] = Xsand_sandstone_1;
391           Next[y][x] = Xsand_stonein_2;
392           Next[y+1][x] = Xsand_sandstone_2;
393           goto loop;
394
395         case Xspring:
396         case Xspring_pause:
397         case Xspring_e:
398         case Xspring_w:
399         case Xandroid:
400         case Xandroid_1_n:
401         case Xandroid_2_n:
402         case Xandroid_1_e:
403         case Xandroid_2_e:
404         case Xandroid_1_s:
405         case Xandroid_2_s:
406         case Xandroid_1_w:
407         case Xandroid_2_w:
408         case Xstone:
409         case Xstone_pause:
410         case Xemerald:
411         case Xemerald_pause:
412         case Xdiamond:
413         case Xdiamond_pause:
414         case Xbomb:
415         case Xbomb_pause:
416         case Xballoon:
417         case Xacid_ne:
418         case Xacid_nw:
419         case Xball_1:
420         case Xball_2:
421         case Xnut:
422         case Xnut_pause:
423         case Xslidewall_ns:
424         case Xslidewall_ew:
425         case Xkey_1:
426         case Xkey_2:
427         case Xkey_3:
428         case Xkey_4:
429         case Xkey_5:
430         case Xkey_6:
431         case Xkey_7:
432         case Xkey_8:
433         case Xbumper:
434         case Xswitch:
435         case Xlenses:
436         case Xmagnify:
437         case Xroundwall_1:
438         case Xroundwall_2:
439         case Xroundwall_3:
440         case Xroundwall_4:
441           if (RANDOM & 1)
442           {
443             if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
444             {
445               Cave[y][x] = Ystone_eB;
446               Cave[y][x+1] = Ystone_e;
447               Next[y][x] = Xblank;
448               Next[y][x+1] = Xstone_pause;
449               goto loop;
450             }
451
452             if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
453             {
454               Cave[y][x] = Ystone_wB;
455               Cave[y][x-1] = Ystone_w;
456               Next[y][x] = Xblank;
457               Next[y][x-1] = Xstone_pause;
458               goto loop;
459             }
460           }
461           else
462           {
463             if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
464             {
465               Cave[y][x] = Ystone_wB;
466               Cave[y][x-1] = Ystone_w;
467               Next[y][x] = Xblank;
468               Next[y][x-1] = Xstone_pause;
469               goto loop;
470             }
471
472             if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
473             {
474               Cave[y][x] = Ystone_eB;
475               Cave[y][x+1] = Ystone_e;
476               Next[y][x] = Xblank;
477               Next[y][x+1] = Xstone_pause;
478               goto loop;
479             }
480           }
481
482         default:
483           goto loop;
484       }
485
486     /* --------------------------------------------------------------------- */
487
488     case Xstone_pause:
489       switch (Cave[y+1][x])
490       {
491         case Xacid_1:
492         case Xacid_2:
493         case Xacid_3:
494         case Xacid_4:
495         case Xacid_5:
496         case Xacid_6:
497         case Xacid_7:
498         case Xacid_8:
499           Cave[y][x] = Ystone_sB;
500           if (Cave[y][x+1] == Xblank)
501             Cave[y][x+1] = Xacid_splash_e;
502           if (Cave[y][x-1] == Xblank)
503             Cave[y][x-1] = Xacid_splash_w;
504           Next[y][x] = Xblank;
505           play_element_sound(x, y, SOUND_acid, Xacid_1);
506           goto loop;
507
508         case Xblank:
509         case Xacid_splash_e:
510         case Xacid_splash_w:
511 #if 1
512         case Xfake_acid_1:
513         case Xfake_acid_2:
514         case Xfake_acid_3:
515         case Xfake_acid_4:
516         case Xfake_acid_5:
517         case Xfake_acid_6:
518         case Xfake_acid_7:
519         case Xfake_acid_8:
520 #endif
521           Cave[y][x] = Ystone_sB;
522           Cave[y+1][x] = Ystone_s;
523           Next[y][x] = Xblank;
524           Next[y+1][x] = Xstone_fall;
525           goto loop;
526
527         default:
528           Cave[y][x] = Xstone;
529           Next[y][x] = Xstone;
530           goto loop;
531         }
532
533     /* --------------------------------------------------------------------- */
534
535     case Xstone_fall:
536       switch (Cave[y+1][x])
537       {
538         case Xacid_1:
539         case Xacid_2:
540         case Xacid_3:
541         case Xacid_4:
542         case Xacid_5:
543         case Xacid_6:
544         case Xacid_7:
545         case Xacid_8:
546           Cave[y][x] = Ystone_sB;
547           if (Cave[y][x+1] == Xblank)
548             Cave[y][x+1] = Xacid_splash_e;
549           if (Cave[y][x-1] == Xblank)
550             Cave[y][x-1] = Xacid_splash_w;
551           Next[y][x] = Xblank;
552           play_element_sound(x, y, SOUND_acid, Xacid_1);
553           goto loop;
554
555         case Xblank:
556         case Xacid_splash_e:
557         case Xacid_splash_w:
558         case Zplayer:
559 #if 1
560         case Xfake_acid_1:
561         case Xfake_acid_2:
562         case Xfake_acid_3:
563         case Xfake_acid_4:
564         case Xfake_acid_5:
565         case Xfake_acid_6:
566         case Xfake_acid_7:
567         case Xfake_acid_8:
568 #endif
569           Cave[y][x] = Ystone_sB;
570           Cave[y+1][x] = Ystone_s;
571           Next[y][x] = Xblank;
572           Next[y+1][x] = Xstone_fall;
573           goto loop;
574
575         case Xnut:
576         case Xnut_pause:
577           Cave[y+1][x] = Ynut_stone;
578           Next[y][x] = Xstone;
579           Next[y+1][x] = Xemerald;
580           play_element_sound(x, y, SOUND_crack, Xnut);
581           score += lev.nut_score;
582           goto loop;
583
584         case Xbug_1_n:
585         case Xbug_1_e:
586         case Xbug_1_s:
587         case Xbug_1_w:
588         case Xbug_2_n:
589         case Xbug_2_e:
590         case Xbug_2_s:
591         case Xbug_2_w:
592           Cave[y][x] = Ystone_sB;
593           Cave[y+1][x] = Ybug_stone;
594           Next[y+1][x] = Znormal;
595           Boom[y][x-1] = Xemerald;
596           Boom[y][x] = Xemerald;
597           Boom[y][x+1] = Xemerald;
598           Boom[y+1][x-1] = Xemerald;
599           Boom[y+1][x] = Xdiamond;
600           Boom[y+1][x+1] = Xemerald;
601           Boom[y+2][x-1] = Xemerald;
602           Boom[y+2][x] = Xemerald;
603           Boom[y+2][x+1] = Xemerald;
604 #if PLAY_ELEMENT_SOUND
605           play_element_sound(x, y, SOUND_boom, element);
606 #endif
607           score += lev.bug_score;
608           goto loop;
609
610         case Xtank_1_n:
611         case Xtank_1_e:
612         case Xtank_1_s:
613         case Xtank_1_w:
614         case Xtank_2_n:
615         case Xtank_2_e:
616         case Xtank_2_s:
617         case Xtank_2_w:
618           Cave[y][x] = Ystone_sB;
619           Cave[y+1][x] = Ytank_stone;
620           Next[y+1][x] = Znormal;
621           Boom[y][x-1] = Xblank;
622           Boom[y][x] = Xblank;
623           Boom[y][x+1] = Xblank;
624           Boom[y+1][x-1] = Xblank;
625           Boom[y+1][x] = Xblank;
626           Boom[y+1][x+1] = Xblank;
627           Boom[y+2][x-1] = Xblank;
628           Boom[y+2][x] = Xblank;
629           Boom[y+2][x+1] = Xblank;
630 #if PLAY_ELEMENT_SOUND
631           play_element_sound(x, y, SOUND_boom, element);
632 #endif
633           score += lev.tank_score;
634           goto loop;
635
636         case Xspring:
637           if (RANDOM & 1)
638           {
639             switch (Cave[y+1][x+1])
640             {
641               case Xblank:
642               case Xacid_splash_e:
643               case Xacid_splash_w:
644               case Xalien:
645               case Xalien_pause:
646                 Cave[y+1][x] = Xspring_e;
647                 break;
648
649               default:
650                 Cave[y+1][x] = Xspring_w;
651                 break;
652             }
653           }
654           else
655           {
656             switch (Cave[y+1][x-1])
657             {
658               case Xblank:
659               case Xacid_splash_e:
660               case Xacid_splash_w:
661               case Xalien:
662               case Xalien_pause:
663                 Cave[y+1][x] = Xspring_w;
664                 break;
665               default:
666                 Cave[y+1][x] = Xspring_e;
667                 break;
668             }
669           }
670
671           Next[y][x] = Xstone;
672           goto loop;
673
674         case Xeater_n:
675         case Xeater_e:
676         case Xeater_s:
677         case Xeater_w:
678           Cave[y][x] = Ystone_sB;
679           Cave[y+1][x] = Yeater_stone;
680           Next[y+1][x] = Znormal;
681           Boom[y][x-1] = lev.eater_array[lev.eater_pos][0];
682           Boom[y][x] = lev.eater_array[lev.eater_pos][1];
683           Boom[y][x+1] = lev.eater_array[lev.eater_pos][2];
684           Boom[y+1][x-1] = lev.eater_array[lev.eater_pos][3];
685           Boom[y+1][x] = lev.eater_array[lev.eater_pos][4];
686           Boom[y+1][x+1] = lev.eater_array[lev.eater_pos][5];
687           Boom[y+2][x-1] = lev.eater_array[lev.eater_pos][6];
688           Boom[y+2][x] = lev.eater_array[lev.eater_pos][7];
689           Boom[y+2][x+1] = lev.eater_array[lev.eater_pos][8];
690 #if PLAY_ELEMENT_SOUND
691           play_element_sound(x, y, SOUND_boom, element);
692 #endif
693           lev.eater_pos = (lev.eater_pos + 1) & 7;
694           score += lev.eater_score;
695           goto loop;
696
697         case Xalien:
698         case Xalien_pause:
699           Cave[y][x] = Ystone_sB;
700           Cave[y+1][x] = Yalien_stone;
701           Next[y+1][x] = Znormal;
702           Boom[y][x-1] = Xblank;
703           Boom[y][x] = Xblank;
704           Boom[y][x+1] = Xblank;
705           Boom[y+1][x-1] = Xblank;
706           Boom[y+1][x] = Xblank;
707           Boom[y+1][x+1] = Xblank;
708           Boom[y+2][x-1] = Xblank;
709           Boom[y+2][x] = Xblank;
710           Boom[y+2][x+1] = Xblank;
711 #if PLAY_ELEMENT_SOUND
712           play_element_sound(x, y, SOUND_boom, element);
713 #endif
714           score += lev.alien_score;
715           goto loop;
716
717         case Xdiamond:
718         case Xdiamond_pause:
719           switch (Cave[y+2][x])
720           {
721             case Xblank:
722             case Xacid_splash_e:
723             case Xacid_splash_w:
724             case Zplayer:
725             case Xbug_1_n:
726             case Xbug_1_e:
727             case Xbug_1_s:
728             case Xbug_1_w:
729             case Xbug_2_n:
730             case Xbug_2_e:
731             case Xbug_2_s:
732             case Xbug_2_w:
733             case Xtank_1_n:
734             case Xtank_1_e:
735             case Xtank_1_s:
736             case Xtank_1_w:
737             case Xtank_2_n:
738             case Xtank_2_e:
739             case Xtank_2_s:
740             case Xtank_2_w:
741             case Xspring_fall:
742             case Xandroid:
743             case Xandroid_1_n:
744             case Xandroid_2_n:
745             case Xandroid_1_e:
746             case Xandroid_2_e:
747             case Xandroid_1_s:
748             case Xandroid_2_s:
749             case Xandroid_1_w:
750             case Xandroid_2_w:
751             case Xstone_fall:
752             case Xemerald_fall:
753             case Xdiamond_fall:
754             case Xbomb_fall:
755             case Xacid_s:
756             case Xacid_1:
757             case Xacid_2:
758             case Xacid_3:
759             case Xacid_4:
760             case Xacid_5:
761             case Xacid_6:
762             case Xacid_7:
763             case Xacid_8:
764             case Xnut_fall:
765             case Xplant:
766             case Yplant:
767               Next[y][x] = Xstone;
768               play_element_sound(x, y, SOUND_stone, Xstone);
769               goto loop;
770           }
771
772           Cave[y][x] = Ystone_sB;
773           Cave[y+1][x] = Ydiamond_stone;
774           Next[y][x] = Xblank;
775           Next[y+1][x] = Xstone_pause;
776           play_element_sound(x, y, SOUND_squash, Xdiamond);
777           goto loop;
778
779         case Xbomb:
780         case Xbomb_pause:
781           Cave[y+1][x] = Ybomb_blank;
782           Next[y+1][x] = Znormal;
783           Boom[y][x-1] = Xblank;
784           Boom[y][x] = Xblank;
785           Boom[y][x+1] = Xblank;
786           Boom[y+1][x-1] = Xblank;
787           Boom[y+1][x] = Xblank;
788           Boom[y+1][x+1] = Xblank;
789           Boom[y+2][x-1] = Xblank;
790           Boom[y+2][x] = Xblank;
791           Boom[y+2][x+1] = Xblank;
792 #if PLAY_ELEMENT_SOUND
793           play_element_sound(x, y, SOUND_boom, element);
794 #endif
795           goto loop;
796
797         case Xwonderwall:
798           if (lev.wonderwall_time)
799           {
800             lev.wonderwall_state = 1;
801             Cave[y][x] = Ystone_sB;
802
803             if (tab_blank[Cave[y+2][x]])
804             {
805               Cave[y+2][x] = Yemerald_s;
806               Next[y+2][x] = Xemerald_fall;
807             }
808
809             Next[y][x] = Xblank;
810             play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
811             goto loop;
812           }
813
814         default:
815           Cave[y][x] = Xstone;
816           Next[y][x] = Xstone;
817           play_element_sound(x, y, SOUND_stone, Xstone);
818           goto loop;
819       }
820
821     /* --------------------------------------------------------------------- */
822
823     case Xnut:
824       switch (Cave[y+1][x])
825       {
826         case Xacid_1:
827         case Xacid_2:
828         case Xacid_3:
829         case Xacid_4:
830         case Xacid_5:
831         case Xacid_6:
832         case Xacid_7:
833         case Xacid_8:
834           Cave[y][x] = Ynut_sB;
835           if (Cave[y][x+1] == Xblank)
836             Cave[y][x+1] = Xacid_splash_e;
837           if (Cave[y][x-1] == Xblank)
838             Cave[y][x-1] = Xacid_splash_w;
839           Next[y][x] = Xblank;
840           play_element_sound(x, y, SOUND_acid, Xacid_1);
841           goto loop;
842
843         case Xblank:
844         case Xacid_splash_e:
845         case Xacid_splash_w:
846           Cave[y][x] = Ynut_sB;
847           Cave[y+1][x] = Ynut_s;
848           Next[y][x] = Xblank;
849           Next[y+1][x] = Xnut_fall;
850           goto loop;
851
852         case Xspring:
853         case Xspring_pause:
854         case Xspring_e:
855         case Xspring_w:
856         case Xandroid:
857         case Xandroid_1_n:
858         case Xandroid_2_n:
859         case Xandroid_1_e:
860         case Xandroid_2_e:
861         case Xandroid_1_s:
862         case Xandroid_2_s:
863         case Xandroid_1_w:
864         case Xandroid_2_w:
865         case Xstone:
866         case Xstone_pause:
867         case Xemerald:
868         case Xemerald_pause:
869         case Xdiamond:
870         case Xdiamond_pause:
871         case Xbomb:
872         case Xbomb_pause:
873         case Xballoon:
874         case Xacid_ne:
875         case Xacid_nw:
876         case Xball_1:
877         case Xball_2:
878         case Xnut:
879         case Xnut_pause:
880         case Xslidewall_ns:
881         case Xslidewall_ew:
882         case Xkey_1:
883         case Xkey_2:
884         case Xkey_3:
885         case Xkey_4:
886         case Xkey_5:
887         case Xkey_6:
888         case Xkey_7:
889         case Xkey_8:
890         case Xbumper:
891         case Xswitch:
892         case Xroundwall_1:
893         case Xroundwall_2:
894         case Xroundwall_3:
895         case Xroundwall_4:
896           if (RANDOM & 1)
897           {
898             if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
899             {
900               Cave[y][x] = Ynut_eB;
901               Cave[y][x+1] = Ynut_e;
902               Next[y][x] = Xblank;
903               Next[y][x+1] = Xnut_pause;
904               goto loop;
905             }
906
907             if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
908             {
909               Cave[y][x] = Ynut_wB;
910               Cave[y][x-1] = Ynut_w;
911               Next[y][x] = Xblank;
912               Next[y][x-1] = Xnut_pause;
913               goto loop;
914             }
915           }
916           else
917           {
918             if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
919             {
920               Cave[y][x] = Ynut_wB;
921               Cave[y][x-1] = Ynut_w;
922               Next[y][x] = Xblank;
923               Next[y][x-1] = Xnut_pause;
924               goto loop;
925             }
926
927             if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
928             {
929               Cave[y][x] = Ynut_eB;
930               Cave[y][x+1] = Ynut_e;
931               Next[y][x] = Xblank;
932               Next[y][x+1] = Xnut_pause;
933               goto loop;
934             }
935           }
936
937         default:
938           goto loop;
939       }
940
941     /* --------------------------------------------------------------------- */
942
943
944     case Xnut_pause:
945       switch (Cave[y+1][x])
946       {
947         case Xacid_1:
948         case Xacid_2:
949         case Xacid_3:
950         case Xacid_4:
951         case Xacid_5:
952         case Xacid_6:
953         case Xacid_7:
954         case Xacid_8:
955           Cave[y][x] = Ynut_sB;
956           if (Cave[y][x+1] == Xblank)
957             Cave[y][x+1] = Xacid_splash_e;
958           if (Cave[y][x-1] == Xblank)
959             Cave[y][x-1] = Xacid_splash_w;
960           Next[y][x] = Xblank;
961           play_element_sound(x, y, SOUND_acid, Xacid_1);
962           goto loop;
963
964         case Xblank:
965         case Xacid_splash_e:
966         case Xacid_splash_w:
967           Cave[y][x] = Ynut_sB;
968           Cave[y+1][x] = Ynut_s;
969           Next[y][x] = Xblank;
970           Next[y+1][x] = Xnut_fall;
971           goto loop;
972
973         default:
974           Cave[y][x] = Xnut;
975           Next[y][x] = Xnut;
976           goto loop;
977       }
978
979     /* --------------------------------------------------------------------- */
980
981     case Xnut_fall:
982       switch (Cave[y+1][x])
983       {
984         case Xacid_1:
985         case Xacid_2:
986         case Xacid_3:
987         case Xacid_4:
988         case Xacid_5:
989         case Xacid_6:
990         case Xacid_7:
991         case Xacid_8:
992           Cave[y][x] = Ynut_sB;
993           if (Cave[y][x+1] == Xblank)
994             Cave[y][x+1] = Xacid_splash_e;
995           if (Cave[y][x-1] == Xblank)
996             Cave[y][x-1] = Xacid_splash_w;
997           Next[y][x] = Xblank;
998           play_element_sound(x, y, SOUND_acid, Xacid_1);
999           goto loop;
1000
1001         case Xblank:
1002         case Xacid_splash_e:
1003         case Xacid_splash_w:
1004         case Zplayer:
1005           Cave[y][x] = Ynut_sB;
1006           Cave[y+1][x] = Ynut_s;
1007           Next[y][x] = Xblank;
1008           Next[y+1][x] = Xnut_fall;
1009           goto loop;
1010
1011         default:
1012           Cave[y][x] = Xnut;
1013           Next[y][x] = Xnut;
1014           play_element_sound(x, y, SOUND_nut, Xnut);
1015           goto loop;
1016       }
1017
1018     /* --------------------------------------------------------------------- */
1019
1020     case Xbug_1_n:
1021       if (tab_amoeba[Cave[y-1][x]] ||
1022           tab_amoeba[Cave[y][x+1]] ||
1023           tab_amoeba[Cave[y+1][x]] ||
1024           tab_amoeba[Cave[y][x-1]])
1025         goto bug_boom;
1026
1027       switch (Cave[y][x+1])
1028       {
1029         case Xblank:
1030         case Xacid_splash_e:
1031         case Xacid_splash_w:
1032         case Xplant:
1033         case Yplant:
1034         case Xacid_1:
1035         case Xacid_2:
1036         case Xacid_3:
1037         case Xacid_4:
1038         case Xacid_5:
1039         case Xacid_6:
1040         case Xacid_7:
1041         case Xacid_8:
1042         case Zplayer:
1043           Cave[y][x] = Ybug_n_e;
1044           Next[y][x] = Xbug_2_e;
1045           play_element_sound(x, y, SOUND_bug, element);
1046           goto loop;
1047
1048         default:
1049           goto bug_gon;
1050         }
1051
1052     case Xbug_2_n:
1053       if (tab_amoeba[Cave[y-1][x]] ||
1054           tab_amoeba[Cave[y][x+1]] ||
1055           tab_amoeba[Cave[y+1][x]] ||
1056           tab_amoeba[Cave[y][x-1]])
1057         goto bug_boom;
1058
1059     bug_gon:
1060
1061       switch (Cave[y-1][x])
1062       {
1063         case Xacid_1:
1064         case Xacid_2:
1065         case Xacid_3:
1066         case Xacid_4:
1067         case Xacid_5:
1068         case Xacid_6:
1069         case Xacid_7:
1070         case Xacid_8:
1071           Cave[y][x] = Ybug_nB;
1072           if (Cave[y-2][x+1] == Xblank)
1073             Cave[y-2][x+1] = Xacid_splash_e;
1074           if (Cave[y-2][x-1] == Xblank)
1075             Cave[y-2][x-1] = Xacid_splash_w;
1076           Next[y][x] = Xblank;
1077           play_element_sound(x, y, SOUND_acid, Xacid_1);
1078           goto loop;
1079
1080         case Xblank:
1081         case Xacid_splash_e:
1082         case Xacid_splash_w:
1083         case Xplant:
1084         case Yplant:
1085         case Zplayer:
1086           Cave[y][x] = Ybug_nB;
1087           Cave[y-1][x] = Ybug_n;
1088           Next[y][x] = Xblank;
1089           Next[y-1][x] = Xbug_1_n;
1090           play_element_sound(x, y, SOUND_bug, element);
1091           goto loop;
1092
1093         default:
1094           Cave[y][x] = Ybug_n_w;
1095           Next[y][x] = Xbug_2_w;
1096           play_element_sound(x, y, SOUND_bug, element);
1097           goto loop;
1098       }
1099
1100     /* --------------------------------------------------------------------- */
1101
1102     case Xbug_1_e:
1103       if (tab_amoeba[Cave[y-1][x]] ||
1104           tab_amoeba[Cave[y][x+1]] ||
1105           tab_amoeba[Cave[y+1][x]] ||
1106           tab_amoeba[Cave[y][x-1]])
1107         goto bug_boom;
1108
1109       switch (Cave[y+1][x])
1110       {
1111         case Xblank:
1112         case Xacid_splash_e:
1113         case Xacid_splash_w:
1114         case Xplant:
1115         case Yplant:
1116         case Xacid_1:
1117         case Xacid_2:
1118         case Xacid_3:
1119         case Xacid_4:
1120         case Xacid_5:
1121         case Xacid_6:
1122         case Xacid_7:
1123         case Xacid_8:
1124         case Zplayer:
1125           Cave[y][x] = Ybug_e_s;
1126           Next[y][x] = Xbug_2_s;
1127           play_element_sound(x, y, SOUND_bug, element);
1128           goto loop;
1129
1130         default:
1131           goto bug_goe;
1132       }
1133
1134     case Xbug_2_e:
1135       if (tab_amoeba[Cave[y-1][x]] ||
1136           tab_amoeba[Cave[y][x+1]] ||
1137           tab_amoeba[Cave[y+1][x]] ||
1138           tab_amoeba[Cave[y][x-1]])
1139         goto bug_boom;
1140
1141     bug_goe:
1142
1143       switch (Cave[y][x+1])
1144       {
1145         case Xacid_1:
1146         case Xacid_2:
1147         case Xacid_3:
1148         case Xacid_4:
1149         case Xacid_5:
1150         case Xacid_6:
1151         case Xacid_7:
1152         case Xacid_8:
1153           Cave[y][x] = Ybug_eB;
1154           if (Cave[y-1][x+2] == Xblank)
1155             Cave[y-1][x+2] = Xacid_splash_e;
1156           if (Cave[y-1][x] == Xblank)
1157             Cave[y-1][x] = Xacid_splash_w;
1158           Next[y][x] = Xblank;
1159           play_element_sound(x, y, SOUND_acid, Xacid_1);
1160           goto loop;
1161
1162         case Xblank:
1163         case Xacid_splash_e:
1164         case Xacid_splash_w:
1165         case Xplant:
1166         case Yplant:
1167         case Zplayer:
1168           Cave[y][x] = Ybug_eB;
1169           Cave[y][x+1] = Ybug_e;
1170           Next[y][x] = Xblank;
1171           Next[y][x+1] = Xbug_1_e;
1172           play_element_sound(x, y, SOUND_bug, element);
1173           goto loop;
1174
1175         default:
1176           Cave[y][x] = Ybug_e_n;
1177           Next[y][x] = Xbug_2_n;
1178           play_element_sound(x, y, SOUND_bug, element);
1179           goto loop;
1180       }
1181
1182     /* --------------------------------------------------------------------- */
1183
1184     case Xbug_1_s:
1185       if (tab_amoeba[Cave[y-1][x]] ||
1186           tab_amoeba[Cave[y][x+1]] ||
1187           tab_amoeba[Cave[y+1][x]] ||
1188           tab_amoeba[Cave[y][x-1]])
1189         goto bug_boom;
1190
1191       switch (Cave[y][x-1])
1192       {
1193         case Xblank:
1194         case Xacid_splash_e:
1195         case Xacid_splash_w:
1196         case Xplant:
1197         case Yplant:
1198         case Xacid_1:
1199         case Xacid_2:
1200         case Xacid_3:
1201         case Xacid_4:
1202         case Xacid_5:
1203         case Xacid_6:
1204         case Xacid_7:
1205         case Xacid_8:
1206         case Zplayer:
1207           Cave[y][x] = Ybug_s_w;
1208           Next[y][x] = Xbug_2_w;
1209           play_element_sound(x, y, SOUND_bug, element);
1210           goto loop;
1211
1212         default:
1213           goto bug_gos;
1214       }
1215
1216     case Xbug_2_s:
1217       if (tab_amoeba[Cave[y-1][x]] ||
1218           tab_amoeba[Cave[y][x+1]] ||
1219           tab_amoeba[Cave[y+1][x]] ||
1220           tab_amoeba[Cave[y][x-1]])
1221         goto bug_boom;
1222
1223     bug_gos:
1224
1225       switch (Cave[y+1][x])
1226       {
1227         case Xacid_1:
1228         case Xacid_2:
1229         case Xacid_3:
1230         case Xacid_4:
1231         case Xacid_5:
1232         case Xacid_6:
1233         case Xacid_7:
1234         case Xacid_8:
1235           Cave[y][x] = Ybug_sB;
1236           if (Cave[y][x+1] == Xblank)
1237             Cave[y][x+1] = Xacid_splash_e;
1238           if (Cave[y][x-1] == Xblank)
1239             Cave[y][x-1] = Xacid_splash_w;
1240           Next[y][x] = Xblank;
1241           play_element_sound(x, y, SOUND_acid, Xacid_1);
1242           goto loop;
1243
1244         case Xblank:
1245         case Xacid_splash_e:
1246         case Xacid_splash_w:
1247         case Xplant:
1248         case Yplant:
1249         case Zplayer:
1250           Cave[y][x] = Ybug_sB;
1251           Cave[y+1][x] = Ybug_s;
1252           Next[y][x] = Xblank;
1253           Next[y+1][x] = Xbug_1_s;
1254           play_element_sound(x, y, SOUND_bug, element);
1255           goto loop;
1256
1257         default:
1258           Cave[y][x] = Ybug_s_e;
1259           Next[y][x] = Xbug_2_e;
1260           play_element_sound(x, y, SOUND_bug, element);
1261           goto loop;
1262       }
1263
1264     /* --------------------------------------------------------------------- */
1265
1266     case Xbug_1_w:
1267       if (tab_amoeba[Cave[y-1][x]] ||
1268           tab_amoeba[Cave[y][x+1]] ||
1269           tab_amoeba[Cave[y+1][x]] ||
1270           tab_amoeba[Cave[y][x-1]])
1271         goto bug_boom;
1272
1273       switch (Cave[y-1][x])
1274       {
1275         case Xblank:
1276         case Xacid_splash_e:
1277         case Xacid_splash_w:
1278         case Xplant:
1279         case Yplant:
1280         case Xacid_1:
1281         case Xacid_2:
1282         case Xacid_3:
1283         case Xacid_4:
1284         case Xacid_5:
1285         case Xacid_6:
1286         case Xacid_7:
1287         case Xacid_8:
1288         case Zplayer:
1289           Cave[y][x] = Ybug_w_n;
1290           Next[y][x] = Xbug_2_n;
1291           play_element_sound(x, y, SOUND_bug, element);
1292           goto loop;
1293
1294         default:
1295           goto bug_gow;
1296       }
1297
1298     case Xbug_2_w:
1299       if (tab_amoeba[Cave[y-1][x]] ||
1300           tab_amoeba[Cave[y][x+1]] ||
1301           tab_amoeba[Cave[y+1][x]] ||
1302           tab_amoeba[Cave[y][x-1]])
1303         goto bug_boom;
1304
1305     bug_gow:
1306
1307       switch (Cave[y][x-1])
1308       {
1309         case Xacid_1:
1310         case Xacid_2:
1311         case Xacid_3:
1312         case Xacid_4:
1313         case Xacid_5:
1314         case Xacid_6:
1315         case Xacid_7:
1316         case Xacid_8:
1317           Cave[y][x] = Ybug_wB;
1318           if (Cave[y-1][x] == Xblank)
1319             Cave[y-1][x] = Xacid_splash_e;
1320           if (Cave[y-1][x-2] == Xblank)
1321             Cave[y-1][x-2] = Xacid_splash_w;
1322           Next[y][x] = Xblank;
1323           play_element_sound(x, y, SOUND_acid, Xacid_1);
1324           goto loop;
1325
1326         case Xblank:
1327         case Xacid_splash_e:
1328         case Xacid_splash_w:
1329         case Xplant:
1330         case Yplant:
1331         case Zplayer:
1332           Cave[y][x] = Ybug_wB;
1333           Cave[y][x-1] = Ybug_w;
1334           Next[y][x] = Xblank;
1335           Next[y][x-1] = Xbug_1_w;
1336           play_element_sound(x, y, SOUND_bug, element);
1337           goto loop;
1338
1339         default:
1340           Cave[y][x] = Ybug_w_s;
1341           Next[y][x] = Xbug_2_s;
1342           play_element_sound(x, y, SOUND_bug, element);
1343           goto loop;
1344       }
1345
1346     /* --------------------------------------------------------------------- */
1347
1348     case Xtank_1_n:
1349       if (tab_amoeba[Cave[y-1][x]] ||
1350           tab_amoeba[Cave[y][x+1]] ||
1351           tab_amoeba[Cave[y+1][x]] ||
1352           tab_amoeba[Cave[y][x-1]])
1353         goto tank_boom;
1354
1355       switch (Cave[y][x-1])
1356       {
1357         case Xblank:
1358         case Xacid_splash_e:
1359         case Xacid_splash_w:
1360         case Xplant:
1361         case Yplant:
1362         case Xacid_1:
1363         case Xacid_2:
1364         case Xacid_3:
1365         case Xacid_4:
1366         case Xacid_5:
1367         case Xacid_6:
1368         case Xacid_7:
1369         case Xacid_8:
1370         case Zplayer:
1371           Cave[y][x] = Ytank_n_w;
1372           Next[y][x] = Xtank_2_w;
1373           play_element_sound(x, y, SOUND_tank, element);
1374           goto loop;
1375
1376         default:
1377           goto tank_gon;
1378       }
1379
1380     case Xtank_2_n:
1381       if (tab_amoeba[Cave[y-1][x]] ||
1382           tab_amoeba[Cave[y][x+1]] ||
1383           tab_amoeba[Cave[y+1][x]] ||
1384           tab_amoeba[Cave[y][x-1]])
1385         goto tank_boom;
1386
1387     tank_gon:
1388
1389       switch (Cave[y-1][x])
1390       {
1391         case Xacid_1:
1392         case Xacid_2:
1393         case Xacid_3:
1394         case Xacid_4:
1395         case Xacid_5:
1396         case Xacid_6:
1397         case Xacid_7:
1398         case Xacid_8:
1399           Cave[y][x] = Ytank_nB;
1400           if (Cave[y-2][x+1] == Xblank)
1401             Cave[y-2][x+1] = Xacid_splash_e;
1402           if (Cave[y-2][x-1] == Xblank)
1403             Cave[y-2][x-1] = Xacid_splash_w;
1404           Next[y][x] = Xblank;
1405           play_element_sound(x, y, SOUND_acid, Xacid_1);
1406           goto loop;
1407
1408         case Xblank:
1409         case Xacid_splash_e:
1410         case Xacid_splash_w:
1411         case Xplant:
1412         case Yplant:
1413         case Zplayer:
1414           Cave[y][x] = Ytank_nB;
1415           Cave[y-1][x] = Ytank_n;
1416           Next[y][x] = Xblank;
1417           Next[y-1][x] = Xtank_1_n;
1418           play_element_sound(x, y, SOUND_tank, element);
1419           goto loop;
1420
1421         default:
1422           Cave[y][x] = Ytank_n_e;
1423           Next[y][x] = Xtank_2_e;
1424           play_element_sound(x, y, SOUND_tank, element);
1425           goto loop;
1426       }
1427
1428     /* --------------------------------------------------------------------- */
1429
1430     case Xtank_1_e:
1431       if (tab_amoeba[Cave[y-1][x]] ||
1432           tab_amoeba[Cave[y][x+1]] ||
1433           tab_amoeba[Cave[y+1][x]] ||
1434           tab_amoeba[Cave[y][x-1]])
1435         goto tank_boom;
1436
1437       switch (Cave[y-1][x])
1438       {
1439         case Xblank:
1440         case Xacid_splash_e:
1441         case Xacid_splash_w:
1442         case Xplant:
1443         case Yplant:
1444         case Xacid_1:
1445         case Xacid_2:
1446         case Xacid_3:
1447         case Xacid_4:
1448         case Xacid_5:
1449         case Xacid_6:
1450         case Xacid_7:
1451         case Xacid_8:
1452         case Zplayer:
1453           Cave[y][x] = Ytank_e_n;
1454           Next[y][x] = Xtank_2_n;
1455           play_element_sound(x, y, SOUND_tank, element);
1456           goto loop;
1457
1458         default:
1459           goto tank_goe;
1460       }
1461
1462     case Xtank_2_e:
1463       if (tab_amoeba[Cave[y-1][x]] ||
1464           tab_amoeba[Cave[y][x+1]] ||
1465           tab_amoeba[Cave[y+1][x]] ||
1466           tab_amoeba[Cave[y][x-1]])
1467         goto tank_boom;
1468
1469     tank_goe:
1470
1471       switch (Cave[y][x+1])
1472       {
1473         case Xacid_1:
1474         case Xacid_2:
1475         case Xacid_3:
1476         case Xacid_4:
1477         case Xacid_5:
1478         case Xacid_6:
1479         case Xacid_7:
1480         case Xacid_8:
1481           Cave[y][x] = Ytank_eB;
1482           if (Cave[y-1][x+2] == Xblank)
1483             Cave[y-1][x+2] = Xacid_splash_e;
1484           if (Cave[y-1][x] == Xblank)
1485             Cave[y-1][x] = Xacid_splash_w;
1486           Next[y][x] = Xblank;
1487           play_element_sound(x, y, SOUND_acid, Xacid_1);
1488           goto loop;
1489
1490         case Xblank:
1491         case Xacid_splash_e:
1492         case Xacid_splash_w:
1493         case Xplant:
1494         case Yplant:
1495         case Zplayer:
1496           Cave[y][x] = Ytank_eB;
1497           Cave[y][x+1] = Ytank_e;
1498           Next[y][x] = Xblank;
1499           Next[y][x+1] = Xtank_1_e;
1500           play_element_sound(x, y, SOUND_tank, element);
1501           goto loop;
1502
1503         default:
1504           Cave[y][x] = Ytank_e_s;
1505           Next[y][x] = Xtank_2_s;
1506           play_element_sound(x, y, SOUND_tank, element);
1507           goto loop;
1508       }
1509
1510     /* --------------------------------------------------------------------- */
1511
1512     case Xtank_1_s:
1513       if (tab_amoeba[Cave[y-1][x]] ||
1514           tab_amoeba[Cave[y][x+1]] ||
1515           tab_amoeba[Cave[y+1][x]] ||
1516           tab_amoeba[Cave[y][x-1]])
1517         goto tank_boom;
1518
1519       switch (Cave[y][x+1])
1520       {
1521         case Xblank:
1522         case Xacid_splash_e:
1523         case Xacid_splash_w:
1524         case Xplant:
1525         case Yplant:
1526         case Xacid_1:
1527         case Xacid_2:
1528         case Xacid_3:
1529         case Xacid_4:
1530         case Xacid_5:
1531         case Xacid_6:
1532         case Xacid_7:
1533         case Xacid_8:
1534         case Zplayer:
1535           Cave[y][x] = Ytank_s_e;
1536           Next[y][x] = Xtank_2_e;
1537           play_element_sound(x, y, SOUND_tank, element);
1538           goto loop;
1539
1540         default:
1541           goto tank_gos;
1542       }
1543
1544     case Xtank_2_s:
1545       if (tab_amoeba[Cave[y-1][x]] ||
1546           tab_amoeba[Cave[y][x+1]] ||
1547           tab_amoeba[Cave[y+1][x]] ||
1548           tab_amoeba[Cave[y][x-1]])
1549         goto tank_boom;
1550
1551     tank_gos:
1552
1553       switch (Cave[y+1][x])
1554       {
1555         case Xacid_1:
1556         case Xacid_2:
1557         case Xacid_3:
1558         case Xacid_4:
1559         case Xacid_5:
1560         case Xacid_6:
1561         case Xacid_7:
1562         case Xacid_8:
1563           Cave[y][x] = Ytank_sB;
1564           if (Cave[y][x+1] == Xblank)
1565             Cave[y][x+1] = Xacid_splash_e;
1566           if (Cave[y][x-1] == Xblank)
1567             Cave[y][x-1] = Xacid_splash_w;
1568           Next[y][x] = Xblank;
1569           play_element_sound(x, y, SOUND_acid, Xacid_1);
1570           goto loop;
1571
1572         case Xblank:
1573         case Xacid_splash_e:
1574         case Xacid_splash_w:
1575         case Xplant:
1576         case Yplant:
1577         case Zplayer:
1578           Cave[y][x] = Ytank_sB;
1579           Cave[y+1][x] = Ytank_s;
1580           Next[y][x] = Xblank;
1581           Next[y+1][x] = Xtank_1_s;
1582           play_element_sound(x, y, SOUND_tank, element);
1583           goto loop;
1584
1585         default:
1586           Cave[y][x] = Ytank_s_w;
1587           Next[y][x] = Xtank_2_w;
1588           play_element_sound(x, y, SOUND_tank, element);
1589           goto loop;
1590       }
1591
1592     /* --------------------------------------------------------------------- */
1593
1594     case Xtank_1_w:
1595       if (tab_amoeba[Cave[y-1][x]] ||
1596           tab_amoeba[Cave[y][x+1]] ||
1597           tab_amoeba[Cave[y+1][x]] ||
1598           tab_amoeba[Cave[y][x-1]])
1599         goto tank_boom;
1600
1601       switch (Cave[y+1][x])
1602       {
1603         case Xblank:
1604         case Xacid_splash_e:
1605         case Xacid_splash_w:
1606         case Xplant:
1607         case Yplant:
1608         case Xacid_1:
1609         case Xacid_2:
1610         case Xacid_3:
1611         case Xacid_4:
1612         case Xacid_5:
1613         case Xacid_6:
1614         case Xacid_7:
1615         case Xacid_8:
1616         case Zplayer:
1617           Cave[y][x] = Ytank_w_s;
1618           Next[y][x] = Xtank_2_s;
1619           play_element_sound(x, y, SOUND_tank, element);
1620           goto loop;
1621
1622         default:
1623           goto tank_gow;
1624       }
1625
1626     case Xtank_2_w:
1627       if (tab_amoeba[Cave[y-1][x]] ||
1628           tab_amoeba[Cave[y][x+1]] ||
1629           tab_amoeba[Cave[y+1][x]] ||
1630           tab_amoeba[Cave[y][x-1]])
1631         goto tank_boom;
1632
1633     tank_gow:
1634
1635       switch (Cave[y][x-1])
1636       {
1637         case Xacid_1:
1638         case Xacid_2:
1639         case Xacid_3:
1640         case Xacid_4:
1641         case Xacid_5:
1642         case Xacid_6:
1643         case Xacid_7:
1644         case Xacid_8:
1645           Cave[y][x] = Ytank_wB;
1646           if (Cave[y-1][x] == Xblank)
1647             Cave[y-1][x] = Xacid_splash_e;
1648           if (Cave[y-1][x-2] == Xblank)
1649             Cave[y-1][x-2] = Xacid_splash_w;
1650           Next[y][x] = Xblank;
1651           play_element_sound(x, y, SOUND_acid, Xacid_1);
1652           goto loop;
1653
1654         case Xblank:
1655         case Xacid_splash_e:
1656         case Xacid_splash_w:
1657         case Xplant:
1658         case Yplant:
1659         case Zplayer:
1660           Cave[y][x] = Ytank_wB;
1661           Cave[y][x-1] = Ytank_w;
1662           Next[y][x] = Xblank;
1663           Next[y][x-1] = Xtank_1_w;
1664           play_element_sound(x, y, SOUND_tank, element);
1665           goto loop;
1666
1667         default:
1668           Cave[y][x] = Ytank_w_n;
1669           Next[y][x] = Xtank_2_n;
1670           play_element_sound(x, y, SOUND_tank, element);
1671           goto loop;
1672       }
1673
1674     /* --------------------------------------------------------------------- */
1675
1676     case Xandroid:
1677
1678     android:
1679
1680       if (lev.android_clone_cnt == 0)
1681       {
1682         if (Cave[y-1][x-1] != Xblank &&
1683             Cave[y-1][x]   != Xblank &&
1684             Cave[y-1][x+1] != Xblank &&
1685             Cave[y][x-1]   != Xblank &&
1686             Cave[y][x+1]   != Xblank &&
1687             Cave[y+1][x-1] != Xblank &&
1688             Cave[y+1][x]   != Xblank &&
1689             Cave[y+1][x+1] != Xblank)
1690           goto android_move;
1691
1692         switch (RANDOM & 7)
1693         {
1694           /* randomly find an object to clone */
1695
1696           case 0: /* S,NE,W,NW,SE,E,SW,N */
1697             temp= lev.android_array[Cave[y+1][x]];   if (temp != Xblank) break;
1698             temp= lev.android_array[Cave[y-1][x+1]]; if (temp != Xblank) break;
1699             temp= lev.android_array[Cave[y][x-1]];   if (temp != Xblank) break;
1700             temp= lev.android_array[Cave[y-1][x-1]]; if (temp != Xblank) break;
1701             temp= lev.android_array[Cave[y+1][x+1]]; if (temp != Xblank) break;
1702             temp= lev.android_array[Cave[y][x+1]];   if (temp != Xblank) break;
1703             temp= lev.android_array[Cave[y+1][x-1]]; if (temp != Xblank) break;
1704             temp= lev.android_array[Cave[y-1][x]];   if (temp != Xblank) break;
1705             goto android_move;
1706
1707           case 1: /* NW,SE,N,S,NE,SW,E,W */
1708             temp= lev.android_array[Cave[y-1][x-1]]; if (temp != Xblank) break;
1709             temp= lev.android_array[Cave[y+1][x+1]]; if (temp != Xblank) break;
1710             temp= lev.android_array[Cave[y-1][x]];   if (temp != Xblank) break;
1711             temp= lev.android_array[Cave[y+1][x]];   if (temp != Xblank) break;
1712             temp= lev.android_array[Cave[y-1][x+1]]; if (temp != Xblank) break;
1713             temp= lev.android_array[Cave[y+1][x-1]]; if (temp != Xblank) break;
1714             temp= lev.android_array[Cave[y][x+1]];   if (temp != Xblank) break;
1715             temp= lev.android_array[Cave[y][x-1]];   if (temp != Xblank) break;
1716             goto android_move;
1717
1718           case 2: /* SW,E,S,W,N,NW,SE,NE */
1719             temp= lev.android_array[Cave[y+1][x-1]]; if (temp != Xblank) break;
1720             temp= lev.android_array[Cave[y][x+1]];   if (temp != Xblank) break;
1721             temp= lev.android_array[Cave[y+1][x]];   if (temp != Xblank) break;
1722             temp= lev.android_array[Cave[y][x-1]];   if (temp != Xblank) break;
1723             temp= lev.android_array[Cave[y-1][x]];   if (temp != Xblank) break;
1724             temp= lev.android_array[Cave[y-1][x-1]]; if (temp != Xblank) break;
1725             temp= lev.android_array[Cave[y+1][x+1]]; if (temp != Xblank) break;
1726             temp= lev.android_array[Cave[y-1][x+1]]; if (temp != Xblank) break;
1727             goto android_move;
1728
1729           case 3: /* N,SE,NE,E,W,S,NW,SW */
1730             temp= lev.android_array[Cave[y-1][x]];   if (temp != Xblank) break;
1731             temp= lev.android_array[Cave[y+1][x+1]]; if (temp != Xblank) break;
1732             temp= lev.android_array[Cave[y-1][x+1]]; if (temp != Xblank) break;
1733             temp= lev.android_array[Cave[y][x+1]];   if (temp != Xblank) break;
1734             temp= lev.android_array[Cave[y][x-1]];   if (temp != Xblank) break;
1735             temp= lev.android_array[Cave[y+1][x]];   if (temp != Xblank) break;
1736             temp= lev.android_array[Cave[y-1][x-1]]; if (temp != Xblank) break;
1737             temp= lev.android_array[Cave[y+1][x-1]]; if (temp != Xblank) break;
1738             goto android_move;
1739
1740           case 4: /* SE,NW,E,NE,SW,W,N,S */
1741             temp= lev.android_array[Cave[y+1][x+1]]; if (temp != Xblank) break;
1742             temp= lev.android_array[Cave[y-1][x-1]]; if (temp != Xblank) break;
1743             temp= lev.android_array[Cave[y][x+1]];   if (temp != Xblank) break;
1744             temp= lev.android_array[Cave[y-1][x+1]]; if (temp != Xblank) break;
1745             temp= lev.android_array[Cave[y+1][x-1]]; if (temp != Xblank) break;
1746             temp= lev.android_array[Cave[y][x-1]];   if (temp != Xblank) break;
1747             temp= lev.android_array[Cave[y-1][x]];   if (temp != Xblank) break;
1748             temp= lev.android_array[Cave[y+1][x]];   if (temp != Xblank) break;
1749             goto android_move;
1750
1751           case 5: /* NE,W,SE,SW,S,N,E,NW */
1752             temp= lev.android_array[Cave[y-1][x+1]]; if (temp != Xblank) break;
1753             temp= lev.android_array[Cave[y][x-1]];   if (temp != Xblank) break;
1754             temp= lev.android_array[Cave[y+1][x+1]]; if (temp != Xblank) break;
1755             temp= lev.android_array[Cave[y+1][x-1]]; if (temp != Xblank) break;
1756             temp= lev.android_array[Cave[y+1][x]];   if (temp != Xblank) break;
1757             temp= lev.android_array[Cave[y-1][x]];   if (temp != Xblank) break;
1758             temp= lev.android_array[Cave[y][x+1]];   if (temp != Xblank) break;
1759             temp= lev.android_array[Cave[y-1][x-1]]; if (temp != Xblank) break;
1760             goto android_move;
1761
1762           case 6: /* E,N,SW,S,NW,NE,SE,W */
1763             temp= lev.android_array[Cave[y][x+1]];   if (temp != Xblank) break;
1764             temp= lev.android_array[Cave[y-1][x]];   if (temp != Xblank) break;
1765             temp= lev.android_array[Cave[y+1][x-1]]; if (temp != Xblank) break;
1766             temp= lev.android_array[Cave[y+1][x]];   if (temp != Xblank) break;
1767             temp= lev.android_array[Cave[y-1][x-1]]; if (temp != Xblank) break;
1768             temp= lev.android_array[Cave[y-1][x+1]]; if (temp != Xblank) break;
1769             temp= lev.android_array[Cave[y+1][x+1]]; if (temp != Xblank) break;
1770             temp= lev.android_array[Cave[y][x-1]];   if (temp != Xblank) break;
1771             goto android_move;
1772
1773           case 7: /* W,SW,NW,N,E,SE,NE,S */
1774             temp= lev.android_array[Cave[y][x-1]];   if (temp != Xblank) break;
1775             temp= lev.android_array[Cave[y+1][x-1]]; if (temp != Xblank) break;
1776             temp= lev.android_array[Cave[y-1][x-1]]; if (temp != Xblank) break;
1777             temp= lev.android_array[Cave[y-1][x]];   if (temp != Xblank) break;
1778             temp= lev.android_array[Cave[y][x+1]];   if (temp != Xblank) break;
1779             temp= lev.android_array[Cave[y+1][x+1]]; if (temp != Xblank) break;
1780             temp= lev.android_array[Cave[y-1][x+1]]; if (temp != Xblank) break;
1781             temp= lev.android_array[Cave[y+1][x]];   if (temp != Xblank) break;
1782             goto android_move;
1783         }
1784
1785         Next[y][x] = temp;      /* the item we chose to clone */
1786         play_element_sound(x, y, SOUND_android_clone, temp);
1787
1788         switch (RANDOM & 7)
1789         {
1790           /* randomly find a direction to move */
1791
1792           case 0: /* S,NE,W,NW,SE,E,SW,N */
1793             if (Cave[y+1][x] == Xblank)   goto android_s;
1794             if (Cave[y-1][x+1] == Xblank) goto android_ne;
1795             if (Cave[y][x-1] == Xblank)   goto android_w;
1796             if (Cave[y-1][x-1] == Xblank) goto android_nw;
1797             if (Cave[y+1][x+1] == Xblank) goto android_se;
1798             if (Cave[y][x+1] == Xblank)   goto android_e;
1799             if (Cave[y+1][x-1] == Xblank) goto android_sw;
1800             if (Cave[y-1][x] == Xblank)   goto android_n;
1801             goto android_move;
1802
1803           case 1: /* NW,SE,N,S,NE,SW,E,W */
1804             if (Cave[y-1][x-1] == Xblank) goto android_nw;
1805             if (Cave[y+1][x+1] == Xblank) goto android_se;
1806             if (Cave[y-1][x] == Xblank)   goto android_n;
1807             if (Cave[y+1][x] == Xblank)   goto android_s;
1808             if (Cave[y-1][x+1] == Xblank) goto android_ne;
1809             if (Cave[y+1][x-1] == Xblank) goto android_sw;
1810             if (Cave[y][x+1] == Xblank)   goto android_e;
1811             if (Cave[y][x-1] == Xblank)   goto android_w;
1812             goto android_move;
1813
1814           case 2: /* SW,E,S,W,N,NW,SE,NE */
1815             if (Cave[y+1][x-1] == Xblank) goto android_sw;
1816             if (Cave[y][x+1] == Xblank)   goto android_e;
1817             if (Cave[y+1][x] == Xblank)   goto android_s;
1818             if (Cave[y][x-1] == Xblank)   goto android_w;
1819             if (Cave[y-1][x] == Xblank)   goto android_n;
1820             if (Cave[y-1][x-1] == Xblank) goto android_nw;
1821             if (Cave[y+1][x+1] == Xblank) goto android_se;
1822             if (Cave[y-1][x+1] == Xblank) goto android_ne;
1823             goto android_move;
1824
1825           case 3: /* N,SE,NE,E,W,S,NW,SW */
1826             if (Cave[y-1][x] == Xblank)   goto android_n;
1827             if (Cave[y+1][x+1] == Xblank) goto android_se;
1828             if (Cave[y-1][x+1] == Xblank) goto android_ne;
1829             if (Cave[y][x+1] == Xblank)   goto android_e;
1830             if (Cave[y][x-1] == Xblank)   goto android_w;
1831             if (Cave[y+1][x] == Xblank)   goto android_s;
1832             if (Cave[y-1][x-1] == Xblank) goto android_nw;
1833             if (Cave[y+1][x-1] == Xblank) goto android_sw;
1834             goto android_move;
1835
1836           case 4: /* SE,NW,E,NE,SW,W,N,S */
1837             if (Cave[y+1][x+1] == Xblank) goto android_se;
1838             if (Cave[y-1][x-1] == Xblank) goto android_nw;
1839             if (Cave[y][x+1] == Xblank)   goto android_e;
1840             if (Cave[y-1][x+1] == Xblank) goto android_ne;
1841             if (Cave[y+1][x-1] == Xblank) goto android_sw;
1842             if (Cave[y][x-1] == Xblank)   goto android_w;
1843             if (Cave[y-1][x] == Xblank)   goto android_n;
1844             if (Cave[y+1][x] == Xblank)   goto android_s;
1845             goto android_move;
1846
1847           case 5: /* NE,W,SE,SW,S,N,E,NW */
1848             if (Cave[y-1][x+1] == Xblank) goto android_ne;
1849             if (Cave[y][x-1] == Xblank)   goto android_w;
1850             if (Cave[y+1][x+1] == Xblank) goto android_se;
1851             if (Cave[y+1][x-1] == Xblank) goto android_sw;
1852             if (Cave[y+1][x] == Xblank)   goto android_s;
1853             if (Cave[y-1][x] == Xblank)   goto android_n;
1854             if (Cave[y][x+1] == Xblank)   goto android_e;
1855             if (Cave[y-1][x-1] == Xblank) goto android_nw;
1856             goto android_move;
1857
1858           case 6: /* E,N,SW,S,NW,NE,SE,W */
1859             if (Cave[y][x+1] == Xblank)   goto android_e;
1860             if (Cave[y-1][x] == Xblank)   goto android_n;
1861             if (Cave[y+1][x-1] == Xblank) goto android_sw;
1862             if (Cave[y+1][x] == Xblank)   goto android_s;
1863             if (Cave[y-1][x-1] == Xblank) goto android_nw;
1864             if (Cave[y-1][x+1] == Xblank) goto android_ne;
1865             if (Cave[y+1][x+1] == Xblank) goto android_se;
1866             if (Cave[y][x-1] == Xblank)   goto android_w;
1867             goto android_move;
1868
1869           case 7: /* W,SW,NW,N,E,SE,NE,S */
1870             if (Cave[y][x-1] == Xblank)   goto android_w;
1871             if (Cave[y+1][x-1] == Xblank) goto android_sw;
1872             if (Cave[y-1][x-1] == Xblank) goto android_nw;
1873             if (Cave[y-1][x] == Xblank)   goto android_n;
1874             if (Cave[y][x+1] == Xblank)   goto android_e;
1875             if (Cave[y+1][x+1] == Xblank) goto android_se;
1876             if (Cave[y-1][x+1] == Xblank) goto android_ne;
1877             if (Cave[y+1][x] == Xblank)   goto android_s;
1878             goto android_move;
1879         }
1880       }
1881
1882     android_move:
1883       if (lev.android_move_cnt == 0)
1884       {
1885         if (Cave[y-1][x-1] == Zplayer ||
1886             Cave[y-1][x]   == Zplayer ||
1887             Cave[y-1][x+1] == Zplayer ||
1888             Cave[y][x-1]   == Zplayer ||
1889             Cave[y][x+1]   == Zplayer ||
1890             Cave[y+1][x-1] == Zplayer ||
1891             Cave[y+1][x]   == Zplayer ||
1892             Cave[y+1][x+1] == Zplayer)
1893           goto android_still;
1894
1895         set_nearest_player_xy(x, y, &dx, &dy);
1896
1897         Next[y][x] = Xblank;    /* assume we will move */
1898         temp = ((x < dx) + 1 - (x > dx)) + ((y < dy) + 1 - (y > dy)) * 3;
1899
1900         if (RANDOM & 1)
1901         {
1902           switch (temp)
1903           {
1904             /* attempt clockwise move first if direct path is blocked */
1905
1906             case 0: /* north west */
1907               if (tab_android_move[Cave[y-1][x-1]]) goto android_nw;
1908               if (tab_android_move[Cave[y-1][x]])   goto android_n;
1909               if (tab_android_move[Cave[y][x-1]])   goto android_w;
1910               break;
1911
1912             case 1: /* north */
1913               if (tab_android_move[Cave[y-1][x]])   goto android_n;
1914               if (tab_android_move[Cave[y-1][x+1]]) goto android_ne;
1915               if (tab_android_move[Cave[y-1][x-1]]) goto android_nw;
1916               break;
1917
1918             case 2: /* north east */
1919               if (tab_android_move[Cave[y-1][x+1]]) goto android_ne;
1920               if (tab_android_move[Cave[y][x+1]])   goto android_e;
1921               if (tab_android_move[Cave[y-1][x]])   goto android_n;
1922               break;
1923
1924             case 3: /* west */
1925               if (tab_android_move[Cave[y][x-1]])   goto android_w;
1926               if (tab_android_move[Cave[y-1][x-1]]) goto android_nw;
1927               if (tab_android_move[Cave[y+1][x-1]]) goto android_sw;
1928               break;
1929
1930             case 4: /* nowhere */
1931               break;
1932
1933             case 5: /* east */
1934               if (tab_android_move[Cave[y][x+1]])   goto android_e;
1935               if (tab_android_move[Cave[y+1][x+1]]) goto android_se;
1936               if (tab_android_move[Cave[y-1][x+1]]) goto android_ne;
1937               break;
1938
1939             case 6: /* south west */
1940               if (tab_android_move[Cave[y+1][x-1]]) goto android_sw;
1941               if (tab_android_move[Cave[y][x-1]])   goto android_w;
1942               if (tab_android_move[Cave[y+1][x]])   goto android_s;
1943               break;
1944
1945             case 7: /* south */
1946               if (tab_android_move[Cave[y+1][x]])   goto android_s;
1947               if (tab_android_move[Cave[y+1][x-1]]) goto android_sw;
1948               if (tab_android_move[Cave[y+1][x+1]]) goto android_se;
1949               break;
1950
1951             case 8: /* south east */
1952               if (tab_android_move[Cave[y+1][x+1]]) goto android_se;
1953               if (tab_android_move[Cave[y+1][x]])   goto android_s;
1954               if (tab_android_move[Cave[y][x+1]])   goto android_e;
1955               break;
1956           }
1957         }
1958         else
1959         {
1960           switch (temp)
1961           {
1962             /* attempt counterclockwise move first if direct path is blocked */
1963
1964             case 0: /* north west */
1965               if (tab_android_move[Cave[y-1][x-1]]) goto android_nw;
1966               if (tab_android_move[Cave[y][x-1]])   goto android_w;
1967               if (tab_android_move[Cave[y-1][x]])   goto android_n;
1968               break;
1969
1970             case 1: /* north */
1971               if (tab_android_move[Cave[y-1][x]])   goto android_n;
1972               if (tab_android_move[Cave[y-1][x-1]]) goto android_nw;
1973               if (tab_android_move[Cave[y-1][x+1]]) goto android_ne;
1974               break;
1975
1976             case 2: /* north east */
1977               if (tab_android_move[Cave[y-1][x+1]]) goto android_ne;
1978               if (tab_android_move[Cave[y-1][x]])   goto android_n;
1979               if (tab_android_move[Cave[y][x+1]])   goto android_e;
1980               break;
1981
1982             case 3: /* west */
1983               if (tab_android_move[Cave[y][x-1]])   goto android_w;
1984               if (tab_android_move[Cave[y+1][x-1]]) goto android_sw;
1985               if (tab_android_move[Cave[y-1][x-1]]) goto android_nw;
1986               break;
1987
1988             case 4: /* nowhere */
1989               break;
1990
1991             case 5: /* east */
1992               if (tab_android_move[Cave[y][x+1]])   goto android_e;
1993               if (tab_android_move[Cave[y-1][x+1]]) goto android_ne;
1994               if (tab_android_move[Cave[y+1][x+1]]) goto android_se;
1995               break;
1996
1997             case 6: /* south west */
1998               if (tab_android_move[Cave[y+1][x-1]]) goto android_sw;
1999               if (tab_android_move[Cave[y+1][x]])   goto android_s;
2000               if (tab_android_move[Cave[y][x-1]])   goto android_w;
2001               break;
2002
2003             case 7: /* south */
2004               if (tab_android_move[Cave[y+1][x]])   goto android_s;
2005               if (tab_android_move[Cave[y+1][x+1]]) goto android_se;
2006               if (tab_android_move[Cave[y+1][x-1]]) goto android_sw;
2007               break;
2008
2009             case 8: /* south east */
2010               if (tab_android_move[Cave[y+1][x+1]]) goto android_se;
2011               if (tab_android_move[Cave[y][x+1]])   goto android_e;
2012               if (tab_android_move[Cave[y+1][x]])   goto android_s;
2013               break;
2014           }
2015         }
2016       }
2017
2018     android_still:
2019
2020       Next[y][x] = Xandroid;
2021       goto loop;
2022
2023     android_n:
2024
2025       Cave[y][x] = Yandroid_nB;
2026       Cave[y-1][x] = Yandroid_n;
2027       Next[y-1][x] = Xandroid;
2028       play_element_sound(x, y, SOUND_android_move, element);
2029       goto loop;
2030
2031     android_ne:
2032
2033       Cave[y][x] = Yandroid_neB;
2034       Cave[y-1][x+1] = Yandroid_ne;
2035       Next[y-1][x+1] = Xandroid;
2036       play_element_sound(x, y, SOUND_android_move, element);
2037       goto loop;
2038
2039     android_e:
2040
2041       Cave[y][x] = Yandroid_eB;
2042       Cave[y][x+1] = Yandroid_e;
2043       Next[y][x+1] = Xandroid;
2044       play_element_sound(x, y, SOUND_android_move, element);
2045       goto loop;
2046
2047     android_se:
2048
2049       Cave[y][x] = Yandroid_seB;
2050       Cave[y+1][x+1] = Yandroid_se;
2051       Next[y+1][x+1] = Xandroid;
2052       play_element_sound(x, y, SOUND_android_move, element);
2053       goto loop;
2054
2055     android_s:
2056
2057       Cave[y][x] = Yandroid_sB;
2058       Cave[y+1][x] = Yandroid_s;
2059       Next[y+1][x] = Xandroid;
2060       play_element_sound(x, y, SOUND_android_move, element);
2061       goto loop;
2062
2063     android_sw:
2064
2065       Cave[y][x] = Yandroid_swB;
2066       Cave[y+1][x-1] = Yandroid_sw;
2067       Next[y+1][x-1] = Xandroid;
2068       play_element_sound(x, y, SOUND_android_move, element);
2069       goto loop;
2070
2071     android_w:
2072
2073       Cave[y][x] = Yandroid_wB;
2074       Cave[y][x-1] = Yandroid_w;
2075       Next[y][x-1] = Xandroid;
2076       play_element_sound(x, y, SOUND_android_move, element);
2077       goto loop;
2078
2079     android_nw:
2080
2081       Cave[y][x] = Yandroid_nwB;
2082       Cave[y-1][x-1] = Yandroid_nw;
2083       Next[y-1][x-1] = Xandroid;
2084       play_element_sound(x, y, SOUND_android_move, element);
2085       goto loop;
2086
2087     /* --------------------------------------------------------------------- */
2088
2089     case Xandroid_1_n:
2090       switch (Cave[y-1][x])
2091       {
2092         case Xacid_1:
2093         case Xacid_2:
2094         case Xacid_3:
2095         case Xacid_4:
2096         case Xacid_5:
2097         case Xacid_6:
2098         case Xacid_7:
2099         case Xacid_8:
2100           Cave[y][x] = Yandroid_nB;
2101           if (Cave[y-2][x+1] == Xblank)
2102             Cave[y-2][x+1] = Xacid_splash_e;
2103           if (Cave[y-2][x-1] == Xblank)
2104             Cave[y-2][x-1] = Xacid_splash_w;
2105           Next[y][x] = Xblank;
2106           play_element_sound(x, y, SOUND_acid, Xacid_1);
2107           goto loop;
2108
2109         case Xblank:
2110         case Xacid_splash_e:
2111         case Xacid_splash_w:
2112           Cave[y][x] = Yandroid_nB;
2113           Cave[y-1][x] = Yandroid_n;
2114           Next[y][x] = Xblank;
2115           Next[y-1][x] = Xandroid;
2116           play_element_sound(x, y, SOUND_android_move, element);
2117           goto loop;
2118
2119         default:
2120           goto android;
2121       }
2122
2123     case Xandroid_2_n:
2124       switch (Cave[y-1][x])
2125       {
2126         case Xacid_1:
2127         case Xacid_2:
2128         case Xacid_3:
2129         case Xacid_4:
2130         case Xacid_5:
2131         case Xacid_6:
2132         case Xacid_7:
2133         case Xacid_8:
2134           Cave[y][x] = Yandroid_nB;
2135           if (Cave[y-2][x+1] == Xblank)
2136             Cave[y-2][x+1] = Xacid_splash_e;
2137           if (Cave[y-2][x-1] == Xblank)
2138             Cave[y-2][x-1] = Xacid_splash_w;
2139           Next[y][x] = Xblank;
2140           play_element_sound(x, y, SOUND_acid, Xacid_1);
2141           goto loop;
2142
2143         case Xblank:
2144         case Xacid_splash_e:
2145         case Xacid_splash_w:
2146           Cave[y][x] = Yandroid_nB;
2147           Cave[y-1][x] = Yandroid_n;
2148           Next[y][x] = Xblank;
2149           Next[y-1][x] = Xandroid_1_n;
2150           play_element_sound(x, y, SOUND_android_move, element);
2151           goto loop;
2152
2153         default:
2154           goto android;
2155       }
2156
2157     /* --------------------------------------------------------------------- */
2158
2159     case Xandroid_1_e:
2160       switch (Cave[y][x+1])
2161       {
2162         case Xacid_1:
2163         case Xacid_2:
2164         case Xacid_3:
2165         case Xacid_4:
2166         case Xacid_5:
2167         case Xacid_6:
2168         case Xacid_7:
2169         case Xacid_8:
2170           Cave[y][x] = Yandroid_eB;
2171           if (Cave[y-1][x+2] == Xblank)
2172             Cave[y-1][x+2] = Xacid_splash_e;
2173           if (Cave[y-1][x] == Xblank)
2174             Cave[y-1][x] = Xacid_splash_w;
2175           Next[y][x] = Xblank;
2176           play_element_sound(x, y, SOUND_acid, Xacid_1);
2177           goto loop;
2178
2179         case Xblank:
2180         case Xacid_splash_e:
2181         case Xacid_splash_w:
2182           Cave[y][x] = Yandroid_eB;
2183           Cave[y][x+1] = Yandroid_e;
2184           Next[y][x] = Xblank;
2185           Next[y][x+1] = Xandroid;
2186           play_element_sound(x, y, SOUND_android_move, element);
2187           goto loop;
2188
2189         default:
2190           goto android;
2191       }
2192
2193     case Xandroid_2_e:
2194       switch (Cave[y][x+1])
2195       {
2196         case Xacid_1:
2197         case Xacid_2:
2198         case Xacid_3:
2199         case Xacid_4:
2200         case Xacid_5:
2201         case Xacid_6:
2202         case Xacid_7:
2203         case Xacid_8:
2204           Cave[y][x] = Yandroid_eB;
2205           if (Cave[y-1][x+2] == Xblank)
2206             Cave[y-1][x+2] = Xacid_splash_e;
2207           if (Cave[y-1][x] == Xblank)
2208             Cave[y-1][x] = Xacid_splash_w;
2209           Next[y][x] = Xblank;
2210           play_element_sound(x, y, SOUND_acid, Xacid_1);
2211           goto loop;
2212
2213         case Xblank:
2214         case Xacid_splash_e:
2215         case Xacid_splash_w:
2216           Cave[y][x] = Yandroid_eB;
2217           Cave[y][x+1] = Yandroid_e;
2218           Next[y][x] = Xblank;
2219           Next[y][x+1] = Xandroid_1_e;
2220           play_element_sound(x, y, SOUND_android_move, element);
2221           goto loop;
2222
2223         default:
2224           goto android;
2225       }
2226
2227     /* --------------------------------------------------------------------- */
2228
2229     case Xandroid_1_s:
2230       switch (Cave[y+1][x])
2231       {
2232         case Xacid_1:
2233         case Xacid_2:
2234         case Xacid_3:
2235         case Xacid_4:
2236         case Xacid_5:
2237         case Xacid_6:
2238         case Xacid_7:
2239         case Xacid_8:
2240           Cave[y][x] = Yandroid_sB;
2241           if (Cave[y][x+1] == Xblank)
2242             Cave[y][x+1] = Xacid_splash_e;
2243           if (Cave[y][x-1] == Xblank)
2244             Cave[y][x-1] = Xacid_splash_w;
2245           Next[y][x] = Xblank;
2246           play_element_sound(x, y, SOUND_acid, Xacid_1);
2247           goto loop;
2248
2249         case Xblank:
2250         case Xacid_splash_e:
2251         case Xacid_splash_w:
2252           Cave[y][x] = Yandroid_sB;
2253           Cave[y+1][x] = Yandroid_s;
2254           Next[y][x] = Xblank;
2255           Next[y+1][x] = Xandroid;
2256           play_element_sound(x, y, SOUND_android_move, element);
2257           goto loop;
2258
2259         default:
2260           goto android;
2261       }
2262
2263     case Xandroid_2_s:
2264       switch (Cave[y+1][x])
2265       {
2266         case Xacid_1:
2267         case Xacid_2:
2268         case Xacid_3:
2269         case Xacid_4:
2270         case Xacid_5:
2271         case Xacid_6:
2272         case Xacid_7:
2273         case Xacid_8:
2274           Cave[y][x] = Yandroid_sB;
2275           if (Cave[y][x+1] == Xblank)
2276             Cave[y][x+1] = Xacid_splash_e;
2277           if (Cave[y][x-1] == Xblank)
2278             Cave[y][x-1] = Xacid_splash_w;
2279           Next[y][x] = Xblank;
2280           play_element_sound(x, y, SOUND_acid, Xacid_1);
2281           goto loop;
2282
2283         case Xblank:
2284         case Xacid_splash_e:
2285         case Xacid_splash_w:
2286           Cave[y][x] = Yandroid_sB;
2287           Cave[y+1][x] = Yandroid_s;
2288           Next[y][x] = Xblank;
2289           Next[y+1][x] = Xandroid_1_s;
2290           play_element_sound(x, y, SOUND_android_move, element);
2291           goto loop;
2292
2293         default:
2294           goto android;
2295       }
2296
2297     /* --------------------------------------------------------------------- */
2298
2299     case Xandroid_1_w:
2300       switch (Cave[y][x-1])
2301       {
2302         case Xacid_1:
2303         case Xacid_2:
2304         case Xacid_3:
2305         case Xacid_4:
2306         case Xacid_5:
2307         case Xacid_6:
2308         case Xacid_7:
2309         case Xacid_8:
2310           Cave[y][x] = Yandroid_wB;
2311           if (Cave[y-1][x] == Xblank)
2312             Cave[y-1][x] = Xacid_splash_e;
2313           if (Cave[y-1][x-2] == Xblank)
2314             Cave[y-1][x-2] = Xacid_splash_w;
2315           Next[y][x] = Xblank;
2316           play_element_sound(x, y, SOUND_acid, Xacid_1);
2317           goto loop;
2318
2319         case Xblank:
2320         case Xacid_splash_e:
2321         case Xacid_splash_w:
2322           Cave[y][x] = Yandroid_wB;
2323           Cave[y][x-1] = Yandroid_w;
2324           Next[y][x] = Xblank;
2325           Next[y][x-1] = Xandroid;
2326           play_element_sound(x, y, SOUND_android_move, element);
2327           goto loop;
2328
2329         default:
2330           goto android;
2331       }
2332
2333     case Xandroid_2_w:
2334       switch (Cave[y][x-1])
2335       {
2336         case Xacid_1:
2337         case Xacid_2:
2338         case Xacid_3:
2339         case Xacid_4:
2340         case Xacid_5:
2341         case Xacid_6:
2342         case Xacid_7:
2343         case Xacid_8:
2344           Cave[y][x] = Yandroid_wB;
2345           if (Cave[y-1][x] == Xblank)
2346             Cave[y-1][x] = Xacid_splash_e;
2347           if (Cave[y-1][x-2] == Xblank)
2348             Cave[y-1][x-2] = Xacid_splash_w;
2349           Next[y][x] = Xblank;
2350           play_element_sound(x, y, SOUND_acid, Xacid_1);
2351           goto loop;
2352
2353         case Xblank:
2354         case Xacid_splash_e:
2355         case Xacid_splash_w:
2356           Cave[y][x] = Yandroid_wB;
2357           Cave[y][x-1] = Yandroid_w;
2358           Next[y][x] = Xblank;
2359           Next[y][x-1] = Xandroid_1_w;
2360           play_element_sound(x, y, SOUND_android_move, element);
2361           goto loop;
2362
2363         default:
2364           goto android;
2365       }
2366
2367     /* --------------------------------------------------------------------- */
2368
2369     case Xspring:
2370       switch (Cave[y+1][x])
2371       {
2372         case Xacid_1:
2373         case Xacid_2:
2374         case Xacid_3:
2375         case Xacid_4:
2376         case Xacid_5:
2377         case Xacid_6:
2378         case Xacid_7:
2379         case Xacid_8:
2380           Cave[y][x] = Yspring_sB;
2381           if (Cave[y][x+1] == Xblank)
2382             Cave[y][x+1] = Xacid_splash_e;
2383           if (Cave[y][x-1] == Xblank)
2384             Cave[y][x-1] = Xacid_splash_w;
2385           Next[y][x] = Xblank;
2386           play_element_sound(x, y, SOUND_acid, Xacid_1);
2387           goto loop;
2388
2389         case Xblank:
2390         case Xacid_splash_e:
2391         case Xacid_splash_w:
2392         case Xplant:
2393         case Yplant:
2394           Cave[y][x] = Yspring_sB;
2395           Cave[y+1][x] = Yspring_s;
2396           Next[y][x] = Xblank;
2397           Next[y+1][x] = Xspring_fall;
2398           goto loop;
2399
2400         case Xspring:
2401         case Xspring_pause:
2402         case Xspring_e:
2403         case Xspring_w:
2404         case Xandroid:
2405         case Xandroid_1_n:
2406         case Xandroid_2_n:
2407         case Xandroid_1_e:
2408         case Xandroid_2_e:
2409         case Xandroid_1_s:
2410         case Xandroid_2_s:
2411         case Xandroid_1_w:
2412         case Xandroid_2_w:
2413         case Xstone:
2414         case Xstone_pause:
2415         case Xemerald:
2416         case Xemerald_pause:
2417         case Xdiamond:
2418         case Xdiamond_pause:
2419         case Xbomb:
2420         case Xbomb_pause:
2421         case Xballoon:
2422         case Xacid_ne:
2423         case Xacid_nw:
2424         case Xball_1:
2425         case Xball_2:
2426         case Xnut:
2427         case Xnut_pause:
2428         case Xslidewall_ns:
2429         case Xslidewall_ew:
2430         case Xkey_1:
2431         case Xkey_2:
2432         case Xkey_3:
2433         case Xkey_4:
2434         case Xkey_5:
2435         case Xkey_6:
2436         case Xkey_7:
2437         case Xkey_8:
2438         case Xbumper:
2439         case Xswitch:
2440         case Xroundwall_1:
2441         case Xroundwall_2:
2442         case Xroundwall_3:
2443         case Xroundwall_4:
2444           if (RANDOM & 1)
2445           {
2446             if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
2447             {
2448               Cave[y][x] = Yspring_eB;
2449               Cave[y][x+1] = Yspring_e;
2450               if (Cave[y+1][x] == Xbumper)
2451                 Cave[y+1][x] = XbumperB;
2452               Next[y][x] = Xblank;
2453
2454 #ifdef SPRING_ROLL
2455               Next[y][x+1] = Xspring_e;
2456 #else   
2457               Next[y][x+1] = Xspring_pause;
2458 #endif
2459
2460               goto loop;
2461             }
2462
2463             if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
2464             {
2465               Cave[y][x] = Yspring_wB;
2466               Cave[y][x-1] = Yspring_w;
2467               if (Cave[y+1][x] == Xbumper)
2468                 Cave[y+1][x] = XbumperB;
2469               Next[y][x] = Xblank;
2470
2471 #ifdef SPRING_ROLL
2472               Next[y][x-1] = Xspring_w;
2473 #else
2474               Next[y][x-1] = Xspring_pause;
2475 #endif
2476
2477               goto loop;
2478             }
2479           }
2480           else
2481           {
2482             if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
2483             {
2484               Cave[y][x] = Yspring_wB;
2485               Cave[y][x-1] = Yspring_w;
2486               if (Cave[y+1][x] == Xbumper)
2487                 Cave[y+1][x] = XbumperB;
2488               Next[y][x] = Xblank;
2489
2490 #ifdef SPRING_ROLL
2491               Next[y][x-1] = Xspring_w;
2492 #else
2493               Next[y][x-1] = Xspring_pause;
2494 #endif
2495
2496               goto loop;
2497             }
2498
2499             if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
2500             {
2501               Cave[y][x] = Yspring_eB;
2502               Cave[y][x+1] = Yspring_e;
2503               if (Cave[y+1][x] == Xbumper)
2504                 Cave[y+1][x] = XbumperB;
2505               Next[y][x] = Xblank;
2506
2507 #ifdef SPRING_ROLL
2508               Next[y][x+1] = Xspring_e;
2509 #else
2510               Next[y][x+1] = Xspring_pause;
2511 #endif
2512
2513               goto loop;
2514             }
2515           }
2516
2517         default:
2518           goto loop;
2519       }
2520
2521     /* --------------------------------------------------------------------- */
2522
2523     case Xspring_pause:
2524       switch (Cave[y+1][x])
2525       {
2526         case Xacid_1:
2527         case Xacid_2:
2528         case Xacid_3:
2529         case Xacid_4:
2530         case Xacid_5:
2531         case Xacid_6:
2532         case Xacid_7:
2533         case Xacid_8:
2534           Cave[y][x] = Yspring_sB;
2535           if (Cave[y][x+1] == Xblank)
2536             Cave[y][x+1] = Xacid_splash_e;
2537           if (Cave[y][x-1] == Xblank)
2538             Cave[y][x-1] = Xacid_splash_w;
2539           Next[y][x] = Xblank;
2540           play_element_sound(x, y, SOUND_acid, Xacid_1);
2541           goto loop;
2542
2543         case Xblank:
2544         case Xacid_splash_e:
2545         case Xacid_splash_w:
2546           Cave[y][x] = Yspring_sB;
2547           Cave[y+1][x] = Yspring_s;
2548           Next[y][x] = Xblank;
2549           Next[y+1][x] = Xspring_fall;
2550           goto loop;
2551
2552         default:
2553           Cave[y][x] = Xspring;
2554           Next[y][x] = Xspring;
2555           goto loop;
2556       }
2557
2558     /* --------------------------------------------------------------------- */
2559
2560     case Xspring_e:
2561       switch (Cave[y+1][x])
2562       {
2563         case Xacid_1:
2564         case Xacid_2:
2565         case Xacid_3:
2566         case Xacid_4:
2567         case Xacid_5:
2568         case Xacid_6:
2569         case Xacid_7:
2570         case Xacid_8:
2571           Cave[y][x] = Yspring_sB;
2572           if (Cave[y][x+1] == Xblank)
2573             Cave[y][x+1] = Xacid_splash_e;
2574           if (Cave[y][x-1] == Xblank)
2575             Cave[y][x-1] = Xacid_splash_w;
2576           Next[y][x] = Xblank;
2577           play_element_sound(x, y, SOUND_acid, Xacid_1);
2578           goto loop;
2579
2580         case Xblank:
2581         case Xacid_splash_e:
2582         case Xacid_splash_w:
2583           Cave[y][x] = Yspring_sB;
2584           Cave[y+1][x] = Yspring_s;
2585           Next[y][x] = Xblank;
2586           Next[y+1][x] = Xspring_fall;
2587           goto loop;
2588
2589         case Xbumper:
2590           Cave[y+1][x] = XbumperB;
2591       }
2592
2593       switch (Cave[y][x+1])
2594       {
2595         case Xacid_1:
2596         case Xacid_2:
2597         case Xacid_3:
2598         case Xacid_4:
2599         case Xacid_5:
2600         case Xacid_6:
2601         case Xacid_7:
2602         case Xacid_8:
2603           Cave[y][x] = Yspring_eB;
2604           if (Cave[y-1][x+2] == Xblank)
2605             Cave[y-1][x+2] = Xacid_splash_e;
2606           if (Cave[y-1][x] == Xblank)
2607             Cave[y-1][x] = Xacid_splash_w;
2608           Next[y][x] = Xblank;
2609           play_element_sound(x, y, SOUND_acid, Xacid_1);
2610           goto loop;
2611
2612         case Xblank:
2613         case Xacid_splash_e:
2614         case Xacid_splash_w:
2615         case Yalien_nB:
2616         case Yalien_eB:
2617         case Yalien_sB:
2618         case Yalien_wB:
2619           Cave[y][x] = Yspring_eB;
2620           Cave[y][x+1] = Yspring_e;
2621           Next[y][x] = Xblank;
2622           Next[y][x+1] = Xspring_e;
2623           goto loop;
2624
2625         case Xalien:
2626         case Xalien_pause:
2627         case Yalien_n:
2628         case Yalien_e:
2629         case Yalien_s:
2630         case Yalien_w:
2631           Cave[y][x] = Yspring_alien_eB;
2632           Cave[y][x+1] = Yspring_alien_e;
2633           Next[y][x] = Xblank;
2634           Next[y][x+1] = Xspring_e;
2635           play_element_sound(x, y, SOUND_slurp, Xalien);
2636           score += lev.slurp_score;
2637           goto loop;
2638
2639         case Xbumper:
2640         case XbumperB:
2641           Cave[y][x+1] = XbumperB;
2642           Next[y][x] = Xspring_w;
2643           play_element_sound(x, y, SOUND_spring, Xspring);
2644           goto loop;
2645
2646         default:
2647           Cave[y][x] = Xspring;
2648           Next[y][x] = Xspring;
2649           play_element_sound(x, y, SOUND_spring, Xspring);
2650           goto loop;
2651       }
2652
2653     /* --------------------------------------------------------------------- */
2654
2655     case Xspring_w:
2656       switch (Cave[y+1][x])
2657       {
2658         case Xacid_1:
2659         case Xacid_2:
2660         case Xacid_3:
2661         case Xacid_4:
2662         case Xacid_5:
2663         case Xacid_6:
2664         case Xacid_7:
2665         case Xacid_8:
2666           Cave[y][x] = Yspring_sB;
2667           if (Cave[y][x+1] == Xblank)
2668             Cave[y][x+1] = Xacid_splash_e;
2669           if (Cave[y][x-1] == Xblank)
2670             Cave[y][x-1] = Xacid_splash_w;
2671           Next[y][x] = Xblank;
2672           play_element_sound(x, y, SOUND_acid, Xacid_1);
2673           goto loop;
2674
2675         case Xblank:
2676         case Xacid_splash_e:
2677         case Xacid_splash_w:
2678           Cave[y][x] = Yspring_sB;
2679           Cave[y+1][x] = Yspring_s;
2680           Next[y][x] = Xblank;
2681           Next[y+1][x] = Xspring_fall;
2682           goto loop;
2683
2684         case Xbumper:
2685           Cave[y+1][x] = XbumperB;
2686       }
2687
2688       switch (Cave[y][x-1])
2689       {
2690         case Xacid_1:
2691         case Xacid_2:
2692         case Xacid_3:
2693         case Xacid_4:
2694         case Xacid_5:
2695         case Xacid_6:
2696         case Xacid_7:
2697         case Xacid_8:
2698           Cave[y][x] = Yspring_wB;
2699           if (Cave[y-1][x] == Xblank)
2700             Cave[y-1][x] = Xacid_splash_e;
2701           if (Cave[y-1][x-2] == Xblank)
2702             Cave[y-1][x-2] = Xacid_splash_w;
2703           Next[y][x] = Xblank;
2704           play_element_sound(x, y, SOUND_acid, Xacid_1);
2705           goto loop;
2706
2707         case Xblank:
2708         case Xacid_splash_e:
2709         case Xacid_splash_w:
2710         case Yalien_nB:
2711         case Yalien_eB:
2712         case Yalien_sB:
2713         case Yalien_wB:
2714           Cave[y][x] = Yspring_wB;
2715           Cave[y][x-1] = Yspring_w;
2716           Next[y][x] = Xblank;
2717           Next[y][x-1] = Xspring_w;
2718           goto loop;
2719
2720         case Xalien:
2721         case Xalien_pause:
2722         case Yalien_n:
2723         case Yalien_e:
2724         case Yalien_s:
2725         case Yalien_w:
2726           Cave[y][x] = Yspring_alien_wB;
2727           Cave[y][x-1] = Yspring_alien_w;
2728           Next[y][x] = Xblank;
2729           Next[y][x-1] = Xspring_w;
2730           play_element_sound(x, y, SOUND_slurp, Xalien);
2731           score += lev.slurp_score;
2732           goto loop;
2733
2734         case Xbumper:
2735         case XbumperB:
2736           Cave[y][x-1] = XbumperB;
2737           Next[y][x] = Xspring_e;
2738           play_element_sound(x, y, SOUND_spring, Xspring);
2739           goto loop;
2740
2741         default:
2742           Cave[y][x] = Xspring;
2743           Next[y][x] = Xspring;
2744           play_element_sound(x, y, SOUND_spring, Xspring);
2745           goto loop;
2746       }
2747
2748     /* --------------------------------------------------------------------- */
2749
2750     case Xspring_fall:
2751       switch (Cave[y+1][x])
2752       {
2753         case Xacid_1:
2754         case Xacid_2:
2755         case Xacid_3:
2756         case Xacid_4:
2757         case Xacid_5:
2758         case Xacid_6:
2759         case Xacid_7:
2760         case Xacid_8:
2761           Cave[y][x] = Yspring_sB;
2762           if (Cave[y][x+1] == Xblank)
2763             Cave[y][x+1] = Xacid_splash_e;
2764           if (Cave[y][x-1] == Xblank)
2765             Cave[y][x-1] = Xacid_splash_w;
2766           Next[y][x] = Xblank;
2767           play_element_sound(x, y, SOUND_acid, Xacid_1);
2768           goto loop;
2769
2770         case Xblank:
2771         case Xacid_splash_e:
2772         case Xacid_splash_w:
2773         case Zplayer:
2774           Cave[y][x] = Yspring_sB;
2775           Cave[y+1][x] = Yspring_s;
2776           Next[y][x] = Xblank;
2777           Next[y+1][x] = Xspring_fall;
2778           goto loop;
2779
2780         case Xbomb:
2781         case Xbomb_pause:
2782           Cave[y+1][x] = Ybomb_blank;
2783           Next[y+1][x] = Znormal;
2784           Boom[y][x-1] = Xblank;
2785           Boom[y][x] = Xblank;
2786           Boom[y][x+1] = Xblank;
2787           Boom[y+1][x-1] = Xblank;
2788           Boom[y+1][x] = Xblank;
2789           Boom[y+1][x+1] = Xblank;
2790           Boom[y+2][x-1] = Xblank;
2791           Boom[y+2][x] = Xblank;
2792           Boom[y+2][x+1] = Xblank;
2793 #if PLAY_ELEMENT_SOUND
2794           play_element_sound(x, y, SOUND_boom, element);
2795 #endif
2796           goto loop;
2797
2798         case Xbug_1_n:
2799         case Xbug_1_e:
2800         case Xbug_1_s:
2801         case Xbug_1_w:
2802         case Xbug_2_n:
2803         case Xbug_2_e:
2804         case Xbug_2_s:
2805         case Xbug_2_w:
2806           Cave[y][x] = Yspring_sB;
2807           Cave[y+1][x] = Ybug_spring;
2808           Next[y+1][x] = Znormal;
2809           Boom[y][x-1] = Xemerald;
2810           Boom[y][x] = Xemerald;
2811           Boom[y][x+1] = Xemerald;
2812           Boom[y+1][x-1] = Xemerald;
2813           Boom[y+1][x] = Xdiamond;
2814           Boom[y+1][x+1] = Xemerald;
2815           Boom[y+2][x-1] = Xemerald;
2816           Boom[y+2][x] = Xemerald;
2817           Boom[y+2][x+1] = Xemerald;
2818 #if PLAY_ELEMENT_SOUND
2819           play_element_sound(x, y, SOUND_boom, element);
2820 #endif
2821           score += lev.bug_score;
2822           goto loop;
2823
2824         case Xtank_1_n:
2825         case Xtank_1_e:
2826         case Xtank_1_s:
2827         case Xtank_1_w:
2828         case Xtank_2_n:
2829         case Xtank_2_e:
2830         case Xtank_2_s:
2831         case Xtank_2_w:
2832           Cave[y][x] = Yspring_sB;
2833           Cave[y+1][x] = Ytank_spring;
2834           Next[y+1][x] = Znormal;
2835           Boom[y][x-1] = Xblank;
2836           Boom[y][x] = Xblank;
2837           Boom[y][x+1] = Xblank;
2838           Boom[y+1][x-1] = Xblank;
2839           Boom[y+1][x] = Xblank;
2840           Boom[y+1][x+1] = Xblank;
2841           Boom[y+2][x-1] = Xblank;
2842           Boom[y+2][x] = Xblank;
2843           Boom[y+2][x+1] = Xblank;
2844 #if PLAY_ELEMENT_SOUND
2845           play_element_sound(x, y, SOUND_boom, element);
2846 #endif
2847           score += lev.tank_score;
2848           goto loop;
2849
2850         case Xeater_n:
2851         case Xeater_e:
2852         case Xeater_s:
2853         case Xeater_w:
2854           Cave[y][x] = Yspring_sB;
2855           Cave[y+1][x] = Yeater_spring;
2856           Next[y+1][x] = Znormal;
2857           Boom[y][x-1] = lev.eater_array[lev.eater_pos][0];
2858           Boom[y][x] = lev.eater_array[lev.eater_pos][1];
2859           Boom[y][x+1] = lev.eater_array[lev.eater_pos][2];
2860           Boom[y+1][x-1] = lev.eater_array[lev.eater_pos][3];
2861           Boom[y+1][x] = lev.eater_array[lev.eater_pos][4];
2862           Boom[y+1][x+1] = lev.eater_array[lev.eater_pos][5];
2863           Boom[y+2][x-1] = lev.eater_array[lev.eater_pos][6];
2864           Boom[y+2][x] = lev.eater_array[lev.eater_pos][7];
2865           Boom[y+2][x+1] = lev.eater_array[lev.eater_pos][8];
2866 #if PLAY_ELEMENT_SOUND
2867           play_element_sound(x, y, SOUND_boom, element);
2868 #endif
2869           lev.eater_pos = (lev.eater_pos + 1) & 7;
2870           score += lev.eater_score;
2871           goto loop;
2872
2873         case Xalien:
2874         case Xalien_pause:
2875           Cave[y][x] = Yspring_sB;
2876           Cave[y+1][x] = Yalien_spring;
2877           Next[y+1][x] = Znormal;
2878           Boom[y][x-1] = Xblank;
2879           Boom[y][x] = Xblank;
2880           Boom[y][x+1] = Xblank;
2881           Boom[y+1][x-1] = Xblank;
2882           Boom[y+1][x] = Xblank;
2883           Boom[y+1][x+1] = Xblank;
2884           Boom[y+2][x-1] = Xblank;
2885           Boom[y+2][x] = Xblank;
2886           Boom[y+2][x+1] = Xblank;
2887 #if PLAY_ELEMENT_SOUND
2888           play_element_sound(x, y, SOUND_boom, element);
2889 #endif
2890           score += lev.alien_score;
2891           goto loop;
2892
2893         default:
2894           Cave[y][x] = Xspring;
2895           Next[y][x] = Xspring;
2896           play_element_sound(x, y, SOUND_spring, Xspring);
2897           goto loop;
2898       }
2899
2900     /* --------------------------------------------------------------------- */
2901
2902     case Xeater_n:
2903       if (Cave[y][x+1] == Xdiamond)
2904       {
2905         Cave[y][x+1] = Ydiamond_blank;
2906         Next[y][x+1] = Xblank;
2907         play_element_sound(x, y, SOUND_eater_eat, element);
2908         goto loop;
2909       }
2910
2911       if (Cave[y+1][x] == Xdiamond)
2912       {
2913         Cave[y+1][x] = Ydiamond_blank;
2914         Next[y+1][x] = Xblank;
2915         play_element_sound(x, y, SOUND_eater_eat, element);
2916         goto loop;
2917       }
2918
2919       if (Cave[y][x-1] == Xdiamond)
2920       {
2921         Cave[y][x-1] = Ydiamond_blank;
2922         Next[y][x-1] = Xblank;
2923         play_element_sound(x, y, SOUND_eater_eat, element);
2924         goto loop;
2925       }
2926
2927       if (Cave[y-1][x] == Xdiamond)
2928       {
2929         Cave[y-1][x] = Ydiamond_blank;
2930         Next[y-1][x] = Xblank;
2931         play_element_sound(x, y, SOUND_eater_eat, element);
2932         goto loop;
2933       }
2934
2935       switch (Cave[y-1][x])
2936       {
2937         case Xacid_1:
2938         case Xacid_2:
2939         case Xacid_3:
2940         case Xacid_4:
2941         case Xacid_5:
2942         case Xacid_6:
2943         case Xacid_7:
2944         case Xacid_8:
2945           Cave[y][x] = Yeater_nB;
2946           if (Cave[y-2][x+1] == Xblank)
2947             Cave[y-2][x+1] = Xacid_splash_e;
2948           if (Cave[y-2][x-1] == Xblank)
2949             Cave[y-2][x-1] = Xacid_splash_w;
2950           Next[y][x] = Xblank;
2951           play_element_sound(x, y, SOUND_acid, Xacid_1);
2952           goto loop;
2953
2954         case Xblank:
2955         case Xacid_splash_e:
2956         case Xacid_splash_w:
2957         case Xplant:
2958         case Yplant:
2959         case Zplayer:
2960           Cave[y][x] = Yeater_nB;
2961           Cave[y-1][x] = Yeater_n;
2962           Next[y][x] = Xblank;
2963           Next[y-1][x] = Xeater_n;
2964           goto loop;
2965
2966         default:
2967           Next[y][x] = RANDOM & 1 ? Xeater_e : Xeater_w;
2968           play_element_sound(x, y, SOUND_eater, element);
2969           goto loop;
2970       }
2971
2972     /* --------------------------------------------------------------------- */
2973
2974     case Xeater_e:
2975       if (Cave[y+1][x] == Xdiamond)
2976       {
2977         Cave[y+1][x] = Ydiamond_blank;
2978         Next[y+1][x] = Xblank;
2979         play_element_sound(x, y, SOUND_eater_eat, element);
2980         goto loop;
2981       }
2982
2983       if (Cave[y][x-1] == Xdiamond)
2984       {
2985         Cave[y][x-1] = Ydiamond_blank;
2986         Next[y][x-1] = Xblank;
2987         play_element_sound(x, y, SOUND_eater_eat, element);
2988         goto loop;
2989       }
2990
2991       if (Cave[y-1][x] == Xdiamond)
2992       {
2993         Cave[y-1][x] = Ydiamond_blank;
2994         Next[y-1][x] = Xblank;
2995         play_element_sound(x, y, SOUND_eater_eat, element);
2996         goto loop;
2997       }
2998
2999       if (Cave[y][x+1] == Xdiamond)
3000       {
3001         Cave[y][x+1] = Ydiamond_blank;
3002         Next[y][x+1] = Xblank;
3003         play_element_sound(x, y, SOUND_eater_eat, element);
3004         goto loop;
3005       }
3006
3007       switch (Cave[y][x+1])
3008       {
3009         case Xacid_1:
3010         case Xacid_2:
3011         case Xacid_3:
3012         case Xacid_4:
3013         case Xacid_5:
3014         case Xacid_6:
3015         case Xacid_7:
3016         case Xacid_8:
3017           Cave[y][x] = Yeater_eB;
3018           if (Cave[y-1][x+2] == Xblank)
3019             Cave[y-1][x+2] = Xacid_splash_e;
3020           if (Cave[y-1][x] == Xblank)
3021             Cave[y-1][x] = Xacid_splash_w;
3022           Next[y][x] = Xblank;
3023           play_element_sound(x, y, SOUND_acid, Xacid_1);
3024           goto loop;
3025
3026         case Xblank:
3027         case Xacid_splash_e:
3028         case Xacid_splash_w:
3029         case Xplant:
3030         case Yplant:
3031         case Zplayer:
3032           Cave[y][x] = Yeater_eB;
3033           Cave[y][x+1] = Yeater_e;
3034           Next[y][x] = Xblank;
3035           Next[y][x+1] = Xeater_e;
3036           goto loop;
3037
3038         default:
3039           Next[y][x] = RANDOM & 1 ? Xeater_n : Xeater_s;
3040           play_element_sound(x, y, SOUND_eater, element);
3041           goto loop;
3042       }
3043
3044     /* --------------------------------------------------------------------- */
3045
3046     case Xeater_s:
3047       if (Cave[y][x-1] == Xdiamond)
3048       {
3049         Cave[y][x-1] = Ydiamond_blank;
3050         Next[y][x-1] = Xblank;
3051         play_element_sound(x, y, SOUND_eater_eat, element);
3052         goto loop;
3053       }
3054
3055       if (Cave[y-1][x] == Xdiamond)
3056       {
3057         Cave[y-1][x] = Ydiamond_blank;
3058         Next[y-1][x] = Xblank;
3059         play_element_sound(x, y, SOUND_eater_eat, element);
3060         goto loop;
3061       }
3062
3063       if (Cave[y][x+1] == Xdiamond)
3064       {
3065         Cave[y][x+1] = Ydiamond_blank;
3066         Next[y][x+1] = Xblank;
3067         play_element_sound(x, y, SOUND_eater_eat, element);
3068         goto loop;
3069       }
3070
3071       if (Cave[y+1][x] == Xdiamond)
3072       {
3073         Cave[y+1][x] = Ydiamond_blank;
3074         Next[y+1][x] = Xblank;
3075         play_element_sound(x, y, SOUND_eater_eat, element);
3076         goto loop;
3077       }
3078
3079       switch (Cave[y+1][x])
3080       {
3081         case Xacid_1:
3082         case Xacid_2:
3083         case Xacid_3:
3084         case Xacid_4:
3085         case Xacid_5:
3086         case Xacid_6:
3087         case Xacid_7:
3088         case Xacid_8:
3089           Cave[y][x] = Yeater_sB;
3090           if (Cave[y][x+1] == Xblank)
3091             Cave[y][x+1] = Xacid_splash_e;
3092           if (Cave[y][x-1] == Xblank)
3093             Cave[y][x-1] = Xacid_splash_w;
3094           Next[y][x] = Xblank;
3095           play_element_sound(x, y, SOUND_acid, Xacid_1);
3096           goto loop;
3097
3098         case Xblank:
3099         case Xacid_splash_e:
3100         case Xacid_splash_w:
3101         case Xplant:
3102         case Yplant:
3103         case Zplayer:
3104           Cave[y][x] = Yeater_sB;
3105           Cave[y+1][x] = Yeater_s;
3106           Next[y][x] = Xblank;
3107           Next[y+1][x] = Xeater_s;
3108           goto loop;
3109
3110         default:
3111           Next[y][x] = RANDOM & 1 ? Xeater_e : Xeater_w;
3112           play_element_sound(x, y, SOUND_eater, element);
3113           goto loop;
3114       }
3115
3116     /* --------------------------------------------------------------------- */
3117
3118     case Xeater_w:
3119       if (Cave[y-1][x] == Xdiamond)
3120       {
3121         Cave[y-1][x] = Ydiamond_blank;
3122         Next[y-1][x] = Xblank;
3123         play_element_sound(x, y, SOUND_eater_eat, element);
3124         goto loop;
3125       }
3126
3127       if (Cave[y][x+1] == Xdiamond)
3128       {
3129         Cave[y][x+1] = Ydiamond_blank;
3130         Next[y][x+1] = Xblank;
3131         play_element_sound(x, y, SOUND_eater_eat, element);
3132         goto loop;
3133       }
3134
3135       if (Cave[y+1][x] == Xdiamond)
3136       {
3137         Cave[y+1][x] = Ydiamond_blank;
3138         Next[y+1][x] = Xblank;
3139         play_element_sound(x, y, SOUND_eater_eat, element);
3140         goto loop;
3141       }
3142
3143       if (Cave[y][x-1] == Xdiamond)
3144       {
3145         Cave[y][x-1] = Ydiamond_blank;
3146         Next[y][x-1] = Xblank;
3147         play_element_sound(x, y, SOUND_eater_eat, element);
3148         goto loop;
3149       }
3150
3151       switch (Cave[y][x-1])
3152       {
3153         case Xacid_1:
3154         case Xacid_2:
3155         case Xacid_3:
3156         case Xacid_4:
3157         case Xacid_5:
3158         case Xacid_6:
3159         case Xacid_7:
3160         case Xacid_8:
3161           Cave[y][x] = Yeater_wB;
3162           if (Cave[y-1][x] == Xblank)
3163             Cave[y-1][x] = Xacid_splash_e;
3164           if (Cave[y-1][x-2] == Xblank)
3165             Cave[y-1][x-2] = Xacid_splash_w;
3166           Next[y][x] = Xblank;
3167           play_element_sound(x, y, SOUND_acid, Xacid_1);
3168           goto loop;
3169
3170         case Xblank:
3171         case Xacid_splash_e:
3172         case Xacid_splash_w:
3173         case Xplant:
3174         case Yplant:
3175         case Zplayer:
3176           Cave[y][x] = Yeater_wB;
3177           Cave[y][x-1] = Yeater_w;
3178           Next[y][x] = Xblank;
3179           Next[y][x-1] = Xeater_w;
3180           goto loop;
3181
3182         default:
3183           Next[y][x] = RANDOM & 1 ? Xeater_n : Xeater_s;
3184           play_element_sound(x, y, SOUND_eater, element);
3185           goto loop;
3186       }
3187
3188     /* --------------------------------------------------------------------- */
3189
3190     case Xalien:
3191
3192       if (lev.wheel_cnt)
3193       {
3194         dx = lev.wheel_x;
3195         dy = lev.wheel_y;
3196       }
3197       else
3198       {
3199         set_nearest_player_xy(x, y, &dx, &dy);
3200       }
3201
3202       if (RANDOM & 1)
3203       {
3204         if (y > dy)
3205         {
3206           switch (Cave[y-1][x])
3207           {
3208             case Xacid_1:
3209             case Xacid_2:
3210             case Xacid_3:
3211             case Xacid_4:
3212             case Xacid_5:
3213             case Xacid_6:
3214             case Xacid_7:
3215             case Xacid_8:
3216               Cave[y][x] = Yalien_nB;
3217               if (Cave[y-2][x+1] == Xblank)
3218                 Cave[y-2][x+1] = Xacid_splash_e;
3219               if (Cave[y-2][x-1] == Xblank)
3220                 Cave[y-2][x-1] = Xacid_splash_w;
3221               Next[y][x] = Xblank;
3222               play_element_sound(x, y, SOUND_acid, Xacid_1);
3223               goto loop;
3224
3225             case Xblank:
3226             case Xacid_splash_e:
3227             case Xacid_splash_w:
3228             case Xplant:
3229             case Yplant:
3230             case Zplayer:
3231               Cave[y][x] = Yalien_nB;
3232               Cave[y-1][x] = Yalien_n;
3233               Next[y][x] = Xblank;
3234               Next[y-1][x] = Xalien_pause;
3235               play_element_sound(x, y, SOUND_alien, Xalien);
3236               goto loop;
3237           }
3238         }
3239         else if (y < dy)
3240         {
3241           switch (Cave[y+1][x])
3242           {
3243             case Xacid_1:
3244             case Xacid_2:
3245             case Xacid_3:
3246             case Xacid_4:
3247             case Xacid_5:
3248             case Xacid_6:
3249             case Xacid_7:
3250             case Xacid_8:
3251               Cave[y][x] = Yalien_sB;
3252               Next[y][x] = Xblank;
3253               if (Cave[y][x+1] == Xblank)
3254                 Cave[y][x+1] = Xacid_splash_e;
3255               if (Cave[y][x-1] == Xblank)
3256                 Cave[y][x-1] = Xacid_splash_w;
3257               play_element_sound(x, y, SOUND_acid, Xacid_1);
3258               goto loop;
3259
3260             case Xblank:
3261             case Xacid_splash_e:
3262             case Xacid_splash_w:
3263             case Xplant:
3264             case Yplant:
3265             case Zplayer:
3266               Cave[y][x] = Yalien_sB;
3267               Cave[y+1][x] = Yalien_s;
3268               Next[y][x] = Xblank;
3269               Next[y+1][x] = Xalien_pause;
3270               play_element_sound(x, y, SOUND_alien, Xalien);
3271               goto loop;
3272           }
3273         }
3274       }
3275       else
3276       {
3277         if (x < dx)
3278         {
3279           switch (Cave[y][x+1])
3280           {
3281             case Xacid_1:
3282             case Xacid_2:
3283             case Xacid_3:
3284             case Xacid_4:
3285             case Xacid_5:
3286             case Xacid_6:
3287             case Xacid_7:
3288             case Xacid_8:
3289               Cave[y][x] = Yalien_eB;
3290               if (Cave[y-1][x+2] == Xblank)
3291                 Cave[y-1][x+2] = Xacid_splash_e;
3292               if (Cave[y-1][x] == Xblank)
3293                 Cave[y-1][x] = Xacid_splash_w;
3294               Next[y][x] = Xblank;
3295               play_element_sound(x, y, SOUND_acid, Xacid_1);
3296               goto loop;
3297
3298             case Xblank:
3299             case Xacid_splash_e:
3300             case Xacid_splash_w:
3301             case Xplant:
3302             case Yplant:
3303             case Zplayer:
3304               Cave[y][x] = Yalien_eB;
3305               Cave[y][x+1] = Yalien_e;
3306               Next[y][x] = Xblank;
3307               Next[y][x+1] = Xalien_pause;
3308               play_element_sound(x, y, SOUND_alien, Xalien);
3309               goto loop;
3310           }
3311         }
3312         else if (x > dx)
3313         {
3314           switch (Cave[y][x-1])
3315           {
3316             case Xacid_1:
3317             case Xacid_2:
3318             case Xacid_3:
3319             case Xacid_4:
3320             case Xacid_5:
3321             case Xacid_6:
3322             case Xacid_7:
3323             case Xacid_8:
3324               Cave[y][x] = Yalien_wB;
3325               if (Cave[y-1][x] == Xblank)
3326                 Cave[y-1][x] = Xacid_splash_e;
3327               if (Cave[y-1][x-2] == Xblank)
3328                 Cave[y-1][x-2] = Xacid_splash_w;
3329               Next[y][x] = Xblank;
3330               play_element_sound(x, y, SOUND_acid, Xacid_1);
3331               goto loop;
3332
3333             case Xblank:
3334             case Xacid_splash_e:
3335             case Xacid_splash_w:
3336             case Xplant:
3337             case Yplant:
3338             case Zplayer:
3339               Cave[y][x] = Yalien_wB;
3340               Cave[y][x-1] = Yalien_w;
3341               Next[y][x] = Xblank;
3342               Next[y][x-1] = Xalien_pause;
3343               play_element_sound(x, y, SOUND_alien, Xalien);
3344               goto loop;
3345           }
3346         }
3347       }
3348
3349       goto loop;
3350
3351     case Xalien_pause:
3352       Next[y][x] = Xalien;
3353       goto loop;
3354
3355     /* --------------------------------------------------------------------- */
3356
3357     case Xemerald:
3358       switch (Cave[y+1][x])
3359       {
3360         case Xacid_1:
3361         case Xacid_2:
3362         case Xacid_3:
3363         case Xacid_4:
3364         case Xacid_5:
3365         case Xacid_6:
3366         case Xacid_7:
3367         case Xacid_8:
3368           Cave[y][x] = Yemerald_sB;
3369           if (Cave[y][x+1] == Xblank)
3370             Cave[y][x+1] = Xacid_splash_e;
3371           if (Cave[y][x-1] == Xblank)
3372             Cave[y][x-1] = Xacid_splash_w;
3373           Next[y][x] = Xblank;
3374           play_element_sound(x, y, SOUND_acid, Xacid_1);
3375           goto loop;
3376
3377         case Xblank:
3378         case Xacid_splash_e:
3379         case Xacid_splash_w:
3380           Cave[y][x] = Yemerald_sB;
3381           Cave[y+1][x] = Yemerald_s;
3382           Next[y][x] = Xblank;
3383           Next[y+1][x] = Xemerald_fall;
3384           goto loop;
3385
3386         case Xspring:
3387         case Xspring_pause:
3388         case Xspring_e:
3389         case Xspring_w:
3390         case Xandroid:
3391         case Xandroid_1_n:
3392         case Xandroid_2_n:
3393         case Xandroid_1_e:
3394         case Xandroid_2_e:
3395         case Xandroid_1_s:
3396         case Xandroid_2_s:
3397         case Xandroid_1_w:
3398         case Xandroid_2_w:
3399         case Xstone:
3400         case Xstone_pause:
3401         case Xemerald:
3402         case Xemerald_pause:
3403         case Xdiamond:
3404         case Xdiamond_pause:
3405         case Xbomb:
3406         case Xbomb_pause:
3407         case Xballoon:
3408         case Xacid_ne:
3409         case Xacid_nw:
3410         case Xball_1:
3411         case Xball_2:
3412         case Xnut:
3413         case Xnut_pause:
3414         case Xslidewall_ns:
3415         case Xslidewall_ew:
3416         case Xwonderwall:
3417         case Xkey_1:
3418         case Xkey_2:
3419         case Xkey_3:
3420         case Xkey_4:
3421         case Xkey_5:
3422         case Xkey_6:
3423         case Xkey_7:
3424         case Xkey_8:
3425         case Xbumper:
3426         case Xswitch:
3427         case Xsteel_1:
3428         case Xsteel_2:
3429         case Xsteel_3:
3430         case Xsteel_4:
3431         case Xwall_1:
3432         case Xwall_2:
3433         case Xwall_3:
3434         case Xwall_4:
3435         case Xroundwall_1:
3436         case Xroundwall_2:
3437         case Xroundwall_3:
3438         case Xroundwall_4:
3439           if (RANDOM & 1)
3440           {
3441             if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
3442             {
3443               Cave[y][x] = Yemerald_eB;
3444               Cave[y][x+1] = Yemerald_e;
3445               Next[y][x] = Xblank;
3446               Next[y][x+1] = Xemerald_pause;
3447               goto loop;
3448             }
3449
3450             if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
3451             {
3452               Cave[y][x] = Yemerald_wB;
3453               Cave[y][x-1] = Yemerald_w;
3454               Next[y][x] = Xblank;
3455               Next[y][x-1] = Xemerald_pause;
3456               goto loop;
3457             }
3458           }
3459           else
3460           {
3461             if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
3462             {
3463               Cave[y][x] = Yemerald_wB;
3464               Cave[y][x-1] = Yemerald_w;
3465               Next[y][x] = Xblank;
3466               Next[y][x-1] = Xemerald_pause;
3467               goto loop;
3468             }
3469
3470             if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
3471             {
3472               Cave[y][x] = Yemerald_eB;
3473               Cave[y][x+1] = Yemerald_e;
3474               Next[y][x] = Xblank;
3475               Next[y][x+1] = Xemerald_pause;
3476               goto loop;
3477             }
3478           }
3479
3480         default:
3481           if (++lev.shine_cnt > 50)
3482           {
3483             lev.shine_cnt = RANDOM & 7;
3484             Cave[y][x] = Xemerald_shine;
3485           }
3486
3487           goto loop;
3488       }
3489
3490     /* --------------------------------------------------------------------- */
3491
3492     case Xemerald_pause:
3493       switch (Cave[y+1][x])
3494       {
3495         case Xacid_1:
3496         case Xacid_2:
3497         case Xacid_3:
3498         case Xacid_4:
3499         case Xacid_5:
3500         case Xacid_6:
3501         case Xacid_7:
3502         case Xacid_8:
3503           Cave[y][x] = Yemerald_sB;
3504           if (Cave[y][x+1] == Xblank)
3505             Cave[y][x+1] = Xacid_splash_e;
3506           if (Cave[y][x-1] == Xblank)
3507             Cave[y][x-1] = Xacid_splash_w;
3508           Next[y][x] = Xblank;
3509           play_element_sound(x, y, SOUND_acid, Xacid_1);
3510           goto loop;
3511
3512         case Xblank:
3513         case Xacid_splash_e:
3514         case Xacid_splash_w:
3515           Cave[y][x] = Yemerald_sB;
3516           Cave[y+1][x] = Yemerald_s;
3517           Next[y][x] = Xblank;
3518           Next[y+1][x] = Xemerald_fall;
3519           goto loop;
3520
3521         default:
3522           Cave[y][x] = Xemerald;
3523           Next[y][x] = Xemerald;
3524           goto loop;
3525       }
3526
3527     /* --------------------------------------------------------------------- */
3528
3529     case Xemerald_fall:
3530       switch (Cave[y+1][x])
3531       {
3532         case Xacid_1:
3533         case Xacid_2:
3534         case Xacid_3:
3535         case Xacid_4:
3536         case Xacid_5:
3537         case Xacid_6:
3538         case Xacid_7:
3539         case Xacid_8:
3540           Cave[y][x] = Yemerald_sB;
3541           if (Cave[y][x+1] == Xblank)
3542             Cave[y][x+1] = Xacid_splash_e;
3543           if (Cave[y][x-1] == Xblank)
3544             Cave[y][x-1] = Xacid_splash_w;
3545           Next[y][x] = Xblank;
3546           play_element_sound(x, y, SOUND_acid, Xacid_1);
3547           goto loop;
3548
3549         case Xblank:
3550         case Xacid_splash_e:
3551         case Xacid_splash_w:
3552         case Zplayer:
3553           Cave[y][x] = Yemerald_sB;
3554           Cave[y+1][x] = Yemerald_s;
3555           Next[y][x] = Xblank;
3556           Next[y+1][x] = Xemerald_fall;
3557           goto loop;
3558
3559         case Xwonderwall:
3560           if (lev.wonderwall_time)
3561           {
3562             lev.wonderwall_state = 1;
3563             Cave[y][x] = Yemerald_sB;
3564             if (tab_blank[Cave[y+2][x]])
3565             {
3566               Cave[y+2][x] = Ydiamond_s;
3567               Next[y+2][x] = Xdiamond_fall;
3568             }
3569
3570             Next[y][x] = Xblank;
3571             play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
3572             goto loop;
3573           }
3574
3575         default:
3576           Cave[y][x] = Xemerald;
3577           Next[y][x] = Xemerald;
3578           play_element_sound(x, y, SOUND_diamond, Xemerald);
3579           goto loop;
3580       }
3581
3582     /* --------------------------------------------------------------------- */
3583
3584     case Xdiamond:
3585       switch (Cave[y+1][x])
3586       {
3587         case Xacid_1:
3588         case Xacid_2:
3589         case Xacid_3:
3590         case Xacid_4:
3591         case Xacid_5:
3592         case Xacid_6:
3593         case Xacid_7:
3594         case Xacid_8:
3595           Cave[y][x] = Ydiamond_sB;
3596           if (Cave[y][x+1] == Xblank)
3597             Cave[y][x+1] = Xacid_splash_e;
3598           if (Cave[y][x-1] == Xblank)
3599             Cave[y][x-1] = Xacid_splash_w;
3600           Next[y][x] = Xblank;
3601           play_element_sound(x, y, SOUND_acid, Xacid_1);
3602           goto loop;
3603
3604         case Xblank:
3605         case Xacid_splash_e:
3606         case Xacid_splash_w:
3607           Cave[y][x] = Ydiamond_sB;
3608           Cave[y+1][x] = Ydiamond_s;
3609           Next[y][x] = Xblank;
3610           Next[y+1][x] = Xdiamond_fall;
3611           goto loop;
3612
3613         case Xspring:
3614         case Xspring_pause:
3615         case Xspring_e:
3616         case Xspring_w:
3617         case Xandroid:
3618         case Xandroid_1_n:
3619         case Xandroid_2_n:
3620         case Xandroid_1_e:
3621         case Xandroid_2_e:
3622         case Xandroid_1_s:
3623         case Xandroid_2_s:
3624         case Xandroid_1_w:
3625         case Xandroid_2_w:
3626         case Xstone:
3627         case Xstone_pause:
3628         case Xemerald:
3629         case Xemerald_pause:
3630         case Xdiamond:
3631         case Xdiamond_pause:
3632         case Xbomb:
3633         case Xbomb_pause:
3634         case Xballoon:
3635         case Xacid_ne:
3636         case Xacid_nw:
3637         case Xball_1:
3638         case Xball_2:
3639         case Xnut:
3640         case Xnut_pause:
3641         case Xslidewall_ns:
3642         case Xslidewall_ew:
3643         case Xwonderwall:
3644         case Xkey_1:
3645         case Xkey_2:
3646         case Xkey_3:
3647         case Xkey_4:
3648         case Xkey_5:
3649         case Xkey_6:
3650         case Xkey_7:
3651         case Xkey_8:
3652         case Xbumper:
3653         case Xswitch:
3654         case Xsteel_1:
3655         case Xsteel_2:
3656         case Xsteel_3:
3657         case Xsteel_4:
3658         case Xwall_1:
3659         case Xwall_2:
3660         case Xwall_3:
3661         case Xwall_4:
3662         case Xroundwall_1:
3663         case Xroundwall_2:
3664         case Xroundwall_3:
3665         case Xroundwall_4:
3666           if (RANDOM & 1)
3667           {
3668             if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
3669             {
3670               Cave[y][x] = Ydiamond_eB;
3671               Cave[y][x+1] = Ydiamond_e;
3672               Next[y][x] = Xblank;
3673               Next[y][x+1] = Xdiamond_pause;
3674               goto loop;
3675             }
3676
3677             if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
3678             {
3679               Cave[y][x] = Ydiamond_wB;
3680               Cave[y][x-1] = Ydiamond_w;
3681               Next[y][x] = Xblank;
3682               Next[y][x-1] = Xdiamond_pause;
3683               goto loop;
3684             }
3685           }
3686           else
3687           {
3688             if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
3689             {
3690               Cave[y][x] = Ydiamond_wB;
3691               Cave[y][x-1] = Ydiamond_w;
3692               Next[y][x] = Xblank;
3693               Next[y][x-1] = Xdiamond_pause;
3694               goto loop;
3695             }
3696
3697             if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
3698             {
3699               Cave[y][x] = Ydiamond_eB;
3700               Cave[y][x+1] = Ydiamond_e;
3701               Next[y][x] = Xblank;
3702               Next[y][x+1] = Xdiamond_pause;
3703               goto loop;
3704             }
3705           }
3706
3707         default:
3708           if (++lev.shine_cnt > 50)
3709           {
3710             lev.shine_cnt = RANDOM & 7;
3711             Cave[y][x] = Xdiamond_shine;
3712           }
3713
3714           goto loop;
3715       }
3716
3717     /* --------------------------------------------------------------------- */
3718
3719     case Xdiamond_pause:
3720       switch (Cave[y+1][x])
3721       {
3722         case Xacid_1:
3723         case Xacid_2:
3724         case Xacid_3:
3725         case Xacid_4:
3726         case Xacid_5:
3727         case Xacid_6:
3728         case Xacid_7:
3729         case Xacid_8:
3730           Cave[y][x] = Ydiamond_sB;
3731           if (Cave[y][x+1] == Xblank)
3732             Cave[y][x+1] = Xacid_splash_e;
3733           if (Cave[y][x-1] == Xblank)
3734             Cave[y][x-1] = Xacid_splash_w;
3735           Next[y][x] = Xblank;
3736           play_element_sound(x, y, SOUND_acid, Xacid_1);
3737           goto loop;
3738
3739         case Xblank:
3740         case Xacid_splash_e:
3741         case Xacid_splash_w:
3742           Cave[y][x] = Ydiamond_sB;
3743           Cave[y+1][x] = Ydiamond_s;
3744           Next[y][x] = Xblank;
3745           Next[y+1][x] = Xdiamond_fall;
3746           goto loop;
3747
3748         default:
3749           Cave[y][x] = Xdiamond;
3750           Next[y][x] = Xdiamond;
3751           goto loop;
3752       }
3753
3754     /* --------------------------------------------------------------------- */
3755
3756     case Xdiamond_fall:
3757       switch (Cave[y+1][x])
3758       {
3759         case Xacid_1:
3760         case Xacid_2:
3761         case Xacid_3:
3762         case Xacid_4:
3763         case Xacid_5:
3764         case Xacid_6:
3765         case Xacid_7:
3766         case Xacid_8:
3767           Cave[y][x] = Ydiamond_sB;
3768           if (Cave[y][x+1] == Xblank)
3769             Cave[y][x+1] = Xacid_splash_e;
3770           if (Cave[y][x-1] == Xblank)
3771             Cave[y][x-1] = Xacid_splash_w;
3772           Next[y][x] = Xblank;
3773           play_element_sound(x, y, SOUND_acid, Xacid_1);
3774           goto loop;
3775
3776         case Xblank:
3777         case Xacid_splash_e:
3778         case Xacid_splash_w:
3779         case Zplayer:
3780           Cave[y][x] = Ydiamond_sB;
3781           Cave[y+1][x] = Ydiamond_s;
3782           Next[y][x] = Xblank;
3783           Next[y+1][x] = Xdiamond_fall;
3784           goto loop;
3785
3786         case Xwonderwall:
3787           if (lev.wonderwall_time)
3788           {
3789             lev.wonderwall_state = 1;
3790             Cave[y][x] = Ydiamond_sB;
3791             if (tab_blank[Cave[y+2][x]])
3792             {
3793               Cave[y+2][x] = Ystone_s;
3794               Next[y+2][x] = Xstone_fall;
3795             }
3796
3797             Next[y][x] = Xblank;
3798             play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
3799             goto loop;
3800           }
3801
3802         default:
3803           Cave[y][x] = Xdiamond;
3804           Next[y][x] = Xdiamond;
3805           play_element_sound(x, y, SOUND_diamond, Xdiamond);
3806           goto loop;
3807       }
3808
3809     /* --------------------------------------------------------------------- */
3810
3811     case Xdrip_fall:
3812       switch (Cave[y+1][x])
3813       {
3814         case Xacid_1:
3815         case Xacid_2:
3816         case Xacid_3:
3817         case Xacid_4:
3818         case Xacid_5:
3819         case Xacid_6:
3820         case Xacid_7:
3821         case Xacid_8:
3822           Cave[y][x] = Ydrip_1_sB;
3823           if (Cave[y][x+1] == Xblank)
3824             Cave[y][x+1] = Xacid_splash_e;
3825           if (Cave[y][x-1] == Xblank)
3826             Cave[y][x-1] = Xacid_splash_w;
3827           Next[y][x] = Xdrip_stretchB;
3828           play_element_sound(x, y, SOUND_acid, Xacid_1);
3829           goto loop;
3830
3831         case Xblank:
3832         case Xacid_splash_e:
3833         case Xacid_splash_w:
3834         case Xplant:
3835         case Yplant:
3836         case Zplayer:
3837           Cave[y][x] = Ydrip_1_sB;
3838           Cave[y+1][x] = Ydrip_1_s;
3839           Next[y][x] = Xdrip_stretchB;
3840           Next[y+1][x] = Xdrip_stretch;
3841           goto loop;
3842
3843         default:
3844           switch (RANDOM & 7)
3845           {
3846             case 0:
3847               temp = Xamoeba_1;
3848               break;
3849
3850             case 1:
3851               temp = Xamoeba_2;
3852               break;
3853
3854             case 2:
3855               temp = Xamoeba_3;
3856               break;
3857
3858             case 3:
3859               temp = Xamoeba_4;
3860               break;
3861
3862             case 4:
3863               temp = Xamoeba_5;
3864               break;
3865
3866             case 5:
3867               temp = Xamoeba_6;
3868               break;
3869
3870             case 6:
3871               temp = Xamoeba_7;
3872               break;
3873
3874             case 7:
3875               temp = Xamoeba_8;
3876               break;
3877           }
3878
3879           Cave[y][x] = temp;
3880           Next[y][x] = temp;
3881           play_element_sound(x, y, SOUND_drip, Xdrip_fall);
3882           goto loop;
3883       }
3884
3885     /* --------------------------------------------------------------------- */
3886
3887     case Xdrip_stretch:
3888       Cave[y][x] = Ydrip_2_s;
3889       Next[y][x] = Xdrip_fall;
3890       goto loop;
3891
3892     case Xdrip_stretchB:
3893       Cave[y][x] = Ydrip_2_sB;
3894       Next[y][x] = Xblank;
3895       goto loop;
3896
3897     case Xdrip:
3898       Next[y][x] = Xdrip_fall;
3899       goto loop;
3900
3901     /* --------------------------------------------------------------------- */
3902
3903     case Xbomb:
3904       switch (Cave[y+1][x])
3905       {
3906         case Xacid_1:
3907         case Xacid_2:
3908         case Xacid_3:
3909         case Xacid_4:
3910         case Xacid_5:
3911         case Xacid_6:
3912         case Xacid_7:
3913         case Xacid_8:
3914           Cave[y][x] = Ybomb_sB;
3915           if (Cave[y][x+1] == Xblank)
3916             Cave[y][x+1] = Xacid_splash_e;
3917           if (Cave[y][x-1] == Xblank)
3918             Cave[y][x-1] = Xacid_splash_w;
3919           Next[y][x] = Xblank;
3920           play_element_sound(x, y, SOUND_acid, Xacid_1);
3921           goto loop;
3922
3923         case Xblank:
3924         case Xacid_splash_e:
3925         case Xacid_splash_w:
3926           Cave[y][x] = Ybomb_sB;
3927           Cave[y+1][x] = Ybomb_s;
3928           Next[y][x] = Xblank;
3929           Next[y+1][x] = Xbomb_fall;
3930           goto loop;
3931
3932         case Xspring:
3933         case Xspring_pause:
3934         case Xspring_e:
3935         case Xspring_w:
3936         case Xandroid:
3937         case Xandroid_1_n:
3938         case Xandroid_2_n:
3939         case Xandroid_1_e:
3940         case Xandroid_2_e:
3941         case Xandroid_1_s:
3942         case Xandroid_2_s:
3943         case Xandroid_1_w:
3944         case Xandroid_2_w:
3945         case Xstone:
3946         case Xstone_pause:
3947         case Xemerald:
3948         case Xemerald_pause:
3949         case Xdiamond:
3950         case Xdiamond_pause:
3951         case Xbomb:
3952         case Xbomb_pause:
3953         case Xballoon:
3954         case Xacid_ne:
3955         case Xacid_nw:
3956         case Xball_1:
3957         case Xball_2:
3958         case Xnut:
3959         case Xnut_pause:
3960         case Xslidewall_ns:
3961         case Xslidewall_ew:
3962         case Xkey_1:
3963         case Xkey_2:
3964         case Xkey_3:
3965         case Xkey_4:
3966         case Xkey_5:
3967         case Xkey_6:
3968         case Xkey_7:
3969         case Xkey_8:
3970         case Xbumper:
3971         case Xswitch:
3972         case Xroundwall_1:
3973         case Xroundwall_2:
3974         case Xroundwall_3:
3975         case Xroundwall_4:
3976           if (RANDOM & 1)
3977           {
3978             if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
3979             {
3980               Cave[y][x] = Ybomb_eB;
3981               Cave[y][x+1] = Ybomb_e;
3982               Next[y][x] = Xblank;
3983               Next[y][x+1] = Xbomb_pause;
3984               goto loop;
3985             }
3986
3987             if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
3988             {
3989               Cave[y][x] = Ybomb_wB;
3990               Cave[y][x-1] = Ybomb_w;
3991               Next[y][x] = Xblank;
3992               Next[y][x-1] = Xbomb_pause;
3993               goto loop;
3994             }
3995           }
3996           else
3997           {
3998             if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
3999             {
4000               Cave[y][x] = Ybomb_wB;
4001               Cave[y][x-1] = Ybomb_w;
4002               Next[y][x] = Xblank;
4003               Next[y][x-1] = Xbomb_pause;
4004               goto loop;
4005             }
4006
4007             if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
4008             {
4009               Cave[y][x] = Ybomb_eB;
4010               Cave[y][x+1] = Ybomb_e;
4011               Next[y][x] = Xblank;
4012               Next[y][x+1] = Xbomb_pause;
4013               goto loop;
4014             }
4015           }
4016
4017         default:
4018           goto loop;
4019       }
4020
4021     /* --------------------------------------------------------------------- */
4022
4023     case Xbomb_pause:
4024       switch (Cave[y+1][x])
4025       {
4026         case Xacid_1:
4027         case Xacid_2:
4028         case Xacid_3:
4029         case Xacid_4:
4030         case Xacid_5:
4031         case Xacid_6:
4032         case Xacid_7:
4033         case Xacid_8:
4034           Cave[y][x] = Ybomb_sB;
4035           if (Cave[y][x+1] == Xblank)
4036             Cave[y][x+1] = Xacid_splash_e;
4037           if (Cave[y][x-1] == Xblank)
4038             Cave[y][x-1] = Xacid_splash_w;
4039           Next[y][x] = Xblank;
4040           play_element_sound(x, y, SOUND_acid, Xacid_1);
4041           goto loop;
4042
4043         case Xblank:
4044         case Xacid_splash_e:
4045         case Xacid_splash_w:
4046           Cave[y][x] = Ybomb_sB;
4047           Cave[y+1][x] = Ybomb_s;
4048           Next[y][x] = Xblank;
4049           Next[y+1][x] = Xbomb_fall;
4050           goto loop;
4051
4052         default:
4053           Cave[y][x] = Xbomb;
4054           Next[y][x] = Xbomb;
4055           goto loop;
4056       }
4057
4058     /* --------------------------------------------------------------------- */
4059
4060     case Xbomb_fall:
4061       switch (Cave[y+1][x])
4062       {
4063         case Xacid_1:
4064         case Xacid_2:
4065         case Xacid_3:
4066         case Xacid_4:
4067         case Xacid_5:
4068         case Xacid_6:
4069         case Xacid_7:
4070         case Xacid_8:
4071           Cave[y][x] = Ybomb_sB;
4072           if (Cave[y][x+1] == Xblank)
4073             Cave[y][x+1] = Xacid_splash_e;
4074           if (Cave[y][x-1] == Xblank)
4075             Cave[y][x-1] = Xacid_splash_w;
4076           Next[y][x] = Xblank;
4077           play_element_sound(x, y, SOUND_acid, Xacid_1);
4078           goto loop;
4079
4080         case Xblank:
4081         case Xacid_splash_e:
4082         case Xacid_splash_w:
4083           Cave[y][x] = Ybomb_sB;
4084           Cave[y+1][x] = Ybomb_s;
4085           Next[y][x] = Xblank;
4086           Next[y+1][x] = Xbomb_fall;
4087           goto loop;
4088
4089         default:
4090           Cave[y][x] = Ybomb_blank;
4091           Next[y][x] = Znormal;
4092           Boom[y-1][x-1] = Xblank;
4093           Boom[y-1][x] = Xblank;
4094           Boom[y-1][x+1] = Xblank;
4095           Boom[y][x-1] = Xblank;
4096           Boom[y][x] = Xblank;
4097           Boom[y][x+1] = Xblank;
4098           Boom[y+1][x-1] = Xblank;
4099           Boom[y+1][x] = Xblank;
4100           Boom[y+1][x+1] = Xblank;
4101 #if PLAY_ELEMENT_SOUND
4102           play_element_sound(x, y, SOUND_boom, element);
4103 #endif
4104           goto loop;
4105       }
4106
4107     /* --------------------------------------------------------------------- */
4108
4109     case Xballoon:
4110       if (lev.wind_cnt == 0)
4111         goto loop;
4112
4113       switch (lev.wind_direction)
4114       {
4115         case 0: /* north */
4116           switch (Cave[y-1][x])
4117           {
4118             case Xacid_1:
4119             case Xacid_2:
4120             case Xacid_3:
4121             case Xacid_4:
4122             case Xacid_5:
4123             case Xacid_6:
4124             case Xacid_7:
4125             case Xacid_8:
4126               Cave[y][x] = Yballoon_nB;
4127               if (Cave[y-2][x+1] == Xblank)
4128                 Cave[y-2][x+1] = Xacid_splash_e;
4129               if (Cave[y-2][x-1] == Xblank)
4130                 Cave[y-2][x-1] = Xacid_splash_w;
4131               Next[y][x] = Xblank;
4132               play_element_sound(x, y, SOUND_acid, Xacid_1);
4133               goto loop;
4134
4135             case Xblank:
4136             case Xacid_splash_e:
4137             case Xacid_splash_w:
4138               Cave[y][x] = Yballoon_nB;
4139               Cave[y-1][x] = Yballoon_n;
4140               Next[y][x] = Xblank;
4141               Next[y-1][x] = Xballoon;
4142               goto loop;
4143
4144             default:
4145               goto loop;
4146           }
4147
4148         case 1: /* east */
4149           switch (Cave[y][x+1])
4150           {
4151             case Xacid_1:
4152             case Xacid_2:
4153             case Xacid_3:
4154             case Xacid_4:
4155             case Xacid_5:
4156             case Xacid_6:
4157             case Xacid_7:
4158             case Xacid_8:
4159               Cave[y][x] = Yballoon_eB;
4160               if (Cave[y-1][x+2] == Xblank)
4161                 Cave[y-1][x+2] = Xacid_splash_e;
4162               if (Cave[y-1][x] == Xblank)
4163                 Cave[y-1][x] = Xacid_splash_w;
4164               Next[y][x] = Xblank;
4165               play_element_sound(x, y, SOUND_acid, Xacid_1);
4166               goto loop;
4167
4168             case Xblank:
4169             case Xacid_splash_e:
4170             case Xacid_splash_w:
4171               Cave[y][x] = Yballoon_eB;
4172               Cave[y][x+1] = Yballoon_e;
4173               Next[y][x] = Xblank;
4174               Next[y][x+1] = Xballoon;
4175               goto loop;
4176
4177             default:
4178               goto loop;
4179           }
4180
4181         case 2: /* south */
4182           switch (Cave[y+1][x])
4183           {
4184             case Xacid_1:
4185             case Xacid_2:
4186             case Xacid_3:
4187             case Xacid_4:
4188             case Xacid_5:
4189             case Xacid_6:
4190             case Xacid_7:
4191             case Xacid_8:
4192               Cave[y][x] = Yballoon_sB;
4193               if (Cave[y][x+1] == Xblank)
4194                 Cave[y][x+1] = Xacid_splash_e;
4195               if (Cave[y][x-1] == Xblank)
4196                 Cave[y][x-1] = Xacid_splash_w;
4197               Next[y][x] = Xblank;
4198               play_element_sound(x, y, SOUND_acid, Xacid_1);
4199               goto loop;
4200
4201             case Xblank:
4202             case Xacid_splash_e:
4203             case Xacid_splash_w:
4204               Cave[y][x] = Yballoon_sB;
4205               Cave[y+1][x] = Yballoon_s;
4206               Next[y][x] = Xblank;
4207               Next[y+1][x] = Xballoon;
4208               goto loop;
4209
4210             default:
4211               goto loop;
4212           }
4213
4214         case 3: /* west */
4215           switch (Cave[y][x-1])
4216           {
4217             case Xacid_1:
4218             case Xacid_2:
4219             case Xacid_3:
4220             case Xacid_4:
4221             case Xacid_5:
4222             case Xacid_6:
4223             case Xacid_7:
4224             case Xacid_8:
4225               Cave[y][x] = Yballoon_wB;
4226               if (Cave[y-1][x] == Xblank)
4227                 Cave[y-1][x] = Xacid_splash_e;
4228               if (Cave[y-1][x-2] == Xblank)
4229                 Cave[y-1][x-2] = Xacid_splash_w;
4230               Next[y][x] = Xblank;
4231               play_element_sound(x, y, SOUND_acid, Xacid_1);
4232               goto loop;
4233
4234             case Xblank:
4235             case Xacid_splash_e:
4236             case Xacid_splash_w:
4237               Cave[y][x] = Yballoon_wB;
4238               Cave[y][x-1] = Yballoon_w;
4239               Next[y][x] = Xblank;
4240               Next[y][x-1] = Xballoon;
4241               goto loop;
4242
4243             default:
4244               goto loop;
4245           }
4246       }
4247
4248     /* --------------------------------------------------------------------- */
4249
4250     case Xacid_1:
4251       Next[y][x] = Xacid_2;
4252       goto loop;
4253
4254     case Xacid_2:
4255       Next[y][x] = Xacid_3;
4256       goto loop;
4257
4258     case Xacid_3:
4259       Next[y][x] = Xacid_4;
4260       goto loop;
4261
4262     case Xacid_4:
4263       Next[y][x] = Xacid_5;
4264       goto loop;
4265
4266     case Xacid_5:
4267       Next[y][x] = Xacid_6;
4268       goto loop;
4269
4270     case Xacid_6:
4271       Next[y][x] = Xacid_7;
4272       goto loop;
4273
4274     case Xacid_7:
4275       Next[y][x] = Xacid_8;
4276       goto loop;
4277
4278     case Xacid_8:
4279       Next[y][x] = Xacid_1;
4280       goto loop;
4281
4282     case Xfake_acid_1:
4283       Next[y][x] = Xfake_acid_2;
4284       goto loop;
4285
4286     case Xfake_acid_2:
4287       Next[y][x] = Xfake_acid_3;
4288       goto loop;
4289
4290     case Xfake_acid_3:
4291       Next[y][x] = Xfake_acid_4;
4292       goto loop;
4293
4294     case Xfake_acid_4:
4295       Next[y][x] = Xfake_acid_5;
4296       goto loop;
4297
4298     case Xfake_acid_5:
4299       Next[y][x] = Xfake_acid_6;
4300       goto loop;
4301
4302     case Xfake_acid_6:
4303       Next[y][x] = Xfake_acid_7;
4304       goto loop;
4305
4306     case Xfake_acid_7:
4307       Next[y][x] = Xfake_acid_8;
4308       goto loop;
4309
4310     case Xfake_acid_8:
4311       Next[y][x] = Xfake_acid_1;
4312       goto loop;
4313
4314     /* --------------------------------------------------------------------- */
4315
4316     case Xball_1:
4317       if (lev.ball_state == 0)
4318         goto loop;
4319
4320       Cave[y][x] = Yball_1;
4321       Next[y][x] = Xball_2;
4322       if (lev.ball_cnt)
4323         goto loop;
4324
4325       goto ball_common;
4326
4327     case Xball_2:
4328       if (lev.ball_state == 0)
4329         goto loop;
4330
4331       Cave[y][x] = Yball_2;
4332       Next[y][x] = Xball_1;
4333       if (lev.ball_cnt)
4334         goto loop;
4335
4336       goto ball_common;
4337
4338     ball_common:
4339
4340       play_element_sound(x, y, SOUND_ball, element);
4341       if (lev.ball_random)
4342       {
4343         switch (RANDOM & 7)
4344         {
4345           case 0:
4346             if (lev.ball_array[lev.ball_pos][0] != Xblank &&
4347                 tab_blank[Cave[y-1][x-1]])
4348             {
4349               Cave[y-1][x-1] = Yball_blank;
4350               Next[y-1][x-1] = lev.ball_array[lev.ball_pos][0];
4351             }
4352             break;
4353
4354           case 1:
4355             if (lev.ball_array[lev.ball_pos][1] != Xblank &&
4356                 tab_blank[Cave[y-1][x]])
4357             {
4358               Cave[y-1][x] = Yball_blank;
4359               Next[y-1][x] = lev.ball_array[lev.ball_pos][1];
4360             }
4361             break;
4362
4363           case 2:
4364             if (lev.ball_array[lev.ball_pos][2] != Xblank &&
4365                 tab_blank[Cave[y-1][x+1]])
4366             {
4367               Cave[y-1][x+1] = Yball_blank;
4368               Next[y-1][x+1] = lev.ball_array[lev.ball_pos][2];
4369             }
4370             break;
4371
4372           case 3:
4373             if (lev.ball_array[lev.ball_pos][3] != Xblank &&
4374                 tab_blank[Cave[y][x-1]])
4375             {
4376               Cave[y][x-1] = Yball_blank;
4377               Next[y][x-1] = lev.ball_array[lev.ball_pos][3];
4378             }
4379             break;
4380
4381           case 4:
4382             if (lev.ball_array[lev.ball_pos][4] != Xblank &&
4383                 tab_blank[Cave[y][x+1]])
4384             {
4385               Cave[y][x+1] = Yball_blank;
4386               Next[y][x+1] = lev.ball_array[lev.ball_pos][4];
4387             }
4388             break;
4389
4390           case 5:
4391             if (lev.ball_array[lev.ball_pos][5] != Xblank &&
4392                 tab_blank[Cave[y+1][x-1]])
4393             {
4394               Cave[y+1][x-1] = Yball_blank;
4395               Next[y+1][x-1] = lev.ball_array[lev.ball_pos][5];
4396             }
4397             break;
4398
4399           case 6:
4400             if (lev.ball_array[lev.ball_pos][6] != Xblank &&
4401                 tab_blank[Cave[y+1][x]])
4402             {
4403               Cave[y+1][x] = Yball_blank;
4404               Next[y+1][x] = lev.ball_array[lev.ball_pos][6];
4405             }
4406             break;
4407
4408           case 7:
4409             if (lev.ball_array[lev.ball_pos][7] != Xblank &&
4410                 tab_blank[Cave[y+1][x+1]])
4411             {
4412               Cave[y+1][x+1] = Yball_blank;
4413               Next[y+1][x+1] = lev.ball_array[lev.ball_pos][7];
4414             }
4415             break;
4416         }
4417       }
4418       else
4419       {
4420         if (lev.ball_array[lev.ball_pos][0] != Xblank &&
4421             tab_blank[Cave[y-1][x-1]])
4422         {
4423           Cave[y-1][x-1] = Yball_blank;
4424           Next[y-1][x-1] = lev.ball_array[lev.ball_pos][0];
4425         }
4426
4427         if (lev.ball_array[lev.ball_pos][1] != Xblank &&
4428             tab_blank[Cave[y-1][x]])
4429         {
4430           Cave[y-1][x] = Yball_blank;
4431           Next[y-1][x] = lev.ball_array[lev.ball_pos][1];
4432         }
4433
4434         if (lev.ball_array[lev.ball_pos][2] != Xblank &&
4435             tab_blank[Cave[y-1][x+1]])
4436         {
4437           Cave[y-1][x+1] = Yball_blank;
4438           Next[y-1][x+1] = lev.ball_array[lev.ball_pos][2];
4439         }
4440
4441         if (lev.ball_array[lev.ball_pos][3] != Xblank &&
4442             tab_blank[Cave[y][x-1]])
4443         {
4444           Cave[y][x-1] = Yball_blank;
4445           Next[y][x-1] = lev.ball_array[lev.ball_pos][3];
4446         }
4447
4448         if (lev.ball_array[lev.ball_pos][4] != Xblank &&
4449             tab_blank[Cave[y][x+1]])
4450         {
4451           Cave[y][x+1] = Yball_blank;
4452           Next[y][x+1] = lev.ball_array[lev.ball_pos][4];
4453         }
4454
4455         if (lev.ball_array[lev.ball_pos][5] != Xblank &&
4456             tab_blank[Cave[y+1][x-1]])
4457         {
4458           Cave[y+1][x-1] = Yball_blank;
4459           Next[y+1][x-1] = lev.ball_array[lev.ball_pos][5];
4460         }
4461
4462         if (lev.ball_array[lev.ball_pos][6] != Xblank &&
4463             tab_blank[Cave[y+1][x]])
4464         {
4465           Cave[y+1][x] = Yball_blank;
4466           Next[y+1][x] = lev.ball_array[lev.ball_pos][6];
4467         }
4468
4469         if (lev.ball_array[lev.ball_pos][7] != Xblank &&
4470             tab_blank[Cave[y+1][x+1]])
4471         {
4472           Cave[y+1][x+1] = Yball_blank;
4473           Next[y+1][x+1] = lev.ball_array[lev.ball_pos][7];
4474         }
4475       }
4476
4477       lev.ball_pos = (lev.ball_pos + 1) % lev.num_ball_arrays;
4478
4479       goto loop;
4480
4481     /* --------------------------------------------------------------------- */
4482
4483     case Xslidewall_ns:
4484       if (tab_blank[Cave[y-1][x]])
4485       {
4486         Cave[y-1][x] = Yslidewall_ns_blank;
4487         Next[y-1][x] = Xslidewall_ns;
4488         play_element_sound(x, y, SOUND_slidewall, Xslidewall_ns);
4489       }
4490
4491       if (tab_blank[Cave[y+1][x]])
4492       {
4493         Cave[y+1][x] = Yslidewall_ns_blank;
4494         Next[y+1][x] = Xslidewall_ns;
4495         play_element_sound(x, y, SOUND_slidewall, Xslidewall_ns);
4496       }
4497
4498       goto loop;
4499
4500     case Xslidewall_ew:
4501       if (tab_blank[Cave[y][x+1]])
4502       {
4503         Cave[y][x+1] = Yslidewall_ew_blank;
4504         Next[y][x+1] = Xslidewall_ew;
4505         play_element_sound(x, y, SOUND_slidewall, Xslidewall_ew);
4506       }
4507
4508       if (tab_blank[Cave[y][x-1]])
4509       {
4510         Cave[y][x-1] = Yslidewall_ew_blank;
4511         Next[y][x-1] = Xslidewall_ew;
4512         play_element_sound(x, y, SOUND_slidewall, Xslidewall_ew);
4513       }
4514
4515       goto loop;
4516
4517     /* --------------------------------------------------------------------- */
4518
4519     case Xwonderwall:
4520       if (lev.wonderwall_time && lev.wonderwall_state)
4521       {
4522         Cave[y][x] = XwonderwallB;
4523         play_element_sound(x, y, SOUND_wonder, Xwonderwall);
4524       }
4525
4526       goto loop;
4527
4528     /* --------------------------------------------------------------------- */
4529
4530     case Xexit:
4531       if (lev.required > 0)
4532         goto loop;
4533
4534       temp = RANDOM & 63;
4535       if (temp < 21)
4536       {
4537         Cave[y][x] = Xexit_1;
4538         Next[y][x] = Xexit_2;
4539       }
4540       else if (temp < 42)
4541       {
4542         Cave[y][x] = Xexit_2;
4543         Next[y][x] = Xexit_3;
4544       }
4545       else
4546       {
4547         Cave[y][x] = Xexit_3;
4548         Next[y][x] = Xexit_1;
4549       }
4550
4551       play_element_sound(x, y, SOUND_exit_open, Xexit);
4552
4553       goto loop;
4554
4555     case Xexit_1:
4556       Next[y][x] = Xexit_2;
4557       goto loop;
4558
4559     case Xexit_2:
4560       Next[y][x] = Xexit_3;
4561       goto loop;
4562
4563     case Xexit_3:
4564       Next[y][x] = Xexit_1;
4565       goto loop;
4566
4567     /* --------------------------------------------------------------------- */
4568
4569     case Xdynamite_1:
4570       play_element_sound(x, y, SOUND_tick, Xdynamite_1);
4571       Next[y][x] = Xdynamite_2;
4572       goto loop;
4573
4574     case Xdynamite_2:
4575       play_element_sound(x, y, SOUND_tick, Xdynamite_2);
4576       Next[y][x] = Xdynamite_3;
4577       goto loop;
4578
4579     case Xdynamite_3:
4580       play_element_sound(x, y, SOUND_tick, Xdynamite_3);
4581       Next[y][x] = Xdynamite_4;
4582       goto loop;
4583
4584     case Xdynamite_4:
4585       play_element_sound(x, y, SOUND_tick, Xdynamite_4);
4586       Next[y][x] = Zdynamite;
4587       Boom[y-1][x-1] = Xblank;
4588       Boom[y-1][x] = Xblank;
4589       Boom[y-1][x+1] = Xblank;
4590       Boom[y][x-1] = Xblank;
4591       Boom[y][x] = Xblank;
4592       Boom[y][x+1] = Xblank;
4593       Boom[y+1][x-1] = Xblank;
4594       Boom[y+1][x] = Xblank;
4595       Boom[y+1][x+1] = Xblank;
4596       goto loop;
4597
4598     /* --------------------------------------------------------------------- */
4599
4600     case Xwheel:
4601       if (lev.wheel_cnt && x == lev.wheel_x && y == lev.wheel_y)
4602         Cave[y][x] = XwheelB;
4603       goto loop;
4604
4605     /* --------------------------------------------------------------------- */
4606
4607     case Xswitch:
4608       if (lev.ball_state)
4609         Cave[y][x] = XswitchB;
4610       goto loop;
4611
4612     /* --------------------------------------------------------------------- */
4613
4614     case Xsand_stone:
4615       switch (Cave[y+1][x])
4616       {
4617         case Xacid_1:
4618         case Xacid_2:
4619         case Xacid_3:
4620         case Xacid_4:
4621         case Xacid_5:
4622         case Xacid_6:
4623         case Xacid_7:
4624         case Xacid_8:
4625           Cave[y][x] = Xsand_stonesand_quickout_1;
4626           if (Cave[y][x+1] == Xblank)
4627             Cave[y][x+1] = Xacid_splash_e;
4628           if (Cave[y][x-1] == Xblank)
4629             Cave[y][x-1] = Xacid_splash_w;
4630           Next[y][x] = Xsand_stonesand_quickout_2;
4631           play_element_sound(x, y, SOUND_acid, Xacid_1);
4632           goto loop;
4633
4634         case Xblank:
4635         case Xacid_splash_e:
4636         case Xacid_splash_w:
4637           Cave[y][x] = Xsand_stonesand_quickout_1;
4638           Cave[y+1][x] = Xsand_stoneout_1;
4639           Next[y][x] = Xsand_stonesand_quickout_2;
4640           Next[y+1][x] = Xsand_stoneout_2;
4641           goto loop;
4642
4643         case Xsand:
4644           Cave[y][x] = Xsand_stonesand_1;
4645           Cave[y+1][x] = Xsand_sandstone_1;
4646           Next[y][x] = Xsand_stonesand_2;
4647           Next[y+1][x] = Xsand_sandstone_2;
4648           goto loop;
4649
4650         default:
4651           goto loop;
4652       }
4653
4654     case Xsand_stonein_1:
4655       Next[y][x] = Xsand_stonein_2;
4656       goto loop;
4657
4658     case Xsand_stonein_2:
4659       Next[y][x] = Xsand_stonein_3;
4660       goto loop;
4661
4662     case Xsand_stonein_3:
4663       Next[y][x] = Xsand_stonein_4;
4664       goto loop;
4665
4666     case Xsand_stonein_4:
4667       Next[y][x] = Xblank;
4668       goto loop;
4669
4670     case Xsand_stonesand_1:
4671       Next[y][x] = Xsand_stonesand_2;
4672       goto loop;
4673
4674     case Xsand_stonesand_2:
4675       Next[y][x] = Xsand_stonesand_3;
4676       goto loop;
4677
4678     case Xsand_stonesand_3:
4679       Next[y][x] = Xsand_stonesand_4;
4680       goto loop;
4681
4682     case Xsand_stonesand_4:
4683       Next[y][x] = Xsand;
4684       goto loop;
4685
4686 #if 1
4687     case Xsand_stonesand_quickout_1:
4688       Next[y][x] = Xsand_stonesand_quickout_2;
4689       goto loop;
4690
4691     case Xsand_stonesand_quickout_2:
4692       Next[y][x] = Xsand;
4693       goto loop;
4694 #endif
4695
4696     case Xsand_stoneout_1:
4697       Next[y][x] = Xsand_stoneout_2;
4698       goto loop;
4699
4700     case Xsand_stoneout_2:
4701       Next[y][x] = Xstone_fall;
4702       goto loop;
4703
4704     case Xsand_sandstone_1:
4705       Next[y][x] = Xsand_sandstone_2;
4706       goto loop;
4707
4708     case Xsand_sandstone_2:
4709       Next[y][x] = Xsand_sandstone_3;
4710       goto loop;
4711
4712     case Xsand_sandstone_3:
4713       Next[y][x] = Xsand_sandstone_4;
4714       goto loop;
4715
4716     case Xsand_sandstone_4:
4717       Next[y][x] = Xsand_stone;
4718       goto loop;
4719
4720     /* --------------------------------------------------------------------- */
4721
4722     case Xfake_amoeba:
4723       if (lev.lenses_cnt)
4724         Cave[y][x] = Xfake_amoebaB;
4725       goto loop;
4726
4727     /* --------------------------------------------------------------------- */
4728
4729     case Xfake_blank:
4730       if (lev.lenses_cnt)
4731         Cave[y][x] = Xfake_blankB;
4732       goto loop;
4733
4734     /* --------------------------------------------------------------------- */
4735
4736     case Xfake_grass:
4737       if (lev.magnify_cnt)
4738         Cave[y][x] = Xfake_grassB;
4739       goto loop;
4740
4741     /* --------------------------------------------------------------------- */
4742
4743     case Xfake_door_1:
4744       if (lev.magnify_cnt)
4745         Cave[y][x] = Xdoor_1;
4746       goto loop;
4747
4748     case Xfake_door_2:
4749       if (lev.magnify_cnt)
4750         Cave[y][x] = Xdoor_2;
4751       goto loop;
4752
4753     case Xfake_door_3:
4754       if (lev.magnify_cnt)
4755         Cave[y][x] = Xdoor_3;
4756       goto loop;
4757
4758     case Xfake_door_4:
4759       if (lev.magnify_cnt)
4760         Cave[y][x] = Xdoor_4;
4761       goto loop;
4762
4763     case Xfake_door_5:
4764       if (lev.magnify_cnt)
4765         Cave[y][x] = Xdoor_5;
4766       goto loop;
4767
4768     case Xfake_door_6:
4769       if (lev.magnify_cnt)
4770         Cave[y][x] = Xdoor_6;
4771       goto loop;
4772
4773     case Xfake_door_7:
4774       if (lev.magnify_cnt)
4775         Cave[y][x] = Xdoor_7;
4776       goto loop;
4777
4778     case Xfake_door_8:
4779       if (lev.magnify_cnt)
4780         Cave[y][x] = Xdoor_8;
4781       goto loop;
4782
4783     /* --------------------------------------------------------------------- */
4784
4785     case Xboom_bug:
4786       bug_boom:
4787       Next[y][x] = Znormal;
4788       Boom[y-1][x-1] = Xemerald;
4789       Boom[y-1][x] = Xemerald;
4790       Boom[y-1][x+1] = Xemerald;
4791       Boom[y][x-1] = Xemerald;
4792       Boom[y][x] = Xdiamond;
4793       Boom[y][x+1] = Xemerald;
4794       Boom[y+1][x-1] = Xemerald;
4795       Boom[y+1][x] = Xemerald;
4796       Boom[y+1][x+1] = Xemerald;
4797 #if PLAY_ELEMENT_SOUND
4798       play_element_sound(x, y, SOUND_boom, element);
4799 #endif
4800       goto loop;
4801
4802     case Xboom_bomb:
4803
4804     tank_boom:
4805
4806       Next[y][x] = Znormal;
4807       Boom[y-1][x-1] = Xblank;
4808       Boom[y-1][x] = Xblank;
4809       Boom[y-1][x+1] = Xblank;
4810       Boom[y][x-1] = Xblank;
4811       Boom[y][x] = Xblank;
4812       Boom[y][x+1] = Xblank;
4813       Boom[y+1][x-1] = Xblank;
4814       Boom[y+1][x] = Xblank;
4815       Boom[y+1][x+1] = Xblank;
4816 #if PLAY_ELEMENT_SOUND
4817       play_element_sound(x, y, SOUND_boom, element);
4818 #endif
4819       goto loop;
4820
4821     case Xboom_android:
4822 #if PLAY_ELEMENT_SOUND
4823       play_element_sound(x, y, SOUND_boom, Xandroid);
4824 #endif
4825     case Xboom_1:
4826       Next[y][x] = Xboom_2;
4827 #if !PLAY_ELEMENT_SOUND
4828       if (x != lev.exit_x && y != lev.exit_y)
4829         play_sound(x, y, SOUND_boom);
4830       else
4831         lev.exit_x = lev.exit_y = -1;
4832 #endif
4833       goto loop;
4834
4835     case Xboom_2:
4836       Next[y][x] = Boom[y][x];
4837       goto loop;
4838
4839     /* --------------------------------------------------------------------- */
4840
4841     case Zborder:
4842       if (++y < HEIGHT - 1)
4843       {
4844         x = 0;
4845         cave_cache = Cave[y];
4846         goto loop;
4847       }
4848
4849       goto done;
4850   }
4851
4852 #undef RANDOM
4853 #undef PLAY
4854 #undef PLAY_FORCE
4855
4856  done:
4857
4858   if (ply[0].alive || ply[1].alive || ply[2].alive || ply[3].alive)
4859     lev.score += score;         /* only add a score if someone is alive */
4860   else
4861     game_em.game_over = TRUE;
4862
4863   RandomEM = random;
4864
4865   {
4866     void *temp = Cave;
4867
4868     /* triple buffering */
4869     Cave = Next;
4870     Next = Draw;
4871     Draw = temp;
4872   }
4873 }