Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2001:
[Freeciv-Dev] Re: PATCH: cleanup in fill_tile_sprite_array (PR#1016)
Home

[Freeciv-Dev] Re: PATCH: cleanup in fill_tile_sprite_array (PR#1016)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: PATCH: cleanup in fill_tile_sprite_array (PR#1016)
From: Jason Dorje Short <vze2zq63@xxxxxxxxxxx>
Date: Mon, 15 Oct 2001 11:33:41 -0400
Reply-to: jdorje@xxxxxxxxxxxx

Raimar Falke wrote:
> 
> On Mon, Oct 15, 2001 at 04:59:30AM -0700, jdorje@xxxxxxxxxxxxxxxxxxxxx wrote:
> > The attached patch cleans up fill_tile_sprite_array and
> > fill_tile_sprite_array_iso.  The new code still has some ugliness to it
> > (I'm not sure how to get rid of this...), but should be safe with the
> > check_map_pos changes and should also be topology-independent (which
> > some of the old code was not).
> 
> Very nice. I have waited for such a patch a long time.
> 
> >
> > jason
> > Index: client/tilespec.c
> > ===================================================================
> > RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
> > retrieving revision 1.54
> > diff -u -r1.54 tilespec.c
> > --- client/tilespec.c 2001/10/12 10:12:13     1.54
> > +++ client/tilespec.c 2001/10/15 10:54:29
> > @@ -1066,6 +1066,18 @@
> >  }
> >
> >  /**********************************************************************
> > +This is a hack wrapper to tile_is_known needed to make
> > +fill_tile_sprite_array[iso] prettier.
> > +***********************************************************************/
> > +static enum known_type is_tile_known(int x, int y)
> > +{
> > +  if (!normalize_map_pos(&x, &y))
> > +    return TILE_UNKNOWN;
> > +  else
> > +    return tile_is_known(x, y);
> > +}
> > +
> > +/**********************************************************************
> 
> > -  dither[0] = get_dither(ttype, tile_is_known(x, y-1) ? ttype_north : 
> > T_UNKNOWN);
> > -  dither[1] = get_dither(ttype, tile_is_known(x, y+1) ? ttype_south : 
> > T_UNKNOWN);
> > -  dither[2] = get_dither(ttype, tile_is_known(x+1, y) ? ttype_east : 
> > T_UNKNOWN);
> > -  dither[3] = get_dither(ttype, tile_is_known(x-1, y) ? ttype_west : 
> > T_UNKNOWN);
> > +  /* To make this work cleanly I wrote is_tile_known as a wrapper to 
> > tile_is_known.  Ugly! */
> > +  dither[0] = get_dither(ttype, is_tile_known(x, y-1) ? 
> > ttype_near[DIR8_NORTH] : T_UNKNOWN);
> > +  dither[1] = get_dither(ttype, is_tile_known(x, y+1) ? 
> > ttype_near[DIR8_SOUTH] : T_UNKNOWN);
> > +  dither[2] = get_dither(ttype, is_tile_known(x+1, y) ? 
> > ttype_near[DIR8_EAST] : T_UNKNOWN);
> > +  dither[3] = get_dither(ttype, is_tile_known(x-1, y) ? 
> > ttype_near[DIR8_WEST] : T_UNKNOWN);
> 
> What do you think about:
> 
> in map.h
> enum direction4 {
>   DIR4_NORTH = 0,
>   DIR4_WEST = 1,
>   DIR4_EAST = 2,
>   DIR4_SOUTH = 3,
> };

Such an enumeration already exists; in fact it's the reason the
direction8 enumeration is so named.  I'm leaving it in tilespec.h for
now.

> enum direction8 dir4_to_dir8(enum direction4 dir);
>
> in tilespec.c
> 
> for(i=0;i<4;i++)
> {
>   dither[i]=get_dither(ttype, T_UNKNOWN);
> }
> 
> cartesian_dir_adjacent_iterate(x,y,x1,y1,dir4)
> {
>   dither[dir4] = get_dither(ttype, tile_is_known(x1, y1) ? 
> ttype_near[dir4_to_dir8(dir4)] : T_UNKNOWN);
> }

I'd rather go the other way; i.e. from dir8->dir4.  This will allow the
use of existing macros, and if a new macro is created it should still
use the dir8 system.

This also leaves a problem for the other use of is_tile_known in
fill_tile_sprite_array.  This can be handled, but it introduces
additional clumsiness.

Patch attached.

jason
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.54
diff -u -r1.54 tilespec.c
--- client/tilespec.c   2001/10/12 10:12:13     1.54
+++ client/tilespec.c   2001/10/15 13:49:36
@@ -1065,6 +1065,26 @@
     return NULL;
 }
 
+int DIR4_BITS[4] = {BIT_NORTH, BIT_SOUTH, BIT_EAST, BIT_WEST};
+
+/**********************************************************************
+Converts from a dir8 (8-direction) direction to a dir4 (cardinal
+direction) value.
+***********************************************************************/
+enum direction4 dir8_to_dir4(enum direction8 dir8)
+{
+  switch (dir8) {
+    case DIR8_NORTH: return DIR4_NORTH;
+    case DIR8_SOUTH: return DIR4_SOUTH;
+    case DIR8_EAST:  return DIR4_EAST;
+    case DIR8_WEST:  return DIR4_WEST;
+    default:
+      freelog(LOG_FATAL, "dir8_to_dir4: bad direction %d.", dir8);
+      assert(0);
+      return DIR4_NORTH; /* best we can do */
+  }
+}
+
 /**********************************************************************
 Fill in the sprite array for the tile at position (abs_x0,abs_y0).
 Does not fill in the city or unit; that have to be done seperatly in
@@ -1087,10 +1107,6 @@
 {
   int ttype, ttype_near[8];
   int tspecial, tspecial_near[8];
-  int ttype_north, ttype_south, ttype_east, ttype_west;
-  int ttype_north_east, ttype_south_east, ttype_south_west, ttype_north_west;
-  int tspecial_north, tspecial_south, tspecial_east, tspecial_west;
-  int tspecial_north_east, tspecial_south_east, tspecial_south_west, 
tspecial_north_west;
 
   int tileno;
   struct tile *ptile;
@@ -1099,10 +1115,8 @@
   int dir, i;
 
   *solid_bg = 0;
-
-  if (!normalize_map_pos(&x, &y))
-    return -1;
 
+  assert(is_normal_map_pos(x, y)); /* should be check_map_pos */
   ptile = map_get_tile(x, y);
   if (!ptile->known)
     return -1;
@@ -1132,49 +1146,32 @@
       tspecial_near[dir] |= S_RIVER;
     }
   } adjc_dir_iterate_end;
