[Freeciv-Dev] Re: PATCH: check_map_pos
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Raimar Falke wrote:
>
> On Mon, Oct 15, 2001 at 04:29:10AM -0400, Jason Dorje Short wrote:
> > The attached patch introduces a check_map_pos() function.
> >
> > It's done as an inline function within map.h, but this is unimportant at
> > this point. As said before, the advantage of a function is that it can
> > be used within map_inx if desired; there's not really any advantage to a
> > macro.
> >
> > It does not touch client code. With all the different GUI's and the
> > tendancy to pass around coordinates picked by the user, the client is
> > not yet ready for this function.
> >
> > I have run several full (endyear=2000) autogames, and have not had any
> > problems yet.
> >
> > Note that check_map_pos is not called on coordinates that are simply
> > passed off to another function; for instance most of the code in map.c
> > just calls MAP_TILE or map_inx with the coordinates so it's not
> > necessary to call check_map_pos directly.
>
> So since the code base is ready for the change we have to discuss
> about the form. IMHO we should use macros to be able to completely
> disable this checks. IMHO it isn't a good idea to mix these two things
> (introduction of check_map_pos and inline).
Here is an updated check_map_pos patch.
Differences from the earlier patch: one use of check_map_pos removed
(normalization was needed), fill_tile_sprite_array in tilespec.[ch]
changed, square_iterate (from the other topology patch I submitted) is
used in control.c, and punit->x=-1 is removed in control.c. I have not
yet done any changes to the check_map_pos function.
jason ? rc
? old
? topology
? mydiff
? check_map_pos
? client/mapview_common.c
? client/mapview_common.h
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.60
diff -u -r1.60 control.c
--- client/control.c 2001/09/15 15:31:19 1.60
+++ client/control.c 2001/10/15 18:49:30
@@ -1033,7 +1033,7 @@
was_teleported=!is_tiles_adjacent(punit->x, punit->y, pinfo->x, pinfo->y);
x=punit->x;
y=punit->y;
- punit->x=-1; /* focus hack - if we're moving the unit in focus, it wont
+ /* punit->x=-1; */ /* focus hack - if we're moving the unit in focus, it
wont
* be redrawn on top of the city */
unit_list_unlink(&map_get_tile(x, y)->units, punit);
@@ -1062,17 +1062,14 @@
punit->hp=pinfo->hp;
unit_list_insert(&map_get_tile(punit->x, punit->y)->units, punit);
- for(y=punit->y-2; y<punit->y+3; ++y) {
- if(y<0 || y>=map.ysize)
- continue;
- for(x=punit->x-2; x<punit->x+3; ++x) {
- unit_list_iterate(map_get_tile(x, y)->units, pu)
+ square_iterate(punit->x, punit->y, 2, x, y) {
+ unit_list_iterate(map_get_tile(x, y)->units, pu) {
if(unit_flag(pu, F_PARTIAL_INVIS)) {
- refresh_tile_mapcanvas(map_adjust_x(pu->x), y, 1);
+ /* should we really refresh more than once? */
+ refresh_tile_mapcanvas(x, y, 1);
}
- unit_list_iterate_end
- }
- }
+ } unit_list_iterate_end;
+ } square_iterate_end;
if(!pinfo->carried && tile_is_known(punit->x,punit->y) == TILE_KNOWN)
refresh_tile_mapcanvas(punit->x, punit->y, 1);
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 18:49:31
@@ -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 18:49:32
@@ -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],
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.97
diff -u -r1.97 map.c
--- common/map.c 2001/10/15 13:42:50 1.97
+++ common/map.c 2001/10/15 18:49:33
@@ -1068,8 +1068,7 @@
int maxcost = 72; /* should be big enough without being TOO big */
struct tile *tile0, *tile1;
- assert(is_real_tile(x, y));
- normalize_map_pos(&x, &y);
+ check_map_pos(&x, &y);
tile0 = map_get_tile(x, y);
debug_log_move_costs("Resetting move costs for", x, y, tile0);
@@ -1156,10 +1155,6 @@
***************************************************************/
struct tile *map_get_tile(int x, int y)
{
- int is_real = normalize_map_pos(&x, &y);
-
- assert(is_real);
-
return MAP_TILE(x, y);
}
@@ -1168,10 +1163,7 @@
***************************************************************/
signed short map_get_continent(int x, int y)
{
- if (!normalize_map_pos(&x, &y))
- return -1;
- else
- return MAP_TILE(x, y)->continent;
+ return MAP_TILE(x, y)->continent;
}
/***************************************************************
@@ -1179,8 +1171,6 @@
***************************************************************/
void map_set_continent(int x, int y, int val)
{
- assert(is_real_tile(x, y));
- normalize_map_pos(&x, &y);
MAP_TILE(x, y)->continent = val;
}
@@ -1190,10 +1180,7 @@
***************************************************************/
enum tile_terrain_type map_get_terrain(int x, int y)
{
- if (!normalize_map_pos(&x, &y))
- return T_UNKNOWN;
- else
- return MAP_TILE(x, y)->terrain;
+ return MAP_TILE(x, y)->terrain;
}
/***************************************************************
@@ -1201,10 +1188,7 @@
***************************************************************/
enum tile_special_type map_get_special(int x, int y)
{
- if (!normalize_map_pos(&x, &y))
- return S_NO_SPECIAL;
- else
- return MAP_TILE(x, y)->special;
+ return MAP_TILE(x, y)->special;
}
/***************************************************************
@@ -1212,8 +1196,6 @@
***************************************************************/
void map_set_terrain(int x, int y, enum tile_terrain_type ter)
{
- assert(is_real_tile(x, y));
- normalize_map_pos(&x, &y);
MAP_TILE(x, y)->terrain = ter;
}
@@ -1222,9 +1204,6 @@
***************************************************************/
void map_set_special(int x, int y, enum tile_special_type spe)
{
- assert(is_real_tile(x, y));
- normalize_map_pos(&x, &y);
-
MAP_TILE(x, y)->special |= spe;
if (spe & (S_ROAD | S_RAILROAD))
@@ -1236,8 +1215,6 @@
***************************************************************/
void map_clear_special(int x, int y, enum tile_special_type spe)
{
- assert(is_real_tile(x, y));
- normalize_map_pos(&x, &y);
MAP_TILE(x, y)->special &= ~spe;
if (spe & (S_ROAD | S_RAILROAD))
@@ -1249,8 +1226,6 @@
***************************************************************/
struct city *map_get_city(int x, int y)
{
- assert(is_real_tile(x, y));
- normalize_map_pos(&x, &y);
return MAP_TILE(x, y)->city;
}
@@ -1260,8 +1235,6 @@
***************************************************************/
void map_set_city(int x, int y, struct city *pcity)
{
- assert(is_real_tile(x, y));
- normalize_map_pos(&x, &y);
MAP_TILE(x, y)->city = pcity;
}
@@ -1271,10 +1244,7 @@
***************************************************************/
enum known_type tile_is_known(int x, int y)
{
- if (!normalize_map_pos(&x, &y))
- return TILE_UNKNOWN;
- else
- return (enum known_type) (MAP_TILE(x, y)->known);
+ return (enum known_type) (MAP_TILE(x, y)->known);
}
/***************************************************************
@@ -1283,9 +1253,8 @@
***************************************************************/
int same_pos(int x1, int y1, int x2, int y2)
{
- assert(is_real_tile(x1, y1) && is_real_tile(x2, y2));
- normalize_map_pos(&x1, &y1);
- normalize_map_pos(&x2, &y2);
+ check_map_pos(&x1, &y1);
+ check_map_pos(&x2, &y2);
return (x1 == x2 && y1 == y2);
}
@@ -1424,9 +1393,8 @@
**************************************************************************/
int is_move_cardinal(int start_x, int start_y, int end_x, int end_y)
{
- assert(is_real_tile(start_x, start_y) && is_real_tile(end_x, end_y));
- normalize_map_pos(&start_x, &start_y);
- normalize_map_pos(&end_x, &end_y);
+ check_map_pos(&start_x, &start_y);
+ check_map_pos(&end_x, &end_y);
assert(is_tiles_adjacent(start_x, start_y, end_x, end_y));
/* FIXME: this check will not work with an orthogonal map */
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.99
diff -u -r1.99 map.h
--- common/map.h 2001/10/15 13:42:51 1.99
+++ common/map.h 2001/10/15 18:49:33
@@ -13,6 +13,9 @@
#ifndef FC__MAP_H
#define FC__MAP_H
+#include <assert.h>
+
+#include "log.h"
#include "player.h"
#include "terrain.h"
#include "unit.h"
@@ -208,7 +211,7 @@
(((Y)<0) ? 0 : (((Y)>=map.ysize) ? map.ysize-1 : (Y)))
#define map_inx(x,y) \
- ((x)+(y)*map.xsize)
+ (check_map_pos(&x, &y), (x)+(y)*map.xsize)
#define DIRSTEP(dest_x, dest_y, dir) \
( (dest_x) = DIR_DX[(dir)], \
@@ -242,6 +245,20 @@
int normalize_map_pos(int *x, int *y);
void nearest_real_pos(int *x, int *y);
+static inline void check_map_pos(int *x, int *y)
+{
+ /* When we're pretty sure things work it'll be worthwhile to remove this
+ code. Until then, something like this is safest. */
+ if (!is_normal_map_pos(*x, *y)) {
+ freelog(LOG_ERROR, "Bad coordinates (%d, %d) passed to check_map_pos.",
*x, *y);
+ assert(0);
+ if (!normalize_map_pos(x, y)) {
+ nearest_real_pos(x, y);
+ freelog(LOG_FATAL, "Unreal coordinates 'fixed' to (%d, %d).", *x, *y);
+ }
+ }
+}
+
void rand_neighbour(int x0, int y0, int *x, int *y);
int is_water_adjacent_to_tile(int x, int y);
@@ -409,7 +426,7 @@
int x_itr, y_itr, dir_itr, MACRO_border; \
int MACRO_center_x = (center_x); \
int MACRO_center_y = (center_y); \
- assert(is_normal_map_pos(MACRO_center_x, MACRO_center_y)); \
+ check_map_pos(&MACRO_center_x, &MACRO_center_y); \
MACRO_border = IS_BORDER_MAP_POS(MACRO_center_x, MACRO_center_y); \
for (dir_itr = 0; dir_itr < 8; dir_itr++) { \
DIRSTEP(x_itr, y_itr, dir_itr); \
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.87
diff -u -r1.87 maphand.c
--- server/maphand.c 2001/10/11 12:37:06 1.87
+++ server/maphand.c 2001/10/15 18:49:34
@@ -771,11 +771,8 @@
***************************************************************/
int map_get_known_and_seen(int x, int y, struct player *pplayer)
{
- int is_real = normalize_map_pos(&x, &y);
int playerid=pplayer->player_no;
int offset = map_inx(x, y);
-
- assert(is_real);
return ((map.tiles + offset)->known) & (1u << playerid) &&
(pplayer->private_map + offset)->seen;
Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.13
diff -u -r1.13 sanitycheck.c
--- server/sanitycheck.c 2001/10/14 21:02:17 1.13
+++ server/sanitycheck.c 2001/10/15 18:49:34
@@ -128,7 +128,7 @@
assert(unit_owner(punit) == pplayer);
} unit_list_iterate_end;
- assert(is_normal_map_pos(pcity->x, pcity->y));
+ check_map_pos(&pcity->x, &pcity->y);
assert(map_get_terrain(pcity->x, pcity->y) != T_OCEAN);
city_map_iterate(x, y) {
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.112
diff -u -r1.112 settlers.c
--- server/settlers.c 2001/10/14 21:02:17 1.112
+++ server/settlers.c 2001/10/15 18:49:35
@@ -405,8 +405,7 @@
**************************************************************************/
static int is_already_assigned(struct unit *myunit, struct player *pplayer,
int x, int y)
{
- assert(is_real_tile(x, y));
- normalize_map_pos(&x, &y);
+ check_map_pos(&x, &y);
if (same_pos(myunit->x, myunit->y, x, y) ||
same_pos(myunit->goto_dest_x, myunit->goto_dest_y, x, y)) {
/* I'm still not sure this is exactly right -- Syela */
@@ -647,8 +646,8 @@
int ii[12] = { -1, 0, 1, -1, 1, -1, 0, 1, 0, -2, 2, 0 };
int jj[12] = { -1, -1, -1, 0, 0, 1, 1, 1, -2, 0, 0, 2 };
struct tile *ptile;
- if (!normalize_map_pos(&x, &y))
- return 0;
+
+ check_map_pos(&x, &y);
for (k = 0; k < 12; k++) {
int x1 = x + ii[k], y1 = y + jj[k];
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.143
diff -u -r1.143 unittools.c
--- server/unittools.c 2001/10/15 13:42:52 1.143
+++ server/unittools.c 2001/10/15 18:49:37
@@ -1628,8 +1628,7 @@
idex_register_unit(punit);
punit->owner=pplayer->player_no;
- assert(is_real_tile(x, y));
- normalize_map_pos(&x, &y);
+ check_map_pos(&x, &y);
punit->x = x;
punit->y = y;
- [Freeciv-Dev] Re: PATCH: check_map_pos, (continued)
- [Freeciv-Dev] Re: PATCH: check_map_pos, Gaute B Strokkenes, 2001/10/21
- [Freeciv-Dev] Re: PATCH: check_map_pos, Jason Dorje Short, 2001/10/21
- [Freeciv-Dev] Re: PATCH: check_map_pos, Gaute B Strokkenes, 2001/10/23
- [Freeciv-Dev] Re: PATCH: check_map_pos, Jason Dorje Short, 2001/10/23
- [Freeciv-Dev] Re: PATCH: check_map_pos, Gaute B Strokkenes, 2001/10/23
- [Freeciv-Dev] Re: PATCH: check_map_pos, Jason Dorje Short, 2001/10/23
- [Freeciv-Dev] Re: PATCH: check_map_pos, Gaute B Strokkenes, 2001/10/23
- [Freeciv-Dev] Re: PATCH: check_map_pos, Raimar Falke, 2001/10/24
[Freeciv-Dev] Re: PATCH: check_map_pos,
Jason Dorje Short <=
|
|