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; y<map.ysize; y++) {
-    for(x=0; x<map.xsize; x++) {
-      tile_init(map_get_tile(x, y));
-    }
-  }
+  whole_map_iterate(x, y) {
+    tile_init(map_get_tile(x, y));
+  } whole_map_iterate_end;
 }
 
 
@@ -320,21 +320,15 @@
 }
 
 /***************************************************************
- The following two function should always be used, such
- that hand optimizations need only be performed once.
- using isnt_ is faster than using is_ sometimes.
- is terrain close diagonally or gridwise ?
+...
 ***************************************************************/
 int is_terrain_near_tile(int x, int y, enum tile_terrain_type t)
 {
-  if (map_get_terrain(x-1, y+1)==t) return 1;
-  if (map_get_terrain(x+1, y-1)==t) return 1;
-  if (map_get_terrain(x-1, y-1)==t) return 1;
-  if (map_get_terrain(x+1, y+1)==t) return 1;
-  if (map_get_terrain(x, y+1)==t)   return 1;
-  if (map_get_terrain(x-1, y)==t)   return 1;
-  if (map_get_terrain(x+1, y)==t)   return 1;
-  if (map_get_terrain(x, y-1)==t)   return 1;
+  adjc_iterate(x, y, x1, y1) {
+    if (map_get_terrain(x1, y1) == t)
+      return 1;
+  } adjc_iterate_end;
+
   return 0;
 }
 
@@ -343,16 +337,14 @@
 ***************************************************************/
 int count_terrain_near_tile(int x, int y, enum tile_terrain_type t)
 {
-  int rval= 0;
-  if (map_get_terrain(x, y+1)==t)   rval++;
-  if (map_get_terrain(x-1, y-1)==t) rval++;
-  if (map_get_terrain(x-1, y)==t)   rval++;
-  if (map_get_terrain(x-1, y+1)==t) rval++;
-  if (map_get_terrain(x+1, y-1)==t) rval++;
-  if (map_get_terrain(x+1, y)==t)   rval++;
-  if (map_get_terrain(x+1, y+1)==t) rval++;
-  if (map_get_terrain(x, y-1)==t)   rval++;
-  return rval;
+  int count = 0;
+
+  adjc_iterate(x, y, x1, y1) {
+    if (map_get_terrain(x1, y1) == t)
+      count++;
+  } adjc_iterate_end;
+
+  return count;
 }
 
 /***************************************************************
@@ -360,14 +352,11 @@
 ***************************************************************/
 int is_special_near_tile(int x, int y, enum tile_special_type spe)
 {
-  if (map_get_special(x-1, y+1)&spe) return 1;
-  if (map_get_special(x+1, y-1)&spe) return 1;
-  if (map_get_special(x-1, y-1)&spe) return 1;
-  if (map_get_special(x+1, y+1)&spe) return 1;
-  if (map_get_special(x, y+1)&spe)   return 1;
-  if (map_get_special(x-1, y)&spe)   return 1;
-  if (map_get_special(x+1, y)&spe)   return 1;
-  if (map_get_special(x, y-1)&spe)   return 1;
+  adjc_iterate(x, y, x1, y1) {
+    if (map_get_special(x1, y1) & spe)
+      return 1;
+  } adjc_iterate_end;
+
   return 0;
 }
 
@@ -376,16 +365,14 @@
 ***************************************************************/
 int count_special_near_tile(int x, int y, enum tile_special_type spe)
 {
-  int rval= 0;
-  if (map_get_special(x, y+1)&spe)   rval++;
-  if (map_get_special(x-1, y-1)&spe) rval++;
-  if (map_get_special(x-1, y)&spe)   rval++;
-  if (map_get_special(x-1, y+1)&spe) rval++;
-  if (map_get_special(x+1, y-1)&spe) rval++;
-  if (map_get_special(x+1, y)&spe)   rval++;
-  if (map_get_special(x+1, y+1)&spe) rval++;
-  if (map_get_special(x, y-1)&spe)   rval++;
-  return rval;
+  int count = 0;
+
+  adjc_iterate(x, y, x1, y1) {
+    if (map_get_special(x, y+1) & spe)
+      count++;
+  } adjc_iterate_end;
+
+  return count;
 }
 
 /***************************************************************
@@ -393,28 +380,24 @@
 ***************************************************************/
 int is_at_coast(int x, int y)
 {
-  if (map_get_terrain(x-1,y)==T_OCEAN)   return 1;
-  if (map_get_terrain(x,y-1)==T_OCEAN)   return 1;
-  if (map_get_terrain(x,y+1)==T_OCEAN)   return 1;
-  if (map_get_terrain(x+1,y)==T_OCEAN)   return 1;
+  cartesian_adjacent_iterate(x, y, x1, y1) {
+    if (map_get_terrain(x1, y1) == T_OCEAN)
+      return 1;
+  } cartesian_adjacent_iterate_end;
+
   return 0;
-  
 }
 
 /***************************************************************
 ...
 ***************************************************************/
