Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] Re: (PR#12140) use sprites to draw the mapview grid
Home

[Freeciv-Dev] Re: (PR#12140) use sprites to draw the mapview grid

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#12140) use sprites to draw the mapview grid
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 11 Feb 2005 15:04:21 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This new version works with the draw_city_outlines option.

-jason


? data/isotrident/grid.png
? data/misc/colors.png
? data/trident/grid.png
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.90
diff -u -r1.90 mapview_common.h
--- client/mapview_common.h     9 Feb 2005 17:15:17 -0000       1.90
+++ client/mapview_common.h     11 Feb 2005 22:59:52 -0000
@@ -157,11 +157,11 @@
            pedge->tile[1] = map_pos_to_tile((GRI_sum - 4) / 4, /* S */     \
                                             (GRI_diff + 2) / 4);           \
          } else {                                                          \
-           pedge->type = EDGE_EW;                                          \
+           pedge->type = EDGE_WE;                                          \
            pedge->tile[0] = map_pos_to_tile((GRI_sum - 6) / 4,             \
-                                            GRI_diff / 4); /* E */         \
-           pedge->tile[1] = map_pos_to_tile((GRI_sum - 2) / 4,             \
                                             GRI_diff / 4); /* W */         \
+           pedge->tile[1] = map_pos_to_tile((GRI_sum - 2) / 4,             \
+                                            GRI_diff / 4); /* E */         \
          }                                                                 \
        }                                                                   \
       } else {                                                             \
@@ -186,17 +186,17 @@
          /* Edge. */                                                       \
          pedge = &GRI_edge;                                                \
          if (GRI_y_itr % 2 == 0) {                                         \
-           pedge->type = EDGE_EW;                                          \
-           pedge->tile[0] = map_pos_to_tile(GRI_x_itr / 2 - 1,             \
-                                            (GRI_y_itr - 1) / 2);          \
-           pedge->tile[1] = map_pos_to_tile(GRI_x_itr / 2,                 \
-                                            (GRI_y_itr - 1) / 2);          \
-         } else {                                                          \
            pedge->type = EDGE_NS;                                          \
-           pedge->tile[0] = map_pos_to_tile((GRI_x_itr - 1) / 2,           \
+           pedge->tile[0] = map_pos_to_tile((GRI_x_itr - 1) / 2, /* N */   \
                                             GRI_y_itr / 2 - 1);            \
-           pedge->tile[1] = map_pos_to_tile((GRI_x_itr - 1) / 2,           \
+           pedge->tile[1] = map_pos_to_tile((GRI_x_itr - 1) / 2, /* S */   \
                                             GRI_y_itr / 2);                \
+         } else {                                                          \
+           pedge->type = EDGE_WE;                                          \
+           pedge->tile[0] = map_pos_to_tile(GRI_x_itr / 2 - 1, /* W */     \
+                                            (GRI_y_itr - 1) / 2);          \
+           pedge->tile[1] = map_pos_to_tile(GRI_x_itr / 2, /* E */         \
+                                            (GRI_y_itr - 1) / 2);          \
          }                                                                 \
        }                                                                   \
       }                                                                        
    \
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.235
diff -u -r1.235 tilespec.c
--- client/tilespec.c   11 Feb 2005 16:57:59 -0000      1.235
+++ client/tilespec.c   11 Feb 2005 22:59:53 -0000
@@ -1459,6 +1459,54 @@
   SET_SPRITE(tx.airbase,    "tx.airbase");
   SET_SPRITE(tx.fog,        "tx.fog");
 
+  if (load_sprite("grid.main.ns")) {
+    for (i = 0; i < MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS; i++) {
+      my_snprintf(buffer, sizeof(buffer), "colors.player%d", i);
+      SET_SPRITE(colors.player[i], buffer);
+    }
+
+    for (i = 0; i < EDGE_COUNT; i++) {
+      char *name[EDGE_COUNT] = {"ns", "we"};
+      int j, p;
+
+      my_snprintf(buffer, sizeof(buffer), "grid.main.%s", name[i]);
+      SET_SPRITE(grid.main[i], buffer);
+
+      my_snprintf(buffer, sizeof(buffer), "grid.city.%s", name[i]);
+      SET_SPRITE(grid.city[i], buffer);
+
+      my_snprintf(buffer, sizeof(buffer), "grid.worked.%s", name[i]);
+      SET_SPRITE(grid.worked[i], buffer);
+
+      my_snprintf(buffer, sizeof(buffer), "grid.unavailable.%s", name[i]);
+      SET_SPRITE(grid.unavailable[i], buffer);
+
+      my_snprintf(buffer, sizeof(buffer), "grid.selected.%s", name[i]);
+      SET_SPRITE(grid.selected[i], buffer);
+
+      my_snprintf(buffer, sizeof(buffer), "grid.coastline.%s", name[i]);
+      SET_SPRITE(grid.coastline[i], buffer);
+
+      for (j = 0; j < 2; j++) {
+       struct Sprite *s;
+
+       my_snprintf(buffer, sizeof(buffer), "grid.borders.%c", name[i][j]);
+       SET_SPRITE(grid.borders[i][j], buffer);
+
+       for (p = 0; p < MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS; p++) {
+         if (sprites.colors.player[p] && sprites.grid.borders[i][j]) {
+           s = crop_sprite(sprites.colors.player[p],
+                           0, 0, NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT,
+                           sprites.grid.borders[i][j], 0, 0);
+         } else {
+           s = sprites.grid.borders[i][j];
+         }
+         sprites.grid.player_borders[p][i][j] = s;
+       }
+      }
+    }
+  }
+
   for (i = 0; i < num_index_cardinal; i++) {
     my_snprintf(buffer, sizeof(buffer), "tx.s_river_%s",
                cardinal_index_str(i));
@@ -2735,6 +2783,110 @@
 
 
 /****************************************************************************
+  Fill in the grid sprites for the given tile, city, and unit.
+****************************************************************************/
+static int fill_grid_sprite_array(struct drawn_sprite *sprs,
+                                 const struct tile *ptile,
+                                 const struct tile_edge *pedge,
+                                 const struct tile_corner *pcorner,
+                                 const struct unit *punit,
+                                 const struct city *pcity,
+                                 bool citymode)
+{
+  struct drawn_sprite *saved_sprs = sprs;
+
+  if (!sprites.grid.main[EDGE_NS]) {
+    if (ptile && tile_get_known(ptile) != TILE_UNKNOWN) {
+      /* Add grid.  In classic view this is done later. */
+      ADD_GRID(ptile, citymode);
+    }
+  } else if (pedge) {
+    bool known[EDGE_COUNT], city[EDGE_COUNT], unit[EDGE_COUNT];
+    bool worked[EDGE_COUNT], blocked[EDGE_COUNT];
+    int i;
+    struct unit *pfocus = get_unit_in_focus();
+
+    for (i = 0; i < 2; i++) {
+      struct tile *tile = pedge->tile[i];
+      struct player *powner = tile ? map_get_owner(tile) : NULL;
+      int dummy_x, dummy_y;
+
+      known[i] = tile && tile_get_known(tile) != TILE_UNKNOWN;
+      city[i] = tile && (powner == NULL || powner == game.player_ptr)
+       && player_in_city_radius(game.player_ptr, tile);
+      unit[i] = tile && pfocus && unit_flag(pfocus, F_CITIES)
+       && city_can_be_built_here(pfocus->tile, pfocus)
+       && base_map_to_city_map(&dummy_x, &dummy_y, pfocus->tile, tile);
+      worked[i] = blocked[i] = FALSE;
+      if (city[i]) {
+       enum city_tile_type ttype;
+       struct city *dummy;
+
+       get_worker_on_map_position(tile, &ttype, &dummy);
+       switch (ttype) {
+       case C_TILE_EMPTY:
+         break;
+       case C_TILE_WORKER:
+         worked[i] = TRUE;
+         break;
+       case C_TILE_UNAVAILABLE:
+         blocked[i] = TRUE;
+         break;
+       }
+      }
+    }
+
+    if ((pedge->tile[0]
+        && map_deco[pedge->tile[0]->index].hilite == HILITE_CITY)
+       || (pedge->tile[1]
+           && map_deco[pedge->tile[1]->index].hilite == HILITE_CITY)) {
+      ADD_SPRITE_SIMPLE(sprites.grid.selected[pedge->type]);
+    } else if (!draw_terrain && draw_coastline
+              && pedge->tile[0] && pedge->tile[1]
+              && known[0] && known[1]
+              && (is_ocean(pedge->tile[0]->terrain)
+                  ^ is_ocean(pedge->tile[1]->terrain))) {
+      ADD_SPRITE_SIMPLE(sprites.grid.coastline[pedge->type]);
+    } else if (draw_map_grid) {
+      if (blocked[0] || blocked[1]) {
+       ADD_SPRITE_SIMPLE(sprites.grid.unavailable[pedge->type]);
+      } else if (worked[0] || worked[1]) {
+       ADD_SPRITE_SIMPLE(sprites.grid.worked[pedge->type]);
+      } else if (city[0] || city[1]) {
+       ADD_SPRITE_SIMPLE(sprites.grid.city[pedge->type]);
+      } else if (known[0] || known[1]) {
+       ADD_SPRITE_SIMPLE(sprites.grid.main[pedge->type]);
+      }
+    } else if (draw_city_outlines) {
+      if (XOR(city[0], city[1])) {
+       ADD_SPRITE_SIMPLE(sprites.grid.city[pedge->type]);
+      }
+      if (XOR(unit[0], unit[1])) {
+       ADD_SPRITE_SIMPLE(sprites.grid.worked[pedge->type]);
+      }
+    }
+
+    if (draw_borders && game.borders > 0 && known[0] && known[1]) {
+      struct player *owner0 = map_get_owner(pedge->tile[0]);
+      struct player *owner1 = map_get_owner(pedge->tile[1]);
+
+      if (owner0 != owner1) {
+       if (owner0) {
+         ADD_SPRITE_SIMPLE(sprites.grid.player_borders
+                           [owner0->player_no][pedge->type][0]);
+       }
+       if (owner1) {
+         ADD_SPRITE_SIMPLE(sprites.grid.player_borders
+                           [owner1->player_no][pedge->type][1]);
+       }
+      }
+    }
+  }
+
+  return sprs - saved_sprs;
+}
+
+/****************************************************************************
   Fill in the sprite array for the given tile, city, and unit.
 
   ptile, if specified, gives the tile.  If specified the terrain and specials
@@ -2869,9 +3021,9 @@
     break;
 
   case LAYER_GRID1:
-    if (ptile && tile_get_known(ptile) != TILE_UNKNOWN && is_isometric) {
-      /* Add grid.  In classic view this is done later. */
-      ADD_GRID(ptile, citymode);
+    if (is_isometric) {
+      sprs += fill_grid_sprite_array(sprs, ptile, pedge, pcorner,
+                                    punit, pcity, citymode);
     }
     break;
 
@@ -2948,9 +3100,9 @@
     break;
 
   case LAYER_GRID2:
-    if (ptile && tile_get_known(ptile) != TILE_UNKNOWN && !is_isometric) {
-      /* Add grid.  In iso-view this is done earlier. */
-      ADD_GRID(ptile, citymode);
+    if (!is_isometric) {
+      sprs += fill_grid_sprite_array(sprs, ptile, pedge, pcorner,
+                                    punit, pcity, citymode);
     }
     break;
 
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.102
diff -u -r1.102 tilespec.h
--- client/tilespec.h   11 Feb 2005 16:57:59 -0000      1.102
+++ client/tilespec.h   11 Feb 2005 22:59:53 -0000
@@ -27,10 +27,12 @@
 struct Sprite;                 /* opaque; gui-dep */
 
 /* An edge is the border between two tiles.  This structure represents one
- * edge.  The tiles are in unspecified order for the moment. */
+ * edge.  The tiles are given in the same order as the enumeration name. */
 struct tile_edge {
   enum {
-    EDGE_NS, EDGE_EW
+    EDGE_NS, /* North and south */
+    EDGE_WE, /* West and east */
+    EDGE_COUNT
   } type;
   struct tile *tile[2];
 };
@@ -314,6 +316,20 @@
       *darkness[MAX_INDEX_CARDINAL],         /* first unused */
       *river_outlet[4];                /* indexed by enum direction4 */
   } tx;                                /* terrain extra */
+  struct {
+    struct Sprite
+      *main[EDGE_COUNT],
+      *city[EDGE_COUNT],
+      *worked[EDGE_COUNT],
+      *unavailable[EDGE_COUNT],
+      *selected[EDGE_COUNT],
+      *coastline[EDGE_COUNT],
+      *borders[EDGE_COUNT][2],
+      *player_borders[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS][EDGE_COUNT][2];
+  } grid;
+  struct {
+    struct Sprite *player[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS];
+  } colors;
 
   struct terrain_drawing_data *terrain[MAX_NUM_TERRAINS];
 };
Index: data/isotrident.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isotrident.tilespec,v
retrieving revision 1.28
diff -u -r1.28 isotrident.tilespec
--- data/isotrident.tilespec    11 Feb 2005 16:58:00 -0000      1.28
+++ data/isotrident.tilespec    11 Feb 2005 22:59:53 -0000
@@ -49,9 +49,11 @@
 ; low-color systems, and if there are any duplicate tags (lattermost
 ; tag is used).
 files = 
+  "misc/colors.spec",
   "isotrident/terrain1.spec",
   "isotrident/terrain2.spec",
   "isotrident/tiles.spec",
+  "isotrident/grid.spec",
   "misc/small.spec",
   "trident/units.spec",
   "isotrident/unitextras.spec",
Index: data/trident.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident.tilespec,v
retrieving revision 1.30
diff -u -r1.30 trident.tilespec
--- data/trident.tilespec       11 Feb 2005 16:58:00 -0000      1.30
+++ data/trident.tilespec       11 Feb 2005 22:59:53 -0000
@@ -45,10 +45,12 @@
 ; low-color systems, and if there are any duplicate tags (lattermost
 ; tag is used).
 files = 
+  "misc/colors.spec",
   "trident/tiles.spec",
   "misc/small.spec",
   "trident/units.spec",
   "misc/flags.spec",
+  "trident/grid.spec",
   "trident/roads.spec",
   "misc/buildings.spec",
   "misc/space.spec",
Index: data/trident_shields.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident_shields.tilespec,v
retrieving revision 1.20
diff -u -r1.20 trident_shields.tilespec
--- data/trident_shields.tilespec       11 Feb 2005 16:58:00 -0000      1.20
+++ data/trident_shields.tilespec       11 Feb 2005 22:59:53 -0000
@@ -48,10 +48,12 @@
 ; low-color systems, and if there are any duplicate tags (lattermost
 ; tag is used).
 files = 
+  "misc/colors.spec",
   "trident/tiles.spec",
   "misc/small.spec",
   "trident/units.spec",
   "misc/flags.spec",
+  "trident/grid.spec",
   "trident/roads.spec",
   "misc/buildings.spec",
   "misc/space.spec",
Index: data/isotrident/Makefile.am
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isotrident/Makefile.am,v
retrieving revision 1.7
diff -u -r1.7 Makefile.am
--- data/isotrident/Makefile.am 6 Feb 2005 22:11:11 -0000       1.7
+++ data/isotrident/Makefile.am 11 Feb 2005 22:59:53 -0000
@@ -8,6 +8,8 @@
        cities.spec     \
        fog.png         \
        fog.spec        \
+       grid.png        \
+       grid.spec       \
        morecities.png  \
        morecities.spec \
        nuke.spec       \
Index: data/isotrident/grid.spec
===================================================================
RCS file: data/isotrident/grid.spec
diff -N data/isotrident/grid.spec
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ data/isotrident/grid.spec   11 Feb 2005 22:59:53 -0000
@@ -0,0 +1,42 @@
+
+[spec]
+
+; Format and options of this spec file:
+options = "+spec3"
+
+[info]
+
+artists = "
+    Jason Dorje Short <jdorje@xxxxxxxxxxx>
+"
+
+[file]
+gfx = "isotrident/grid"
+
+[grid_main]
+
+x_top_left = 1
+y_top_left = 1
+dx = 64
+dy = 32
+pixel_border = 1
+
+tiles = { "row", "column", "tag"
+  0, 0, "grid.main.we"
+  1, 0, "grid.main.ns"
+  0, 1, "grid.city.we"
+  1, 1, "grid.city.ns"
+  0, 2, "grid.worked.we"
+  1, 2, "grid.worked.ns"
+  0, 3, "grid.unavailable.we"
+  1, 3, "grid.unavailable.ns"
+  0, 4, "grid.selected.we"
+  1, 4, "grid.selected.ns"
+  0, 5, "grid.coastline.we"
+  1, 5, "grid.coastline.ns"
+
+  2, 0, "grid.borders.n"
+  2, 1, "grid.borders.s"
+  2, 2, "grid.borders.w"
+  2, 3, "grid.borders.e"
+}
Index: data/misc/Makefile.am
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/misc/Makefile.am,v
retrieving revision 1.8
diff -u -r1.8 Makefile.am
--- data/misc/Makefile.am       3 Nov 2004 03:34:54 -0000       1.8
+++ data/misc/Makefile.am       11 Feb 2005 22:59:53 -0000
@@ -8,6 +8,8 @@
        buildings.spec  \
        chiefs.png      \
        chiefs.spec     \
+       colors.png      \
+       colors.spec     \
        flags.spec      \
        intro.png       \
        radar.png       \
Index: data/misc/colors.spec
===================================================================
RCS file: data/misc/colors.spec
diff -N data/misc/colors.spec
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ data/misc/colors.spec       11 Feb 2005 22:59:53 -0000
@@ -0,0 +1,60 @@
+
+[spec]
+
+; Format and options of this spec file:
+options = "+spec3"
+
+[info]
+
+artists = "
+    Jason Dorje Short <jdorje@xxxxxxxxxxx>
+"
+
+[file]
+gfx = "misc/colors"
+
+[grid_main]
+
+x_top_left = 2
+y_top_left = 2
+dx = 128
+dy = 64
+pixel_border=2
+
+tiles = { "row", "column", "tag"
+
+  0, 0, "colors.player0"
+  0, 1, "colors.player1"
+  0, 2, "colors.player2"
+  0, 3, "colors.player3"
+  1, 0, "colors.player4"
+  1, 1, "colors.player5"
+  1, 2, "colors.player6"
+  1, 3, "colors.player7"
+  2, 0, "colors.player8"
+  2, 1, "colors.player9"
+  2, 2, "colors.player10"
+  2, 3, "colors.player11"
+  3, 0, "colors.player12"
+  3, 1, "colors.player13"
+
+  0, 0, "colors.player14"
+  0, 1, "colors.player15"
+  0, 2, "colors.player16"
+  0, 3, "colors.player17"
+  1, 0, "colors.player18"
+  1, 1, "colors.player19"
+  1, 2, "colors.player20"
+  1, 3, "colors.player21"
+  2, 0, "colors.player22"
+  2, 1, "colors.player23"
+  2, 2, "colors.player24"
+  2, 3, "colors.player25"
+  3, 0, "colors.player26"
+  3, 1, "colors.player27"
+
+  0, 0, "colors.player28"
+  0, 1, "colors.player29"
+  0, 2, "colors.player30"
+  0, 3, "colors.player31"
+}
Index: data/trident/Makefile.am
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident/Makefile.am,v
retrieving revision 1.9
diff -u -r1.9 Makefile.am
--- data/trident/Makefile.am    6 Feb 2005 22:11:11 -0000       1.9
+++ data/trident/Makefile.am    11 Feb 2005 22:59:53 -0000
@@ -11,6 +11,8 @@
        explosions.spec \
        fog.png         \
        fog.spec        \
+       grid.png        \
+       grid.spec       \
        roads.png       \
        roads.spec      \
        tiles.png       \
Index: data/trident/grid.spec
===================================================================
RCS file: data/trident/grid.spec
diff -N data/trident/grid.spec
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ data/trident/grid.spec      11 Feb 2005 22:59:53 -0000
@@ -0,0 +1,42 @@
+
+[spec]
+
+; Format and options of this spec file:
+options = "+spec3"
+
+[info]
+
+artists = "
+    Jason Dorje Short <jdorje@xxxxxxxxxxx>
+"
+
+[file]
+gfx = "trident/grid"
+
+[grid_main]
+
+x_top_left = 1
+y_top_left = 1
+dx = 30
+dy = 30
+pixel_border = 1
+
+tiles = { "row", "column", "tag"
+  0, 0, "grid.main.we"
+  1, 0, "grid.main.ns"
+  0, 1, "grid.city.we"
+  1, 1, "grid.city.ns"
+  0, 2, "grid.worked.we"
+  1, 2, "grid.worked.ns"
+  0, 3, "grid.unavailable.we"
+  1, 3, "grid.unavailable.ns"
+  0, 4, "grid.selected.we"
+  1, 4, "grid.selected.ns"
+  0, 5, "grid.coastline.we"
+  1, 5, "grid.coastline.ns"
+
+  2, 0, "grid.borders.n"
+  2, 1, "grid.borders.s"
+  2, 2, "grid.borders.w"
+  2, 3, "grid.borders.e"
+}

Attachment: grid-6.tar.gz
Description: Unix tar archive


[Prev in Thread] Current Thread [Next in Thread]