? typescript ? wo_me_p ? diff.diff ? ffff ? tidying.diff ? xyzzy ? gmon.out ? tidying2.diff ? map.diff ? nohup.out ? formatting.diff ? with_me_p ? zappa ? gmon.out-CVS-20010809 ? gmon.out-CVS-20010809.txt.bz2 ? gmon.out-CVS-no-map-adjx-20010809 ? cc.diff ? adjc_dir_iterate3.diff ? gmon.out-CVS-no-map-adjx-20010809.txt.bz2 ? gmon.out.txt.bz2 ? coordfix.diff ? shithappens.diff ? shithappens2.diff ? client/gui-mui/zappa ? common/fitte.diff ? common/PANAMA.diff ? server/zappa ? server/1 Index: ai/advdomestic.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/advdomestic.c,v retrieving revision 1.71 diff -u -r1.71 advdomestic.c --- ai/advdomestic.c 2001/08/26 13:10:11 1.71 +++ ai/advdomestic.c 2001/09/11 19:00:22 @@ -90,6 +90,7 @@ static int ocean_workers(struct city *pcity) { int i = 0; + city_map_checked_iterate(pcity->x, pcity->y, cx, cy, mx, my) { if (map_get_terrain(mx, my) == T_OCEAN) { /* this is a kluge; wasn't getting enough harbors because often @@ -99,31 +100,34 @@ if (is_worker_here(pcity, cx, cy)) i++; } - } - city_map_checked_iterate_end; - return (i / 2); + } city_map_checked_iterate_end; + return i / 2; } static int road_trade(struct city *pcity) { int i = 0; + city_map_checked_iterate(pcity->x, pcity->y, cx, cy, mx, my) { - if (map_get_special(mx, my) & S_ROAD && is_worker_here(pcity, cx, cy)) + if (map_get_special(mx, my) & S_ROAD + && is_worker_here(pcity, cx, cy)) i++; - } - city_map_checked_iterate_end; - return(i); + } city_map_checked_iterate_end; + + return i; } static int farmland_food(struct city *pcity) { int i = 0; + city_map_checked_iterate(pcity->x, pcity->y, cx, cy, mx, my) { if (map_get_special(mx, my) & S_FARMLAND - && is_worker_here(pcity, cx, cy)) i++; - } - city_map_checked_iterate_end; - return(i); + && is_worker_here(pcity, cx, cy)) + i++; + } city_map_checked_iterate_end; + + 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.153 diff -u -r1.153 aiunit.c --- ai/aiunit.c 2001/09/06 22:04:38 1.153 +++ ai/aiunit.c 2001/09/11 19:00:26 @@ -685,10 +685,9 @@ best = 1; *dest_y = y1; *dest_x = x1; } /* next to nothing is better than nothing */ } - } - adjc_iterate_end; + } adjc_iterate_end; - return(best); + return best; } /************************************************************************* @@ -743,32 +742,40 @@ adjc_iterate(dest_x, dest_y, x1, y1) { ok = 0; t = map_get_terrain(x1, y1); - if (warmap.seacost[x1][y1] <= 6 * THRESHOLD && t != T_OCEAN) { /* accessible beachhead */ + if (warmap.seacost[x1][y1] <= 6 * THRESHOLD && t != T_OCEAN) { + /* accessible beachhead */ adjc_iterate(x1, y1, x2, y2) { - if (map_get_terrain(x2, y2) == T_OCEAN) { - if (is_my_zoc(unit_owner(punit), x2, y2)) { - ok++; - goto OK; /* out of adjc_iterate */ - } + if (map_get_terrain(x2, y2) == T_OCEAN + && is_my_zoc(unit_owner(punit), x2, y2)) { + ok++; + goto OK; + + /* FIXME: The above used to be "break; out of adjc_iterate", + but this is incorrect since the current adjc_iterate() is + implemented as two nested loops. */ } - } - adjc_iterate_end; - OK: + } adjc_iterate_end; + OK: - if (ok) { /* accessible beachhead with zoc-ok water tile nearby */ + if (ok) { + /* accessible beachhead with zoc-ok water tile nearby */ ok = get_tile_type(t)->defense_bonus; if (map_get_special(x1, y1) & S_RIVER) ok += (ok * terrain_control.river_defense_bonus) / 100; if (get_tile_type(t)->movement_cost * SINGLE_MOVE < - unit_types[punit->type].move_rate) ok *= 8; + unit_types[punit->type].move_rate) + ok *= 8; ok += (6 * THRESHOLD - warmap.seacost[x1][y1]); - if (ok > best) { best = ok; *x = x1; *y = y1; } + if (ok > best) { + best = ok; + *x = x1; + *y = y1; + } } } - } - adjc_iterate_end; + } adjc_iterate_end; - return(best); + return best; } /************************************************************************** @@ -778,22 +785,23 @@ **************************************************************************/ static void find_city_beach( struct city *pc, struct unit *punit, int *x, int *y) { - int best_xx = punit->x, best_yy = punit->y; + int best_x = punit->x; + int best_y = punit->y; int dist = 100; - int search_dist = real_map_distance( pc->x, pc->y, punit->x, punit->y ); + int search_dist = real_map_distance(pc->x, pc->y, punit->x, punit->y) - 1; + + square_iterate(punit->x, punit->y, search_dist, xx, yy) { + if (map_same_continent(xx, yy, pc->x, pc->y) + && real_map_distance(punit->x, punit->y, xx, yy) < dist) { - square_iterate(punit->x, punit->y, search_dist - 1, xx, yy) { - if (map_same_continent(xx, yy, pc->x, pc->y) && - real_map_distance(punit->x, punit->y, xx, yy) < dist) { dist = real_map_distance(punit->x, punit->y, xx, yy); - best_xx = xx; - best_yy = yy; + best_x = xx; + best_y = yy; } - } - square_iterate_end; + } square_iterate_end; - *x = best_xx; - *y = best_yy; + *x = best_x; + *y = best_y; } /************************************************************************** Index: client/goto.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v retrieving revision 1.20 diff -u -r1.20 goto.c --- client/goto.c 2001/08/30 10:44:16 1.20 +++ client/goto.c 2001/09/11 19:00:26 @@ -324,7 +324,8 @@ /* Try to move to all tiles adjacent to x,y. The coordinats of the tile we try to move to are x1,y1 */ adjc_dir_iterate(x, y, x1, y1, dir) { - if (restriction == GOTO_MOVE_CARDINAL_ONLY && !DIR_IS_CARDINAL(dir)) + if ((restriction == GOTO_MOVE_CARDINAL_ONLY) + && !DIR_IS_CARDINAL(dir)) continue; pdesttile = map_get_tile(x1, y1); @@ -452,13 +453,10 @@ abort(); break; } /****** end switch ******/ - } - adjc_dir_iterate_end; + } adjc_dir_iterate_end; } /* end while */ } - - /************************************************************************** Insert a point and draw the line on the map. Will extend the array if needed. @@ -703,6 +701,7 @@ } /* undraw the line segment */ + dir = get_direction_for_step(line_x, line_y, dest_x, dest_y); undraw_segment(line_x, line_y, dir); @@ -752,7 +751,8 @@ ***********************************************************************/ static int find_route(int x, int y) { - int i, first_index, last_x, last_y; + int last_x, last_y; + int i, first_index; if (route == NULL) { route = fc_malloc(route_length * sizeof(struct map_position)); @@ -786,8 +786,8 @@ route_index++; return find_route(new_x, new_y); /* how about recoding freeciv in MosML? */ } - } - adjc_dir_iterate_end; + } adjc_dir_iterate_end; + assert(0); /* should find direction... */ return -1; /* why can't the compiler figure out that create_goto_map() will newer create a vector that leads to a pos without a Index: common/city.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/city.h,v retrieving revision 1.87 diff -u -r1.87 city.h --- common/city.h 2001/09/06 18:19:09 1.87 +++ common/city.h 2001/09/11 19:00:26 @@ -64,36 +64,41 @@ Some places in the code hardcodes this number (yet). */ #define CITY_MAP_SIZE 5 -/* Iterate a city map. x and y will be elements of [0,CITY_MAP_SIZE). */ -#define city_map_iterate(x, y) \ -{ \ - int x, y; \ - for (y=0;yspecial & + (S_ROAD | S_RAILROAD | S_IRRIGATION | S_FARMLAND | S_MINE | S_FORTRESS | S_AIRBASE); +} + +/*************************************************************** Return a (static) string with terrain name; eg: "Hills" eg: "Hills (Coals)" @@ -167,34 +177,33 @@ 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); } @@ -245,11 +254,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,13 +263,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 < ARRAY_SIZE(tile_special_type_names); inx++) { - if (0 == strcmp(name, tile_special_type_names[inx])) { + for (i = 0; i < ARRAY_SIZE(tile_special_type_names); i++) { + if (0 == strcmp(name, tile_special_type_names[i])) return st; - } + st <<= 1; } @@ -275,11 +281,11 @@ ***************************************************************/ const char *get_special_name(enum tile_special_type type) { - int inx; + int i; - for (inx = 0; inx < ARRAY_SIZE(tile_special_type_names); inx++) { + for (i = 0; i < ARRAY_SIZE(tile_special_type_names); i++) { if (type & 0x1) { - return tile_special_type_names[inx]; + return tile_special_type_names[i]; } type >>= 1; } @@ -590,22 +596,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; } /*************************************************************** @@ -1121,33 +1117,30 @@ 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 (!normalize_map_pos(&x, &y)) - return &void_tile; /* accurate fix by Syela */ + return &void_tile; /* accurate fix by Syela */ else - return map.tiles + x + y * map.xsize; + return map.tiles + map_inx(x, y); } /*************************************************************** @@ -1285,8 +1278,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_pos(x, y); return 0; } @@ -1296,28 +1288,42 @@ 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) - return FALSE; - +int normalize_map_pos(int *x, int *y) +{ while (*x < 0) *x += map.xsize; while (*x >= map.xsize) *x -= map.xsize; + if (!is_real_tile(*x, *y)) + return FALSE; + return TRUE; +} + +/************************************************************************** +Twiddle *x and *y to point the the nearest real tile, and ensure that the +position is normalized. +**************************************************************************/ +void nearest_real_pos(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; } /************************************************************************** Index: common/map.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/map.h,v retrieving revision 1.88 diff -u -r1.88 map.h --- common/map.h 2001/09/06 18:19:09 1.88 +++ common/map.h 2001/09/11 19:00:27 @@ -216,6 +216,8 @@ 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_pos(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); @@ -423,7 +425,8 @@ |-+-+-| |5|6|7| ------- - */ +Note that you must normalize x1 and y1 yourself. +*/ enum direction8 { /* FIXME: DIR8 is used to avoid conflict with Index: server/cityturn.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v retrieving revision 1.160 diff -u -r1.160 cityturn.c --- server/cityturn.c 2001/08/30 11:01:12 1.160 +++ server/cityturn.c 2001/09/11 19:00:27 @@ -1107,7 +1107,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_pos(&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/gotohand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v retrieving revision 1.112 diff -u -r1.112 gotohand.c --- server/gotohand.c 2001/09/08 22:53:27 1.112 +++ server/gotohand.c 2001/09/11 19:00:29 @@ -360,8 +360,7 @@ freelog(LOG_FATAL, "Bad/unimplemented move_type in really_generate_warmap()."); abort(); } - } - adjc_dir_iterate_end; + } adjc_dir_iterate_end; } freelog(LOG_DEBUG, "Generated warmap for (%d,%d).", @@ -990,7 +989,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); Index: server/maphand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v retrieving revision 1.84 diff -u -r1.84 maphand.c --- server/maphand.c 2001/09/02 13:37:59 1.84 +++ server/maphand.c 2001/09/11 19:00:29 @@ -952,12 +952,11 @@ struct player_tile *map_get_player_tile(int x, int y, struct player *pplayer) { - if (y < 0 || y >= map.ysize) { + if (!is_real_tile(x, y)) { freelog(LOG_ERROR, "Trying to get nonexistant tile at %i,%i", x, y); - return pplayer->private_map - + map_adjust_x(x) + map_adjust_y(y) * map.xsize; - } else - return pplayer->private_map + map_adjust_x(x) + y * map.xsize; + } + nearest_real_pos(&x, &y); + return pplayer->private_map + map_inx(x, y); } /*************************************************************** Index: server/settlers.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v retrieving revision 1.105 diff -u -r1.105 settlers.c --- server/settlers.c 2001/09/08 22:53:28 1.105 +++ server/settlers.c 2001/09/11 19:00:29 @@ -766,8 +766,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_pos(&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);