[Freeciv-Dev] Re: (PR#9799) PATCH: rewrited adjust_map()
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9799 >
Marcelo Burda wrote:
> @@ -75,7 +75,8 @@
> static int *river_map;
>
> static int *height_map;
> -static int maxval=0;
> +static const int maxval = 1000;
> +static int seaval=0, reliefval =0;
> static int forests=0;
seaval is good. But reliefval should be mountainval I think (or maybe
hillval). We haven't agreed on a name for "relief" but it won't be
called relief. And slope isn't a cutoff it's a scale.
> struct isledata {
> @@ -101,6 +102,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, MAX, VAL) \
> + { \
> + int INI_INEX; \
> + for(INI_INEX = 0; INI_INEX < (MAX);INI_INEX++) { \
> + (A)[INI_INEX] = (VAL); \
> + } \
> + }
The parameters don't need to be capitalized. but INI_INDEX should be
_ini_index.
> -static void make_mountains(int thill)
> +static void make_relief()
Same problem with naming: I think this should stay as make_mountains for
now. Also the parameter should be (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;
> - }
> -
> + reliefval = ((maxval - seaval)* (100 - map.mountains)) / 100 + seaval;
Nice.
> -static void adjust_map(void)
> +static void adjust_hmap(void)
> {
> - int minval = maxval = hnat(0, 0);
> + int i, min = hnat(0, 0), max = hnat(0, 0);
> + int count=0, f[maxval];
> +
> + INITIALIZE_ARRAY(f,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 pos in granularity */
> + max -= min;
> whole_map_iterate(x, y) {
> - hmap(x, y) -= minval;
> + hmap(x, y) = (hmap(x, y) - min) * maxval;
> + hmap(x, y) /= max;
> + f[hmap(x, y)]++;
> } whole_map_iterate_end;
> +
> + /* create the linearize function */
> + for(i = -1; i++ < maxval;) {
> + count += f[i];
> + f[i] = (count * maxval) / (map.xsize * map.ysize) ;
> + }
> +
> + /* apply the linearize function */
> + whole_map_iterate(x, y) {
> + hmap(x, y) = f[hmap(x, y)];
> + } whole_map_iterate_end;
> }
I think this can be better done using qsort and skipping the translation
step.
jason
- [Freeciv-Dev] Re: (PR#9799) PATCH: rewrited adjust_map(), Marcelo Burda, 2004/08/25
- [Freeciv-Dev] (PR#9799) PATCH: rewrited adjust_map(), Marcelo Burda, 2004/08/25
- [Freeciv-Dev] Re: (PR#9799) PATCH: rewrited adjust_map(),
Jason Short <=
- [Freeciv-Dev] (PR#9799) PATCH: rewrited adjust_map(), Marcelo Burda, 2004/08/27
- [Freeciv-Dev] (PR#9799) PATCH: rewrited adjust_map(), Marcelo Burda, 2004/08/27
- [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
|
|