Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2005:
[Freeciv-Dev] (PR#13582) A fog "layer" for the overview
Home

[Freeciv-Dev] (PR#13582) A fog "layer" for the overview

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13582) A fog "layer" for the overview
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 31 Jul 2005 20:46:32 -0700
Reply-to: bugs@xxxxxxxxxxx

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

The attached patch and tarball make a fog "layer" for the overview.

This isn't implemented as a layer at all but as a special case.  All
other layers must still be opaque, but fog is drawn on top.  This is
done by drawing the tx.fog sprite which should contain generic fog
coloration.

The data files are also updated to fix tx.fog.  Previously tx.fog was
only provided for non-iso tilesets.  Trident had it but it was dithered
not alpha-blended.  Isotrident and isophex had no such sprite; the tag
existed (since it's required) but pointed at garbage.  Now all three
tilesets have this sprite, copied over from the full-fog sprite in
fog.png (44% alpha).

See the screenshot at http://www.freeciv.org/~jdorje/overview-fog.png .
 This shows relief with fog, which was not previously possible.

-jason

Index: client/colors_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/colors_common.c,v
retrieving revision 1.8
diff -p -u -r1.8 colors_common.c
--- client/colors_common.c      31 Jul 2005 18:42:34 -0000      1.8
+++ client/colors_common.c      1 Aug 2005 03:45:38 -0000
@@ -70,9 +70,7 @@ char *color_names[] = {
   "overview_alliedunit",
   "overview_enemyunit",
   "overview_ocean",
-  "overview_foggedocean",
   "overview_ground",
-  "overview_foggedground",
   "overview_viewrect",
 
   /* Reqtree */
Index: client/colors_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/colors_common.h,v
retrieving revision 1.7
diff -p -u -r1.7 colors_common.h
--- client/colors_common.h      31 Jul 2005 16:23:13 -0000      1.7
+++ client/colors_common.h      1 Aug 2005 03:45:38 -0000
@@ -45,9 +45,7 @@ enum color_std {
   COLOR_OVERVIEW_ALLIED_UNIT,
   COLOR_OVERVIEW_ENEMY_UNIT, /* red */
   COLOR_OVERVIEW_OCEAN, /* ocean/blue */
-  COLOR_OVERVIEW_FOGGED_OCEAN, /* race4/dark blue */
   COLOR_OVERVIEW_LAND, /* ground/green */
-  COLOR_OVERVIEW_FOGGED_LAND, /* background/gray */
   COLOR_OVERVIEW_VIEWRECT, /* white */
 
   /* Reqtree colors */
Index: client/options.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.c,v
retrieving revision 1.137
diff -p -u -r1.137 options.c
--- client/options.c    1 Aug 2005 02:35:19 -0000       1.137
+++ client/options.c    1 Aug 2005 03:45:38 -0000
@@ -221,8 +221,8 @@ static client_option common_options[] = 
 
   GEN_BOOL_OPTION(overview.layers[OLAYER_BACKGROUND],
                  N_("Background layer"),
-                 N_("The background layer of the overview shows ocean, "
-                    "land, and fog."), COC_OVERVIEW),
+                 N_("The background layer of the overview shows just "
+                    "ocean and land."), COC_OVERVIEW),
   GEN_BOOL_OPTION(overview.layers[OLAYER_RELIEF],
                  N_("Terrain relief map layer"),
                  N_("The relief layer shows all terrains on the map."),
@@ -238,6 +238,10 @@ static client_option common_options[] = 
   GEN_BOOL_OPTION(overview.layers[OLAYER_CITIES],
                  N_("Cities layer"),
                  N_("If enabled then cities will be drawn on the overview."),
+                 COC_OVERVIEW),
+  GEN_BOOL_OPTION(overview.fog,
+                 N_("Overview fog of war"),
+                 N_("If enabled, fog of war is shown on the overview."),
                  COC_OVERVIEW)
 };
 #undef GEN_INT_OPTION
Index: client/overview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/overview_common.c,v
retrieving revision 1.15
diff -p -u -r1.15 overview_common.c
--- client/overview_common.c    31 Jul 2005 16:23:13 -0000      1.15
+++ client/overview_common.c    1 Aug 2005 03:45:38 -0000
@@ -27,6 +27,8 @@
 
 int OVERVIEW_TILE_SIZE = 2;
 struct overview overview = {
+  /* These are the default values.  All others are zeroed automatically. */
+  .fog = TRUE,
   .layers = {[OLAYER_BACKGROUND] = TRUE,
             [OLAYER_UNITS] = TRUE,
             [OLAYER_CITIES] = TRUE}
@@ -146,19 +148,9 @@ static struct color *overview_tile_color
   }
   if (overview.layers[OLAYER_BACKGROUND] && ptile->terrain != T_UNKNOWN) {
     if (is_ocean(ptile->terrain)) {
-      if (client_tile_get_known(ptile) == TILE_KNOWN_FOGGED
-         && draw_fog_of_war) {
-       return get_color(tileset, COLOR_OVERVIEW_FOGGED_OCEAN);
-      } else {
-       return get_color(tileset, COLOR_OVERVIEW_OCEAN);
-      }
+      return get_color(tileset, COLOR_OVERVIEW_OCEAN);
     } else {
-      if (client_tile_get_known(ptile) == TILE_KNOWN_FOGGED
-         && draw_fog_of_war) {
-       return get_color(tileset, COLOR_OVERVIEW_FOGGED_LAND);
-      } else {
-       return get_color(tileset, COLOR_OVERVIEW_LAND);
-      }
+      return get_color(tileset, COLOR_OVERVIEW_LAND);
     }
   }
 
@@ -348,6 +340,26 @@ void refresh_overview_canvas(void)
   redraw_overview();
 }
 
+/****************************************************************************
+  Draws the color for this tile onto the given rectangle of the canvas.
+
+  This is just a simple helper function for overview_update_tile, since
+  sometimes a tile may cover more than one rectangle.
+****************************************************************************/
+static void put_overview_tile_area(struct canvas *pcanvas,
+                                  struct tile *ptile,
+                                  int x, int y, int w, int h)
+{
+  canvas_put_rectangle(pcanvas,
+                      overview_tile_color(ptile),
+                      x, y, w, h);
+  if (client_tile_get_known(ptile) == TILE_KNOWN_FOGGED
+      && overview.fog) {
+    canvas_put_sprite(pcanvas, x, y, get_basic_fog_sprite(tileset),
+                     0, 0, w, h);
+  }
+}
+
 /**************************************************************************
   Redraw the given map position in the overview canvas.
 **************************************************************************/
@@ -364,10 +376,9 @@ void overview_update_tile(struct tile *p
        if (overview_x > overview.width - OVERVIEW_TILE_WIDTH) {
          /* This tile is shown half on the left and half on the right
           * side of the overview.  So we have to draw it in two parts. */
-         canvas_put_rectangle(overview.map,
-                              overview_tile_color(ptile),
-                              overview_x - overview.width, overview_y,
-                              OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT); 
+         put_overview_tile_area(overview.map, ptile,
+                                overview_x - overview.width, overview_y,
+                                OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT); 
        }     
       } else {
        /* Clip half tile left and right.
@@ -376,9 +387,9 @@ void overview_update_tile(struct tile *p
       }
     } 
 
-    canvas_put_rectangle(overview.map, overview_tile_color(ptile),
-                        overview_x, overview_y,
-                        OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
+    put_overview_tile_area(overview.map, ptile,
+                          overview_x, overview_y,
+                          OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
 
     dirty_overview();
   } do_in_natural_pos_end;
Index: client/overview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/overview_common.h,v
retrieving revision 1.6
diff -p -u -r1.6 overview_common.h
--- client/overview_common.h    31 Jul 2005 16:23:13 -0000      1.6
+++ client/overview_common.h    1 Aug 2005 03:45:38 -0000
@@ -39,6 +39,7 @@ struct overview {
   /* A backing store for the window itself, wrapped. */
   struct canvas *window;
 
+  bool fog;
   bool layers[OLAYER_COUNT];
 };
 
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.319
diff -p -u -r1.319 tilespec.c
--- client/tilespec.c   31 Jul 2005 16:23:13 -0000      1.319
+++ client/tilespec.c   1 Aug 2005 03:45:39 -0000
@@ -4555,6 +4555,15 @@ struct sprite *get_unit_upkeep_sprite(co
 }
 
 /****************************************************************************
+  Return a rectangular sprite containing a fog "color".  This can be used
+  for drawing fog onto arbitrary areas (like the overview).
+****************************************************************************/
+struct sprite *get_basic_fog_sprite(const struct tileset *t)
+{
+  return t->sprites.tx.fog;
+}
+
+/****************************************************************************
   Return the tileset's color system.
 ****************************************************************************/
 struct color_system *get_color_system(const struct tileset *t)
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.157
diff -p -u -r1.157 tilespec.h
--- client/tilespec.h   22 Jul 2005 16:18:05 -0000      1.157
+++ client/tilespec.h   1 Aug 2005 03:45:39 -0000
@@ -219,6 +219,7 @@ struct sprite *get_unit_unhappy_sprite(c
 struct sprite *get_unit_upkeep_sprite(const struct tileset *t,
                                      Output_type_id otype,
                                      const struct unit *punit);
+struct sprite *get_basic_fog_sprite(const struct tileset *t);
 
 struct color_system;
 struct color_system *get_color_system(const struct tileset *t);
Index: data/isophex/terrain1.png
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isophex/terrain1.png,v
retrieving revision 1.2
diff -p -u -r1.2 terrain1.png
Binary files /tmp/cvsAsgH5X and terrain1.png differ
Index: data/isophex/terrain1.spec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isophex/terrain1.spec,v
retrieving revision 1.4
diff -p -u -r1.4 terrain1.spec
--- data/isophex/terrain1.spec  2 Mar 2005 18:23:00 -0000       1.4
+++ data/isophex/terrain1.spec  1 Aug 2005 03:45:41 -0000
@@ -133,11 +133,10 @@ pixel_border = 1
 tiles = { "row", "column","tag"
   0, 0, "t.dither_tile"
   0, 0, "tx.darkness"
-  0, 1, "tx.fog"
   0, 2, "mask.tile"
   0, 3, "t.coast_color"
-
   0, 4, "user.attention"
+  0, 5, "tx.fog"
 }
 
 
Index: data/isotrident/terrain1.png
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isotrident/terrain1.png,v
retrieving revision 1.4
diff -p -u -r1.4 terrain1.png
Binary files /tmp/cvsQpnHRi and terrain1.png differ
Index: data/isotrident/terrain1.spec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isotrident/terrain1.spec,v
retrieving revision 1.8
diff -p -u -r1.8 terrain1.spec
--- data/isotrident/terrain1.spec       2 Mar 2005 18:23:00 -0000       1.8
+++ data/isotrident/terrain1.spec       1 Aug 2005 03:45:42 -0000
@@ -132,12 +132,11 @@ pixel_border = 1
 tiles = { "row", "column","tag"
   0, 0, "t.dither_tile"
   0, 0, "tx.darkness"
-  0, 1, "tx.fog"
   0, 2, "mask.tile"
   0, 2, "t.unknown1"
   0, 3, "t.ocean1"
-
   0, 4, "user.attention"
+  0, 5, "tx.fog"
 }
 
 
Index: data/misc/colors.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/misc/colors.tilespec,v
retrieving revision 1.3
diff -p -u -r1.3 colors.tilespec
--- data/misc/colors.tilespec   31 Jul 2005 16:23:14 -0000      1.3
+++ data/misc/colors.tilespec   1 Aug 2005 03:45:42 -0000
@@ -80,15 +80,9 @@ overview_ocean = {"r", "g", "b"
 ; Generic ocean, not the same as the Ocean terrain (see "terrains" above)
     0,     0, 200
 }
-overview_foggedocean = {"r", "g", "b"
-    0,     0, 128
-}
 overview_ground = {"r", "g", "b"
     0,   200,   0
 }
-overview_foggedground = {"r", "g", "b"
-    86,   86,  86
-}
 overview_viewrect = {"r", "g", "b"
     255, 255, 255
 }
Index: data/trident/tiles.png
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident/tiles.png,v
retrieving revision 1.9
diff -p -u -r1.9 tiles.png
Binary files /tmp/cvs0QNh7N and tiles.png differ

Attachment: overview-fog.tar.gz
Description: GNU Zip compressed data


[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13582) A fog "layer" for the overview, Jason Short <=