moved function to different source file
[rocksndiamonds.git] / src / game_mm / mm_tools.c
index 54c2572815b1322e8715b8fd07da80f04a58f3f2..ae20aa24d428bb78969df40ba17aa907a95f0262 100644 (file)
@@ -1,15 +1,13 @@
-/***********************************************************
-* Mirror Magic -- McDuffin's Revenge                       *
-*----------------------------------------------------------*
-* (c) 1994-2001 Artsoft Entertainment                      *
-*               Holger Schemel                             *
-*               Detmolder Strasse 189                      *
-*               33604 Bielefeld                            *
-*               Germany                                    *
-*               e-mail: info@artsoft.org                   *
-*----------------------------------------------------------*
-* tools.c                                                  *
-***********************************************************/
+// ============================================================================
+// Mirror Magic -- McDuffin's Revenge
+// ----------------------------------------------------------------------------
+// (c) 1994-2017 by Artsoft Entertainment
+//                         Holger Schemel
+//                 info@artsoft.org
+//                 https://www.artsoft.org/
+// ----------------------------------------------------------------------------
+// mm_tools.c
+// ============================================================================
 
 #include "main_mm.h"
 
@@ -67,8 +65,10 @@ void DrawGraphic_MM(int x, int y, int graphic)
 #if DEBUG
   if (!IN_SCR_FIELD(x,y))
   {
-    printf("DrawGraphic_MM(): x = %d, y = %d, graphic = %d\n",x,y,graphic);
-    printf("DrawGraphic_MM(): This should never happen!\n");
+    Debug("game:mm:DrawGraphic_MM", "x = %d, y = %d, graphic = %d",
+         x, y, graphic);
+    Debug("game:mm:DrawGraphic_MM", "This should never happen!");
+
     return;
   }
 #endif
@@ -93,8 +93,10 @@ void DrawGraphicThruMask_MM(int x, int y, int graphic)
 #if DEBUG
   if (!IN_SCR_FIELD(x,y))
   {
-    printf("DrawGraphicThruMask_MM(): x = %d,y = %d, graphic = %d\n",x,y,graphic);
-    printf("DrawGraphicThruMask_MM(): This should never happen!\n");
+    Debug("game:mm:DrawGraphicThruMask_MM", "x = %d,y = %d, graphic = %d",
+         x, y, graphic);
+    Debug("game:mm:DrawGraphicThruMask_MM", "This should never happen!");
+
     return;
   }
 #endif
@@ -127,10 +129,12 @@ void DrawMiniGraphic_MM(int x, int y, int graphic)
   MarkTileDirty(x / 2, y / 2);
 }
 
