From 020d3134d50a9ea026f68205c8874978ef1dd302 Mon Sep 17 00:00:00 2001 From: Alina Lenk Date: Wed, 23 Mar 2022 15:19:02 +0100 Subject: [PATCH] Remove direct references to alltemperate and singlepole in common code See osdn #44166 Signed-off-by: Alina Lenk --- common/map.c | 19 +++---------------- common/map.h | 23 +++++++++++++++++++++++ common/requirements.c | 5 +---- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/common/map.c b/common/map.c index ae43046e6a..bc7b043c9b 100644 --- a/common/map.c +++ b/common/map.c @@ -1579,21 +1579,8 @@ int map_signed_latitude(const struct tile *ptile) int north_latitude, south_latitude; double southness; - /* TODO: Move upper and lower latitude bounds to server settings - * (replacing alltemperate and singlepole). */ - if (wld.map.alltemperate) { - /* An all-temperate map has "average" temperature everywhere. */ - north_latitude = south_latitude = MAP_MAX_LATITUDE / 2; - } else if (wld.map.single_pole) { - /* Partial planetary map. A polar zone is placed at the north end - * and a tropical zone at the south end. */ - north_latitude = MAP_MAX_LATITUDE; - south_latitude = 0; - } else { - /* Full latitude range */ - north_latitude = MAP_MAX_LATITUDE; - south_latitude = -MAP_MAX_LATITUDE; - } + north_latitude = MAP_NORTH_LATITUDE(wld.map); + south_latitude = MAP_SOUTH_LATITUDE(wld.map); if (north_latitude == south_latitude) { /* Single-latitude / all-temperate map; no need to examine tile. */ @@ -1604,7 +1591,7 @@ int map_signed_latitude(const struct tile *ptile) southness = map_relative_southness(ptile); - /* Linear interpolation between maximum and minimum latitude. + /* Linear interpolation between northernmost and southernmost latitude. * Truncate / round towards zero so northern and southern hemisphere * are symmetrical when south_latitude = -north_latitude. */ return north_latitude * (1.0 - southness) + south_latitude * southness; diff --git a/common/map.h b/common/map.h index 9e09180a11..68c6977f3c 100644 --- a/common/map.h +++ b/common/map.h @@ -562,8 +562,31 @@ bool is_cardinal_dir(enum direction8 dir); extern const int DIR_DX[8]; extern const int DIR_DY[8]; +/* Latitude granularity, irrespective of map/generator settings */ #define MAP_MAX_LATITUDE 1000 +/* Northernmost and southernmost latitude for the given map */ +#define MAP_NORTH_LATITUDE(_nmap) \ + ((_nmap).alltemperate ? (MAP_MAX_LATITUDE / 2) : MAP_MAX_LATITUDE) +#define MAP_SOUTH_LATITUDE(_nmap) \ + ((_nmap).alltemperate \ + ? (MAP_MAX_LATITUDE / 2) \ + : ((_nmap).single_pole ? 0 : (-MAP_MAX_LATITUDE))) + +/* Maximum and minimum latitude present in the given map */ +#define MAP_MAX_REAL_LATITUDE(_nmap) \ + MAX(MAP_NORTH_LATITUDE(_nmap), MAP_SOUTH_LATITUDE(_nmap)) +#define MAP_MIN_REAL_LATITUDE(_nmap) \ + MIN(MAP_NORTH_LATITUDE(_nmap), MAP_SOUTH_LATITUDE(_nmap)) +#define MAP_REAL_LATITUDE_RANGE(_nmap) \ + (MAP_MAX_REAL_LATITUDE(_nmap) - MAP_MIN_REAL_LATITUDE(_nmap)) + +/* Maximum and minimum absolute latitude */ +#define MAP_MAX_ABS_LATITUDE(_nmap) \ + MAX(MAP_MAX_REAL_LATITUDE(_nmap), -MAP_MIN_REAL_LATITUDE(_nmap)) +#define MAP_MIN_ABS_LATITUDE(_nmap) \ + MAX(0, MAX(MAP_MIN_REAL_LATITUDE(_nmap), -MAP_MAX_REAL_LATITUDE(_nmap))) + int map_signed_latitude(const struct tile *ptile); /* Used for network transmission; do not change. */ diff --git a/common/requirements.c b/common/requirements.c index 1de5882bac..1ae3d2ab11 100644 --- a/common/requirements.c +++ b/common/requirements.c @@ -3813,10 +3813,7 @@ bool universal_never_there(const struct universal *source) case VUT_EXTRAFLAG: return !extra_flag_is_in_use(source->value.extraflag); case VUT_MINLATITUDE: - /* If the map is not alltemperate, there is always a north pole with - * MAP_MAX_LATITUDE. Otherwise, everything is MAP_MAX_LATITUDE / 2. */ - return (wld.map.alltemperate - && source->value.latitude > (MAP_MAX_LATITUDE / 2)); + return source->value.latitude > MAP_MAX_REAL_LATITUDE(wld.map); case VUT_OTYPE: case VUT_SPECIALIST: case VUT_AI_LEVEL: -- 2.17.1