-
-  ttype_north      = ttype_near[DIR8_NORTH];
-  ttype_north_east = ttype_near[DIR8_NORTHEAST];
-  ttype_east       = ttype_near[DIR8_EAST];
-  ttype_south_east = ttype_near[DIR8_SOUTHEAST];
-  ttype_south      = ttype_near[DIR8_SOUTH];
-  ttype_south_west = ttype_near[DIR8_SOUTHWEST];
-  ttype_west       = ttype_near[DIR8_WEST];
-  ttype_north_west = ttype_near[DIR8_NORTHWEST];
-  tspecial_north      = tspecial_near[DIR8_NORTH];
-  tspecial_north_east = tspecial_near[DIR8_NORTHEAST];
-  tspecial_east       = tspecial_near[DIR8_EAST];
-  tspecial_south_east = tspecial_near[DIR8_SOUTHEAST];
-  tspecial_south      = tspecial_near[DIR8_SOUTH];
-  tspecial_south_west = tspecial_near[DIR8_SOUTHWEST];
-  tspecial_west       = tspecial_near[DIR8_WEST];
-  tspecial_north_west = tspecial_near[DIR8_NORTHWEST];
   
   if (draw_terrain) {
     if (ttype != T_OCEAN) /* painted via coasts. */
       *sprs++ = get_tile_type(ttype)->sprite[0];
 
     if (ttype == T_HILLS) {
-      tileno = INDEX_NSEW((ttype_north==T_HILLS || ttype_north==T_HILLS),
-                         (ttype_south==T_HILLS || ttype_south==T_HILLS),
-                         (ttype_east==T_HILLS || ttype_east==T_HILLS),
-                         (ttype_west==T_HILLS || ttype_west==T_HILLS));
+      tileno = INDEX_NSEW(ttype_near[DIR8_NORTH] == T_HILLS,
+                         ttype_near[DIR8_SOUTH] == T_HILLS,
+                         ttype_near[DIR8_EAST] == T_HILLS,
+                         ttype_near[DIR8_WEST] == T_HILLS);
       *sprs++=sprites.tx.spec_hill[tileno];
     }
 
     if (ttype == T_FOREST) {
-      tileno = INDEX_NSEW((ttype_north==T_FOREST || ttype_north==T_FOREST),
-                         (ttype_south==T_FOREST || ttype_south==T_FOREST),
-                         (ttype_east==T_FOREST || ttype_east==T_FOREST),
-                         (ttype_west==T_FOREST || ttype_west==T_FOREST));
+      tileno = INDEX_NSEW(ttype_near[DIR8_NORTH] == T_FOREST,
+                         ttype_near[DIR8_SOUTH] == T_FOREST,
+                         ttype_near[DIR8_EAST] == T_FOREST,
+                         ttype_near[DIR8_WEST] == T_FOREST);
       *sprs++=sprites.tx.spec_forest[tileno];
     }
 
     if (ttype == T_MOUNTAINS) {
-      tileno = INDEX_NSEW((ttype_north==T_MOUNTAINS || 
ttype_north==T_MOUNTAINS),
-                         (ttype_south==T_MOUNTAINS || 
ttype_south==T_MOUNTAINS),
-                         (ttype_east==T_MOUNTAINS || ttype_east==T_MOUNTAINS),
-                         (ttype_west==T_MOUNTAINS || ttype_west==T_MOUNTAINS));
+      tileno = INDEX_NSEW(ttype_near[DIR8_NORTH] == T_MOUNTAINS,
+                         ttype_near[DIR8_SOUTH] == T_MOUNTAINS,
+                         ttype_near[DIR8_EAST] == T_MOUNTAINS,
+                         ttype_near[DIR8_WEST] == T_MOUNTAINS);
       *sprs++=sprites.tx.spec_mountain[tileno];
     }
     
@@ -1187,22 +1184,22 @@
     }
 
     if (tspecial&S_RIVER) {
-      tileno = INDEX_NSEW((tspecial_north&S_RIVER || ttype_north==T_OCEAN),
-                         (tspecial_south&S_RIVER || ttype_south==T_OCEAN),
-                         (tspecial_east&S_RIVER || ttype_east==T_OCEAN),
-                         (tspecial_west&S_RIVER || ttype_west==T_OCEAN));
+      tileno = INDEX_NSEW(tspecial_near[DIR8_NORTH] & S_RIVER || 
ttype_near[DIR8_NORTH] == T_OCEAN,
+                         tspecial_near[DIR8_SOUTH] & S_RIVER || 
ttype_near[DIR8_SOUTH] == T_OCEAN,
+                         tspecial_near[DIR8_EAST] & S_RIVER || 
ttype_near[DIR8_EAST] == T_OCEAN,
+                         tspecial_near[DIR8_WEST] & S_RIVER || 
ttype_near[DIR8_WEST] == T_OCEAN);
       *sprs++=sprites.tx.spec_river[tileno];
     }
 
     if (ttype == T_OCEAN) {
-      if(tspecial_north&S_RIVER || ttype_north==T_RIVER)
-       *sprs++ = sprites.tx.river_outlet[DIR_NORTH];
-      if(tspecial_west&S_RIVER || ttype_west==T_RIVER)
-       *sprs++ = sprites.tx.river_outlet[DIR_WEST];
-      if(tspecial_south&S_RIVER || ttype_south==T_RIVER)
-       *sprs++ = sprites.tx.river_outlet[DIR_SOUTH];
-      if(tspecial_east&S_RIVER || ttype_east==T_RIVER)
-       *sprs++ = sprites.tx.river_outlet[DIR_EAST];
+      if(tspecial_near[DIR8_NORTH] & S_RIVER || 
ttype_near[DIR8_NORTH]==T_RIVER)
+       *sprs++ = sprites.tx.river_outlet[DIR4_NORTH];
+      if(tspecial_near[DIR8_WEST] & S_RIVER || ttype_near[DIR8_WEST]==T_RIVER)
+       *sprs++ = sprites.tx.river_outlet[DIR4_WEST];
+      if(tspecial_near[DIR8_SOUTH] & S_RIVER || 
ttype_near[DIR8_SOUTH]==T_RIVER)
+       *sprs++ = sprites.tx.river_outlet[DIR4_SOUTH];
+      if(tspecial_near[DIR8_EAST] & S_RIVER || ttype_near[DIR8_EAST]==T_RIVER)
+       *sprs++ = sprites.tx.river_outlet[DIR4_EAST];
     }
   } else {
     *solid_bg = 1;
@@ -1267,24 +1264,24 @@
       int array_index;
       switch (i) {
       case 0: /* up */
-       ttype_adj[0] = ttype_west;
-       ttype_adj[1] = ttype_north_west;
-       ttype_adj[2] = ttype_north;
+       ttype_adj[0] = ttype_near[DIR8_WEST];
+       ttype_adj[1] = ttype_near[DIR8_NORTHWEST];
+       ttype_adj[2] = ttype_near[DIR8_NORTH];
        break;
       case 1: /* down */
-       ttype_adj[0] = ttype_east;
-       ttype_adj[1] = ttype_south_east;
-       ttype_adj[2] = ttype_south;
+       ttype_adj[0] = ttype_near[DIR8_EAST];
+       ttype_adj[1] = ttype_near[DIR8_SOUTHEAST];
+       ttype_adj[2] = ttype_near[DIR8_SOUTH];
        break;
       case 2: /* left */
-       ttype_adj[0] = ttype_south;
-       ttype_adj[1] = ttype_south_west;
-       ttype_adj[2] = ttype_west;
+       ttype_adj[0] = ttype_near[DIR8_SOUTH];
+       ttype_adj[1] = ttype_near[DIR8_SOUTHWEST];
+       ttype_adj[2] = ttype_near[DIR8_WEST];
        break;
       case 3: /* right*/
-       ttype_adj[0] = ttype_north;
-       ttype_adj[1] = ttype_north_east;
-       ttype_adj[2] = ttype_east;
+       ttype_adj[0] = ttype_near[DIR8_NORTH];
+       ttype_adj[1] = ttype_near[DIR8_NORTHEAST];
+       ttype_adj[2] = ttype_near[DIR8_EAST];
        break;
       default:
        abort();
@@ -1297,10 +1294,11 @@
     }
   }
 
