fixed bug in single button handling causing broken tapes (EM engine)
[rocksndiamonds.git] / src / game_em / synchro_2.c
index 5079b7c253d7b31a8339f97aaf0b1b67bb99d46c..8fc7ada1d9e91dcafebc7982380d7427d0d68d74 100644 (file)
@@ -8,10 +8,7 @@
  * compilers suck.
  */
 
-#include "display.h"
-#include "tile.h"
-#include "level.h"
-#include "sample.h"
+#include "main_em.h"
 
 
 #define RANDOM (random = random << 31 | random >> 1)
@@ -44,15 +41,15 @@ static void set_nearest_player_xy(int x, int y, int *dx, int *dy)
 
 void synchro_2(void)
 {
-  register unsigned int x = 0;
-  register unsigned int y = 1;
-  register unsigned long random = RandomEM;
-  register unsigned short *cave_cache = Cave[y]; /* might be a win */
-  unsigned long score = 0;
-
-  unsigned int temp = 0;       /* initialized to make compilers happy */
-  unsigned int dx; /* only needed to find closest player */
-  unsigned int dy;
+  int x = 0;
+  int y = 1;
+  unsigned int random = RandomEM;
+  short *cave_cache = Cave[y]; /* might be a win */
+  int score = 0;
+
+  int temp = 0;                        /* initialized to make compilers happy */
+  int dx;                      /* only needed to find closest player */
+  int dy;
   int element;
 
  loop:
@@ -614,7 +611,7 @@ void synchro_2(void)
          Boom[y+2][x-1] = Xemerald;
          Boom[y+2][x] = Xemerald;
          Boom[y+2][x+1] = Xemerald;
-#if 0
+#if PLAY_ELEMENT_SOUND
          play_element_sound(x, y, SAMPLE_boom, element);
 #endif
          score += lev.bug_score;
@@ -640,7 +637,7 @@ void synchro_2(void)
          Boom[y+2][x-1] = Xblank;
          Boom[y+2][x] = Xblank;
          Boom[y+2][x+1] = Xblank;
-#if 0
+#if PLAY_ELEMENT_SOUND
          play_element_sound(x, y, SAMPLE_boom, element);
 #endif
          score += lev.tank_score;
@@ -700,7 +697,7 @@ void synchro_2(void)
          Boom[y+2][x-1] = lev.eater_array[lev.eater_pos][6];
          Boom[y+2][x] = lev.eater_array[lev.eater_pos][7];
          Boom[y+2][x+1] = lev.eater_array[lev.eater_pos][8];
-#if 0
+#if PLAY_ELEMENT_SOUND
          play_element_sound(x, y, SAMPLE_boom, element);
 #endif
          lev.eater_pos = (lev.eater_pos + 1) & 7;
@@ -721,7 +718,7 @@ void synchro_2(void)
          Boom[y+2][x-1] = Xblank;
          Boom[y+2][x] = Xblank;
          Boom[y+2][x+1] = Xblank;
-#if 0
+#if PLAY_ELEMENT_SOUND
          play_element_sound(x, y, SAMPLE_boom, element);
 #endif
          score += lev.alien_score;
@@ -802,7 +799,7 @@ void synchro_2(void)
          Boom[y+2][x-1] = Xblank;
          Boom[y+2][x] = Xblank;
          Boom[y+2][x+1] = Xblank;
-#if 0
+#if PLAY_ELEMENT_SOUND
          play_element_sound(x, y, SAMPLE_boom, element);
 #endif
          goto loop;
@@ -1905,46 +1902,8 @@ void synchro_2(void)
            Cave[y+1][x+1] == Zplayer)
          goto android_still;
 
-#if 1
-
        set_nearest_player_xy(x, y, &dx, &dy);
 
