From ef9406d2d8fd0efc475b1a81d72ccc45ae4c48d8 Mon Sep 17 00:00:00 2001 From: Alina Lenk Date: Thu, 24 Mar 2022 18:01:49 +0100 Subject: [PATCH 3/3] mapgen: Add minimum parameter to adjust_int_map[_filtered]() See osdn #44173 Signed-off-by: Alina Lenk --- server/generator/fracture_map.c | 2 +- server/generator/height_map.c | 4 ++-- server/generator/mapgen_utils.c | 17 ++++++++++------- server/generator/mapgen_utils.h | 14 ++++++++------ server/generator/startpos.c | 2 +- server/generator/temperature_map.c | 8 ++------ 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/server/generator/fracture_map.c b/server/generator/fracture_map.c index 0ef3ad514c..52610db84c 100644 --- a/server/generator/fracture_map.c +++ b/server/generator/fracture_map.c @@ -135,7 +135,7 @@ void make_fracture_map(void) } } whole_map_iterate_end; - adjust_int_map(height_map, hmap_max_level); + adjust_int_map(height_map, 0, hmap_max_level); free(landmass); free(fracture_points); } diff --git a/server/generator/height_map.c b/server/generator/height_map.c index a06d41e851..274be276ca 100644 --- a/server/generator/height_map.c +++ b/server/generator/height_map.c @@ -108,7 +108,7 @@ void make_random_hmap(int smooth) smooth_int_map(height_map, TRUE); } - adjust_int_map(height_map, hmap_max_level); + adjust_int_map(height_map, 0, hmap_max_level); } /**********************************************************************//** @@ -256,7 +256,7 @@ void make_pseudofractal1_hmap(int extra_div) hmap(ptile) = 8 * hmap(ptile) + fc_rand(4) - 2; } whole_map_iterate_end; - adjust_int_map(height_map, hmap_max_level); + adjust_int_map(height_map, 0, hmap_max_level); } /**********************************************************************//** diff --git a/server/generator/mapgen_utils.c b/server/generator/mapgen_utils.c index 5e3a309a6c..61a14a88e9 100644 --- a/server/generator/mapgen_utils.c +++ b/server/generator/mapgen_utils.c @@ -112,17 +112,20 @@ void set_placed_near_pos(struct tile *ptile, int dist) } /**********************************************************************//** - Change the values of the integer map, so that they contain ranking of each - tile scaled to [0 .. int_map_max]. - The lowest 20% of tiles will have values lower than 0.2 * int_map_max. + Change the values of the integer map, so that they contain ranking of + each tile scaled to [int_map_min .. int_map_max]. + E.g. the lowest 20% of tiles will have values lower than + int_map_min + 0.2 * (int_map_max - int_map_min). If filter is non-null then it only tiles for which filter(ptile, data) is TRUE will be considered. **************************************************************************/ -void adjust_int_map_filtered(int *int_map, int int_map_max, void *data, - bool (*filter)(const struct tile *ptile, - const void *data)) +void adjust_int_map_filtered(int *int_map, int int_map_min, + int int_map_max, void *data, + bool (*filter)(const struct tile *ptile, + const void *data)) { + const int int_map_delta = int_map_max - int_map_min; int minval = 0, maxval = 0, total = 0; bool first = TRUE; @@ -160,7 +163,7 @@ void adjust_int_map_filtered(int *int_map, int int_map_max, void *data, /* create the linearize function as "incremental" frequencies */ for (i = 0; i < size; i++) { count += frequencies[i]; - frequencies[i] = (count * int_map_max) / total; + frequencies[i] = int_map_min + (count * int_map_delta) / total; } /* apply the linearize function */ diff --git a/server/generator/mapgen_utils.h b/server/generator/mapgen_utils.h index c3474078af..b559dd8f68 100644 --- a/server/generator/mapgen_utils.h +++ b/server/generator/mapgen_utils.h @@ -98,12 +98,14 @@ struct extra_type *pick_resource(const struct terrain *pterrain); bool is_normal_nat_pos(int x, int y); /* int maps tools */ -void adjust_int_map_filtered(int *int_map, int int_map_max, void *data, - bool (*filter)(const struct tile *ptile, - const void *data)); -#define adjust_int_map(int_map, int_map_max) \ - adjust_int_map_filtered(int_map, int_map_max, (void *)NULL, \ - (bool (*)(const struct tile *ptile, const void *data) )NULL) +void adjust_int_map_filtered(int *int_map, int int_map_min, + int int_map_max, void *data, + bool (*filter)(const struct tile *ptile, + const void *data)); +#define adjust_int_map(int_map, int_map_min, int_map_max) \ + adjust_int_map_filtered(int_map, int_map_min, int_map_max, \ + (void *)NULL, \ + (bool (*)(const struct tile *ptile, const void *data))NULL) void smooth_int_map(int *int_map, bool zeroes_at_edges); /* placed_map tool */ diff --git a/server/generator/startpos.c b/server/generator/startpos.c index d97e490d00..13b234d70d 100644 --- a/server/generator/startpos.c +++ b/server/generator/startpos.c @@ -379,7 +379,7 @@ bool create_start_positions(enum map_startpos mode, } whole_map_iterate_end; /* evaluate the best places on the map */ - adjust_int_map_filtered(tile_value, 1000, NULL, filter_starters); + adjust_int_map_filtered(tile_value, 0, 1000, NULL, filter_starters); /* Sort the islands so the best ones come first. Note that islands[0] is * unused so we just skip it. */ diff --git a/server/generator/temperature_map.c b/server/generator/temperature_map.c index ab02a03446..470146d379 100644 --- a/server/generator/temperature_map.c +++ b/server/generator/temperature_map.c @@ -154,12 +154,8 @@ void create_tmap(bool real) * make sense - if most variation comes from height and coast, don't try * to squish that back into its original narrow range */ if (REAL_COLATITUDE_RANGE(wld.map) >= MAX_COLATITUDE * 2 / 5) { - if (MIN_REAL_COLATITUDE(wld.map) > 0) { - /* FIXME: adjust_int_map always makes 0 the lowest value - * ~> can't call adjust until it supports constant offsets */ - } else { - adjust_int_map(temperature_map, MAX_REAL_COLATITUDE(wld.map)); - } + adjust_int_map(temperature_map, MIN_REAL_COLATITUDE(wld.map), + MAX_REAL_COLATITUDE(wld.map)); } /* now simplify to 4 base values */ -- 2.17.1