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