From f9d192e14153de7b7b1106c2ca559462e9fc937a Mon Sep 17 00:00:00 2001 From: Alina Lenk Date: Wed, 23 Mar 2022 20:01:56 +0100 Subject: [PATCH 2/2] mapgen: Remove direct references to alltemperate and singlepole See osdn #44167 Signed-off-by: Alina Lenk --- server/generator/mapgen.c | 4 +++- server/generator/mapgen_topology.c | 19 +++++++++---------- server/generator/mapgen_topology.h | 17 ++++++++++++++++- server/generator/temperature_map.c | 19 +++++++++++++------ 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/server/generator/mapgen.c b/server/generator/mapgen.c index 703d25de6a..86ab016eaf 100644 --- a/server/generator/mapgen.c +++ b/server/generator/mapgen.c @@ -152,7 +152,9 @@ static void make_rivers(void); static void river_types_init(void); -#define HAS_POLES (wld.map.server.temperature < 70 && !wld.map.alltemperate) +/* Note: Only use after calling generator_init_topology() */ +#define HAS_POLES \ + (MIN(COLD_LEVEL, 2 * ICE_BASE_LEVEL) > MIN_REAL_COLATITUDE(wld.map)) /* These are the old parameters of terrains types in % TODO: they depend on the hardcoded terrains */ diff --git a/server/generator/mapgen_topology.c b/server/generator/mapgen_topology.c index ce60212055..4026d04c2e 100644 --- a/server/generator/mapgen_topology.c +++ b/server/generator/mapgen_topology.c @@ -43,11 +43,7 @@ int map_colatitude(const struct tile *ptile) latitude = map_signed_latitude(ptile); latitude = MAX(latitude, -latitude); -#if MAX_COLATITUDE == MAP_MAX_LATITUDE - return MAX_COLATITUDE - latitude; -#else - return MAX_COLATITUDE - (latitude * MAX_COLATITUDE / MAP_MAX_LATITUDE); -#endif + return colat_from_abs_lat(latitude); } /************************************************************************//** @@ -249,11 +245,14 @@ void generator_init_topology(bool autosize) + 2 * MAX_COLATITUDE * sqsize) / (100 * sqsize); } - /* correction for single pole (Flat Earth) */ - if (wld.map.single_pole) { - if (!current_topo_has_flag(TF_WRAPY) || !current_topo_has_flag(TF_WRAPX)) { - ice_base_colatitude /= 2; - } + /* Correction for single-pole and similar map types + * The pole should be the same size relative to world size, + * so the smaller the actual latitude range, + * the smaller the ice base level has to be. */ + if (MAP_REAL_LATITUDE_RANGE(wld.map) < (2 * MAP_MAX_LATITUDE)) { + ice_base_colatitude = ((ice_base_colatitude + * MAP_REAL_LATITUDE_RANGE(wld.map)) + / (2 * MAP_MAX_LATITUDE)); } if (wld.map.server.huts_absolute >= 0) { diff --git a/server/generator/mapgen_topology.h b/server/generator/mapgen_topology.h index c2c7c823f5..759b6bb1ed 100644 --- a/server/generator/mapgen_topology.h +++ b/server/generator/mapgen_topology.h @@ -17,9 +17,24 @@ #include "support.h" /* bool type */ /* This is the maximal colatitude at equators returned by map_colatitude() - * When changing this, make sure map_colatitude() still works correctly */ + * When changing this, make sure colat_from_abs_lat() still works */ #define MAX_COLATITUDE MAP_MAX_LATITUDE +#if MAX_COLATITUDE == MAP_MAX_LATITUDE +#define colat_from_abs_lat(_lat) (MAX_COLATITUDE - _lat) +#else +#define colat_from_abs_lat(_lat) \ + (MAX_COLATITUDE - (_lat * MAX_COLATITUDE / MAP_MAX_LATITUDE)) +#endif + +/* Maximum and minimum colatitude actually present in the world */ +#define MAX_REAL_COLATITUDE(_nmap) \ + colat_from_abs_lat(MAP_MIN_ABS_LATITUDE(_nmap)) +#define MIN_REAL_COLATITUDE(_nmap) \ + colat_from_abs_lat(MAP_MAX_ABS_LATITUDE(_nmap)) +#define REAL_COLATITUDE_RANGE(_nmap) \ + (MAX_REAL_COLATITUDE(_nmap) - MIN_REAL_COLATITUDE(_nmap)) + int get_sqsize(void); /* Size safe Unit of colatitude. 0 is not allowed due to possibility of diff --git a/server/generator/temperature_map.c b/server/generator/temperature_map.c index b17e8d5660..ab02a03446 100644 --- a/server/generator/temperature_map.c +++ b/server/generator/temperature_map.c @@ -148,13 +148,20 @@ void create_tmap(bool real) tmap(ptile) = t * (1.0 + temperate) * (1.0 + height); } } whole_map_iterate_end; - /* adjust to get well sizes frequencies */ - /* Notice: if colatitude is loaded from a scenario never call adjust. - Scenario may have an odd colatitude distribution and adjust will - break it */ - if (!wld.map.alltemperate) { - adjust_int_map(temperature_map, MAX_COLATITUDE); + + /* adjust to get evenly distributed frequencies + * Only call adjust when the colatitude range is large enough for this to + * 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)); + } } + /* now simplify to 4 base values */ for (i = 0; i < MAP_INDEX_SIZE; i++) { int t = temperature_map[i]; -- 2.17.1