Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12489) draw citymap overlays in tilespec code
Home

[Freeciv-Dev] (PR#12489) draw citymap overlays in tilespec code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12489) draw citymap overlays in tilespec code
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 11 Mar 2005 15:08:49 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch moves the drawing of the citymap overlays ('t' behavior) into 
tilespec.c.

-jason

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.212
diff -u -r1.212 mapview_common.c
--- client/mapview_common.c     11 Mar 2005 17:11:25 -0000      1.212
+++ client/mapview_common.c     11 Mar 2005 23:07:21 -0000
@@ -1179,49 +1179,6 @@
     } adjc_dir_iterate_end;
   } gui_rect_iterate_end;
 
-  /* Draw citymap overlays on top. */
-  gui_rect_iterate(gui_x0, gui_y0, width, height,
-                  ptile, pedge, pcorner, gui_x, gui_y) {
-    const int canvas_x2 = gui_x - mapview.gui_x0;
-    const int canvas_y2 = gui_y - mapview.gui_y0;
-
-    if (ptile && tile_get_known(ptile) != TILE_UNKNOWN) {
-      struct unit *punit;
-      struct city *pcity;
-      int city_x, city_y;
-
-      pcity = find_city_or_settler_near_tile(ptile, &punit);
-      if (pcity
-         && pcity->client.colored
-         && map_to_city_map(&city_x, &city_y, pcity, ptile)) {
-       enum city_tile_type worker = get_worker_city(pcity, city_x, city_y);
-       int index = pcity->client.color_index % NUM_CITY_COLORS;
-
-       switch (worker) {
-       case C_TILE_EMPTY:
-         canvas_put_sprite_full(mapview.store,
-                                canvas_x2, canvas_y2,
-                                sprites.city.unworked_tile_overlay.p[index]);
-         break;
-       case C_TILE_WORKER:
-         canvas_put_sprite_full(mapview.store,
-                                canvas_x2, canvas_y2,
-                                sprites.city.worked_tile_overlay.p[index]);
-         break;
-       case C_TILE_UNAVAILABLE:
-         break;
-       }
-      } else if (punit && punit->client.colored) {
-       int index = punit->client.color_index % NUM_CITY_COLORS;
-
-       /* Draw citymap overlay for settlers. */
-       canvas_put_sprite_full(mapview.store,
-                              canvas_x2, canvas_y2,
-                              sprites.city.unworked_tile_overlay.p[index]);
-      }
-    }
-  } gui_rect_iterate_end;
-
   show_city_descriptions(canvas_x, canvas_y, width, height);
 
   if (!full) {
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.265
diff -u -r1.265 tilespec.c
--- client/tilespec.c   11 Mar 2005 17:11:26 -0000      1.265
+++ client/tilespec.c   11 Mar 2005 23:07:24 -0000
@@ -2734,16 +2734,19 @@
 }
 
 /**************************************************************************
-  Fill in the city tile output sprites for the tile.
+  Fill in the city overlays for the tile.  This includes the citymap
+  overlays on the mapview as well as the tile output sprites.
 **************************************************************************/
-static int fill_city_tile_output_sprite_array(struct tileset *t,
-                                             struct drawn_sprite *sprs,
-                                             const struct tile *ptile,
-                                             const struct city *citymode)
+static int fill_city_overlays_sprite_array(struct tileset *t,
+                                          struct drawn_sprite *sprs,
+                                          const struct tile *ptile,
+                                          const struct city *citymode)
 {
   const struct city *pcity;
+  struct unit *psettler;
   struct drawn_sprite *saved_sprs = sprs;
   int city_x, city_y;
+  const int NUM_CITY_COLORS = sprites.city.worked_tile_overlay.size;
 
   if (!ptile || tile_get_known(ptile) == TILE_UNKNOWN) {
     return 0;
@@ -2752,27 +2755,49 @@
   if (citymode) {
     pcity = citymode;
   } else {
-    pcity = find_city_near_tile(ptile);
-    if (!pcity || !pcity->client.colored) {
-      return 0;
-    }
+    pcity = find_city_or_settler_near_tile(ptile, &psettler);
   }
 
-  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], TRUE, ox, oy);
-    ADD_SPRITE(sprites.city.tile_shieldnum[shields], TRUE, ox, oy);
-    ADD_SPRITE(sprites.city.tile_tradenum[trade], TRUE, ox, oy);
+  if (pcity && map_to_city_map(&city_x, &city_y, pcity, ptile)) {
+    if (!citymode && pcity->client.colored) {
+      /* Add citymap overlay for a city. */
+      enum city_tile_type worker = get_worker_city(pcity, city_x, city_y);
+      int index = pcity->client.color_index % NUM_CITY_COLORS;
+
+      switch (worker) {
+      case C_TILE_EMPTY:
+       ADD_SPRITE_SIMPLE(sprites.city.unworked_tile_overlay.p[index]);
+       break;
+      case C_TILE_WORKER:
+       ADD_SPRITE_SIMPLE(sprites.city.worked_tile_overlay.p[index]);
+       break;
+      case C_TILE_UNAVAILABLE:
+       break;
+      }
+    }
+
+    if (get_worker_city(pcity, city_x, city_y) == C_TILE_WORKER
+       && (citymode || pcity->client.colored)) {
+      /* Add on the tile output sprites. */
+      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], TRUE, ox, oy);
+      ADD_SPRITE(sprites.city.tile_shieldnum[shields], TRUE, ox, oy);
+      ADD_SPRITE(sprites.city.tile_tradenum[trade], TRUE, ox, oy);
+    }
+  } else if (psettler && psettler->client.colored) {
+    /* Add citymap overlay for a unit. */
+    int index = psettler->client.color_index % NUM_CITY_COLORS;
+
+    ADD_SPRITE_SIMPLE(sprites.city.unworked_tile_overlay.p[index]);
   }
 
   return sprs - saved_sprs;
@@ -3486,7 +3511,7 @@
     break;
 
   case LAYER_OVERLAYS:
-    sprs += fill_city_tile_output_sprite_array(t, sprs, ptile, citymode);
+    sprs += fill_city_overlays_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#12489) draw citymap overlays in tilespec code, Jason Short <=