moved code for explosions in EM engine to separate functions
[rocksndiamonds.git] / src / game_em / logic.c
index d71c1d06e42ee317ea2153d9d931c2e693a44b27..a32073ace5fc305a47143b81dc4cace475e9a3a2 100644 (file)
 static unsigned int seed;
 static int score;
 
-static void Lboom_bug(int x, int y)
+static void Lboom_generic(int x, int y, int element, int element_middle)
+{
+  Boom[x-1][y-1] = element;
+  Boom[x][y-1]   = element;
+  Boom[x+1][y-1] = element;
+  Boom[x-1][y]   = element;
+  Boom[x][y]     = element_middle;
+  Boom[x+1][y]   = element;
+  Boom[x-1][y+1] = element;
+  Boom[x][y+1]   = element;
+  Boom[x+1][y+1] = element;
+}
+
+static void Lboom_bug(int x, int y, int by_element)
+{
+  Next[x][y] = Znormal;
+
+  Lboom_generic(x, y, Xemerald, Xdiamond);
+
+#if PLAY_ELEMENT_SOUND
+  play_element_sound(x, y, SOUND_boom, by_element);
+#endif
+}
+
+static void Lboom_tank(int x, int y, int by_element)
 {
   Next[x][y] = Znormal;
-  Boom[x-1][y-1] = Xemerald;
-  Boom[x][y-1] = Xemerald;
-  Boom[x+1][y-1] = Xemerald;
-  Boom[x-1][y] = Xemerald;
-  Boom[x][y] = Xdiamond;
-  Boom[x+1][y] = Xemerald;
-  Boom[x-1][y+1] = Xemerald;
-  Boom[x][y+1] = Xemerald;
-  Boom[x+1][y+1] = Xemerald;
+
+  Lboom_generic(x, y, Xblank, Xblank);
 
 #if PLAY_ELEMENT_SOUND
-  play_element_sound(x, y, SOUND_boom, element);
+  play_element_sound(x, y, SOUND_boom, by_element);
 #endif
 }
 
-static void Lboom_tank(int x, int y)
+static void Lboom_eater(int x, int y, int by_element)
 {
   Next[x][y] = Znormal;
-  Boom[x-1][y-1] = Xblank;
-  Boom[x][y-1] = Xblank;
-  Boom[x+1][y-1] = Xblank;
-  Boom[x-1][y] = Xblank;
-  Boom[x][y] = Xblank;
-  Boom[x+1][y] = Xblank;
-  Boom[x-1][y+1] = Xblank;
-  Boom[x][y+1] = Xblank;
-  Boom[x+1][y+1] = Xblank;
+
+  Boom[x-1][y-1] = lev.eater_array[lev.eater_pos][0];
+  Boom[x][y-1]   = lev.eater_array[lev.eater_pos][1];
+  Boom[x+1][y-1] = lev.eater_array[lev.eater_pos][2];
+  Boom[x-1][y]   = lev.eater_array[lev.eater_pos][3];
+  Boom[x][y]     = lev.eater_array[lev.eater_pos][4];
+  Boom[x+1][y]   = lev.eater_array[lev.eater_pos][5];
+  Boom[x-1][y+1] = lev.eater_array[lev.eater_pos][6];
+  Boom[x][y+1]   = lev.eater_array[lev.eater_pos][7];
+  Boom[x+1][y+1] = lev.eater_array[lev.eater_pos][8];
+
+  lev.eater_pos = (lev.eater_pos + 1) & 7;
+
 #if PLAY_ELEMENT_SOUND
-  play_element_sound(x, y, SOUND_boom, element);
+  play_element_sound(x, y, SOUND_boom, by_element);
 #endif
 }
 
@@ -544,6 +565,13 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
 
        switch(Cave[x+dx][y])
        {
+          case Xblank:
+          case Xacid_splash_e:
+          case Xacid_splash_w:
+           Cave[x+dx][y] = dx > 0 ? Ystone_e : Ystone_w;
+           Next[x+dx][y] = Xstone_pause;
+           goto stone_walk;
+
           case Xacid_1:
           case Xacid_2:
           case Xacid_3:
@@ -557,13 +585,6 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
            if (Cave[x+dx-1][y-1] == Xblank)
              Cave[x+dx-1][y-1] = Xacid_splash_w;
            play_element_sound(x, y, SOUND_acid, Xacid_1);
-           goto stone_walk;
-
-          case Xblank:
-          case Xacid_splash_e:
-          case Xacid_splash_w:
-           Cave[x+dx][y] = dx > 0 ? Ystone_e : Ystone_w;
-           Next[x+dx][y] = Xstone_pause;
 
           stone_walk:
 
@@ -571,6 +592,7 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
            Next[x][y] = Zplayer;
            play_element_sound(x, y, SOUND_roll, Xstone);
            ply->x = x;
+           break;
        }
 
        ply->anim = PLY_push_n + anim;
@@ -582,6 +604,13 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
 
        switch(Cave[x+dx][y])
        {
+         case Xblank:
+          case Xacid_splash_e:
+          case Xacid_splash_w:
+           Cave[x+dx][y] = dx > 0 ? Ybomb_e : Ybomb_w;
+           Next[x+dx][y] = Xbomb_pause;
+           goto bomb_walk;
+
           case Xacid_1:
           case Xacid_2:
           case Xacid_3:
@@ -595,13 +624,6 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
            if (Cave[x+dx-1][y-1] == Xblank)
              Cave[x+dx-1][y-1] = Xacid_splash_w;
            play_element_sound(x, y, SOUND_acid, Xacid_1);
-           goto bomb_walk;
-
-         case Xblank:
-          case Xacid_splash_e:
-          case Xacid_splash_w:
-           Cave[x+dx][y] = dx > 0 ? Ybomb_e : Ybomb_w;
-           Next[x+dx][y] = Xbomb_pause;
 
           bomb_walk:
 
@@ -609,6 +631,7 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
            Next[x][y] = Zplayer;
            play_element_sound(x, y, SOUND_roll, Xbomb);
            ply->x = x;
+           break;
        }
 
        ply->anim = PLY_push_n + anim;
@@ -620,6 +643,13 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
 
        switch(Cave[x+dx][y])
        {
+          case Xblank:
+          case Xacid_splash_e:
+          case Xacid_splash_w:
+           Cave[x+dx][y] = dx > 0 ? Ynut_e : Ynut_w;
+           Next[x+dx][y] = Xnut_pause;
+           goto nut_walk;
+
           case Xacid_1:
           case Xacid_2:
           case Xacid_3:
@@ -633,13 +663,6 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
            if (Cave[x+dx-1][y-1] == Xblank)
              Cave[x+dx-1][y-1] = Xacid_splash_w;
            play_element_sound(x, y, SOUND_acid, Xacid_1);
-           goto nut_walk;
-
-          case Xblank:
-          case Xacid_splash_e:
-          case Xacid_splash_w:
-           Cave[x+dx][y] = dx > 0 ? Ynut_e : Ynut_w;
-           Next[x+dx][y] = Xnut_pause;
 
           nut_walk:
 
@@ -647,6 +670,7 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
            Next[x][y] = Zplayer;
            play_element_sound(x, y, SOUND_roll, Xnut);
            ply->x = x;
+           break;
        }
 
        ply->anim = PLY_push_n + anim;
@@ -658,16 +682,12 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
 
        switch(Cave[x+dx][y])
        {
-          case Xalien:
-          case Xalien_pause:
-           Cave[x][y] = dx > 0 ? Yspring_alien_eB : Yspring_alien_wB;
-           Cave[x+dx][y] = dx > 0 ? Yspring_alien_e : Yspring_alien_w;
-           Next[x][y] = Zplayer;
+          case Xblank:
+          case Xacid_splash_e:
+          case Xacid_splash_w:
+           Cave[x+dx][y] = dx > 0 ? Yspring_e : Yspring_w;
            Next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
-           play_element_sound(x, y, SOUND_slurp, Xalien);
-           lev.score += lev.slurp_score;
-           ply->x = x;
-           break;
+           goto spring_walk;
 
           case Xacid_1:
           case Xacid_2:
@@ -682,19 +702,25 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
            if (Cave[x+dx-1][y-1] == Xblank)
              Cave[x+dx-1][y-1] = Xacid_splash_w;
            play_element_sound(x, y, SOUND_acid, Xacid_1);
-           goto spring_walk;
-
-          case Xblank:
-          case Xacid_splash_e:
-          case Xacid_splash_w:
-           Cave[x+dx][y] = dx > 0 ? Yspring_e : Yspring_w;
-           Next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
 
          spring_walk:
+
            Cave[x][y] = dx > 0 ? Yspring_eB : Yspring_wB;
            Next[x][y] = Zplayer;
            play_element_sound(x, y, SOUND_roll, Xspring);
            ply->x = x;
+           break;
+
+          case Xalien:
+          case Xalien_pause:
+           Cave[x][y] = dx > 0 ? Yspring_alien_eB : Yspring_alien_wB;
+           Cave[x+dx][y] = dx > 0 ? Yspring_alien_e : Yspring_alien_w;
+           Next[x][y] = Zplayer;
+           Next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
+           play_element_sound(x, y, SOUND_slurp, Xalien);
+           lev.score += lev.slurp_score;
+           ply->x = x;
+           break;
        }
 
        ply->anim = PLY_push_n + anim;
