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