fixed element scores for MM style elements (MM engine)
[rocksndiamonds.git] / src / game_mm / mm_game.c
index ced5a021d60ada7e1d75a1a69fb1dcf1a6b2bd2b..e2a2e5f8745093c0387e208640e44a1128d6c26f 100644 (file)
 #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)
 
+#define BEGIN_NO_HEADLESS                      \
+  {                                            \
+    boolean last_headless = program.headless;  \
+                                               \
+    program.headless = FALSE;                  \
+
+#define END_NO_HEADLESS                                \
+    program.headless = last_headless;          \
+  }                                            \
+
 /* forward declaration for internal use */
 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);
 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] =
+{
+  {
+    "                ",
+    "    XXXXX       ",
+    "   XXXXXXX      ",
+    "  XXXXXXXXXXX   ",
+    "  XXXXXXXXXXXXX ",
+    "  XXXXXXXXXXXXXX",
+    "  XXXXXXXXXXXXXX",
+    "  XXXXXXXXXXXXX ",
+    "  XXXXXXXXXXXXX ",
+    "  XXXXXXXXXXXXX ",
+    "  XXXXXXXXXXXXX ",
+    "  XXXXXXXXXXXXX ",
+    "  XXXXXXXXXXXXX ",
+    "  XXXXXXXXXXXXX ",
+    "  XXXXXXXXXXXX  ",
+    "  XXXXXXXXXXXX  ",
+  },
+  {
+    "                ",
+    "    XXXXXXXX    ",
+    "  XXXXXXXXXXXX  ",
+    " XXXXXXXXXXXXXX ",
+    " XXXXXXXXXXXXXX ",
+    " XXXXXXXXXXXXXX ",
+    " XXXXXXXXXXXXXX ",
+    " XXXXXXXXXXXXXX ",
+    " XXXXXXXXXXXXXX ",
+    " XXXXXXXXXXXXXX ",
+    " XXXXXXXXXXXXXX ",
+    " XXXXXXXXXXXXXX ",
+    " XXXXXXXXXXXXXX ",
+    "  XXXXXXXXXXXXX ",
+    "  XXXXXXXXXXXX  ",
+    "  XXXXXXXXXXXX  ",
+  },
+  {
+    "                ",
+    "    XXXXXX      ",
+    "  XXXXXXXXX     ",
+    " XXXXXXXXXXX    ",
+    "XXXXXXXXXXXXX   ",
+    "XXXXXXXXXXXXX   ",
+    "XXXXXXXXXXXXXX  ",
+    " XXXXXXXXXXXXX  ",
+    " XXXXXXXXXXXXX  ",
+    " XXXXXXXXXXXXX  ",
+    " XXXXXXXXXXXXX  ",
+    " XXXXXXXXXXXXX  ",
+    " XXXXXXXXXXXXX  ",
+    " XXXXXXXXXXXXX  ",
+    "  XXXXXXXXXXXX  ",
+    "  XXXXXXXXXXXX  ",
+  },
+  {
+    "                ",
+    "    XXXXXX      ",
+    "   XXXXXXXX     ",
+    "  XXXXXXXXXX    ",
+    "  XXXXXXXXXXX   ",
+    "  XXXXXXXXXXX   ",
+    "  XXXXXXXXXXXX  ",
+    "  XXXXXXXXXXXX  ",
+    "  XXXXXXXXXXXX  ",
+    "  XXXXXXXXXXXX  ",
+    "  XXXXXXXXXXXX  ",
+    "  XXXXXXXXXXXX  ",
+    "  XXXXXXXXXXXX  ",
+    "  XXXXXXXXXXXX  ",
+    "  XXXXXXXXXXXX  ",
+    "  XXXXX  XXXXX  ",
+  },
+  {
+    " XXXXXX  XXXXXX ",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "                ",
+    "                ",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    " XXXXXX  XXXXXX ",
+  },
+  {
+    " XXXXXX  XXXXXX ",
+    "XXXXXXX  XXXXXXX",
+    "XXXXXXX  XXXXXXX",
+    "XXXXXXX  XXXXXXX",
+    "XXXXXXX  XXXXXXX",
+    "XXXXXXX  XXXXXXX",
+    "XXXXXXX  XXXXXXX",
+    " XXXXXX  XXXXXX ",
+    " XXXXXX  XXXXXX ",
+    "XXXXXXX  XXXXXXX",
+    "XXXXXXX  XXXXXXX",
+    "XXXXXXX  XXXXXXX",
+    "XXXXXXX  XXXXXXX",
+    "XXXXXXX  XXXXXXX",
+    "XXXXXXX  XXXXXXX",
+    " XXXXXX  XXXXXX ",
+  },
+  {
+    "     XX  XXXXX  ",
+    "    XXX  XXXX   ",
+    "   XXXX  XXX   X",
+    "  XXXXXXXXX   XX",
+    " XXXXXXXXX   XXX",
+    "XXXXXXXXX   XXXX",
+    "XXXXXXXX   XXXXX",
+    "   XXXX   XXX   ",
+    "   XXX   XXXX   ",
+    "XXXXX   XXXXXXXX",
+    "XXXX   XXXXXXXXX",
+    "XXX   XXXXXXXXX ",
+    "XX   XXXXXXXXX  ",
+    "X   XXX  XXXX   ",
+    "   XXXX  XXX    ",
+    "  XXXXX  XX     ",
+  },
+  {
+    "  XXXXX  XX     ",
+    "   XXXX  XXX    ",
+    "X   XXX  XXXX   ",
+    "XX   XXXXXXXXX  ",
+    "XXX   XXXXXXXXX ",
+    "XXXX   XXXXXXXXX",
+    "XXXXX   XXXXXXXX",
+    "   XXX   XXXX   ",
+    "   XXXX   XXX   ",
+    "XXXXXXXX   XXXXX",
+    "XXXXXXXXX   XXXX",
+    " XXXXXXXXX   XXX",
+    "  XXXXXXXXX   XX",
+    "   XXXX  XXX   X",
+    "    XXX  XXXX   ",
+    "     XX  XXXXX  ",
+  },
+  {
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+    "XXXXXXXXXXXXXXXX",
+  },
+  {
+    "                ",
+    "      XXXX      ",
+    "    XXXXXXXX    ",
+    "   XXXXXXXXXX   ",
+    "  XXXXXXXXXXXX  ",
+    "  XXXXXXXXXXXX  ",
+    " XXXXXXXXXXXXXX ",
+    " XXXXXXXXXXXXXX ",
+    " XXXXXXXXXXXXXX ",
+    " XXXXXXXXXXXXXX ",
+    "  XXXXXXXXXXXX  ",
+    "  XXXXXXXXXXXX  ",
+    "   XXXXXXXXXX   ",
+    "    XXXXXXXX    ",
+    "      XXXX      ",
+    "                ",
+  },
+};
 
 static int get_element_angle(int element)
 {
@@ -117,6 +328,87 @@ static int get_mirrored_angle(int laser_angle, int mirror_angle)
   return (reflected_angle + 16) % 16;
 }
 
