Index: client/goto.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v retrieving revision 1.25 diff -u -r1.25 goto.c --- client/goto.c 2001/09/19 19:09:17 1.25 +++ client/goto.c 2001/09/22 20:34:20 @@ -616,17 +616,16 @@ ***********************************************************************/ static unsigned char *get_drawn_char(int x, int y, int dir) { - int x1, y1; + int x1, y1, is_real; /* Replace with check for is_normal_tile later */ assert(is_real_tile(x, y)); normalize_map_pos(&x, &y); - x1 = x + DIR_DX[dir]; - y1 = y + DIR_DY[dir]; + is_real = MAPSTEP(x1, y1, x, y, dir); + /* It makes no sense to draw a goto line to a non-existant tile. */ - assert(is_real_tile(x1, y1)); - normalize_map_pos(&x1, &y1); + assert(is_real); if (dir >= 4) { x = x1; @@ -661,7 +660,9 @@ ***********************************************************************/ int get_drawn(int x, int y, int dir) { - if (!is_real_tile(x + DIR_DX[dir], y + DIR_DY[dir])) + int dummy_x, dummy_y; + + if (!MAPSTEP(dummy_x, dummy_y, x, y, dir)) return 0; return *get_drawn_char(x, y, dir); Index: client/tilespec.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v retrieving revision 1.52 diff -u -r1.52 tilespec.c --- client/tilespec.c 2001/09/16 12:43:22 1.52 +++ client/tilespec.c 2001/09/22 20:34:21 @@ -1109,23 +1109,22 @@ tspecial |= S_RIVER; } - for (dir=0; dir<8; dir++) { - int x1 = x + DIR_DX[dir]; - int y1 = y + DIR_DY[dir]; - if (normalize_map_pos(&x1, &y1)) { - ttype_near[dir] = map_get_terrain(x1, y1); - tspecial_near[dir] = map_get_special(x1, y1); + for (dir = 0; dir < 8; dir++) { + ttype_near[dir] = T_UNKNOWN; + tspecial_near[dir] = S_NO_SPECIAL; + } - /* hacking away the river here... */ - if (ttype_near[dir] == T_RIVER) { - ttype_near[dir] = T_GRASSLAND; - tspecial_near[dir] |= S_RIVER; - } - } else { - ttype_near[dir] = T_UNKNOWN; - tspecial_near[dir] = S_NO_SPECIAL; + adjc_dir_iterate(x, y, x1, y1, dir) { + ttype_near[dir] = map_get_terrain(x1, y1); + tspecial_near[dir] = map_get_special(x1, y1); + + /* hacking away the river here... */ + if (ttype_near[dir] == T_RIVER) { + ttype_near[dir] = T_GRASSLAND; + tspecial_near[dir] |= S_RIVER; } - } + } adjc_dir_iterate_end; + ttype_north = ttype_near[DIR8_NORTH]; ttype_north_east = ttype_near[DIR8_NORTHEAST]; ttype_east = ttype_near[DIR8_EAST]; Index: client/gui-gtk/mapview.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v retrieving revision 1.98 diff -u -r1.98 mapview.c --- client/gui-gtk/mapview.c 2001/09/15 21:25:07 1.98 +++ client/gui-gtk/mapview.c 2001/09/22 20:34:23 @@ -1358,16 +1358,11 @@ int x1 = x_itr; int y1 = y_itr; if (normalize_map_pos(&x1, &y1)) { - int dir; - for (dir = 0; dir < 8; dir++) { + adjc_dir_iterate(x1, y1, x2, y2, dir) { if (get_drawn(x1, y1, dir)) { - int x2 = x1 + DIR_DX[dir]; - int y2 = y1 + DIR_DY[dir]; - if (normalize_map_pos(&x2, &y2)) { - really_draw_segment(x1, y1, dir, 0, 1); - } + really_draw_segment(x1, y1, dir, 0, 1); } - } + } adjc_dir_iterate_end; } } } @@ -1937,16 +1932,14 @@ static void really_draw_segment(int src_x, int src_y, int dir, int write_to_screen, int force) { - int dest_x, dest_y; + int dest_x, dest_y, is_real; int canvas_start_x, canvas_start_y; int canvas_end_x, canvas_end_y; gdk_gc_set_foreground(thick_line_gc, colors_standard[COLOR_STD_CYAN]); - dest_x = src_x + DIR_DX[dir]; - dest_y = src_y + DIR_DY[dir]; - assert(is_real_tile(dest_x, dest_y)); - normalize_map_pos(&dest_x, &dest_y); + is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir); + assert(is_real); /* Find middle of tiles. y-1 to not undraw the the middle pixel of a horizontal line when we refresh the tile below-between. */ @@ -1986,14 +1979,11 @@ really_draw_segment(src_x, src_y, dir, 1, 0); } } else { - int dest_x, dest_y; + int dest_x, dest_y, is_real; - dest_x = src_x + DIR_DX[dir]; - dest_y = src_y + DIR_DY[dir]; + is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir); + assert(is_real); - assert(is_real_tile(dest_x, dest_y)); - normalize_map_pos(&dest_x, &dest_y); - /* A previous line already marks the place */ if (get_drawn(src_x, src_y, dir)) { increment_drawn(src_x, src_y, dir); @@ -2019,14 +2009,12 @@ **************************************************************************/ void undraw_segment(int src_x, int src_y, int dir) { - if (is_isometric) { - int dest_x, dest_y; + int dest_x, dest_y, is_real; - dest_x = src_x + DIR_DX[dir]; - dest_y = src_y + DIR_DY[dir]; - assert(is_real_tile(dest_x, dest_y)); - normalize_map_pos(&dest_x, &dest_y); + is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir); + assert(is_real); + if (is_isometric) { assert(get_drawn(src_x, src_y, dir)); decrement_drawn(src_x, src_y, dir); @@ -2038,8 +2026,6 @@ 1); } } else { - int dest_x = src_x + DIR_DX[dir]; - int dest_y = src_y + DIR_DY[dir]; int drawn = get_drawn(src_x, src_y, dir); assert(drawn > 0); @@ -2051,8 +2037,6 @@ decrement_drawn(src_x, src_y, dir); refresh_tile_mapcanvas(src_x, src_y, 1); - assert(is_real_tile(dest_x, dest_y)); - normalize_map_pos(&dest_x, &dest_y); refresh_tile_mapcanvas(dest_x, dest_y, 1); if (NORMAL_TILE_WIDTH%2 == 0 || NORMAL_TILE_HEIGHT%2 == 0) { if (dir == DIR8_NORTHEAST) { @@ -2083,8 +2067,9 @@ get_canvas_xy(x, y, &canvas_src_x, &canvas_src_y); canvas_src_x += NORMAL_TILE_WIDTH/2; canvas_src_y += NORMAL_TILE_HEIGHT/2; - canvas_dest_x = canvas_src_x + (NORMAL_TILE_WIDTH * DIR_DX[dir])/2; - canvas_dest_y = canvas_src_y + (NORMAL_TILE_WIDTH * DIR_DY[dir])/2; + _MAPSTEP(canvas_dest_x, canvas_dest_y, dir); + canvas_dest_x = canvas_src_x + (NORMAL_TILE_WIDTH * canvas_dest_x) / 2; + canvas_dest_y = canvas_src_y + (NORMAL_TILE_WIDTH * canvas_dest_y) / 2; gdk_gc_set_foreground(civ_gc, colors_standard[COLOR_STD_CYAN]); Index: client/gui-mui/graphics.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/graphics.c,v retrieving revision 1.14 diff -u -r1.14 graphics.c --- client/gui-mui/graphics.c 2001/08/15 16:03:28 1.14 +++ client/gui-mui/graphics.c 2001/09/22 20:34:24 @@ -846,8 +846,9 @@ get_canvas_xy(x, y, &canvas_src_x, &canvas_src_y); canvas_src_x += NORMAL_TILE_WIDTH/2; canvas_src_y += NORMAL_TILE_HEIGHT/2; - canvas_dest_x = canvas_src_x + (NORMAL_TILE_WIDTH * DIR_DX[dir])/2; - canvas_dest_y = canvas_src_y + (NORMAL_TILE_WIDTH * DIR_DY[dir])/2; + _MAPSTEP(canvas_dest_x, canvas_dest_y, dir); + canvas_dest_x = canvas_src_x + (NORMAL_TILE_WIDTH * canvas_dest_x) / 2; + canvas_dest_y = canvas_src_y + (NORMAL_TILE_WIDTH * canvas_dest_y) / 2; SetAPen(rp,GetColorPen(COLOR_STD_CYAN)); Move(rp,canvas_src_x+dest_x, canvas_src_y+dest_y); @@ -1025,14 +1026,12 @@ void really_draw_segment(struct RastPort *rp, int dest_x_add, int dest_y_add, int src_x, int src_y, int dir, int force) { - int dest_x, dest_y; + int dest_x, dest_y, is_real; int canvas_start_x, canvas_start_y; int canvas_end_x, canvas_end_y; - dest_x = src_x + DIR_DX[dir]; - dest_y = src_y + DIR_DY[dir]; - assert(is_real_tile(dest_x, dest_y)); - normalize_map_pos(&dest_x, &dest_y); + is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir); + assert(is_real); /* Find middle of tiles. y-1 to not undraw the the middle pixel of a horizontal line when we refresh the tile below-between. */ Index: client/gui-mui/mapclass.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapclass.c,v retrieving revision 1.62 diff -u -r1.62 mapclass.c --- client/gui-mui/mapclass.c 2001/09/15 15:31:22 1.62 +++ client/gui-mui/mapclass.c 2001/09/22 20:34:26 @@ -1273,12 +1273,11 @@ really_draw_segment(_rp(o), _mleft(o), _mtop(o), src_x, src_y, dir, 0); } } else { - int dest_x, dest_y; - dest_x = src_x + DIR_DX[dir]; - dest_y = src_y + DIR_DY[dir]; - assert(is_real_tile(dest_x, dest_y)); - normalize_map_pos(&dest_x, &dest_y); + int dest_x, dest_y, is_real; + is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir); + assert(is_real); + /* A previous line already marks the place */ if (get_drawn(src_x, src_y, dir)) { increment_drawn(src_x, src_y, dir); @@ -1309,14 +1308,12 @@ int dir = data->segment_dir; APTR cliphandle = MUI_AddClipping(muiRenderInfo(o), _mleft(o), _mtop(o), _mwidth(o), _mheight(o)); - if (is_isometric) { - int dest_x, dest_y; + int dest_x, dest_y, is_real; - dest_x = src_x + DIR_DX[dir]; - dest_y = src_y + DIR_DY[dir]; - assert(is_real_tile(dest_x, dest_y)); - normalize_map_pos(&dest_x, &dest_y); + is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir); + assert(is_real); + if (is_isometric) { assert(get_drawn(src_x, src_y, dir)); decrement_drawn(src_x, src_y, dir); @@ -1328,8 +1325,6 @@ 1); } } else { - int dest_x = src_x + DIR_DX[dir]; - int dest_y = src_y + DIR_DY[dir]; int drawn = get_drawn(src_x, src_y, dir); assert(drawn > 0); @@ -1339,8 +1334,6 @@ } else { decrement_drawn(src_x, src_y, dir); refresh_tile_mapcanvas(src_x, src_y, 1); /* !! */ - assert(is_real_tile(dest_x, dest_y)); - normalize_map_pos(&dest_x, &dest_y); refresh_tile_mapcanvas(dest_x, dest_y, 1); /* !! */ if (NORMAL_TILE_WIDTH%2 == 0 || NORMAL_TILE_HEIGHT%2 == 0) { if (dir == DIR8_NORTHEAST) { @@ -1536,16 +1529,12 @@ int x1 = x_itr; int y1 = y_itr; if (normalize_map_pos(&x1, &y1)) { - int dir; - for (dir = 0; dir < 8; dir++) { + adjc_dir_iterate(x1, y1, x2, y2, dir) { if (get_drawn(x1, y1, dir)) { - int x2 = x1 + DIR_DX[dir]; - int y2 = y1 + DIR_DY[dir]; - if (normalize_map_pos(&x2, &y2)) { - really_draw_segment(data->map_layer->rp, 0, 0, x1, y1, dir, 1); - } - } - } + really_draw_segment(data->map_layer->rp, 0, 0, x1, y1, + dir, 1); + } + } adjc_dir_iterate_end; } } } Index: client/gui-win32/mapview.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v retrieving revision 1.4 diff -u -r1.4 mapview.c --- client/gui-win32/mapview.c 2001/09/15 21:25:09 1.4 +++ client/gui-win32/mapview.c 2001/09/22 20:34:27 @@ -809,16 +809,11 @@ int x1 = x_itr; int y1 = y_itr; if (normalize_map_pos(&x1, &y1)) { - int dir; - for (dir = 0; dir < 8; dir++) { + adjc_dir_iterate(x1, y1, x2, y2, dir) { if (get_drawn(x1, y1, dir)) { - int x2 = x1 + DIR_DX[dir]; - int y2 = y1 + DIR_DY[dir]; - if (normalize_map_pos(&x2, &y2)) { - really_draw_segment(x1, y1, dir, 1, 1); - } + really_draw_segment(x1, y1, dir, 0, 1); } - } + } adjc_dir_iterate_end; } } } @@ -1450,13 +1445,12 @@ int write_to_screen, int force) { HPEN old; - int dest_x, dest_y; + int dest_x, dest_y, is_real; int canvas_start_x, canvas_start_y; int canvas_end_x, canvas_end_y; - - dest_x = src_x + DIR_DX[dir]; - dest_y = src_y + DIR_DY[dir]; - assert(normalize_map_pos(&dest_x, &dest_y)); + + is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir); + assert(is_real); /* Find middle of tiles. y-1 to not undraw the the middle pixel of a horizontal line when we refresh the tile below-between. */ @@ -1880,9 +1874,9 @@ get_canvas_xy(x, y, &canvas_src_x, &canvas_src_y); canvas_src_x += NORMAL_TILE_WIDTH/2; canvas_src_y += NORMAL_TILE_HEIGHT/2; - canvas_dest_x = canvas_src_x + (NORMAL_TILE_WIDTH * DIR_DX[dir])/2; - canvas_dest_y = canvas_src_y + (NORMAL_TILE_WIDTH * DIR_DY[dir])/2; - + _MAPSTEP(canvas_dest_x, canvas_dest_y, dir); + canvas_dest_x = canvas_src_x + (NORMAL_TILE_WIDTH * canvas_dest_x) / 2; + canvas_dest_y = canvas_src_y + (NORMAL_TILE_WIDTH * canvas_dest_y) / 2; old=SelectObject(hdc,pen_std[COLOR_STD_CYAN]); MoveToEx(hdc,canvas_src_x+(write_to_screen?map_win_x:0), @@ -1908,12 +1902,10 @@ really_draw_segment(src_x, src_y, dir, 1, 0); } } else { - int dest_x, dest_y; - - dest_x = src_x + DIR_DX[dir]; - dest_y = src_y + DIR_DY[dir]; - - assert(normalize_map_pos(&dest_x, &dest_y)); + int dest_x, dest_y, is_real; + + is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir); + assert(is_real); /* A previous line already marks the place */ if (get_drawn(src_x, src_y, dir)) { @@ -1942,13 +1934,12 @@ **************************************************************************/ void undraw_segment(int src_x, int src_y, int dir) { - if (is_isometric) { - int dest_x, dest_y; + int dest_x, dest_y, is_real; - dest_x = src_x + DIR_DX[dir]; - dest_y = src_y + DIR_DY[dir]; - assert(normalize_map_pos(&dest_x, &dest_y)); + is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir); + assert(is_real); + if (is_isometric) { assert(get_drawn(src_x, src_y, dir)); decrement_drawn(src_x, src_y, dir); @@ -1960,8 +1951,6 @@ 1); } } else { - int dest_x = src_x + DIR_DX[dir]; - int dest_y = src_y + DIR_DY[dir]; int drawn = get_drawn(src_x, src_y, dir); assert(drawn > 0); @@ -1973,7 +1962,6 @@ decrement_drawn(src_x, src_y, dir); refresh_tile_mapcanvas(src_x, src_y, 1); - assert(normalize_map_pos(&dest_x, &dest_y)); refresh_tile_mapcanvas(dest_x, dest_y, 1); if (NORMAL_TILE_WIDTH%2 == 0 || NORMAL_TILE_HEIGHT%2 == 0) { Index: client/gui-xaw/mapview.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v retrieving revision 1.79 diff -u -r1.79 mapview.c --- client/gui-xaw/mapview.c 2001/09/15 21:25:10 1.79 +++ client/gui-xaw/mapview.c 2001/09/22 20:34:28 @@ -1294,14 +1294,11 @@ **************************************************************************/ void draw_segment(int src_x, int src_y, int dir) { - int dest_x, dest_y; + int dest_x, dest_y, is_real; - dest_x = src_x + DIR_DX[dir]; - dest_y = src_y + DIR_DY[dir]; + is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir); + assert(is_real); - assert(is_real_tile(dest_x, dest_y)); - normalize_map_pos(&dest_x, &dest_y); - /* A previous line already marks the place */ if (get_drawn(src_x, src_y, dir)) { increment_drawn(src_x, src_y, dir); @@ -1327,10 +1324,12 @@ **************************************************************************/ void undraw_segment(int src_x, int src_y, int dir) { - int dest_x = src_x + DIR_DX[dir]; - int dest_y = src_y + DIR_DY[dir]; + int dest_x, dest_y, is_real; int drawn = get_drawn(src_x, src_y, dir); + is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir); + assert(is_real); + assert(drawn > 0); /* If we walk on a path twice it looks just like walking on it once. */ if (drawn > 1) { @@ -1340,8 +1339,6 @@ decrement_drawn(src_x, src_y, dir); refresh_tile_mapcanvas(src_x, src_y, 1); - assert(is_real_tile(dest_x, dest_y)); - normalize_map_pos(&dest_x, &dest_y); refresh_tile_mapcanvas(dest_x, dest_y, 1); if (NORMAL_TILE_WIDTH%2 == 0 || NORMAL_TILE_HEIGHT%2 == 0) { if (dir == DIR8_NORTHEAST) { Index: common/map.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/map.c,v retrieving revision 1.89 diff -u -r1.89 map.c --- common/map.c 2001/09/16 09:38:07 1.89 +++ common/map.c 2001/09/22 20:34:29 @@ -1059,7 +1059,6 @@ ***************************************************************/ void reset_move_costs(int x, int y) { - int dir, x1, y1; int maxcost = 72; /* should be big enough without being TOO big */ struct tile *tile0, *tile1; @@ -1069,21 +1068,17 @@ tile0 = map_get_tile(x, y); 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)) { - tile1 = map_get_tile(x1, y1); - tile0->move_cost[dir] = tile_move_cost_ai(tile0, tile1, x, y, - x1, y1, maxcost); - /* reverse: not at all obfuscated now --dwp */ - tile1->move_cost[DIR_REVERSE(dir)] = - tile_move_cost_ai(tile1, tile0, x1, y1, x, y, maxcost); - } else { - /* trying to move off the screen. */ - tile0->move_cost[dir] = maxcost; - } - } + /* trying to move off the screen is the default */ + memset(tile0->move_cost, maxcost, sizeof(tile0->move_cost)); + + adjc_dir_iterate(x, y, x1, y1, dir) { + tile1 = map_get_tile(x1, y1); + tile0->move_cost[dir] = tile_move_cost_ai(tile0, tile1, x, y, + x1, y1, maxcost); + /* reverse: not at all obfuscated now --dwp */ + tile1->move_cost[DIR_REVERSE(dir)] = + tile_move_cost_ai(tile1, tile0, x1, y1, x, y, maxcost); + } adjc_dir_iterate_end; debug_log_move_costs("Reset move costs for", x, y, tile0); } @@ -1103,19 +1098,17 @@ whole_map_iterate(x, y) { struct tile *tile0, *tile1; - int x1, y1; tile0 = map_get_tile(x, y); - for (dir = 0; dir < 8; dir++) { - x1 = x + DIR_DX[dir]; - y1 = y + DIR_DY[dir]; - if (normalize_map_pos(&x1, &y1)) { - tile1 = map_get_tile(x1, y1); - tile0->move_cost[dir] = tile_move_cost_ai(tile0, tile1, x, y, - x1, y1, maxcost); - } else { - tile0->move_cost[dir] = maxcost; - } + + /* trying to move off the screen is the default */ + memset(tile0->move_cost, maxcost, sizeof(tile0->move_cost)); + + adjc_dir_iterate(x, y, x1, y1, dir) { + tile1 = map_get_tile(x1, y1); + tile0->move_cost[dir] = tile_move_cost_ai(tile0, tile1, x, y, + x1, y1, maxcost); } + adjc_dir_iterate_end; } whole_map_iterate_end; } @@ -1371,10 +1364,9 @@ * 8 tries to find a valid direction. */ for (n = 8; n > 0; n--) { enum direction8 choice = (enum direction8) myrand(n); - *x = x0 + DIR_DX[dirs[choice]]; - *y = y0 + DIR_DY[dirs[choice]]; - if (normalize_map_pos(x, y)) /* this neighbour's OK */ + /* this neighbour's OK */ + if (MAPSTEP(*x, *y, x0, y0, dirs[choice])) return; /* Choice was bad, so replace it with the last direction in the list. @@ -1420,16 +1412,13 @@ **************************************************************************/ int get_direction_for_step(int start_x, int start_y, int end_x, int end_y) { - int dir; - assert(is_tiles_adjacent(start_x, start_y, end_x, end_y)); - for (dir = 0; dir < 8; dir++) { - int x1 = start_x + DIR_DX[dir]; - int y1 = start_y + DIR_DY[dir]; - if (normalize_map_pos(&x1, &y1) && x1 == end_x && y1 == end_y) + adjc_dir_iterate(start_x, start_y, x1, y1, dir) { + if (x1 == end_x && y1 == end_y) return dir; - } + } adjc_dir_iterate_end; + assert(0); return -1; } Index: common/map.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/map.h,v retrieving revision 1.92 diff -u -r1.92 map.h --- common/map.h 2001/09/16 09:38:08 1.92 +++ common/map.h 2001/09/22 20:34:29 @@ -204,6 +204,16 @@ #define map_inx(x,y) \ ((x)+(y)*map.xsize) +#define _MAPSTEP(dest_x, dest_y, dir) \ +( (dest_x) = DIR_DX[(dir)], \ + (dest_y) = DIR_DY[(dir)]) + +#define MAPSTEP(dest_x, dest_y, src_x, src_y, dir) \ +( _MAPSTEP(dest_x, dest_y, dir), \ + (dest_x) += (src_x), \ + (dest_y) += (src_y), \ + normalize_map_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); enum tile_terrain_type map_get_terrain(int x, int y); @@ -392,8 +402,9 @@ || MACRO_center_y == map.ysize-1 \ || MACRO_center_x == map.xsize-1); \ for (dir_itr = 0; dir_itr < 8; dir_itr++) { \ - y_itr = MACRO_center_y + DIR_DY[dir_itr]; \ - x_itr = MACRO_center_x + DIR_DX[dir_itr]; \ + _MAPSTEP(x_itr, y_itr, dir_itr); \ + x_itr += MACRO_center_x; \ + y_itr += MACRO_center_y; \ if (MACRO_border) { \ if (!normalize_map_pos(&x_itr, &y_itr)) \ continue; \ Index: server/gotohand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v retrieving revision 1.118 diff -u -r1.118 gotohand.c --- server/gotohand.c 2001/09/19 19:09:18 1.118 +++ server/gotohand.c 2001/09/22 20:34:31 @@ -520,20 +520,15 @@ return 0; { - int dir; - int x, y; struct player *owner = unit_owner(punit); - for (dir = 0; dir < 8; dir++) { - x = map_adjust_x(src_x + DIR_DX[dir]); - y = map_adjust_y(src_y + DIR_DY[dir]); - + adjc_dir_iterate(src_x, src_y, x, y, dir) { if (!dir_ok(dest_x, dest_y, punit->goto_dest_x, punit->goto_dest_y, dir)) continue; if ((map_get_terrain(x, y) != T_OCEAN) && is_enemy_unit_tile(map_get_tile(x, y), owner)) return 0; - } + } adjc_dir_iterate_end; return 0; } } @@ -601,7 +596,7 @@ enum goto_move_restriction restriction) { struct player *pplayer = unit_owner(punit); - 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_type(punit)->move_type; @@ -659,15 +654,10 @@ /* 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 ((restriction == GOTO_MOVE_CARDINAL_ONLY) && !DIR_IS_CARDINAL(dir)) continue; - x1 = x + DIR_DX[dir]; - y1 = y + DIR_DY[dir]; - if (!normalize_map_pos(&x1, &y1)) - continue; - pdesttile = map_get_tile(x1, y1); switch (move_type) { @@ -842,7 +832,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", @@ -863,15 +853,11 @@ if (!get_from_mapqueue(&x, &y)) break; - for (dir = 0; dir < 8; dir++) { + adjc_dir_iterate(x, y, x1, y1, dir) { if ((restriction == GOTO_MOVE_CARDINAL_ONLY) && !DIR_IS_CARDINAL(dir)) continue; if (local_vector[x][y] & (1<x][punit->y] & (1 << k) + adjc_dir_iterate(punit->x, punit->y, x, y, dir) { + if (warmap.vector[punit->x][punit->y] & (1 << dir) && !(restriction == GOTO_MOVE_CARDINAL_ONLY - && !DIR_IS_CARDINAL(k))) { - x = map_adjust_x(punit->x + DIR_DX[k]); - y = map_adjust_y(punit->y + DIR_DY[k]); + && !DIR_IS_CARDINAL(dir))) { if (x == dest_x && y == dest_y) - return k; + return dir; } - } + } adjc_dir_iterate_end; + + memset(d, 0, sizeof(d)); - for (k = 0; k < 8; k++) { + adjc_dir_iterate(punit->x, punit->y, x, y, k) { if ((restriction == GOTO_MOVE_CARDINAL_ONLY) && !DIR_IS_CARDINAL(k)) continue; @@ -936,8 +922,6 @@ c = map_get_tile(punit->x, punit->y)->move_cost[k]; else c = 3; if (unit_flag(punit, F_IGTER) && c) c = 1; - 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); @@ -975,8 +959,8 @@ nearland = 0; if (!pplayer->ai.control && !map_get_known(x, y, pplayer)) nearland++; - for (n = 0; n < 8; n++) { - adjtile = map_get_tile(x + DIR_DX[n], y + DIR_DY[n]); + adjc_iterate(x, y, tmp_x, tmp_y) { + adjtile = map_get_tile(tmp_x, tmp_y); if (adjtile->terrain != T_OCEAN) nearland++; if (!((adjtile->known)&(1u<owner))) { if (punit->moves_left <= c) d[k] -= (d[k]/16); /* Avoid the unknown */ @@ -992,16 +976,17 @@ } unit_list_iterate_end; } /* end this-tile-is-seen else */ - } /* end tiles-adjacent-to-dest for */ + } adjc_iterate_end; if (unit_flag(punit, F_TRIREME) && !nearland) { if (punit->moves_left < 6) d[k] = -1; /* Tired of Kaput!! -- Syela */ else if (punit->moves_left == 6) { - for (n = 0; n < 8; n++) { - if ((warmap.vector[x][y]&(1<x, punit->y, x, y); } } /* end is-a-valid-vector */ - } /* end for */ + } adjc_dir_iterate_end; if (!best) { return(-1); @@ -1035,28 +1020,26 @@ int goto_is_sane(struct unit *punit, int x, int y, int omni) { struct player *pplayer = unit_owner(punit); - int k, possible = 0; + int possible = 0; if (same_pos(punit->x, punit->y, x, y)) return 1; if (is_ground_unit(punit) && (omni || map_get_known_and_seen(x, y, pplayer))) { if (map_get_terrain(x, y) == T_OCEAN) { if (ground_unit_transporter_capacity(x, y, pplayer) > 0) { - for (k = 0; k < 8; k++) { - if (map_get_continent(punit->x, punit->y) == - map_get_continent(x + DIR_DX[k], y + DIR_DY[k])) - possible++; - } + adjc_iterate(punit->x, punit->y, tmp_x, tmp_y) { + if (map_get_continent(tmp_x, tmp_y) == map_get_continent(x, y)) + possible++; + } adjc_iterate_end; } } else { /* going to a land tile */ if (map_get_continent(punit->x, punit->y) == map_get_continent(x, y)) possible++; else { - for (k = 0; k < 8; k++) { - if (map_get_continent(punit->x + DIR_DX[k], punit->y + DIR_DY[k]) == - map_get_continent(x, y)) - possible++; - } + adjc_iterate(punit->x, punit->y, tmp_x, tmp_y) { + if (map_get_continent(tmp_x, tmp_y) == map_get_continent(x, y)) + possible++; + } adjc_iterate_end; } } return(possible); @@ -1133,7 +1116,8 @@ /* This has the side effect of marking the warmap with the possible paths */ if (find_the_shortest_path(punit, waypoint_x, waypoint_y, restriction)) { do { /* move the unit along the path chosen by find_the_shortest_path() while we can */ - int last_tile; + int last_tile, is_real; + if (!punit->moves_left) return; @@ -1146,8 +1130,9 @@ } freelog(LOG_DEBUG, "Going %s", dir_get_name(dir)); - x = map_adjust_x(punit->x + DIR_DX[dir]); - y = punit->y + DIR_DY[dir]; /* no need to adjust this */ + is_real = MAPSTEP(x, y, punit->x, punit->y, dir); + assert(is_real); + penemy = is_enemy_unit_tile(map_get_tile(x, y), unit_owner(punit)); if (!punit->moves_left) @@ -1544,7 +1529,7 @@ TRYFULL: freelog(LOG_DEBUG, "didn't work. Lets try full"); { - int x1, y1, dir, cost; + int cost; struct unit *penemy; init_warmap(src_x, src_y, AIR_MOVING); @@ -1555,11 +1540,7 @@ || warmap.cost[dest_x][dest_y] != MAXCOST) /* 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_dir_iterate(x, y, x1, y1, dir) { if (warmap.cost[x1][y1] <= warmap.cost[x][y]) continue; /* No need for all the calculations */ @@ -1572,7 +1553,7 @@ add_to_mapqueue(cost, x1, y1); } } - } /* end for */ + } adjc_dir_iterate_end; } freelog(LOG_DEBUG, "movecost: %i", warmap.cost[dest_x][dest_y]);