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