Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12469) draw city tile output through the tilespec code
Home

[Freeciv-Dev] (PR#12469) draw city tile output through the tilespec code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12469) draw city tile output through the tilespec code
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 9 Mar 2005 12:19:25 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12469 >

This patch moves the drawing of the city tile output sprites out of 
mapview_common and citydlg_common and into the tilespec code.  It is 
drawn as part of the overlays layer.

-jason

Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.66
diff -u -r1.66 citydlg_common.c
--- client/citydlg_common.c     8 Mar 2005 00:43:26 -0000       1.66
+++ client/citydlg_common.c     9 Mar 2005 20:17:34 -0000
@@ -186,25 +186,6 @@
                      punit, pcity_draw, canvas_x, canvas_y, pcity);
     } citydlg_iterate_end;
   } mapview_layer_iterate_end;
-
-  /* We have to put the output afterwards or it will be covered
-   * in iso-view.
-   *
-   * This sometimes will draw one of the lines on top of a city or
-   * unit pixmap (in iso-view). This should maybe be moved to
-   * put_one_tile to fix this, but maybe it wouldn't be a good idea because
-   * the lines would get obscured. */
-  citydlg_iterate(pcity, ptile, pedge, pcorner, canvas_x, canvas_y) {
-    int city_x, city_y;
-
-    if (ptile && map_to_city_map(&city_x, &city_y, pcity, ptile)
-       && tile_get_known(ptile) != TILE_UNKNOWN) {
-      if (pcity->city_map[city_x][city_y] == C_TILE_WORKER) {
-       put_city_tile_output(pcity, city_x, city_y,
-                            pcanvas, canvas_x, canvas_y);
-      }
-    }
-  } citydlg_iterate_end;
 }
 
 /**************************************************************************
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.208
diff -u -r1.208 mapview_common.c
--- client/mapview_common.c     9 Mar 2005 18:12:33 -0000       1.208
+++ client/mapview_common.c     9 Mar 2005 20:17:35 -0000
@@ -966,40 +966,6 @@
 }
 
 /****************************************************************************
-  Draw food, shield, and trade output values on the tile.
-
-  The proper way to do this is probably something like what Civ II does
-  (one sprite drawn N times on top of itself), but we just use separate
-  sprites (limiting the number of combinations).
-****************************************************************************/
-void put_city_tile_output(struct city *pcity, int city_x, int city_y,
-                         struct canvas *pcanvas,
-                         int canvas_x, int canvas_y)
-{
-  int food = city_get_output_tile(city_x, city_y, pcity, O_FOOD);
-  int shields = city_get_output_tile(city_x, city_y, pcity, O_SHIELD);
-  int trade = city_get_output_tile(city_x, city_y, pcity, O_TRADE);
-
-  food = CLIP(0, food, NUM_TILES_DIGITS - 1);
-  shields = CLIP(0, shields, NUM_TILES_DIGITS - 1);
-  trade = CLIP(0, trade, NUM_TILES_DIGITS - 1);
-
-  /* In iso-view the output sprite is a bit smaller than the tile, so we
-   * have to use an offset. */
-  if (tileset_is_isometric()) {
-    canvas_x += NORMAL_TILE_WIDTH / 3;
-    canvas_y -= NORMAL_TILE_HEIGHT / 3;
-  }
-
-  canvas_put_sprite_full(pcanvas, canvas_x, canvas_y,
-                        sprites.city.tile_foodnum[food]);
-  canvas_put_sprite_full(pcanvas, canvas_x, canvas_y,
-                        sprites.city.tile_shieldnum[shields]);
-  canvas_put_sprite_full(pcanvas, canvas_x, canvas_y,
-                        sprites.city.tile_tradenum[trade]);
-}
-
-/****************************************************************************
   Draw food, gold, and shield upkeep values on the unit.
 
   The proper way to do this is probably something like what Civ II does
@@ -1249,8 +1215,6 @@
          canvas_put_sprite_full(mapview.store,
                                 canvas_x2, canvas_y2,
                                 sprites.city.worked_tile_overlay.p[index]);
-         put_city_tile_output(pcity, city_x, city_y,
-                              mapview.store, canvas_x2, canvas_y2);
          break;
        case C_TILE_UNAVAILABLE:
          break;
@@ -1622,7 +1586,7 @@
         closest one (only if punit != NULL).
     g.  If nobody can work it, return NULL.
 **************************************************************************/
