[Freeciv-Dev] Re: (PR#9799) PATCH: rewrited 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#9799) PATCH: rewrited adjust_map() |
From: |
"Marcelo Burda" <mburda@xxxxxxxxx> |
Date: |
Tue, 31 Aug 2004 14:24:06 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9799 >
Le mar 31/08/2004 à 16:57, Mateusz Stefek a écrit :
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=9799 >
>
> > [mburda - Tue Aug 31 14:29:27 2004]:
> >
> > Le mar 31/08/2004 à 16:11, Mateusz Stefek a écrit :
> > > <URL: http://rt.freeciv.org/Ticket/Display.html?id=9799 >
> > >
> > > > [mburda - Tue Aug 31 13:03:34 2004]:
> > >
> > > + for(i = -1; (++i) < maxval;) {
> > >
> > > there's a simpler form:
> > > for (i = 0; i < maxval; i++) {
> > > }
> > >
> > this is a point of ( like or not like) normally all C coders can see a
> > ++i with not problem, i am not a C coder! but i like it
> > but if you not like it, be free to change, i am not problem!!
> I understand it, but it took me few seconds to imagine a set of values
> which are used by i.
> Please change it.
done
>
> > >
> > > + /* apply the linearize function */
> > > + whole_map_iterate(x, y) {
> > > + hmap(x, y) = frequencies[hmap(x, y)];
> > > + } whole_map_iterate_end;
> > >
> > > Are you sure that hmap(x, y) is < maxval ?. I'm not
> > >
> > yes, in the loop
> >
> > whole_map_iterate(x, y) {
> > hmap(x, y) = (hmap(x, y) - min) * maxval;
> > hmap(x, y) /= max;
> > frequencies[hmap(x, y)]++;
> > } whole_map_iterate_end;
> >
> > this is done
> but if hmap(x, y) = max ?
> and min = 0
>
> and BTW:
> - hmap(x, y) /= max
> + hmap(x, y) /= (max - min)
>
ok, ok, some day i am more stupid, others ones a little less, today is
not the best.
FIXED
> --
> mateusz
>
thx, Marcelo
diff -ruN -Xfreeciv/diff_ignore freeciv/common/map.h
freeciv_improved/common/map.h
--- freeciv/common/map.h 2004-08-26 20:37:52.000000000 +0200
+++ freeciv_improved/common/map.h 2004-08-31 21:19:21.015863600 +0200
@@ -229,7 +229,7 @@
void reset_move_costs(int x, int y);
/* Maximum value of index (for sanity checks and allocations) */
-#define MAX_MAP_INDEX map.xsize * map.ysize
+#define MAX_MAP_INDEX (map.xsize * map.ysize)
#ifdef DEBUG
#define CHECK_MAP_POS(x,y) assert(is_normal_map_pos((x),(y)))
diff -ruN -Xfreeciv/diff_ignore freeciv/server/mapgen.c
freeciv_improved/server/mapgen.c
--- freeciv/server/mapgen.c 2004-08-28 18:50:49.000000000 +0200
+++ freeciv_improved/server/mapgen.c 2004-08-31 21:21:00.729704792 +0200
@@ -63,7 +63,7 @@
static void mapgenerator4(void);
static void mapgenerator5(void);
static void smooth_map(void);
-static void adjust_map(void);
+static void adjust_hmap(void);
static void adjust_terrain_param(void);
#define RIVERS_MAXTRIES 32767
@@ -75,8 +75,18 @@
A value of 2 means river. -Erik Sigra */
static int *river_map;
+/*******************************************************************
+ * Height map information
+ ******************************************************************/
static int *height_map;
-static int maxval=0;
+/* maximum value for height_map after be adjusted */
+static const int maxval = 1000;
+/* after call make_land(), this is the level of sea in height_map */
+static int seaval = 0;
+/* after call make_mountains(), this the minimum level where mountains and hill
+ probably will placed */
+static int mountainsval = 0;
+
static int forests=0;
struct isledata {
@@ -106,6 +116,17 @@
? MAX_TEMP * (3 + 2 * SQSIZE) / (100 * SQSIZE) \
: 5 * MAX_TEMP / 100 /* 5% for all maps */)
+/********************************************************************
+ * used to initialize a array with some value
+ ********************************************************************/
+#define INITIALIZE_ARRAY(_a, _size, _val) \
+ { \
+ int _ini_index = 0; \
+ for(; _ini_index < (_size);_ini_index++) { \
+ (_a)[_ini_index] = (_val); \
+ } \
+ }
+
/****************************************************************************
Returns the temperature of this map position. This is a value in the
range of 0 to MAX_TEMP (inclusive).
@@ -293,28 +314,11 @@
the map.mountains value, so increase map.mountains and you'll get more
hills and mountains (and vice versa).
**************************************************************************/
-static void make_mountains(int thill)
+static void make_mountains(void)
{
- int mount;
- int j;
-
- for (j = 0; j < 10; j++) {
- mount = 0;
- whole_map_iterate(x, y) {
- if (hmap(x, y) > thill) {
- mount++;
- }
- } whole_map_iterate_end;
- if (mount < (map_num_tiles() * map.mountains) / 1000) {
- thill *= 95;
- } else {
- thill *= 105;
- }
- thill /= 100;
- }
-
+ mountainsval = ((maxval - seaval)* (100 - map.mountains)) / 100 + seaval;
whole_map_iterate(x, y) {
- if (hmap(x, y) > thill && !is_ocean(map_get_terrain(x,y))) {
+ if (hmap(x, y) > mountainsval && !is_ocean(map_get_terrain(x,y))) {
/* Randomly place hills and mountains on "high" tiles. But don't
* put hills near the poles (they're too green). */
if (myrand(100) > 75
@@ -1135,37 +1139,20 @@
**************************************************************************/
static void make_land(void)
{
- int tres;
- int count=0;
- int total = (map_num_tiles() * map.landpercent) / 100;
- int forever=0;
-
- adjust_map();
+ adjust_hmap();
normalize_hmap_poles();
- tres = (maxval * map.landpercent) / 100;
-
- do {
- forever++;
- if (forever>50) break; /* loop elimination */
- count=0;
- whole_map_iterate(x, y) {
- if (hmap(x, y) < tres)
- map_set_terrain(x, y, T_OCEAN);
- else {
- map_set_terrain(x, y, T_NOT_PLACED);
- count++;
- }
- } whole_map_iterate_end;
- if (count>total)
- tres*=11;
- else
- tres*=9;
- tres/=10;
- } while (abs(total-count)> maxval/40);
+ seaval = (maxval *(100 - map.landpercent)) / 100;
+ whole_map_iterate(x, y) {
+ if (hmap(x, y) < seaval)
+ map_set_terrain(x, y, T_OCEAN);
+ else {
+ map_set_terrain(x, y, T_NOT_PLACED);
+ }
+ } whole_map_iterate_end;
renormalize_hmap_poles();
make_polar_land(); /* make extra land at poles*/
- make_mountains(maxval*8/10);
+ make_mountains();
make_arctic();
make_tundra();
make_forests();
@@ -1643,25 +1630,45 @@
}
/**************************************************************************
- Adjust the map so that its minimum height is 0. This raises or lowers
- every position by a fixed amount and sets the "maxval" global variable
- to hold the maximum height.
+ Adjust the hmap to be a linearize distribution of heights
+ form 0 to maxval (maxval is a global const )
+
+ ( hmap[x,y] < 0.13 * maxval) handle the 13% lowerest part of the map
+ slope can globaly be estiamted as maxval*sqrt(num_of_isles)/linear_size
**************************************************************************/
-static void adjust_map(void)
+static void adjust_hmap(void)
{
- int minval = maxval = hnat(0, 0);
+ int i, min = hnat(0, 0), max = min;
+ int count = 0, frequencies[maxval];
+
+ INITIALIZE_ARRAY(frequencies, maxval, 0);
/* Determine minimum and maximum heights. */
whole_map_iterate(x, y) {
- maxval = MAX(maxval, hmap(x, y));
- minval = MIN(minval, hmap(x, y));
+ max = MAX(max, hmap(x, y));
+ min = MIN(min, hmap(x, y));
} whole_map_iterate_end;
- /* Translate heights so the minimum height is 0. */
- maxval -= minval;
+ /* Translate heights so the minimum height is 0 and maximum is maxval.
+ and count the number of accurnecies in all values to initialise the
+ frequencies[] (frequency is the right word in probability for it) */
+ max -= min;
whole_map_iterate(x, y) {
- hmap(x, y) -= minval;
+ hmap(x, y) = (hmap(x, y) - min) * (maxval - 1);
+ hmap(x, y) /= max;
+ frequencies[hmap(x, y)]++;
} whole_map_iterate_end;
+
+ /* create the linearize function as "incremental" frequencies */
+ for(i = 0; i < maxval; i++) {
+ count += frequencies[i];
+ frequencies[i] = (count * maxval ) / MAX_MAP_INDEX;
+ }
+
+ /* apply the linearize function */
+ whole_map_iterate(x, y) {
+ hmap(x, y) = frequencies[hmap(x, y)];
+ } whole_map_iterate_end;
}
/**************************************************************************
- [Freeciv-Dev] (PR#9799) PATCH: rewrited adjust_map(), (continued)
- [Freeciv-Dev] (PR#9799) PATCH: rewrited adjust_map(), Marcelo Burda, 2004/08/31
- [Freeciv-Dev] (PR#9799) PATCH: rewrited adjust_map(), Mateusz Stefek, 2004/08/31
- [Freeciv-Dev] Re: (PR#9799) PATCH: rewrited adjust_map(), Marcelo Burda, 2004/08/31
- [Freeciv-Dev] Re: (PR#9799) PATCH: rewrited adjust_map(), Jason Short, 2004/08/31
- [Freeciv-Dev] Re: (PR#9799) PATCH: rewrited adjust_map(), Jason Short, 2004/08/31
- [Freeciv-Dev] Re: (PR#9799) PATCH: rewrited adjust_map(), Jason Short, 2004/08/31
- [Freeciv-Dev] Re: (PR#9799) PATCH: rewrited adjust_map(), Marcelo Burda, 2004/08/31
- [Freeciv-Dev] (PR#9799) PATCH: rewrited adjust_map(), Mateusz Stefek, 2004/08/31
- [Freeciv-Dev] Re: (PR#9799) PATCH: rewrited adjust_map(), Marcelo Burda, 2004/08/31
- [Freeciv-Dev] (PR#9799) PATCH: rewrited adjust_map(), Mateusz Stefek, 2004/08/31
- [Freeciv-Dev] Re: (PR#9799) PATCH: rewrited adjust_map(),
Marcelo Burda <=
- [Freeciv-Dev] Re: (PR#9799) PATCH: rewrited adjust_map(), Jason Short, 2004/08/31
- [Freeciv-Dev] (PR#9799) PATCH: rewrited adjust_map(), Mateusz Stefek, 2004/08/31
- [Freeciv-Dev] (PR#9799) PATCH: rewrited adjust_map(), Mateusz Stefek, 2004/08/31
- [Freeciv-Dev] Re: (PR#9799) PATCH: rewrited adjust_map(), Jason Short, 2004/08/31
- [Freeciv-Dev] (PR#9799) PATCH: rewrited adjust_map(), Mateusz Stefek, 2004/08/31
|
|