added optional button to restart game (door, panel and touch variants)
[rocksndiamonds.git] / src / game_mm / mm_tools.c
index 0906862b33cbaa3d6f478e8f6d0d9697b1fa4c89..12ca83cee8e22041ee608e659ad1f106c5d1ac3a 100644 (file)
@@ -29,8 +29,8 @@ void SetDrawtoField_MM(int mode)
   // for convenience, absolute screen position to centered level playfield
   cSX = SX + dSX;
   cSY = SY + dSY;
-  cSX2 = SX + dSX + 2; // including playfield border
-  cSY2 = SY + dSY + 2; // including playfield border
+  cSX2 = SX + dSX + 2;         // including half laser line size
+  cSY2 = SY + dSY + 2;         // including half laser line size
 
   if (mode == DRAW_TO_BACKBUFFER)
   {
@@ -41,9 +41,16 @@ void SetDrawtoField_MM(int mode)
   SetTileCursorSXSY(cSX, cSY);
 }
 
+void BackToFront_MM(void)
+{
+  BlitScreenToBitmap_MM(backbuffer);
+
+  BackToFront();
+}
+
 void ClearWindow(void)
 {
-  ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
+  ClearRectangle(drawto_mm, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
 
   SetDrawtoField(DRAW_TO_BACKBUFFER);
   SetDrawtoField_MM(DRAW_TO_BACKBUFFER);
@@ -58,14 +65,14 @@ void DrawGraphicAnimation_MM(int x, int y, int graphic, int frame)
 
   getGraphicSource(graphic, frame, &bitmap, &src_x, &src_y);
 
-  BlitBitmap(bitmap, drawto_field, src_x, src_y, TILEX, TILEY,
+  BlitBitmap(bitmap, drawto_mm, src_x, src_y, TILEX, TILEY,
             cFX + x * TILEX, cFY + y * TILEY);
 }
 
 void DrawGraphic_MM(int x, int y, int graphic)
 {
 #if DEBUG
-  if (!IN_SCR_FIELD(x,y))
+  if (!IN_SCR_FIELD(x, y))
   {
     Debug("game:mm:DrawGraphic_MM", "x = %d, y = %d, graphic = %d",
          x, y, graphic);
@@ -75,7 +82,9 @@ void DrawGraphic_MM(int x, int y, int graphic)
   }
 #endif
 
-  DrawGraphicExt_MM(drawto_field, cFX + x * TILEX, cFY + y * TILEY, graphic);
+  int frame = getGraphicAnimationFrameXY(graphic, x, y);
+
+  DrawGraphicAnimation_MM(x, y, graphic, frame);
 
   MarkTileDirty(x, y);
 }
@@ -90,12 +99,12 @@ void DrawGraphicExt_MM(DrawBuffer *d, int x, int y, int graphic)
   BlitBitmap(bitmap, d, src_x, src_y, TILEX, TILEY, x, y);
 }
 
-void DrawGraphicThruMask_MM(int x, int y, int graphic)
+void DrawGraphicThruMask_MM(int x, int y, int graphic, int frame)
 {
 #if DEBUG
-  if (!IN_SCR_FIELD(x,y))
+  if (!IN_SCR_FIELD(x, y))
   {
-    Debug("game:mm:DrawGraphicThruMask_MM", "x = %d,y = %d, graphic = %d",
+    Debug("game:mm:DrawGraphicThruMask_MM", "x = %d, y = %d, graphic = %d",
          x, y, graphic);
     Debug("game:mm:DrawGraphicThruMask_MM", "This should never happen!");
 
@@ -103,14 +112,14 @@ void DrawGraphicThruMask_MM(int x, int y, int graphic)
   }
 #endif
 
-  DrawGraphicThruMaskExt_MM(drawto_field, cFX + x * TILEX, cFY + y * TILEY,
-                           graphic);
+  DrawGraphicThruMaskExt_MM(drawto_mm, cFX + x * TILEX, cFY + y * TILEY,
+                           graphic, frame);
 
-  MarkTileDirty(x,y);
+  MarkTileDirty(x, y);
 }
 
 void DrawGraphicThruMaskExt_MM(DrawBuffer *d, int dest_x, int dest_y,
-                              int graphic)
+                              int graphic, int frame)
 {
   int src_x, src_y;
   Bitmap *src_bitmap;
@@ -118,26 +127,19 @@ void DrawGraphicThruMaskExt_MM(DrawBuffer *d, int dest_x, int dest_y,
   if (graphic == IMG_EMPTY)
     return;
 
-  getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
+  getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y);
 
   BlitBitmapMasked(src_bitmap, d, src_x, src_y, TILEX, TILEY, dest_x, dest_y);
 }
 
 void DrawMiniGraphic_MM(int x, int y, int graphic)
 {
-  DrawMiniGraphicExt_MM(drawto, cSX + x * MINI_TILEX, cSY + y * MINI_TILEY,
+  DrawMiniGraphicExt_MM(drawto_mm, cSX + x * MINI_TILEX, cSY + y * MINI_TILEY,
                        graphic);
 
   MarkTileDirty(x / 2, y / 2);
 }
 
-#if 0
-static void getMicroGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y)
-{
-  getSizedGraphicSource(graphic, 0, TILESIZE / 4, bitmap, x, y);
-}
-#endif
-
 void DrawMiniGraphicExt_MM(DrawBuffer *d, int x, int y, int graphic)
 {
   Bitmap *bitmap;
@@ -148,8 +150,8 @@ void DrawMiniGraphicExt_MM(DrawBuffer *d, int x, int y, int graphic)
   BlitBitmap(bitmap, d, src_x, src_y, MINI_TILEX, MINI_TILEY, x, y);
 }
 
-void DrawGraphicShifted_MM(int x,int y, int dx,int dy, int graphic,
-                       int cut_mode, int mask_mode)
+void DrawGraphicShifted_MM(int x, int y, int dx, int dy, int graphic,
+                          int cut_mode, int mask_mode)
 {
   int width = TILEX, height = TILEY;
   int cx = 0, cy = 0;
@@ -240,7 +242,7 @@ void DrawGraphicShifted_MM(int x,int y, int dx,int dy, int graphic,
   dest_y = cFY + y * TILEY + dy;
 
 #if DEBUG
-  if (!IN_SCR_FIELD(x,y))
+  if (!IN_SCR_FIELD(x, y))
   {
     Debug("game:mm:DrawGraphicShifted_MM", "x = %d, y = %d, graphic = %d",
          x, y, graphic);
@@ -251,19 +253,13 @@ void DrawGraphicShifted_MM(int x,int y, int dx,int dy, int graphic,
 #endif
 
   if (mask_mode == USE_MASKING)
-    BlitBitmapMasked(src_bitmap, drawto_field,
+    BlitBitmapMasked(src_bitmap, drawto_mm,
                     src_x, src_y, TILEX, TILEY, dest_x, dest_y);
   else
-    BlitBitmap(src_bitmap, drawto_field,
+    BlitBitmap(src_bitmap, drawto_mm,
               src_x, src_y, width, height, dest_x, dest_y);
 
-  MarkTileDirty(x,y);
-}
-
-void DrawGraphicShiftedThruMask_MM(int x,int y, int dx,int dy, int graphic,
-                               int cut_mode)
-{
-  DrawGraphicShifted_MM(x, y, dx, dy, graphic, cut_mode, USE_MASKING);
+  MarkTileDirty(x, y);
 }
 
 void DrawScreenElementExt_MM(int x, int y, int dx, int dy, int element,
@@ -290,7 +286,7 @@ void DrawScreenElementExt_MM(int x, int y, int dx, int dy, int element,
   if (dx || dy)
     DrawGraphicShifted_MM(x, y, dx, dy, graphic, cut_mode, mask_mode);
   else if (mask_mode == USE_MASKING)
-    DrawGraphicThruMask_MM(x, y, graphic);
+    DrawGraphicThruMask_MM(x, y, graphic, 0);
   else
     DrawGraphic_MM(x, y, graphic);
 }
@@ -309,38 +305,11 @@ void DrawScreenElementShifted_MM(int x, int y, int dx, int dy, int element,
   DrawScreenElementExt_MM(x, y, dx, dy, element, cut_mode, NO_MASKING);
 }
 
-void DrawLevelElementShifted_MM(int x, int y, int dx, int dy, int element,
-                            int cut_mode)
-{
-  DrawLevelElementExt_MM(x, y, dx, dy, element, cut_mode, NO_MASKING);
-}
-
-void DrawScreenElementThruMask_MM(int x, int y, int element)
-{
-  DrawScreenElementExt_MM(x, y, 0, 0, element, NO_CUTTING, USE_MASKING);
-}
-
-void DrawLevelElementThruMask_MM(int x, int y, int element)
-{
-  DrawLevelElementExt_MM(x, y, 0, 0, element, NO_CUTTING, USE_MASKING);
-}
-
-void DrawLevelFieldThruMask_MM(int x, int y)
-{
-  DrawLevelElementExt_MM(x, y, 0, 0, Tile[x][y], NO_CUTTING, USE_MASKING);
-}
-
 void DrawScreenElement_MM(int x, int y, int element)
 {
   DrawScreenElementExt_MM(x, y, 0, 0, element, NO_CUTTING, NO_MASKING);
 }
 
-void DrawLevelElement_MM(int x, int y, int element)
-{
-  if (IN_LEV_FIELD(x, y) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
-    DrawScreenElement_MM(SCREENX(x), SCREENY(y), element);
-}
-
 void DrawScreenField_MM(int x, int y)
 {
   int element = Tile[x][y];
@@ -395,7 +364,24 @@ void DrawScreenField_MM(int x, int y)
 
 void DrawLevelField_MM(int x, int y)
 {
-  DrawScreenField_MM(x, y);
+  if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+    DrawScreenField_MM(SCREENX(x), SCREENY(y));
+  else if (IS_MOVING(x, y))
+  {
+    int newx, newy;
+
+    Moving2Blocked(x, y, &newx, &newy);
+    if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
+      DrawScreenField_MM(SCREENX(newx), SCREENY(newy));
+  }
+  else if (IS_BLOCKED(x, y))
+  {
+    int oldx, oldy;
+
+    Blocked2Moving(x, y, &oldx, &oldy);
+    if (IN_SCR_FIELD(SCREENX(oldx), SCREENY(oldy)))
+      DrawScreenField_MM(SCREENX(oldx), SCREENY(oldy));
+  }
 }
 
 void DrawMiniElement_MM(int x, int y, int element)
@@ -433,7 +419,7 @@ void DrawField_MM(int x, int y)
 
 void DrawLevel_MM(void)
 {
-  int x,y;
+  int x, y;
 
   ClearWindow();
 
@@ -472,10 +458,10 @@ void DrawWallsExt_MM(int x, int y, int element, int draw_mask)
       continue;
 
     if (element & (1 << i))
-      BlitBitmap(bitmap, drawto, gx, gy, MINI_TILEX, MINI_TILEY,
+      BlitBitmap(bitmap, drawto_mm, gx, gy, MINI_TILEX, MINI_TILEY,
                 dest_x, dest_y);
     else
-      ClearRectangle(drawto, dest_x, dest_y, MINI_TILEX, MINI_TILEY);
+      ClearRectangle(drawto_mm, dest_x, dest_y, MINI_TILEX, MINI_TILEY);
   }
 
   MarkTileDirty(x, y);
@@ -526,7 +512,7 @@ void DrawWallsAnimation_MM(int x, int y, int element, int phase, int bit_mask)
       getSizedGraphicSource(graphic, frame, MINI_TILESIZE, &bitmap,
                            &src_x, &src_y);
 
-      BlitBitmap(bitmap, drawto, src_x, src_y, MINI_TILEX, MINI_TILEY,
+      BlitBitmap(bitmap, drawto_mm, src_x, src_y, MINI_TILEX, MINI_TILEY,
                 dst_x, dst_y);
     }
   }
@@ -555,79 +541,18 @@ void DrawElement_MM(int x, int y, int element)
           laser.fuse_x == x &&
           laser.fuse_y == y)
     DrawGraphic_MM(x, y, IMG_MM_FUSE);
+  else if (element == EL_GRAY_BALL_ACTIVE)
+    DrawGraphic_MM(x, y, el_act2gfx(EL_GRAY_BALL, MM_ACTION_ACTIVE));
+  else if (element == EL_GRAY_BALL_OPENING)
+    DrawGraphic_MM(x, y, el_act2gfx(EL_GRAY_BALL, MM_ACTION_OPENING));
+  else if (element == EL_BOMB_ACTIVE)
+    DrawGraphic_MM(x, y, el_act2gfx(EL_BOMB, MM_ACTION_ACTIVE));
+  else if (element == EL_MINE_ACTIVE)
+    DrawGraphic_MM(x, y, el_act2gfx(EL_MINE, MM_ACTION_ACTIVE));
   else
     DrawGraphic_MM(x, y, el2gfx(element));
 }
 
-#if 0
-static void DrawMicroWalls_MM(int x, int y, int element)
-{
-  Bitmap *bitmap;
-  int graphic = el2gfx(WALL_BASE(element));
-  int gx, gy;
-  int i;
-
-  getMicroGraphicSource(graphic, &bitmap, &gx, &gy);
-
-  for (i = 0; i < 4; i++)
-  {
-    int xpos = MICROLEV_XPOS + x * MICRO_TILEX + MICRO_WALLX * (i % 2);
-    int ypos = MICROLEV_YPOS + y * MICRO_TILEY + MICRO_WALLY * (i / 2);
-
-    if (element & (1 << i))
-      BlitBitmap(bitmap, drawto, gx, gy, MICRO_WALLX, MICRO_WALLY, xpos, ypos);
-    else
-      ClearRectangle(drawto, xpos, ypos, MICRO_WALLX, MICRO_WALLY);
-  }
-}
-
-static void DrawMicroElement_MM(int x, int y, int element)
-{
-  Bitmap *bitmap;
-  int graphic = el2gfx(element);
-  int gx, gy;
-
-  if (element == EL_EMPTY)
-    return;
-
-  if (IS_WALL(element))
-  {
-    DrawMicroWalls_MM(x, y, element);
-
-    return;
-  }
-
-  getMicroGraphicSource(graphic, &bitmap, &gx, &gy);
-
-  BlitBitmap(bitmap, drawto, gx, gy, MICRO_TILEX, MICRO_TILEY,
-            MICROLEV_XPOS + x * MICRO_TILEX, MICROLEV_YPOS + y * MICRO_TILEY);
-}
-
-static void DrawMicroLevelExt_MM(int xpos, int ypos)
-{
-  int x, y;
-
-  ClearRectangle(drawto, xpos, ypos, MICROLEV_XSIZE, MICROLEV_YSIZE);
-
-  for (x = 0; x < STD_LEV_FIELDX; x++)
-    for (y = 0; y < STD_LEV_FIELDY; y++)
-      DrawMicroElement_MM(x, y, Ur[x][y]);
-
-  redraw_mask |= REDRAW_FIELD;
-}
-#endif
-
-void DrawMiniLevel_MM(int size_x, int size_y, int scroll_x, int scroll_y)
-{
-  int x, y;
-
-  for (x = 0; x < size_x; x++)
-    for (y = 0; y < size_y; y++)
-      DrawMiniElementOrWall_MM(x, y, scroll_x, scroll_y);
-
-  redraw_mask |= REDRAW_FIELD;
-}
-
 
 // ----------------------------------------------------------------------------
 // XSN
@@ -648,6 +573,7 @@ void DrawMiniLevel_MM(int size_x, int size_y, int scroll_x, int scroll_y)
 #define XSN_CHANGE_DELAY       30
 #define XSN_CHANGE_FACTOR      3
 #define XSN_ALPHA_DEFAULT      XSN_ALPHA_VALUE(95)
+#define XSN_ALPHA_VISIBLE      XSN_ALPHA_VALUE(50)
 #define XSN_DEBUG_STEPS                5
 
 static byte xsn_bits_0[] = { 0x05, 0x02, 0x05 };
@@ -707,6 +633,8 @@ struct Xsn
   struct XsnItem items[XSN_MAX_ITEMS];
 
   Bitmap *bitmap;
+
+  int alpha;
 };
 
 static struct Xsn xsn = { 0 };
@@ -719,7 +647,7 @@ static int xsn_percent(void)
   int xsn_m3 = xsn_m2 + 10;
   time_t xsn_e0 = time(NULL);
   struct tm *xsn_t0 = localtime(&xsn_e0);
-  struct tm xsn_t1 = { 0,0,0, xsn_m2*3, xsn_m3/3, xsn_t0->tm_year, 0,0,-1 };
+  struct tm xsn_t1 = { 0,0,0, xsn_m2 * 3, xsn_m3 / 3, xsn_t0->tm_year, 0,0,-1 };
   time_t xsn_e1 = mktime(&xsn_t1);
   int xsn_c0 = (25 * xsn_m3) << xsn_m1;
   int xsn_c1 = (xsn_t1.tm_wday - xsn_m1) * !!xsn_t1.tm_wday;
@@ -847,7 +775,7 @@ static void xsn_update_item(int nr)
       BlitBitmapMasked(xsn.bitmap, xsn.bitmap, xpos1, xsn.max_height,
                       xsize, xsn.max_height, xpos1, 0);
 
-      SDLSetAlpha(surface_masked, TRUE, XSN_ALPHA_DEFAULT);
+      SDLSetAlpha(surface_masked, TRUE, xsn.alpha);
 
       for (i = xpos1; i < xpos2; i++)
        xsn.height[i] = MIN(xsn.height[i] + shrink, xsn.area_ysize - 1);
@@ -896,16 +824,11 @@ static void DrawTileCursor_Xsn(int draw_target)
   static boolean started = FALSE;
   static boolean active = FALSE;
   static boolean debug = FALSE;
-  static unsigned int check_delay = 0;
-  static unsigned int start_delay = 0;
-  static unsigned int growth_delay = 0;
-  static unsigned int update_delay = 0;
-  static unsigned int change_delay = 0;
-  static unsigned int check_delay_value = XSN_CHECK_DELAY * 1000;
-  static unsigned int start_delay_value = 0;
-  static unsigned int growth_delay_value = 0;
-  static unsigned int update_delay_value = 0;
-  static unsigned int change_delay_value = 0;
+  static DelayCounter check_delay = { XSN_CHECK_DELAY * 1000 };
+  static DelayCounter start_delay = { 0 };
+  static DelayCounter growth_delay = { 0 };
+  static DelayCounter update_delay = { 0 };
+  static DelayCounter change_delay = { 0 };
   static int percent = 0;
   static int debug_value = 0;
   boolean reinitialize = FALSE;
@@ -915,7 +838,7 @@ static void DrawTileCursor_Xsn(int draw_target)
   if (draw_target != DRAW_TO_SCREEN)
     return;
 
-  if (DelayReached(&check_delay, check_delay_value))
+  if (DelayReached(&check_delay))
   {
     percent = (debug ? debug_value * 100 / XSN_DEBUG_STEPS : xsn_percent());
 
@@ -943,7 +866,7 @@ static void DrawTileCursor_Xsn(int draw_target)
     debug = TRUE;
     active = FALSE;
 
-    DelayReached(&check_delay, 0);
+    ResetDelayCounter(&check_delay);
 
     setup.debug.xsn_mode = (debug_value > 0);
     tile_cursor.xsn_debug = FALSE;
@@ -993,11 +916,11 @@ static void DrawTileCursor_Xsn(int draw_target)
 
   if (!active_last)
   {
-    start_delay_value = (debug || setup.debug.xsn_mode == TRUE ? 0 :
+    start_delay.value = (debug || setup.debug.xsn_mode == TRUE ? 0 :
                         (XSN_START_DELAY + XSN_RND(XSN_START_DELAY)) * 1000);
     started = FALSE;
 
-    DelayReached(&start_delay, 0);
+    ResetDelayCounter(&start_delay);
 
     reinitialize = TRUE;
   }
@@ -1015,6 +938,8 @@ static void DrawTileCursor_Xsn(int draw_target)
     xsn.change_type  = 0;
     xsn.change_dir   = 0;
 
+    xsn.alpha = XSN_ALPHA_DEFAULT;
+
     for (i = 0; i < xsn.max_items; i++)
       xsn_init_item(i);
   }
@@ -1045,8 +970,8 @@ static void DrawTileCursor_Xsn(int draw_target)
     SDL_SetColorKey(surface_masked, SET_TRANSPARENT_PIXEL,
                    SDL_MapRGB(surface_masked->format, 0x00, 0x00, 0x00));
 
-    SDLSetAlpha(surface, TRUE, XSN_ALPHA_DEFAULT);
-    SDLSetAlpha(surface_masked, TRUE, XSN_ALPHA_DEFAULT);
+    SDLSetAlpha(surface, TRUE, xsn.alpha);
+    SDLSetAlpha(surface_masked, TRUE, xsn.alpha);
 
     SDLCreateBitmapTextures(xsn.bitmap);
 
@@ -1067,40 +992,54 @@ static void DrawTileCursor_Xsn(int draw_target)
 
   if (!started)
   {
-    if (!DelayReached(&start_delay, start_delay_value))
+    if (!DelayReached(&start_delay))
       return;
 
-    update_delay_value = XSN_UPDATE_DELAY;
-    growth_delay_value = XSN_GROWTH_DELAY * 1000;
-    change_delay_value = XSN_CHANGE_DELAY * 1000;
+    update_delay.value = XSN_UPDATE_DELAY;
+    growth_delay.value = XSN_GROWTH_DELAY * 1000;
+    change_delay.value = XSN_CHANGE_DELAY * 1000;
 
-    DelayReached(&growth_delay, 0);
-    DelayReached(&update_delay, 0);
-    DelayReached(&change_delay, 0);
+    ResetDelayCounter(&growth_delay);
+    ResetDelayCounter(&update_delay);
+    ResetDelayCounter(&change_delay);
 
     started = TRUE;
   }
 
   if (xsn.num_items < xsn.max_items)
   {
-    if (DelayReached(&growth_delay, growth_delay_value))
+    if (DelayReached(&growth_delay))
     {
       xsn.num_items += XSN_RND(XSN_GROWTH_RATE * 2);
       xsn.num_items = MIN(xsn.num_items, xsn.max_items);
     }
   }
 
-  if (DelayReached(&update_delay, update_delay_value))
+  if (DelayReached(&update_delay))
   {
     for (i = 0; i < xsn.num_items; i++)
       xsn_update_item(i);
   }
 
-  if (DelayReached(&change_delay, change_delay_value))
+  if (DelayReached(&change_delay))
   {
     xsn_update_change();
 
-    change_delay_value = xsn.change_delay * 1000;
+    change_delay.value = xsn.change_delay * 1000;
+  }
+
+  int xsn_alpha_dx = (gfx.mouse_y > xsn.area_ysize - xsn.max_height ?
+                     (xsn.alpha > XSN_ALPHA_VISIBLE ? -1 : 0) :
+                     (xsn.alpha < XSN_ALPHA_DEFAULT ? +1 : 0));
+
+  if (xsn_alpha_dx != 0)
+  {
+    xsn.alpha += xsn_alpha_dx;
+
+    SDLSetAlpha(xsn.bitmap->surface_masked, TRUE, xsn.alpha);
+
+    SDLFreeBitmapTextures(xsn.bitmap);
+    SDLCreateBitmapTextures(xsn.bitmap);
   }
 
   BlitToScreenMasked(xsn.bitmap, 0, 0, xsn.area_xsize, xsn.max_height,
@@ -1118,7 +1057,8 @@ static void DrawTileCursor_Xsn(int draw_target)
   }
 }
 
-void DrawTileCursor_MM(int draw_target, boolean tile_cursor_active)
+void DrawTileCursor_MM(int draw_target, int drawing_stage,
+                      boolean tile_cursor_active)
 {
   if (program.headless)
     return;
@@ -1133,7 +1073,12 @@ void DrawTileCursor_MM(int draw_target, boolean tile_cursor_active)
   int width = tilesize;
   int height = tilesize;
 
-  DrawTileCursor_Xsn(draw_target);
+  if (!drawing_stage)
+  {
+    DrawTileCursor_Xsn(draw_target);
+
+    return;
+  }
 
   if (!tile_cursor.enabled ||
       !tile_cursor.active ||
@@ -1179,31 +1124,11 @@ void DrawTileCursor_MM(int draw_target, boolean tile_cursor_active)
                     dst_x, dst_y);
 }
 
-#if 0
-static int REQ_in_range(int x, int y)
-{
-  if (y > DY + 249 && y < DY + 278)
-  {
-    if (x > DX + 1 && x < DX + 48)
-      return 1;
-    else if (x > DX + 51 && x < DX + 98)
-      return 2;
-  }
-
-  return 0;
-}
-#endif
-
 Pixel ReadPixel(DrawBuffer *bitmap, int x, int y)
 {
   return GetPixel(bitmap, x, y);
 }
 
-void SetRGB(unsigned int pixel,
-           unsigned short red, unsigned short green, unsigned short blue)
-{
-}
-
 int get_base_element(int element)
 {
   if (IS_MIRROR(element))
@@ -1228,6 +1153,10 @@ int get_base_element(int element)
     return EL_DF_MIRROR_START;
   else if (IS_DF_MIRROR_AUTO(element))
     return EL_DF_MIRROR_AUTO_START;
+  else if (IS_DF_MIRROR_FIXED(element))
+    return EL_DF_MIRROR_FIXED_START;
+  else if (IS_DF_SLOPE(element))
+    return EL_DF_SLOPE_START;
   else if (IS_PACMAN(element))
     return EL_PACMAN_START;
   else if (IS_GRID_STEEL(element))
@@ -1271,7 +1200,8 @@ int get_num_elements(int element)
       IS_POLAR(element) ||
       IS_BEAMER(element) ||
       IS_DF_MIRROR(element) ||
-      IS_DF_MIRROR_AUTO(element))
+      IS_DF_MIRROR_AUTO(element) ||
+      IS_DF_MIRROR_FIXED(element))
     return 16;
   else if (IS_GRID_STEEL_FIXED(element) ||
           IS_GRID_WOOD_FIXED(element) ||
@@ -1285,7 +1215,8 @@ int get_num_elements(int element)
           IS_RECEIVER(element) ||
           IS_PACMAN(element) ||
           IS_GRID_STEEL(element) ||
-          IS_GRID_WOOD(element))
+          IS_GRID_WOOD(element) ||
+          IS_DF_SLOPE(element))
     return 4;
   else
     return 1;
@@ -1300,35 +1231,150 @@ int get_rotated_element(int element, int step)
   return base_element + (element_phase + step + num_elements) % num_elements;
 }
 
-static int map_element(int element)
+static boolean has_full_rotation(int element)
+{
+  return (IS_BEAMER(element) ||
+         IS_MCDUFFIN(element) ||
+         IS_LASER(element) ||
+         IS_RECEIVER(element) ||
+         IS_PACMAN(element));
+}
+
+#define MM_FLIP_X                      0
+#define MM_FLIP_Y                      1
+#define MM_FLIP_XY                     2
+
+static int getFlippedTileExt_MM(int element, int mode)
+{
+  if (IS_WALL(element))
+  {
+    int base = WALL_BASE(element);
+    int bits = WALL_BITS(element);
+
+    if (mode == MM_FLIP_X)
+    {
+      bits = ((bits & 1) << 1 |
+             (bits & 2) >> 1 |
+             (bits & 4) << 1 |
+             (bits & 8) >> 1);
+    }
+    else if (mode == MM_FLIP_Y)
+    {
+      bits = ((bits & 1) << 2 |
+             (bits & 2) << 2 |
+             (bits & 4) >> 2 |
+             (bits & 8) >> 2);
+    }
+    else if (mode == MM_FLIP_XY)
+    {
+      bits = ((bits & 1) << 0 |
+             (bits & 2) << 1 |
+             (bits & 4) >> 1 |
+             (bits & 8) >> 0);
+    }
+
+    element = base | bits;
+  }
+  else
+  {
+    int base_element = get_base_element(element);
+    int num_elements = get_num_elements(element);
+    int element_phase = element - base_element;
+
+    if (IS_GRID_STEEL(element) || IS_GRID_WOOD(element))
+    {
+      if ((mode == MM_FLIP_XY && element_phase < 2) ||
+         (mode != MM_FLIP_XY && element_phase > 1))
+       element_phase ^= 1;
+    }
+    else if (IS_DF_SLOPE(element))
+    {
+      element_phase = (mode == MM_FLIP_X  ? 5 - element_phase :
+                      mode == MM_FLIP_Y  ? 3 - element_phase :
+                      mode == MM_FLIP_XY ? 4 - element_phase :
+                      element_phase);
+    }
+    else
+    {
+      int num_elements_flip = num_elements;
+
+      if (has_full_rotation(element))
+      {
+       if (mode == MM_FLIP_X)
+         num_elements_flip = num_elements / 2;
+       else if (mode == MM_FLIP_XY)
+         num_elements_flip = num_elements * 3 / 4;
+      }
+      else
+      {
+       if (mode == MM_FLIP_XY)
+         num_elements_flip = num_elements / 2;
+      }
+
+      element_phase = num_elements_flip - element_phase;
+    }
+
+    element = base_element + (element_phase + num_elements) % num_elements;
+  }
+
+  return element;
+}
+
+int getFlippedTileX_MM(int element)
+{
+  return getFlippedTileExt_MM(element, MM_FLIP_X);
+}
+
+int getFlippedTileY_MM(int element)
+{
+  return getFlippedTileExt_MM(element, MM_FLIP_Y);
+}
+
+int getFlippedTileXY_MM(int element)
+{
+  return getFlippedTileExt_MM(element, MM_FLIP_XY);
+}
+
+int map_wall_from_base_element(int element)
 {
   switch (element)
   {
-    case EL_WALL_STEEL:                return EL_STEEL_WALL;
-    case EL_WALL_WOOD:         return EL_WOODEN_WALL;
-    case EL_WALL_ICE:          return EL_ICE_WALL;
-    case EL_WALL_AMOEBA:       return EL_AMOEBA_WALL;
-    case EL_DF_WALL_STEEL:     return EL_DF_STEEL_WALL;
-    case EL_DF_WALL_WOOD:      return EL_DF_WOODEN_WALL;
+    case EL_WALL_STEEL_BASE:   return EL_WALL_STEEL;
+    case EL_WALL_WOOD_BASE:    return EL_WALL_WOOD;
+    case EL_WALL_ICE_BASE:     return EL_WALL_ICE;
+    case EL_WALL_AMOEBA_BASE:  return EL_WALL_AMOEBA;
+    case EL_DF_WALL_STEEL_BASE:        return EL_DF_WALL_STEEL;
+    case EL_DF_WALL_WOOD_BASE: return EL_DF_WALL_WOOD;
 
     default:                   return element;
   }
 }
 
-int el2gfx(int element)
+int map_wall_to_base_element(int element)
 {
-  element = map_element(element);
-
   switch (element)
   {
-    case EL_LIGHTBALL:
-      return IMG_MM_LIGHTBALL_RED + RND(3);
+    case EL_WALL_STEEL:                return EL_WALL_STEEL_BASE;
+    case EL_WALL_WOOD:         return EL_WALL_WOOD_BASE;
+    case EL_WALL_ICE:          return EL_WALL_ICE_BASE;
+    case EL_WALL_AMOEBA:       return EL_WALL_AMOEBA_BASE;
+    case EL_DF_WALL_STEEL:     return EL_DF_WALL_STEEL_BASE;
+    case EL_DF_WALL_WOOD:      return EL_DF_WALL_WOOD_BASE;
 
-    default:
-      return el2img_mm(element);
+    default:                   return element;
   }
 }
 
+int el2gfx(int element)
+{
+  return el2img_mm(map_wall_from_base_element(element));
+}
+
+int el_act2gfx(int element, int action)
+{
+  return el_act2img_mm(map_wall_from_base_element(element), action);
+}
+
 void RedrawPlayfield_MM(void)
 {
   DrawLevel_MM();
@@ -1337,6 +1383,6 @@ void RedrawPlayfield_MM(void)
 
 void BlitScreenToBitmap_MM(Bitmap *target_bitmap)
 {
-  BlitBitmap(drawto_field, target_bitmap,
+  BlitBitmap(drawto_mm, target_bitmap,
             REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, REAL_SX, REAL_SY);
 }