fixed element scores for MM style elements (MM engine)
[rocksndiamonds.git] / src / game_mm / mm_game.c
index 5a9470999aa3bd2a1119034cb86e1b540f30b608..e2a2e5f8745093c0387e208640e44a1128d6c26f 100644 (file)
@@ -73,7 +73,7 @@
 #define INIT_GAME_ACTIONS_DELAY        (ONE_SECOND_DELAY / GAME_FRAME_DELAY)
 #define NUM_INIT_CYCLE_STEPS   16
 #define PACMAN_MOVE_DELAY      12
-#define ENERGY_DELAY           (4 * ONE_SECOND_DELAY / GAME_FRAME_DELAY)
+#define ENERGY_DELAY           (ONE_SECOND_DELAY / GAME_FRAME_DELAY)
 #define HEALTH_DEC_DELAY       3
 #define HEALTH_INC_DELAY       9
 #define HEALTH_DELAY(x)                ((x) ? HEALTH_DEC_DELAY : HEALTH_INC_DELAY)
@@ -92,6 +92,7 @@
 static int MovingOrBlocked2Element_MM(int, int);
 static void Bang_MM(int, int);
 static void RaiseScore_MM(int);
+static void RaiseScoreElement_MM(int);
 static void RemoveMovingField_MM(int, int);
 static void InitMovingField_MM(int, int, int);
 static void ContinueMoving_MM(int, int);
@@ -100,6 +101,19 @@ static void Moving2Blocked_MM(int, int, int *, int *);
 /* bitmap for laser beam detection */
 static Bitmap *laser_bitmap = NULL;
 
+/* variables for laser control */
+static int last_LX = 0, last_LY = 0, last_hit_mask = 0;
+static int hold_x = -1, hold_y = -1;
+
+/* variables for pacman control */
+static int pacman_nr = -1;
+
+/* various game engine delay counters */
+static unsigned int rotate_delay = 0;
+static unsigned int pacman_delay = 0;
+static unsigned int energy_delay = 0;
+static unsigned int overload_delay = 0;
+
 /* element masks for scanning pixels of MM elements */
 static const char mm_masks[10][16][16 + 1] =
 {
@@ -341,6 +355,60 @@ static boolean CheckLaserPixel(int x, int y)
   return (pixel == WHITE_PIXEL);
 }
 
+static void CheckExitMM()
+{
+  int exit_element = EL_EMPTY;
+  int exit_x = 0;
+  int exit_y = 0;
+  int x, y;
+  static int xy[4][2] =
+  {
+    { +1,  0 },
+    {  0, -1 },
+    { -1,  0 },
+    {  0, +1 }
+  };
+
+  for (y = 0; y < lev_fieldy; y++)
+  {
+    for (x = 0; x < lev_fieldx; x++)
+    {
+      if (Feld[x][y] == EL_EXIT_CLOSED)
+      {
+       /* initiate opening animation of exit door */
+       Feld[x][y] = EL_EXIT_OPENING;
+
+       exit_element = EL_EXIT_OPEN;
+       exit_x = x;
+       exit_y = y;
+      }
+      else if (IS_RECEIVER(Feld[x][y]))
+      {
+       /* remove field that blocks receiver */
+       int phase = Feld[x][y] - EL_RECEIVER_START;
+       int blocking_x, blocking_y;
+
+       blocking_x = x + xy[phase][0];
+       blocking_y = y + xy[phase][1];
+
+       if (IN_LEV_FIELD(blocking_x, blocking_y))
+       {
+         Feld[blocking_x][blocking_y] = EL_EMPTY;
+
+         DrawField_MM(blocking_x, blocking_y);
+       }
+
+       exit_element = EL_RECEIVER;
+       exit_x = x;
+       exit_y = y;
+      }
+    }
+  }
+
+  if (exit_element != EL_EMPTY)
+    PlayLevelSound_MM(exit_x, exit_y, exit_element, MM_ACTION_OPENING);
+}
+
 static void InitMovDir_MM(int x, int y)
 {
   int element = Feld[x][y];
@@ -555,8 +623,24 @@ void InitGameEngine_MM()
   laser.dest_element = EL_EMPTY;
   laser.wall_mask = 0;
 
+  last_LX = 0;
+  last_LY = 0;
+  last_hit_mask = 0;
+
+  hold_x = -1;
+  hold_y = -1;
+
+  pacman_nr = -1;
+
   CT = Ct = 0;
 
+  rotate_delay = 0;
+  pacman_delay = 0;
+  energy_delay = 0;
+  overload_delay = 0;
+
+  ClickElement(-1, -1, -1);
+
   for (x = 0; x < lev_fieldx; x++)
   {
     for (y = 0; y < lev_fieldy; y++)
@@ -654,6 +738,9 @@ void InitGameActions_MM()
 #endif
 
   ScanLaser();
+
+  if (game_mm.kettles_still_needed == 0)
+    CheckExitMM();
 }
 
 void AddLaserEdge(int lx, int ly)
@@ -1210,7 +1297,7 @@ void DrawLaser(int start_edge, int mode)
       int num_beamers = laser.num_beamers;
 
       /* delete laser segments backward from the end to the first beamer */
-      for (i = num_beamers-1; i >= 0; i--)
+      for (i = num_beamers - 1; i >= 0; i--)
       {
        int tmp_num_edges = last_num_edges - laser.beamer_edge[i];
 
@@ -1229,6 +1316,11 @@ void DrawLaser(int start_edge, int mode)
               last_num_edges, start_edge);
 #endif
 
+      // special case when rotating first beamer: delete laser edge on beamer
+      // (but do not start scanning on previous edge to prevent mirror sound)
+      if (last_num_edges - start_edge == 1 && start_edge > 0)
+       DrawLaserLines(&laser.edge[start_edge - 1], 2, DL_LASER_DISABLED);
+
       /* delete first segment from start to the first beamer */
       DrawLaserExt(start_edge, last_num_edges - start_edge, DL_LASER_DISABLED);
     }