-struct city *find_city_or_settler_near_tile(struct tile *ptile,
+struct city *find_city_or_settler_near_tile(const struct tile *ptile,
                                            struct unit **punit)
 {
   struct city *pcity = ptile->worked, *closest_city;
@@ -1706,7 +1670,7 @@
 /**************************************************************************
   Find the nearest/best city that owns the tile.
 **************************************************************************/
-struct city *find_city_near_tile(struct tile *ptile)
+struct city *find_city_near_tile(const struct tile *ptile)
 {
   return find_city_or_settler_near_tile(ptile, NULL);
 }
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.103
diff -u -r1.103 mapview_common.h
--- client/mapview_common.h     5 Mar 2005 02:23:29 -0000       1.103
+++ client/mapview_common.h     9 Mar 2005 20:17:35 -0000
@@ -254,9 +254,6 @@
 void put_terrain(struct tile *ptile,
                 struct canvas *pcanvas, int canvas_x, int canvas_y);
 
-void put_city_tile_output(struct city *pcity, int city_x, int city_y,
-                         struct canvas *pcanvas,
-                         int canvas_x, int canvas_y);
 void put_unit_city_overlays(struct unit *punit,
                            struct canvas *pcanvas,
                            int canvas_x, int canvas_y);
@@ -289,9 +286,9 @@
 void move_unit_map_canvas(struct unit *punit,
                          struct tile *ptile, int dx, int dy);
 
-struct city *find_city_or_settler_near_tile(struct tile *ptile,
+struct city *find_city_or_settler_near_tile(const struct tile *ptile,
                                            struct unit **punit);
-struct city *find_city_near_tile(struct tile *ptile);
+struct city *find_city_near_tile(const struct tile *ptile);
 
 void get_city_mapview_production(struct city *pcity,
                                  char *buf, size_t buf_len);
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.261
diff -u -r1.261 tilespec.c
--- client/tilespec.c   9 Mar 2005 18:12:34 -0000       1.261
+++ client/tilespec.c   9 Mar 2005 20:17:38 -0000
@@ -2728,6 +2728,52 @@
   return sprs - saved_sprs;
 }
 
+/**************************************************************************
+  Fill in the city tile output sprites for the tile.
+**************************************************************************/
+static int fill_city_tile_output_sprite_array(struct tileset *t,
+                                             struct drawn_sprite *sprs,
+                                             const struct tile *ptile,
+                                             const struct city *citymode)
+{
+  const struct city *pcity;
+  struct drawn_sprite *saved_sprs = sprs;
+  int city_x, city_y;
+
+  if (!ptile || tile_get_known(ptile) == TILE_UNKNOWN) {
+    return 0;
+  }
+
+  if (citymode) {
+    pcity = citymode;
+  } else {
+    pcity = find_city_near_tile(ptile);
+    if (!pcity || !pcity->client.colored) {
+      return 0;
+    }
+  }
+
+  if (map_to_city_map(&city_x, &city_y, pcity, ptile)
+      && get_worker_city(pcity, city_x, city_y) == C_TILE_WORKER) {
+    int food = city_get_output_tile(city_x, city_y, pcity, O_FOOD);
+    int shields = city_get_output_tile(city_x, city_y, pcity, O_SHIELD);
+    int trade = city_get_output_tile(city_x, city_y, pcity, O_TRADE);
+    const int ox = t->is_isometric ? NORMAL_TILE_WIDTH / 3 : 0;
+    const int oy = t->is_isometric ? -NORMAL_TILE_HEIGHT / 3 : 0;
+
+    food = CLIP(0, food, NUM_TILES_DIGITS - 1);
+    shields = CLIP(0, shields, NUM_TILES_DIGITS - 1);
+    trade = CLIP(0, trade, NUM_TILES_DIGITS - 1);
+
+    ADD_SPRITE(sprites.city.tile_foodnum[food], DRAW_NORMAL, TRUE, ox, oy);
+    ADD_SPRITE(sprites.city.tile_shieldnum[shields], DRAW_NORMAL,
+              TRUE, ox, oy);
+    ADD_SPRITE(sprites.city.tile_tradenum[trade], DRAW_NORMAL, TRUE, ox, oy);
+  }
+
+  return sprs - saved_sprs;
+}
+
 /****************************************************************************
   Fill in the sprite array for blended terrain.
 ****************************************************************************/
@@ -3428,6 +3474,7 @@
     break;
 
   case LAYER_OVERLAYS:
+    sprs += fill_city_tile_output_sprite_array(t, sprs, ptile, citymode);
     if (ptile && map_deco[ptile->index].crosshair > 0) {
       ADD_SPRITE_SIMPLE(sprites.user.attention);
     }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12469) draw city tile output through the tilespec code, Jason Short <=