rnd-20030223-2-src
[rocksndiamonds.git] / src / tools.c
index 5569bce9ce46e1d4bbdec448a695dc15d3e8dcc6..7330f9f9c2e11bce490501dc316342efb56c787b 100644 (file)
@@ -254,7 +254,7 @@ void BackToFront()
               MICROLEV_XPOS, MICROLEV_YPOS, MICROLEV_XSIZE, MICROLEV_YSIZE,
               MICROLEV_XPOS, MICROLEV_YPOS);
     BlitBitmap(backbuffer, window,
-              SX, MICROLABEL_YPOS, SXSIZE, FONT4_YSIZE,
+              SX, MICROLABEL_YPOS, SXSIZE, getFontHeight(FONT_SPECIAL_GAME),
               SX, MICROLABEL_YPOS);
     redraw_mask &= ~REDRAW_MICROLEVEL;
   }
@@ -279,7 +279,7 @@ void BackToFront()
       info1[0] = '\0';
 
     sprintf(text, "%.1f fps%s", global.frames_per_second, info1);
-    DrawTextExt(window, SX, SY, text, FS_SMALL, FC_YELLOW, FONT_OPAQUE);
+    DrawTextExt(window, SX, SY, text, FONT_DEFAULT_SMALL, FONT_OPAQUE);
   }
 
   FlushDisplay();
@@ -367,7 +367,7 @@ void SetMainBackgroundImage(int graphic)
   SetMainBackgroundBitmap(graphic == IMG_UNDEFINED ? NULL :
                          graphic_info[graphic].bitmap ?
                          graphic_info[graphic].bitmap :
-                         graphic_info[IMG_BACKGROUND_DEFAULT].bitmap);
+                         graphic_info[IMG_BACKGROUND].bitmap);
 }
 
 void SetDoorBackgroundImage(int graphic)
@@ -375,7 +375,7 @@ void SetDoorBackgroundImage(int graphic)
   SetDoorBackgroundBitmap(graphic == IMG_UNDEFINED ? NULL :
                          graphic_info[graphic].bitmap ?
                          graphic_info[graphic].bitmap :
-                         graphic_info[IMG_BACKGROUND_DEFAULT].bitmap);
+                         graphic_info[IMG_BACKGROUND].bitmap);
 }
 
 void DrawBackground(int dest_x, int dest_y, int width, int height)
@@ -437,7 +437,7 @@ void SetBorderElement()
 
 void SetRandomAnimationValue(int x, int y)
 {
-  anim.random_frame = GfxRandom[x][y];
+  gfx.anim_random_frame = GfxRandom[x][y];
 }
 
 inline int getGraphicAnimationFrame(int graphic, int sync_frame)
@@ -560,7 +560,9 @@ void DrawPlayer(struct PlayerInfo *player)
   if (element == EL_EXPLOSION)
     return;
 