@@ -717,6 +743,14 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
       case Xballoon:
        switch(Cave[x+dx][y+dy])
        {
+          case Xblank:
+          case Xacid_splash_e:
+          case Xacid_splash_w:
+           Cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
+                               (dx > 0 ? Yballoon_e : Yballoon_w));
+           Next[x+dx][y+dy] = Xballoon;
+           goto balloon_walk;
+
           case Xacid_1:
           case Xacid_2:
           case Xacid_3:
@@ -730,22 +764,16 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
            if (Cave[x+dx-1][y+dy-1] == Xblank)
              Cave[x+dx-1][y+dy-1] = Xacid_splash_w;
            play_element_sound(x, y, SOUND_acid, Xacid_1);
-           goto balloon_walk;
-
-          case Xblank:
-          case Xacid_splash_e:
-          case Xacid_splash_w:
-           Cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
-                               (dx > 0 ? Yballoon_e : Yballoon_w));
-           Next[x+dx][y+dy] = Xballoon;
 
          balloon_walk:
+
            Cave[x][y] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
                          (dx > 0 ? Yballoon_eB : Yballoon_wB));
            Next[x][y] = Zplayer;
            play_element_sound(x, y, SOUND_push, Xballoon);
            ply->x = x;
            ply->y = y;
+           break;
        }
 
        ply->anim = PLY_push_n + anim;
@@ -762,6 +790,15 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
       case Xandroid_2_w:
        switch(Cave[x+dx][y+dy])
        {
+          case Xblank:
+          case Xacid_splash_e:
+          case Xacid_splash_w:
+           Cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
+                               (dx > 0 ? Yandroid_e : Yandroid_w));
+           Next[x+dx][y+dy] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
+                               (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
+           goto android_walk;
+
           case Xacid_1:
           case Xacid_2:
           case Xacid_3:
@@ -775,23 +812,16 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
            if (Cave[x+dx-1][y+dy-1] == Xblank)
              Cave[x+dx-1][y+dy-1] = Xacid_splash_w;
            play_element_sound(x, y, SOUND_acid, Xacid_1);
-           goto android_walk;
-
-          case Xblank:
-          case Xacid_splash_e:
-          case Xacid_splash_w:
-           Cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
-                               (dx > 0 ? Yandroid_e : Yandroid_w));
-           Next[x+dx][y+dy] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
-                               (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
 
          android_walk:
+
            Cave[x][y] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
                          (dx > 0 ? Yandroid_eB : Yandroid_wB));
            Next[x][y] = Zplayer;
            play_element_sound(x, y, SOUND_push, Xandroid);
            ply->x = x;
            ply->y = y;
+           break;
        }
 
        ply->anim = PLY_push_n + anim;
@@ -854,6 +884,7 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
          break;
 
       door_walk:
+
        if (!tab_blank[Cave[x+dx][y+dy]])
          break;
 
@@ -893,6 +924,7 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
        goto wind_walk;
 
       wind_walk:
+
        play_element_sound(x, y, SOUND_press, element);
        lev.wind_cnt = lev.wind_time;
        break;
@@ -1029,6 +1061,7 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
        goto key_shoot;
 
       key_shoot:
+
        Next[x][y] = Xblank;
        play_element_sound(x, y, SOUND_collect, element);
        lev.score += lev.key_score;