-  dither[0] = get_dither(ttype, tile_is_known(x, y-1) ? ttype_north : 
T_UNKNOWN);
-  dither[1] = get_dither(ttype, tile_is_known(x, y+1) ? ttype_south : 
T_UNKNOWN);
-  dither[2] = get_dither(ttype, tile_is_known(x+1, y) ? ttype_east : 
T_UNKNOWN);
-  dither[3] = get_dither(ttype, tile_is_known(x-1, y) ? ttype_west : 
T_UNKNOWN);
+  for (dir = 0; dir < 4; dir++)
+    dither[dir] = get_dither(ttype, T_UNKNOWN);
+  adjc_dir_iterate(x, y, x1, y1, dir8) {
+    dither[dir8_to_dir4(dir8)] = get_dither(ttype, ttype_near[dir8]);
+  } adjc_dir_iterate_end;
 
   return sprs - save_sprs;
 }
@@ -1325,13 +1323,12 @@
 int fill_tile_sprite_array(struct Sprite **sprs, int abs_x0, int abs_y0,
                           int citymode, int *solid_bg, struct player **pplayer)
 {
-  int ttype, ttype_north, ttype_south, ttype_east, ttype_west;
-  int ttype_north_east, ttype_south_east, ttype_south_west, ttype_north_west;
-  int tspecial, tspecial_north, tspecial_south, tspecial_east, tspecial_west;
-  int tspecial_north_east, tspecial_south_east, tspecial_south_west, 
tspecial_north_west;
+  int ttype, ttype_near[8];
+  int tspecial, tspecial_near[8];
   int rail_card_tileno=0, rail_semi_tileno=0, road_card_tileno=0, 
road_semi_tileno=0;
   int rail_card_count=0, rail_semi_count=0, road_card_count=0, 
road_semi_count=0;
 
+  int dir;
   int tileno;
   struct tile *ptile;
   struct Sprite *mysprite;
@@ -1344,9 +1341,10 @@
   *solid_bg = 0;
   *pplayer = NULL;
 
+  assert(is_normal_map_pos(abs_x0, abs_y0)); /* should be check_map_pos */
   ptile=map_get_tile(abs_x0, abs_y0);
 
-  if(abs_y0>=map.ysize || ptile->known == TILE_UNKNOWN) {
+  if (ptile->known == TILE_UNKNOWN) {
     return 0;
   }
 
@@ -1373,53 +1371,37 @@
   }
 
   ttype=map_get_terrain(abs_x0, abs_y0);
-  ttype_east=map_get_terrain(abs_x0+1, abs_y0);
-  ttype_west=map_get_terrain(abs_x0-1, abs_y0);
-
-  /* make north and south pole seamless: */
-  if(abs_y0==0) {
-    ttype_north=ttype;
-    ttype_north_east=ttype_east;
-    ttype_north_west=ttype_west;
-  } else {
-    ttype_north=map_get_terrain(abs_x0, abs_y0-1);
-    ttype_north_east=map_get_terrain(abs_x0+1, abs_y0-1);
-    ttype_north_west=map_get_terrain(abs_x0-1, abs_y0-1);
-  }
-  if(abs_y0==map.ysize-1) {
-    ttype_south=ttype;
-    ttype_south_east=ttype_east;
-    ttype_south_west=ttype_west;
-  } else {
-    ttype_south=map_get_terrain(abs_x0, abs_y0+1);
-    ttype_south_east=map_get_terrain(abs_x0+1, abs_y0+1);
-    ttype_south_west=map_get_terrain(abs_x0-1, abs_y0+1);
+  for (dir=0; dir<8; dir++) {
+    /* nearest_real_pos is used to make the poles seamless */
+    int x, y, dx, dy;
+    DIRSTEP(dx, dy, dir);
+    x = abs_x0 + dx, y = abs_y0 + dy;
+    nearest_real_pos(&x, &y);
+    ttype_near[dir] = map_get_terrain(x, y);
   }
 
-  /* map_get_special() returns S_NO_SPECIAL past poles anyway */
+  /* make sure we set S_NO_SPECIAL past poles */
   tspecial=map_get_special(abs_x0, abs_y0);
-  tspecial_north=map_get_special(abs_x0, abs_y0-1);
-  tspecial_east=map_get_special(abs_x0+1, abs_y0);
-  tspecial_south=map_get_special(abs_x0, abs_y0+1);
-  tspecial_west=map_get_special(abs_x0-1, abs_y0);
-  tspecial_north_east=map_get_special(abs_x0+1, abs_y0-1);
-  tspecial_south_east=map_get_special(abs_x0+1, abs_y0+1);
-  tspecial_south_west=map_get_special(abs_x0-1, abs_y0+1);
-  tspecial_north_west=map_get_special(abs_x0-1, abs_y0-1);
+  for (dir = 0; dir < 8; dir++) {
+    tspecial_near[dir] = S_NO_SPECIAL;
+  }
+  adjc_dir_iterate(abs_x0, abs_y0, x, y, dir) {
+    tspecial_near[dir] = map_get_special(x, y);
+  } adjc_dir_iterate_end;
 
   if(map.is_earth &&
      abs_x0>=34 && abs_x0<=36 && abs_y0>=den_y && abs_y0<=den_y+1) {
     mysprite = sprites.tx.denmark[abs_y0-den_y][abs_x0-34];
   } else {
-    tileno = INDEX_NSEW((ttype_north==ttype),
-                       (ttype_south==ttype),
-                       (ttype_east==ttype),    
-                       (ttype_west==ttype));
+    tileno = INDEX_NSEW(ttype_near[DIR8_NORTH] == ttype,
+                       ttype_near[DIR8_SOUTH] == ttype,
+                       ttype_near[DIR8_EAST] == ttype, 
+                       ttype_near[DIR8_WEST] == ttype);
     if(ttype==T_RIVER) {
-      tileno |= INDEX_NSEW((ttype_north==T_OCEAN),
-                          (ttype_south==T_OCEAN),
-                          (ttype_east==T_OCEAN),
-                          (ttype_west==T_OCEAN));
+      tileno |= INDEX_NSEW(ttype_near[DIR8_NORTH] == T_OCEAN,
+                          ttype_near[DIR8_SOUTH] == T_OCEAN,
+                          ttype_near[DIR8_EAST] == T_OCEAN,
+                          ttype_near[DIR8_WEST] == T_OCEAN);
     }
     mysprite = get_tile_type(ttype)->sprite[tileno];
   }
@@ -1428,32 +1410,28 @@
   else *solid_bg = 1;
 
   if(ttype==T_OCEAN && draw_terrain) {
-    tileno = INDEX_NSEW((ttype_north==T_OCEAN && ttype_east==T_OCEAN && 
-                         ttype_north_east!=T_OCEAN),
-                        (ttype_south==T_OCEAN && ttype_west==T_OCEAN && 
-                         ttype_south_west!=T_OCEAN),
-                        (ttype_east==T_OCEAN && ttype_south==T_OCEAN && 
-                         ttype_south_east!=T_OCEAN),
-                        (ttype_north==T_OCEAN && ttype_west==T_OCEAN && 
-                         ttype_north_west!=T_OCEAN));
+    tileno = INDEX_NSEW(ttype_near[DIR8_NORTH]==T_OCEAN && 
ttype_near[DIR8_EAST]==T_OCEAN && ttype_near[DIR8_NORTHEAST]!=T_OCEAN,
+                        ttype_near[DIR8_SOUTH]==T_OCEAN && 
ttype_near[DIR8_WEST]==T_OCEAN && ttype_near[DIR8_SOUTHWEST]!=T_OCEAN,
+                        ttype_near[DIR8_EAST]==T_OCEAN && 
ttype_near[DIR8_SOUTH]==T_OCEAN && ttype_near[DIR8_SOUTHEAST]!=T_OCEAN,
+                        ttype_near[DIR8_NORTH]==T_OCEAN && 
ttype_near[DIR8_WEST]==T_OCEAN && ttype_near[DIR8_NORTHWEST]!=T_OCEAN);
     if(tileno!=0)
       *sprs++ = sprites.tx.coast_cape[tileno];
 
-    if(tspecial_north&S_RIVER || ttype_north==T_RIVER)
-      *sprs++ = sprites.tx.river_outlet[DIR_NORTH];
-    if(tspecial_west&S_RIVER || ttype_west==T_RIVER)
-      *sprs++ = sprites.tx.river_outlet[DIR_WEST];
-    if(tspecial_south&S_RIVER || ttype_south==T_RIVER)
-      *sprs++ = sprites.tx.river_outlet[DIR_SOUTH];
-    if(tspecial_east&S_RIVER || ttype_east==T_RIVER)
-      *sprs++ = sprites.tx.river_outlet[DIR_EAST];
+    if(tspecial_near[DIR8_NORTH] & S_RIVER || ttype_near[DIR8_NORTH] == 
T_RIVER)
+      *sprs++ = sprites.tx.river_outlet[DIR4_NORTH];
+    if(tspecial_near[DIR8_WEST] & S_RIVER || ttype_near[DIR8_WEST] == T_RIVER)
+      *sprs++ = sprites.tx.river_outlet[DIR4_WEST];
+    if(tspecial_near[DIR8_SOUTH] & S_RIVER || ttype_near[DIR8_SOUTH]==T_RIVER)
+      *sprs++ = sprites.tx.river_outlet[DIR4_SOUTH];
+    if(tspecial_near[DIR8_EAST] & S_RIVER || ttype_near[DIR8_EAST]==T_RIVER)
+      *sprs++ = sprites.tx.river_outlet[DIR4_EAST];
   }
 
   if (tspecial&S_RIVER && draw_terrain) {
-    tileno = INDEX_NSEW((tspecial_north&S_RIVER || ttype_north==T_OCEAN),
-                       (tspecial_south&S_RIVER || ttype_south==T_OCEAN),
-                       (tspecial_east&S_RIVER  || ttype_east==T_OCEAN),
-                       (tspecial_west&S_RIVER  || ttype_west== T_OCEAN));
+    tileno = INDEX_NSEW(tspecial_near[DIR8_NORTH]&S_RIVER || 
ttype_near[DIR8_NORTH]==T_OCEAN,
+                       tspecial_near[DIR8_SOUTH]&S_RIVER || 
ttype_near[DIR8_SOUTH]==T_OCEAN,
+                       tspecial_near[DIR8_EAST]&S_RIVER  || 
ttype_near[DIR8_EAST]==T_OCEAN,
+                       tspecial_near[DIR8_WEST]&S_RIVER  || 
ttype_near[DIR8_WEST]== T_OCEAN);
     *sprs++=sprites.tx.spec_river[tileno];
   }
 
@@ -1464,32 +1442,32 @@
 
   if(((tspecial & S_ROAD) || (tspecial & S_RAILROAD)) && draw_roads_rails) {
     int n, s, e, w;
-    
-    n = BOOL_VAL(tspecial_north&S_RAILROAD);
-    s = BOOL_VAL(tspecial_south&S_RAILROAD);
-    e = BOOL_VAL(tspecial_east&S_RAILROAD);
-    w = BOOL_VAL(tspecial_west&S_RAILROAD);
+
+    n = BOOL_VAL(tspecial_near[DIR8_NORTH]&S_RAILROAD);
+    s = BOOL_VAL(tspecial_near[DIR8_SOUTH]&S_RAILROAD);
+    e = BOOL_VAL(tspecial_near[DIR8_EAST]&S_RAILROAD);
+    w = BOOL_VAL(tspecial_near[DIR8_WEST]&S_RAILROAD);
     rail_card_count = n + s + e + w;
     rail_card_tileno = INDEX_NSEW(n,s,e,w);
     
-    n = BOOL_VAL(tspecial_north&S_ROAD);
-    s = BOOL_VAL(tspecial_south&S_ROAD);
-    e = BOOL_VAL(tspecial_east&S_ROAD);
-    w = BOOL_VAL(tspecial_west&S_ROAD);
+    n = BOOL_VAL(tspecial_near[DIR8_NORTH]&S_ROAD);
+    s = BOOL_VAL(tspecial_near[DIR8_SOUTH]&S_ROAD);
+    e = BOOL_VAL(tspecial_near[DIR8_EAST]&S_ROAD);
+    w = BOOL_VAL(tspecial_near[DIR8_WEST]&S_ROAD);
     road_card_count = n + s + e + w;
     road_card_tileno = INDEX_NSEW(n,s,e,w);
     
-    n = BOOL_VAL(tspecial_north_east&S_RAILROAD);
-    s = BOOL_VAL(tspecial_south_west&S_RAILROAD);
-    e = BOOL_VAL(tspecial_south_east&S_RAILROAD);
-    w = BOOL_VAL(tspecial_north_west&S_RAILROAD);
+    n = BOOL_VAL(tspecial_near[DIR8_NORTHEAST]&S_RAILROAD);
+    s = BOOL_VAL(tspecial_near[DIR8_SOUTHWEST]&S_RAILROAD);
+    e = BOOL_VAL(tspecial_near[DIR8_SOUTHEAST]&S_RAILROAD);
+    w = BOOL_VAL(tspecial_near[DIR8_NORTHWEST]&S_RAILROAD);
     rail_semi_count = n + s + e + w;
     rail_semi_tileno = INDEX_NSEW(n,s,e,w);
     
-    n = BOOL_VAL(tspecial_north_east&S_ROAD);
-    s = BOOL_VAL(tspecial_south_west&S_ROAD);
-    e = BOOL_VAL(tspecial_south_east&S_ROAD);
-    w = BOOL_VAL(tspecial_north_west&S_ROAD);
+    n = BOOL_VAL(tspecial_near[DIR8_NORTHEAST]&S_ROAD);
+    s = BOOL_VAL(tspecial_near[DIR8_SOUTHWEST]&S_ROAD);
+    e = BOOL_VAL(tspecial_near[DIR8_SOUTHEAST]&S_ROAD);
+    w = BOOL_VAL(tspecial_near[DIR8_NORTHWEST]&S_ROAD);
     road_semi_count = n + s + e + w;
     road_semi_tileno = INDEX_NSEW(n,s,e,w);
 
@@ -1573,10 +1551,17 @@
   if(ptile->known==TILE_KNOWN_FOGGED && draw_fog_of_war) *sprs++ = 
sprites.tx.fog;
 
   if(!citymode) {
-    tileno = INDEX_NSEW((tile_is_known(abs_x0, abs_y0-1)==TILE_UNKNOWN),
-                        (tile_is_known(abs_x0, abs_y0+1)==TILE_UNKNOWN),
-                        (tile_is_known(abs_x0+1, abs_y0)==TILE_UNKNOWN),
-                        (tile_is_known(abs_x0-1, abs_y0)==TILE_UNKNOWN));
+    /* This is an ugly hack.  We're looking to find tileno, the set of BIT 
masks
+       for the directions that are unknown (black) */
+    tileno = 0;
+    adjc_dir_iterate(abs_x0, abs_y0, x, y, dir8) {
+      if (!DIR_IS_CARDINAL(dir8))
+       continue;
+      if (tile_is_known(x, y) != TILE_UNKNOWN)
+        tileno |= DIR4_BITS[dir8_to_dir4(dir8)];
+    } adjc_dir_iterate_end;
+    tileno = ~tileno & (BIT_NORTH | BIT_SOUTH | BIT_EAST | BIT_WEST);
+
     if (tileno) 
       *sprs++ = sprites.tx.darkness[tileno];
   }
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.22
diff -u -r1.22 tilespec.h
--- client/tilespec.h   2001/09/16 12:43:22     1.22
+++ client/tilespec.h   2001/10/15 13:49:36
@@ -70,7 +70,10 @@
 #define NUM_TILES_HP_BAR 11
 #define NUM_TILES_DIGITS 10
 
-enum Directions { DIR_NORTH=0, DIR_SOUTH, DIR_EAST, DIR_WEST };
+/* This could be moved to common/map.h if there's more use for it. */
+enum direction4 { DIR4_NORTH=0, DIR4_SOUTH, DIR4_EAST, DIR4_WEST };
+enum direction4 dir8_to_dir4(enum direction8 dir8);
+extern int DIR4_BITS[]; /* index from enum direction4 to BIT value */
 
 
 struct named_sprites {
@@ -165,7 +168,7 @@
       *fog,
       *spec_river[NUM_DIRECTION_NSEW],
       *darkness[NUM_DIRECTION_NSEW],         /* first unused */
-      *river_outlet[4],                /* indexed by enum Directions */
+      *river_outlet[4],                /* indexed by enum direction4 */
       /* for isometric */
       *spec_forest[NUM_DIRECTION_NSEW],
       *spec_mountain[NUM_DIRECTION_NSEW],

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