-int is_coastline(int x,int y) 
+int is_coastline(int x, int y)
 {
-  /*if (map_get_terrain(x,y)!=T_OCEAN)   return 0;*/
-  if (map_get_terrain(x-1,y)!=T_OCEAN)   return 1;
-  if (map_get_terrain(x-1,y-1)!=T_OCEAN) return 1;
-  if (map_get_terrain(x-1,y+1)!=T_OCEAN) return 1;
-  if (map_get_terrain(x,y-1)!=T_OCEAN)   return 1;
-  if (map_get_terrain(x,y+1)!=T_OCEAN)   return 1;
-  if (map_get_terrain(x+1,y-1)!=T_OCEAN) return 1;
-  if (map_get_terrain(x+1,y)!=T_OCEAN)   return 1;
-  if (map_get_terrain(x+1,y+1)!=T_OCEAN) return 1;
+  adjc_iterate(x, y, x1, y1) {
+    if (map_get_terrain(x1, y1) != T_OCEAN)
+      return 1;
+  } adjc_iterate_end;
+
   return 0;
 }
 
@@ -423,11 +406,12 @@
 ***************************************************************/
 int terrain_is_clean(int x, int y)
 {
-  int x1,y1;
-  for (x1=x-3;x1<x+3;x1++)
-    for (y1=y-3;y1<y+3;y1++) 
-      if (map_get_terrain(x1,y1)!=T_GRASSLAND
-	  && map_get_terrain(x1,y1)!=T_PLAINS) return 0;
+  square_iterate(x, y, 2, x1, y1) {
+    if (map_get_terrain(x1,y1) != T_GRASSLAND
+	&& map_get_terrain(x1,y1) != T_PLAINS)
+      return 0;
+  } square_iterate_end;
+
   return 1;
 }
 
@@ -524,12 +508,11 @@
 ***************************************************************/
 int is_hut_close(int x, int y)
 {
-  int x1,y1;
-  for (y1=y-3;y1<y+4;y1++) 
-    for (x1=x-3;x1<x+4;x1++) {
-      if (map_get_tile(x1,y1)->special&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;x1<x+2;x1++)
-    for (y1=y-1;y1<=y+2;y1++) 
-      if(map_get_tile(x1,y1)->special&(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;x1<x+3;x1++)
-    for (y1=y-2;y1<=y+3;y1++) 
-      if( !( (x==x1-2||x==x1+2) && (y==y1-2||y==y1+2) ) )
-	if(map_get_terrain(x1,y1)!=T_OCEAN)
-	  return 1;
+  map_city_radius_iterate(x, y, x1, y1) {
+    if (map_get_terrain(x1, y1) != T_OCEAN)
+      return 1;
+  } map_city_radius_iterate_end;
+
   return 0;
 }
 
@@ -688,24 +671,25 @@
 ***************************************************************/
 int is_water_adjacent_to_tile(int x, int y)
 {
-  struct tile *ptile, *ptile_n, *ptile_e, *ptile_s, *ptile_w;
+  struct tile *ptile;
+
+  ptile = map_get_tile(x, y);
+  if (ptile->terrain == 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<map.ysize-3;y++) {
+  for (y=2;y<map.ysize-2;y++) {
     for (x=0;x<map.xsize;x++) {
       if (terrain_is_clean(x,y)) {
 	if (map_get_terrain(x, y) != T_RIVER &&