-  /* draw things in the field the player is leaving, if needed */
+  /* ----------------------------------------------------------------------- */
+  /* draw things in the field the player is leaving, if needed               */
+  /* ----------------------------------------------------------------------- */
 
   if (player_is_moving)
   {
@@ -598,7 +600,9 @@ void DrawPlayer(struct PlayerInfo *player)
   if (setup.direct_draw)
     SetDrawtoField(DRAW_BUFFERED);
 
-  /* draw things behind the player, if needed */
+  /* ----------------------------------------------------------------------- */
+  /* draw things behind the player, if needed                                */
+  /* ----------------------------------------------------------------------- */
 
   if (Store[jx][jy])
     DrawLevelElement(jx, jy, Store[jx][jy]);
@@ -607,88 +611,32 @@ void DrawPlayer(struct PlayerInfo *player)
   else
     DrawLevelElement(jx, jy, EL_EMPTY);
 
-  /* draw player himself */
+  /* ----------------------------------------------------------------------- */
+  /* draw player himself                                                     */
+  /* ----------------------------------------------------------------------- */
 
-  if (game.emulation == EMU_SUPAPLEX)
-  {
-    static int last_dir = MV_LEFT;
-    int action = (player->programmed_action ? player->programmed_action :
-                 player->action);
-    boolean action_moving =
-      (player_is_moving ||
-       ((action & (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)) &&
-       !(action & ~(MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN))));
+  player->GfxAction = (player->Pushing ? ACTION_PUSHING :
+                      player->is_digging ? ACTION_DIGGING :
+                      player->is_moving ? ACTION_MOVING :
+                      player->snapped ? ACTION_SNAPPING : ACTION_DEFAULT);
 
-    graphic = IMG_SP_MURPHY;
+  if (player->use_murphy_graphic)
+  {
+    static int last_horizontal_dir = MV_LEFT;
+    int direction;
 
-    if (player->Pushing)
-    {
-      if (player->MovDir == MV_LEFT)
-       graphic = IMG_SP_MURPHY_PUSHING_LEFT;
-      else if (player->MovDir == MV_RIGHT)
-       graphic = IMG_SP_MURPHY_PUSHING_RIGHT;
-      else if (player->MovDir & (MV_UP | MV_DOWN) && last_dir == MV_LEFT)
-       graphic = IMG_SP_MURPHY_PUSHING_LEFT;
-      else if (player->MovDir & (MV_UP | MV_DOWN) && last_dir == MV_RIGHT)
-       graphic = IMG_SP_MURPHY_PUSHING_RIGHT;
-    }
-    else if (player->snapped)
-    {
-      if (player->MovDir == MV_LEFT)
-       graphic = IMG_SP_MURPHY_SNAPPING_LEFT;
-      else if (player->MovDir == MV_RIGHT)
-       graphic = IMG_SP_MURPHY_SNAPPING_RIGHT;
-      else if (player->MovDir == MV_UP)
-       graphic = IMG_SP_MURPHY_SNAPPING_UP;
-      else if (player->MovDir == MV_DOWN)
-       graphic = IMG_SP_MURPHY_SNAPPING_DOWN;
-    }
-    else if (action_moving)
-    {
-      if (player->MovDir == MV_LEFT)
-       graphic = IMG_SP_MURPHY_MOVING_LEFT;
-      else if (player->MovDir == MV_RIGHT)
-       graphic = IMG_SP_MURPHY_MOVING_RIGHT;
-      else if (player->MovDir & (MV_UP | MV_DOWN) && last_dir == MV_LEFT)
-       graphic = IMG_SP_MURPHY_MOVING_LEFT;
-      else if (player->MovDir & (MV_UP | MV_DOWN) && last_dir == MV_RIGHT)
-       graphic = IMG_SP_MURPHY_MOVING_RIGHT;
-      else
-       graphic = IMG_SP_MURPHY_MOVING_LEFT;
+    if (player->MovDir == MV_LEFT || player->MovDir == MV_RIGHT)
+      last_horizontal_dir = player->MovDir;
 
-      frame = getGraphicAnimationFrame(graphic, -1);
-    }
+    direction = (player->snapped ? player->MovDir : last_horizontal_dir);
 
-    if (player->MovDir == MV_LEFT || player->MovDir == MV_RIGHT)
-      last_dir = player->MovDir;
+    graphic = el_act_dir2img(EL_SP_MURPHY, player->GfxAction, direction);
   }
   else
-  {
-    if (player->MovDir == MV_LEFT)
-      graphic = (player->Pushing ? IMG_PLAYER1_PUSHING_LEFT :
-                player->is_moving ? IMG_PLAYER1_MOVING_LEFT :
-                IMG_PLAYER1_LEFT);
-    else if (player->MovDir == MV_RIGHT)
-      graphic = (player->Pushing ? IMG_PLAYER1_PUSHING_RIGHT :
-                player->is_moving ? IMG_PLAYER1_MOVING_RIGHT :
-                IMG_PLAYER1_RIGHT);
-    else if (player->MovDir == MV_UP)
-      graphic = (player->Pushing ? IMG_PLAYER1_PUSHING_UP :
-                player->is_moving ? IMG_PLAYER1_MOVING_UP :
-                IMG_PLAYER1_UP);
-    else       /* MV_DOWN || MV_NO_MOVING */
-      graphic = (player->Pushing ? IMG_PLAYER1_PUSHING_DOWN :
-                player->is_moving ? IMG_PLAYER1_MOVING_DOWN :
-                IMG_PLAYER1_DOWN);
-
-    graphic = PLAYER_NR_GFX(graphic, player->index_nr);
+    graphic = el_act_dir2img(player->element_nr, player->GfxAction,
+                            player->MovDir);
 
-#if 0
-    frame = player->Frame;
-#else
-    frame = getGraphicAnimationFrame(graphic, player->Frame);
-#endif
-  }
+  frame = getGraphicAnimationFrame(graphic, player->Frame);
 
   if (player->GfxPos)
   {
@@ -701,11 +649,6 @@ void DrawPlayer(struct PlayerInfo *player)
   if (!setup.soft_scrolling && ScreenMovPos)
     sxx = syy = 0;
 
-#if 0
-  if (player->Frame)
-    printf("-> %d\n", player->Frame);
-#endif
-
   DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, frame, NO_CUTTING);
 
   if (SHIELD_ON(player))
@@ -717,11 +660,11 @@ void DrawPlayer(struct PlayerInfo *player)
     DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, frame, NO_CUTTING);
   }
 
