? diff Index: ai/aicity.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v retrieving revision 1.87 diff -u -r1.87 aicity.c --- ai/aicity.c 2001/09/15 15:31:18 1.87 +++ ai/aicity.c 2001/09/24 20:36:20 @@ -1009,12 +1009,15 @@ city_list_init(&minilist); map_city_radius_iterate(pcity->x, pcity->y, x, y) { struct city *acity=map_get_tile(x,y)->worked; + int city_map_x, city_map_y, is_valid; if(acity!=NULL && acity!=pcity && acity->owner==pcity->owner) { if(acity->x==x && acity->y==y) /* can't stop working city center */ continue; freelog(LOG_DEBUG, "Availing square in %s", acity->name); - server_remove_worker_city(acity, map_to_city_x(acity, x), - map_to_city_y(acity, y)); + is_valid = + map_to_local_city_map(&city_map_x, &city_map_y, acity, x, y); + assert(is_valid); + server_remove_worker_city(acity, city_map_x, city_map_y); acity->ppl_elvis++; if (!city_list_find_id(&minilist, acity->id)) city_list_insert(&minilist, acity); Index: client/gui-gtk/citydlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v retrieving revision 1.93 diff -u -r1.93 citydlg.c --- client/gui-gtk/citydlg.c 2001/09/16 12:43:23 1.93 +++ client/gui-gtk/citydlg.c 2001/09/24 20:36:22 @@ -1390,23 +1390,17 @@ Furthermore, we don't have to redraw fog on the part of a fogged tile that overlaps another fogged tile, as on the main map, as no tiles in the city radius can be fogged. */ - city_map_iterate(x, y) { - int map_x = pcity->x + x - CITY_MAP_SIZE/2; - int map_y = pcity->y + y - CITY_MAP_SIZE/2; - if (normalize_map_pos(&map_x, &map_y) - && tile_is_known(map_x, map_y)) { + city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) { + if (tile_is_known(map_x, map_y)) { int canvas_x, canvas_y; city_get_canvas_xy(x, y, &canvas_x, &canvas_y); put_one_tile_full(pdialog->map_canvas_store, map_x, map_y, canvas_x, canvas_y, 1); } - } city_map_iterate_end; + } city_map_checked_iterate_end; /* We have to put the output afterwards or it will be covered. */ - city_map_iterate(x, y) { - int map_x = pcity->x + x - 2; - int map_y = pcity->y + y - 2; - if (normalize_map_pos(&map_x, &map_y) - && tile_is_known(map_x, map_y)) { + city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) { + if (tile_is_known(map_x, map_y)) { int canvas_x, canvas_y; city_get_canvas_xy(x, y, &canvas_x, &canvas_y); if (pcity->city_map[x][y]==C_TILE_WORKER) { @@ -1417,17 +1411,14 @@ city_get_trade_tile(x, y, pcity)); } } - } city_map_iterate_end; + } city_map_checked_iterate_end; /* This sometimes will draw one of the lines on top of a city or unit pixmap. This should maybe be moved to put_one_tile_pixmap() to fix this, but maybe it wouldn't be a good idea because the lines would get obscured. */ - city_map_iterate(x, y) { - int map_x = pcity->x + x - 2; - int map_y = pcity->y + y - 2; - if (normalize_map_pos(&map_x, &map_y) - && tile_is_known(map_x, map_y)) { + city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) { + if (tile_is_known(map_x, map_y)) { int canvas_x, canvas_y; city_get_canvas_xy(x, y, &canvas_x, &canvas_y); if (pcity->city_map[x][y]==C_TILE_UNAVAILABLE) { @@ -1435,7 +1426,7 @@ canvas_x, canvas_y); } } - } city_map_iterate_end; + } city_map_checked_iterate_end; } /**************************************************************** @@ -1447,28 +1438,32 @@ struct city *pcity=pdialog->pcity; for(y=0; yx + x - CITY_MAP_SIZE / 2, - pcity->y + y - CITY_MAP_SIZE / 2)) { - pixmap_put_tile(pdialog->map_canvas_store, - pcity->x + x - CITY_MAP_SIZE / 2, - pcity->y + y - CITY_MAP_SIZE / 2, - x * NORMAL_TILE_WIDTH, y * NORMAL_TILE_HEIGHT, 1); - if (pcity->city_map[x][y] == C_TILE_WORKER) - put_city_tile_output(pdialog->map_canvas_store, - x * NORMAL_TILE_WIDTH, - y * NORMAL_TILE_HEIGHT, - city_get_food_tile(x, y, pcity), - city_get_shields_tile(x, y, pcity), - city_get_trade_tile(x, y, pcity)); - else if (pcity->city_map[x][y] == C_TILE_UNAVAILABLE) - pixmap_frame_tile_red(pdialog->map_canvas_store, + if (is_valid_city_coords(x, y)) { + int map_x, map_y, is_real; + + is_real = local_city_map_to_map(&map_x, &map_y, pcity, x, y); + assert(is_real); + + if (tile_is_known(map_x, map_y)) { + pixmap_put_tile(pdialog->map_canvas_store, map_x, map_y, + x * NORMAL_TILE_WIDTH, y * NORMAL_TILE_HEIGHT, + 1); + if (pcity->city_map[x][y] == C_TILE_WORKER) + put_city_tile_output(pdialog->map_canvas_store, + x * NORMAL_TILE_WIDTH, + y * NORMAL_TILE_HEIGHT, + city_get_food_tile(x, y, pcity), + city_get_shields_tile(x, y, pcity), + city_get_trade_tile(x, y, pcity)); + else if (pcity->city_map[x][y] == C_TILE_UNAVAILABLE) + pixmap_frame_tile_red(pdialog->map_canvas_store, + x * NORMAL_TILE_WIDTH, + y * NORMAL_TILE_HEIGHT); + } else { + pixmap_put_black_tile(pdialog->map_canvas_store, x * NORMAL_TILE_WIDTH, y * NORMAL_TILE_HEIGHT); - } else { - pixmap_put_black_tile(pdialog->map_canvas_store, - x * NORMAL_TILE_WIDTH, - y * NORMAL_TILE_HEIGHT); + } } } } Index: client/gui-gtk/mapctrl.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapctrl.c,v retrieving revision 1.47 diff -u -r1.47 mapctrl.c --- client/gui-gtk/mapctrl.c 2001/09/16 09:38:07 1.47 +++ client/gui-gtk/mapctrl.c 2001/09/24 20:36:22 @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -372,7 +373,7 @@ **************************************************************************/ gint adjust_workers(GtkWidget *widget, GdkEventButton *ev) { - int x,y; + int x, y, map_x, map_y, is_valid; struct city *pcity; struct packet_city_request packet; enum city_tile_type wrk; @@ -380,12 +381,13 @@ if(get_client_state()!=CLIENT_GAME_RUNNING_STATE) return TRUE; - get_map_xy(ev->x, ev->y, &x, &y); + get_map_xy(ev->x, ev->y, &map_x, &map_y); - if(!(pcity = find_city_near_tile(x,y))) return TRUE; + if (!(pcity = find_city_near_tile(map_x, map_y))) + return TRUE; - x = map_to_city_x(pcity, x); - y = map_to_city_y(pcity, y); + is_valid = map_to_local_city_map(&x, &y, pcity, map_x, map_y); + assert(is_valid); packet.city_id=pcity->id; packet.worker_x=x; Index: client/gui-gtk/mapview.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v retrieving revision 1.99 diff -u -r1.99 mapview.c --- client/gui-gtk/mapview.c 2001/09/23 16:09:35 1.99 +++ client/gui-gtk/mapview.c 2001/09/24 20:36:25 @@ -1808,11 +1808,9 @@ } gdk_gc_set_foreground(fill_tile_gc, colors_standard[color]); - city_map_iterate(i, j) { + city_map_checked_iterate(pcity->x, pcity->y, i, j, x, y) { enum city_tile_type worked = get_worker_city(pcity, i, j); - int x = pcity->x + i - CITY_MAP_SIZE/2; - int y = pcity->y + j - CITY_MAP_SIZE/2; - if (normalize_map_pos(&x, &y)) { + get_canvas_xy(x, y, &canvas_x, &canvas_y); /* stipple the area */ @@ -1854,8 +1852,7 @@ city_get_shields_tile(i, j, pcity), city_get_trade_tile(i, j, pcity) ); } - } - } city_map_iterate_end; + } city_map_checked_iterate_end; last_pcity=pcity; } Index: client/gui-mui/mapclass.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapclass.c,v retrieving revision 1.63 diff -u -r1.63 mapclass.c --- client/gui-mui/mapclass.c 2001/09/23 16:09:36 1.63 +++ client/gui-mui/mapclass.c 2001/09/24 20:36:27 @@ -2351,21 +2351,17 @@ that overlaps another fogged tile, as on the main map, as no tiles in the city radius can be fogged. */ - city_map_iterate(x, y) { - int map_x = pcity->x + x - 2; - int map_y = pcity->y + y - 2; - if (normalize_map_pos(&map_x, &map_y) && tile_is_known(map_x, map_y)) { + city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) { + if (tile_is_known(map_x, map_y)) { int canvas_x, canvas_y; city_get_canvas_xy(x, y, &canvas_x, &canvas_y); put_one_tile_full(_rp(o), map_x, map_y, canvas_x + _mleft(o), canvas_y + _mtop(o), 1); } - } city_map_iterate_end; + } city_map_checked_iterate_end; /* We have to put the output afterwards or it will be covered. */ - city_map_iterate(x, y) { - int map_x = pcity->x + x - 2; - int map_y = pcity->y + y - 2; - if (normalize_map_pos(&map_x, &map_y) && tile_is_known(map_x, map_y)) { + city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) { + if (tile_is_known(map_x, map_y)) { int canvas_x, canvas_y; city_get_canvas_xy(x, y, &canvas_x, &canvas_y); if (pcity->city_map[x][y]==C_TILE_WORKER) { @@ -2376,16 +2372,14 @@ _mleft(o) + canvas_x, _mtop(o) + canvas_y,0,0); } } - } city_map_iterate_end; + } city_map_checked_iterate_end; /* This sometimes will draw one of the lines on top of a city or unit pixmap. This should maybe be moved to put_one_tile_pixmap() to fix this, but maybe it wouldn't be a good idea because the lines would get obscured. */ - city_map_iterate(x, y) { - int map_x = pcity->x + x - 2; - int map_y = pcity->y + y - 2; - if (normalize_map_pos(&map_x, &map_y) && tile_is_known(map_x, map_y)) + city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) { + if (tile_is_known(map_x, map_y)) { int canvas_x, canvas_y; city_get_canvas_xy(x, y, &canvas_x, &canvas_y); @@ -2408,7 +2402,7 @@ Draw(rp,canvas_x, canvas_y+NORMAL_TILE_HEIGHT/2); } } - } city_map_iterate_end; + } city_map_checked_iterate_end; } else { int x,y; @@ -2416,16 +2410,16 @@ { for (x = 0; x < CITY_MAP_SIZE; x++) { - LONG tilex = pcity->x + x - CITY_MAP_SIZE / 2; - LONG tiley = pcity->y + y - CITY_MAP_SIZE / 2; - LONG x1 = _mleft(o) + x * get_normal_tile_width(); LONG y1 = _mtop(o) + y * get_normal_tile_height(); LONG x2 = x1 + get_normal_tile_width() - 1; LONG y2 = y1 + get_normal_tile_height() - 1; + + if (is_valid_city_coords(x, y)) { + LONG tilex, tiley; - if (is_valid_city_coords(x, y) && is_real_tile(tilex, tiley)) { - if (tile_is_known(tilex, tiley)) { + if (local_city_map_to_map(&tilex, &tiley, pcity, x, y) + && tile_is_known(tilex, tiley)) { put_tile(_rp(o), tilex, tiley, x1, y1, 1); if (pcity->city_map[x][y] == C_TILE_WORKER) { Index: client/gui-win32/citydlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/citydlg.c,v retrieving revision 1.1 diff -u -r1.1 citydlg.c --- client/gui-win32/citydlg.c 2001/09/04 19:09:33 1.1 +++ client/gui-win32/citydlg.c 2001/09/24 20:36:29 @@ -514,24 +514,18 @@ Furthermore, we don't have to redraw fog on the part of a fogged tile that overlaps another fogged tile, as on the main map, as no tiles in the city radius can be fogged. */ - city_map_iterate(x, y) { - int map_x = pcity->x + x - 2; - int map_y = pcity->y + y - 2; - if (normalize_map_pos(&map_x, &map_y) - && tile_is_known(map_x, map_y)) { + city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) { + if (tile_is_known(map_x, map_y)) { int canvas_x, canvas_y; city_get_canvas_xy(x, y, &canvas_x, &canvas_y); put_one_tile_full(hdc, map_x, map_y, canvas_x, canvas_y, 1); } - } city_map_iterate_end; + } city_map_checked_iterate_end; /* We have to put the output afterwards or it will be covered. */ - city_map_iterate(x, y) { - int map_x = pcity->x + x - 2; - int map_y = pcity->y + y - 2; - if (normalize_map_pos(&map_x, &map_y) - && tile_is_known(map_x, map_y)) { + city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) { + if (tile_is_known(map_x, map_y)) { int canvas_x, canvas_y; city_get_canvas_xy(x, y, &canvas_x, &canvas_y); if (pcity->city_map[x][y]==C_TILE_WORKER) { @@ -542,17 +536,14 @@ city_get_trade_tile(x, y, pcity)); } } - } city_map_iterate_end; + } city_map_checked_iterate_end; /* This sometimes will draw one of the lines on top of a city or unit pixmap. This should maybe be moved to put_one_tile_pixmap() to fix this, but maybe it wouldn't be a good idea because the lines would get obscured. */ - city_map_iterate(x, y) { - int map_x = pcity->x + x - 2; - int map_y = pcity->y + y - 2; - if (normalize_map_pos(&map_x, &map_y) - && tile_is_known(map_x, map_y)) { + city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) { + if (tile_is_known(map_x, map_y)) { int canvas_x, canvas_y; city_get_canvas_xy(x, y, &canvas_x, &canvas_y); if (pcity->city_map[x][y]==C_TILE_UNAVAILABLE) { @@ -560,7 +551,7 @@ canvas_x, canvas_y); } } - } city_map_iterate_end; + } city_map_checked_iterate_end; } @@ -574,14 +565,12 @@ pcity=pdialog->pcity; for(y=0; yx+x-CITY_MAP_SIZE/2, - pcity->y+y-CITY_MAP_SIZE/2)) { - pixmap_put_tile(citydlgdc, - pcity->x+x-CITY_MAP_SIZE/2, - pcity->y+y-CITY_MAP_SIZE/2, + int map_x, map_y; + + if (is_valid_city_coords(x, y) + && local_city_map_to_map(&map_x, &map_y, pcity, x, y) + && tile_is_known(map_x, map_y)) { + pixmap_put_tile(citydlgdc, map_x, map_y, x*NORMAL_TILE_WIDTH, y*NORMAL_TILE_HEIGHT,1); if(pcity->city_map[x][y]==C_TILE_WORKER) Index: client/gui-xaw/citydlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/citydlg.c,v retrieving revision 1.55 diff -u -r1.55 citydlg.c --- client/gui-xaw/citydlg.c 2001/09/15 21:25:10 1.55 +++ client/gui-xaw/citydlg.c 2001/09/24 20:36:31 @@ -1563,12 +1563,12 @@ for(y=0; yx + x - CITY_MAP_SIZE / 2, - pcity->y + y - CITY_MAP_SIZE / 2)) { - pixmap_put_tile(XtWindow(pdialog->map_canvas), - pcity->x + x - CITY_MAP_SIZE / 2, - pcity->y + y - CITY_MAP_SIZE / 2, + int map_x, map_y; + + if (is_valid_city_coords(x, y) + && local_city_map_to_map(&map_x, &map_y, pcity, x, y) + && tile_is_known(map_x, map_y)) { + pixmap_put_tile(XtWindow(pdialog->map_canvas), map_x, map_y, x * NORMAL_TILE_WIDTH, y * NORMAL_TILE_HEIGHT, 1); if (pcity->city_map[x][y] == C_TILE_WORKER) put_city_tile_output(XtWindow(pdialog->map_canvas), Index: client/gui-xaw/mapview.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v retrieving revision 1.80 diff -u -r1.80 mapview.c --- client/gui-xaw/mapview.c 2001/09/23 16:09:38 1.80 +++ client/gui-xaw/mapview.c 2001/09/24 20:36:31 @@ -1174,11 +1174,10 @@ XSetForeground(display, fill_tile_gc, colors_standard[color]); get_canvas_xy(pcity->x, pcity->y, &canvas_x, &canvas_y); + city_map_checked_iterate(pcity->x, pcity->y, i,j, x, y) { city_map_iterate(i, j) { enum city_tile_type worked = get_worker_city(pcity, i, j); - int x = pcity->x + i - CITY_MAP_SIZE/2; - int y = pcity->y + j - CITY_MAP_SIZE/2; - if (normalize_map_pos(&x, &y)) { + get_canvas_xy(x, y, &canvas_x, &canvas_y); if (!(i==2 && j==2)) { if (worked == C_TILE_EMPTY) { @@ -1201,8 +1200,7 @@ city_get_shields_tile(i, j, pcity), city_get_trade_tile(i, j, pcity) ); } - } - } city_map_iterate_end; + } city_map_checked_iterate_end; last_pcity = pcity; } Index: common/city.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/city.c,v retrieving revision 1.122 diff -u -r1.122 city.c --- common/city.c 2001/09/17 08:39:26 1.122 +++ common/city.c 2001/09/24 20:36:33 @@ -93,37 +93,67 @@ } /************************************************************************** -Given a real map position and a city finds the city map coordinates of the -tiles. -Returns whether the real map position was inside the city map. -**************************************************************************/ -int get_citymap_xy(const struct city *pcity, const int x, const int y, - int *city_x, int *city_y) -{ - assert(is_real_tile(x, y)); - city_map_iterate(x1, y1) { - int map_x = pcity->x + x1 - CITY_MAP_SIZE/2; - int map_y = pcity->y + y1 - CITY_MAP_SIZE/2; - if (normalize_map_pos(&map_x, &map_y) - && map_x == x && map_y == y) { - *city_x = x1; - *city_y = y1; +Given a real map position and a city finds the city map coordinates of +the tiles. Returns whether the real map position was inside the city +map. +**************************************************************************/ +int base_map_to_local_city_map(int *local_city_map_x, + 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)); + 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; + int test_map_y = + city_center_y + test_local_city_map_y - CITY_MAP_SIZE / 2; + if (normalize_map_pos(&test_map_x, &test_map_y) + && test_map_x == map_x && test_map_y == map_y) { + *local_city_map_x = test_local_city_map_x; + *local_city_map_y = test_local_city_map_y; return 1; } } city_map_iterate_end; - return 0; } +int map_to_local_city_map(int *local_city_map_x, int *local_city_map_y, + const struct city *const pcity, int map_x, + int map_y) +{ + return base_map_to_local_city_map(local_city_map_x, + local_city_map_y, pcity->x, pcity->y, + map_x, map_y); +} + +int base_local_city_map_to_map(int *map_x, int *map_y, + int city_center_x, int city_center_y, + int local_city_map_x, int local_city_map_y) +{ + assert(is_valid_city_coords(local_city_map_x, local_city_map_y)); + *map_x = city_center_x + local_city_map_x - CITY_MAP_SIZE / 2; + *map_y = city_center_y + local_city_map_y - CITY_MAP_SIZE / 2; + return normalize_map_pos(map_x, map_y); +} + +int local_city_map_to_map(int *map_x, int *map_y, + const struct city *const pcity, + int local_city_map_x, int local_city_map_y) +{ + return base_local_city_map_to_map(map_x, map_y, + pcity->x, pcity->y, + local_city_map_x, local_city_map_y); +} + /************************************************************************** Set the worker on the citymap. Also sets the worked field in the map. **************************************************************************/ void set_worker_city(struct city *pcity, int city_x, int city_y, enum city_tile_type type) { - int map_x = pcity->x + city_x - CITY_MAP_SIZE/2; - int map_y = pcity->y + city_y - CITY_MAP_SIZE/2; - if (normalize_map_pos(&map_x, &map_y)) { + int map_x, map_y; + + if (local_city_map_to_map(&map_x, &map_y, pcity, city_x, city_y)) { struct tile *ptile = map_get_tile(map_x, map_y); if (pcity->city_map[city_x][city_y] == C_TILE_WORKER) if (ptile->worked == pcity) @@ -159,25 +189,6 @@ } /************************************************************************** - Convert map coordinate into position in city map -**************************************************************************/ -int map_to_city_x(struct city *pcity, int x) -{ - int t = map.xsize/2; - x -= pcity->x; - if (x > t) - x -= map.xsize; - else if (x < -t) - x += map.xsize; - - return x+CITY_MAP_SIZE/2; -} -int map_to_city_y(struct city *pcity, int y) -{ - return y-pcity->y+CITY_MAP_SIZE/2; -} - -/************************************************************************** FIXME: This should be replaced in the near future with improvment_redundant() **************************************************************************/ @@ -503,14 +514,20 @@ **************************************************************************/ int city_get_shields_tile(int x, int y, struct city *pcity) { - int s=0; - enum tile_special_type spec_t=map_get_special(pcity->x+x-2, pcity->y+y-2); - enum tile_terrain_type tile_t=map_get_terrain(pcity->x+x-2, pcity->y+y-2); + int is_real, map_x, map_y, s = 0; + enum tile_special_type spec_t; + enum tile_terrain_type tile_t; struct government *g = get_gov_pcity(pcity); int celeb = city_celebrating(pcity); int before_penalty = (celeb ? g->celeb_shields_before_penalty : g->shields_before_penalty); + + is_real = local_city_map_to_map(&map_x, &map_y, pcity, x, y); + assert(is_real); + spec_t = map_get_special(map_x, map_y); + tile_t = map_get_terrain(map_x, map_y); + if (spec_t & S_SPECIAL_1) s=get_tile_type(tile_t)->shield_special_1; else if (spec_t & S_SPECIAL_2) @@ -582,10 +599,16 @@ **************************************************************************/ int city_get_trade_tile(int x, int y, struct city *pcity) { - enum tile_special_type spec_t=map_get_special(pcity->x+x-2, pcity->y+y-2); - enum tile_terrain_type tile_t=map_get_terrain(pcity->x+x-2, pcity->y+y-2); + enum tile_special_type spec_t; + enum tile_terrain_type tile_t; struct government *g = get_gov_pcity(pcity); - int t; + int is_real, map_x, map_y, t; + + is_real = local_city_map_to_map(&map_x, &map_y, pcity, x, y); + assert(is_real); + + spec_t = map_get_special(map_x, map_y); + tile_t = map_get_terrain(map_x, map_y); if (spec_t & S_SPECIAL_1) t=get_tile_type(tile_t)->trade_special_1; @@ -673,15 +696,21 @@ **************************************************************************/ int city_get_food_tile(int x, int y, struct city *pcity) { - int f; - enum tile_special_type spec_t=map_get_special(pcity->x+x-2, pcity->y+y-2); - enum tile_terrain_type tile_t=map_get_terrain(pcity->x+x-2, pcity->y+y-2); + int is_real, map_x, map_y, f; + enum tile_special_type spec_t; + enum tile_terrain_type tile_t; struct tile_type *type; struct government *g = get_gov_pcity(pcity); int celeb = city_celebrating(pcity); int before_penalty = (celeb ? g->celeb_food_before_penalty : g->food_before_penalty); int city_auto_water; + + is_real = local_city_map_to_map(&map_x, &map_y, pcity, x, y); + assert(is_real); + + spec_t = map_get_special(map_x, map_y); + tile_t = map_get_terrain(map_x, map_y); type=get_tile_type(tile_t); city_auto_water = (x==2 && y==2 && tile_t==type->irrigation_result Index: common/city.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/city.h,v retrieving revision 1.89 diff -u -r1.89 city.h --- common/city.h 2001/09/16 12:43:25 1.89 +++ common/city.h 2001/09/24 20:36:33 @@ -107,10 +107,9 @@ * (mx,my). */ #define city_map_checked_iterate(x0, y0, cx, cy, mx, my) { \ - int _x0= (x0)-CITY_MAP_SIZE/2, _y0= (y0)-CITY_MAP_SIZE/2; \ city_map_iterate_outwards(cx, cy) { \ - int my= cy + _y0, mx= cx + _x0; \ - if(normalize_map_pos(&mx,&my)) { + int mx, my; \ + if (base_local_city_map_to_map(&mx, &my, x0, y0, cx, cy)) { #define city_map_checked_iterate_end \ } \ @@ -133,9 +132,8 @@ for (MCMI_y = 0; MCMI_y < CITY_MAP_SIZE; MCMI_y++) { \ if (! ((MCMI_x == 0 || MCMI_x == (CITY_MAP_SIZE-1)) \ && (MCMI_y == 0 || MCMI_y == (CITY_MAP_SIZE-1))) ) { \ - x_itr = city_x + MCMI_x - CITY_MAP_SIZE/2; \ - y_itr = city_y + MCMI_y - CITY_MAP_SIZE/2; \ - if (!normalize_map_pos(&x_itr, &y_itr)) \ + if(!base_local_city_map_to_map(&x_itr, &y_itr, city_x, \ + city_y, MCMI_x, MCMI_y)) \ continue; #define map_city_radius_iterate_end \ @@ -344,8 +342,20 @@ /* city map functions */ int is_valid_city_coords(const int city_x, const int city_y); -int get_citymap_xy(const struct city *pcity, const int x, const int y, - int *city_x, int *city_y); +int base_map_to_local_city_map(int *local_city_map_x, + int *local_city_map_y, int city_center_x, + int city_center_y, int map_x, int map_y); + +int map_to_local_city_map(int *local_city_map_x, int *local_city_map_y, + const struct city *const pcity, int map_x, + int map_y); + +int base_local_city_map_to_map(int *map_x, int *map_y, + int city_center_x, int city_center_y, + int local_city_map_x, int local_city_map_y); +int local_city_map_to_map(int *map_x, int *map_y, + const struct city *const pcity, + int local_city_map_x, int local_city_map_y); int city_get_shields_tile(int x, int y, struct city *pcity); /* shield on spot */ int city_get_trade_tile(int x, int y, struct city *pcity); /* trade on spot */ int city_get_food_tile(int x, int y, struct city *pcity); /* food on spot */ @@ -357,8 +367,6 @@ enum city_tile_type *result_city_tile_type, struct city **result_pcity); int is_worker_here(struct city *pcity, int city_x, int city_y); -int map_to_city_x(struct city *pcity, int x); -int map_to_city_y(struct city *pcity, int y); int city_can_be_built_here(int x, int y); Index: server/citytools.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v retrieving revision 1.142 diff -u -r1.142 citytools.c --- server/citytools.c 2001/09/21 20:08:24 1.142 +++ server/citytools.c 2001/09/24 20:36:36 @@ -1679,11 +1679,7 @@ int map_x, map_y; struct tile *ptile; - assert(is_valid_city_coords(city_x, city_y)); - map_x = city_x + pcity->x - CITY_MAP_SIZE/2; - map_y = city_y + pcity->y - CITY_MAP_SIZE/2; - - if (!normalize_map_pos(&map_x, &map_y)) + if (!local_city_map_to_map(&map_x, &map_y, pcity, city_x, city_y)) return 0; ptile = map_get_tile(map_x, map_y); @@ -1725,17 +1721,19 @@ /* Update adjacent cities. */ { - 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)); - normalize_map_pos(&map_x, &map_y); + int map_x, map_y, is_real; + is_real = local_city_map_to_map(&map_x, &map_y, pcity, city_x, city_y); + assert(is_real); + map_city_radius_iterate(map_x, map_y, x1, y1) { struct city *pcity2 = map_get_city(x1, y1); if (pcity2 && pcity2 != pcity) { - int city_x2, city_y2; - int res = get_citymap_xy(pcity2, map_x, map_y, &city_x2, &city_y2); - assert(res); + int city_x2, city_y2, is_valid; + + is_valid = map_to_local_city_map(&city_x2, &city_y2, pcity2, map_x, + map_y); + assert(is_valid); update_city_tile_status(pcity2, city_x2, city_y2); } } map_city_radius_iterate_end; @@ -1773,9 +1771,10 @@ **************************************************************************/ void update_city_tile_status_map(struct city *pcity, int map_x, int map_y) { - int city_x, city_y; + int city_x, city_y, is_valid; - get_citymap_xy(pcity, map_x, map_y, &city_x, &city_y); + is_valid = map_to_local_city_map(&city_x, &city_y, pcity, map_x, map_y); + assert(is_valid); update_city_tile_status(pcity, city_x, city_y); } Index: server/sanitycheck.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v retrieving revision 1.11 diff -u -r1.11 sanitycheck.c --- server/sanitycheck.c 2001/09/12 09:12:15 1.11 +++ server/sanitycheck.c 2001/09/24 20:36:36 @@ -134,10 +134,9 @@ assert(map_get_terrain(pcity->x, pcity->y) != T_OCEAN); city_map_iterate(x, y) { - int map_x = pcity->x + x - CITY_MAP_SIZE/2; - int map_y = pcity->y + y - CITY_MAP_SIZE/2; + int map_x,map_y; - if (normalize_map_pos(&map_x, &map_y)) { + if (local_city_map_to_map(&map_x, &map_y, pcity, x, y)) { struct tile *ptile = map_get_tile(map_x, map_y); switch (get_worker_city(pcity, x, y)) { case C_TILE_EMPTY: @@ -186,8 +185,11 @@ struct tile *ptile = map_get_tile(x, y); if (ptile->worked) { struct city *pcity = ptile->worked; - int city_x, city_y; - get_citymap_xy(pcity, x, y, &city_x, &city_y); + int city_x, city_y, is_valid; + + is_valid = map_to_local_city_map(&city_x, &city_y, pcity, x, y); + assert(is_valid); + if (pcity->city_map[city_x][city_y] != C_TILE_WORKER) { freelog(LOG_ERROR, "%d,%d is listed as being worked by %s " "on the map, but %s lists the tile %d,%d as having " Index: server/savegame.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v retrieving revision 1.31 diff -u -r1.31 savegame.c --- server/savegame.c 2001/09/16 12:43:31 1.31 +++ server/savegame.c 2001/09/24 20:36:38 @@ -999,7 +999,12 @@ if (*p=='0') { set_worker_city(pcity, x, y, C_TILE_EMPTY); } else if (*p=='1') { - if (map_get_tile(pcity->x+x-2, pcity->y+y-2)->worked) { + int map_x, map_y, is_real; + + is_real = local_city_map_to_map(&map_x, &map_y, pcity, x, y); + assert(is_real); + + if (map_get_tile(map_x, map_y)->worked) { /* oops, inconsistent savegame; minimal fix: */ freelog(LOG_VERBOSE, "Inconsistent worked for %s (%d,%d), " "converting to elvis", pcity->name, x, y); @@ -1914,12 +1919,14 @@ break; case C_TILE_WORKER: if (!res) { - int map_x, map_y; + int map_x, map_y, is_real; pcity->ppl_elvis++; set_worker_city(pcity, x, y, C_TILE_UNAVAILABLE); freelog(LOG_DEBUG, "Worked tile was unavailable!"); + + is_real = local_city_map_to_map(&map_x,&map_y,pcity,x,y); + assert(is_real); - get_citymap_xy(pcity, x, y, &map_x, &map_y); map_city_radius_iterate(map_x, map_y, x2, y2) { struct city *pcity2 = map_get_city(x2, y2); if (pcity2) Index: server/settlers.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v retrieving revision 1.108 diff -u -r1.108 settlers.c --- server/settlers.c 2001/09/15 15:31:27 1.108 +++ server/settlers.c 2001/09/24 20:36:39 @@ -418,9 +418,8 @@ static int ai_calc_pollution(struct city *pcity, int i, int j, int best) { int x, y, m; - x = pcity->x + i - CITY_MAP_SIZE/2; - y = pcity->y + j - CITY_MAP_SIZE/2; - if (!normalize_map_pos(&x, &y)) + + if (!local_city_map_to_map(&x, &y, pcity, i, j)) return -1; if (!(map_get_special(x, y) & S_POLLUTION)) return(-1); map_clear_special(x, y, S_POLLUTION); @@ -437,9 +436,8 @@ int i, int j, int best) { int x, y, m; - x = pcity->x + i - CITY_MAP_SIZE/2; - y = pcity->y + j - CITY_MAP_SIZE/2; - if (!normalize_map_pos(&x, &y)) + + if (!local_city_map_to_map(&x, &y, pcity, i, j)) return -1; if (!(map_get_special(x, y) & S_FALLOUT)) return(-1); map_clear_special(x, y, S_FALLOUT); @@ -473,15 +471,13 @@ static int ai_calc_irrigate(struct city *pcity, struct player *pplayer, int i, int j) { - int m; - int x = pcity->x + i - CITY_MAP_SIZE/2; - int y = pcity->y + j - CITY_MAP_SIZE/2; + int m, x, y; enum tile_terrain_type t; struct tile_type *type; int s; - struct tile *ptile; - if (!normalize_map_pos(&x, &y)) + + if (!local_city_map_to_map(&x, &y, pcity, i, j)) return -1; ptile = map_get_tile(x, y); t = ptile->terrain; @@ -525,11 +521,10 @@ **************************************************************************/ static int ai_calc_mine(struct city *pcity, int i, int j) { - int m; - int x = pcity->x + i - CITY_MAP_SIZE/2; - int y = pcity->y + j - CITY_MAP_SIZE/2; + int m, x, y; struct tile *ptile; - if (!normalize_map_pos(&x, &y)) + + if (!local_city_map_to_map(&x, &y, pcity, i, j)) return -1; ptile = map_get_tile(x, y); @@ -565,15 +560,14 @@ **************************************************************************/ static int ai_calc_transform(struct city *pcity, int i, int j) { - int m; - int x = pcity->x + i - CITY_MAP_SIZE/2; - int y = pcity->y + j - CITY_MAP_SIZE/2; + int m, x, y; enum tile_terrain_type t; struct tile_type *type; int s; enum tile_terrain_type r; struct tile *ptile; - if (!normalize_map_pos(&x, &y)) + + if (!local_city_map_to_map(&x, &y, pcity, i, j)) return -1; ptile = map_get_tile(x, y); @@ -662,11 +656,10 @@ static int ai_calc_road(struct city *pcity, struct player *pplayer, int i, int j) { - int m; + int m, x, y; struct tile *ptile; - int x = pcity->x + i - CITY_MAP_SIZE/2; - int y = pcity->y + j - CITY_MAP_SIZE/2; - if (!normalize_map_pos(&x, &y)) + + if (!local_city_map_to_map(&x, &y, pcity, i, j)) return -1; ptile = map_get_tile(x, y); if (ptile->terrain != T_OCEAN && @@ -686,14 +679,13 @@ static int ai_calc_railroad(struct city *pcity, struct player *pplayer, int i, int j) { - int m; + int m, x, y; struct tile *ptile; enum tile_special_type spe_sav; - - int x = pcity->x + i - CITY_MAP_SIZE/2; - int y = pcity->y + j - CITY_MAP_SIZE/2; - if (!normalize_map_pos(&x, &y)) + + if (!local_city_map_to_map(&x, &y, pcity, i, j)) return -1; + ptile = map_get_tile(x, y); if (ptile->terrain != T_OCEAN && player_knows_techs_with_flag(pplayer, TF_RAILROAD) &&