-#else
-
-       if (ply1.alive && ply2.alive)
-       {
-         if ((ply1.x > x ? ply1.x - x : x - ply1.x) +
-             (ply1.y > y ? ply1.y - y : y - ply1.y) <
-             (ply2.x > x ? ply2.x - x : x - ply2.x) +
-             (ply2.y > y ? ply2.y - y : y - ply2.y))
-         {
-           dx = ply1.x;
-           dy = ply1.y;
-         }
-         else
-         {
-           dx = ply2.x;
-           dy = ply2.y;
-         }
-       }
-       else if (ply1.alive)
-       {
-         dx = ply1.x;
-         dy = ply1.y;
-       }
-       else if (ply2.alive)
-       {
-         dx = ply2.x;
-         dy = ply2.y;
-       }
-       else
-       {
-         dx = 0;
-         dy = 0;
-       }
-
-#endif
-
        Next[y][x] = Xblank;    /* assume we will move */
        temp = ((x < dx) + 1 - (x > dx)) + ((y < dy) + 1 - (y > dy)) * 3;
 
@@ -2841,7 +2800,7 @@ void synchro_2(void)
          Boom[y+2][x-1] = Xblank;
          Boom[y+2][x] = Xblank;
          Boom[y+2][x+1] = Xblank;
-#if 0
+#if PLAY_ELEMENT_SOUND
          play_element_sound(x, y, SAMPLE_boom, element);
 #endif
          goto loop;
@@ -2866,7 +2825,7 @@ void synchro_2(void)
          Boom[y+2][x-1] = Xemerald;
          Boom[y+2][x] = Xemerald;
          Boom[y+2][x+1] = Xemerald;
-#if 0
+#if PLAY_ELEMENT_SOUND
          play_element_sound(x, y, SAMPLE_boom, element);
 #endif
          score += lev.bug_score;
@@ -2892,7 +2851,7 @@ void synchro_2(void)
          Boom[y+2][x-1] = Xblank;
          Boom[y+2][x] = Xblank;
          Boom[y+2][x+1] = Xblank;
-#if 0
+#if PLAY_ELEMENT_SOUND
          play_element_sound(x, y, SAMPLE_boom, element);
 #endif
          score += lev.tank_score;
@@ -2914,7 +2873,7 @@ void synchro_2(void)
          Boom[y+2][x-1] = lev.eater_array[lev.eater_pos][6];
          Boom[y+2][x] = lev.eater_array[lev.eater_pos][7];
          Boom[y+2][x+1] = lev.eater_array[lev.eater_pos][8];
-#if 0
+#if PLAY_ELEMENT_SOUND
          play_element_sound(x, y, SAMPLE_boom, element);
 #endif
          lev.eater_pos = (lev.eater_pos + 1) & 7;
@@ -2935,7 +2894,7 @@ void synchro_2(void)
          Boom[y+2][x-1] = Xblank;
          Boom[y+2][x] = Xblank;
          Boom[y+2][x+1] = Xblank;
-#if 0
+#if PLAY_ELEMENT_SOUND
          play_element_sound(x, y, SAMPLE_boom, element);
 #endif
          score += lev.alien_score;
@@ -3240,8 +3199,6 @@ void synchro_2(void)
 
     case Xalien:
 
-#if 1
-
       if (lev.wheel_cnt)
       {
        dx = lev.wheel_x;
@@ -3252,47 +3209,6 @@ void synchro_2(void)
        set_nearest_player_xy(x, y, &dx, &dy);
       }
 
-#else
-
-      if (lev.wheel_cnt)
-      {
-       dx = lev.wheel_x;
-       dy = lev.wheel_y;
-      }
-      else if (ply1.alive && ply2.alive)
-      {
-       if ((ply1.x > x ? ply1.x - x : x - ply1.x) +
-           (ply1.y > y ? ply1.y - y : y - ply1.y) <
-           (ply2.x > x ? ply2.x - x : x - ply2.x) +
-           (ply2.y > y ? ply2.y - y : y - ply2.y))
-       {
-         dx = ply1.x;
-         dy = ply1.y;
-       }
-       else
-       {
-         dx = ply2.x;
-         dy = ply2.y;
-       }
-      }
-      else if (ply1.alive)
-      {
-       dx = ply1.x;
-       dy = ply1.y;
-      }
-      else if (ply2.alive)
-      {
-       dx = ply2.x;
-       dy = ply2.y;
-      }
-      else
-      {
-       dx = 0;
-       dy = 0;
-      }
-
-#endif
-
       if (RANDOM & 1)
       {
        if (y > dy)
@@ -4192,7 +4108,7 @@ void synchro_2(void)
          Boom[y+1][x-1] = Xblank;
          Boom[y+1][x] = Xblank;
          Boom[y+1][x+1] = Xblank;
-#if 0
+#if PLAY_ELEMENT_SOUND
          play_element_sound(x, y, SAMPLE_boom, element);
 #endif
          goto loop;
@@ -4568,11 +4484,8 @@ void synchro_2(void)
        }
       }
 