-#if 0
-  if (player->Pushing && player->GfxPos)
-#else
+  /* ----------------------------------------------------------------------- */
+  /* draw things the player is pushing, if needed                            */
+  /* ----------------------------------------------------------------------- */
+
   if (player->Pushing && player_is_moving)
-#endif
   {
     int px = SCREENX(next_jx), py = SCREENY(next_jy);
 
@@ -734,35 +677,12 @@ void DrawPlayer(struct PlayerInfo *player)
     {
       int element = Feld[next_jx][next_jy];
       int graphic = el2img(element);
-#if 1
       int frame = 0;
-#endif
 
       if ((sxx || syy) && IS_PUSHABLE(element))
       {
        graphic = el_act_dir2img(element, ACTION_MOVING, player->MovDir);
-#if 1
-       frame = getGraphicAnimationFrame(graphic, player->GfxPos);
-
        frame = getGraphicAnimationFrame(graphic, player->Frame);
-#endif
-
-#if 0
-       printf("-> %d [%d]\n", player->Frame, player->GfxPos);
-#endif
-
-#if 0
-       /* !!! FIX !!! */
-       if (player->MovDir == MV_LEFT)
-         frame = 3 - frame;
-#endif
-
-#if 0
-       frame = (player->GfxPos / (TILEX / 4));
-
-       if (player->MovDir == MV_RIGHT)
-         frame = (frame + 4) % 4;
-#endif
       }
 
       DrawGraphicShifted(px, py, sxx, syy, graphic, frame,
@@ -770,32 +690,14 @@ void DrawPlayer(struct PlayerInfo *player)
     }
   }
 
-  /* draw things in front of player (active dynamite or dynabombs) */
+  /* ----------------------------------------------------------------------- */
+  /* draw things in front of player (active dynamite or dynabombs)           */
+  /* ----------------------------------------------------------------------- */
 
   if (IS_ACTIVE_BOMB(element))
   {
     graphic = el2img(element);
-
-#if 0
-    if (element == EL_DYNAMITE_ACTIVE)
-    {
-      if ((frame = (96 - MovDelay[jx][jy]) / 12) > 6)
-       frame = 6;
-    }
-    else
-    {
-      if ((frame = ((96 - MovDelay[jx][jy]) / 6) % 8) > 3)
-       frame = 7 - frame;
-    }
-#else
-
-#if 0
-    frame = getGraphicAnimationFrame(graphic, 96 - MovDelay[jx][jy]);
-#else
     frame = getGraphicAnimationFrame(graphic, GfxFrame[jx][jy]);
-#endif
-
-#endif
 
     if (game.emulation == EMU_SUPAPLEX)
       DrawGraphic(sx, sy, IMG_SP_DISK_RED, frame);
@@ -817,7 +719,10 @@ void DrawPlayer(struct PlayerInfo *player)
       DrawGraphicThruMask(SCREENX(last_jx), SCREENY(last_jy), graphic, frame);
   }
 
-  /* draw elements that stay over the player */
+  /* ----------------------------------------------------------------------- */
+  /* draw elements that stay over the player                                 */
+  /* ----------------------------------------------------------------------- */
+
   /* handle the field the player is leaving ... */
   if (player_is_moving && IS_OVER_PLAYER(last_element))
     DrawLevelField(last_jx, last_jy);
@@ -1621,13 +1526,12 @@ static void DrawMicroLevelExt(int xpos, int ypos, int from_x, int from_y)
 #define MICROLABEL_IMPORTED_FROM       4
 #define MICROLABEL_LEVEL_IMPORT_INFO   5
 
-#define MAX_MICROLABEL_SIZE            (SXSIZE / FONT4_XSIZE)
-
 static void DrawMicroLevelLabelExt(int mode)
 {
-  char label_text[MAX_MICROLABEL_SIZE + 1];
+  char label_text[MAX_OUTPUT_LINESIZE + 1];
+  int max_len_label_text = SXSIZE / getFontWidth(FONT_SPECIAL_GAME);
 
-  DrawBackground(SX, MICROLABEL_YPOS, SXSIZE, FONT4_YSIZE);
+  DrawBackground(SX, MICROLABEL_YPOS, SXSIZE,getFontHeight(FONT_SPECIAL_GAME));
 
   strncpy(label_text, (mode == MICROLABEL_LEVEL_NAME ? level.name :
                       mode == MICROLABEL_CREATED_BY ? "created by" :
@@ -1635,15 +1539,16 @@ static void DrawMicroLevelLabelExt(int mode)
                       mode == MICROLABEL_IMPORTED_FROM ? "imported from" :
                       mode == MICROLABEL_LEVEL_IMPORT_INFO ?
                       leveldir_current->imported_from : ""),
-         MAX_MICROLABEL_SIZE);
-  label_text[MAX_MICROLABEL_SIZE] = '\0';
+         max_len_label_text);
+  label_text[max_len_label_text] = '\0';
 
   if (strlen(label_text) > 0)
   {
-    int lxpos = SX + (SXSIZE - strlen(label_text) * FONT4_XSIZE) / 2;
+    int text_width = strlen(label_text) * getFontWidth(FONT_SPECIAL_GAME);
+    int lxpos = SX + (SXSIZE - text_width) / 2;
     int lypos = MICROLABEL_YPOS;
 
-    DrawText(lxpos, lypos, label_text, FS_SMALL, FC_SPECIAL2);
+    DrawText(lxpos, lypos, label_text, FONT_SPECIAL_GAME);
   }
 
   redraw_mask |= REDRAW_MICROLEVEL;
@@ -1811,7 +1716,7 @@ boolean Request(char *text, unsigned int req_state)
     text_line[tl] = 0;
 
     DrawText(DX + 50 - (tl * 14)/2, DY + 8 + ty * 16,
-            text_line, FS_SMALL, FC_YELLOW);
+            text_line, FONT_DEFAULT_SMALL);
 
     text += tl + (tc == ' ' ? 1 : 0);
   }
@@ -2471,10 +2376,10 @@ int el2img(int element)
 
 int el2edimg(int element)
 {
-  return element_info[element].editor_graphic;
+  return element_info[element].special_graphic[GFX_SPECIAL_ARG_EDITOR];
 }
 
 int el2preimg(int element)
 {
-  return element_info[element].preview_graphic;
+  return element_info[element].special_graphic[GFX_SPECIAL_ARG_PREVIEW];
 }