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: Sun, 25 Jan 2004 14:27:53 -0800
Reply-to: rt@xxxxxxxxxxx

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

> [Gregory.Berkolaiko@xxxxxxxxxxxxx - Sun Jan 25 19:48:22 2004]:

> It looks sane to me.  Minor requests:
> 
> 1. Make sure you format the lines you change.

I fixed a few that I'd mised before.

> 2. We should agree on a policy where the name of a coordinate would 
> indicate its type.  I am really aginst things like
>       native_to_map_pos(&x, &y, x, y);
> It seems the default is map coords, so native should _always_ be called 
> (xn, yn).

I've now renamed some variables, but not all.  I didn't rename most
variables that I didn't create.

> 3. I don't understand the need for the extra layer in do_in_map_pos.  Is 
> it to const the variables?

I removed the extra layer.  I also removed do_with_map_pos since it was
only used in one place.  Also I added another iso-map check to
make_passable.

jason

Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.158
diff -u -r1.158 map.c
--- common/map.c        2004/01/25 08:04:52     1.158
+++ common/map.c        2004/01/25 22:27: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))
 
 /****************************************************************************
   Return a bitfield of the specials on the tile that are infrastructure.
@@ -1112,6 +1113,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;
+}
+
 /***************************************************************
 ...
 ***************************************************************/
@@ -1162,6 +1171,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.171
diff -u -r1.171 map.h
--- common/map.h        2004/01/25 08:04:52     1.171
+++ common/map.h        2004/01/25 22:27:02
@@ -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.126
diff -u -r1.126 mapgen.c
--- server/mapgen.c     2004/01/24 23:19:27     1.126
+++ server/mapgen.c     2004/01/25 22:27:22
@@ -32,8 +32,26 @@
 
 #include "mapgen.h"
 
+/* Provide a block to convert from native to map coordinates.  For instance
+ *   do_in_map_pos(mx, my, xn, yn) {
+ *     map_set_terrain(mx, my, T_OCEAN);
+ *   } do_in_map_pos_end;
+ * Note that changing the value of the map coordinates won't change the native
+ * coordinates.
+ */
+#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);                          \
+  {                                                                         \
+
+#define do_in_map_pos_end                                                   \
+  }                                                                         \
+}
+
 /* 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 +131,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 +160,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 +196,29 @@
   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++;
   }
 }
@@ -210,10 +240,13 @@
       make_forest(x, y, hmap(x, y), 25);
     }
     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) {
-       make_forest(x, y, hmap(x, y), 25);
+      int yn = myrand(map.ysize * 2 / 10) + map.ysize * 4 / 10;
+      int xn = myrand(map.xsize);
+
+      if (nat_get_terrain(xn, yn) == T_GRASSLAND) {
+       do_in_map_pos(x, y, xn, yn) {
+         make_forest(x, y, hmap(x, y), 25);
+       } do_in_map_pos_end;
       }
     }
   } while (forests < forestsize);
@@ -266,6 +299,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 +806,25 @@
   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);
+
+    /* Iso-maps need two lines of ocean. */
+    if (myrand(2) != 0 || topo_has_flag(TF_ISO)) {
+      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 || topo_has_flag(TF_ISO)) {
+      nat_set_terrain(x, map.ysize - 2, T_OCEAN);
+    }
+    if (myrand(2) != 0) {
+      nat_set_terrain(x, map.ysize - 4, T_OCEAN);
+    }
   } 
   
 }
@@ -859,11 +906,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 +968,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;
   }
       
@@ -1368,24 +1420,27 @@
 
 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;
@@ -1399,35 +1454,38 @@
   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;
+  int map_x, map_y;
 
-  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);
+  native_to_map_pos(&map_x, &map_y, *x, *y);
+  if (!normalize_map_pos(&map_x, &map_y)) {
+    die("Invalid map operation.");
+  }
+  map_to_native_pos(x, y, map_x, map_y);
 }
 
 /**************************************************************************
@@ -1442,7 +1500,7 @@
                        enum tile_terrain_type cold1,
                        const struct gen234_state *const pstate)
 {
-  int x, y, i, k, capac;
+  int xn, yn, x, y, i, k, capac;
   long int failsafe;
 
   if (*bucket <= 0 ) return;
@@ -1459,7 +1517,8 @@
     i= 0;
 
   while (i > 0 && (failsafe--) > 0) {
-    get_random_map_position_from_state(&x, &y, pstate);
+    get_random_nat_position_from_state(&xn, &yn, pstate);
+    native_to_map_pos(&x, &y, xn, yn);
 
     if (map_get_continent(x, y) == pstate->isleindex &&
        map_get_terrain(x, y) == T_GRASSLAND) {
@@ -1475,12 +1534,13 @@
             )
           &&( !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
+         } else {
             map_set_terrain(x, y, 
(myrand(warm0_weight+warm1_weight)<warm0_weight) 
                            ? warm0 : warm1);
+         }
         } else {
           if (is_water_adjacent_to_tile(x, y) &&
              count_ocean_near_tile(x, y) < 4 &&
@@ -1499,7 +1559,7 @@
 static void fill_island_rivers(int coast, long int *bucket,
                               const struct gen234_state *const pstate)
 {
-  int x, y, i, k, capac;
+  int xn, yn, x, y, i, k, capac;
   long int failsafe;
 
   if (*bucket <= 0 ) return;
@@ -1513,7 +1573,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(&xn, &yn, pstate);
+    native_to_map_pos(&x, &y, xn, yn);
+
     if (map_get_continent(x, y) == pstate->isleindex &&
        map_get_terrain(x, y) == T_GRASSLAND) {
 
@@ -1545,14 +1607,18 @@
 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;
     if (hmap(x, y) != 0 && is_coastline(map_x, map_y))
@@ -1561,8 +1627,10 @@
                       
   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;
@@ -1573,11 +1641,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);
 
@@ -1612,17 +1682,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++;
@@ -1632,10 +1702,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--; 
           }
        }
@@ -1790,33 +1860,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;
@@ -2090,32 +2168,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 */
@@ -2167,7 +2248,8 @@
   /* 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;
     }
   }
 
@@ -2175,26 +2257,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) 
-                                                       - myrand(3*avoidedge);
-       hmap(xmax - 2, y * ymax / ydiv) 
-                         = hmap(xmax, y * ymax / ydiv) - myrand(3*avoidedge);
+       hnat(2, y * ymax / ydiv)
+         = hnat(0, 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) 
-                                                       - myrand(3*avoidedge);
-       hmap(x * xmax / xdiv, ymax - 2) 
-                         = hmap(x * xmax / xdiv, ymax) - myrand(3*avoidedge);
+       hnat(x * xmax / xdiv, 2)
+         = hnat(x * xmax / xdiv, 0) - myrand(3 * avoidedge);
+       hnat(x * xmax / xdiv, ymax - 2) 
+         = hnat(x * xmax / xdiv, ymax) - myrand(3 * avoidedge);
       }
     }
   }
@@ -2213,8 +2295,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]