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