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