? typescript
? wo_me_p
? diff.diff
? ffff
? tidying.diff
? xyzzy
? gmon.out
? tidying2.diff
? map.diff
? nohup.out
? with_me_p
? zappa
? gmon.out-CVS-20010809
? gmon.out-CVS-20010809.txt.bz2
? gmon.out-CVS-no-map-adjx-20010809
? adjc_dir_iterate3.diff
? gmon.out-CVS-no-map-adjx-20010809.txt.bz2
? gmon.out.txt.bz2
? coordfix.diff
? shithappens.diff
? client/gui-mui/zappa
? common/fitte.diff
? server/zappa
? server/1
Index: ai/advdomestic.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdomestic.c,v
retrieving revision 1.70
diff -u -r1.70 advdomestic.c
--- ai/advdomestic.c 2001/08/14 14:31:18 1.70
+++ ai/advdomestic.c 2001/08/15 22:59:51
@@ -91,35 +91,51 @@
{
int i = 0;
city_map_iterate(x, y) {
- if (map_get_tile(pcity->x+x-2, pcity->y+y-2)->terrain == T_OCEAN) {
- i++; /* this is a kluge; wasn't getting enough harbors because
-often everyone was stuck farming grassland. */
- if (is_worker_here(pcity, x, y)) i++;
+ int x1 = pcity->x + x - 2;
+ int y1 = pcity->y + y - 2;
+ if (normalize_map_pos(&x1, &y1)) {
+ if (map_get_tile(x1, y1)->terrain == T_OCEAN) {
+ i++;
+ /* this is a kluge; wasn't getting enough harbors because
+ often everyone was stuck farming grassland. */
+ if (is_worker_here(pcity, x, y))
+ i++;
+ }
}
} city_map_iterate_end;
- return(i/2);
+ return i/2;
}
static int road_trade(struct city *pcity)
{
- int i = 0;
+ int i = 0;
city_map_iterate(x, y) {
- if (is_worker_here(pcity, x, y)) {
- if (map_get_special(pcity->x+x-2, pcity->y+y-2) & S_ROAD) i++;
+ int x1 = pcity->x + x - 2;
+ int y1 = pcity->y + y - 2;
+ if (normalize_map_pos(&x1, &y1)) {
+ if (is_worker_here(pcity, x, y)
+ && map_get_special(x1, y1) & S_ROAD)
+ i++;
}
} city_map_iterate_end;
- return(i);
+
+ return i;
}
static int farmland_food(struct city *pcity)
{
int i = 0;
city_map_iterate(x, y) {
- if (is_worker_here(pcity, x, y)) {
- if (map_get_special(pcity->x+x-2, pcity->y+y-2) & S_FARMLAND) i++;
+ int x1 = pcity->x + x - 2;
+ int y1 = pcity->y + y - 2;
+ if (normalize_map_pos(&x1, &y1)) {
+ if (is_worker_here(pcity, x, y)
+ && map_get_special(x1, y1) & S_FARMLAND)
+ i++;
}
} city_map_iterate_end;
- return(i);
+
+ return i;
}
static int pollution_cost(struct player *pplayer, struct city *pcity,
Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.145
diff -u -r1.145 aiunit.c
--- ai/aiunit.c 2001/08/13 12:25:24 1.145
+++ ai/aiunit.c 2001/08/15 22:59:52
@@ -593,7 +593,7 @@
static int ai_military_findvictim(struct player *pplayer, struct unit *punit,
int *dest_x, int *dest_y)
{
- int x, y, x1, y1, k;
+ int x, y;
int best = 0, a, b, c, d, e, f;
struct unit *pdef;
struct unit *patt;
@@ -612,12 +612,7 @@
unit_list_iterate_end;
} /* ferryboats do not attack. no. -- Syela */
- for (k = 0; k < 8; k++) {
- x1 = x + DIR_DX[k];
- y1 = y + DIR_DY[k];
- if (!normalize_map_pos(&x1, &y1))
- continue;
-
+ adjc_iterate(x, y, x1, y1) {
pdef = get_defender(punit, x1, y1);
if (pdef) {
patt = get_attacker(punit, x1, y1);
@@ -683,7 +678,7 @@
best = 1; *dest_y = y1; *dest_x = x1;
} /* next to nothing is better than nothing */
}
- }
+ } adjc_iterate_end;
return(best);
}
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.58
diff -u -r1.58 control.c
--- client/control.c 2001/06/29 19:39:00 1.58
+++ client/control.c 2001/08/15 22:59:52
@@ -602,7 +602,7 @@
would mean that we tried to move off the map... */
/* Catches attempts to move off map */
- if (!is_real_tile(dest_x, dest_y))
+ if (!IS_REAL_TILE(dest_x, dest_y))
return;
req_unit = *punit;
Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.16
diff -u -r1.16 goto.c
--- client/goto.c 2001/08/14 11:04:19 1.16
+++ client/goto.c 2001/08/15 22:59:53
@@ -632,13 +632,13 @@
int x1, y1;
/* Replace with check for is_normal_tile later */
- assert(is_real_tile(x, y));
+ assert(IS_REAL_TILE(x, y));
normalize_map_pos(&x, &y);
x1 = x + DIR_DX[dir];
y1 = y + DIR_DY[dir];
/* It makes no sense to draw a goto line to a non-existant tile. */
- assert(is_real_tile(x1, y1));
+ assert(IS_REAL_TILE(x1, y1));
normalize_map_pos(&x1, &y1);
if (dir >= 4) {
@@ -792,7 +792,7 @@
if (goto_map.vector[x][y] & (1<
x + x1 - CITY_MAP_SIZE/2;
int map_y = pcity->y + y1 - CITY_MAP_SIZE/2;
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.81
diff -u -r1.81 city.h
--- common/city.h 2001/05/23 19:09:55 1.81
+++ common/city.h 2001/08/15 22:59:56
@@ -64,33 +64,33 @@
Some places in the code hardcodes this number (yet). */
#define CITY_MAP_SIZE 5
-
/* Iterate a city map */
-#define city_map_iterate(x, y) \
-{ \
- int x, y; \
- for (y=0;y= map.ysize) \
- continue; \
+ y_itr = city_y + MCMI_y - CITY_MAP_SIZE/2; \
+ if (y_itr < 0 || y_itr >= map.ysize) \
+ continue; \
x_itr = map_adjust_x(city_x + MCMI_x - CITY_MAP_SIZE/2);
-#define map_city_radius_iterate_end \
- } \
- } \
- } \
+#define map_city_radius_iterate_end \
+ } \
+ } \
+ } \
}
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.79
diff -u -r1.79 map.c
--- common/map.c 2001/08/14 14:31:19 1.79
+++ common/map.c 2001/08/15 22:59:56
@@ -73,6 +73,9 @@
N_("Fallout")
};
+#define NUM_SPECIAL_NAMES \
+ (sizeof(tile_special_type_names)/sizeof(tile_special_type_names[0]))
+
extern int is_server;
/***************************************************************
@@ -157,44 +160,32 @@
}
/***************************************************************
- Returns 1 if we are at a stage of the game where the map
- has not yet been generated/loaded.
- (To be precise, returns 1 if map_allocate() has not yet been
- called.)
-***************************************************************/
-int map_is_empty(void)
-{
- return map.tiles==0;
-}
-
-
-/***************************************************************
put some sensible values into the map structure
Also initialize special void_tile.
***************************************************************/
void map_init(void)
{
- map.xsize=MAP_DEFAULT_WIDTH;
- map.ysize=MAP_DEFAULT_HEIGHT;
- map.seed=MAP_DEFAULT_SEED;
- map.riches=MAP_DEFAULT_RICHES;
- map.is_earth=0;
- map.huts=MAP_DEFAULT_HUTS;
- map.landpercent=MAP_DEFAULT_LANDMASS;
- map.grasssize=MAP_DEFAULT_GRASS;
- map.swampsize=MAP_DEFAULT_SWAMPS;
- map.deserts=MAP_DEFAULT_DESERTS;
- map.mountains=MAP_DEFAULT_MOUNTAINS;
- map.riverlength=MAP_DEFAULT_RIVERS;
- map.forestsize=MAP_DEFAULT_FORESTS;
- map.generator=MAP_DEFAULT_GENERATOR;
- map.tiles=0;
- map.num_continents = 0;
- map.num_start_positions=0;
- map.fixed_start_positions=0;
- map.have_specials = 0;
- map.have_rivers_overlay = 0;
- map.have_huts = 0;
+ map.xsize = MAP_DEFAULT_WIDTH;
+ map.ysize = MAP_DEFAULT_HEIGHT;
+ map.seed = MAP_DEFAULT_SEED;
+ map.riches = MAP_DEFAULT_RICHES;
+ map.is_earth = 0;
+ map.huts = MAP_DEFAULT_HUTS;
+ map.landpercent = MAP_DEFAULT_LANDMASS;
+ map.grasssize = MAP_DEFAULT_GRASS;
+ map.swampsize = MAP_DEFAULT_SWAMPS;
+ map.deserts = MAP_DEFAULT_DESERTS;
+ map.mountains = MAP_DEFAULT_MOUNTAINS;
+ map.riverlength = MAP_DEFAULT_RIVERS;
+ map.forestsize = MAP_DEFAULT_FORESTS;
+ map.generator = MAP_DEFAULT_GENERATOR;
+ map.tiles = NULL;
+ map.num_continents = 0;
+ map.num_start_positions = 0;
+ map.fixed_start_positions = 0;
+ map.have_specials = 0;
+ map.have_rivers_overlay = 0;
+ map.have_huts = 0;
tile_init(&void_tile);
}
@@ -221,22 +212,13 @@
/***************************************************************
...
***************************************************************/
-struct tile_type *get_tile_type(enum tile_terrain_type type)
-{
- return &tile_types[type];
-}
-
-/***************************************************************
-...
-***************************************************************/
enum tile_terrain_type get_terrain_by_name(char * name)
{
enum tile_terrain_type tt;
- for (tt = T_FIRST; tt < T_COUNT; tt++) {
- if (0 == strcmp (tile_types[tt].terrain_name, name)) {
+ for (tt = T_FIRST; tt < T_COUNT; tt++)
+ if (!strcmp (tile_types[tt].terrain_name, name))
break;
- }
- }
+
return tt;
}
@@ -245,11 +227,8 @@
***************************************************************/
char *get_terrain_name(enum tile_terrain_type type)
{
- if (type < T_COUNT) {
- return get_tile_type(type)->terrain_name;
- } else {
- return NULL;
- }
+ assert(type < T_COUNT);
+ return tile_types[type].terrain_name;
}
/***************************************************************
@@ -257,15 +236,13 @@
***************************************************************/
enum tile_special_type get_special_by_name(char * name)
{
- int inx;
+ int i;
enum tile_special_type st = 1;
- for (inx = 0;
- inx < sizeof(tile_special_type_names)/sizeof(tile_special_type_names[0]);
- inx++) {
- if (0 == strcmp(name, tile_special_type_names[inx])) {
+ for (i = 0; i < NUM_SPECIAL_NAMES; i++) {
+ if (!strcmp(name, tile_special_type_names[i]))
return st;
- }
+
st <<= 1;
}
@@ -277,14 +254,12 @@
***************************************************************/
const char *get_special_name(enum tile_special_type type)
{
- int inx;
+ int i;
- for (inx = 0;
- inx < sizeof(tile_special_type_names)/sizeof(tile_special_type_names[0]);
- inx++) {
- if (type & 0x1) {
- return tile_special_type_names[inx];
- }
+ for (i = 0; i < NUM_SPECIAL_NAMES; i++) {
+ if (type & 0x1)
+ return tile_special_type_names[i];
+
type >>= 1;
}
@@ -435,14 +410,6 @@
}
/***************************************************************
-...
-***************************************************************/
-int map_same_continent(int x1, int y1, int x2, int y2)
-{
- return (map_get_continent(x1,y1) == map_get_continent(x2,y2));
-}
-
-/***************************************************************
Returns 1 if (x,y) is _not_ a good position to start from;
Bad places:
- Non-suitable terrain;
@@ -594,22 +561,12 @@
***************************************************************/
int get_tile_trade_base(struct tile * ptile)
{
- if(ptile->special&S_SPECIAL_1)
- return (tile_types[ptile->terrain].trade_special_1);
- else if(ptile->special&S_SPECIAL_2)
- return (tile_types[ptile->terrain].trade_special_2);
+ if (ptile->special & S_SPECIAL_1)
+ return tile_types[ptile->terrain].trade_special_1;
+ else if (ptile->special & S_SPECIAL_2)
+ return tile_types[ptile->terrain].trade_special_2;
else
- return (tile_types[ptile->terrain].trade);
-}
-
-/***************************************************************
-...
-***************************************************************/
-int get_tile_infrastructure_set(struct tile * ptile)
-{
- return
- ptile->special &
- (S_ROAD | S_RAILROAD | S_IRRIGATION | S_FARMLAND | S_MINE | S_FORTRESS | S_AIRBASE);
+ return tile_types[ptile->terrain].trade;
}
/***************************************************************
@@ -1007,7 +964,7 @@
static int tile_move_cost_ai(struct tile *tile0, struct tile *tile1,
int x, int y, int x1, int y1, int maxcost)
{
- assert(y >= 0 && y <= map.ysize);
+ assert(IS_REAL_TILE(x, y));
assert(!is_server || (tile0->terrain != T_UNKNOWN && tile1->terrain != T_UNKNOWN));
if (tile0->terrain == T_OCEAN) {
@@ -1051,9 +1008,8 @@
debug_log_move_costs("Resetting move costs for", x, y, tile0);
for (dir = 0; dir < 8; dir++) {
- x1 = x + DIR_DX[dir];
- y1 = y + DIR_DY[dir];
- if (normalize_map_pos(&x1, &y1)) {
+ MAPSTEP(x1, y1, x, y, dir);
+ if (IS_REAL_TILE(x1, y1)) {
tile1 = map_get_tile(x1, y1);
tile0->move_cost[dir] = tile_move_cost_ai(tile0, tile1, x, y,
x1, y1, maxcost);
@@ -1087,9 +1043,8 @@
int x1, y1;
tile0 = map_get_tile(x, y);
for (dir = 0; dir < 8; dir++) {
- x1 = map_adjust_x(x + DIR_DX[dir]);
- y1 = y + DIR_DY[dir];
- if (normalize_map_pos(&x1, &y1)) {
+ MAPSTEP(x1, y1, x, y, dir);
+ if (IS_REAL_TILE(x1, y1)) {
tile1 = map_get_tile(x1, y1);
tile0->move_cost[dir] = tile_move_cost_ai(tile0, tile1, x, y,
x1, y1, maxcost);
@@ -1123,33 +1078,31 @@
return 0;
}
-
-
/***************************************************************
...
***************************************************************/
void tile_init(struct tile *ptile)
{
- ptile->terrain=T_UNKNOWN;
- ptile->special=S_NO_SPECIAL;
- ptile->known=0;
- ptile->sent=0;
- ptile->city=NULL;
+ ptile->terrain = T_UNKNOWN;
+ ptile->special = S_NO_SPECIAL;
+ ptile->known = 0;
+ ptile->sent = 0;
+ ptile->city = NULL;
unit_list_init(&ptile->units);
- ptile->worked = NULL; /* pointer to city working tile */
+ ptile->worked = NULL; /* pointer to city working tile */
ptile->assigned = 0; /* bitvector */
}
-
/***************************************************************
...
***************************************************************/
struct tile *map_get_tile(int x, int y)
{
- if(y<0 || y>=map.ysize)
+ x = map_adjust_x(x);
+ if(!IS_REAL_TILE(x, y))
return &void_tile; /* accurate fix by Syela */
else
- return map.tiles+map_adjust_x(x)+y*map.xsize;
+ return MAP(x, y);
}
/***************************************************************
@@ -1157,10 +1110,11 @@
***************************************************************/
signed short map_get_continent(int x, int y)
{
- if (y<0 || y>=map.ysize)
+ x = map_adjust_x(x);
+ if (!IS_REAL_TILE(x, y))
return -1;
else
- return (map.tiles + map_adjust_x(x) + y * map.xsize)->continent;
+ return MAP(x, y)->continent;
}
/***************************************************************
@@ -1168,20 +1122,20 @@
***************************************************************/
void map_set_continent(int x, int y, int val)
{
- assert(is_real_tile(x, y));
- (map.tiles + map_adjust_x(x) + y * map.xsize)->continent=val;
+ x = map_adjust_x(x);
+ MAP(x, y)->continent = val;
}
-
/***************************************************************
...
***************************************************************/
enum tile_terrain_type map_get_terrain(int x, int y)
{
- if(y<0 || y>=map.ysize)
+ x = map_adjust_x(x);
+ if (!IS_REAL_TILE(x, y))
return T_UNKNOWN;
else
- return (map.tiles+map_adjust_x(x)+y*map.xsize)->terrain;
+ return MAP(x, y)->terrain;
}
/***************************************************************
@@ -1189,10 +1143,11 @@
***************************************************************/
enum tile_special_type map_get_special(int x, int y)
{
- if(!is_real_tile(x, y))
+ x = map_adjust_x(x);
+ if(!IS_REAL_TILE(x, y))
return S_NO_SPECIAL;
else
- return (map.tiles + map_adjust_x(x) + y*map.xsize)->special;
+ return MAP(x, y)->special;
}
/***************************************************************
@@ -1200,8 +1155,8 @@
***************************************************************/
void map_set_terrain(int x, int y, enum tile_terrain_type ter)
{
- (map.tiles+map_adjust_x(x)+
- map_adjust_y(y)*map.xsize)->terrain=ter;
+ x = map_adjust_x(x);
+ MAP(x, y)->terrain = ter;
}
/***************************************************************
@@ -1209,10 +1164,8 @@
***************************************************************/
void map_set_special(int x, int y, enum tile_special_type spe)
{
- x = map_adjust_x(x);
- y = map_adjust_y(y);
-
- (map.tiles +x + y*map.xsize)->special |= spe;
+ x = map_adjust_x(x);
+ MAP(x, y)->special |= spe;
if (spe & (S_ROAD | S_RAILROAD))
reset_move_costs(x, y);
@@ -1223,9 +1176,8 @@
***************************************************************/
void map_clear_special(int x, int y, enum tile_special_type spe)
{
- x = map_adjust_x(x);
- y = map_adjust_y(y);
- (map.tiles + x + y*map.xsize)->special &= ~spe;
+ normalize_map_pos(&x, &y);
+ MAP(x, y)->special &= ~spe;
if (spe & (S_ROAD | S_RAILROAD))
reset_move_costs(x, y);
@@ -1236,8 +1188,8 @@
***************************************************************/
struct city *map_get_city(int x, int y)
{
- x = map_adjust_x(x); y = map_adjust_y(y);
- return (map.tiles + x + y*map.xsize)->city;
+ x = map_adjust_x(x);
+ return MAP(x, y)->city;
}
@@ -1246,7 +1198,8 @@
***************************************************************/
void map_set_city(int x, int y, struct city *pcity)
{
- (map.tiles+map_adjust_x(x)+map_adjust_y(y)*map.xsize)->city=pcity;
+ x = map_adjust_x(x);
+ MAP(x, y)->city = pcity;
}
@@ -1255,8 +1208,9 @@
***************************************************************/
enum known_type tile_is_known(int x, int y)
{
- return (enum known_type) (((map.tiles+map_adjust_x(x)+
- map_adjust_y(y)*map.xsize)->known));
+ x = map_adjust_x(x);
+ assert(!is_server);
+ return (enum known_type) MAP(x, y)->known;
}
/***************************************************************
@@ -1265,8 +1219,8 @@
***************************************************************/
int same_pos(int x1, int y1, int x2, int y2)
{
- return (map_adjust_x(x1) == map_adjust_x(x2)
- && map_adjust_y(y1) == map_adjust_y(y2));
+ return (map_adjust_y(y1) == map_adjust_y(y2)
+ && map_adjust_x(x1 - x2) == 0);
}
/**************************************************************************
@@ -1278,8 +1232,7 @@
if (!normalize_map_pos(x, y)) {
freelog(LOG_ERROR, "%d, %d is not a real tile!", *x, *y);
- *x = map_adjust_x(*x);
- *y = map_adjust_y(*y);
+ nearest_real_tile(x, y);
return 0;
}
@@ -1289,20 +1242,12 @@
return 1;
}
-/***************************************************************
-If we just adjust we might light a tile twice; That would be a
-Mayor problem with fog of war
-***************************************************************/
-int is_real_tile(int x, int y)
-{
- return 0 <= y && y < map.ysize;
-}
-
/**************************************************************************
-Normalizes the map position. Returns TRUE if it is valid, false otherwise.
+Normalizes the map position. Returns TRUE if it is real, FALSE otherwise.
**************************************************************************/
-int normalize_map_pos(int *x, int *y) {
- if (*y < 0 || *y >= map.ysize)
+int normalize_map_pos(int *x, int *y)
+{
+ if (!IS_REAL_TILE(*x, *y))
return FALSE;
while (*x < 0)
@@ -1314,12 +1259,30 @@
}
/**************************************************************************
+Twiddle *x and *y to point the the nearest real tile.
+**************************************************************************/
+void nearest_real_tile(int *x, int *y)
+{
+ if (*y < 0)
+ *y = 0;
+ else if (*y >= map.ysize)
+ *y = map.ysize - 1;
+
+ while (*x < 0)
+ *x += map.xsize;
+ while (*x >= map.xsize)
+ *x -= map.xsize;
+}
+
+/**************************************************************************
Random neighbouring square.
**************************************************************************/
void rand_neighbour(int x0, int y0, int *x, int *y)
{
int choice;
+ assert(IS_NORM_TILE(x0, y0));
+
if (y0 == 0) {
choice = 3 + myrand(5);
} else if(y0 == map.ysize-1){
@@ -1328,9 +1291,7 @@
choice = myrand(8);
}
- *x = x0 + DIR_DX[choice];
- *y = y0 + DIR_DY[choice];
+ MAPSTEP(*x, *y, x0, y0, choice);
- assert(is_real_tile(*x, *y));
- normalize_map_pos(x, y);
+ assert(IS_REAL_TILE(*x, *y));
}
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.85
diff -u -r1.85 map.h
--- common/map.h 2001/08/14 14:31:19 1.85
+++ common/map.h 2001/08/15 22:59:56
@@ -168,7 +168,6 @@
struct map_position start_positions[MAX_NUM_NATIONS];
};
-int map_is_empty(void);
void map_init(void);
void map_allocate(void);
@@ -200,8 +199,10 @@
#define map_adjust_y(Y) \
(((Y)<0) ? 0 : (((Y)>=map.ysize) ? map.ysize-1 : (Y)))
+#if 1
#define map_inx(x,y) \
((x)+(y)*map.xsize)
+#endif
struct city *map_get_city(int x, int y);
void map_set_city(int x, int y, struct city *pcity);
@@ -213,14 +214,13 @@
void tile_init(struct tile *ptile);
enum known_type tile_is_known(int x, int y);
int check_coords(int *x, int *y);
-int is_real_tile(int x, int y);
int normalize_map_pos(int *x, int *y);
+void nearest_real_tile(int *x, int *y);
void rand_neighbour(int x0, int y0, int *x, int *y);
int is_water_adjacent_to_tile(int x, int y);
int is_tiles_adjacent(int x0, int y0, int x1, int y1);
int map_move_cost(struct unit *punit, int x, int y);
-struct tile_type *get_tile_type(enum tile_terrain_type type);
enum tile_terrain_type get_terrain_by_name(char * name);
char *get_terrain_name(enum tile_terrain_type type);
enum tile_special_type get_special_by_name(char * name);
@@ -240,7 +240,6 @@
int get_tile_food_base(struct tile * ptile);
int get_tile_shield_base(struct tile * ptile);
int get_tile_trade_base(struct tile * ptile);
-int get_tile_infrastructure_set(struct tile * ptile);
char *map_get_infrastructure_text(int spe);
int map_get_infrastructure_prerequisite(int spe);
int get_preferred_pillage(int pset);
@@ -268,6 +267,56 @@
extern struct terrain_misc terrain_control;
extern struct tile_type tile_types[T_LAST];
+/***************************************************************
+ Returns 1 if we are at a stage of the game where the map
+ has not yet been generated/loaded.
+ (To be precise, returns 1 if map_allocate() has not yet been
+ called.)
+***************************************************************/
+#define map_is_empty() (map.tiles == NULL)
+
+/***************************************************************
+...
+***************************************************************/
+#define map_same_continent(x1, y1, x2, y2) \
+ (map_get_continent((x1), (y1)) == map_get_continent((x2), (y2)))
+
+/* FIXME: These are particularly useless, but used everywhere. */
+#define get_tile_type(tt) (&tile_types[(tt)])
+#define get_tile_infrastructure_set(ptile) \
+ ((ptile)->special & S_INFRASTRUCTURE_MASK)
+
+#define IS_REAL_TILE(x,y) \
+ (((unsigned) (y)) < ((unsigned) map.ysize))
+
+#define IS_NORM_TILE(x,y) \
+ (((unsigned) (x)) < ((unsigned) map.xsize))
+
+#define IS_PROP_TILE(x,y) \
+ (IS_REAL_TILE((x),(y)) && IS_NORM_TILE((x),(y)))
+
+#if 1
+#define MAP(x,y) (map.tiles + (IS_PROP_TILE((x),(y)) \
+ ? ((x) + map.xsize * (y)) \
+ : (abort(), 0)))
+#else
+#define MAP(x,y) (map.tiles + (x) + map.xsize * (y))
+#endif
+
+#define MAPSTEP(x,y,x1,y1,dir) \
+ do { \
+ (x) = (x1) + DIR_DX[(dir)]; \
+ (y) = (y1) + DIR_DY[(dir)]; \
+ /* if ((x) == -1) */ \
+ /* (x) = map.xsize-1; */ \
+ /* else if ((x) == map.xsize) */ \
+ /* (x) = 0; */ \
+ (x) = map_adjust_x((x)); \
+ } while (0)
+
+#define MAPJUMP(x,y,dir) \
+ MAPSTEP((x), (y), (x), (y), (dir))
+
/* This iterates outwards from the starting point (Duh?).
Every tile within max_dist will show up exactly once. (even takes
into account wrap). All positions given correspond to real tiles.
@@ -401,7 +450,7 @@
x_itr -= map.xsize; \
}
-#define adjc_iterate_dir_end \
+#define adjc_dir_iterate_end \
} \
}
@@ -428,7 +477,8 @@
|-+-+-|
|5|6|7|
-------
- */
+Note that you must normalize x1 and y1 yourself.
+*/
extern const int DIR_DX[8];
extern const int DIR_DY[8];
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.126
diff -u -r1.126 citytools.c
--- server/citytools.c 2001/07/28 16:39:13 1.126
+++ server/citytools.c 2001/08/15 22:59:58
@@ -1886,7 +1886,7 @@
{
int map_x = pcity->x + city_x - CITY_MAP_SIZE/2;
int map_y = pcity->y + city_y - CITY_MAP_SIZE/2;
- assert(is_real_tile(map_x, map_y));
+ assert(IS_REAL_TILE(map_x, map_y));
normalize_map_pos(&map_x, &map_y);
map_city_radius_iterate(map_x, map_y, x1, y1) {
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.153
diff -u -r1.153 cityturn.c
--- server/cityturn.c 2001/08/13 11:09:19 1.153
+++ server/cityturn.c 2001/08/15 22:59:58
@@ -1529,7 +1529,9 @@
x=myrand(5)-2;
y=myrand(5)-2;
if ( ( x != -2 && x != 2 ) || ( y != -2 && y != 2 ) ) {
- x=map_adjust_x(pcity->x+x); y=map_adjust_y(pcity->y+y);
+ x = pcity->x + x;
+ y = pcity->y + y;
+ nearest_real_tile(&x, &y);
if ( (map_get_terrain(x,y)!=T_OCEAN && map_get_terrain(x,y)<=T_TUNDRA) &&
(!(map_get_special(x,y)&S_POLLUTION)) ) {
map_set_special(x,y, S_POLLUTION);
Index: server/gamehand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gamehand.c,v
retrieving revision 1.91
diff -u -r1.91 gamehand.c
--- server/gamehand.c 2001/04/14 11:30:45 1.91
+++ server/gamehand.c 2001/08/15 22:59:58
@@ -112,7 +112,7 @@
dx = x + myrand (2*game.dispersion+1) - game.dispersion;
dy = y + myrand (2*game.dispersion+1) - game.dispersion;
dx = map_adjust_x(dx);
- } while (!(is_real_tile(dx, dy) &&
+ } while (!(IS_REAL_TILE(dx, dy) &&
map_same_continent(x, y, dx, dy) &&
(map_get_terrain(dx, dy) != T_OCEAN) &&
!is_non_allied_unit_tile(map_get_tile(dx, dy),
Index: server/gotohand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v
retrieving revision 1.102
diff -u -r1.102 gotohand.c
--- server/gotohand.c 2001/08/14 11:04:22 1.102
+++ server/gotohand.c 2001/08/15 23:00:00
@@ -358,7 +358,7 @@
freelog(LOG_FATAL, "Bad/unimplemented move_type in really_generate_warmap().");
abort();
}
- } adjc_iterate_dir_end;
+ } adjc_dir_iterate_end;
}
freelog(LOG_DEBUG, "Generated warmap for (%d,%d).",
@@ -625,7 +625,7 @@
{
struct player *pplayer = unit_owner(punit);
static const char *d[] = { "NW", "N", "NE", "W", "E", "SW", "S", "SE" };
- int igter, x, y, x1, y1, dir;
+ int igter, x, y;
int orig_x, orig_y;
struct tile *psrctile, *pdesttile;
enum unit_move_type move_type = unit_types[punit->type].move_type;
@@ -677,15 +677,11 @@
/* Try to move to all tiles adjacent to x,y. The coordinats of the tile we
try to move to are x1,y1 */
- for (dir = 0; dir < 8; dir++) {
+ adjc_dir_iterate(x, y, x1, y1, dir) {
/* if the direction is N, S, E or W d[dir][1] is the /0 character... */
- if ((restriction == GOTO_MOVE_CARDINAL_ONLY) && d[dir][1]) continue;
-
- x1 = x + DIR_DX[dir];
- y1 = y + DIR_DY[dir];
- if (!normalize_map_pos(&x1, &y1))
+ if ((restriction == GOTO_MOVE_CARDINAL_ONLY) && d[dir][1])
continue;
-
+
pdesttile = map_get_tile(x1, y1);
switch (move_type) {
@@ -890,7 +886,7 @@
/* Make sure we stop searching when we have no hope of finding a shorter path */
maxcost = total_cost + 1;
}
- } /* end for (dir = 0; dir < 8; dir++) */
+ } adjc_dir_iterate_end;
}
freelog(LOG_DEBUG, "GOTO: (%d, %d) -> (%d, %d), cost = %d",
@@ -908,6 +904,8 @@
add_to_mapqueue(0, dest_x, dest_y);
while (1) {
+ int dir;
+ int x1, y1;
if (!get_from_mapqueue(&x, &y))
break;
@@ -981,7 +979,8 @@
c = map_get_tile(punit->x, punit->y)->move_cost[k];
else c = 3;
if (unit_flag(punit->type, F_IGTER) && c) c = 1;
- x = map_adjust_x(punit->x + DIR_DX[k]); y = map_adjust_y(punit->y + DIR_DY[k]);
+ x = map_adjust_x(punit->x + DIR_DX[k]);
+ y = map_adjust_y(punit->y + DIR_DY[k]);
if (passenger) {
freelog(LOG_DEBUG, "%d@(%d,%d) evaluating (%d,%d)[%d/%d]",
punit->id, punit->x, punit->y, x, y, c, punit->moves_left);
@@ -1533,7 +1532,7 @@
if (x == dest_x) {
for (i = x-1 ; i <= x+1; i++)
if ((ptile = map_get_tile(i, y+go_y))
- /* && is_real_tile(i, y+go_y) */
+ /* && IS_REAL_TILE(i, y+go_y) */
&& ! is_non_allied_unit_tile(ptile, playerid)) {
x = i;
y += go_y;
@@ -1543,7 +1542,7 @@
} else if (y == dest_y) {
for (i = y-1 ; i <= y+1; i++)
if ((ptile = map_get_tile(x+go_x, i))
- && is_real_tile(x+go_x, i)
+ && IS_REAL_TILE(x+go_x, i)
&& ! is_non_allied_unit_tile(ptile, playerid)) {
x += go_x;
y = i;
@@ -1590,7 +1589,7 @@
TRYFULL:
freelog(LOG_DEBUG, "didn't work. Lets try full");
{
- int x1, y1, dir, cost;
+ int cost;
struct unit *penemy;
init_gotomap(src_x, src_y, AIR_MOVING);
@@ -1601,11 +1600,7 @@
|| warmap.cost[dest_x][dest_y] != 255) /* found route */
break;
- for (dir = 0; dir < 8; dir++) {
- x1 = x + DIR_DX[dir];
- y1 = y + DIR_DY[dir];
- if (!normalize_map_pos(&x1, &y1))
- continue;
+ adjc_iterate(x, y, x1, y1) {
if (warmap.cost[x1][y1] <= warmap.cost[x][y])
continue; /* No need for all the calculations */
@@ -1618,7 +1613,7 @@
add_to_mapqueue(cost, x1, y1);
}
}
- } /* end for */
+ } adjc_iterate_end;
}
freelog(LOG_DEBUG, "movecost: %i", warmap.cost[dest_x][dest_y]);
Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.70
diff -u -r1.70 mapgen.c
--- server/mapgen.c 2001/07/28 12:03:29 1.70
+++ server/mapgen.c 2001/08/15 23:00:00
@@ -1356,8 +1356,14 @@
int a;
for (y=0;yknown)&(1u<private_map+offset)->seen;
+ x = map_adjust_x(x);
+ return (MAP(x,y)->known & (1u<private_map + map_inx(x, y))->seen;
}
/***************************************************************
@@ -940,13 +940,12 @@
***************************************************************/
struct player_tile *map_get_player_tile(int x, int y, int playerid)
{
- if(y<0 || y>=map.ysize) {
+ x = map_adjust_x(x);
+ if(!IS_REAL_TILE(x, y)) {
freelog(LOG_ERROR, "Trying to get nonexistant tile at %i,%i", x,y);
- return get_player(playerid)->private_map
- + map_adjust_x(x)+map_adjust_y(y)*map.xsize;
- } else
- return get_player(playerid)->private_map
- + map_adjust_x(x)+y*map.xsize;
+ nearest_real_tile(&x, &y);
+ }
+ return get_player(playerid)->private_map + map_inx(x, y);
}
/***************************************************************
Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.8
diff -u -r1.8 sanitycheck.c
--- server/sanitycheck.c 2001/05/23 18:21:29 1.8
+++ server/sanitycheck.c 2001/08/15 23:00:01
@@ -210,7 +210,7 @@
struct city *pcity;
assert(unit_owner(punit) == pplayer);
- assert(is_real_tile(x, y));
+ assert(IS_REAL_TILE(x, y));
if (punit->homecity) {
pcity = player_find_city_by_id(pplayer, punit->homecity);
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.101
diff -u -r1.101 settlers.c
--- server/settlers.c 2001/08/14 14:31:20 1.101
+++ server/settlers.c 2001/08/15 23:00:01
@@ -770,8 +770,9 @@
**************************************************************************/
int auto_settler_do_goto(struct player *pplayer, struct unit *punit, int x, int y)
{
- punit->goto_dest_x=map_adjust_x(x);
- punit->goto_dest_y=map_adjust_y(y);
+ nearest_real_tile(&x, &y);
+ punit->goto_dest_x = x;
+ punit->goto_dest_y = y;
set_unit_activity(punit, ACTIVITY_GOTO);
send_unit_info(0, punit);
do_unit_goto(punit, GOTO_MOVE_ANY, 0);
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.45
diff -u -r1.45 srv_main.c
--- server/srv_main.c 2001/08/13 12:46:39 1.45
+++ server/srv_main.c 2001/08/15 23:00:01
@@ -1971,6 +1971,9 @@
show_map_to_all();
notify_player(0, _("Game: The game is over..."));
+ printf ("GAME OVER!!!");
+ exit(0);
+
while(server_state==GAME_OVER_STATE) {
force_end_of_sniff=0;
sniff_packets();