Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2004:
[Freeciv-Dev] (PR#7304) iso-map support for mapgen
Home

[Freeciv-Dev] (PR#7304) iso-map support for mapgen

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#7304) iso-map support for mapgen
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 24 Jan 2004 09:22:23 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=7304 >

Adding iso-map support to mapgen is an ugly task.  Here's the patch to
do it.

We must constantly be thinking about whether the positions we're working
with are in map or native coordinates.  Mapgen must generally work with
both.

A few wrappers (suggested by Marcelo) are used for convenience:
  nat_get_terrain => returns the terrain for a position in native coords
  nat_set_terrain => blah, blah
  do_in_map_pos(map_x, map_y, nat_x, nat_y) {
    => mapgen macro to allow local conversion from native to map coords
  } do_in_map_pos_end;

It's been tested moderately with a variety of generators and topologies.
 However there are a very high number of possibilities so it's possible
some bugs remain (usually these bugs lead to an immediate segfault and
so are easy to find).

jason

Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.156
diff -u -r1.156 map.c
--- common/map.c        2004/01/22 23:52:21     1.156
+++ common/map.c        2004/01/24 17:18:02
@@ -67,6 +67,7 @@
 };
 
 #define MAP_TILE(x,y)  (map.tiles + map_pos_to_index(x, y))
+#define NAT_TILE(x, y)  (map.tiles + native_pos_to_index(x, y))
 
 /***************************************************************
 ...
@@ -1149,6 +1150,14 @@
   return MAP_TILE(x, y)->terrain;
 }
 
+/****************************************************************************
+  Return the terrain type of the given tile (in native coordinates).
+****************************************************************************/
+enum tile_terrain_type nat_get_terrain(int nat_x, int nat_y)
+{
+  return NAT_TILE(nat_x, nat_y)->terrain;
+}
+
 /***************************************************************
 ...
 ***************************************************************/
@@ -1199,6 +1208,14 @@
 void map_set_terrain(int x, int y, enum tile_terrain_type ter)
 {
   MAP_TILE(x, y)->terrain = ter;
+}
+
+/****************************************************************************
+  Set the terrain of the given tile (in native coordinates).
+****************************************************************************/
+void nat_set_terrain(int nat_x, int nat_y, enum tile_terrain_type ter)
+{
+  NAT_TILE(nat_x, nat_y)->terrain = ter;
 }
 
 /***************************************************************
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.169
diff -u -r1.169 map.h
--- common/map.h        2004/01/20 21:52:08     1.169
+++ common/map.h        2004/01/24 17:18:03
@@ -247,8 +247,10 @@
 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);
+enum tile_terrain_type nat_get_terrain(int nat_x, int nat_y);
 enum tile_special_type map_get_special(int x, int y);
 void map_set_terrain(int x, int y, enum tile_terrain_type ter);
+void nat_set_terrain(int nat_x, int nat_y, enum tile_terrain_type ter);
 void map_set_special(int x, int y, enum tile_special_type spe);
 void map_clear_special(int x, int y, enum tile_special_type spe);
 void map_clear_all_specials(int x, int y);
Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.125
diff -u -r1.125 mapgen.c
--- server/mapgen.c     2004/01/17 17:21:20     1.125
+++ server/mapgen.c     2004/01/24 17:18:03
@@ -32,8 +32,45 @@
 
 #include "mapgen.h"
 
+/* Provide a block to convert from native to map coordinates.  For instance
+ *   do_in_map_pos(mx, my, x, y) {
+ *     map_set_terrain(mx, my, T_OCEAN);
+ *   } do_in_map_pos_end;
+ */
+#define do_in_map_pos(map_x, map_y, nat_x, nat_y)                           \
+{                                                                           \
+  int _map_x, _map_y;                                                       \
+  native_to_map_pos(&_map_x, &_map_y, nat_x, nat_y);                        \
+  {                                                                         \
+    /* Changing map_x and map_y would probably be an error. */              \
+    const int map_x = _map_x, map_y = _map_y;                               \
+    {
+
+#define do_in_map_pos_end                                                   \
+    }                                                                       \
+  }                                                                         \
+}
+
+/* Provide a block to convert from native to map coordinates, and back.
+ * For instance
+ *   do_with_map_pos(mx, my, x, y) {
+ *     MAPSTEP(mx, my, DIR8_NORTH);
+ *   } do_with_map_pos_end;
+ */
+#define do_with_map_pos(map_x, map_y, nat_x, nat_y)                         \
+{                                                                           \
+  int map_x, map_y;                                                         \
+  native_to_map_pos(&map_x, &map_y, nat_x, nat_y);                          \
+  {                                                                         \
+
+#define do_with_map_pos_end(max_x, map_y, nat_x, nat_y)                     \
+  }                                                                         \
+  map_to_native_pos(&nat_x, &nat_y, map_x, map_y);                          \
+}
+
 /* Wrapper for easy access.  It's a macro so it can be a lvalue. */
 #define hmap(x, y) (height_map[map_pos_to_index(x, y)])
+#define hnat(x, y) (height_map[native_pos_to_index(x, y)])
 #define rmap(x, y) (river_map[map_pos_to_index(x, y)])
 
 static void make_huts(int number);
@@ -113,24 +150,26 @@
 
   for (y=0;y<map.ysize/10;y++) {
     for (x=0;x<map.xsize;x++) {
-      if ((hmap(x, y)+(map.ysize/10-y*25)>myrand(maxval) &&
-          map_get_terrain(x,y)==T_GRASSLAND) || y==0) { 
+      if ((hnat(x, y) + (map.ysize / 10 - y * 25) > myrand(maxval)
+          && nat_get_terrain(x, y) == T_GRASSLAND) || y == 0) { 
        if (y<2)
-         map_set_terrain(x, y, T_ARCTIC);
+         nat_set_terrain(x, y, T_ARCTIC);
        else
-         map_set_terrain(x, y, T_TUNDRA);
+         nat_set_terrain(x, y, T_TUNDRA);
          
       } 
     }
   }
   for (y=map.ysize*9/10;y<map.ysize;y++) {
     for (x=0;x<map.xsize;x++) {
-      if ((hmap(x, y)+(map.ysize/10-(map.ysize-y)*25)>myrand(maxval) &&
-          map_get_terrain(x, y)==T_GRASSLAND) || y==map.ysize-1) {
+      if (((hnat(x, y) + (map.ysize / 10 - (map.ysize - y) * 25)
+           > myrand(maxval))
+          && nat_get_terrain(x, y) == T_GRASSLAND)
+         || y == map.ysize - 1) {
        if (y>map.ysize-3)
-         map_set_terrain(x, y, T_ARCTIC);
+         nat_set_terrain(x, y, T_ARCTIC);
        else
-         map_set_terrain(x, y, T_TUNDRA);
+         nat_set_terrain(x, y, T_TUNDRA);
       }
     }
   }
@@ -140,12 +179,14 @@
      turn every land tile on the second lines that is not arctic into tundra,
      since the first lines has already been set to all arctic above. */
   for (x=0;x<map.xsize;x++) {
-    if (map_get_terrain(x, 1)!=T_ARCTIC &&
-       !is_ocean(map_get_terrain(x, 1)))
-      map_set_terrain(x, 1, T_TUNDRA);
-    if (map_get_terrain(x, map.ysize-2)!=T_ARCTIC && 
-       !is_ocean(map_get_terrain(x, map.ysize-2)))
-      map_set_terrain(x, map.ysize-2, T_TUNDRA);
+    if (nat_get_terrain(x, 1) != T_ARCTIC
+       && !is_ocean(nat_get_terrain(x, 1))) {
+      nat_set_terrain(x, 1, T_TUNDRA);
+    }
+    if (nat_get_terrain(x, map.ysize - 2) != T_ARCTIC
+       && !is_ocean(nat_get_terrain(x, map.ysize - 2))) {
+      nat_set_terrain(x, map.ysize - 2, T_TUNDRA);
+    }
   }
 }
 
@@ -174,21 +215,27 @@
   enough forest has been planted. diff is again the block function.
   if we're close to equator it will with 50% chance generate jungle instead
 **************************************************************************/
-static void make_forest(int x, int y, int height, int diff)
+static void make_forest(int map_x, int map_y, int height, int diff)
 {
-  if (y==0 || y==map.ysize-1)
+  int nat_x, nat_y;
+
+  map_to_native_pos(&nat_x, &nat_y, map_x, map_y);
+  if (has_poles && (nat_y == 0 || nat_y == map.ysize - 1)) {
     return;
+  }
 
-  if (map_get_terrain(x, y)==T_GRASSLAND) {
-    if (y>map.ysize*42/100 && y<map.ysize*58/100 && myrand(100)>50)
-      map_set_terrain(x, y, T_JUNGLE);
-    else 
-      map_set_terrain(x, y, T_FOREST);
-      if (abs(hmap(x, y)-height)<diff) {
-       cartesian_adjacent_iterate(x, y, x1, y1) {
-         if (myrand(10)>5) make_forest(x1, y1, height, diff-5);
-       } cartesian_adjacent_iterate_end;
-      }
+  if (map_get_terrain(map_x, map_y) == T_GRASSLAND) {
+    if (has_poles && nat_y > map.ysize * 42 / 100
+       && nat_y < map.ysize * 58 / 100 && myrand(100) > 50) {
+      map_set_terrain(map_x, map_y, T_JUNGLE);
+    } else {
+      map_set_terrain(map_x, map_y, T_FOREST);
+    }
+    if (abs(hmap(map_x, map_y) - height) < diff) {
+      cartesian_adjacent_iterate(map_x, map_y, x1, y1) {
+       if (myrand(10)>5) make_forest(x1, y1, height, diff-5);
+      } cartesian_adjacent_iterate_end;
+    }
     forests++;
   }
 }
@@ -212,7 +259,8 @@
     if (has_poles && myrand(100) > 75) {
       y = (myrand(map.ysize * 2 / 10)) + map.ysize * 4 / 10;
       x = myrand(map.xsize);
-      if (map_get_terrain(x, y) == T_GRASSLAND) {
+      if (nat_get_terrain(x, y) == T_GRASSLAND) {
+       native_to_map_pos(&x, &y, x, y);
        make_forest(x, y, hmap(x, y), 25);
       }
     }
@@ -266,6 +314,7 @@
       if (myrand(2) != 0) {
        y = map.ysize - 1 - y;
       }
+      native_to_map_pos(&x, &y, x, y);
     } else {
       /* If there are no poles we can pick any location to be a desert. */
       rand_map_pos(&x, &y);
@@ -772,12 +821,24 @@
   int x;
   
   for (x=0;x<map.xsize;x++) {
-    map_set_terrain(x, 2, T_OCEAN);
-    if (myrand(100)>50) map_set_terrain(x,1,T_OCEAN);
-    if (myrand(100)>50) map_set_terrain(x,3,T_OCEAN);
-    map_set_terrain(x, map.ysize-3, T_OCEAN);
-    if (myrand(100)>50) map_set_terrain(x,map.ysize-2,T_OCEAN);
-    if (myrand(100)>50) map_set_terrain(x,map.ysize-4,T_OCEAN);
+    nat_set_terrain(x, 2, T_OCEAN);
+
+    if (myrand(2) != 0) {
+      nat_set_terrain(x, 1, T_OCEAN);
+    }
+
+    if (myrand(2) != 0) {
+      nat_set_terrain(x, 3, T_OCEAN);
+    }
+
+    nat_set_terrain(x, map.ysize - 3, T_OCEAN);
+
+    if (myrand(2) != 0) {
+      nat_set_terrain(x, map.ysize - 2, T_OCEAN);
+    }
+    if (myrand(2) != 0) {
+      nat_set_terrain(x, map.ysize - 4, T_OCEAN);
+    }
   } 
   
 }
@@ -859,11 +920,11 @@
     return FALSE;
   }
 
-  cartesian_adjacent_iterate(x, y, x1, y1) {
+  adjc_iterate(x, y, x1, y1) {
     if (!is_ocean(map_get_terrain(x1, y1))) {
       return FALSE;
     }
-  } cartesian_adjacent_iterate_end;
+  } adjc_iterate_end;
 
   return TRUE;
 }
@@ -921,8 +982,13 @@
   } whole_map_iterate_end;
 
   if (map.generator != 0 && has_poles) {
-    assign_continent_flood(0, 0, 1);
-    assign_continent_flood(0, map.ysize-1, 2);
+    do_in_map_pos(x, y, 0, 0) {
+      assign_continent_flood(x, y, 1);
+    } do_in_map_pos_end;
+
+    do_in_map_pos(x, y, 0, map.ysize - 1) {
+      assign_continent_flood(x, y, 2);
+    } do_in_map_pos_end;
     isle = 3;
   }
       