-#if 1
       lev.ball_pos = (lev.ball_pos + 1) % lev.num_ball_arrays;
-#else
-      lev.ball_pos = (lev.ball_pos + 1) & 7;
-#endif
+
       goto loop;
 
     /* --------------------------------------------------------------------- */
@@ -4719,21 +4632,21 @@ void synchro_2(void)
        case Xacid_6:
        case Xacid_7:
        case Xacid_8:
-         Cave[y][x] = Xsand_stonesand_3;
+         Cave[y][x] = Xsand_stonesand_quickout_1;
          if (Cave[y][x+1] == Xblank)
            Cave[y][x+1] = Yacid_splash_eB;
          if (Cave[y][x-1] == Xblank)
            Cave[y][x-1] = Yacid_splash_wB;
-         Next[y][x] = Xsand_stonesand_4;
+         Next[y][x] = Xsand_stonesand_quickout_2;
          play_element_sound(x, y, SAMPLE_acid, Xacid_1);
          goto loop;
 
        case Xblank:
        case Yacid_splash_eB:
        case Yacid_splash_wB:
-         Cave[y][x] = Xsand_stonesand_3;
+         Cave[y][x] = Xsand_stonesand_quickout_1;
          Cave[y+1][x] = Xsand_stoneout_1;
-         Next[y][x] = Xsand_stonesand_4;
+         Next[y][x] = Xsand_stonesand_quickout_2;
          Next[y+1][x] = Xsand_stoneout_2;
          goto loop;
 
@@ -4780,6 +4693,16 @@ void synchro_2(void)
       Next[y][x] = Xsand;
       goto loop;
 
+#if 1
+    case Xsand_stonesand_quickout_1:
+      Next[y][x] = Xsand_stonesand_quickout_2;
+      goto loop;
+
+    case Xsand_stonesand_quickout_2:
+      Next[y][x] = Xsand;
+      goto loop;
+#endif
+
     case Xsand_stoneout_1:
       Next[y][x] = Xsand_stoneout_2;
       goto loop;
@@ -4881,7 +4804,7 @@ void synchro_2(void)
       Boom[y+1][x-1] = Xemerald;
       Boom[y+1][x] = Xemerald;
       Boom[y+1][x+1] = Xemerald;
-#if 0
+#if PLAY_ELEMENT_SOUND
       play_element_sound(x, y, SAMPLE_boom, element);
 #endif
       goto loop;
@@ -4900,19 +4823,22 @@ void synchro_2(void)
       Boom[y+1][x-1] = Xblank;
       Boom[y+1][x] = Xblank;
       Boom[y+1][x+1] = Xblank;
-#if 0
+#if PLAY_ELEMENT_SOUND
       play_element_sound(x, y, SAMPLE_boom, element);
 #endif
       goto loop;
 
     case Xboom_android:
-#if 0
+#if PLAY_ELEMENT_SOUND
       play_element_sound(x, y, SAMPLE_boom, Xandroid);
 #endif
     case Xboom_1:
       Next[y][x] = Xboom_2;
-#if 1
-      play_sound(x, y, SAMPLE_boom);
+#if !PLAY_ELEMENT_SOUND
+      if (x != lev.exit_x && y != lev.exit_y)
+       play_sound(x, y, SAMPLE_boom);
+      else
+       lev.exit_x = lev.exit_y = -1;
 #endif
       goto loop;