+static void DrawLaserLines(struct XY *points, int num_points, int mode)
+{
+  Pixel pixel_drawto = (mode == DL_LASER_ENABLED ? pen_ray     : pen_bg);
+  Pixel pixel_buffer = (mode == DL_LASER_ENABLED ? WHITE_PIXEL : BLACK_PIXEL);
+
+  DrawLines(drawto, points, num_points, pixel_drawto);
+
+  BEGIN_NO_HEADLESS
+  {
+    DrawLines(laser_bitmap, points, num_points, pixel_buffer);
+  }
+  END_NO_HEADLESS
+}
+
+static boolean CheckLaserPixel(int x, int y)
+{
+  Pixel pixel;
+
+  BEGIN_NO_HEADLESS
+  {
+    pixel = ReadPixel(laser_bitmap, x, y);
+  }
+  END_NO_HEADLESS
+
+  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];
@@ -275,6 +567,9 @@ static void InitLaser()
   laser.num_beamers = 0;
   laser.beamer_edge[0] = 0;
 
+  laser.dest_element = EL_EMPTY;
+  laser.wall_mask = 0;
+
   AddLaserEdge(LX, LY);                /* set laser starting edge */
 
   pen_ray = GetPixelFromRGB(window,
@@ -287,6 +582,14 @@ void InitGameEngine_MM()
 {
   int i, x, y;
 
+  BEGIN_NO_HEADLESS
+  {
+    /* initialize laser bitmap to current playfield (screen) size */
+    ReCreateBitmap(&laser_bitmap, drawto->width, drawto->height);
+    ClearRectangle(laser_bitmap, 0, 0, drawto->width, drawto->height);
+  }
+  END_NO_HEADLESS
+
   /* set global game control values */
   game_mm.num_cycle = 0;
   game_mm.num_pacman = 0;
@@ -320,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++)
@@ -419,6 +738,9 @@ void InitGameActions_MM()
 #endif
 
   ScanLaser();
+
+  if (game_mm.kettles_still_needed == 0)
+    CheckExitMM();
 }
 
 void AddLaserEdge(int lx, int ly)