-void getMicroGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y)
+#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)
 {
@@ -157,35 +161,35 @@ void DrawGraphicShifted_MM(int x,int y, int dx,int dy, int graphic,
     return;
   }
 
-  if (dx || dy)                        /* Verschiebung der Grafik? */
+  if (dx || dy)                        // Verschiebung der Grafik?
   {
-    if (x < BX1)               /* Element kommt von links ins Bild */
+    if (x < BX1)               // Element kommt von links ins Bild
     {
       x = BX1;
       width = dx;
       cx = TILEX - dx;
       dx = 0;
     }
-    else if (x > BX2)          /* Element kommt von rechts ins Bild */
+    else if (x > BX2)          // Element kommt von rechts ins Bild
     {
       x = BX2;
       width = -dx;
       dx = TILEX + dx;
     }
-    else if (x==BX1 && dx < 0) /* Element verläßt links das Bild */
+    else if (x==BX1 && dx < 0) // Element verläßt links das Bild
     {
       width += dx;
       cx = -dx;
       dx = 0;
     }
-    else if (x==BX2 && dx > 0) /* Element verläßt rechts das Bild */
+    else if (x==BX2 && dx > 0) // Element verläßt rechts das Bild
       width -= dx;
-    else if (dx)               /* allg. Bewegung in x-Richtung */
+    else if (dx)               // allg. Bewegung in x-Richtung
       MarkTileDirty(x + SIGN(dx), y);
 
-    if (y < BY1)               /* Element kommt von oben ins Bild */
+    if (y < BY1)               // Element kommt von oben ins Bild
     {
-      if (cut_mode==CUT_BELOW) /* Element oberhalb des Bildes */
+      if (cut_mode==CUT_BELOW) // Element oberhalb des Bildes
        return;
 
       y = BY1;
@@ -193,13 +197,13 @@ void DrawGraphicShifted_MM(int x,int y, int dx,int dy, int graphic,
       cy = TILEY - dy;
       dy = 0;
     }
-    else if (y > BY2)          /* Element kommt von unten ins Bild */
+    else if (y > BY2)          // Element kommt von unten ins Bild
     {
       y = BY2;
       height = -dy;
       dy = TILEY + dy;
     }
-    else if (y==BY1 && dy < 0) /* Element verläßt oben das Bild */
+    else if (y==BY1 && dy < 0) // Element verläßt oben das Bild
     {
       height += dy;
       cy = -dy;
@@ -207,19 +211,19 @@ void DrawGraphicShifted_MM(int x,int y, int dx,int dy, int graphic,
     }
     else if (dy > 0 && cut_mode == CUT_ABOVE)
     {
-      if (y == BY2)            /* Element unterhalb des Bildes */
+      if (y == BY2)            // Element unterhalb des Bildes
        return;
 
       height = dy;
       cy = TILEY - dy;
       dy = TILEY;
       MarkTileDirty(x, y + 1);
-    }                          /* Element verläßt unten das Bild */
+    }                          // Element verläßt unten das Bild
     else if (dy > 0 && (y == BY2 || cut_mode == CUT_BELOW))
     {
       height -= dy;
     }
-    else if (dy)               /* allg. Bewegung in y-Richtung */
+    else if (dy)               // allg. Bewegung in y-Richtung
     {
       MarkTileDirty(x, y + SIGN(dy));
     }
@@ -236,8 +240,10 @@ void DrawGraphicShifted_MM(int x,int y, int dx,int dy, int graphic,
 #if DEBUG
   if (!IN_SCR_FIELD(x,y))
   {
-    printf("DrawGraphicShifted_MM(): x = %d, y = %d, graphic = %d\n",x,y,graphic);
-    printf("DrawGraphicShifted_MM(): This should never happen!\n");
+    Debug("game:mm:DrawGraphicShifted_MM", "x = %d, y = %d, graphic = %d",
+         x, y, graphic);
+    Debug("game:mm:DrawGraphicShifted_MM", "This should never happen!");
+
     return;
   }
 #endif
@@ -319,7 +325,7 @@ void DrawLevelElementThruMask_MM(int x, int y, int element)
 
 void DrawLevelFieldThruMask_MM(int x, int y)
 {
-  DrawLevelElementExt_MM(x, y, 0, 0, Feld[x][y], NO_CUTTING, USE_MASKING);
+  DrawLevelElementExt_MM(x, y, 0, 0, Tile[x][y], NO_CUTTING, USE_MASKING);
 }
 
 void DrawScreenElement_MM(int x, int y, int element)
@@ -335,7 +341,7 @@ void DrawLevelElement_MM(int x, int y, int element)
 
 void DrawScreenField_MM(int x, int y)
 {
-  int element = Feld[x][y];
+  int element = Tile[x][y];
 
   if (!IN_LEV_FIELD(x, y))
     return;
@@ -366,7 +372,7 @@ void DrawScreenField_MM(int x, int y)
 
     DrawScreenElement_MM(x, y, EL_EMPTY);
 
-    element = Feld[oldx][oldy];
+    element = Tile[oldx][oldy];
 
     if (horiz_move)
       DrawScreenElementShifted_MM(sx, sy, MovPos[oldx][oldy], 0, element,
@@ -413,12 +419,12 @@ void DrawMiniElementOrWall_MM(int sx, int sy, int scroll_x, int scroll_y)
   if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy)
     DrawMiniElement_MM(sx, sy, EL_EMPTY);
   else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy)
-    DrawMiniElement_MM(sx, sy, Feld[x][y]);
+    DrawMiniElement_MM(sx, sy, Tile[x][y]);
 }
 
 void DrawField_MM(int x, int y)
 {
-  int element = Feld[x][y];
+  int element = Tile[x][y];
 
   DrawElement_MM(x, y, element);
 }
@@ -533,9 +539,9 @@ void DrawElement_MM(int x, int y, int element)
   else if (IS_WALL(element))
     DrawWalls_MM(x, y, element);
 #if 0
-  else if (IS_WALL_CHANGING(element) && IS_WALL_CHANGING(Feld[x][y]))
+  else if (IS_WALL_CHANGING(element) && IS_WALL_CHANGING(Tile[x][y]))
   {
-    int wall_element = Feld[x][y] - EL_WALL_CHANGING + Store[x][y];
+    int wall_element = Tile[x][y] - EL_WALL_CHANGING + Store[x][y];
 
     DrawWalls_MM(x, y, wall_element);
   }
@@ -551,7 +557,8 @@ void DrawElement_MM(int x, int y, int element)
     DrawGraphic_MM(x, y, el2gfx(element));
 }
 
-void DrawMicroWalls_MM(int x, int y, int element)
+#if 0
+static void DrawMicroWalls_MM(int x, int y, int element)
 {
   Bitmap *bitmap;
   int graphic = el2gfx(WALL_BASE(element));
@@ -572,7 +579,7 @@ void DrawMicroWalls_MM(int x, int y, int element)
   }
 }
 
-void DrawMicroElement_MM(int x, int y, int element)
+static void DrawMicroElement_MM(int x, int y, int element)
 {
   Bitmap *bitmap;
   int graphic = el2gfx(element);
@@ -594,7 +601,7 @@ void DrawMicroElement_MM(int x, int y, int element)
             MICROLEV_XPOS + x * MICRO_TILEX, MICROLEV_YPOS + y * MICRO_TILEY);
 }
 
