[Freeciv-Dev] (PR#10124) PATCH: new generator 1, hmap generator (1,5) mv
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://RT::WebBaseURL.not.configured:80/Ticket/Display.html?id=10124 >
this is a new uncorrelated generator than remplace the old generator
1.
after created whe can choice the number of call to smoth function,
this allow control over size of continents, very nice.
this one has a stupid bug but i not known why fix it
the bug :
> set generator_smoth 1
Value must be an integer.
help plz
some one
diff -ruN -Xfreeciv/diff_ignore freeciv/common/map.c freeciv_/common/map.c
--- freeciv/common/map.c 2004-09-14 12:04:30.000000000 +0200
+++ freeciv_/common/map.c 2004-09-15 11:54:30.225766768 +0200
@@ -204,6 +204,7 @@
map.riverlength = MAP_DEFAULT_RIVERS;
map.forestsize = MAP_DEFAULT_FORESTS;
map.generator = MAP_DEFAULT_GENERATOR;
+ map.generator_smoth = MAP_DEFAULT_GENERATOR_SMOTH;
map.tinyisles = MAP_DEFAULT_TINYISLES;
map.separatepoles = MAP_DEFAULT_SEPARATE_POLES;
map.alltemperate = MAP_DEFAULT_ALLTEMPERATE;
diff -ruN -Xfreeciv/diff_ignore freeciv/common/map.h freeciv_/common/map.h
--- freeciv/common/map.h 2004-09-14 12:04:30.000000000 +0200
+++ freeciv_/common/map.h 2004-09-15 12:15:14.260644720 +0200
@@ -170,6 +170,7 @@
int riverlength;
int forestsize;
int generator;
+ int generator_smoth;
bool tinyisles;
bool separatepoles;
bool alltemperate;
@@ -664,6 +665,10 @@
#define MAP_MIN_GENERATOR 1
#define MAP_MAX_GENERATOR 5
+#define MAP_DEFAULT_GENERATOR_SMOTH 3
+#define MAP_MIN_GENERATOR_SMOTH 1
+#define MAP_MAX_GENERATOR_SMOTH 8
+
#define MAP_DEFAULT_TINYISLES FALSE
#define MAP_MIN_TINYISLES FALSE
#define MAP_MAX_TINYISLES TRUE
Les fichiers freeciv/manual/civmanual et freeciv_/manual/civmanual sont
différents.
diff -ruN -Xfreeciv/diff_ignore freeciv/server/generator/height_map.c
freeciv_/server/generator/height_map.c
--- freeciv/server/generator/height_map.c 2004-09-14 10:23:00.000000000
+0200
+++ freeciv_/server/generator/height_map.c 2004-09-15 11:52:56.320042608
+0200
@@ -1,5 +1,6 @@
/**********************************************************************
Freeciv - Copyright (C) 2004 - Marcelo J. Burda
+ Copyright (C) 2002 - Karen Yeats for make_pseudofractal_hmap
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
@@ -11,5 +12,215 @@
GNU General Public License for more details.
***********************************************************************/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "map.h"
+#include "rand.h"
+
+#include "height_map.h"
+#include "mapgen_topology.h"
+#include "utilities.h"
+
int *height_map;
int hmap_shore_level, hmap_mountain_level;
+/****************************************************************************
+ Lower the land near the polar region to avoid too much land there.
+
+ See also renomalize_hmap_poles
+****************************************************************************/
+void normalize_hmap_poles(void)
+{
+ whole_map_iterate(x, y) {
+ if (near_singularity(x, y)) {
+ hmap(x, y) = 0;
+ } else if (map_colatitude(x, y) < 2 * ICE_BASE_LEVEL) {
+ hmap(x, y) *= map_colatitude(x, y) / (2.5 * ICE_BASE_LEVEL);
+ } else if (map.separatepoles
+ && map_colatitude(x, y) <= 2.5 * ICE_BASE_LEVEL) {
+ hmap(x, y) *= 0.1;
+ } else if (map_colatitude(x, y) <= 2.5 * ICE_BASE_LEVEL) {
+ hmap(x, y) *= map_colatitude(x, y) / (2.5 * ICE_BASE_LEVEL);
+ }
+ } whole_map_iterate_end;
+}
+
+/****************************************************************************
+ Invert the effects of normalize_hmap_poles so that we have accurate heights
+ for texturing the poles.
+****************************************************************************/
+void renormalize_hmap_poles(void)
+{
+ whole_map_iterate(x, y) {
+ if (hmap(x, y) == 0 || map_colatitude(x, y) == 0) {
+ /* Nothing. */
+ } else if (map_colatitude(x, y) < 2 * ICE_BASE_LEVEL) {
+ hmap(x, y) *= (2.5 * ICE_BASE_LEVEL) / map_colatitude(x, y);
+ } else if (map.separatepoles
+ && map_colatitude(x, y) <= 2.5 * ICE_BASE_LEVEL) {
+ hmap(x, y) *= 10;
+ } else if (map_colatitude(x, y) <= 2.5 * ICE_BASE_LEVEL) {
+ hmap(x, y) *= (2.5 * ICE_BASE_LEVEL) / map_colatitude(x, y);
+ }
+ } whole_map_iterate_end;
+}
+
+/**********************************************************************
+ Create uncorrelated rand map and do some call to smoth to correlate
+ it a little and creante randoms shapes
+ **********************************************************************/
+void make_random_hmap(int smooth)
+{
+ int i = 0;
+ height_map = fc_malloc (sizeof(int) * MAX_MAP_INDEX);
+
+ INITIALIZE_ARRAY(height_map, MAX_MAP_INDEX, myrand(1000 * smooth) );
+
+ for (; i < smooth; i++) {
+ smooth_int_map(height_map, TRUE);
+ }
+
+ adjust_int_map(height_map, hmap_max_level);
+}
+
+/**************************************************************************
+ Recursive function which does the work for generator 5.
+
+ All (x0,y0) and (x1,y1) are in native coordinates.
+
+ Freeciv - Copyright (C) 2002 - Karen Yeats
+**************************************************************************/
+static void gen5rec(int step, int x0, int y0, int x1, int y1)
+{
+ int val[2][2];
+ int x1wrap = x1; /* to wrap correctly */
+ int y1wrap = y1;
+
+ /* All x and y values are native. */
+
+ if (((y1 - y0 <= 0) || (x1 - x0 <= 0))
+ || ((y1 - y0 == 1) && (x1 - x0 == 1))) {
+ return;
+ }
+
+ if (x1 == map.xsize)
+ x1wrap = 0;
+ if (y1 == map.ysize)
+ y1wrap = 0;
+
+ 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 */
+#define set_midpoints(X, Y, V) \
+ do_in_map_pos(map_x, map_y, (X), (Y)) { \
+ if (!near_singularity(map_x, map_y)
\
+ && map_colatitude(map_x, map_y) > ICE_BASE_LEVEL/2 \
+ && 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 */
+ 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));
+
+#undef set_midpoints
+
+ /* now call recursively on the four subrectangles */
+ gen5rec(2 * step / 3, x0, y0, (x1 + x0) / 2, (y1 + y0) / 2);
+ gen5rec(2 * step / 3, x0, (y1 + y0) / 2, (x1 + x0) / 2, y1);
+ gen5rec(2 * step / 3, (x1 + x0) / 2, y0, x1, (y1 + y0) / 2);
+ gen5rec(2 * step / 3, (x1 + x0) / 2, (y1 + y0) / 2, x1, y1);
+}
+
+/**************************************************************************
+Generator 5 makes earthlike worlds with one or more large continents and
+a scattering of smaller islands. It does so by dividing the world into
+blocks and on each block raising or lowering the corners, then the
+midpoints and middle and so on recursively. Fiddling with 'xdiv' and
+'ydiv' will change the size of the initial blocks and, if the map does not
+wrap in at least one direction, fiddling with 'avoidedge' will change the
+liklihood of continents butting up to non-wrapped edges.
+
+ All X and Y values used in this function are in native coordinates.
+
+ Freeciv - Copyright (C) 2002 - Karen Yeats
+**************************************************************************/
+void make_pseudofractal1_hmap(void)
+{
+ const bool xnowrap = !topo_has_flag(TF_WRAPX);
+ const bool ynowrap = !topo_has_flag(TF_WRAPY);
+
+ /*
+ * How many blocks should the x and y directions be divided into
+ * initially.
+ */
+ const int xdiv = 6;
+ const int ydiv = 5;
+
+ int xdiv2 = xdiv + (xnowrap ? 1 : 0);
+ int ydiv2 = ydiv + (ynowrap ? 1 : 0);
+
+ int xmax = map.xsize - (xnowrap ? 1 : 0);
+ int ymax = map.ysize - (ynowrap ? 1 : 0);
+ 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 */
+ int avoidedge = (50 - map.landpercent) * step / 100 + step / 3;
+
+ height_map = fc_malloc(sizeof(int) * MAX_MAP_INDEX);
+
+ /* initialize map */
+ INITIALIZE_ARRAY(height_map, MAX_MAP_INDEX, 0);
+
+ /* set initial points */
+ for (xn = 0; xn < xdiv2; xn++) {
+ for (yn = 0; yn < ydiv2; yn++) {
+ do_in_map_pos(x, y, (xn * xmax / xdiv), (yn * ymax / ydiv)) {
+ /* set initial points */
+ hmap(x, y) = myrand(2 * step) - (2 * step) / 2;
+
+ if (near_singularity(x, y)) {
+ /* avoid edges (topological singularities) */
+ hmap(x, y) -= avoidedge;
+ }
+
+ if (map_colatitude(x, y) <= ICE_BASE_LEVEL / 2 ) {
+ /* separate poles and avoid too much land at poles */
+ hmap(x, y) -= myrand(avoidedge);
+ }
+ } do_in_map_pos_end;
+ }
+ }
+
+ /* calculate recursively on each block */
+ for (xn = 0; xn < xdiv; xn++) {
+ for (yn = 0; yn < ydiv; yn++) {
+ gen5rec(step, xn * xmax / xdiv, yn * ymax / ydiv,
+ (xn + 1) * xmax / xdiv, (yn + 1) * ymax / ydiv);
+ }
+ }
+
+ /* put in some random fuzz */
+ whole_map_iterate(x, y) {
+ hmap(x, y) = 8 * hmap(x, y) + myrand(4) - 2;
+ } whole_map_iterate_end;
+
+ adjust_int_map(height_map, hmap_max_level);
+}
diff -ruN -Xfreeciv/diff_ignore freeciv/server/generator/height_map.h
freeciv_/server/generator/height_map.h
--- freeciv/server/generator/height_map.h 2004-09-14 10:23:00.000000000
+0200
+++ freeciv_/server/generator/height_map.h 2004-09-15 11:52:39.487601528
+0200
@@ -1,5 +1,6 @@
/**********************************************************************
Freeciv - Copyright (C) 2004 - Marcelo J. Burda
+ Copyright (C) 2002 - Karen Yeats for make_pseudofractal_hmap
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
@@ -35,4 +36,9 @@
extern int *height_map;
extern int hmap_shore_level, hmap_mountain_level;
+void normalize_hmap_poles(void);
+void renormalize_hmap_poles(void);
+void make_random_hmap(int smooth);
+void make_pseudofractal1_hmap(void);
+
#endif /* FC__HEIGHT__MAP_H */
diff -ruN -Xfreeciv/diff_ignore freeciv/server/generator/mapgen.c
freeciv_/server/generator/mapgen.c
--- freeciv/server/generator/mapgen.c 2004-09-14 12:04:31.000000000 +0200
+++ freeciv_/server/generator/mapgen.c 2004-09-15 11:47:29.190773816 +0200
@@ -50,12 +50,9 @@
static void make_huts(int number);
static void add_specials(int prob);
-static void mapgenerator1(void);
static void mapgenerator2(void);
static void mapgenerator3(void);
static void mapgenerator4(void);
-static void mapgenerator5(void);
-static void smooth_map(void);
static void adjust_terrain_param(void);
#define RIVERS_MAXTRIES 32767
@@ -917,47 +914,6 @@
river_map = NULL;
}
-/****************************************************************************
- Lower the land near the polar region to avoid too much land there.
-
- See also renomalize_hmap_poles
-****************************************************************************/
-static void normalize_hmap_poles(void)
-{
- whole_map_iterate(x, y) {
- if (near_singularity(x, y)) {
- hmap(x, y) = 0;
- } else if (map_colatitude(x, y) < 2 * ICE_BASE_LEVEL) {
- hmap(x, y) *= map_colatitude(x, y) / (2.5 * ICE_BASE_LEVEL);
- } else if (map.separatepoles
- && map_colatitude(x, y) <= 2.5 * ICE_BASE_LEVEL) {
- hmap(x, y) *= 0.1;
- } else if (map_colatitude(x, y) <= 2.5 * ICE_BASE_LEVEL) {
- hmap(x, y) *= map_colatitude(x, y) / (2.5 * ICE_BASE_LEVEL);
- }
- } whole_map_iterate_end;
-}
-
-/****************************************************************************
- Invert the effects of normalize_hmap_poles so that we have accurate heights
- for texturing the poles.
-****************************************************************************/
-static void renormalize_hmap_poles(void)
-{
- whole_map_iterate(x, y) {
- if (hmap(x, y) == 0 || map_colatitude(x, y) == 0) {
- /* Nothing. */
- } else if (map_colatitude(x, y) < 2 * ICE_BASE_LEVEL) {
- hmap(x, y) *= (2.5 * ICE_BASE_LEVEL) / map_colatitude(x, y);
- } else if (map.separatepoles
- && map_colatitude(x, y) <= 2.5 * ICE_BASE_LEVEL) {
- hmap(x, y) *= 10;
- } else if (map_colatitude(x, y) <= 2.5 * ICE_BASE_LEVEL) {
- hmap(x, y) *= (2.5 * ICE_BASE_LEVEL) / map_colatitude(x, y);
- }
- } whole_map_iterate_end;
-}
-
/**************************************************************************
make land simply does it all based on a generated heightmap
1) with map.landpercent it generates a ocean/grassland map
@@ -965,7 +921,7 @@
**************************************************************************/
static void make_land(void)
{
- adjust_int_map(height_map, hmap_max_level);
+
if (HAS_POLES) {
normalize_hmap_poles();
}
@@ -1325,16 +1281,26 @@
adjust_terrain_param();
/* if one mapgenerator fails, it will choose another mapgenerator */
/* with a lower number to try again */
- if (map.generator == 5 )
- mapgenerator5();
+ if (map.generator == 5 ) {
+ make_pseudofractal1_hmap();
+ }
if (map.generator == 4 )
mapgenerator4();
if (map.generator == 3 )
mapgenerator3();
- if( map.generator == 2 )
+ if (map.generator == 2 )
mapgenerator2();
- if( map.generator == 1 )
- mapgenerator1();
+ if (map.generator == 1 ) {
+ make_random_hmap(map.generator_smoth);
+ }
+
+ /* if hmap only genrator make any thing else */
+ if (map.generator == 1 || map.generator == 5) {
+ make_land();
+ free(height_map);
+ height_map = NULL;
+ }
+
if (!map.tinyisles) {
remove_tiny_islands();
}
@@ -1379,82 +1345,6 @@
}
}
-/**************************************************************************
- mapgenerator1, highlevel function, that calls all the previous functions
-**************************************************************************/
-static void mapgenerator1(void)
-{
- int i;
- height_map = fc_malloc (sizeof(int) * MAX_MAP_INDEX);
-
- INITIALIZE_ARRAY(height_map, MAX_MAP_INDEX, myrand(40) );
-
- for (i=0;i<1500;i++) {
- int x, y;
-
- rand_map_pos(&x, &y);
-
- if (near_singularity(x, y)
- || map_colatitude(x, y) <= ICE_BASE_LEVEL / 2) {
- /* Avoid land near singularities or at the poles. */
- hmap(x, y) -= myrand(5000);
- } else {
- hmap(x, y) += myrand(5000);
- }
- if ((i % 100) == 0) {
- smooth_map();
- }
- }
-
- smooth_map();
- smooth_map();
- smooth_map();
-
- make_land();
- free(height_map);
- height_map = NULL;
-}
-
-/**************************************************************************
- smooth_map should be viewed as a corrosion function on the map, it
- levels out the differences in the heightmap.
-**************************************************************************/
-static void smooth_map(void)
-{
- /* We make a new height map and then copy it back over the old one.
- * Care must be taken so that the new height map uses the exact same
- * storage structure as the real one - it must be the same size and
- * use the same indexing. The advantage of the new array is there's
- * no feedback from overwriting in-use values.
- */
- int *new_hmap = fc_malloc(sizeof(int) * map.xsize * map.ysize);
-
- whole_map_iterate(x, y) {
- /* double-count this tile */
- int height_sum = hmap(x, y) * 2;
-
- /* weight of counted tiles */
- int counter = 2;
-
- adjc_iterate(x, y, x2, y2) {
- /* count adjacent tile once */
- height_sum += hmap(x2, y2);
- counter++;
- } adjc_iterate_end;
-
- /* random factor: -30..30 */
- height_sum += myrand(61) - 30;
-
- if (height_sum < 0)
- height_sum = 0;
- new_hmap[map_pos_to_index(x, y)] = height_sum / counter;
- } whole_map_iterate_end;
-
- memcpy(height_map, new_hmap, sizeof(int) * map.xsize * map.ysize);
- free(new_hmap);
-}
-
-
/****************************************************************************
Return TRUE if a safe tile is in a radius of 1. This function is used to
test where to place specials on the sea.
@@ -2275,142 +2165,3 @@
}
#undef DMSIS
-
-/**************************************************************************
- Recursive function which does the work for generator 5.
-
- All (x0,y0) and (x1,y1) are in native coordinates.
-**************************************************************************/
-static void gen5rec(int step, int x0, int y0, int x1, int y1)
-{
- int val[2][2];
- int x1wrap = x1; /* to wrap correctly */
- int y1wrap = y1;
-
- /* All x and y values are native. */
-
- if (((y1 - y0 <= 0) || (x1 - x0 <= 0))
- || ((y1 - y0 == 1) && (x1 - x0 == 1))) {
- return;
- }
-
- if (x1 == map.xsize)
- x1wrap = 0;
- if (y1 == map.ysize)
- y1wrap = 0;
-
- 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 */
-#define set_midpoints(X, Y, V) \
- do_in_map_pos(map_x, map_y, (X), (Y)) { \
- if (!near_singularity(map_x, map_y)
\
- && map_colatitude(map_x, map_y) > ICE_BASE_LEVEL/2 \
- && 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 */
- 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));
-
-#undef set_midpoints
-
- /* now call recursively on the four subrectangles */
- gen5rec(2 * step / 3, x0, y0, (x1 + x0) / 2, (y1 + y0) / 2);
- gen5rec(2 * step / 3, x0, (y1 + y0) / 2, (x1 + x0) / 2, y1);
- gen5rec(2 * step / 3, (x1 + x0) / 2, y0, x1, (y1 + y0) / 2);
- gen5rec(2 * step / 3, (x1 + x0) / 2, (y1 + y0) / 2, x1, y1);
-}
-
-/**************************************************************************
-Generator 5 makes earthlike worlds with one or more large continents and
-a scattering of smaller islands. It does so by dividing the world into
-blocks and on each block raising or lowering the corners, then the
-midpoints and middle and so on recursively. Fiddling with 'xdiv' and
-'ydiv' will change the size of the initial blocks and, if the map does not
-wrap in at least one direction, fiddling with 'avoidedge' will change the
-liklihood of continents butting up to non-wrapped edges.
-
- All X and Y values used in this function are in native coordinates.
-**************************************************************************/
-static void mapgenerator5(void)
-{
- const bool xnowrap = !topo_has_flag(TF_WRAPX);
- const bool ynowrap = !topo_has_flag(TF_WRAPY);
-
- /*
- * How many blocks should the x and y directions be divided into
- * initially.
- */
- const int xdiv = 6;
- const int ydiv = 5;
-
- int xdiv2 = xdiv + (xnowrap ? 1 : 0);
- int ydiv2 = ydiv + (ynowrap ? 1 : 0);
-
- int xmax = map.xsize - (xnowrap ? 1 : 0);
- int ymax = map.ysize - (ynowrap ? 1 : 0);
- 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 */
- int avoidedge = (50 - map.landpercent) * step / 100 + step / 3;
-
- height_map = fc_malloc(sizeof(int) * MAX_MAP_INDEX);
-
- /* initialize map */
- INITIALIZE_ARRAY(height_map, MAX_MAP_INDEX, 0);
-
- /* set initial points */
- for (xn = 0; xn < xdiv2; xn++) {
- for (yn = 0; yn < ydiv2; yn++) {
- do_in_map_pos(x, y, (xn * xmax / xdiv), (yn * ymax / ydiv)) {
- /* set initial points */
- hmap(x, y) = myrand(2 * step) - (2 * step) / 2;
-
- if (near_singularity(x, y)) {
- /* avoid edges (topological singularities) */
- hmap(x, y) -= avoidedge;
- }
-
- if (map_colatitude(x, y) <= ICE_BASE_LEVEL / 2 ) {
- /* separate poles and avoid too much land at poles */
- hmap(x, y) -= myrand(avoidedge);
- }
- } do_in_map_pos_end;
- }
- }
-
- /* calculate recursively on each block */
- for (xn = 0; xn < xdiv; xn++) {
- for (yn = 0; yn < ydiv; yn++) {
- gen5rec(step, xn * xmax / xdiv, yn * ymax / ydiv,
- (xn + 1) * xmax / xdiv, (yn + 1) * ymax / ydiv);
- }
- }
-
- /* put in some random fuzz */
- whole_map_iterate(x, y) {
- hmap(x, y) = 8 * hmap(x, y) + myrand(4) - 2;
- } whole_map_iterate_end;
-
- make_land();
- free(height_map);
- height_map = NULL;
-}
diff -ruN -Xfreeciv/diff_ignore freeciv/server/generator/utilities.c
freeciv_/server/generator/utilities.c
--- freeciv/server/generator/utilities.c 2004-09-14 10:23:00.000000000
+0200
+++ freeciv_/server/generator/utilities.c 2004-09-15 11:06:35.663766616
+0200
@@ -134,3 +134,88 @@
}
}
}
+bool normalize_nat_pos(int *x, int *y)
+{
+ int map_x, map_y;
+ bool return_value;
+
+ NATIVE_TO_MAP_POS(&map_x, &map_y, *x, *y);
+ return_value = normalize_map_pos(&map_x, &map_y);
+ MAP_TO_NATIVE_POS(x, y, map_x, map_y);
+
+ return return_value;
+}
+
+bool is_normal_nat_pos(int x, int y)
+{
+ do_in_map_pos(map_x, map_y, x, y) {
+ return is_normal_map_pos(map_x, map_y);
+ } do_in_map_pos_end;
+}
+
+#define iterate_axe(x, y, i, x0, y0, dist, Xaxe) \
+{ \
+ int x, y, i; \
+ \
+ for (i = -(dist); i <= (dist); i++) { \
+ x = x0 + (Xaxe ? i : 0); \
+ y = y0 + (Xaxe ? 0 : i); \
+ if(!normalize_nat_pos(&x, &y)) { \
+ continue; \
+ }
+
+#define iterate_axe_end \
+ } \
+}
+/**************************************************************************
+ * Apply a difusion filtre on the map
+ * we assume the size is MAX_MAP_INDEX and is indexed has the main map
+ * native_to_index is used!
+ * code assume out map value of 0 if zeroes_at_edges is set. else code dont't
+ * diffuse from outside the real map.
+ * the filter is a Gaussian difusion
+ * aproximated by -2..+2 tiles finite math
+ ****************************************************************************/
+ void smooth_int_map(int *int_map, bool zeroes_at_edges)
+{
+ assert(int_map != NULL);
+ float weight[5] = {0.35, 0.5 ,1 , 0.5, 0.35};
+ float total_weight = 2.70;
+ int x, y;
+ bool axe = TRUE;
+ int alt_int_map[MAX_MAP_INDEX];
+ int *target_map, *source_map;
+
+ target_map = alt_int_map;
+ source_map = int_map;
+
+ do {
+ for (y = 0; y < map.ysize; y++) {
+ for (x = 0; x < map.xsize; x++) {
+ int N = 0, D = 0;
+ iterate_axe(x1, y1, i, x, y, 2, axe) {
+ D += weight[i + 2];
+ N += weight[i + 2] * source_map[native_pos_to_index(x1, y1)];
+ } iterate_axe_end;
+ if(zeroes_at_edges) {
+ D = total_weight;
+ }
+ target_map[native_pos_to_index(x, y)] = N / D;
+
+ }
+ }
+
+ if (topo_has_flag(TF_ISO) || topo_has_flag(TF_HEX)) {
+ weight[0] = weight[4] = 0.5;
+ weight[1] = weight[3] = 0.7;
+ total_weight = 3.4;
+ }
+
+ axe = !axe;
+
+ source_map = alt_int_map;
+ target_map = int_map;
+
+ } while ( !axe );
+}
+
diff -ruN -Xfreeciv/diff_ignore freeciv/server/generator/utilities.h
freeciv_/server/generator/utilities.h
--- freeciv/server/generator/utilities.h 2004-09-14 10:23:00.000000000
+0200
+++ freeciv_/server/generator/utilities.h 2004-09-14 21:56:01.000000000
+0200
@@ -30,6 +30,39 @@
} \
}
+/* Provide a block to convert from map to native coordinates. This allows
+ * you to use a native version of the map position within the block. Note
+ * that the native position is declared as const and can't be changed
+ * inside the block. */
+#define index_do_in_native_pos(nat_x, nat_y, index) \
+{ \
+ int _nat_x, _nat_y; \
+ index_to_native_pos(&_nat_x, &_nat_y, map_x, map_y); \
+ { \
+ const int nat_x = _nat_x, nat_y = _nat_y;
+
+#define index_do_in_native_pos_end
\
+ } \
+}
+
+/* Provide a block to convert from map to natural coordinates. This allows
+ * you to use a natural version of the map position within the block. Note
+ * that the natural position is declared as const and can't be changed
+ * inside the block. */
+#define index_do_in_natural_pos(ntl_x, ntl_y, index) \
+{ \
+ int _ntl_x, _ntl_y; \
+ index_to_natural_pos(&_ntl_x, &_ntl_y, index); \
+ { \
+ const int ntl_x = _ntl_x, ntl_y = _ntl_y;
+
+#define do_in_natural_pos_end \
+ } \
+}
+
+bool normalize_nat_pos(int *x, int *y);
+bool is_normal_nat_pos(int x, int y);
+
void adjust_int_map(int *int_map, int int_map_max);
void create_placed_map(void);
void destroy_placed_map(void);
@@ -39,6 +72,7 @@
bool placed_map_is_initialized(void);
void set_all_ocean_tiles_placed(void) ;
void set_placed_near_pos(int map_x, int map_y, int dist);
+void smooth_int_map(int *int_map, bool zeroes_at_edges);
#endif /* FC__UTILITIES_H */
diff -ruN -Xfreeciv/diff_ignore freeciv/server/savegame.c
freeciv_/server/savegame.c
--- freeciv/server/savegame.c 2004-09-14 12:04:31.000000000 +0200
+++ freeciv_/server/savegame.c 2004-09-15 12:09:42.516077560 +0200
@@ -3093,6 +3093,9 @@
map.riches = secfile_lookup_int(file, "map.riches");
map.huts = secfile_lookup_int(file, "map.huts");
map.generator = secfile_lookup_int(file, "map.generator");
+ map.generator_smoth =
+ secfile_lookup_int_default(file,
+ MAP_DEFAULT_GENERATOR_SMOTH, "map.generator_smoth");
map.seed = secfile_lookup_int(file, "map.seed");
map.landpercent = secfile_lookup_int(file, "map.landpercent");
map.grasssize =
@@ -3485,6 +3488,7 @@
secfile_insert_int(file, map.forestsize, "map.forestsize");
secfile_insert_int(file, map.huts, "map.huts");
secfile_insert_int(file, map.generator, "map.generator");
+ secfile_insert_int(file, map.generator_smoth, "map.generator_smoth");
secfile_insert_bool(file, map.have_huts, "map.have_huts");
secfile_insert_int(file, map.temperature, "map.temperature");
secfile_insert_bool(file, map.alltemperate, "map.alltemperate");
diff -ruN -Xfreeciv/diff_ignore freeciv/server/settings.c
freeciv_/server/settings.c
--- freeciv/server/settings.c 2004-09-14 12:04:31.000000000 +0200
+++ freeciv_/server/settings.c 2004-09-15 12:27:27.456182056 +0200
@@ -274,6 +274,16 @@
"(Zero indicates a scenario map.)"), NULL,
MAP_MIN_GENERATOR, MAP_MAX_GENERATOR, MAP_DEFAULT_GENERATOR)
+ GEN_INT("generator_smoth", map.generator_smoth,
+ SSET_MAP_GEN, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
+ N_("number of smoth passes for random generator 1"),
+ N_("1 = do small continents and islands with irregular shore,"
+ " nice in small maps;\n\n"
+ "3 = default value wiht medium continents ;\n\n"
+ "8 = big continents, only nice for huges maps.\n\n"), NULL,
+ MAP_MIN_GENERATOR_SMOTH, MAP_MAX_GENERATOR_SMOTH,
+ MAP_DEFAULT_GENERATOR_SMOTH)
+
GEN_BOOL("tinyisles", map.tinyisles,
SSET_MAP_GEN, SSET_GEOLOGY, SSET_RARE, SSET_TO_CLIENT,
N_("Presence of 1x1 islands"),
- [Freeciv-Dev] (PR#10124) PATCH: new generator 1, hmap generator (1,5) mv to height_map.[ch],
Marcelo Burda via RT <=
- [Freeciv-Dev] (PR#10124) PATCH: new generator 1, hmap generator (1,5) mv to height_map.[ch], Marcelo Burda via RT, 2004/09/15
- [Freeciv-Dev] (PR#10124) PATCH: new generator 1, hmap generator (1,5) mv to height_map.[ch], Marcelo Burda via RT, 2004/09/15
- [Freeciv-Dev] (PR#10124) PATCH: new generator 1, hmap generator (1,5) mv to height_map.[ch], Marcelo Burda via RT, 2004/09/16
|
|