diff -urd -X freeciv.current/diff_ignore patched/client/climisc.c work/client/climisc.c --- patched/client/climisc.c Tue Sep 25 22:12:45 2001 +++ work/client/climisc.c Wed Sep 26 14:25:33 2001 @@ -200,8 +200,7 @@ { int old; - if( !normalize_map_pos(&x, &y) ) - return; + CHECK_MAP_POS(x, y); old = map_get_continent(x,y); @@ -478,7 +477,7 @@ player_in_city_radius(game.player_ptr, x1, y1); int pos2_is_in_city_radius = 0; - assert(is_real_tile(x1, y1)); + CHECK_MAP_POS(x1, y1); assert(map_get_tile(x1, y1)->known); if (is_real_tile(x2, y2)) { diff -urd -X freeciv.current/diff_ignore patched/common/city.c work/common/city.c --- patched/common/city.c Wed Sep 26 14:08:18 2001 +++ work/common/city.c Wed Sep 26 14:26:59 2001 @@ -101,7 +101,8 @@ int *local_city_map_y, int city_center_x, int city_center_y, int map_x, int map_y) { - assert(is_real_tile(map_x, map_y)); + CHECK_MAP_POS(map_x, map_y); + city_map_iterate(test_local_city_map_x, test_local_city_map_y) { int test_map_x = city_center_x + test_local_city_map_x - CITY_MAP_SIZE / 2; @@ -2055,7 +2056,7 @@ *result_city_tile_type, struct city **result_pcity) { - assert(is_real_tile(map_x, map_y)); + CHECK_MAP_POS(map_x, map_y); *result_pcity = map_get_tile(map_x, map_y)->worked; if (*result_pcity) { diff -urd -X freeciv.current/diff_ignore patched/common/map.c work/common/map.c --- patched/common/map.c Tue Sep 25 22:03:28 2001 +++ work/common/map.c Wed Sep 26 14:21:08 2001 @@ -1017,7 +1017,7 @@ static int tile_move_cost_ai(struct tile *tile0, struct tile *tile1, int x, int y, int x1, int y1, int maxcost) { - assert(is_real_tile(x, y)); + CHECK_MAP_POS(x, y); assert(!is_server || (tile0->terrain != T_UNKNOWN && tile1->terrain != T_UNKNOWN)); if (tile0->terrain == T_OCEAN) { @@ -1055,8 +1055,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); @@ -1143,9 +1142,7 @@ ***************************************************************/ struct tile *map_get_tile(int x, int y) { - int is_real = normalize_map_pos(&x, &y); - - assert(is_real); + CHECK_MAP_POS(x, y); return map.tiles + map_inx(x, y); } @@ -1155,10 +1152,9 @@ ***************************************************************/ signed short map_get_continent(int x, int y) { - if (!normalize_map_pos(&x, &y)) - return -1; - else - return (map.tiles + x + y * map.xsize)->continent; + CHECK_MAP_POS(x, y); + + return (map.tiles + x + y * map.xsize)->continent; } /*************************************************************** @@ -1166,8 +1162,8 @@ ***************************************************************/ void map_set_continent(int x, int y, int val) { - assert(is_real_tile(x, y)); - normalize_map_pos(&x, &y); + CHECK_MAP_POS(x, y); + (map.tiles + x + y * map.xsize)->continent = val; } @@ -1177,10 +1173,9 @@ ***************************************************************/ enum tile_terrain_type map_get_terrain(int x, int y) { - if (!normalize_map_pos(&x, &y)) - return T_UNKNOWN; - else - return (map.tiles + x + y * map.xsize)->terrain; + CHECK_MAP_POS(x, y); + + return (map.tiles + x + y * map.xsize)->terrain; } /*************************************************************** @@ -1188,10 +1183,9 @@ ***************************************************************/ enum tile_special_type map_get_special(int x, int y) { - if (!normalize_map_pos(&x, &y)) - return S_NO_SPECIAL; - else - return (map.tiles + x + y * map.xsize)->special; + CHECK_MAP_POS(x, y); + + return (map.tiles + x + y * map.xsize)->special; } /*************************************************************** @@ -1199,8 +1193,8 @@ ***************************************************************/ void map_set_terrain(int x, int y, enum tile_terrain_type ter) { - assert(is_real_tile(x, y)); - normalize_map_pos(&x, &y); + CHECK_MAP_POS(x, y); + (map.tiles + x + y * map.xsize)->terrain = ter; } @@ -1209,8 +1203,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); + CHECK_MAP_POS(x, y); (map.tiles + x + y * map.xsize)->special |= spe; @@ -1223,8 +1216,8 @@ ***************************************************************/ void map_clear_special(int x, int y, enum tile_special_type spe) { - assert(is_real_tile(x, y)); - normalize_map_pos(&x, &y); + CHECK_MAP_POS(x, y); + (map.tiles + x + y * map.xsize)->special &= ~spe; if (spe & (S_ROAD | S_RAILROAD)) @@ -1236,8 +1229,8 @@ ***************************************************************/ struct city *map_get_city(int x, int y) { - assert(is_real_tile(x, y)); - normalize_map_pos(&x, &y); + CHECK_MAP_POS(x, y); + return (map.tiles + x + y*map.xsize)->city; } @@ -1247,8 +1240,8 @@ ***************************************************************/ void map_set_city(int x, int y, struct city *pcity) { - assert(is_real_tile(x, y)); - normalize_map_pos(&x, &y); + CHECK_MAP_POS(x, y); + (map.tiles + x + y*map.xsize)->city=pcity; } @@ -1258,10 +1251,9 @@ ***************************************************************/ 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.tiles + x + y * map.xsize)->known); + CHECK_MAP_POS(x, y); + + return (enum known_type) ((map.tiles + x + y * map.xsize)->known); } /*************************************************************** @@ -1270,9 +1262,9 @@ ***************************************************************/ 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); } @@ -1347,7 +1339,7 @@ DIR8_SOUTHWEST, DIR8_SOUTH, DIR8_SOUTHEAST }; - assert(is_real_tile(x0, y0)); + CHECK_MAP_POS(x0, y0); /* This clever loop by Trent Piepho will take no more than * 8 tries to find a valid direction. */ @@ -1418,9 +1410,9 @@ **************************************************************************/ 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 */ diff -urd -X freeciv.current/diff_ignore patched/common/map.h work/common/map.h --- patched/common/map.h Sun Sep 23 19:11:04 2001 +++ work/common/map.h Wed Sep 26 14:17:11 2001 @@ -214,6 +214,12 @@ (dest_y) += (src_y), \ normalize_map_pos(&(dest_x), &(dest_y))) +#define CHECK_MAP_POS(x,y) do{\ + int dx = x, dy = y; \ + assert(normalize_map_pos(&dx, &dy)); \ + assert(x == dx && y == dy); \ + } while(0) + struct city *map_get_city(int x, int y); void map_set_city(int x, int y, struct city *pcity); enum tile_terrain_type map_get_terrain(int x, int y); Only in patched/: diff Only in patched/: err Only in work/: gmon.out Only in patched/: out Only in work/: prof diff -urd -X freeciv.current/diff_ignore patched/server/maphand.c work/server/maphand.c --- patched/server/maphand.c Sun Sep 23 21:41:02 2001 +++ work/server/maphand.c Wed Sep 26 14:23:00 2001 @@ -952,10 +952,8 @@ struct player_tile *map_get_player_tile(int x, int y, struct player *pplayer) { - if (!is_real_tile(x, y)) { - freelog(LOG_ERROR, "Trying to get nonexistant tile at %i,%i", x, y); - } - nearest_real_pos(&x, &y); + CHECK_MAP_POS(x, y); + return pplayer->private_map + map_inx(x, y); } diff -urd -X freeciv.current/diff_ignore patched/server/settlers.c work/server/settlers.c --- patched/server/settlers.c Wed Sep 26 14:08:18 2001 +++ work/server/settlers.c Wed Sep 26 18:01:57 2001 @@ -468,6 +468,23 @@ /************************************************************************** ... **************************************************************************/ +static int is_wet_or_is_wet_cardinal_around(struct player *pplayer, int x, + int y) +{ + if (is_wet(pplayer, x, y)) + return 1; + + cartesian_adjacent_iterate(x, y, x1, y1) { + if (is_wet(pplayer, x1, y1)) + return 1; + } cartesian_adjacent_iterate_end; + + return 0; +} + +/************************************************************************** +... +**************************************************************************/ static int ai_calc_irrigate(struct city *pcity, struct player *pplayer, int i, int j) { @@ -497,8 +514,7 @@ } else if((ptile->terrain==type->irrigation_result && !(ptile->special&S_IRRIGATION) && !(ptile->special&S_MINE) && !(ptile->city) && - (is_wet(pplayer,x,y) || is_wet(pplayer,x,y-1) || is_wet(pplayer,x,y+1) || - is_wet(pplayer,x-1,y) || is_wet(pplayer,x+1,y)))) { + (is_wet_or_is_wet_cardinal_around(pplayer,x,y)))) { map_set_special(x, y, S_IRRIGATION); m = city_tile_value(pcity, i, j, 0, 0); map_clear_special(x, y, S_IRRIGATION); @@ -507,8 +523,7 @@ (ptile->special&S_IRRIGATION) && !(ptile->special&S_FARMLAND) && player_knows_techs_with_flag(pplayer, TF_FARMLAND) && !(ptile->special&S_MINE) && !(ptile->city) && - (is_wet(pplayer,x,y) || is_wet(pplayer,x,y-1) || is_wet(pplayer,x,y+1) || - is_wet(pplayer,x-1,y) || is_wet(pplayer,x+1,y)))) { + (is_wet_or_is_wet_cardinal_around(pplayer,x,y)))) { map_set_special(x, y, S_FARMLAND); m = city_tile_value(pcity, i, j, 0, 0); map_clear_special(x, y, S_FARMLAND); Only in work/: times