Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] Re: (PR#8624) New clima function to best handle terrain pl
Home

[Freeciv-Dev] Re: (PR#8624) New clima function to best handle terrain pl

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#8624) New clima function to best handle terrain place, used to place poles.
From: "Marcelo Burda" <mburda@xxxxxxxxx>
Date: Sat, 22 May 2004 05:56:51 -0700
Reply-to: rt@xxxxxxxxxxx

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

Le mer 12/05/2004 à 05:32, Jason Short a écrit :
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=8624 >
> 
> > [mburda - Tue May 11 21:02:57 2004]:
> 
> > this file is in debug status.
> 
> I guess that means it's not ready?
now yes
> 
> IS_SINGULAR_MAP_POS is a function, so it should be is_singular_map_pos
> (this is true of is_border_map_pos too, but that's for another day).
> 
ok
> Also I think some of this code should use "natural" positions once they
> are available.
? i use it.
> 
> jason

continent number 1 and 2 still reserved to poles but this is no more
needed, this was a hack to see poles wen searching start pos, this was
easy solved with clima function, too cool places are simply no good
start pos.
reserve this force to create a separate fonction to set poles continents
numbers, i make this function very nice but this is realy no needed,
best i we no more reserve the 1 and or 2 for the poles continents.

i make a big number of tuning but probably there are some tuning to be
donne, i propose to get this patch and then tune one at one all
generators.

but first i need know if you autorize me to no more reserve the poles
numbers. this way i can delete all unided code
Marcelo
-- 
 . /  .     '    ,    .      (*)   '        `     '      `    .    
  |    ,  |   `     ,     .      ,   '  Marcelo Julián Burda      .
 /  '     \     `     \@_     '      .        '      `        '    
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

diff -ruN -Xfreeciv/diff_ignore freeciv/common/map.c freeciv_/common/map.c
--- freeciv/common/map.c        2004-05-21 10:54:00.000000000 +0200
+++ freeciv_/common/map.c       2004-05-22 14:41:59.000000000 +0200
@@ -1547,3 +1547,4 @@
   map_distance_vector(&diff_x, &diff_y, start_x, start_y, end_x, end_y);
   return (diff_x == 0) || (diff_y == 0);
 }
+
diff -ruN -Xfreeciv/diff_ignore freeciv/common/map.h freeciv_/common/map.h
--- freeciv/common/map.h        2004-05-21 10:54:00.000000000 +0200
+++ freeciv_/common/map.h       2004-05-22 14:41:59.000000000 +0200
@@ -734,4 +734,26 @@
   } do_in_native_pos_end;
 }
 
+/****************************************************************************
+  A "SINGULAR position" is any map position that have a redused number of
+ tiles in the radius of dist 
+ arg need to be normal
+****************************************************************************/
+static inline bool is_singular_map_pos(int map_x, int map_y, int dist)
+{
+  CHECK_MAP_POS(map_x, map_y);
+  do_in_native_pos(nat_x, nat_y, map_x, map_y) {
+    /* HACK: An iso-map compresses the value in the X direction but not in
+     * the Y direction.  Hence (x+1,y) is 1 tile away while (x,y+2) is also
+     * one tile away. */
+    int xdist = dist, ydist = topo_has_flag(TF_ISO) ? (2 * dist) : dist;
+
+    return  (!topo_has_flag(TF_WRAPX) 
+            && (nat_x < xdist || nat_x >= map.xsize - xdist))
+           || 
+           (!topo_has_flag(TF_WRAPY)
+            && (nat_y < ydist || nat_y >= map.ysize - ydist));
+  } do_in_native_pos_end;
+}
+
 #endif  /* FC__MAP_H */
diff -ruN -Xfreeciv/diff_ignore freeciv/server/mapgen.c freeciv_/server/mapgen.c
--- freeciv/server/mapgen.c     2004-05-21 10:54:02.000000000 +0200
+++ freeciv_/server/mapgen.c    2004-05-22 14:38:27.000000000 +0200
@@ -77,7 +77,7 @@
 static int *height_map;
 static int maxval=0;
 static int forests=0;
-static bool has_poles;
+static bool has_poles = TRUE;
 
 struct isledata {
   int goodies;
@@ -88,6 +88,117 @@
 /* this is used for generator>1 */
 #define MAP_NCONT 255
 
+/* **********************************************************************
+ * return 0 for the coolest map_x,map_y tile of the map
+ * and 100 for the hotest one, this is proportional to area climatic zones
+ * see doc/HACKING#Poles                                            [mburda]
+ *************************************************************************/ 
+
+static int map_clima(int map_x, int map_y)
+{
+  int x_2, y_2;
+  double x, y;
+  
+  do_in_natural_pos(ntl_x, ntl_y, map_x, map_y) {
+
+    /*
+     * Is a FLAT (unwraped) map 
+     * I asume this is a partial map of Earth, at top i place a polar zone 
+     * at bottom the ecuator one. this is a partial Earth map.
+     * flat as only one pole!
+     */
+    if (!topo_has_flag(TF_WRAPX) && !topo_has_flag(TF_WRAPY)) {
+      return 100 * ntl_y / (NATURAL_HEIGHT - 1);
+    }
+
+    /*
+     * Is a global map,
+     * firt we cut all symeties of the map to make easy get clima
+     * the map us cuted in 4 1/4
+     */
+
+    x_2 = NATURAL_WIDTH / 2 - 1 + NATURAL_WIDTH % 2;
+    y_2 = NATURAL_HEIGHT / 2 - 1 + NATURAL_HEIGHT % 2;
+
+    x = (double)( ntl_x > x_2 ? NATURAL_WIDTH  - 1 - ntl_x : ntl_x) / 
(double)x_2;
+    y = (double)( ntl_y > y_2 ? NATURAL_HEIGHT - 1 - ntl_y : ntl_y) / 
(double)y_2;
+  } do_in_natural_pos_end;
+  /*
+   * classic topo 
+   * the polar zone are at N and S
+   */
+  if (topo_has_flag(TF_WRAPX) && !topo_has_flag(TF_WRAPY)) {
+    return 100 * y;
+  }
+  
+  /* Uranus topo */
+  /* poles at E and W */
+  if (!topo_has_flag(TF_WRAPX) && topo_has_flag(TF_WRAPY)) {
+    return 100 * x;
+  }
+
+  /*
+   * torus topo
+   * i make 2 circle polar zone (2 poles)
+   * Equatorial zone as the shape of a square in the map
+   */
+  
+  /* poles (N,S) and equator ( /,\) shape
+     ........
+     :N /\ N:
+     : /  \ :
+     :/ SS \:
+     :\ SS /: .....
+     : \  / :
+     :N \/ N:
+     ''''''''
+  */
+  
+  if (x + y > 1) {
+      x = 1 - x;
+      y = 1 - y;
+  }
+  return 150 * (x * x * y + x * y * y) - 50 * (x * x * x + y * y * y) +
+      150 * (x * x + y * y);
+  
+}
+
+/* **************************************************************
+ * return random map coordinates where clima is in selected range
+ * return false if pos is not finded in a all temperate planet
+ * a false value can be used to make less of this type of terrains
+ * or to make a call of rand_map_pos
+ * **************************************************************/
+static bool rand_clima_map_pos( int *map_x, int *map_y, int T_min, int T_max)
+{
+  int T;
+  /* no poles, all temperate */
+  if(!has_poles) {
+    const int T_ = abs((T_max + T_min) - 100 ); /* far temperate factor */
+    rand_map_pos( map_x, map_y);
+    return T_ < myrand(100);
+  }
+  for(;;) {
+    rand_map_pos( map_x, map_y);
+    T = map_clima( *map_x, *map_y);
+    if( T >= T_min && T <= T_max ) {
+      return TRUE;
+    } 
+  }
+}
+
+
+/* ************************************************************
+ * Return TRUE if the map in a radius of 2 is  singular 
+ * This need to be best defined in future topologies works
+ * This def is ok for generalised topologies
+ * ************************************************************/
+
+static bool near_singularity(int map_x, int map_y)
+{
+  return is_singular_map_pos(map_x, map_y, 2) ;
+}
+
 /**************************************************************************
   make_mountains() will convert all squares that are higher than thill to
   mountains and hills. Notice that thill will be adjusted according to
@@ -123,53 +234,36 @@
 
 /**************************************************************************
  add arctic and tundra squares in the arctic zone. 
- (that is the top 10%, and low 10% of the map)
+ (that is the coolest 10% of the map)
+ if make_polar(TRUE) we add some tundra
 **************************************************************************/
-static void make_polar(void)
+static void make_polar(bool addtundra )
 {
-  int xn, yn;
-
-  for (yn = 0; yn < map.ysize / 10; yn++) {
-    for (xn = 0; xn < map.xsize; xn++) {
-      if ((hnat(xn, yn) + (map.ysize / 10 - yn * 25) > myrand(maxval)
-          && nat_get_terrain(xn, yn) == T_GRASSLAND) || yn == 0) { 
-       if (yn < 2) {
-         nat_set_terrain(xn, yn, T_ARCTIC);
-       } else {
-         nat_set_terrain(xn, yn, T_TUNDRA);
-       }
-      } 
-    }
-  }
-  for (yn = map.ysize * 9 / 10; yn < map.ysize; yn++) {
-    for (xn = 0; xn < map.xsize; xn++) {
-      if (((hnat(xn, yn) + (map.ysize / 10 - (map.ysize - yn - 1) * 25)
-           > myrand(maxval))
-          && nat_get_terrain(xn, yn) == T_GRASSLAND)
-         || yn == map.ysize - 1) {
-       if (yn > map.ysize - 3) {
-         nat_set_terrain(xn, yn, T_ARCTIC);
-       } else {
-         nat_set_terrain(xn, yn, T_TUNDRA);
+  int T;
+  struct tile *ptile;
+  whole_map_iterate(map_x, map_y) {
+    T = map_clima(map_x, map_y);       /* temperature parameter */
+    ptile = map_get_tile(map_x, map_y);
+    if (T < 5) {               /* get the 10% coldest part of the map */
+      ptile->terrain = T_ARCTIC;
+    } else if (T <= 8) {
+      if (ptile->terrain == T_OCEAN) {
+       ptile->terrain = T_ARCTIC;
+      } else {
+       ptile->terrain = T_TUNDRA;
+      }
+    } else if (T <= 10) {
+      if (ptile->terrain == T_OCEAN) {
+       if (myrand(10) > 5) {
+         ptile->terrain = T_ARCTIC;
+       } else if (addtundra && myrand(10) > 4) {
+         ptile->terrain = T_TUNDRA;
        }
+      } else if (myrand(10) > 5) {
+       ptile->terrain = T_TUNDRA;
       }
     }
-  }
-
-  /* only arctic and tundra allowed at the poles (first and last two lines,
-     as defined in make_passable() ), to be consistent with generator>1. 
-     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 (xn = 0; xn < map.xsize; xn++) {
-    if (nat_get_terrain(xn, 1) != T_ARCTIC
-       && !is_ocean(nat_get_terrain(xn, 1))) {
-      nat_set_terrain(xn, 1, T_TUNDRA);
-    }
-    if (nat_get_terrain(xn, map.ysize - 2) != T_ARCTIC
-       && !is_ocean(nat_get_terrain(xn, map.ysize - 2))) {
-      nat_set_terrain(xn, map.ysize - 2, T_TUNDRA);
-    }
-  }
+  } whole_map_iterate_end;
 }
 
 /**************************************************************************
@@ -199,16 +293,12 @@
 **************************************************************************/
 static void make_forest(int map_x, int map_y, int height, int diff)
 {
-  int nat_x, nat_y;
+  int nat_x, nat_y,T;
 
   map_to_native_pos(&nat_x, &nat_y, map_x, map_y);
-  if (has_poles && (nat_y == 0 || nat_y == map.ysize - 1)) {
-    return;
-  }
-
+  T = map_clima(map_x, map_y);
   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) {
+    if (T > 42         && T <  58  && myrand(100) > 50) {
       map_set_terrain(map_x, map_y, T_JUNGLE);
     } else {
       map_set_terrain(map_x, map_y, T_FOREST);
@@ -236,18 +326,22 @@
   forests = 0;
 
   do {
-    rand_map_pos(&x, &y);
-    if (map_get_terrain(x, y) == T_GRASSLAND) {
-      make_forest(x, y, hmap(x, y), 25);
-    }
-    if (has_poles && myrand(100) > 75) {
-      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) {
+    if( rand_clima_map_pos(&x, &y, 10, 90)) {
+      if (has_poles && myrand(100) > 75) {
+       if (map_get_terrain(x, y) == T_GRASSLAND) {
          make_forest(x, y, hmap(x, y), 25);
-       } do_in_map_pos_end;
+       }
+      }
+    } else { 
+      /* false inc of count for all temperate planets 
+       * for a 10 - 90 this never executed*/
+      forests++;
+    }
+    if( rand_clima_map_pos(&x, &y, 20, 40) && myrand(100) > 75) {
+      if (has_poles && myrand(100) > 75) {
+       if (map_get_terrain(x, y) == T_GRASSLAND) {
+         make_forest(x, y, hmap(x, y), 25);
+       }
       }
     }
   } while (forests < forestsize);
@@ -291,18 +385,11 @@
   while (i > 0 && j < 100 * map.deserts) {
     j++;
 
-    if (has_poles) {
-      /* Choose a random coordinate between 20 and 30 degrees north/south
-       * (deserts tend to be between 15 and 35; make_desert will expand
-       * them). */
-      int xn = myrand(map.xsize);
-      int yn = myrand(map.ysize * 10 / 180) + map.ysize * 60 / 180;
+    /* Choose a random coordinate between 20 and 30 degrees north/south
+     * (deserts tend to be between 15 and 35; make_desert will expand
+     * them). */
 
-      if (myrand(2) != 0) {
-       yn = map.ysize - 1 - yn;
-      }
-      native_to_map_pos(&x, &y, xn, yn);
-    } else {
+    if(!rand_clima_map_pos(&x, &y, 67, 78)){
       /* If there are no poles we can pick any location to be a desert. */
       rand_map_pos(&x, &y);
     }
@@ -561,8 +648,10 @@
            x, y);
 
     /* Test if the river is done. */
-    if (adjacent_river_tiles4(x, y) != 0||
-       adjacent_ocean_tiles4(x, y) != 0) {
+    if (adjacent_river_tiles4(x, y) != 0 ||
+       adjacent_ocean_tiles4(x, y) != 0 ||
+        (map_get_terrain(x, y) == T_ARCTIC 
+         && map_clima(x, y) < 8)) { /*rivers end at poles */
       freelog(LOG_DEBUG,
              "The river ended at (%d, %d).\n", x, y);
       return TRUE;
@@ -678,7 +767,7 @@
      * 1000 rather than the current 100 */
     10 *
     /* The size of the map (poles don't count). */
-    (map_num_tiles() - 2 * map.xsize) *
+    map_num_tiles() * (has_poles ? 0.9 : 1.0) *
     /* Rivers need to be on land only. */
     map.landpercent /
     /* Adjustment value. Tested by me. Gives no rivers with 'set
@@ -799,40 +888,6 @@
   } whole_map_iterate_end;
 }
 
-/**************************************************************************
-  we want the map to be sailable east-west at least at north and south pole 
-  and make it a bit jagged at the edge as well.
-  So this procedure converts the second line and the second last line to
-  ocean, and 50% of the 3rd and 3rd last line to ocean. 
-**************************************************************************/
-static void make_passable(void)
-{
-  int x;
-  
-  for (x=0;x<map.xsize;x++) {
-    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);
-    }
-  } 
-  
-}
-
 /****************************************************************************
   Return TRUE if the terrain at the given map position is "clean".  This
   means that all the terrain for 2 squares around it is either grassland or
@@ -901,16 +956,14 @@
       tres*=9;
     tres/=10;
   } while (abs(total-count)> maxval/40);
-  if (map.separatepoles && has_poles) {
-    make_passable();
-  }
+
   make_mountains(maxval*8/10);
   make_forests();
   make_swamps();
   make_deserts();
   make_plains();
   if (has_poles) {
-    make_polar();
+    make_polar(map.separatepoles); /* add tundra if pole is separate */
   }
   make_fair();
   make_rivers();
@@ -974,6 +1027,37 @@
 }
 
 /**************************************************************************
+ Assign continent numbers to Poles in gen 2,3 or 4
+ (poles are separates island)
+ Numbers 1 and 2 are reserved for polar continents if
+ map.generator != 0; otherwise are not special.
+ Also sets map.num_continents (note 0 is ocean)
+ See the doc/HACKING#Poles
+**************************************************************************/
+
+static void assign_poles_numbers(void)
+{
+  /* Default poles, cilinder(classic or uranus) topology */
+  int map_x, map_y, num_poles = 2;
+  
+  /* FLAT TOPOLOGIE (single pole)*/
+  if (!topo_has_flag(TF_WRAPX) && !topo_has_flag(TF_WRAPY) ) {
+    num_poles = 1;
+  }
+
+  /* search and set the poles */
+  map.num_continents = 0;
+  while(map.num_continents < num_poles )
+  {
+    if( !rand_clima_map_pos(&map_x, &map_y, 0, 6)) { return ;}
+    if( map_get_continent(map_x, map_y) == 0 ) {
+      map.num_continents++;    
+      assign_continent_flood(map_x, map_y, map.num_continents);
+    }
+  }
+}
+
+/**************************************************************************
  Assign continent numbers to all tiles.
  Numbers 1 and 2 are reserved for polar continents if
  map.generator != 0; otherwise are not special.
@@ -984,34 +1068,21 @@
 **************************************************************************/
 void assign_continent_numbers(void)
 {
-  int isle = 1;
-
   whole_map_iterate(x, y) {
     map_set_continent(x, y, 0);
   } whole_map_iterate_end;
 
-  if (map.generator != 0 && has_poles) {
-    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;
-  }
-      
+  assign_poles_numbers();
+
   whole_map_iterate(x, y) {
     if (map_get_continent(x, y) == 0 
         && !is_ocean(map_get_terrain(x, y))) {
-      assign_continent_flood(x, y, isle++);
+      assign_continent_flood(x, y, ++map.num_continents);
     }
   } whole_map_iterate_end;
-  map.num_continents = isle-1;
 
   freelog(LOG_VERBOSE, "Map has %d continents", map.num_continents);
 }
-
 /****************************************************************************
   Return an approximation of the goodness of a tile to a civilization.
 ****************************************************************************/
@@ -1060,20 +1131,13 @@
 static void setup_isledata(void)
 {
   int starters = 0;
-  int min, firstcont, i;
+  int min,  i;
   
   assert(map.num_continents > 0);
   
   /* allocate + 1 so can use continent number as index */
   islands = fc_calloc((map.num_continents + 1), sizeof(struct isledata));
-  
-  /* the arctic and the antarctic are continents 1 and 2 for generator > 0 */
-  if (map.generator > 0 && map.separatepoles && has_poles) {
-    firstcont = 3;
-  } else {
-    firstcont = 1;
-  }
-  
+
   /* add up all the resources of the map */
   whole_map_iterate(x, y) {
     /* number of different continents seen from (x,y) */
@@ -1087,7 +1151,7 @@
     map_city_radius_iterate(x, y, x1, y1) {
       /* (x1,y1) is possible location of a future city which will
        * be able to get benefit of the tile (x,y) */
-      if (map_get_continent(x1, y1) < firstcont) { 
+      if (map_get_continent(x1, y1) < 1 || map_clima(x1, y1) < 15) { 
         /* (x1, y1) belongs to a non-startable continent */
         continue;
       }
@@ -1118,7 +1182,7 @@
   /* set minimum number of resources per starting position to be value of
    * the best continent */
   min = 0;
-  for (i = firstcont; i < map.num_continents + 1; i++) {
+  for (i = 1; i < map.num_continents + 1; i++) {
     if (min < islands[i].goodies) {
       min = islands[i].goodies;
     }
@@ -1130,7 +1194,7 @@
     int nextmin = 0;
     
     starters = 0;
-    for (i = firstcont; i <= map.num_continents; i++) {
+    for (i = 1; i <= map.num_continents; i++) {
       int value = islands[i].goodies;
       
       starters += value / min;
@@ -1159,7 +1223,7 @@
             "Please report this bug at " WEBSITE_URL);
     abort();
   } else {
-    for (i = firstcont; i <= map.num_continents; i++) {
+    for (i = 1; i <= map.num_continents; i++) {
       islands[i].starters = islands[i].goodies / min;
     }
   }
@@ -1294,12 +1358,8 @@
 
   mysrand(map.seed);
 
-  /* FIXME: currently the lack of poles is hard-coded for maps that wrap
-   * north-south.  In the future this could be a server option.  It also
-   * needs to control the temperature gradient between "poles" and
-   * "equator"; e.g., if there are no poles desert and tundra should be
-   * equally likely at either end. */
-  has_poles = !topo_has_flag(TF_WRAPY);
+  has_poles = TRUE; /* fixed all maps has poles [mburda], this option
+                       is used for a all-temperate map, set False */
 
   /* don't generate tiles with mapgen==0 as we've loaded them from file */
   /* also, don't delete (the handcrafted!) tiny islands in a scenario */
@@ -1364,6 +1424,10 @@
 {
   whole_map_iterate(x, y) {
     hmap(x, y) -= minval;
+    
+    if(near_singularity(x, y)) {
+      hmap(x, y) = 0;
+    }
   } whole_map_iterate_end;
 }
 
@@ -1384,7 +1448,12 @@
     int x, y;
 
     rand_map_pos(&x, &y);
-    hmap(x, y) += myrand(5000);
+    if(near_singularity(x, y) /* avoid land in singularities */
+       || (map.separatepoles && map_clima(x, y) < 10)) { 
+      hmap(x, y) -= myrand(5000);
+    } else { 
+      hmap(x, y) += myrand(5000);
+    }
     if ((i % 100) == 0) {
       smooth_map(); 
     }
@@ -1484,21 +1553,17 @@
 **************************************************************************/
 static void make_huts(int number)
 {
-  int x,y,l;
+  int x,y;
   int count=0;
-  while (number * map_num_tiles() >= 2000 && count++ < map_num_tiles() * 2) {
-    rand_map_pos(&x, &y);
-    l=myrand(6);
-    if (!is_ocean(map_get_terrain(x, y)) && 
-       ( map_get_terrain(x, y)!=T_ARCTIC || l<3 )
-       ) {
-      if (!is_hut_close(x,y)) {
+  while (number * map_num_tiles() >= 2000 && count++ < map_num_tiles() * 2) { 
+    if( rand_clima_map_pos(&x, &y, 12, 100) /* no hut in poles */
+       && !is_ocean(map_get_terrain(x, y) )/* not hut in oceans ! */
+       && !is_hut_close(x,y)) {
        number--;
        map_set_special(x, y, S_HUT);
        /* Don't add to islands[].goodies because islands[] not
           setup at this point, except for generator>1, but they
           have pre-set starters anyway. */
-      }
     }
   }
 }
@@ -1523,32 +1588,24 @@
   Add specials to the map with given probability.
 ****************************************************************************/
 static void add_specials(int prob)
-{
-  int xn, yn;
-  int ymin = has_poles ? 1 : 0, ymax = has_poles ? map.ysize - 1 : map.ysize;
+{ 
   enum tile_terrain_type ttype;
 
-  for (yn = ymin; yn < ymax; 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) && near_safe_tiles(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;
+  whole_map_iterate(x, y)  {
+    ttype = map_get_terrain(x, y);
+    if (((is_ocean(ttype) && near_safe_tiles(x,y)) 
+        || !is_ocean(ttype)) && !is_special_close(x, y) 
+       && myrand(1000) < prob) {
+      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);
+      }
     }
-  }
+  } whole_map_iterate_end;
+  
   map.have_specials = TRUE;
 }
 
@@ -1829,7 +1886,8 @@
   while (i > 0 && tries-->0) {
     get_random_map_position_from_state(&x, &y, pstate);
     map_to_native_pos(&xn, &yn, x, y);
-    if (hmap(x, y) == 0 && count_card_adjc_elevated_tiles(x, y) > 0) {
+    if ((!near_singularity(x, y) || myrand(50) < 25 ) 
+      && hmap(x, y) == 0 && count_card_adjc_elevated_tiles(x, y) > 0) {
       hmap(x, y) = 1;
       i--;
       if (yn >= pstate->s - 1 && pstate->s < map.ysize - 2) {
@@ -1999,11 +2057,10 @@
 **************************************************************************/
 static void initworld(struct gen234_state *pstate)
 {
-  int xn;
-  
   height_map = fc_malloc(sizeof(int) * map.ysize * map.xsize);
   islands = fc_malloc((MAP_NCONT+1)*sizeof(struct isledata));
 
+  map.num_continents = 0;
   whole_map_iterate(x, y) {
     map_set_terrain(x, y, T_OCEAN);
     map_set_continent(x, y, 0);
@@ -2011,31 +2068,15 @@
     map_set_owner(x, y, NULL);
   } whole_map_iterate_end;
   if (has_poles) {
-    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) {
-       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) {
-       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;
+    make_polar(TRUE);
+    assign_poles_numbers(); /* this set map.num_continents to 1 or 2 too */
+    /* clean no in poles continent island */
+    whole_map_iterate(mx, my) {
+      if (map_get_continent(mx, my) == 0
+         && !is_ocean(map_get_terrain(mx, my))) {
+       map_set_terrain(mx, my, T_OCEAN);
       }
-    }
-    map.num_continents = 2;
-  } else {
-    map.num_continents = 0;
+    } whole_map_iterate_end;
   }
   make_island(0, 0, pstate, 0);
   islands[2].starters = 0;
@@ -2315,29 +2356,27 @@
 
   /* set midpoints of sides to avg of side's vertices plus a random factor */
   /* unset points are zero, don't reset if set */
-  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;
-  }
+#define set_midpoints(X,Y,V)                                              \
+  do_in_map_pos(map_x, map_y, (X), (Y)) {                               \
+    if( !near_singularity( map_x, map_y) && hnat((X), (Y)) == 0 ) {       \
+      hnat((X), (Y)) = V; }                                               \
+  } do_in_map_pos_end;
+
+  set_midpoints((x0 + x1)/2, y0,
+               (val[0][0] + val[1][0])/2 + myrand(step) - step/2);
+  set_midpoints((x0 + x1)/2,  y1wrap,
+               (val[0][1] + val[1][1])/2 + myrand(step) - step/2);
+  set_midpoints(x0,  (y0 + y1)/2,
+               (val[0][0] + val[0][1])/2 + myrand(step) - step/2);  
+  set_midpoints(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 (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;
-  }
+   set_midpoints((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 */
   gen5rec(2 * step / 3, x0, y0, (x1 + x0) / 2, (y1 + y0) / 2);
@@ -2375,6 +2414,8 @@
   int xmax = map.xsize - (xnowrap ? 1 : 0);
   int ymax = map.ysize - (ynowrap ? 1 : 0);
   int xn, yn, minval;
+  int T=0;
+
   /* just need something > log(max(xsize, ysize)) for the recursion */
   int step = map.xsize + map.ysize; 
   /* edges are avoided more strongly as this increases */
@@ -2390,36 +2431,23 @@
   /* set initial points */
   for (xn = 0; xn < xdiv2; xn++) {
     for (yn = 0; yn < ydiv2; yn++) {
-      hnat(xn * xmax / xdiv, yn * ymax / ydiv)
-       =  myrand(2 * step) - (2 * step) / 2;
-    }
-  }
-
-  /* if we aren't wrapping stay away from edges to some extent, try
-     even harder to avoid the edges naturally if separatepoles is true */
-  if (xnowrap) {
-    for (yn = 0; yn < ydiv2; yn++) {
-      hnat(0, yn * ymax / ydiv) -= avoidedge;
-      hnat(xmax, yn * ymax / ydiv) -= avoidedge;
-      if (map.separatepoles && has_poles) {
-       hnat(2, yn * ymax / ydiv)
-         = hnat(0, yn * ymax / ydiv) - myrand(3*avoidedge);
-       hnat(xmax - 2, yn * ymax / ydiv) 
-         = hnat(xmax, yn * ymax / ydiv) - myrand(3 * avoidedge);
-      }
-    }
-  }
-
-  if (ynowrap) {
-    for (xn = 0; xn < xdiv2; xn++) {
-      hnat(xn * xmax / xdiv, 0) -= avoidedge;
-      hnat(xn * xmax / xdiv, ymax) -= avoidedge;
-      if (map.separatepoles && has_poles) {
-       hnat(xn * xmax / xdiv, 2)
-         = hnat(xn * xmax / xdiv, 0) - myrand(3 * avoidedge);
-       hnat(xn * xmax / xdiv, ymax - 2) 
-         = hnat(xn * xmax / xdiv, ymax) - myrand(3 * avoidedge);
-      }
+      do_in_map_pos(x, y, (xn * xmax / xdiv), (yn * ymax / ydiv)) {
+       /* set initial points */
+       hmap(x, y) =
+           myrand(2 * step) - (2 * step) / 2;
+
+       /* avoid edges (simplest topologicals singularities) */
+       if (near_singularity(x, y))
+         hmap(x, y ) -= avoidedge;
+
+       if (has_poles) {
+         T = map_clima(x, y);
+         if (map.separatepoles && T <= 10) {
+           hmap(x, y) -= myrand(3 * avoidedge);
+           /* separate poles */
+         }
+       }
+      } do_in_map_pos_end;
     }
   }
 

[Prev in Thread] Current Thread [Next in Thread]