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