-void DrawMicroLevelExt_MM(int xpos, int ypos)
+static void DrawMicroLevelExt_MM(int xpos, int ypos)
 {
   int x, y;
 
@@ -606,19 +613,77 @@ void DrawMicroLevelExt_MM(int xpos, int ypos)
 
   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++)
+  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;
 }
 
-int REQ_in_range(int x, int y)
+void DrawTileCursor_MM(int draw_target, boolean tile_cursor_active)
+{
+  Bitmap *fade_bitmap;
+  Bitmap *src_bitmap;
+  int src_x, src_y;
+  int dst_x, dst_y;
+  int graphic = IMG_GLOBAL_TILE_CURSOR;
+  int frame = 0;
+  int tilesize = TILESIZE_VAR;
+  int width = tilesize;
+  int height = tilesize;
+
+  if (!tile_cursor.enabled ||
+      !tile_cursor.active ||
+      !tile_cursor_active)
+    return;
+
+  if (tile_cursor.moving)
+  {
+    int step = TILESIZE_VAR / 4;
+    int dx = tile_cursor.target_x - tile_cursor.x;
+    int dy = tile_cursor.target_y - tile_cursor.y;
+
+    if (ABS(dx) < step)
+      tile_cursor.x = tile_cursor.target_x;
+    else
+      tile_cursor.x += SIGN(dx) * step;
+
+    if (ABS(dy) < step)
+      tile_cursor.y = tile_cursor.target_y;
+    else
+      tile_cursor.y += SIGN(dy) * step;
+
+    if (tile_cursor.x == tile_cursor.target_x &&
+       tile_cursor.y == tile_cursor.target_y)
+      tile_cursor.moving = FALSE;
+  }
+
+  dst_x = tile_cursor.x;
+  dst_y = tile_cursor.y;
+
+  frame = getGraphicAnimationFrame(graphic, -1);
+
+  getSizedGraphicSource(graphic, frame, tilesize, &src_bitmap, &src_x, &src_y);
+
+  fade_bitmap =
+    (draw_target == DRAW_TO_FADE_SOURCE ? gfx.fade_bitmap_source :
+     draw_target == DRAW_TO_FADE_TARGET ? gfx.fade_bitmap_target : NULL);
+
+  if (draw_target == DRAW_TO_SCREEN)
+    BlitToScreenMasked(src_bitmap, src_x, src_y, width, height, dst_x, dst_y);
+  else
+    BlitBitmapMasked(src_bitmap, fade_bitmap, src_x, src_y, width, height,
+                    dst_x, dst_y);
+}
+
+#if 0
+static int REQ_in_range(int x, int y)
 {
   if (y > DY + 249 && y < DY + 278)
   {
@@ -630,6 +695,7 @@ int REQ_in_range(int x, int y)
 
   return 0;
 }
+#endif
 
 Pixel ReadPixel(DrawBuffer *bitmap, int x, int y)
 {