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