@@ -525,17 +847,9 @@ int ScanPixel()
        }
        else
        {
-         int graphic_mask = getMaskFromElement(element);
-         Bitmap *bitmap;
-         int src_x, src_y;
-         int mask_x, mask_y;
-
-         getGraphicSource(graphic_mask, 0, &bitmap, &src_x, &src_y);
+         int pos = getMaskFromElement(element) - IMG_MM_MASK_MCDUFFIN_RIGHT;
 
-         mask_x = src_x + dx;
-         mask_y = src_y + dy;
-
-         pixel = (ReadPixel(bitmap, mask_x, mask_y) ? 1 : 0);
+         pixel = (mm_masks[pos][dy / 2][dx / 2] == 'X' ? 1 : 0);
        }
       }
       else
@@ -738,7 +1052,7 @@ void ScanLaser()
   if (rf)
     DrawLaser(rf - 1, DL_LASER_ENABLED);
 
-  Ct = CT = Counter();
+  Ct = CT = FrameCounter;
 
 #if 0
     if (!IN_LEV_FIELD(ELX, ELY))
@@ -778,8 +1092,7 @@ void DrawLaserExt(int start_edge, int num_edges, int mode)
 #endif
 
   /* now draw the laser to the backbuffer and (if enabled) to the screen */
-  DrawLines(drawto, &laser.edge[start_edge], num_edges,
-           (mode == DL_LASER_ENABLED ? pen_ray : pen_bg));
+  DrawLaserLines(&laser.edge[start_edge], num_edges, mode);
 
   redraw_mask |= REDRAW_FIELD;
 
@@ -984,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];
 
@@ -1003,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);
     }
@@ -1210,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);
       }
@@ -1260,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;
   }
 
@@ -1859,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)
       {
@@ -2181,9 +2455,8 @@ static void Explode_MM(int x, int y, int phase, int mode)
   {
     if (Store[x][y] == EL_BOMB)
     {
-      laser.num_damages--;
       DrawLaser(0, DL_LASER_DISABLED);
-      laser.num_edges = 0;
+      InitLaser();
 
       Bang_MM(laser.start_edge.x, laser.start_edge.y);
       Store[x][y] = EL_EMPTY;
@@ -2446,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;
@@ -2534,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);
   }
 
@@ -2544,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 */
@@ -2641,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))
@@ -2675,25 +2955,24 @@ boolean ObjHit(int obx, int oby, int bits)
 
   if (bits & HIT_POS_CENTER)
   {
-    if (ReadPixel(drawto, SX + obx + 15, SY + oby + 15) == pen_ray)
+    if (CheckLaserPixel(SX + obx + 15,
+                       SY + oby + 15))
       return TRUE;
   }
 
   if (bits & HIT_POS_EDGE)
   {
     for (i = 0; i < 4; i++)
-      if (ReadPixel(drawto,
-                   SX + obx + 31 * (i % 2),
-                   SY + oby + 31 * (i / 2)) == pen_ray)
+      if (CheckLaserPixel(SX + obx + 31 * (i % 2),
+                         SY + oby + 31 * (i / 2)))
        return TRUE;
   }
 
   if (bits & HIT_POS_BETWEEN)
   {
     for (i = 0; i < 4; i++)
-      if (ReadPixel(drawto,
-                   SX + 4 + obx + 22 * (i % 2),
-                   SY + 4 + oby + 22 * (i / 2)) == pen_ray)
+      if (CheckLaserPixel(SX + 4 + obx + 22 * (i % 2),
+                         SY + 4 + oby + 22 * (i / 2)))
        return TRUE;
   }
 
@@ -2736,9 +3015,9 @@ void ColorCycling(void)
   if (color_status == STATIC_COLORS)
     return;
 
-  CC = Counter();
+  CC = FrameCounter;
 
