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