Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] Re: (PR#8870) moving some code in adjust_map().
Home

[Freeciv-Dev] Re: (PR#8870) moving some code in adjust_map().

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#8870) moving some code in adjust_map().
From: "Marcelo Burda" <mburda@xxxxxxxxx>
Date: Mon, 31 May 2004 01:45:18 -0700
Reply-to: rt@xxxxxxxxxxx

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

Le lun 31/05/2004 à 08:14, Jason Short a écrit :
fixed donne file adjust_map
and 
i propose to change this by a normalize_hmap function in the second
patch. (this is best, then i use a renormalize function to texture poles
in the other patch
-- 
 . /  .     '    ,    .      (*)   '        `     '      `    .    
  |    ,  |   `     ,     .      ,   '  Marcelo Julián Burda      .
 /  '     \     `     \@_     '      .        '      `        '    
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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-31 12:29:59.000000000 +0200
@@ -62,7 +62,7 @@
 static void mapgenerator4(void);
 static void mapgenerator5(void);
 static void smooth_map(void);
-static void adjust_map(int minval);
+static void adjust_map(void);
 static void adjust_terrain_param(void);
 
 #define RIVERS_MAXTRIES 32767
@@ -879,10 +879,14 @@
 **************************************************************************/
 static void make_land(void)
 {
-  int tres=(maxval*map.landpercent)/100;
+  int tres;
   int count=0;
   int total = (map_num_tiles() * map.landpercent) / 100;
   int forever=0;
+
+  adjust_map(); 
+  tres = (maxval * map.landpercent ) / 100;
+
   do {
     forever++;
     if (forever>50) break; /* loop elimination */
@@ -1360,8 +1364,16 @@
   i reduce the height so the lowest height is zero, this makes calculations
   easier
 **************************************************************************/
-static void adjust_map(int minval)
+static void adjust_map(void)
 {
+  int minval = maxval = hnat(0, 0);
+
+  whole_map_iterate(x, y) {
+    maxval = MAX(maxval, hmap(x, y));
+    minval = MIN(minval, hmap(x, y));
+  } whole_map_iterate_end;
+
+  maxval -= minval;
   whole_map_iterate(x, y) {
     hmap(x, y) -= minval;
   } whole_map_iterate_end;
@@ -1373,7 +1385,6 @@
 static void mapgenerator1(void)
 {
   int i;
-  int minval=5000000;
   height_map=fc_malloc (sizeof(int)*map.xsize*map.ysize);
 
   whole_map_iterate(x, y) {
@@ -1394,16 +1405,6 @@
   smooth_map(); 
   smooth_map(); 
 
-  whole_map_iterate(x, y) {
-    if (hmap(x, y) > maxval)
-      maxval = hmap(x, y);
-    if (hmap(x, y) < minval)
-      minval = hmap(x, y);
-  } whole_map_iterate_end;
-
-  maxval-=minval;
-  adjust_map(minval);
-
   make_land();
   free(height_map);
   height_map = NULL;
@@ -2374,7 +2375,7 @@
 
   int xmax = map.xsize - (xnowrap ? 1 : 0);
   int ymax = map.ysize - (ynowrap ? 1 : 0);
-  int xn, yn, minval;
+  int xn, yn;
   /* just need something > log(max(xsize, ysize)) for the recursion */
   int step = map.xsize + map.ysize; 
   /* edges are avoided more strongly as this increases */
@@ -2436,16 +2437,6 @@
     hmap(x, y) = 8 * hmap(x, y) + myrand(4) - 2;
   } whole_map_iterate_end;
 
-  /* and calibrate maxval and minval */
-  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));
-  } whole_map_iterate_end;
-  maxval -= minval;
-  adjust_map(minval);
-  
   make_land();
   free(height_map);
   height_map = NULL;
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-31 12:39:43.000000000 +0200
@@ -53,6 +53,7 @@
 #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)])
+#define MAX_HMAP 10000
 
 static void make_huts(int number);
 static void add_specials(int prob);
@@ -62,7 +63,7 @@
 static void mapgenerator4(void);
 static void mapgenerator5(void);
 static void smooth_map(void);
-static void adjust_map(int minval);
+static void normalize_hmap(void);
 static void adjust_terrain_param(void);
 
 #define RIVERS_MAXTRIES 32767
@@ -75,7 +76,6 @@
 static int *river_map;
 
 static int *height_map;
-static int maxval=0;
 static int forests=0;
 static bool has_poles;
 
@@ -131,7 +131,7 @@
 
   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)
+      if ((hnat(xn, yn) + (map.ysize / 10 - yn * 25) > myrand(MAX_HMAP)
           && nat_get_terrain(xn, yn) == T_GRASSLAND) || yn == 0) { 
        if (yn < 2) {
          nat_set_terrain(xn, yn, T_ARCTIC);
@@ -144,7 +144,7 @@
   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))
+           > myrand(MAX_HMAP))
           && nat_get_terrain(xn, yn) == T_GRASSLAND)
          || yn == map.ysize - 1) {
        if (yn > map.ysize - 3) {
@@ -267,7 +267,7 @@
     forever++;
     if (forever>1000) return;
     rand_map_pos(&x, &y);
-    if (map_get_terrain(x, y)==T_GRASSLAND && hmap(x, y)<(maxval*60)/100) {
+    if (map_get_terrain(x, y)==T_GRASSLAND && hmap(x, y)<(MAX_HMAP*60)/100) {
       map_set_terrain(x, y, T_SWAMP);
       cartesian_adjacent_iterate(x, y, x1, y1) {
        if (myrand(10) > 5 && !is_ocean(map_get_terrain(x1, y1))) { 
@@ -879,10 +879,13 @@
 **************************************************************************/
 static void make_land(void)
 {
-  int tres=(maxval*map.landpercent)/100;
+  int tres = (MAX_HMAP * map.landpercent ) / 100;
   int count=0;
   int total = (map_num_tiles() * map.landpercent) / 100;
   int forever=0;
+
+  normalize_hmap(); 
+
   do {
     forever++;
     if (forever>50) break; /* loop elimination */
@@ -900,11 +903,11 @@
     else
       tres*=9;
     tres/=10;
-  } while (abs(total-count)> maxval/40);
+  } while (abs(total-count)> MAX_HMAP/40);
   if (map.separatepoles && has_poles) {
     make_passable();
   }
-  make_mountains(maxval*8/10);
+  make_mountains(MAX_HMAP*8/10);
   make_forests();
   make_swamps();
   make_deserts();
@@ -1359,11 +1362,20 @@
   since the generated map will always have a positive number as minimum height
   i reduce the height so the lowest height is zero, this makes calculations
   easier
+  then we normalize to a max value of MAX_HMAP
 **************************************************************************/
-static void adjust_map(int minval)
+static void normalize_hmap(void)
 {
+  int minval , maxval = minval = hnat(0, 0);
+
+  whole_map_iterate(x, y) {
+    maxval = MAX(maxval, hmap(x, y));
+    minval = MIN(minval, hmap(x, y));
+  } whole_map_iterate_end;
+
+  maxval -= minval;
   whole_map_iterate(x, y) {
-    hmap(x, y) -= minval;
+    hmap(x, y) = (hmap(x, y) - minval) * MAX_HMAP / maxval;
   } whole_map_iterate_end;
 }
 
@@ -1373,7 +1385,6 @@
 static void mapgenerator1(void)
 {
   int i;
-  int minval=5000000;
   height_map=fc_malloc (sizeof(int)*map.xsize*map.ysize);
 
   whole_map_iterate(x, y) {
@@ -1394,16 +1405,6 @@
   smooth_map(); 
   smooth_map(); 
 
-  whole_map_iterate(x, y) {
-    if (hmap(x, y) > maxval)
-      maxval = hmap(x, y);
-    if (hmap(x, y) < minval)
-      minval = hmap(x, y);
-  } whole_map_iterate_end;
-
-  maxval-=minval;
-  adjust_map(minval);
-
   make_land();
   free(height_map);
   height_map = NULL;
@@ -2374,7 +2375,7 @@
 
   int xmax = map.xsize - (xnowrap ? 1 : 0);
   int ymax = map.ysize - (ynowrap ? 1 : 0);
-  int xn, yn, minval;
+  int xn, yn;
   /* just need something > log(max(xsize, ysize)) for the recursion */
   int step = map.xsize + map.ysize; 
   /* edges are avoided more strongly as this increases */
@@ -2436,16 +2437,6 @@
     hmap(x, y) = 8 * hmap(x, y) + myrand(4) - 2;
   } whole_map_iterate_end;
 
-  /* and calibrate maxval and minval */
-  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));
-  } whole_map_iterate_end;
-  maxval -= minval;
-  adjust_map(minval);
-  
   make_land();
   free(height_map);
   height_map = NULL;

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