diff -Nur -X/data/freeciv-dev/freeciv/diff_ignore freeciv/common/map.c codeciv/common/map.c --- freeciv/common/map.c Tue Jan 9 23:28:47 2001 +++ codeciv/common/map.c Wed Jan 10 02:14:50 2001 @@ -43,6 +43,10 @@ const int DIR_DX[8] = { -1, 0, 1, -1, 1, -1, 0, 1 }; const int DIR_DY[8] = { -1, -1, -1, 0, 0, 1, 1, 1 }; +/* like DIR_DX[] and DIR_DY[], only cartesian */ +const int CAR_DIR_DX[4] = {1, 0, -1, 0}; +const int CAR_DIR_DY[4] = {0, 1, 0, -1}; + /* Names of specials. * (These must correspond to enum tile_special_type in terrain.h.) */ @@ -196,17 +200,13 @@ **************************************************************************/ void map_allocate(void) { - int x,y; - freelog(LOG_DEBUG, "map_allocate (was %p) (%d,%d)", map.tiles, map.xsize, map.ysize); map.tiles=fc_realloc(map.tiles, map.xsize*map.ysize*sizeof(struct tile)); - for(y=0; yspecial&S_HUT) - return 1; - } + square_iterate(x, y, 3, x1, y1) { + if (map_get_tile(x1, y1)->special & S_HUT) + return 1; + } square_iterate_end; + return 0; } @@ -539,25 +522,25 @@ ***************************************************************/ int is_special_close(int x, int y) { - int x1,y1; - for (x1=x-1;x1special&(S_SPECIAL_1 | S_SPECIAL_2)) - return 1; + square_iterate(x, y, 1, x1, y1) { + if (map_get_tile(x1, y1)->special & (S_SPECIAL_1 | S_SPECIAL_2)) + return 1; + } square_iterate_end; + return 0; } /*************************************************************** -... +Returns whether you can put a city on land near enough to use +the tile. ***************************************************************/ int is_sea_usable(int x, int y) { - int x1,y1; - for (x1=x-2;x1terrain == T_OCEAN + || ptile->terrain == T_RIVER + || ptile->special & S_RIVER + || ptile->special & S_IRRIGATION) + return 1; + + cartesian_adjacent_iterate(x, y, x1, y1) { + ptile = map_get_tile(x1, y1); + if (ptile->terrain == T_OCEAN + || ptile->terrain == T_RIVER + || ptile->special & S_RIVER + || ptile->special & S_IRRIGATION) + return 1; + } cartesian_adjacent_iterate_end; - ptile=map_get_tile(x, y); - ptile_n=map_get_tile(x, y-1); - ptile_e=map_get_tile(x+1, y); - ptile_s=map_get_tile(x, y+1); - ptile_w=map_get_tile(x-1, y); - - return (ptile->terrain==T_OCEAN || ptile->terrain==T_RIVER - || ptile->special&S_RIVER || ptile->special&S_IRRIGATION || - ptile_n->terrain==T_OCEAN || ptile_n->terrain==T_RIVER - || ptile_n->special&S_RIVER || ptile_n->special&S_IRRIGATION || - ptile_e->terrain==T_OCEAN || ptile_e->terrain==T_RIVER - || ptile_e->special&S_RIVER || ptile_e->special&S_IRRIGATION || - ptile_s->terrain==T_OCEAN || ptile_s->terrain==T_RIVER - || ptile_s->special&S_RIVER || ptile_s->special&S_IRRIGATION || - ptile_w->terrain==T_OCEAN || ptile_w->terrain==T_RIVER - || ptile_w->special&S_RIVER || ptile_w->special&S_IRRIGATION); + return 0; } /*************************************************************** @@ -955,15 +939,19 @@ debug_log_move_costs("Resetting move costs for", x, y, tile0); for (dir = 0; dir < 8; dir++) { - x1 = map_adjust_x(x + DIR_DX[dir]); + x1 = x + DIR_DX[dir]; y1 = y + DIR_DY[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 */ - /* this might muck with void_tile, but who cares? */ - tile1->move_cost[7 - dir] = tile_move_cost_ai(tile1, tile0, x1, y1, - x, y, maxcost); + 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[7 - dir] = tile_move_cost_ai(tile1, tile0, x1, y1, + x, y, maxcost); + } else { + /* trying to move off the screen. */ + tile0->move_cost[dir] = maxcost; + } } debug_log_move_costs("Reset move costs for", x, y, tile0); } @@ -975,26 +963,27 @@ ***************************************************************/ void initialize_move_costs(void) { - int x, y, x1, y1, dir; int maxcost = 72; /* should be big enough without being TOO big */ - struct tile *tile0, *tile1; + int dir; for (dir = 0; dir < 8; dir++) { void_tile.move_cost[dir] = maxcost; } - for (x = 0; x < map.xsize; x++) { - for (y = 0; y < map.ysize; y++) { - tile0 = map_get_tile(x, y); - for (dir = 0; dir < 8; dir++) { - x1 = map_adjust_x(x + DIR_DX[dir]); - y1 = y + DIR_DY[dir]; - tile1 = map_get_tile(x1, y1); - tile0->move_cost[dir] = tile_move_cost_ai(tile0, tile1, x, y, + whole_map_iterate(x, y) { + struct tile *tile0, *tile1; + int x1, y1; + tile0 = map_get_tile(x, y); + /* Note: it is smart to also calculate the move costs in invalid + directions here, as they will be set to MAXCOST. */ + for (dir = 0; dir < 8; dir++) { + x1 = map_adjust_x(x + DIR_DX[dir]); + y1 = y + DIR_DY[dir]; + tile1 = map_get_tile(x1, y1); + tile0->move_cost[dir] = tile_move_cost_ai(tile0, tile1, x, y, x1, y1, maxcost); - } } - } + } whole_map_iterate_end; } /*************************************************************** diff -Nur -X/data/freeciv-dev/freeciv/diff_ignore freeciv/common/map.h codeciv/common/map.h --- freeciv/common/map.h Wed Jan 10 00:54:25 2001 +++ codeciv/common/map.h Wed Jan 10 01:50:11 2001 @@ -342,7 +342,7 @@ /* Iterate through all tiles adjacent to a tile */ #define adjc_iterate(RI_center_x, RI_center_y, RI_x_itr, RI_y_itr) \ { \ - int SI_x_itr, SI_y_itr; \ + int RI_x_itr, RI_y_itr; \ int RI_x_itr1; \ for (RI_y_itr = RI_center_y - 1; \ RI_y_itr <= RI_center_y + 1; RI_y_itr++) { \ @@ -385,6 +385,49 @@ */ extern const int DIR_DX[8]; extern const int DIR_DY[8]; + +/* like DIR_DX[] and DIR_DY[], only cartesian */ +extern const int CAR_DIR_DX[4]; +extern const int CAR_DIR_DY[4]; + +#define cartesian_adjacent_iterate(x, y, IAC_x, IAC_y) \ +{ \ + int IAC_i; \ + int IAC_x, IAC_y; \ + for (IAC_i = 0; IAC_i < 4; IAC_i++) { \ + switch (IAC_i) { \ + case 0: \ + IAC_x = x + 1; \ + IAC_y = y; \ + if (!normalize_map_pos(&IAC_x, &IAC_y)) \ + continue; \ + break; \ + case 1: \ + IAC_x = x; \ + IAC_y = y + 1; \ + if (!normalize_map_pos(&IAC_x, &IAC_y)) \ + continue; \ + break; \ + case 2: \ + IAC_x = x - 1; \ + IAC_y = y; \ + if (!normalize_map_pos(&IAC_x, &IAC_y)) \ + continue; \ + break; \ + case 3: \ + IAC_x = x; \ + IAC_y = y - 1; \ + if (!normalize_map_pos(&IAC_x, &IAC_y)) \ + continue; \ + break; \ + default: \ + abort(); \ + } + +#define cartesian_adjacent_iterate_end \ + } \ +} + #define MAP_DEFAULT_HUTS 50 #define MAP_MIN_HUTS 0 diff -Nur -X/data/freeciv-dev/freeciv/diff_ignore freeciv/server/mapgen.c codeciv/server/mapgen.c --- freeciv/server/mapgen.c Tue Jan 9 23:29:13 2001 +++ codeciv/server/mapgen.c Wed Jan 10 02:20:03 2001 @@ -45,48 +45,6 @@ #define RIVERS_MAXTRIES 32767 enum river_map_type {RS_BLOCKED = 1, RS_RIVER = 2}; -/* like DIR_DX[] and DIR_DY[], only cartesian */ -const int CAR_DIR_DX[4] = {1, 0, -1, 0}; -const int CAR_DIR_DY[4] = {0, 1, 0, -1}; - -#define cartesian_adjacent_iterate(x, y, IAC_x, IAC_y) \ -{ \ - int IAC_i; \ - int IAC_x, IAC_y; \ - for (IAC_i = 0; IAC_i < 4; IAC_i++) { \ - switch (IAC_i) { \ - case 0: \ - IAC_x = x + 1; \ - IAC_y = y; \ - if (!normalize_map_pos(&IAC_x, &IAC_y)) \ - continue; \ - break; \ - case 1: \ - IAC_x = x; \ - IAC_y = y + 1; \ - if (!normalize_map_pos(&IAC_x, &IAC_y)) \ - continue; \ - break; \ - case 2: \ - IAC_x = x - 1; \ - IAC_y = y; \ - if (!normalize_map_pos(&IAC_x, &IAC_y)) \ - continue; \ - break; \ - case 3: \ - IAC_x = x; \ - IAC_y = y - 1; \ - if (!normalize_map_pos(&IAC_x, &IAC_y)) \ - continue; \ - break; \ - default: \ - abort(); \ - } - -#define cartesian_adjacent_iterate_end \ - } \ -} - /* Array needed to mark tiles as blocked to prevent a river from falling into itself, and for storing rivers temporarly. A value of 1 means blocked. @@ -818,7 +776,7 @@ static void make_fair(void) { int x,y; - for (y=2;y