Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2004:
[Freeciv-Dev] (PR#8434) generalized darkness
Home

[Freeciv-Dev] (PR#8434) generalized darkness

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8434) generalized darkness
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 31 Mar 2004 01:57:04 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8434 >

Currently:

* In non-iso view a 15-sprite drawing method is used for encroaching 
darkness.

* In iso-view a single sprite is split into 4 parts, and used for a 
4-sprite darkness.

This should be merged so that it depends on a darkness_style in the 
tileset rather than on is_isometric.  (However the method of splitting a 
single darkness sprite can't be done in non-iso view unless we add an 
extra mask to the tileset.)

This patch introduces 4 types of darkness:

0 => No darkness.
1 => Single-cell is split into 4 cells. (iso-view only, current iso)
2 => 4-cell
3 => 15-cell (current non-iso)

See the changes to README.graphics for a further explanation.

This also fixes the darkness problems that iso-view has.  Darkness is 
drawn in between the first and second layer of terrain.

jason

? cma_weirdness
? data/bak
? data/civ3
? data/womoks
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.155
diff -u -r1.155 tilespec.c
--- client/tilespec.c   30 Mar 2004 19:07:31 -0000      1.155
+++ client/tilespec.c   31 Mar 2004 09:55:09 -0000
@@ -85,6 +85,24 @@
 static int roadstyle;
 static int flag_offset_x, flag_offset_y;
 
+/* Darkness style.  Don't reorder this enum since tilesets depend on it. */
+static enum {
+  /* No darkness sprites are drawn. */
+  DARKNESS0 = 0,
+
+  /* 1 sprite that is split into 4 parts and treated as a darkness4.  Only
+   * works in iso-view. */
+  DARKNESS1 = 1,
+
+  /* 4 sprites, one per direction.  More than one sprite per tile may be
+   * drawn. */
+  DARKNESS4 = 2,
+
+  /* 15=2^4-1 sprites.  A single sprite is drawn, chosen based on whether
+   * there's darkness in _each_ of the cardinal directions. */
+  DARKNESS15 = 3
+} darkness_style;
+
 struct specfile;
 
 #define SPECLIST_TAG specfile
@@ -681,6 +699,13 @@
 
   roadstyle = secfile_lookup_int_default(file, is_isometric ? 0 : 1,
                                         "tilespec.roadstyle");
+  darkness_style = secfile_lookup_int(file, "tilespec.darkness_style");
+  if (darkness_style < DARKNESS0
+      || darkness_style > DARKNESS15
+      || (darkness_style == DARKNESS1 && !is_isometric)) {
+    freelog(LOG_FATAL, _("Invalid darkness style set in tileset."));
+    exit(EXIT_FAILURE);
+  }
   flag_offset_x = secfile_lookup_int_default(file, 0,
                                             "tilespec.flag_offset_x");
   flag_offset_y = secfile_lookup_int_default(file, 0,
@@ -1075,32 +1100,45 @@
     my_snprintf(buffer, sizeof(buffer), "tx.s_farmland_%s", nsew_str(i));
     SET_SPRITE_ALT(tx.farmland[i], buffer, "tx.farmland");
   }
-  
-  if (!is_isometric) {
-    for(i=1; i<NUM_DIRECTION_NSEW; i++) {
-      my_snprintf(buffer, sizeof(buffer), "tx.darkness_%s", nsew_str(i));
-      SET_SPRITE(tx.darkness[i], buffer);
-    }
 
+  if (!is_isometric) {
     for(i=1; i<NUM_DIRECTION_NSEW; i++) {
       my_snprintf(buffer, sizeof(buffer), "tx.coast_cape_%s", nsew_str(i));
       SET_SPRITE(tx.coast_cape[i], buffer);
     }
-  } else {
-    /* Isometric: take a single tx.darkness tile and split it into 4. */
-    struct Sprite *darkness = load_sprite("tx.darkness");
-    const int W = NORMAL_TILE_WIDTH, H = NORMAL_TILE_HEIGHT;
-    int offsets[4][2] = {{W / 2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}};
+  }
 
-    if (!darkness) {
-      die("Sprite tag darkness missing.");
+  switch (darkness_style) {
+  case DARKNESS0:
+    /* Nothing. */
+    break;
+  case DARKNESS1:
+    {
+      /* Isometric: take a single tx.darkness tile and split it into 4. */
+      struct Sprite *darkness = load_sprite("tx.darkness");
+      const int W = NORMAL_TILE_WIDTH, H = NORMAL_TILE_HEIGHT;
+      int offsets[4][2] = {{W / 2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}};
+
+      for (i = 0; i < 4; i++) {
+       sprites.tx.darkness[i] = crop_sprite(darkness, offsets[i][0],
+                                            offsets[i][1], W / 2, H / 2,
+                                            NULL, 0, 0);
+      }
     }
-
+    break;
+  case DARKNESS4:
     for (i = 0; i < 4; i++) {
-      sprites.tx.darkness[i] = crop_sprite(darkness, offsets[i][0],
-                                          offsets[i][1], W / 2, H / 2,
-                                          NULL, 0, 0);
+      my_snprintf(buffer, sizeof(buffer), "tx.darkness_%s",
+                 dir_get_name(DIR4_TO_DIR8[i]));
+      SET_SPRITE(tx.darkness[i], buffer);
     }
+    break;
+  case DARKNESS15:
+    for(i = 1; i < NUM_DIRECTION_NSEW; i++) {
+      my_snprintf(buffer, sizeof(buffer), "tx.darkness_%s", nsew_str(i));
+      SET_SPRITE(tx.darkness[i], buffer);
+    }
+    break;
   }
 
   for(i=0; i<4; i++) {
@@ -1984,7 +2022,7 @@
   struct tile *ptile = map_get_tile(map_x, map_y);
   enum tile_terrain_type ttype = ptile->terrain;
   struct terrain_drawing_data *draw = sprites.terrain[ttype];
-  int l;
+  int l, dir, adjc_x, adjc_y;
 
   if (!draw_terrain) {
     return 0;
@@ -2049,6 +2087,53 @@
     if (l == 0 && draw->is_blended) {
       sprs += fill_blending_sprite_array(sprs, map_x, map_y, ttype_near);
     }
+
+    /* Add darkness on top of the first layer.  Note that darkness is always
+     * drawn, even in citymode, etc. */
+    if (l == 0) {
+#define UNKNOWN(dir)                                        \
+  (MAPSTEP(adjc_x, adjc_y, map_x, map_y, DIR4_TO_DIR8[dir]) \
+   && tile_get_known(adjc_x, adjc_y) == TILE_UNKNOWN)
+
+      switch (darkness_style) {
+      case DARKNESS0:
+       break;
+      case DARKNESS1:
+       for (dir = 0; dir < 4; dir++) {
+         const int W = NORMAL_TILE_WIDTH, H = NORMAL_TILE_HEIGHT;
+         int offsets[4][2] = {{W / 2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}};
+
+         if (UNKNOWN(dir)) {
+           ADD_SPRITE(sprites.tx.darkness[dir],
+                      offsets[dir][0], offsets[dir][1]);
+         }
+       }
+       break;
+      case DARKNESS4:
+       for (dir = 0; dir < 4; dir++) {
+         if (UNKNOWN(dir)) {
+           ADD_SPRITE_SIMPLE(sprites.tx.darkness[dir]);
+         }
+       }
+       break;
+      case DARKNESS15:
+       /* We're looking to find the INDEX_NSEW for the directions that
+        * are unknown.  We want to mark unknown tiles so that an unreal
+        * tile will be given the same marking as our current tile - that
+        * way we won't get the "unknown" dither along the edge of the
+        * map. */
+       {
+         int tileno = INDEX_NSEW(UNKNOWN(DIR4_NORTH), UNKNOWN(DIR4_SOUTH),
+                                 UNKNOWN(DIR4_EAST), UNKNOWN(DIR4_WEST));
+
+         if (tileno != 0) {
+           ADD_SPRITE_SIMPLE(sprites.tx.darkness[tileno]);
+         }
+       }
+       break;
+      }
+#undef UNKNOWN
+    }
   }
 
   /* Extra "capes" added on in non-iso view. */
@@ -2138,19 +2223,6 @@
   sprs += fill_road_rail_sprite_array(sprs,
                                      tspecial, tspecial_near, pcity);
 
-  /* Add darkness sprites. */
-  for (dir = 0; dir < 4; dir++) {
-    int x1, y1;
-    const int W = NORMAL_TILE_WIDTH, H = NORMAL_TILE_HEIGHT;
-    int offsets[4][2] = {{W / 2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}};
-
-    if (MAPSTEP(x1, y1, x, y, DIR4_TO_DIR8[dir])
-       && tile_get_known(x1, y1) == TILE_UNKNOWN) {
-      ADD_SPRITE(sprites.tx.darkness[dir],
-                offsets[dir][0], offsets[dir][1]);
-    }
-  }
-
   if (draw_specials) {
     if (contains_special(tspecial, S_SPECIAL_1)) {
       ADD_SPRITE_SIMPLE(sprites.terrain[ttype]->special[0]);
@@ -2309,33 +2381,6 @@
   }
   if(tile_get_known(abs_x0,abs_y0) == TILE_KNOWN_FOGGED && draw_fog_of_war) {
     ADD_SPRITE_SIMPLE(sprites.tx.fog);
-  }
-
-  if (!citymode) {
-    /* 
-     * We're looking to find the INDEX_NSEW for the directions that
-     * are unknown.  We want to mark unknown tiles so that an unreal
-     * tile will be given the same marking as our current tile - that
-     * way we won't get the "unknown" dither along the edge of the
-     * map.
-     */
-    bool known[4];
-
-    for (dir = 0; dir < 4; dir++) {
-      int x1, y1;
-
-      if (MAPSTEP(x1, y1, abs_x0, abs_y0, DIR4_TO_DIR8[dir]))
-        known[dir] = (tile_get_known(x1, y1) != TILE_UNKNOWN);
-      else
-        known[dir] = TRUE;
-    }
-
-    tileno =
-       INDEX_NSEW(!known[DIR4_NORTH], !known[DIR4_SOUTH],
-                  !known[DIR4_EAST], !known[DIR4_WEST]);
-
-    if (tileno != 0) 
-      ADD_SPRITE_SIMPLE(sprites.tx.darkness[tileno]);
   }
 
   if (pcity && draw_cities) {
Index: data/isotrident.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isotrident.tilespec,v
retrieving revision 1.15
diff -u -r1.15 isotrident.tilespec
--- data/isotrident.tilespec    30 Mar 2004 18:12:50 -0000      1.15
+++ data/isotrident.tilespec    31 Mar 2004 09:55:09 -0000
@@ -23,6 +23,9 @@
 
 ; Use roadstyle 0 (old iso style)
 roadstyle = 0
+
+; Use darkness style 1 (single-sprite)
+darkness_style = 1
  
 ; offset the flags by this amount when drawing units
 flag_offset_x = 17
Index: data/trident.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident.tilespec,v
retrieving revision 1.20
diff -u -r1.20 trident.tilespec
--- data/trident.tilespec       30 Mar 2004 18:12:50 -0000      1.20
+++ data/trident.tilespec       31 Mar 2004 09:55:09 -0000
@@ -23,6 +23,9 @@
 
 ; Use roadstyle 1 (old non-iso style)
 roadstyle = 1
+
+; Use darkness style 3 (15 sprites)
+darkness_style = 3
  
 ; offset the flags by this amount when drawing units
 flag_offset_x = 0
Index: data/trident_shields.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident_shields.tilespec,v
retrieving revision 1.10
diff -u -r1.10 trident_shields.tilespec
--- data/trident_shields.tilespec       30 Mar 2004 18:12:50 -0000      1.10
+++ data/trident_shields.tilespec       31 Mar 2004 09:55:09 -0000
@@ -28,6 +28,9 @@
 ; Use roadstyle 1 (old non-iso style)
 roadstyle = 1
 
+; Use darkness style 3 (15 sprites)
+darkness_style = 3
+ 
 ; Font to use to draw city names:
 city_names_font = "9x15bold"
 
Index: doc/README.graphics
===================================================================
RCS file: /home/freeciv/CVS/freeciv/doc/README.graphics,v
retrieving revision 1.10
diff -u -r1.10 README.graphics
--- doc/README.graphics 30 Mar 2004 18:12:50 -0000      1.10
+++ doc/README.graphics 31 Mar 2004 09:55:09 -0000
@@ -94,6 +94,24 @@
   normal_tile_height    : the height of terrain tiles
   small_tile_width      : the width of icon sprites
   small_tile_height     : the height of icon sprites
+  roadstyle             : Specifies how roads and rail are drawn.
+                          0 : A single sprite is drawn for every connection
+                              the tile has; only 8 sprites are needed.
+                          1 : A single sprite is drawn for all cardinal
+                              connections and a second sprite is drawn
+                              for all diagonal connections; 32 sprites are
+                              needed.
+  darkness_style        : Specifies how "encroaching darkness" is drawn.
+                          0 : No darkness.
+                          1 : A single sprite can be split into 4 parts, each
+                              containing the darkness for that particular
+                              cardinal direction.  (Iso-view only.)
+                          2 : Four different sprites exist, each holding the
+                              darkness for a particular direction.  Any or all
+                              of the sprites may be drawn.
+                          3 : The sprite is chosen based on the vector sum of
+                              the darkness in all 4 cardinal directions.  15
+                              different sprites are needed.
 
   Booleans (0 or 1)
   -----------------

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#8434) generalized darkness, Jason Short <=