@@ -1707,6 +1740,16 @@ static void Landroid_1_n(int x, int y)
 {
   switch (Cave[x][y-1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Yandroid_nB;
+      Cave[x][y-1] = Yandroid_n;
+      Next[x][y] = Xblank;
+      Next[x][y-1] = Xandroid;
+      play_element_sound(x, y, SOUND_android_move, Xandroid_1_n);
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -1724,16 +1767,6 @@ static void Landroid_1_n(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Yandroid_nB;
-      Cave[x][y-1] = Yandroid_n;
-      Next[x][y] = Xblank;
-      Next[x][y-1] = Xandroid;
-      play_element_sound(x, y, SOUND_android_move, Xandroid_1_n);
-      return;
-
     default:
       Landroid(x, y);
       return;
@@ -1744,6 +1777,16 @@ static void Landroid_2_n(int x, int y)
 {
   switch (Cave[x][y-1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Yandroid_nB;
+      Cave[x][y-1] = Yandroid_n;
+      Next[x][y] = Xblank;
+      Next[x][y-1] = Xandroid_1_n;
+      play_element_sound(x, y, SOUND_android_move, Xandroid_2_n);
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -1761,16 +1804,6 @@ static void Landroid_2_n(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Yandroid_nB;
-      Cave[x][y-1] = Yandroid_n;
-      Next[x][y] = Xblank;
-      Next[x][y-1] = Xandroid_1_n;
-      play_element_sound(x, y, SOUND_android_move, Xandroid_2_n);
-      return;
-
     default:
       Landroid(x, y);
       return;
@@ -1781,6 +1814,16 @@ static void Landroid_1_e(int x, int y)
 {
   switch (Cave[x+1][y])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Yandroid_eB;
+      Cave[x+1][y] = Yandroid_e;
+      Next[x][y] = Xblank;
+      Next[x+1][y] = Xandroid;
+      play_element_sound(x, y, SOUND_android_move, Xandroid_1_e);
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -1798,16 +1841,6 @@ static void Landroid_1_e(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Yandroid_eB;
-      Cave[x+1][y] = Yandroid_e;
-      Next[x][y] = Xblank;
-      Next[x+1][y] = Xandroid;
-      play_element_sound(x, y, SOUND_android_move, Xandroid_1_e);
-      return;
-
     default:
       Landroid(x, y);
       return;
@@ -1818,6 +1851,16 @@ static void Landroid_2_e(int x, int y)
 {
   switch (Cave[x+1][y])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Yandroid_eB;
+      Cave[x+1][y] = Yandroid_e;
+      Next[x][y] = Xblank;
+      Next[x+1][y] = Xandroid_1_e;
+      play_element_sound(x, y, SOUND_android_move, Xandroid_2_e);
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -1835,16 +1878,6 @@ static void Landroid_2_e(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Yandroid_eB;
-      Cave[x+1][y] = Yandroid_e;
-      Next[x][y] = Xblank;
-      Next[x+1][y] = Xandroid_1_e;
-      play_element_sound(x, y, SOUND_android_move, Xandroid_2_e);
-      return;
-
     default:
       Landroid(x, y);
       return;
@@ -1855,6 +1888,16 @@ static void Landroid_1_s(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Yandroid_sB;
+      Cave[x][y+1] = Yandroid_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xandroid;
+      play_element_sound(x, y, SOUND_android_move, Xandroid_1_s);
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -1872,16 +1915,6 @@ static void Landroid_1_s(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Yandroid_sB;
-      Cave[x][y+1] = Yandroid_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xandroid;
-      play_element_sound(x, y, SOUND_android_move, Xandroid_1_s);
-      return;
-
     default:
       Landroid(x, y);
       return;
@@ -1892,6 +1925,16 @@ static void Landroid_2_s(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Yandroid_sB;
+      Cave[x][y+1] = Yandroid_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xandroid_1_s;
+      play_element_sound(x, y, SOUND_android_move, Xandroid_2_s);
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -1909,16 +1952,6 @@ static void Landroid_2_s(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Yandroid_sB;
-      Cave[x][y+1] = Yandroid_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xandroid_1_s;
-      play_element_sound(x, y, SOUND_android_move, Xandroid_2_s);
-      return;
-
     default:
       Landroid(x, y);
       return;
@@ -1929,7 +1962,17 @@ static void Landroid_1_w(int x, int y)
 {
   switch (Cave[x-1][y])
   {
-    case Xacid_1:
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Yandroid_wB;
+      Cave[x-1][y] = Yandroid_w;
+      Next[x][y] = Xblank;
+      Next[x-1][y] = Xandroid;
+      play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
+      return;
+
+    case Xacid_1:
     case Xacid_2:
     case Xacid_3:
     case Xacid_4:
@@ -1946,16 +1989,6 @@ static void Landroid_1_w(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Yandroid_wB;
-      Cave[x-1][y] = Yandroid_w;
-      Next[x][y] = Xblank;
-      Next[x-1][y] = Xandroid;
-      play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
-      return;
-
     default:
       Landroid(x, y);
       return;
@@ -1966,6 +1999,16 @@ static void Landroid_2_w(int x, int y)
 {
   switch (Cave[x-1][y])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Yandroid_wB;
+      Cave[x-1][y] = Yandroid_w;
+      Next[x][y] = Xblank;
+      Next[x-1][y] = Xandroid_1_w;
+      play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -1983,16 +2026,6 @@ static void Landroid_2_w(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Yandroid_wB;
-      Cave[x-1][y] = Yandroid_w;
-      Next[x][y] = Xblank;
-      Next[x-1][y] = Xandroid_1_w;
-      play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
-      return;
-
     default:
       Landroid(x, y);
       return;
@@ -2035,6 +2068,18 @@ static void Leater_n(int x, int y)
 
   switch (Cave[x][y-1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Xplant:
+    case Yplant:
+    case Zplayer:
+      Cave[x][y] = Yeater_nB;
+      Cave[x][y-1] = Yeater_n;
+      Next[x][y] = Xblank;
+      Next[x][y-1] = Xeater_n;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -2052,18 +2097,6 @@ static void Leater_n(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Xplant:
-    case Yplant:
-    case Zplayer:
-      Cave[x][y] = Yeater_nB;
-      Cave[x][y-1] = Yeater_n;
-      Next[x][y] = Xblank;
-      Next[x][y-1] = Xeater_n;
-      return;
-
     default:
       Next[x][y] = RANDOM(2) ? Xeater_e : Xeater_w;
       play_element_sound(x, y, SOUND_eater, Xeater_n);
@@ -2107,6 +2140,18 @@ static void Leater_e(int x, int y)
 
   switch (Cave[x+1][y])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Xplant:
+    case Yplant:
+    case Zplayer:
+      Cave[x][y] = Yeater_eB;
+      Cave[x+1][y] = Yeater_e;
+      Next[x][y] = Xblank;
+      Next[x+1][y] = Xeater_e;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -2124,18 +2169,6 @@ static void Leater_e(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Xplant:
-    case Yplant:
-    case Zplayer:
-      Cave[x][y] = Yeater_eB;
-      Cave[x+1][y] = Yeater_e;
-      Next[x][y] = Xblank;
-      Next[x+1][y] = Xeater_e;
-      return;
-
     default:
       Next[x][y] = RANDOM(2) ? Xeater_n : Xeater_s;
       play_element_sound(x, y, SOUND_eater, Xeater_e);
@@ -2179,6 +2212,18 @@ static void Leater_s(int x, int y)
 
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Xplant:
+    case Yplant:
+    case Zplayer:
+      Cave[x][y] = Yeater_sB;
+      Cave[x][y+1] = Yeater_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xeater_s;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -2196,18 +2241,6 @@ static void Leater_s(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Xplant:
-    case Yplant:
-    case Zplayer:
-      Cave[x][y] = Yeater_sB;
-      Cave[x][y+1] = Yeater_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xeater_s;
-      return;
-
     default:
       Next[x][y] = RANDOM(2) ? Xeater_e : Xeater_w;
       play_element_sound(x, y, SOUND_eater, Xeater_s);
@@ -2251,6 +2284,18 @@ static void Leater_w(int x, int y)
 
   switch (Cave[x-1][y])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Xplant:
+    case Yplant:
+    case Zplayer:
+      Cave[x][y] = Yeater_wB;
+      Cave[x-1][y] = Yeater_w;
+      Next[x][y] = Xblank;
+      Next[x-1][y] = Xeater_w;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -2268,18 +2313,6 @@ static void Leater_w(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Xplant:
-    case Yplant:
-    case Zplayer:
-      Cave[x][y] = Yeater_wB;
-      Cave[x-1][y] = Yeater_w;
-      Next[x][y] = Xblank;
-      Next[x-1][y] = Xeater_w;
-      return;
-
     default:
       Next[x][y] = RANDOM(2) ? Xeater_n : Xeater_s;
       play_element_sound(x, y, SOUND_eater, Xeater_w);
@@ -2307,6 +2340,19 @@ static void Lalien(int x, int y)
     {
       switch (Cave[x][y-1])
       {
+       case Xblank:
+       case Xacid_splash_e:
+       case Xacid_splash_w:
+       case Xplant:
+       case Yplant:
+       case Zplayer:
+         Cave[x][y] = Yalien_nB;
+         Cave[x][y-1] = Yalien_n;
+         Next[x][y] = Xblank;
+         Next[x][y-1] = Xalien_pause;
+         play_element_sound(x, y, SOUND_alien, Xalien);
+         return;
+
        case Xacid_1:
        case Xacid_2:
        case Xacid_3:
@@ -2323,25 +2369,25 @@ static void Lalien(int x, int y)
          Next[x][y] = Xblank;
          play_element_sound(x, y, SOUND_acid, Xacid_1);
          return;
-
+      }
+    }
+    else if (y < dy)
+    {
+      switch (Cave[x][y+1])
+      {
        case Xblank:
        case Xacid_splash_e:
        case Xacid_splash_w:
        case Xplant:
        case Yplant:
        case Zplayer:
-         Cave[x][y] = Yalien_nB;
-         Cave[x][y-1] = Yalien_n;
+         Cave[x][y] = Yalien_sB;
+         Cave[x][y+1] = Yalien_s;
          Next[x][y] = Xblank;
-         Next[x][y-1] = Xalien_pause;
+         Next[x][y+1] = Xalien_pause;
          play_element_sound(x, y, SOUND_alien, Xalien);
          return;
-      }
-    }
-    else if (y < dy)
-    {
-      switch (Cave[x][y+1])
-      {
+
        case Xacid_1:
        case Xacid_2:
        case Xacid_3:
@@ -2358,19 +2404,6 @@ static void Lalien(int x, int y)
            Cave[x-1][y] = Xacid_splash_w;
          play_element_sound(x, y, SOUND_acid, Xacid_1);
          return;
-
-       case Xblank:
-       case Xacid_splash_e:
-       case Xacid_splash_w:
-       case Xplant:
-       case Yplant:
-       case Zplayer:
-         Cave[x][y] = Yalien_sB;
-         Cave[x][y+1] = Yalien_s;
-         Next[x][y] = Xblank;
-         Next[x][y+1] = Xalien_pause;
-         play_element_sound(x, y, SOUND_alien, Xalien);
-         return;
       }
     }
   }
@@ -2380,6 +2413,19 @@ static void Lalien(int x, int y)
     {
       switch (Cave[x+1][y])
       {
+       case Xblank:
+       case Xacid_splash_e:
+       case Xacid_splash_w:
+       case Xplant:
+       case Yplant:
+       case Zplayer:
+         Cave[x][y] = Yalien_eB;
+         Cave[x+1][y] = Yalien_e;
+         Next[x][y] = Xblank;
+         Next[x+1][y] = Xalien_pause;
+         play_element_sound(x, y, SOUND_alien, Xalien);
+         return;
+
        case Xacid_1:
        case Xacid_2:
        case Xacid_3:
@@ -2396,25 +2442,25 @@ static void Lalien(int x, int y)
          Next[x][y] = Xblank;
          play_element_sound(x, y, SOUND_acid, Xacid_1);
          return;
-
+      }
+    }
+    else if (x > dx)
+    {
+      switch (Cave[x-1][y])
+      {
        case Xblank:
        case Xacid_splash_e:
        case Xacid_splash_w:
        case Xplant:
        case Yplant:
        case Zplayer:
-         Cave[x][y] = Yalien_eB;
-         Cave[x+1][y] = Yalien_e;
+         Cave[x][y] = Yalien_wB;
+         Cave[x-1][y] = Yalien_w;
          Next[x][y] = Xblank;
-         Next[x+1][y] = Xalien_pause;
+         Next[x-1][y] = Xalien_pause;
          play_element_sound(x, y, SOUND_alien, Xalien);
          return;
-      }
-    }
-    else if (x > dx)
-    {
-      switch (Cave[x-1][y])
-      {
+
        case Xacid_1:
        case Xacid_2:
        case Xacid_3:
@@ -2431,19 +2477,6 @@ static void Lalien(int x, int y)
          Next[x][y] = Xblank;
          play_element_sound(x, y, SOUND_acid, Xacid_1);
          return;
-
-       case Xblank:
-       case Xacid_splash_e:
-       case Xacid_splash_w:
-       case Xplant:
-       case Yplant:
-       case Zplayer:
-         Cave[x][y] = Yalien_wB;
-         Cave[x-1][y] = Yalien_w;
-         Next[x][y] = Xblank;
-         Next[x-1][y] = Xalien_pause;
-         play_element_sound(x, y, SOUND_alien, Xalien);
-         return;
       }
     }
   }
@@ -2458,6 +2491,19 @@ static void Lbug_n(int x, int y)
 {
   switch (Cave[x][y-1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Xplant:
+    case Yplant:
+    case Zplayer:
+      Cave[x][y] = Ybug_nB;
+      Cave[x][y-1] = Ybug_n;
+      Next[x][y] = Xblank;
+      Next[x][y-1] = Xbug_1_n;
+      play_element_sound(x, y, SOUND_bug, Xbug_1_n);
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -2475,19 +2521,6 @@ static void Lbug_n(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Xplant:
-    case Yplant:
-    case Zplayer:
-      Cave[x][y] = Ybug_nB;
-      Cave[x][y-1] = Ybug_n;
-      Next[x][y] = Xblank;
-      Next[x][y-1] = Xbug_1_n;
-      play_element_sound(x, y, SOUND_bug, Xbug_1_n);
-      return;
-
     default:
       Cave[x][y] = Ybug_n_w;
       Next[x][y] = Xbug_2_w;
@@ -2503,7 +2536,7 @@ static void Lbug_1_n(int x, int y)
       tab_amoeba[Cave[x][y+1]] ||
       tab_amoeba[Cave[x-1][y]])
   {
-    Lboom_bug(x, y);
+    Lboom_bug(x, y, Xbug_1_n);
 
     return;
   }
@@ -2542,7 +2575,7 @@ static void Lbug_2_n(int x, int y)
       tab_amoeba[Cave[x][y+1]] ||
       tab_amoeba[Cave[x-1][y]])
   {
-    Lboom_bug(x, y);
+    Lboom_bug(x, y, Xbug_2_n);
 
     return;
   }
@@ -2554,6 +2587,19 @@ static void Lbug_e(int x, int y)
 {
   switch (Cave[x+1][y])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Xplant:
+    case Yplant:
+    case Zplayer:
+      Cave[x][y] = Ybug_eB;
+      Cave[x+1][y] = Ybug_e;
+      Next[x][y] = Xblank;
+      Next[x+1][y] = Xbug_1_e;
+      play_element_sound(x, y, SOUND_bug, Xbug_1_e);
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -2571,19 +2617,6 @@ static void Lbug_e(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Xplant:
-    case Yplant:
-    case Zplayer:
-      Cave[x][y] = Ybug_eB;
-      Cave[x+1][y] = Ybug_e;
-      Next[x][y] = Xblank;
-      Next[x+1][y] = Xbug_1_e;
-      play_element_sound(x, y, SOUND_bug, Xbug_1_e);
-      return;
-
     default:
       Cave[x][y] = Ybug_e_n;
       Next[x][y] = Xbug_2_n;
@@ -2599,7 +2632,7 @@ static void Lbug_1_e(int x, int y)
       tab_amoeba[Cave[x][y+1]] ||
       tab_amoeba[Cave[x-1][y]])
   {
-    Lboom_bug(x, y);
+    Lboom_bug(x, y, Xbug_1_e);
 
     return;
   }
@@ -2638,7 +2671,7 @@ static void Lbug_2_e(int x, int y)
       tab_amoeba[Cave[x][y+1]] ||
       tab_amoeba[Cave[x-1][y]])
   {
-    Lboom_bug(x, y);
+    Lboom_bug(x, y, Xbug_2_e);
 
     return;
   }
@@ -2646,10 +2679,23 @@ static void Lbug_2_e(int x, int y)
   Lbug_e(x, y);
 }
 
-static void Lbug_s(int x, int y)
-{
-  switch (Cave[x][y+1])
-  {
+static void Lbug_s(int x, int y)
+{
+  switch (Cave[x][y+1])
+  {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Xplant:
+    case Yplant:
+    case Zplayer:
+      Cave[x][y] = Ybug_sB;
+      Cave[x][y+1] = Ybug_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xbug_1_s;
+      play_element_sound(x, y, SOUND_bug, Xbug_1_s);
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -2667,19 +2713,6 @@ static void Lbug_s(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Xplant:
-    case Yplant:
-    case Zplayer:
-      Cave[x][y] = Ybug_sB;
-      Cave[x][y+1] = Ybug_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xbug_1_s;
-      play_element_sound(x, y, SOUND_bug, Xbug_1_s);
-      return;
-
     default:
       Cave[x][y] = Ybug_s_e;
       Next[x][y] = Xbug_2_e;
@@ -2695,7 +2728,7 @@ static void Lbug_1_s(int x, int y)
       tab_amoeba[Cave[x][y+1]] ||
       tab_amoeba[Cave[x-1][y]])
   {
-    Lboom_bug(x, y);
+    Lboom_bug(x, y, Xbug_1_s);
 
     return;
   }
@@ -2734,7 +2767,7 @@ static void Lbug_2_s(int x, int y)
       tab_amoeba[Cave[x][y+1]] ||
       tab_amoeba[Cave[x-1][y]])
   {
-    Lboom_bug(x, y);
+    Lboom_bug(x, y, Xbug_2_s);
 
     return;
   }
@@ -2746,6 +2779,19 @@ static void Lbug_w(int x, int y)
 {
   switch (Cave[x-1][y])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Xplant:
+    case Yplant:
+    case Zplayer:
+      Cave[x][y] = Ybug_wB;
+      Cave[x-1][y] = Ybug_w;
+      Next[x][y] = Xblank;
+      Next[x-1][y] = Xbug_1_w;
+      play_element_sound(x, y, SOUND_bug, Xbug_1_w);
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -2763,19 +2809,6 @@ static void Lbug_w(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Xplant:
-    case Yplant:
-    case Zplayer:
-      Cave[x][y] = Ybug_wB;
-      Cave[x-1][y] = Ybug_w;
-      Next[x][y] = Xblank;
-      Next[x-1][y] = Xbug_1_w;
-      play_element_sound(x, y, SOUND_bug, Xbug_1_w);
-      return;
-
     default:
       Cave[x][y] = Ybug_w_s;
       Next[x][y] = Xbug_2_s;
@@ -2791,7 +2824,7 @@ static void Lbug_1_w(int x, int y)
       tab_amoeba[Cave[x][y+1]] ||
       tab_amoeba[Cave[x-1][y]])
   {
-    Lboom_bug(x, y);
+    Lboom_bug(x, y, Xbug_1_w);
 
     return;
   }
@@ -2830,7 +2863,7 @@ static void Lbug_2_w(int x, int y)
       tab_amoeba[Cave[x][y+1]] ||
       tab_amoeba[Cave[x-1][y]])
   {
-    Lboom_bug(x, y);
+    Lboom_bug(x, y, Xbug_2_w);
 
     return;
   }
@@ -2842,6 +2875,19 @@ static void Ltank_n(int x, int y)
 {
   switch (Cave[x][y-1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Xplant:
+    case Yplant:
+    case Zplayer:
+      Cave[x][y] = Ytank_nB;
+      Cave[x][y-1] = Ytank_n;
+      Next[x][y] = Xblank;
+      Next[x][y-1] = Xtank_1_n;
+      play_element_sound(x, y, SOUND_tank, Xtank_1_n);
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -2859,19 +2905,6 @@ static void Ltank_n(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Xplant:
-    case Yplant:
-    case Zplayer:
-      Cave[x][y] = Ytank_nB;
-      Cave[x][y-1] = Ytank_n;
-      Next[x][y] = Xblank;
-      Next[x][y-1] = Xtank_1_n;
-      play_element_sound(x, y, SOUND_tank, Xtank_1_n);
-      return;
-
     default:
       Cave[x][y] = Ytank_n_e;
       Next[x][y] = Xtank_2_e;
@@ -2887,7 +2920,7 @@ static void Ltank_1_n(int x, int y)
       tab_amoeba[Cave[x][y+1]] ||
       tab_amoeba[Cave[x-1][y]])
   {
-    Lboom_tank(x, y);
+    Lboom_tank(x, y, Xtank_1_n);
 
     return;
   }
@@ -2926,7 +2959,7 @@ static void Ltank_2_n(int x, int y)
       tab_amoeba[Cave[x][y+1]] ||
       tab_amoeba[Cave[x-1][y]])
   {
-    Lboom_tank(x, y);
+    Lboom_tank(x, y, Xtank_2_n);
 
     return;
   }
@@ -2938,6 +2971,19 @@ static void Ltank_e(int x, int y)
 {
   switch (Cave[x+1][y])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Xplant:
+    case Yplant:
+    case Zplayer:
+      Cave[x][y] = Ytank_eB;
+      Cave[x+1][y] = Ytank_e;
+      Next[x][y] = Xblank;
+      Next[x+1][y] = Xtank_1_e;
+      play_element_sound(x, y, SOUND_tank, Xtank_1_e);
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -2955,19 +3001,6 @@ static void Ltank_e(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Xplant:
-    case Yplant:
-    case Zplayer:
-      Cave[x][y] = Ytank_eB;
-      Cave[x+1][y] = Ytank_e;
-      Next[x][y] = Xblank;
-      Next[x+1][y] = Xtank_1_e;
-      play_element_sound(x, y, SOUND_tank, Xtank_1_e);
-      return;
-
     default:
       Cave[x][y] = Ytank_e_s;
       Next[x][y] = Xtank_2_s;
@@ -2983,7 +3016,7 @@ static void Ltank_1_e(int x, int y)
       tab_amoeba[Cave[x][y+1]] ||
       tab_amoeba[Cave[x-1][y]])
   {
-    Lboom_tank(x, y);
+    Lboom_tank(x, y, Xtank_1_e);
 
     return;
   }
@@ -3022,7 +3055,7 @@ static void Ltank_2_e(int x, int y)
       tab_amoeba[Cave[x][y+1]] ||
       tab_amoeba[Cave[x-1][y]])
   {
-    Lboom_tank(x, y);
+    Lboom_tank(x, y, Xtank_2_e);
 
     return;
   }
@@ -3034,6 +3067,19 @@ static void Ltank_s(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Xplant:
+    case Yplant:
+    case Zplayer:
+      Cave[x][y] = Ytank_sB;
+      Cave[x][y+1] = Ytank_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xtank_1_s;
+      play_element_sound(x, y, SOUND_tank, Xtank_1_s);
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -3051,19 +3097,6 @@ static void Ltank_s(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Xplant:
-    case Yplant:
-    case Zplayer:
-      Cave[x][y] = Ytank_sB;
-      Cave[x][y+1] = Ytank_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xtank_1_s;
-      play_element_sound(x, y, SOUND_tank, Xtank_1_s);
-      return;
-
     default:
       Cave[x][y] = Ytank_s_w;
       Next[x][y] = Xtank_2_w;
@@ -3079,7 +3112,7 @@ static void Ltank_1_s(int x, int y)
       tab_amoeba[Cave[x][y+1]] ||
       tab_amoeba[Cave[x-1][y]])
   {
-    Lboom_tank(x, y);
+    Lboom_tank(x, y, Xtank_1_s);
 
     return;
   }
@@ -3118,7 +3151,7 @@ static void Ltank_2_s(int x, int y)
       tab_amoeba[Cave[x][y+1]] ||
       tab_amoeba[Cave[x-1][y]])
   {
-    Lboom_tank(x, y);
+    Lboom_tank(x, y, Xtank_2_s);
 
     return;
   }
@@ -3130,6 +3163,19 @@ static void Ltank_w(int x, int y)
 {
   switch (Cave[x-1][y])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Xplant:
+    case Yplant:
+    case Zplayer:
+      Cave[x][y] = Ytank_wB;
+      Cave[x-1][y] = Ytank_w;
+      Next[x][y] = Xblank;
+      Next[x-1][y] = Xtank_1_w;
+      play_element_sound(x, y, SOUND_tank, Xtank_1_w);
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -3147,19 +3193,6 @@ static void Ltank_w(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Xplant:
-    case Yplant:
-    case Zplayer:
-      Cave[x][y] = Ytank_wB;
-      Cave[x-1][y] = Ytank_w;
-      Next[x][y] = Xblank;
-      Next[x-1][y] = Xtank_1_w;
-      play_element_sound(x, y, SOUND_tank, Xtank_1_w);
-      return;
-
     default:
       Cave[x][y] = Ytank_w_n;
       Next[x][y] = Xtank_2_n;
@@ -3175,7 +3208,7 @@ static void Ltank_1_w(int x, int y)
       tab_amoeba[Cave[x][y+1]] ||
       tab_amoeba[Cave[x-1][y]])
   {
-    Lboom_tank(x, y);
+    Lboom_tank(x, y, Xtank_1_w);
 
     return;
   }
@@ -3214,7 +3247,7 @@ static void Ltank_2_w(int x, int y)
       tab_amoeba[Cave[x][y+1]] ||
       tab_amoeba[Cave[x-1][y]])
   {
-    Lboom_tank(x, y);
+    Lboom_tank(x, y, Xtank_2_w);
 
     return;
   }
@@ -3226,6 +3259,15 @@ static void Lemerald(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Yemerald_sB;
+      Cave[x][y+1] = Yemerald_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xemerald_fall;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -3243,15 +3285,6 @@ static void Lemerald(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Yemerald_sB;
-      Cave[x][y+1] = Yemerald_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xemerald_fall;
-      return;
-
     case Xspring:
     case Xspring_pause:
     case Xspring_e:
@@ -3361,6 +3394,15 @@ static void Lemerald_pause(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Yemerald_sB;
+      Cave[x][y+1] = Yemerald_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xemerald_fall;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -3378,15 +3420,6 @@ static void Lemerald_pause(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Yemerald_sB;
-      Cave[x][y+1] = Yemerald_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xemerald_fall;
-      return;
-
     default:
       Cave[x][y] = Xemerald;
       Next[x][y] = Xemerald;
@@ -3398,6 +3431,16 @@ static void Lemerald_fall(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Zplayer:
+      Cave[x][y] = Yemerald_sB;
+      Cave[x][y+1] = Yemerald_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xemerald_fall;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -3415,16 +3458,6 @@ static void Lemerald_fall(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Zplayer:
-      Cave[x][y] = Yemerald_sB;
-      Cave[x][y+1] = Yemerald_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xemerald_fall;
-      return;
-
     case Xwonderwall:
       if (lev.wonderwall_time)
       {
@@ -3453,6 +3486,15 @@ static void Ldiamond(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Ydiamond_sB;
+      Cave[x][y+1] = Ydiamond_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xdiamond_fall;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -3470,15 +3512,6 @@ static void Ldiamond(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Ydiamond_sB;
-      Cave[x][y+1] = Ydiamond_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xdiamond_fall;
-      return;
-
     case Xspring:
     case Xspring_pause:
     case Xspring_e:
@@ -3588,6 +3621,15 @@ static void Ldiamond_pause(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Ydiamond_sB;
+      Cave[x][y+1] = Ydiamond_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xdiamond_fall;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -3605,26 +3647,27 @@ static void Ldiamond_pause(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
+    default:
+      Cave[x][y] = Xdiamond;
+      Next[x][y] = Xdiamond;
+      return;
+  }
+}
+
+static void Ldiamond_fall(int x, int y)
+{
+  switch (Cave[x][y+1])
+  {
     case Xblank:
     case Xacid_splash_e:
     case Xacid_splash_w:
+    case Zplayer:
       Cave[x][y] = Ydiamond_sB;
       Cave[x][y+1] = Ydiamond_s;
       Next[x][y] = Xblank;
       Next[x][y+1] = Xdiamond_fall;
       return;
 
-    default:
-      Cave[x][y] = Xdiamond;
-      Next[x][y] = Xdiamond;
-      return;
-  }
-}
-
-static void Ldiamond_fall(int x, int y)
-{
-  switch (Cave[x][y+1])
-  {
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -3642,16 +3685,6 @@ static void Ldiamond_fall(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Zplayer:
-      Cave[x][y] = Ydiamond_sB;
-      Cave[x][y+1] = Ydiamond_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xdiamond_fall;
-      return;
-
     case Xwonderwall:
       if (lev.wonderwall_time)
       {
@@ -3680,23 +3713,6 @@ static void Lstone(int x, int y)
 {
   switch (Cave[x][y+1])
   {
-    case Xacid_1:
-    case Xacid_2:
-    case Xacid_3:
-    case Xacid_4:
-    case Xacid_5:
-    case Xacid_6:
-    case Xacid_7:
-    case Xacid_8:
-      Cave[x][y] = Ystone_sB;
-      if (Cave[x+1][y] == Xblank)
-       Cave[x+1][y] = Xacid_splash_e;
-      if (Cave[x-1][y] == Xblank)
-       Cave[x-1][y] = Xacid_splash_w;
-      Next[x][y] = Xblank;
-      play_element_sound(x, y, SOUND_acid, Xacid_1);
-      return;
-
     case Xblank:
     case Xacid_splash_e:
     case Xacid_splash_w:
@@ -3718,6 +3734,23 @@ static void Lstone(int x, int y)
       Next[x][y+1] = Xstone_fall;
       return;
 
+    case Xacid_1:
+    case Xacid_2:
+    case Xacid_3:
+    case Xacid_4:
+    case Xacid_5:
+    case Xacid_6:
+    case Xacid_7:
+    case Xacid_8:
+      Cave[x][y] = Ystone_sB;
+      if (Cave[x+1][y] == Xblank)
+       Cave[x+1][y] = Xacid_splash_e;
+      if (Cave[x-1][y] == Xblank)
+       Cave[x-1][y] = Xacid_splash_w;
+      Next[x][y] = Xblank;
+      play_element_sound(x, y, SOUND_acid, Xacid_1);
+      return;
+
     case Xsand:
       Cave[x][y] = Xsand_stonein_1;
       Cave[x][y+1] = Xsand_sandstone_1;
@@ -3818,23 +3851,6 @@ static void Lstone_pause(int x, int y)
 {
   switch (Cave[x][y+1])
   {
-    case Xacid_1:
-    case Xacid_2:
-    case Xacid_3:
-    case Xacid_4:
-    case Xacid_5:
-    case Xacid_6:
-    case Xacid_7:
-    case Xacid_8:
-      Cave[x][y] = Ystone_sB;
-      if (Cave[x+1][y] == Xblank)
-       Cave[x+1][y] = Xacid_splash_e;
-      if (Cave[x-1][y] == Xblank)
-       Cave[x-1][y] = Xacid_splash_w;
-      Next[x][y] = Xblank;
-      play_element_sound(x, y, SOUND_acid, Xacid_1);
-      return;
-
     case Xblank:
     case Xacid_splash_e:
     case Xacid_splash_w:
@@ -3854,17 +3870,6 @@ static void Lstone_pause(int x, int y)
       Next[x][y+1] = Xstone_fall;
       return;
 
-    default:
-      Cave[x][y] = Xstone;
-      Next[x][y] = Xstone;
-      return;
-  }
-}
-
-static void Lstone_fall(int x, int y)
-{
-  switch (Cave[x][y+1])
-  {
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -3882,6 +3887,17 @@ static void Lstone_fall(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
+    default:
+      Cave[x][y] = Xstone;
+      Next[x][y] = Xstone;
+      return;
+  }
+}
+
+static void Lstone_fall(int x, int y)
+{
+  switch (Cave[x][y+1])
+  {
     case Xblank:
     case Xacid_splash_e:
     case Xacid_splash_w:
@@ -3902,6 +3918,23 @@ static void Lstone_fall(int x, int y)
       Next[x][y+1] = Xstone_fall;
       return;
 
+    case Xacid_1:
+    case Xacid_2:
+    case Xacid_3:
+    case Xacid_4:
+    case Xacid_5:
+    case Xacid_6:
+    case Xacid_7:
+    case Xacid_8:
+      Cave[x][y] = Ystone_sB;
+      if (Cave[x+1][y] == Xblank)
+       Cave[x+1][y] = Xacid_splash_e;
+      if (Cave[x-1][y] == Xblank)
+       Cave[x-1][y] = Xacid_splash_w;
+      Next[x][y] = Xblank;
+      play_element_sound(x, y, SOUND_acid, Xacid_1);
+      return;
+
     case Xnut:
     case Xnut_pause:
       Cave[x][y+1] = Ynut_stone;
@@ -3921,19 +3954,7 @@ static void Lstone_fall(int x, int y)
     case Xbug_2_w:
       Cave[x][y] = Ystone_sB;
       Cave[x][y+1] = Ybug_stone;
-      Next[x][y+1] = Znormal;
-      Boom[x-1][y] = Xemerald;
-      Boom[x][y] = Xemerald;
-      Boom[x+1][y] = Xemerald;
-      Boom[x-1][y+1] = Xemerald;
-      Boom[x][y+1] = Xdiamond;
-      Boom[x+1][y+1] = Xemerald;
-      Boom[x-1][y+2] = Xemerald;
-      Boom[x][y+2] = Xemerald;
-      Boom[x+1][y+2] = Xemerald;
-#if PLAY_ELEMENT_SOUND
-      play_element_sound(x, y, SOUND_boom, Xstone_fall);
-#endif
+      Lboom_bug(x, y+1, Xstone_fall);
       score += lev.bug_score;
       return;
 
@@ -3947,19 +3968,7 @@ static void Lstone_fall(int x, int y)
     case Xtank_2_w:
       Cave[x][y] = Ystone_sB;
       Cave[x][y+1] = Ytank_stone;
-      Next[x][y+1] = Znormal;
-      Boom[x-1][y] = Xblank;
-      Boom[x][y] = Xblank;
-      Boom[x+1][y] = Xblank;
-      Boom[x-1][y+1] = Xblank;
-      Boom[x][y+1] = Xblank;
-      Boom[x+1][y+1] = Xblank;
-      Boom[x-1][y+2] = Xblank;
-      Boom[x][y+2] = Xblank;
-      Boom[x+1][y+2] = Xblank;
-#if PLAY_ELEMENT_SOUND
-      play_element_sound(x, y, SOUND_boom, Xstone_fall);
-#endif
+      Lboom_tank(x, y+1, Xstone_fall);
       score += lev.tank_score;
       return;
 
@@ -4007,20 +4016,7 @@ static void Lstone_fall(int x, int y)
     case Xeater_w:
       Cave[x][y] = Ystone_sB;
       Cave[x][y+1] = Yeater_stone;
-      Next[x][y+1] = Znormal;
-      Boom[x-1][y] = lev.eater_array[lev.eater_pos][0];
-      Boom[x][y] = lev.eater_array[lev.eater_pos][1];
-      Boom[x+1][y] = lev.eater_array[lev.eater_pos][2];
-      Boom[x-1][y+1] = lev.eater_array[lev.eater_pos][3];
-      Boom[x][y+1] = lev.eater_array[lev.eater_pos][4];
-      Boom[x+1][y+1] = lev.eater_array[lev.eater_pos][5];
-      Boom[x-1][y+2] = lev.eater_array[lev.eater_pos][6];
-      Boom[x][y+2] = lev.eater_array[lev.eater_pos][7];
-      Boom[x+1][y+2] = lev.eater_array[lev.eater_pos][8];
-#if PLAY_ELEMENT_SOUND
-      play_element_sound(x, y, SOUND_boom, Xstone_fall);
-#endif
-      lev.eater_pos = (lev.eater_pos + 1) & 7;
+      Lboom_eater(x, y+1, Xstone_fall);
       score += lev.eater_score;
       return;
 
@@ -4028,19 +4024,7 @@ static void Lstone_fall(int x, int y)
     case Xalien_pause:
       Cave[x][y] = Ystone_sB;
       Cave[x][y+1] = Yalien_stone;
-      Next[x][y+1] = Znormal;
-      Boom[x-1][y] = Xblank;
-      Boom[x][y] = Xblank;
-      Boom[x+1][y] = Xblank;
-      Boom[x-1][y+1] = Xblank;
-      Boom[x][y+1] = Xblank;
-      Boom[x+1][y+1] = Xblank;
-      Boom[x-1][y+2] = Xblank;
-      Boom[x][y+2] = Xblank;
-      Boom[x+1][y+2] = Xblank;
-#if PLAY_ELEMENT_SOUND
-      play_element_sound(x, y, SOUND_boom, Xstone_fall);
-#endif
+      Lboom_tank(x, y+1, Xstone_fall);
       score += lev.alien_score;
       return;
 
@@ -4109,19 +4093,7 @@ static void Lstone_fall(int x, int y)
     case Xbomb:
     case Xbomb_pause:
       Cave[x][y+1] = Ybomb_blank;
-      Next[x][y+1] = Znormal;
-      Boom[x-1][y] = Xblank;
-      Boom[x][y] = Xblank;
-      Boom[x+1][y] = Xblank;
-      Boom[x-1][y+1] = Xblank;
-      Boom[x][y+1] = Xblank;
-      Boom[x+1][y+1] = Xblank;
-      Boom[x-1][y+2] = Xblank;
-      Boom[x][y+2] = Xblank;
-      Boom[x+1][y+2] = Xblank;
-#if PLAY_ELEMENT_SOUND
-      play_element_sound(x, y, SOUND_boom, Xstone_fall);
-#endif
+      Lboom_tank(x, y+1, Xstone_fall);
       return;
 
     case Xwonderwall:
@@ -4153,6 +4125,15 @@ static void Lbomb(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Ybomb_sB;
+      Cave[x][y+1] = Ybomb_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xbomb_fall;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -4170,15 +4151,6 @@ static void Lbomb(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Ybomb_sB;
-      Cave[x][y+1] = Ybomb_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xbomb_fall;
-      return;
-
     case Xspring:
     case Xspring_pause:
     case Xspring_e:
@@ -4270,6 +4242,15 @@ static void Lbomb_pause(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Ybomb_sB;
+      Cave[x][y+1] = Ybomb_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xbomb_fall;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -4287,15 +4268,6 @@ static void Lbomb_pause(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Ybomb_sB;
-      Cave[x][y+1] = Ybomb_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xbomb_fall;
-      return;
-
     default:
       Cave[x][y] = Xbomb;
       Next[x][y] = Xbomb;
@@ -4307,6 +4279,15 @@ static void Lbomb_fall(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Ybomb_sB;
+      Cave[x][y+1] = Ybomb_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xbomb_fall;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -4324,30 +4305,9 @@ static void Lbomb_fall(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Ybomb_sB;
-      Cave[x][y+1] = Ybomb_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xbomb_fall;
-      return;
-
     default:
       Cave[x][y] = Ybomb_blank;
-      Next[x][y] = Znormal;
-      Boom[x-1][y-1] = Xblank;
-      Boom[x][y-1] = Xblank;
-      Boom[x+1][y-1] = Xblank;
-      Boom[x-1][y] = Xblank;
-      Boom[x][y] = Xblank;
-      Boom[x+1][y] = Xblank;
-      Boom[x-1][y+1] = Xblank;
-      Boom[x][y+1] = Xblank;
-      Boom[x+1][y+1] = Xblank;
-#if PLAY_ELEMENT_SOUND
-      play_element_sound(x, y, SOUND_boom, Xbomb_fall);
-#endif
+      Lboom_tank(x, y, Xbomb_fall);
       return;
   }
 }
@@ -4356,6 +4316,15 @@ static void Lnut(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Ynut_sB;
+      Cave[x][y+1] = Ynut_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xnut_fall;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -4373,15 +4342,6 @@ static void Lnut(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Ynut_sB;
-      Cave[x][y+1] = Ynut_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xnut_fall;
-      return;
-
     case Xspring:
     case Xspring_pause:
     case Xspring_e:
@@ -4473,6 +4433,15 @@ static void Lnut_pause(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Ynut_sB;
+      Cave[x][y+1] = Ynut_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xnut_fall;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -4490,15 +4459,6 @@ static void Lnut_pause(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Ynut_sB;
-      Cave[x][y+1] = Ynut_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xnut_fall;
-      return;
-
     default:
       Cave[x][y] = Xnut;
       Next[x][y] = Xnut;
@@ -4510,6 +4470,16 @@ static void Lnut_fall(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Zplayer:
+      Cave[x][y] = Ynut_sB;
+      Cave[x][y+1] = Ynut_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xnut_fall;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -4527,16 +4497,6 @@ static void Lnut_fall(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Zplayer:
-      Cave[x][y] = Ynut_sB;
-      Cave[x][y+1] = Ynut_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xnut_fall;
-      return;
-
     default:
       Cave[x][y] = Xnut;
       Next[x][y] = Xnut;
@@ -4549,6 +4509,17 @@ static void Lspring(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Xplant:
+    case Yplant:
+      Cave[x][y] = Yspring_sB;
+      Cave[x][y+1] = Yspring_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xspring_fall;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -4558,23 +4529,12 @@ static void Lspring(int x, int y)
     case Xacid_7:
     case Xacid_8:
       Cave[x][y] = Yspring_sB;
-      if (Cave[x+1][y] == Xblank)
-       Cave[x+1][y] = Xacid_splash_e;
-      if (Cave[x-1][y] == Xblank)
-       Cave[x-1][y] = Xacid_splash_w;
-      Next[x][y] = Xblank;
-      play_element_sound(x, y, SOUND_acid, Xacid_1);
-      return;
-
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Xplant:
-    case Yplant:
-      Cave[x][y] = Yspring_sB;
-      Cave[x][y+1] = Yspring_s;
+      if (Cave[x+1][y] == Xblank)
+       Cave[x+1][y] = Xacid_splash_e;
+      if (Cave[x-1][y] == Xblank)
+       Cave[x-1][y] = Xacid_splash_w;
       Next[x][y] = Xblank;
-      Next[x][y+1] = Xspring_fall;
+      play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
     case Xspring:
@@ -4696,6 +4656,15 @@ static void Lspring_pause(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Yspring_sB;
+      Cave[x][y+1] = Yspring_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xspring_fall;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -4713,15 +4682,6 @@ static void Lspring_pause(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Yspring_sB;
-      Cave[x][y+1] = Yspring_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xspring_fall;
-      return;
-
     default:
       Cave[x][y] = Xspring;
       Next[x][y] = Xspring;
@@ -4733,6 +4693,15 @@ static void Lspring_e(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Yspring_sB;
+      Cave[x][y+1] = Yspring_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xspring_fall;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -4750,21 +4719,25 @@ static void Lspring_e(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Yspring_sB;
-      Cave[x][y+1] = Yspring_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xspring_fall;
-      return;
-
     case Xbumper:
       Cave[x][y+1] = XbumperB;
   }
 
   switch (Cave[x+1][y])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Yalien_nB:
+    case Yalien_eB:
+    case Yalien_sB:
+    case Yalien_wB:
+      Cave[x][y] = Yspring_eB;
+      Cave[x+1][y] = Yspring_e;
+      Next[x][y] = Xblank;
+      Next[x+1][y] = Xspring_e;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -4782,19 +4755,6 @@ static void Lspring_e(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Yalien_nB:
-    case Yalien_eB:
-    case Yalien_sB:
-    case Yalien_wB:
-      Cave[x][y] = Yspring_eB;
-      Cave[x+1][y] = Yspring_e;
-      Next[x][y] = Xblank;
-      Next[x+1][y] = Xspring_e;
-      return;
-
     case Xalien:
     case Xalien_pause:
     case Yalien_n:
@@ -4828,6 +4788,15 @@ static void Lspring_w(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Yspring_sB;
+      Cave[x][y+1] = Yspring_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xspring_fall;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -4845,21 +4814,25 @@ static void Lspring_w(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Yspring_sB;
-      Cave[x][y+1] = Yspring_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xspring_fall;
-      return;
-
     case Xbumper:
       Cave[x][y+1] = XbumperB;
   }
 
   switch (Cave[x-1][y])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Yalien_nB:
+    case Yalien_eB:
+    case Yalien_sB:
+    case Yalien_wB:
+      Cave[x][y] = Yspring_wB;
+      Cave[x-1][y] = Yspring_w;
+      Next[x][y] = Xblank;
+      Next[x-1][y] = Xspring_w;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -4877,19 +4850,6 @@ static void Lspring_w(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Yalien_nB:
-    case Yalien_eB:
-    case Yalien_sB:
-    case Yalien_wB:
-      Cave[x][y] = Yspring_wB;
-      Cave[x-1][y] = Yspring_w;
-      Next[x][y] = Xblank;
-      Next[x-1][y] = Xspring_w;
-      return;
-
     case Xalien:
     case Xalien_pause:
     case Yalien_n:
@@ -4923,6 +4883,16 @@ static void Lspring_fall(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Zplayer:
+      Cave[x][y] = Yspring_sB;
+      Cave[x][y+1] = Yspring_s;
+      Next[x][y] = Xblank;
+      Next[x][y+1] = Xspring_fall;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -4940,32 +4910,10 @@ static void Lspring_fall(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Zplayer:
-      Cave[x][y] = Yspring_sB;
-      Cave[x][y+1] = Yspring_s;
-      Next[x][y] = Xblank;
-      Next[x][y+1] = Xspring_fall;
-      return;
-
     case Xbomb:
     case Xbomb_pause:
       Cave[x][y+1] = Ybomb_blank;
-      Next[x][y+1] = Znormal;
-      Boom[x-1][y] = Xblank;
-      Boom[x][y] = Xblank;
-      Boom[x+1][y] = Xblank;
-      Boom[x-1][y+1] = Xblank;
-      Boom[x][y+1] = Xblank;
-      Boom[x+1][y+1] = Xblank;
-      Boom[x-1][y+2] = Xblank;
-      Boom[x][y+2] = Xblank;
-      Boom[x+1][y+2] = Xblank;
-#if PLAY_ELEMENT_SOUND
-      play_element_sound(x, y, SOUND_boom, Xspring_fall);
-#endif
+      Lboom_tank(x, y+1, Xspring_fall);
       return;
 
     case Xbug_1_n:
@@ -4978,19 +4926,7 @@ static void Lspring_fall(int x, int y)
     case Xbug_2_w:
       Cave[x][y] = Yspring_sB;
       Cave[x][y+1] = Ybug_spring;
-      Next[x][y+1] = Znormal;
-      Boom[x-1][y] = Xemerald;
-      Boom[x][y] = Xemerald;
-      Boom[x+1][y] = Xemerald;
-      Boom[x-1][y+1] = Xemerald;
-      Boom[x][y+1] = Xdiamond;
-      Boom[x+1][y+1] = Xemerald;
-      Boom[x-1][y+2] = Xemerald;
-      Boom[x][y+2] = Xemerald;
-      Boom[x+1][y+2] = Xemerald;
-#if PLAY_ELEMENT_SOUND
-      play_element_sound(x, y, SOUND_boom, Xspring_fall);
-#endif
+      Lboom_bug(x, y+1, Xspring_fall);
       score += lev.bug_score;
       return;
 
@@ -5004,19 +4940,7 @@ static void Lspring_fall(int x, int y)
     case Xtank_2_w:
       Cave[x][y] = Yspring_sB;
       Cave[x][y+1] = Ytank_spring;
-      Next[x][y+1] = Znormal;
-      Boom[x-1][y] = Xblank;
-      Boom[x][y] = Xblank;
-      Boom[x+1][y] = Xblank;
-      Boom[x-1][y+1] = Xblank;
-      Boom[x][y+1] = Xblank;
-      Boom[x+1][y+1] = Xblank;
-      Boom[x-1][y+2] = Xblank;
-      Boom[x][y+2] = Xblank;
-      Boom[x+1][y+2] = Xblank;
-#if PLAY_ELEMENT_SOUND
-      play_element_sound(x, y, SOUND_boom, Xspring_fall);
-#endif
+      Lboom_tank(x, y+1, Xspring_fall);
       score += lev.tank_score;
       return;
 
@@ -5026,20 +4950,7 @@ static void Lspring_fall(int x, int y)
     case Xeater_w:
       Cave[x][y] = Yspring_sB;
       Cave[x][y+1] = Yeater_spring;
-      Next[x][y+1] = Znormal;
-      Boom[x-1][y] = lev.eater_array[lev.eater_pos][0];
-      Boom[x][y] = lev.eater_array[lev.eater_pos][1];
-      Boom[x+1][y] = lev.eater_array[lev.eater_pos][2];
-      Boom[x-1][y+1] = lev.eater_array[lev.eater_pos][3];
-      Boom[x][y+1] = lev.eater_array[lev.eater_pos][4];
-      Boom[x+1][y+1] = lev.eater_array[lev.eater_pos][5];
-      Boom[x-1][y+2] = lev.eater_array[lev.eater_pos][6];
-      Boom[x][y+2] = lev.eater_array[lev.eater_pos][7];
-      Boom[x+1][y+2] = lev.eater_array[lev.eater_pos][8];
-#if PLAY_ELEMENT_SOUND
-      play_element_sound(x, y, SOUND_boom, Xspring_fall);
-#endif
-      lev.eater_pos = (lev.eater_pos + 1) & 7;
+      Lboom_eater(x, y+1, Xspring_fall);
       score += lev.eater_score;
       return;
 
@@ -5047,19 +4958,7 @@ static void Lspring_fall(int x, int y)
     case Xalien_pause:
       Cave[x][y] = Yspring_sB;
       Cave[x][y+1] = Yalien_spring;
-      Next[x][y+1] = Znormal;
-      Boom[x-1][y] = Xblank;
-      Boom[x][y] = Xblank;
-      Boom[x+1][y] = Xblank;
-      Boom[x-1][y+1] = Xblank;
-      Boom[x][y+1] = Xblank;
-      Boom[x+1][y+1] = Xblank;
-      Boom[x-1][y+2] = Xblank;
-      Boom[x][y+2] = Xblank;
-      Boom[x+1][y+2] = Xblank;
-#if PLAY_ELEMENT_SOUND
-      play_element_sound(x, y, SOUND_boom, Xspring_fall);
-#endif
+      Lboom_tank(x, y+1, Xspring_fall);
       score += lev.alien_score;
       return;
 
@@ -5393,15 +5292,8 @@ static void Ldynamite_4(int x, int y)
 {
   play_element_sound(x, y, SOUND_tick, Xdynamite_4);
   Next[x][y] = Zdynamite;
-  Boom[x-1][y-1] = Xblank;
-  Boom[x][y-1] = Xblank;
-  Boom[x+1][y-1] = Xblank;
-  Boom[x-1][y] = Xblank;
-  Boom[x][y] = Xblank;
-  Boom[x+1][y] = Xblank;
-  Boom[x-1][y+1] = Xblank;
-  Boom[x][y+1] = Xblank;
-  Boom[x+1][y+1] = Xblank;
+
+  Lboom_generic(x, y, Xblank, Xblank);
 }
 
 static void Lfake_door_1(int x, int y)
@@ -5462,6 +5354,15 @@ static void Lballoon(int x, int y)
     case 0: /* north */
       switch (Cave[x][y-1])
       {
+       case Xblank:
+       case Xacid_splash_e:
+       case Xacid_splash_w:
+         Cave[x][y] = Yballoon_nB;
+         Cave[x][y-1] = Yballoon_n;
+         Next[x][y] = Xblank;
+         Next[x][y-1] = Xballoon;
+         return;
+
        case Xacid_1:
        case Xacid_2:
        case Xacid_3:
@@ -5478,21 +5379,21 @@ static void Lballoon(int x, int y)
          Next[x][y] = Xblank;
          play_element_sound(x, y, SOUND_acid, Xacid_1);
          return;
+      }
+      break;
 
+    case 1: /* east */
+      switch (Cave[x+1][y])
+      {
        case Xblank:
        case Xacid_splash_e:
        case Xacid_splash_w:
-         Cave[x][y] = Yballoon_nB;
-         Cave[x][y-1] = Yballoon_n;
+         Cave[x][y] = Yballoon_eB;
+         Cave[x+1][y] = Yballoon_e;
          Next[x][y] = Xblank;
-         Next[x][y-1] = Xballoon;
+         Next[x+1][y] = Xballoon;
          return;
-      }
-      break;
 
-    case 1: /* east */
-      switch (Cave[x+1][y])
-      {
        case Xacid_1:
        case Xacid_2:
        case Xacid_3:
@@ -5509,21 +5410,21 @@ static void Lballoon(int x, int y)
          Next[x][y] = Xblank;
          play_element_sound(x, y, SOUND_acid, Xacid_1);
          return;
+      }
+      break;
 
+    case 2: /* south */
+      switch (Cave[x][y+1])
+      {
        case Xblank:
        case Xacid_splash_e:
        case Xacid_splash_w:
-         Cave[x][y] = Yballoon_eB;
-         Cave[x+1][y] = Yballoon_e;
+         Cave[x][y] = Yballoon_sB;
+         Cave[x][y+1] = Yballoon_s;
          Next[x][y] = Xblank;
-         Next[x+1][y] = Xballoon;
+         Next[x][y+1] = Xballoon;
          return;
-      }
-      break;
 
-    case 2: /* south */
-      switch (Cave[x][y+1])
-      {
        case Xacid_1:
        case Xacid_2:
        case Xacid_3:
@@ -5540,21 +5441,21 @@ static void Lballoon(int x, int y)
          Next[x][y] = Xblank;
          play_element_sound(x, y, SOUND_acid, Xacid_1);
          return;
+      }
+      break;
 
+    case 3: /* west */
+      switch (Cave[x-1][y])
+      {
        case Xblank:
        case Xacid_splash_e:
        case Xacid_splash_w:
-         Cave[x][y] = Yballoon_sB;
-         Cave[x][y+1] = Yballoon_s;
+         Cave[x][y] = Yballoon_wB;
+         Cave[x-1][y] = Yballoon_w;
          Next[x][y] = Xblank;
-         Next[x][y+1] = Xballoon;
+         Next[x-1][y] = Xballoon;
          return;
-      }
-      break;
 
-    case 3: /* west */
-      switch (Cave[x-1][y])
-      {
        case Xacid_1:
        case Xacid_2:
        case Xacid_3:
@@ -5571,15 +5472,6 @@ static void Lballoon(int x, int y)
          Next[x][y] = Xblank;
          play_element_sound(x, y, SOUND_acid, Xacid_1);
          return;
-
-       case Xblank:
-       case Xacid_splash_e:
-       case Xacid_splash_w:
-         Cave[x][y] = Yballoon_wB;
-         Cave[x-1][y] = Yballoon_w;
-         Next[x][y] = Xblank;
-         Next[x-1][y] = Xballoon;
-         return;
       }
       break;
   }
@@ -5765,6 +5657,18 @@ static void Ldrip_fall(int x, int y)
 
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+    case Xplant:
+    case Yplant:
+    case Zplayer:
+      Cave[x][y] = Ydrip_1_sB;
+      Cave[x][y+1] = Ydrip_1_s;
+      Next[x][y] = Xdrip_stretchB;
+      Next[x][y+1] = Xdrip_stretch;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -5782,18 +5686,6 @@ static void Ldrip_fall(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-    case Xplant:
-    case Yplant:
-    case Zplayer:
-      Cave[x][y] = Ydrip_1_sB;
-      Cave[x][y+1] = Ydrip_1_s;
-      Next[x][y] = Xdrip_stretchB;
-      Next[x][y+1] = Xdrip_stretch;
-      return;
-
     default:
       switch (RANDOM(8))
       {
@@ -5869,6 +5761,15 @@ static void Lsand_stone(int x, int y)
 {
   switch (Cave[x][y+1])
   {
+    case Xblank:
+    case Xacid_splash_e:
+    case Xacid_splash_w:
+      Cave[x][y] = Xsand_stonesand_quickout_1;
+      Cave[x][y+1] = Xsand_stoneout_1;
+      Next[x][y] = Xsand_stonesand_quickout_2;
+      Next[x][y+1] = Xsand_stoneout_2;
+      return;
+
     case Xacid_1:
     case Xacid_2:
     case Xacid_3:
@@ -5886,15 +5787,6 @@ static void Lsand_stone(int x, int y)
       play_element_sound(x, y, SOUND_acid, Xacid_1);
       return;
 
-    case Xblank:
-    case Xacid_splash_e:
-    case Xacid_splash_w:
-      Cave[x][y] = Xsand_stonesand_quickout_1;
-      Cave[x][y+1] = Xsand_stoneout_1;
-      Next[x][y] = Xsand_stonesand_quickout_2;
-      Next[x][y+1] = Xsand_stoneout_2;
-      return;
-
     case Xsand:
       Cave[x][y] = Xsand_stonesand_1;
       Cave[x][y+1] = Xsand_sandstone_1;
@@ -6091,11 +5983,11 @@ static void Lexplode(int x, int y)
   switch (Cave[x][y])
   {
     case Znormal:
-      Cave[x][y] = Xboom_1;
-      Cave[x][y-1] = tab_explode_normal[Cave[x][y-1]];
-      Cave[x-1][y] = tab_explode_normal[Cave[x-1][y]];
-      Cave[x+1][y] = tab_explode_normal[Cave[x+1][y]];
-      Cave[x][y+1] = tab_explode_normal[Cave[x][y+1]];
+      Cave[x][y]     = Xboom_1;
+      Cave[x][y-1]   = tab_explode_normal[Cave[x][y-1]];
+      Cave[x-1][y]   = tab_explode_normal[Cave[x-1][y]];
+      Cave[x+1][y]   = tab_explode_normal[Cave[x+1][y]];
+      Cave[x][y+1]   = tab_explode_normal[Cave[x][y+1]];
       Cave[x-1][y-1] = tab_explode_normal[Cave[x-1][y-1]];
       Cave[x+1][y-1] = tab_explode_normal[Cave[x+1][y-1]];
       Cave[x-1][y+1] = tab_explode_normal[Cave[x-1][y+1]];
@@ -6103,11 +5995,11 @@ static void Lexplode(int x, int y)
       break;
 
     case Zdynamite:
-      Cave[x][y] = Xboom_1;
-      Cave[x][y-1] = tab_explode_dynamite[Cave[x][y-1]];
-      Cave[x-1][y] = tab_explode_dynamite[Cave[x-1][y]];
-      Cave[x+1][y] = tab_explode_dynamite[Cave[x+1][y]];
-      Cave[x][y+1] = tab_explode_dynamite[Cave[x][y+1]];
+      Cave[x][y]     = Xboom_1;
+      Cave[x][y-1]   = tab_explode_dynamite[Cave[x][y-1]];
+      Cave[x-1][y]   = tab_explode_dynamite[Cave[x-1][y]];
+      Cave[x+1][y]   = tab_explode_dynamite[Cave[x+1][y]];
+      Cave[x][y+1]   = tab_explode_dynamite[Cave[x][y+1]];
       Cave[x-1][y-1] = tab_explode_dynamite[Cave[x-1][y-1]];
       Cave[x+1][y-1] = tab_explode_dynamite[Cave[x+1][y-1]];
       Cave[x-1][y+1] = tab_explode_dynamite[Cave[x-1][y+1]];
@@ -6304,8 +6196,8 @@ static void handle_tile(int x, int y)
 
     case Xpause:               Lpause(x, y);                   break;
 
-    case Xboom_bug:            Lboom_bug(x, y);                break;
-    case Xboom_bomb:           Lboom_tank(x, y);               break;
+    case Xboom_bug:            Lboom_bug(x, y, Xboom_bug);     break;
+    case Xboom_bomb:           Lboom_tank(x, y, Xboom_bomb);   break;
     case Xboom_android:                Lboom_android(x, y);            break;
     case Xboom_1:              Lboom_1(x, y);                  break;
     case Xboom_2:              Lboom_2(x, y);                  break;