@@ -1436,48 +1528,9 @@ boolean HitElement(int element, int hit_mask)
       if (game_mm.kettles_still_needed > 0)
        game_mm.kettles_still_needed--;
 
-      RaiseScore_MM(10);
-
       if (game_mm.kettles_still_needed == 0)
       {
-       int exit_element = (element == EL_KETTLE ? EL_EXIT_OPEN : EL_RECEIVER);
-       int x, y;
-       static int xy[4][2] =
-       {
-         { +1,  0 },
-         {  0, -1 },
-         { -1,  0 },
-         {  0, +1 }
-       };
-
-       PlayLevelSound_MM(ELX, ELY, exit_element, MM_ACTION_OPENING);
-
-       for (y = 0; y < lev_fieldy; y++)
-       {
-         for (x = 0; x < lev_fieldx; x++)
-         {
-           /* initiate opening animation of exit door */
-           if (Feld[x][y] == EL_EXIT_CLOSED)
-             Feld[x][y] = EL_EXIT_OPENING;
-
-           /* remove field that blocks receiver */
-           if (IS_RECEIVER(Feld[x][y]))
-           {
-             int phase = Feld[x][y] - EL_RECEIVER_START;
-             int blocking_x, blocking_y;
-
-             blocking_x = x + xy[phase][0];
-             blocking_y = y + xy[phase][1];
-
-             if (IN_LEV_FIELD(blocking_x, blocking_y))
-             {
-               Feld[blocking_x][blocking_y] = EL_EMPTY;
-
-               DrawField_MM(blocking_x, blocking_y);
-             }
-           }
-         }
-       }
+       CheckExitMM();
 
        DrawLaser(0, DL_LASER_ENABLED);
       }
@@ -1486,16 +1539,13 @@ boolean HitElement(int element, int hit_mask)
     {
       game_mm.num_keys++;
     }
-    else if (element == EL_LIGHTBALL)
-    {
-      RaiseScore_MM(10);
-    }
     else if (IS_PACMAN(element))
     {
       DeletePacMan(ELX, ELY);
-      RaiseScore_MM(50);
     }
 
+    RaiseScoreElement_MM(element);
+
     return FALSE;
   }
 
