[Freeciv-Dev] (PR#9627) PATCH: correct some parameters in map generator
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] (PR#9627) PATCH: correct some parameters in map generator and clean-up |
From: |
"Marcelo Burda" <mburda@xxxxxxxxx> |
Date: |
Fri, 6 Aug 2004 15:20:19 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9627 >
LAST CHANGES:
include swamps and make a litle best desert code
i no like so much swamps, somebody as a best plasing idea?
diff -ruN -Xfreeciv/diff_ignore freeciv/common/map.h freeciv_/common/map.h
--- freeciv/common/map.h 2004-08-06 09:30:55.000000000 +0200
+++ freeciv_/common/map.h 2004-08-06 20:09:02.204438728 +0200
@@ -618,7 +618,7 @@
#define MAP_MIN_SEED 0
#define MAP_MAX_SEED (MAX_UINT32 >> 1)
-#define MAP_DEFAULT_LANDMASS 30
+#define MAP_DEFAULT_LANDMASS 35
#define MAP_MIN_LANDMASS 15
#define MAP_MAX_LANDMASS 85
@@ -626,11 +626,11 @@
#define MAP_MIN_RICHES 0
#define MAP_MAX_RICHES 1000
-#define MAP_DEFAULT_MOUNTAINS 30
+#define MAP_DEFAULT_MOUNTAINS 10
#define MAP_MIN_MOUNTAINS 10
#define MAP_MAX_MOUNTAINS 100
-#define MAP_DEFAULT_GRASS 35
+#define MAP_DEFAULT_GRASS 55
#define MAP_MIN_GRASS 20
#define MAP_MAX_GRASS 100
@@ -646,7 +646,7 @@
#define MAP_MIN_RIVERS 0
#define MAP_MAX_RIVERS 100
-#define MAP_DEFAULT_FORESTS 20
+#define MAP_DEFAULT_FORESTS 12
#define MAP_MIN_FORESTS 0
#define MAP_MAX_FORESTS 100
diff -ruN -Xfreeciv/diff_ignore freeciv/server/mapgen.c freeciv_/server/mapgen.c
--- freeciv/server/mapgen.c 2004-08-06 09:30:56.000000000 +0200
+++ freeciv_/server/mapgen.c 2004-08-06 22:13:15.359386952 +0200
@@ -76,7 +76,11 @@
static int *height_map;
static int maxval=0;
-static int forests=0;
+static int forests_to_be_placed =0;
+static int deserts_to_be_placed=0;
+static int grass_to_be_placed=0;
+static int plains_to_be_placed=0;
+static int swamps_to_be_placed=0;
struct isledata {
int goodies;
@@ -93,13 +97,26 @@
/* An estimate of the linear (1-dimensional) size of the map. */
#define SQSIZE MAX(1, sqrt(map.xsize * map.ysize / 1000))
+/* define the 4 region of a Earth like map
+ =========================================================
+ 0-COLD_LV cold region: most ice/tundra/mountains
+ COLD_LV-TREOPICAL_LV temperate region: all terrains types
+ TROPICAL_LV-WET_LV tropical dry region: most dessert/mountains
+ WET_LV-MAX_TEMP tropical wet region: most jungle/mountains
+*/
+#define COLD_LEVEL (10 * MAX_TEMP / 100)
+#define TROPICAL_LEVEL (65 * MAX_TEMP / 100)
+#define WET_LEVEL (80 * MAX_TEMP / 100)
+
/* used to create the poles and for separating them. In a
* mercator projection map we don't want the poles to be too big. */
#define ICE_BASE_LEVEL \
((!topo_has_flag(TF_WRAPX) || !topo_has_flag(TF_WRAPY)) \
/* 5% for little maps; 2% for big ones */ \
? MAX_TEMP * (3 + 2 * SQSIZE) / (100 * SQSIZE) \
- : 5 * MAX_TEMP / 100 /* 5% for all maps */)
+ : COLD_LEVEL / 2 /* for all maps */)
+
+#define T_NOTPLACED T_UNKNOWN
/****************************************************************************
Returns the temperature of this map position. This is a value in the
@@ -283,24 +300,39 @@
}
/**************************************************************************
- make_mountains() will convert all squares that are higher than thill to
+ Checks if land has not yet been placed on tile at (x, y)
+**************************************************************************/
+static bool not_placed(x, y)
+{
+ return map_get_terrain(x, y) == T_NOTPLACED;
+}
+
+/**************************************************************************
+ make_relief() will convert all squares that are higher than thill to
mountains and hills. Notice that thill will be adjusted according to
the map.mountains value, so increase map.mountains and you'll get more
hills and mountains (and vice versa).
+ TODO: extend to place abys/ocean/sea relief in oceans
**************************************************************************/
-static void make_mountains(int thill)
+static void make_relief()
{
- int mount;
- int j;
+ int mount, total;
+ int j, thill = maxval * 0.8;
for (j = 0; j < 10; j++) {
mount = 0;
+ total = 0;
whole_map_iterate(x, y) {
- if (hmap(x, y) > thill) {
- mount++;
+ if(not_placed(x,y)) {
+ total++;
+ if (hmap(x, y) > thill) {
+ mount++;
+ }
}
} whole_map_iterate_end;
- if (mount < (map_num_tiles() * map.mountains) / 1000) {
+
+ if (mount < total * map.mountains / (map.mountains + map.swampsize
+ + map.forestsize + map.deserts + map.grasssize )) {
thill *= 95;
} else {
thill *= 105;
@@ -309,11 +341,11 @@
}
whole_map_iterate(x, y) {
- if (hmap(x, y) > thill && !is_ocean(map_get_terrain(x,y))) {
+ if (not_placed(x,y) && hmap(x, y) > thill) {
/* Randomly place hills and mountains on "high" tiles. But don't
* put hills near the poles (they're too green). */
if (myrand(100) > 75
- || map_temperature(x, y) <= MAX_TEMP / 10) {
+ || map_temperature(x, y) <= COLD_LEVEL) {
map_set_terrain(x, y, T_MOUNTAINS);
} else if (myrand(100) > 25) {
map_set_terrain(x, y, T_HILLS);
@@ -369,9 +401,9 @@
T = map_temperature(map_x, map_y); /* temperature parameter */
ptile = map_get_tile(map_x, map_y);
if (T < 1.5 * ICE_BASE_LEVEL) {
- ptile->terrain = T_GRASSLAND;
+ ptile->terrain = T_NOTPLACED;
} else if ((T <= 2 * ICE_BASE_LEVEL) && myrand(10) > 4 ) {
- ptile->terrain = T_GRASSLAND;
+ ptile->terrain = T_NOTPLACED;
}
} whole_map_iterate_end;
}
@@ -386,8 +418,8 @@
whole_map_iterate(x, y) {
int T = map_temperature(x, y);
- if (map_get_terrain(x, y) == T_GRASSLAND
- && (2 * ICE_BASE_LEVEL > T || myrand(MAX_TEMP/5) > T)) {
+ if (not_placed(x, y)
+ && (2 * ICE_BASE_LEVEL > T || myrand(2 * COLD_LEVEL) > T)) {
map_set_terrain(x, y, T_TUNDRA);
}
} whole_map_iterate_end;
@@ -401,8 +433,8 @@
whole_map_iterate(x, y) {
int T = map_temperature(x, y);
- if (map_get_terrain(x, y) == T_GRASSLAND
- && myrand(15 * MAX_TEMP / 100) > T - ICE_BASE_LEVEL
+ if (not_placed(x, y)
+ && myrand(1.5 * COLD_LEVEL) > T - ICE_BASE_LEVEL
&& T <= 3 * ICE_BASE_LEVEL) {
map_set_terrain(x, y, T_ARCTIC);
}
@@ -423,14 +455,16 @@
{
const int DeltaT = MAX_TEMP / (3 * SQSIZE);
+ if(deserts_to_be_placed <= 0) { return; }
+
if (abs(hmap(x, y) - height) < diff
- && map_get_terrain(x, y) == T_GRASSLAND) {
+ && not_placed(x, y) && count_ocean_near_tile(x,y) <= 2) {
map_set_terrain(x, y, T_DESERT);
+ deserts_to_be_placed--;
cardinal_adjc_iterate(x, y, x1, y1) {
make_desert(x1, y1, height,
diff - 1 - abs(map_temperature(x1, y1) - base_T) / DeltaT,
base_T);
-
} cardinal_adjc_iterate_end;
}
}
@@ -445,15 +479,16 @@
{
int nat_x, nat_y, T;
+ if(forests_to_be_placed <= 0) { return; }
map_to_native_pos(&nat_x, &nat_y, map_x, map_y);
T = map_temperature(map_x, map_y);
- if (map_get_terrain(map_x, map_y) == T_GRASSLAND) {
- if (T > 8 * MAX_TEMP / 10
- && myrand(1000) > 500 - 300 * (T * 1000 / MAX_TEMP - 800)) {
+ if (not_placed(map_x, map_y)) {
+ if (T > WET_LEVEL && myrand(100) > 50) {
map_set_terrain(map_x, map_y, T_JUNGLE);
} else {
map_set_terrain(map_x, map_y, T_FOREST);
}
+ forests_to_be_placed--;
if (abs(hmap(map_x, map_y) - height) < diff) {
cardinal_adjc_iterate(map_x, map_y, x1, y1) {
if (myrand(10) > 5) {
@@ -461,107 +496,126 @@
}
} cardinal_adjc_iterate_end;
}
- forests++;
}
}
/**************************************************************************
- makeforest calls make_forest with random grassland locations until there
- has been made enough forests. (the map.forestsize value controls this)
+ a recursive function that adds swamps to the current location and try
+ to spread out to the neighbours.
**************************************************************************/
-static void make_forests(void)
+static void make_swamp(int map_x, int map_y, int height, int diff)
+{
+ if(swamps_to_be_placed <= 0) { return; }
+ if (not_placed(map_x, map_y) && count_ocean_near_tile(map_x,map_y) >=
myrand(4)) {
+ map_set_terrain(map_x, map_y, T_SWAMP);
+ swamps_to_be_placed--;
+ if (abs(hmap(map_x, map_y) - height) < diff) {
+ cardinal_adjc_iterate(map_x, map_y, x1, y1) {
+ make_forest(x1, y1, height, diff - 5);
+ } cardinal_adjc_iterate_end;
+ }
+ }
+}
+/**************************************************************************
+ make_terrains calls make_forest, make_dessert with random free locations
+ until there has been made enough. it place grassland and plains too.
+**************************************************************************/
+static void make_terrains(void)
{
int x, y;
- int forestsize = (map_num_tiles() * map.forestsize) / 1000;
+ int total = 0;
+ whole_map_iterate(x, y) {
+ if(not_placed(x,y)) {
+ total++;
+ }
+ } whole_map_iterate_end;
- forests = 0;
+ forests_to_be_placed = total * map.forestsize
+ / ( map.forestsize + map.deserts + map.grasssize + map.swampsize );
- do {
- /* Place one forest clump anywhere. */
- if (rand_map_pos_temperature(&x, &y,
- MAX_TEMP / 10, MAX_TEMP,
- T_GRASSLAND)) {
- make_forest(x, y, hmap(x, y), 25);
- } else {
- /* If rand_map_pos_temperature returns FALSE we may as well stop
- * looking. */
- break;
- }
+ deserts_to_be_placed = total * map.deserts
+ / ( map.forestsize + map.deserts + map.grasssize + map.swampsize);
- /* Now add another tropical forest clump (70-100% temperature). */
- if (rand_map_pos_temperature(&x, &y,
- 7 *MAX_TEMP / 10, MAX_TEMP,
- T_GRASSLAND)) {
- make_forest(x, y, hmap(x, y), 25);
- }
+ swamps_to_be_placed = total * map.swampsize
+ / ( map.forestsize + map.deserts + map.grasssize + map.swampsize);
+ grass_to_be_placed = total * map.grasssize / 2
+ / ( map.forestsize + map.deserts + map.grasssize + map.swampsize);
- /* And add a cold forest clump (10%-30% temperature). */
- if (rand_map_pos_temperature(&x, &y,
- 1 * MAX_TEMP / 10, 3 * MAX_TEMP / 10,
- T_GRASSLAND)) {
- make_forest(x, y, hmap(x, y), 25);
+ plains_to_be_placed = total
+ - forests_to_be_placed - deserts_to_be_placed - grass_to_be_placed;
+
+ do {
+ if(forests_to_be_placed > 0) {
+ /* Place one forest clump anywhere. */
+ if (rand_map_pos_temperature(&x, &y,
+ (COLD_LEVEL + ICE_BASE_LEVEL) / 2, MAX_TEMP,
+ T_NOTPLACED)) {
+ make_forest(x, y, hmap(x, y), 25);
+ } else {
+ /* If rand_map_pos_temperature returns FALSE we may as well stop
+ * looking for forest. */
+ forests_to_be_placed = 0;
+ }
}
- } while (forests < forestsize);
-}
-/**************************************************************************
- swamps, is placed on low lying locations, that will typically be close to
- the shoreline. They're put at random (where there is grassland)
- and with 50% chance each of it's neighbour squares will be converted to
- swamp aswell
-**************************************************************************/
-static void make_swamps(void)
-{
- int x, y, swamps;
- int forever = 0;
- for (swamps = 0; swamps < map.swampsize; ) {
- forever++;
- if (forever > 1000) {
- return;
- }
- rand_map_pos(&x, &y);
- if (map_get_terrain(x, y) == T_GRASSLAND
- && hmap(x, y) < (maxval * 60) / 100) {
- map_set_terrain(x, y, T_SWAMP);
- cardinal_adjc_iterate(x, y, x1, y1) {
- if (myrand(10) > 5 && !is_ocean(map_get_terrain(x1, y1))
- && map_get_terrain(x1, y1) != T_SWAMP ) {
- map_set_terrain(x1, y1, T_SWAMP);
- swamps++;
- }
- } cardinal_adjc_iterate_end;
- swamps++;
+ if(swamps_to_be_placed > 0) {
+ /* Place one swamp clump anywhere. */
+ if (rand_map_pos_temperature(&x, &y,
+ (COLD_LEVEL + ICE_BASE_LEVEL) / 2, MAX_TEMP,
+ T_NOTPLACED)) {
+ make_swamp(x, y, hmap(x, y), 25);
+ } else {
+ /* If rand_map_pos_temperature returns FALSE we may as well stop
+ * looking for swamp. */
+ swamps_to_be_placed = 0;
+ }
}
- }
-}
-/*************************************************************************
- Make deserts until we have enough of them.
-**************************************************************************/
-static void make_deserts(void)
-{
- int x, y, i = map.deserts, j = 0;
+ if(deserts_to_be_placed > 0) {
+ /* 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 (rand_map_pos_temperature(&x, &y,
+ TROPICAL_LEVEL, WET_LEVEL,
+ T_NOTPLACED)){
+ make_desert(x, y, hmap(x, y), 50, map_temperature(x, y));
+ } else {
+ /* If rand_map_pos_temperature returns FALSE we may as well stop
+ * looking for dessert. (convert to plains */
+ plains_to_be_placed += deserts_to_be_placed;
+ deserts_to_be_placed = 0;
+ }
+ }
- /* "i" is the number of desert clumps made; "j" is the number of tries. */
- /* TODO: j is no longer needed */
- while (i > 0 && j < 100 * map.deserts) {
- j++;
+ if(grass_to_be_placed > 0) {
+ if (rand_map_pos_temperature(&x, &y,
+ COLD_LEVEL, MAX_TEMP,
+ T_NOTPLACED)){
+ map_set_terrain(x, y, T_GRASSLAND);
+ grass_to_be_placed--;
+ } else {
+ /* If rand_map_pos_temperature returns FALSE we may as well stop
+ * looking for grass. */
+ grass_to_be_placed = 0;
+ }
+ }
- /* 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 (rand_map_pos_temperature(&x, &y,
- 65 * MAX_TEMP / 100, 80 * MAX_TEMP / 100,
- T_GRASSLAND)){
- make_desert(x, y, hmap(x, y), 50, map_temperature(x, y));
- i--;
- } else {
- /* If rand_map_pos_temperature returns FALSE we may as well stop
- * looking. */
- break;
+ if(plains_to_be_placed > 0) {
+ if (rand_map_pos_temperature(&x, &y,
+ COLD_LEVEL, MAX_TEMP,
+ T_NOTPLACED)){
+ map_set_terrain(x, y, T_PLAINS);
+ plains_to_be_placed--;
+ } else {
+ /* If rand_map_pos_temperature returns FALSE we may as well stop
+ * looking for grass. */
+ plains_to_be_placed = 0;
+ }
}
- }
+
+ } while (forests_to_be_placed > 0 || deserts_to_be_placed > 0 ||
+ grass_to_be_placed > 0 || plains_to_be_placed > 0);
}
/*********************************************************************
@@ -814,7 +868,7 @@
if (adjacent_river_tiles4(x, y) != 0
|| adjacent_ocean_tiles4(x, y) != 0
|| (map_get_terrain(x, y) == T_ARCTIC
- && map_temperature(x, y) < 8 * MAX_TEMP / 100)) {
+ && map_temperature(x, y) < 0.8 * COLD_LEVEL)) {
freelog(LOG_DEBUG,
"The river ended at (%d, %d).\n", x, y);
@@ -1026,18 +1080,6 @@
free(river_map);
river_map = NULL;
}
-
-/**************************************************************************
- make_plains converts 50% of the remaining grassland to plains, this should
- maybe be lowered to 30% or done in batches, like the swamps?
-**************************************************************************/
-static void make_plains(void)
-{
- whole_map_iterate(x, y) {
- if (map_get_terrain(x, y) == T_GRASSLAND && myrand(100) > 50)
- map_set_terrain(x, y, T_PLAINS);
- } whole_map_iterate_end;
-}
/****************************************************************************
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
@@ -1142,26 +1184,24 @@
if (hmap(x, y) < tres)
map_set_terrain(x, y, T_OCEAN);
else {
- map_set_terrain(x, y, T_GRASSLAND);
+ map_set_terrain(x, y, T_NOTPLACED);
count++;
}
} whole_map_iterate_end;
+
if (count>total)
tres*=11;
else
tres*=9;
- tres/=10;
+ tres/=10;
} while (abs(total-count)> maxval/40);
renormalize_hmap_poles();
make_polar_land(); /* make extra land at poles*/
- make_mountains(maxval*8/10);
- make_arctic();
- make_tundra();
- make_forests();
- make_swamps();
- make_deserts();
- make_plains();
+ make_relief(); /* base relief on map */
+ make_arctic(); /* TODO handle in make_terrains */
+ make_tundra(); /* TODO handle in make_terrains */
+ make_terrains();/* place forest/dessert/swamp/grass and plains */
make_fair();
make_rivers();
}
@@ -1655,9 +1695,9 @@
static void adjust_terrain_param(void)
{
int total;
- int polar = 5; /* FIXME: convert to a server option */
+ int polar = ICE_BASE_LEVEL * 100 / MAX_TEMP;
- total = map.mountains + map.deserts + map.forestsize + map.swampsize
+ total = map.mountains + map.forestsize + map.swampsize
+ map.grasssize;
if (total != 100 - polar) {
@@ -2342,6 +2382,17 @@
#define DMSIS 10
/**************************************************************************
+ make_plains converts 50% of the remaining grassland to plains, this should
+ maybe be lowered to 30% or done in batches, like the swamps?
+**************************************************************************/
+static void make_plains(void)
+{
+ whole_map_iterate(x, y) {
+ if (map_get_terrain(x, y) == T_GRASSLAND && myrand(100) > 50)
+ map_set_terrain(x, y, T_PLAINS);
+ } whole_map_iterate_end;
+}
+/**************************************************************************
island base map generators
**************************************************************************/
static void mapgenerator2(void)
diff -ruN -Xfreeciv/diff_ignore freeciv/server/stdinhand.c
freeciv_/server/stdinhand.c
--- freeciv/server/stdinhand.c 2004-07-31 08:21:55.000000000 +0200
+++ freeciv_/server/stdinhand.c 2004-08-06 20:09:02.232434472 +0200
@@ -369,7 +369,7 @@
GEN_INT("grass", map.grasssize,
SSET_MAP_GEN, SSET_ECOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
- N_("Amount of grass squares"), "", NULL,
+ N_("Amount of grass and plains squares"), "", NULL,
MAP_MIN_GRASS, MAP_MAX_GRASS, MAP_DEFAULT_GRASS)
GEN_INT("forests", map.forestsize,
- [Freeciv-Dev] (PR#9627) PATCH: correct some parameters in map generator and clean-up, Marcelo Burda, 2004/08/06
- [Freeciv-Dev] (PR#9627) PATCH: correct some parameters in map generator and clean-up,
Marcelo Burda <=
- [Freeciv-Dev] (PR#9627) PATCH: correct some parameters in map generator and clean-up, Marcelo Burda, 2004/08/07
- [Freeciv-Dev] (PR#9627) PATCH: correct some parameters in map generator and clean-up, Jason Short, 2004/08/09
- [Freeciv-Dev] (PR#9627) PATCH: correct some parameters in map generator and clean-up, Marcelo Burda, 2004/08/10
- [Freeciv-Dev] (PR#9627) PATCH: correct some parameters in map generator and clean-up, Marcelo Burda, 2004/08/10
- [Freeciv-Dev] (PR#9627) PATCH: correct some parameters in map generator and clean-up, Marcelo Burda, 2004/08/13
- [Freeciv-Dev] (PR#9627) PATCH: correct some parameters in map generator and clean-up, Marcelo Burda, 2004/08/13
- [Freeciv-Dev] (PR#9627) PATCH: correct some parameters in map generator and clean-up, Marcelo Burda, 2004/08/13
- [Freeciv-Dev] (PR#9627) PATCH: correct some parameters in map generator and clean-up, Marcelo Burda, 2004/08/15
- [Freeciv-Dev] (PR#9627) PATCH: correct some parameters in map generator and clean-up, Marcelo Burda, 2004/08/22
- [Freeciv-Dev] (PR#9627) PATCH: correct some parameters in map generator and clean-up, Marcelo Burda, 2004/08/27
|
|