-  if (CC < Cc || CC > Cc + 50)
+  if (CC < Cc || CC > Cc + 2)
   {
     Cc = CC;
 
@@ -2772,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;
 
@@ -2814,7 +3090,7 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
   laser.redraw = FALSE;
 #endif
 
-  CT = Counter();
+  CT = FrameCounter;
 
   if (game_mm.num_pacman && FrameReached(&pacman_delay, PACMAN_MOVE_DELAY))
   {
@@ -2829,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,
@@ -2840,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;
 
@@ -3018,7 +3295,7 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
 
   CT -= Ct;
 
-  if (element == EL_BOMB && CT > 1500)
+  if (element == EL_BOMB && CT > 75)
   {
     if (game_mm.cheat_no_explosion)
       return;
@@ -3056,7 +3333,7 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
     return;
   }
 
-  if (element == EL_FUSE_ON && CT > 500)
+  if (element == EL_FUSE_ON && CT > 25)
   {
     laser.fuse_off = TRUE;
     laser.fuse_x = ELX;
@@ -3066,7 +3343,7 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
     DrawGraphic_MM(ELX, ELY, IMG_MM_FUSE);
   }
 
-  if (element == EL_BALL_GRAY && CT > 1500)
+  if (element == EL_BALL_GRAY && CT > 75)
   {
     static int new_elements[] =
     {
@@ -3185,7 +3462,7 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
     return;
   }
 
-  if (IS_WALL_ICE(element) && CT > 1000)
+  if (IS_WALL_ICE(element) && CT > 50)
   {
     PlayLevelSound_MM(ELX, ELY, element, MM_ACTION_SHRINKING);
 
@@ -3237,7 +3514,7 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
     return;
   }
 
-  if (IS_WALL_AMOEBA(element) && CT > 1200)
+  if (IS_WALL_AMOEBA(element) && CT > 60)
   {
     int k1, k2, k3, dx, dy, de, dm;
     int element2 = Feld[ELX][ELY];
@@ -3273,13 +3550,12 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
     {
       if (laser.wall_mask & (1 << i))
       {
-       if (ReadPixel(drawto,
-                     SX + ELX * TILEX + 14 + (i % 2) * 2,
-                     SY + ELY * TILEY + 31 * (i / 2)) == pen_ray)
+       if (CheckLaserPixel(SX + ELX * TILEX + 14 + (i % 2) * 2,
+                           SY + ELY * TILEY + 31 * (i / 2)))
          break;
-       if (ReadPixel(drawto,
-                     SX + ELX * TILEX + 31 * (i % 2),
-                     SY + ELY * TILEY + 14 + (i / 2) * 2) == pen_ray)
+
+       if (CheckLaserPixel(SX + ELX * TILEX + 31 * (i % 2),
+                           SY + ELY * TILEY + 14 + (i / 2) * 2))
          break;
       }
     }
@@ -3290,9 +3566,8 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
     {
       if (laser.wall_mask & (1 << i))
       {
-       if (ReadPixel(drawto,
-                     SX + ELX * TILEX + 31 * (i % 2),
-                     SY + ELY * TILEY + 31 * (i / 2)) == pen_ray)
+       if (CheckLaserPixel(SX + ELX * TILEX + 31 * (i % 2),
+                           SY + ELY * TILEY + 31 * (i / 2)))
          break;
       }
     }
@@ -3301,8 +3576,8 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
 
     if (laser.num_beamers > 0 ||
        k1 < 1 || k2 < 4 || k3 < 4 ||
-       ReadPixel(drawto, SX + ELX * TILEX + 14, SY + ELY * TILEY + 14)
-       == pen_ray)
+       CheckLaserPixel(SX + ELX * TILEX + 14,
+                       SY + ELY * TILEY + 14))
     {
       laser.num_edges = r;
       laser.num_damages = d;
@@ -3355,7 +3630,7 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
   }
 
   if ((element == EL_BLOCK_WOOD || element == EL_BLOCK_STONE) &&
-      laser.stops_inside_element && CT > 1500)
+      laser.stops_inside_element && CT > 75)
   {
     int x, y;
     int k;
@@ -3412,7 +3687,7 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
     return;
   }
 
-  if (element == EL_FUEL_FULL && CT > 200)
+  if (element == EL_FUEL_FULL && CT > 10)
   {
     for (i = game_mm.energy_left; i <= MAX_LASER_ENERGY; i+=2)
     {
@@ -3451,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];
@@ -3497,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);
 
@@ -3514,7 +3788,7 @@ void MovePacMen()
 
       getGraphicSource(graphic, 0, &bitmap, &src_x, &src_y);
 
-      CT = Counter();
+      CT = FrameCounter;
       ox = SX + ox * TILEX;
       oy = SY + oy * TILEY;
 
@@ -3522,7 +3796,7 @@ void MovePacMen()
        BlitBitmap(bitmap, window,
                   src_x, src_y, TILEX, TILEY,
                   ox + i * mx, oy + i * my);
-      Ct = Ct + Counter() - CT;
+      Ct = Ct + FrameCounter - CT;
     }
 
     DrawField_MM(nx, ny);
@@ -3615,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
@@ -3884,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;
 
@@ -3891,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;
   }