renamed some variables to better describe their purpose
[rocksndiamonds.git] / src / game_em / graphics.c
index 972e0d94678ca5af2253a897a52cf30d88d7c3b9..b36f78cb1981913ba5846552571edfa24f182034 100644 (file)
 #define VALID_SCREEN_Y(y)      ((y) < MIN_SCREEN_Y ? MIN_SCREEN_Y :    \
                                 (y) > MAX_SCREEN_Y ? MAX_SCREEN_Y : (y))
 
-#define PLAYER_SCREEN_X(p)     (((7 - frame) * ply[p].oldx +           \
-                                 (1 + frame) * ply[p].x) * TILEX / 8   \
-                                - ((SCR_FIELDX - 1) * TILEX) / 2)
-#define PLAYER_SCREEN_Y(p)     (((7 - frame) * ply[p].oldy +           \
-                                 (1 + frame) * ply[p].y) * TILEY / 8   \
-                                - ((SCR_FIELDY - 1) * TILEY) / 2)
+#define PLAYER_POS_X(nr)       (((7 - frame) * ply[nr].oldx +          \
+                                 (1 + frame) * ply[nr].x) * TILEX / 8)
+#define PLAYER_POS_Y(nr)       (((7 - frame) * ply[nr].oldy +          \
+                                 (1 + frame) * ply[nr].y) * TILEY / 8)
+
+#define PLAYER_SCREEN_X(nr)    (PLAYER_POS_X(nr) -                     \
+                                (SCR_FIELDX - 1) * TILEX / 2)
+#define PLAYER_SCREEN_Y(nr)    (PLAYER_POS_Y(nr) -                     \
+                                (SCR_FIELDY - 1) * TILEY / 2)
 
 #define USE_EXTENDED_GRAPHICS_ENGINE           1
 
@@ -43,7 +46,7 @@ static int screen_tiles[MAX_PLAYFIELD_WIDTH + 2][MAX_PLAYFIELD_HEIGHT + 2];
 static int crumbled_state[MAX_PLAYFIELD_WIDTH + 2][MAX_PLAYFIELD_HEIGHT + 2];
 
 /* graphic info for game objects/frames and players/actions/frames */
-struct GraphicInfo_EM graphic_info_em_object[TILE_MAX][8];
+struct GraphicInfo_EM graphic_info_em_object[GAME_TILE_MAX][8];
 struct GraphicInfo_EM graphic_info_em_player[MAX_PLAYERS][PLY_MAX][8];
 
 int getFieldbufferOffsetX_EM(void)
@@ -70,44 +73,40 @@ void BlitScreenToBitmap_EM(Bitmap *target_bitmap)
   int sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0);
   int sxsize = (full_xsize < xsize ? full_xsize : xsize);
   int sysize = (full_ysize < ysize ? full_ysize : ysize);
+  int xxsize = MAX_BUF_XSIZE * TILEX - x;
+  int yysize = MAX_BUF_YSIZE * TILEY - y;
+  int xoffset = 2 * CAVE_BUFFER_XOFFSET * TILEX;
+  int yoffset = 2 * CAVE_BUFFER_YOFFSET * TILEY;
 
-  if (x < 2 * TILEX && y < 2 * TILEY)
+  if (x < xoffset && y < yoffset)
   {
-    BlitBitmap(screenBitmap, target_bitmap, x, y,
-              sxsize, sysize, sx, sy);
+    BlitBitmap(screenBitmap, target_bitmap, x, y, sxsize, sysize,
+              sx, sy);
   }
