Index: client/climisc.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v retrieving revision 1.62 diff -u -r1.62 climisc.c --- client/climisc.c 2001/10/04 19:36:54 1.62 +++ client/climisc.c 2001/10/16 21:54:53 @@ -199,7 +199,7 @@ { int old; - if( !normalize_map_pos(&x, &y) ) + if (!NORMALIZE_POS(x, y)) return; old = map_get_continent(x,y); @@ -479,8 +479,7 @@ assert(is_real_tile(x1, y1)); - if (is_real_tile(x2, y2)) { - normalize_map_pos(&x2, &y2); + if (NORMALIZE_POS(x2, y2)) { assert(is_tiles_adjacent(x1, y1, x2, y2)); if (!map_get_tile(x2, y2)->known) { Index: client/goto.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v retrieving revision 1.27 diff -u -r1.27 goto.c --- client/goto.c 2001/10/08 12:11:16 1.27 +++ client/goto.c 2001/10/16 21:54:53 @@ -620,7 +620,7 @@ /* Replace with check for is_normal_tile later */ assert(is_real_tile(x, y)); - normalize_map_pos(&x, &y); + NORMALIZE_POS(x, y); is_real = MAPSTEP(x1, y1, x, y, dir); @@ -799,7 +799,7 @@ /* Replace with check for is_normal_tile later */ assert(is_real_tile(dest_x, dest_y)); - normalize_map_pos(&dest_x, &dest_y); + NORMALIZE_POS(dest_x, dest_y); if (!goto_map.vector[dest_x][dest_y]) { undraw_line(); Index: client/packhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v retrieving revision 1.195 diff -u -r1.195 packhand.c --- client/packhand.c 2001/10/08 12:14:38 1.195 +++ client/packhand.c 2001/10/16 21:54:53 @@ -463,7 +463,7 @@ int d = (2 * r) + 1; int x = pcity->x - r; int y = pcity->y - r; - normalize_map_pos(&x, &y); + NORMALIZE_POS(x, y); update_map_canvas(x, y, d, d, 1); } else { refresh_tile_mapcanvas(pcity->x, pcity->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/16 21:54:54 @@ -1100,7 +1100,7 @@ *solid_bg = 0; - if (!normalize_map_pos(&x, &y)) + if (!NORMALIZE_POS(x, y)) return -1; ptile = map_get_tile(x, y); Index: client/gui-gtk/mapview.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v retrieving revision 1.103 diff -u -r1.103 mapview.c --- client/gui-gtk/mapview.c 2001/10/05 09:47:41 1.103 +++ client/gui-gtk/mapview.c 2001/10/16 21:54:55 @@ -152,7 +152,7 @@ int fill_bg; struct player *pplayer; - if (normalize_map_pos(&x, &y) && tile_is_known(x, y)) { + if (NORMALIZE_POS(x, y) && tile_is_known(x, y)) { int count = fill_tile_sprite_array(tile_sprs, x, y, citymode, &fill_bg, &pplayer); int i = 0; Index: common/city.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/city.c,v retrieving revision 1.127 diff -u -r1.127 city.c --- common/city.c 2001/10/12 19:48:29 1.127 +++ common/city.c 2001/10/16 21:54:55 @@ -143,7 +143,7 @@ assert(is_valid_city_coords(city_map_x, city_map_y)); *map_x = city_center_x + city_map_x - CITY_MAP_SIZE / 2; *map_y = city_center_y + city_map_y - CITY_MAP_SIZE / 2; - return normalize_map_pos(map_x, map_y); + return NORMALIZE_POS(*map_x, *map_y); } /************************************************************************** Index: common/map.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/map.c,v retrieving revision 1.96 diff -u -r1.96 map.c --- common/map.c 2001/10/11 12:37:04 1.96 +++ common/map.c 2001/10/16 21:54:56 @@ -1069,7 +1069,7 @@ struct tile *tile0, *tile1; assert(is_real_tile(x, y)); - normalize_map_pos(&x, &y); + NORMALIZE_POS(x, y); tile0 = map_get_tile(x, y); debug_log_move_costs("Resetting move costs for", x, y, tile0); @@ -1156,7 +1156,7 @@ ***************************************************************/ struct tile *map_get_tile(int x, int y) { - int is_real = normalize_map_pos(&x, &y); + int is_real = NORMALIZE_POS(x, y); assert(is_real); @@ -1168,7 +1168,7 @@ ***************************************************************/ signed short map_get_continent(int x, int y) { - if (!normalize_map_pos(&x, &y)) + if (!NORMALIZE_POS(x, y)) return -1; else return MAP_TILE(x, y)->continent; @@ -1180,7 +1180,7 @@ void map_set_continent(int x, int y, int val) { assert(is_real_tile(x, y)); - normalize_map_pos(&x, &y); + NORMALIZE_POS(x, y); MAP_TILE(x, y)->continent = val; } @@ -1190,7 +1190,7 @@ ***************************************************************/ enum tile_terrain_type map_get_terrain(int x, int y) { - if (!normalize_map_pos(&x, &y)) + if (!NORMALIZE_POS(x, y)) return T_UNKNOWN; else return MAP_TILE(x, y)->terrain; @@ -1201,7 +1201,7 @@ ***************************************************************/ enum tile_special_type map_get_special(int x, int y) { - if (!normalize_map_pos(&x, &y)) + if (!NORMALIZE_POS(x, y)) return S_NO_SPECIAL; else return MAP_TILE(x, y)->special; @@ -1213,7 +1213,7 @@ void map_set_terrain(int x, int y, enum tile_terrain_type ter) { assert(is_real_tile(x, y)); - normalize_map_pos(&x, &y); + NORMALIZE_POS(x, y); MAP_TILE(x, y)->terrain = ter; } @@ -1223,7 +1223,7 @@ void map_set_special(int x, int y, enum tile_special_type spe) { assert(is_real_tile(x, y)); - normalize_map_pos(&x, &y); + NORMALIZE_POS(x, y); MAP_TILE(x, y)->special |= spe; @@ -1237,7 +1237,7 @@ void map_clear_special(int x, int y, enum tile_special_type spe) { assert(is_real_tile(x, y)); - normalize_map_pos(&x, &y); + NORMALIZE_POS(x, y); MAP_TILE(x, y)->special &= ~spe; if (spe & (S_ROAD | S_RAILROAD)) @@ -1250,7 +1250,7 @@ struct city *map_get_city(int x, int y) { assert(is_real_tile(x, y)); - normalize_map_pos(&x, &y); + NORMALIZE_POS(x, y); return MAP_TILE(x, y)->city; } @@ -1261,7 +1261,7 @@ void map_set_city(int x, int y, struct city *pcity) { assert(is_real_tile(x, y)); - normalize_map_pos(&x, &y); + NORMALIZE_POS(x, y); MAP_TILE(x, y)->city = pcity; } @@ -1271,7 +1271,7 @@ ***************************************************************/ enum known_type tile_is_known(int x, int y) { - if (!normalize_map_pos(&x, &y)) + if (!NORMALIZE_POS(x, y)) return TILE_UNKNOWN; else return (enum known_type) (MAP_TILE(x, y)->known); @@ -1284,8 +1284,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); + NORMALIZE_POS(x1, y1); + NORMALIZE_POS(x2, y2); return (x1 == x2 && y1 == y2); } @@ -1296,7 +1296,7 @@ { int save_x = *x, save_y = *y; - if (!normalize_map_pos(x, y)) { + if (!NORMALIZE_POS(*x, *y)) { freelog(LOG_ERROR, "%d, %d is not a real tile!", *x, *y); nearest_real_pos(x, y); return 0; @@ -1308,13 +1308,6 @@ return 1; } -int is_real_tile(int x, int y) -{ - int x1 = x, y1 = y; - - return normalize_map_pos(&x1, &y1); -} - /************************************************************************** Returns TRUE iff the map position is normal. "Normal" here means that it is both a real/valid coordinate set and that the coordinates are in @@ -1324,21 +1317,8 @@ int is_normal_map_pos(int x, int y) { int x1 = x, y1 = y; - - return (normalize_map_pos(&x1, &y1) && (x1 == x) && (y1 == y)); -} - -/************************************************************************** -Normalizes the map position. Returns TRUE if it is real, FALSE otherwise. -**************************************************************************/ -int normalize_map_pos(int *x, int *y) -{ - while (*x < 0) - *x += map.xsize; - while (*x >= map.xsize) - *x -= map.xsize; - return (0 <= *y && *y < map.ysize); + return NORMALIZE_POS(x1, y1) && (x1 == x) && (y1 == y); } /************************************************************************** @@ -1444,8 +1424,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); + NORMALIZE_POS(start_x, start_y); + NORMALIZE_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.96 diff -u -r1.96 map.h --- common/map.h 2001/10/09 16:26:46 1.96 +++ common/map.h 2001/10/16 21:54:56 @@ -218,7 +218,7 @@ ( DIRSTEP(dest_x, dest_y, dir), \ (dest_x) += (src_x), \ (dest_y) += (src_y), \ - normalize_map_pos(&(dest_x), &(dest_y))) + NORMALIZE_POS((dest_x), (dest_y))) struct city *map_get_city(int x, int y); void map_set_city(int x, int y, struct city *pcity); @@ -230,9 +230,7 @@ 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 is_normal_map_pos(int x, int y); -int normalize_map_pos(int *x, int *y); void nearest_real_pos(int *x, int *y); void rand_neighbour(int x0, int y0, int *x, int *y); @@ -338,7 +336,7 @@ if (MACRO_dx > MACRO_max_dx || MACRO_dx < MACRO_min_dx) \ continue; \ } \ - if (!normalize_map_pos(&ARG_x_itr, &ARG_y_itr)) \ + if (!NORMALIZE_POS(ARG_x_itr, ARG_y_itr)) \ continue; #define iterate_outward_end \ @@ -366,7 +364,8 @@ SI_x_itr1 <= (SI_center_x) + (radius); SI_x_itr1++) { \ SI_x_itr = SI_x_itr1; \ SI_y_itr = SI_y_itr1; \ - if (!normalize_map_pos(&SI_x_itr, &SI_y_itr)) continue; + if (!NORMALIZE_POS(SI_x_itr, SI_y_itr)) \ + continue; #define square_iterate_end \ } \ @@ -384,7 +383,7 @@ RI_x_itr1 <= RI_center_x + 1; RI_x_itr1++) { \ RI_x_itr = RI_x_itr1; \ RI_y_itr = RI_y_itr1; \ - if (!normalize_map_pos(&RI_x_itr, &RI_y_itr)) \ + if (!NORMALIZE_POS(RI_x_itr, RI_y_itr)) \ continue; \ if (RI_x_itr == RI_center_x && RI_y_itr == RI_center_y) \ continue; @@ -413,7 +412,7 @@ x_itr += MACRO_center_x; \ y_itr += MACRO_center_y; \ if (MACRO_border) { \ - if (!normalize_map_pos(&x_itr, &y_itr)) \ + if (!NORMALIZE_POS(x_itr, y_itr)) \ continue; \ } @@ -431,6 +430,17 @@ #define whole_map_iterate_end \ } +#define is_real_tile(x,y) \ + (0 <= (y) && (y) < map.ysize) + +#define NORMALIZE_POS(x,y) \ + ({ while ((x) < 0) \ + (x) += map.xsize; \ + while ((x) >= map.xsize) \ + (x) -= map.xsize; \ + is_real_tile(x, y); \ + }) + /* used to compute neighboring tiles: using @@ -503,7 +513,7 @@ default: \ abort(); \ } \ - if (!normalize_map_pos(&IAC_x, &IAC_y)) \ + if (!NORMALIZE_POS(IAC_x, IAC_y)) \ continue; #define cartesian_adjacent_iterate_end \ Index: common/unit.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v retrieving revision 1.135 diff -u -r1.135 unit.c --- common/unit.c 2001/09/16 09:38:08 1.135 +++ common/unit.c 2001/10/16 21:54:56 @@ -1255,7 +1255,7 @@ } /* 2) */ - if (!normalize_map_pos(&dest_x, &dest_y)) { + if (!NORMALIZE_POS(dest_x, dest_y)) { return MR_BAD_MAP_POSITION; } Index: server/gamehand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/gamehand.c,v retrieving revision 1.97 diff -u -r1.97 gamehand.c --- server/gamehand.c 2001/09/27 22:49:53 1.97 +++ server/gamehand.c 2001/10/16 21:54:56 @@ -111,7 +111,7 @@ do { dx = x + myrand(2 * game.dispersion + 1) - game.dispersion; dy = y + myrand(2 * game.dispersion + 1) - game.dispersion; - normalize_map_pos(&dx, &dy); + NORMALIZE_POS(dx, dy); } while (!(is_real_tile(dx, dy) && map_get_continent(x, y) == map_get_continent(dx, dy) && map_get_terrain(dx, dy) != T_OCEAN Index: server/mapgen.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v retrieving revision 1.74 diff -u -r1.74 mapgen.c --- server/mapgen.c 2001/10/11 12:37:06 1.74 +++ server/mapgen.c 2001/10/16 21:54:57 @@ -556,7 +556,7 @@ for (dir = 0; dir < 4; dir++) { int x1 = x + CAR_DIR_DX[dir]; int y1 = y + CAR_DIR_DY[dir]; - if (normalize_map_pos(&x1, &y1) + if (NORMALIZE_POS(x1, y1) && rd_direction_is_valid[dir]) { rd_comparison_val[dir] = (test_funcs[func_num].func) (x1, y1); if (best_val == -1) { @@ -575,7 +575,7 @@ for (dir = 0; dir < 4; dir++) { int x1 = x + CAR_DIR_DX[dir]; int y1 = y + CAR_DIR_DY[dir]; - if (normalize_map_pos(&x1, &y1) + if (NORMALIZE_POS(x1, y1) && rd_direction_is_valid[dir]) { if (rd_comparison_val[dir] != best_val) rd_direction_is_valid[dir] = 0; @@ -597,7 +597,7 @@ for (dir = 0; dir < 4; dir++) { int x1 = x + CAR_DIR_DX[dir]; int y1 = y + CAR_DIR_DY[dir]; - if (normalize_map_pos(&x1, &y1) + if (NORMALIZE_POS(x1, y1) && rd_direction_is_valid[dir]) { river_blockmark(x, y); x = x1; @@ -617,7 +617,7 @@ for (dir = 0; dir < 4; dir++) { int x1 = x + CAR_DIR_DX[dir]; int y1 = y + CAR_DIR_DY[dir]; - if (normalize_map_pos(&x1, &y1) + if (NORMALIZE_POS(x1, y1) && rd_direction_is_valid[dir]) { if (direction > 0) direction--; else { @@ -1552,7 +1552,7 @@ for (y = n, x = w ; y < s && x < e ; y++, x++) { int map_x = x + xo - w; int map_y = y + yo - n; - if (!normalize_map_pos(&map_x, &map_y)) + if (!NORMALIZE_POS(map_x, map_y)) return 0; if (hmap(x, y) && is_coastline(map_x, map_y)) return 0; @@ -1562,7 +1562,7 @@ for (x = w ; x < e ; x++) { int map_x = x + xo - w; int map_y = y + yo - n; - if (!normalize_map_pos(&map_x, &map_y)) + if (!NORMALIZE_POS(map_x, map_y)) return 0; if (hmap(x, y) && is_coastline(map_x, map_y)) return 0; @@ -1575,7 +1575,7 @@ int map_y = y + yo - n; int is_real; - is_real = normalize_map_pos(&map_x, &map_y); + is_real = NORMALIZE_POS(map_x, map_y); assert(is_real); checkmass--; 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/16 21:54:57 @@ -771,9 +771,9 @@ ***************************************************************/ 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); + int is_real = NORMALIZE_POS(x, y); + int playerid = pplayer->player_no; + int offset = map_inx(x, y); assert(is_real); Index: server/settlers.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v retrieving revision 1.111 diff -u -r1.111 settlers.c --- server/settlers.c 2001/10/04 20:23:37 1.111 +++ server/settlers.c 2001/10/16 21:54:58 @@ -647,12 +647,12 @@ 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)) + if (!NORMALIZE_POS(x, y)) return 0; for (k = 0; k < 12; k++) { int x1 = x + ii[k], y1 = y + jj[k]; - if (!normalize_map_pos(&x1, &y1)) { + if (!NORMALIZE_POS(x1, y1)) { rd[k] = 0; } else { ptile = map_get_tile(x1, y1);