@@ -2085,8 +2135,6 @@ boolean HitReflectingWalls(int element, int hit_mask)
        (IS_VERT_ANGLE(laser.current_angle) &&
         (!(hit_mask & HIT_MASK_LEFT) || !(hit_mask & HIT_MASK_RIGHT))))
     {
-      static int last_LX = 0, last_LY = 0, last_hit_mask = 0;
-
       /* laser at last step touched nothing or the same side of the wall */
       if (LX != last_LX || LY != last_LY || hit_mask == last_hit_mask)
       {
@@ -2671,6 +2719,16 @@ void ClickElement(int x, int y, int button)
   static boolean new_button = TRUE;
   int element;
 
+  if (button == -1)
+  {
+    /* initialize static variables */
+    click_delay = 0;
+    click_delay_value = CLICK_DELAY;
+    new_button = TRUE;
+
+    return;
+  }
+
   /* do not rotate objects hit by the laser after the game was solved */
   if (game_mm.level_solved && Hit[x][y])
     return;
@@ -2759,7 +2817,7 @@ void ClickElement(int x, int y, int button)
   else if (element == EL_LIGHTBALL)
   {
     Bang_MM(x, y);
-    RaiseScore_MM(10);
+    RaiseScoreElement_MM(element);
     DrawLaser(0, DL_LASER_ENABLED);
   }
 
@@ -2769,8 +2827,6 @@ void ClickElement(int x, int y, int button)
 
 void RotateMirror(int x, int y, int button)
 {
-  static int hold_x = -1, hold_y = -1;
-
   if (button == MB_RELEASED)
   {
     /* release eventually hold auto-rotating mirror */
@@ -2866,7 +2922,6 @@ void RotateMirror(int x, int y, int button)
 
 void AutoRotateMirrors()
 {
-  static unsigned int rotate_delay = 0;
   int x, y;
 
   if (!FrameReached(&rotate_delay, AUTO_ROTATE_DELAY))
@@ -2996,9 +3051,6 @@ void ColorCycling(void)
 
 static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
 {
-  static unsigned int pacman_delay = 0;
-  static unsigned int energy_delay = 0;
-  static unsigned int overload_delay = 0;
   int element;
   int x, y, i;
 
@@ -3053,9 +3105,10 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
 
   if (FrameReached(&energy_delay, ENERGY_DELAY))
   {
-    game_mm.energy_left--;
-    if (game_mm.energy_left >= 0)
+    if (game_mm.energy_left > 0)
     {
+      game_mm.energy_left--;
+
 #if 0
       BlitBitmap(pix[PIX_DOOR], drawto,
                 DOOR_GFX_PAGEX5 + XX_ENERGY, DOOR_GFX_PAGEY1 + YY_ENERGY,
@@ -3064,7 +3117,7 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
 #endif
       redraw_mask |= REDRAW_DOOR_1;
     }
-    else if (setup.time_limit)
+    else if (setup.time_limit && !game_mm.game_over)
     {
       int i;
 
@@ -3673,36 +3726,35 @@ void GameActions_MM(struct MouseActionInfo action, boolean warp_mode)
 
 void MovePacMen()
 {
-  static int p = -1;
   int mx, my, ox, oy, nx, ny;
   int element;
   int l;
 
-  if (++p >= game_mm.num_pacman)
-    p = 0;
+  if (++pacman_nr >= game_mm.num_pacman)
+    pacman_nr = 0;
 
-  game_mm.pacman[p].dir--;
+  game_mm.pacman[pacman_nr].dir--;
 
   for (l = 1; l < 5; l++)
   {
-    game_mm.pacman[p].dir++;
+    game_mm.pacman[pacman_nr].dir++;
 
-    if (game_mm.pacman[p].dir > 4)
-      game_mm.pacman[p].dir = 1;
+    if (game_mm.pacman[pacman_nr].dir > 4)
+      game_mm.pacman[pacman_nr].dir = 1;
 
-    if (game_mm.pacman[p].dir % 2)
+    if (game_mm.pacman[pacman_nr].dir % 2)
     {
       mx = 0;
-      my = game_mm.pacman[p].dir - 2;
+      my = game_mm.pacman[pacman_nr].dir - 2;
     }
     else
     {
       my = 0;
-      mx = 3 - game_mm.pacman[p].dir;
+      mx = 3 - game_mm.pacman[pacman_nr].dir;
     }
 
-    ox = game_mm.pacman[p].x;
-    oy = game_mm.pacman[p].y;
+    ox = game_mm.pacman[pacman_nr].x;
+    oy = game_mm.pacman[pacman_nr].y;
     nx = ox + mx;
     ny = oy + my;
     element = Feld[nx][ny];
@@ -3719,11 +3771,11 @@ void MovePacMen()
     Feld[ox][oy] = EL_EMPTY;
     Feld[nx][ny] =
       EL_PACMAN_RIGHT - 1 +
-      (game_mm.pacman[p].dir - 1 +
-       (game_mm.pacman[p].dir % 2) * 2);
+      (game_mm.pacman[pacman_nr].dir - 1 +
+       (game_mm.pacman[pacman_nr].dir % 2) * 2);
 
-    game_mm.pacman[p].x = nx;
-    game_mm.pacman[p].y = ny;
+    game_mm.pacman[pacman_nr].x = nx;
+    game_mm.pacman[pacman_nr].y = ny;
 
     DrawGraphic_MM(ox, oy, IMG_EMPTY);
 
@@ -3837,7 +3889,7 @@ void GameWon_MM()
       if (!setup.sound_loops)
        PlaySoundStereo(SND_SIRR, SOUND_MAX_RIGHT);
       if (TimePlayed < 999 && !(TimePlayed % 10))
-       RaiseScore_MM(native_mm_level.score[SC_ZEITBONUS]);
+       RaiseScore_MM(native_mm_level.score[SC_TIME_BONUS]);
       if (TimePlayed < 900 && !(TimePlayed % 10))
        TimePlayed += 10;
       else
@@ -4106,6 +4158,10 @@ void RaiseScoreElement_MM(int element)
   switch(element)
   {
     case EL_PACMAN:
+    case EL_PACMAN_RIGHT:
+    case EL_PACMAN_UP:
+    case EL_PACMAN_LEFT:
+    case EL_PACMAN_DOWN:
       RaiseScore_MM(native_mm_level.score[SC_PACMAN]);
       break;
 
@@ -4113,6 +4169,15 @@ void RaiseScoreElement_MM(int element)
       RaiseScore_MM(native_mm_level.score[SC_KEY]);
       break;
 
+    case EL_KETTLE:
+    case EL_CELL:
+      RaiseScore_MM(native_mm_level.score[SC_COLLECTIBLE]);
+      break;
+
+    case EL_LIGHTBALL:
+      RaiseScore_MM(native_mm_level.score[SC_LIGHTBALL]);
+      break;
+
     default:
       break;
   }