-  else if (x < 2 * TILEX && y >= 2 * TILEY)
+  else if (x < xoffset && y >= yoffset)
   {
-    BlitBitmap(screenBitmap, target_bitmap, x, y,
-              sxsize, MAX_BUF_YSIZE * TILEY - y,
+    BlitBitmap(screenBitmap, target_bitmap, x, y, sxsize, yysize,
               sx, sy);
-    BlitBitmap(screenBitmap, target_bitmap, x, 0,
-              sxsize, y - 2 * TILEY,
-              sx, sy + MAX_BUF_YSIZE * TILEY - y);
+    BlitBitmap(screenBitmap, target_bitmap, x, 0, sxsize, y - yoffset,
+              sx, sy + yysize);
   }
-  else if (x >= 2 * TILEX && y < 2 * TILEY)
+  else if (x >= xoffset && y < yoffset)
   {
-    BlitBitmap(screenBitmap, target_bitmap, x, y,
-              MAX_BUF_XSIZE * TILEX - x, sysize,
+    BlitBitmap(screenBitmap, target_bitmap, x, y, xxsize, sysize,
               sx, sy);
-    BlitBitmap(screenBitmap, target_bitmap, 0, y,
-              x - 2 * TILEX, sysize,
-              sx + MAX_BUF_XSIZE * TILEX - x, sy);
+    BlitBitmap(screenBitmap, target_bitmap, 0, y, x - xoffset, sysize,
+              sx + xxsize, sy);
   }
   else
   {
-    BlitBitmap(screenBitmap, target_bitmap, x, y,
-              MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y,
+    BlitBitmap(screenBitmap, target_bitmap, x, y, xxsize, yysize,
               sx, sy);
-    BlitBitmap(screenBitmap, target_bitmap, 0, y,
-              x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y,
-              sx + MAX_BUF_XSIZE * TILEX - x, sy);
-    BlitBitmap(screenBitmap, target_bitmap, x, 0,
-              MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY,
-              sx, sy + MAX_BUF_YSIZE * TILEY - y);
-    BlitBitmap(screenBitmap, target_bitmap, 0, 0,
-              x - 2 * TILEX, y - 2 * TILEY,
-              sx + MAX_BUF_XSIZE * TILEX - x, sy + MAX_BUF_YSIZE * TILEY - y);
+    BlitBitmap(screenBitmap, target_bitmap, 0, y, x - xoffset, yysize,
+              sx + xxsize, sy);
+    BlitBitmap(screenBitmap, target_bitmap, x, 0, xxsize, y - yoffset,
+              sx, sy + yysize);
+    BlitBitmap(screenBitmap, target_bitmap, 0, 0, x - xoffset, y - yoffset,
+              sx + xxsize, sy + yysize);
   }
 }
 
@@ -369,16 +368,16 @@ static void animscreen(void)
  * handles transparency and movement
  */
 
-static void blitplayer(struct PLAYER *ply)
+static void blitplayer(int nr)
 {
   int x1, y1, x2, y2;
 
-  if (!ply->alive)
+  if (!ply[nr].alive)
     return;
 
   /* x1/y1 are left/top and x2/y2 are right/down part of the player movement */
-  x1 = ((7 - frame) * ply->oldx + (1 + frame) * ply->x) * TILEX / 8;
-  y1 = ((7 - frame) * ply->oldy + (1 + frame) * ply->y) * TILEY / 8;
+  x1 = PLAYER_POS_X(nr);
+  y1 = PLAYER_POS_Y(nr);
   x2 = x1 + TILEX - 1;
   y2 = y1 + TILEY - 1;
 
@@ -386,10 +385,10 @@ static void blitplayer(struct PLAYER *ply)
       (int)(y2 - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
   {
     /* some casts to "int" are needed because of negative calculation values */
-    int dx = (int)ply->x - (int)ply->oldx;
-    int dy = (int)ply->y - (int)ply->oldy;
-    int old_x = (int)ply->oldx + (int)frame * dx / 8;
-    int old_y = (int)ply->oldy + (int)frame * dy / 8;
+    int dx = (int)ply[nr].x - (int)ply[nr].oldx;
+    int dy = (int)ply[nr].y - (int)ply[nr].oldy;
+    int old_x = (int)ply[nr].oldx + (int)frame * dx / 8;
+    int old_y = (int)ply[nr].oldy + (int)frame * dy / 8;
     int new_x = old_x + SIGN(dx);
     int new_y = old_y + SIGN(dy);
     int old_sx = old_x % MAX_BUF_XSIZE;
@@ -408,7 +407,7 @@ static void blitplayer(struct PLAYER *ply)
       DrawLevelFieldCrumbled_EM(new_x, new_y, new_sx, new_sy, new_crm, FALSE);
 
       /* draw the player (masked) over the element he is just digging away */
-      DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, TRUE);
+      DrawLevelPlayer_EM(x1, y1, ply[nr].num, ply[nr].anim, TRUE);
 
       /* draw the field the player is moving from (masked over the player) */
       DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
@@ -416,7 +415,7 @@ static void blitplayer(struct PLAYER *ply)
     else
     {
       /* draw the player under the element which is on the same field */
-      DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, FALSE);
+      DrawLevelPlayer_EM(x1, y1, ply[nr].num, ply[nr].anim, FALSE);
 
       /* draw the field the player is moving from (masked over the player) */
       DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
@@ -555,7 +554,7 @@ static boolean checkIfAllPlayersAreVisible(int center_x, int center_y)
 void RedrawPlayfield_EM(boolean force_redraw)
 {
   boolean draw_new_player_location = FALSE;
-  boolean draw_new_player_location_fast = FALSE;
+  boolean draw_new_player_location_wrap = FALSE;
   boolean quick_relocation = setup.quick_switch;
   int max_center_distance_player_nr =
     getMaxCenterDistancePlayerNr(screen_x, screen_y);
@@ -594,11 +593,11 @@ void RedrawPlayfield_EM(boolean force_redraw)
     game.centered_player_nr = game.centered_player_nr_next;
 
     draw_new_player_location = TRUE;
-    draw_new_player_location_fast = game.set_centered_player_fast;
+    draw_new_player_location_wrap = game.set_centered_player_wrap;
     force_redraw = TRUE;
 
     game.set_centered_player = FALSE;
-    game.set_centered_player_fast = FALSE;
+    game.set_centered_player_wrap = FALSE;
   }
 
   if (game.centered_player_nr == -1)
@@ -634,7 +633,7 @@ void RedrawPlayfield_EM(boolean force_redraw)
     int screen_xx = VALID_SCREEN_X(sx);
     int screen_yy = VALID_SCREEN_Y(sy);
 
-    if (draw_new_player_location_fast)
+    if (draw_new_player_location_wrap)
       wait_delay_value /= 4;
 
     SetVideoFrameDelay(wait_delay_value);
@@ -677,7 +676,7 @@ void RedrawPlayfield_EM(boolean force_redraw)
       animscreen();
 
       for (i = 0; i < MAX_PLAYERS; i++)
-       blitplayer(&ply[i]);
+       blitplayer(i);
 
       BlitScreenToBitmap_EM(backbuffer);
       BackToFront_EM();
@@ -689,7 +688,7 @@ void RedrawPlayfield_EM(boolean force_redraw)
       animscreen();
 
       for (i = 0; i < MAX_PLAYERS; i++)
-       blitplayer(&ply[i]);
+       blitplayer(i);
 
       BlitScreenToBitmap_EM(backbuffer);
       BackToFront_EM();
@@ -783,5 +782,5 @@ void RedrawPlayfield_EM(boolean force_redraw)
   animscreen();
 
   for (i = 0; i < MAX_PLAYERS; i++)
-    blitplayer(&ply[i]);
+    blitplayer(i);
 }