@@ -1327,24 +1393,26 @@
 
 static void add_specials(int prob)
 {
-  int x,y;
+  int xn,yn;
   enum tile_terrain_type ttype;
-  for (y=1;y<map.ysize-1;y++) {
-    for (x=0;x<map.xsize; x++) {
-      ttype = map_get_terrain(x, y);
-      if ((is_ocean(ttype) && is_coastline(x,y)) || !is_ocean(ttype)) {
-       if (myrand(1000)<prob) {
-         if (!is_special_close(x,y)) {
-           if (tile_types[ttype].special_1_name[0] != '\0' &&
-               (tile_types[ttype].special_2_name[0] == '\0' || 
(myrand(100)<50))) {
-             map_set_special(x, y, S_SPECIAL_1);
-           }
-           else if (tile_types[ttype].special_2_name[0] != '\0') {
-             map_set_special(x, y, S_SPECIAL_2);
+  for (yn=1;yn<map.ysize-1;yn++) {
+    for (xn=0;xn<map.xsize; xn++) {
+      do_in_map_pos(x, y, xn, yn) {
+       ttype = map_get_terrain(x, y);
+       if ((is_ocean(ttype) && is_coastline(x,y)) || !is_ocean(ttype)) {
+         if (myrand(1000) < prob) {
+           if (!is_special_close(x, y)) {
+             if (tile_types[ttype].special_1_name[0] != '\0'
+                 && (tile_types[ttype].special_2_name[0] == '\0'
+                     || (myrand(100) < 50))) {
+               map_set_special(x, y, S_SPECIAL_1);
+             } else if (tile_types[ttype].special_2_name[0] != '\0') {
+               map_set_special(x, y, S_SPECIAL_2);
+             }
            }
          }
        }
-      }
+      } do_in_map_pos_end;
     }
   }
   map.have_specials = TRUE;
@@ -1358,35 +1426,36 @@
   long int totalmass;
 };
 
-static bool is_cold(int x, int y){
+static bool map_pos_is_cold(int x, int y)
+{
+  if (!has_poles) {
+    return FALSE;
+  }
+
+  map_to_native_pos(&x, &y, x, y);
   return ( y * 5 < map.ysize || y * 5 > map.ysize * 4 );
 }
 
 /**************************************************************************
 Returns a random position in the rectangle denoted by the given state.
 **************************************************************************/
-static void get_random_map_position_from_state(int *x, int *y,
+static void get_random_nat_position_from_state(int *x, int *y,
                                               const struct gen234_state
                                               *const pstate)
 {
-  bool is_real;
-
-  *x = pstate->w;
-  *y = pstate->n;
-
-  is_real = normalize_map_pos(x, y);
-  assert(is_real);
-
   assert((pstate->e - pstate->w) > 0);
   assert((pstate->e - pstate->w) < map.xsize);
   assert((pstate->s - pstate->n) > 0);
   assert((pstate->s - pstate->n) < map.ysize);
 
-  *x += myrand(pstate->e - pstate->w);
-  *y += myrand(pstate->s - pstate->n);
+  *x = pstate->w + myrand(pstate->e - pstate->w);
+  *y = pstate->n + myrand(pstate->s - pstate->n);
 
-  is_real = normalize_map_pos(x, y);
-  assert(is_real);
+  do_with_map_pos(map_x, map_y, *x, *y) {
+    if (!normalize_map_pos(&map_x, &map_y)) {
+      die("Invalid map operation.");
+    }
+  } do_with_map_pos_end(map_x, map_y, *x, *y);
 }
 
 /**************************************************************************
@@ -1418,7 +1487,8 @@
     i= 0;
 
   while (i > 0 && (failsafe--) > 0) {
-    get_random_map_position_from_state(&x, &y, pstate);
+    get_random_nat_position_from_state(&x, &y, pstate);
+    native_to_map_pos(&x, &y, x, y);
 
     if (map_get_continent(x, y) == pstate->isleindex &&
        map_get_terrain(x, y) == T_GRASSLAND) {
@@ -1434,7 +1504,7 @@
             )
           &&( !is_at_coast(x, y) || myrand(100) < coast )) {
         if (cold1 != T_RIVER) {
-          if ( is_cold(x,y) )
+          if (map_pos_is_cold(x, y))
             map_set_terrain(x, y, 
(myrand(cold0_weight+cold1_weight)<cold0_weight) 
                            ? cold0 : cold1);
           else
@@ -1472,7 +1542,9 @@
   if(failsafe<0){ failsafe= -failsafe; }
 
   while (i > 0 && (failsafe--) > 0) {
-    get_random_map_position_from_state(&x, &y, pstate);
+    get_random_nat_position_from_state(&x, &y, pstate);
+    native_to_map_pos(&x, &y, x, y);
+
     if (map_get_continent(x, y) == pstate->isleindex &&
        map_get_terrain(x, y) == T_GRASSLAND) {
 
@@ -1504,13 +1576,17 @@
 static bool place_island(struct gen234_state *pstate)
 {
   int x, y, xo, yo, i=0;
+
   rand_map_pos(&xo, &yo);
+  map_to_native_pos(&xo, &yo, xo, yo);
 
   /* this helps a lot for maps with high landmass */
   for (y = pstate->n, x = pstate->w; y < pstate->s && x < pstate->e;
        y++, x++) {
-    int map_x = x + xo - pstate->w;
-    int map_y = y + yo - pstate->n;
+    int map_x, map_y;
+
+    native_to_map_pos(&map_x, &map_y,
+                     x + xo - pstate->w, y + yo - pstate->n);
 
     if (!normalize_map_pos(&map_x, &map_y))
       return FALSE;
@@ -1520,9 +1596,11 @@
                       
   for (y = pstate->n; y < pstate->s; y++) {
     for (x = pstate->w; x < pstate->e; x++) {
-      int map_x = x + xo - pstate->w;
-      int map_y = y + yo - pstate->n;
+      int map_x, map_y;
 
+      native_to_map_pos(&map_x, &map_y,
+                       x + xo - pstate->w, y + yo - pstate->n);
+
       if (!normalize_map_pos(&map_x, &map_y))
        return FALSE;
       if (hmap(x, y) != 0 && is_coastline(map_x, map_y))
@@ -1532,11 +1610,13 @@
 
   for (y = pstate->n; y < pstate->s; y++) {
     for (x = pstate->w; x < pstate->e; x++) {
-      if (hmap(x, y) != 0) {
-       int map_x = x + xo - pstate->w;
-       int map_y = y + yo - pstate->n;
+      if (hnat(x, y) != 0) {
+       int map_x, map_y;
        bool is_real;
 
+       native_to_map_pos(&map_x, &map_y,
+                         x + xo - pstate->w, y + yo - pstate->n);
+
        is_real = normalize_map_pos(&map_x, &map_y);
        assert(is_real);
 
@@ -1571,17 +1651,17 @@
   memset(height_map, '\0', sizeof(int) * map.xsize * map.ysize);
   y = map.ysize / 2;
   x = map.xsize / 2;
-  hmap(x, y) = 1;
+  hnat(x, y) = 1;
   pstate->n = y - 1;
   pstate->w = x - 1;
   pstate->s = y + 2;
   pstate->e = x + 2;
   i = islemass - 1;
   while (i > 0 && tries-->0) {
-    get_random_map_position_from_state(&x, &y, pstate);
-    if (hmap(x, y) == 0 && (hmap(x + 1, y) != 0 || hmap(x - 1, y) != 0 ||
-                           hmap(x, y + 1) != 0 || hmap(x, y - 1) != 0)) {
-      hmap(x, y) = 1;
+    get_random_nat_position_from_state(&x, &y, pstate);
+    if (hnat(x, y) == 0 && (hnat(x + 1, y) != 0 || hnat(x - 1, y) != 0 ||
+                           hnat(x, y + 1) != 0 || hnat(x, y - 1) != 0)) {
+      hnat(x, y) = 1;
       i--;
       if (y >= pstate->s - 1 && pstate->s < map.ysize - 2) pstate->s++;
       if (x >= pstate->e - 1 && pstate->e < map.xsize - 2) pstate->e++;
@@ -1591,10 +1671,10 @@
     if (i < islemass / 10) {
       for (y = pstate->n; y < pstate->s; y++) {
        for (x = pstate->w; x < pstate->e; x++) {
-         if (hmap(x, y) == 0 && i > 0
-             && (hmap(x + 1, y) != 0 && hmap(x - 1, y) != 0
-                 && hmap(x, y + 1) != 0 && hmap(x, y - 1) != 0)) {
-           hmap(x, y) = 1;
+         if (hnat(x, y) == 0 && i > 0
+             && (hnat(x + 1, y) != 0 && hnat(x - 1, y) != 0
+                 && hnat(x, y + 1) != 0 && hnat(x, y - 1) != 0)) {
+           hnat(x, y) = 1;
             i--; 
           }
        }
@@ -1749,33 +1829,41 @@
 **************************************************************************/
 static void initworld(struct gen234_state *pstate)
 {
-  int x, y;
+  int xn, yn;
   
   height_map = fc_malloc(sizeof(int) * map.ysize * map.xsize);
   islands = fc_malloc((MAP_NCONT+1)*sizeof(struct isledata));
   
-  for (y = 0 ; y < map.ysize ; y++) 
-    for (x = 0 ; x < map.xsize ; x++) {
-      map_set_terrain(x, y, T_OCEAN);
-      map_set_continent(x, y, 0);
-      map_clear_all_specials(x, y);
-      map_set_owner(x, y, NULL);
+  for (yn = 0 ; yn < map.ysize ; yn++) 
+    for (xn = 0 ; xn < map.xsize ; xn++) {
+      do_in_map_pos(x, y, xn, yn) {
+       map_set_terrain(x, y, T_OCEAN);
+       map_set_continent(x, y, 0);
+       map_clear_all_specials(x, y);
+       map_set_owner(x, y, NULL);
+      } do_in_map_pos_end;
     }
   if (has_poles) {
-    for (x = 0; x < map.xsize; x++) {
-      map_set_terrain(x, 0, myrand(9) > 0 ? T_ARCTIC : T_TUNDRA);
-      map_set_continent(x, 0, 1);
+    for (xn = 0; xn < map.xsize; xn++) {
+      do_in_map_pos(x, y, xn, 0) {
+       map_set_terrain(x, y, myrand(9) > 0 ? T_ARCTIC : T_TUNDRA);
+       map_set_continent(x, y, 1);
+      } do_in_map_pos_end;
       if (myrand(9) == 0) {
-       map_set_terrain(x, 1, myrand(9) > 0 ? T_TUNDRA : T_ARCTIC);
-       map_set_continent(x, 1, 1);
-      }
-      map_set_terrain(x, map.ysize - 1,
-                     myrand(9) > 0 ? T_ARCTIC : T_TUNDRA);
-      map_set_continent(x, map.ysize - 1, 2);
+       do_in_map_pos(x, y, xn, 1) {
+         map_set_terrain(x, y, myrand(9) > 0 ? T_TUNDRA : T_ARCTIC);
+         map_set_continent(x, y, 1);
+       } do_in_map_pos_end;
+      }
+      do_in_map_pos(x, y, xn, map.ysize - 1) {
+       map_set_terrain(x, y, myrand(9) > 0 ? T_ARCTIC : T_TUNDRA);
+       map_set_continent(x, y, 2);
+      } do_in_map_pos_end;
       if (myrand(9) == 0) {
-       map_set_terrain(x, map.ysize - 2,
-                       myrand(9) > 0 ? T_TUNDRA : T_ARCTIC);
-       map_set_continent(x, map.ysize - 2, 2);
+       do_in_map_pos(x, y, xn, map.ysize - 2) {
+         map_set_terrain(x, y, myrand(9) > 0 ? T_TUNDRA : T_ARCTIC);
+         map_set_continent(x, y, 2);
+       } do_in_map_pos_end;
       }
     }
     map.num_continents = 2;
@@ -2049,32 +2137,35 @@
   if (y1 == map.ysize)
     y1wrap = 0;
 
-  val[0][0] = hmap(x0, y0);
-  val[0][1] = hmap(x0, y1wrap);
-  val[1][0] = hmap(x1wrap, y0);
-  val[1][1] = hmap(x1wrap, y1wrap);
+  val[0][0] = hnat(x0, y0);
+  val[0][1] = hnat(x0, y1wrap);
+  val[1][0] = hnat(x1wrap, y0);
+  val[1][1] = hnat(x1wrap, y1wrap);
 
   /* set midpoints of sides to avg of side's vertices plus a random factor */
   /* unset points are zero, don't reset if set */
-  if (hmap((x0 + x1)/2, y0) == 0) {
-    hmap((x0 + x1)/2, y0) = (val[0][0] + val[1][0])/2 + myrand(step) - step/2;
-  }
-  if (hmap((x0 + x1)/2, y1wrap) == 0) {
-    hmap((x0 + x1)/2, y1wrap) = (val[0][1] + val[1][1])/2 
-      + myrand(step)- step/2;
-  }
-  if (hmap(x0, (y0 + y1)/2) == 0) {
-    hmap(x0, (y0 + y1)/2) = (val[0][0] + val[0][1])/2 + myrand(step) - step/2;
-  }
-  if (hmap(x1wrap, (y0 + y1)/2) == 0) {
-    hmap(x1wrap, (y0 + y1)/2) = (val[1][0] + val[1][1])/2 
-      + myrand(step) - step/2;
+  if (hnat((x0 + x1) / 2, y0) == 0) {
+    hnat((x0 + x1) / 2, y0)
+      = (val[0][0] + val[1][0]) / 2 + myrand(step) - step / 2;
+  }
+  if (hnat((x0 + x1) /2, y1wrap) == 0) {
+    hnat((x0 + x1) / 2, y1wrap)
+      = (val[0][1] + val[1][1]) / 2 + myrand(step) - step / 2;
+  }
+  if (hnat(x0, (y0 + y1) / 2) == 0) {
+    hnat(x0, (y0 + y1) / 2)
+      = (val[0][0] + val[0][1]) / 2 + myrand(step) - step / 2;
+  }
+  if (hnat(x1wrap, (y0 + y1) / 2) == 0) {
+    hnat(x1wrap, (y0 + y1) / 2)
+      = (val[1][0] + val[1][1]) / 2 + myrand(step) - step / 2;
   }
 
   /* set middle to average of midpoints plus a random factor, if not set */
-  if (hmap((x0 + x1)/2, (y0 + y1)/2) == 0) {
-    hmap((x0 + x1)/2, (y0 + y1)/2) = (val[0][0] + val[0][1] + val[1][0] 
-                                     + val[1][1])/4 + myrand(step) - step/2;
+  if (hnat((x0 + x1) / 2, (y0 + y1) / 2) == 0) {
+    hnat((x0 + x1) / 2, (y0 + y1) / 2)
+      = (val[0][0] + val[0][1] + val[1][0] + val[1][1]) / 4
+        + myrand(step) - step / 2;
   }
 
   /* now call recursively on the four subrectangles */
@@ -2126,7 +2217,7 @@
   /* set initial points */
   for (x = 0; x < xdiv2; x++) {
     for (y = 0; y < ydiv2; y++) {
-      hmap(x * xmax / xdiv, y * ymax / ydiv) =  myrand(2*step) - (2*step)/2;
+      hnat(x * xmax / xdiv, y * ymax / ydiv) =  myrand(2*step) - (2*step)/2;
     }
   }
 
@@ -2134,26 +2225,26 @@
      even harder to avoid the edges naturally if separatepoles is true */
   if (xnowrap) {
     for (y = 0; y < ydiv2; y++) {
-      hmap(0, y * ymax / ydiv) -= avoidedge;
-      hmap(xmax, y * ymax / ydiv) -= avoidedge;
+      hnat(0, y * ymax / ydiv) -= avoidedge;
+      hnat(xmax, y * ymax / ydiv) -= avoidedge;
       if (map.separatepoles && has_poles) {
-       hmap(2, y * ymax / ydiv) = hmap(0, y * ymax / ydiv) 
+       hnat(2, y * ymax / ydiv) = hnat(0, y * ymax / ydiv) 
                                                        - myrand(3*avoidedge);
-       hmap(xmax - 2, y * ymax / ydiv) 
-                         = hmap(xmax, y * ymax / ydiv) - myrand(3*avoidedge);
+       hnat(xmax - 2, y * ymax / ydiv) 
+                         = hnat(xmax, y * ymax / ydiv) - myrand(3*avoidedge);
       }
     }
   }
 
   if (ynowrap) {
     for (x = 0; x < xdiv2; x++) {
-      hmap(x * xmax / xdiv, 0) -= avoidedge;
-      hmap(x * xmax / xdiv, ymax) -= avoidedge;
+      hnat(x * xmax / xdiv, 0) -= avoidedge;
+      hnat(x * xmax / xdiv, ymax) -= avoidedge;
       if (map.separatepoles && has_poles) {
-       hmap(x * xmax / xdiv, 2) = hmap(x * xmax / xdiv, 0) 
+       hnat(x * xmax / xdiv, 2) = hnat(x * xmax / xdiv, 0) 
                                                        - myrand(3*avoidedge);
-       hmap(x * xmax / xdiv, ymax - 2) 
-                         = hmap(x * xmax / xdiv, ymax) - myrand(3*avoidedge);
+       hnat(x * xmax / xdiv, ymax - 2) 
+                         = hnat(x * xmax / xdiv, ymax) - myrand(3*avoidedge);
       }
     }
   }
@@ -2172,8 +2263,8 @@
   } whole_map_iterate_end;
 
   /* and calibrate maxval and minval */
-  maxval = hmap(0, 0);
-  minval = hmap(0, 0);
+  maxval = hnat(0, 0);
+  minval = hnat(0, 0);
   whole_map_iterate(x, y) {
     maxval = MAX(maxval, hmap(x, y));
     minval = MIN(minval, hmap(x, y));

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#7304) iso-map support for mapgen, Jason Short <=