From 1be42f203d149554f64c1d7abf0e83daef68ccd2 Mon Sep 17 00:00:00 2001 From: Dino Date: Sat, 27 Dec 2025 23:26:03 -0500 Subject: [PATCH] fix bug in can_reclaim_ocean() HR #1278 --- common/map.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/common/map.c b/common/map.c index 664b2b66ca..b96d929e82 100644 --- a/common/map.c +++ b/common/map.c @@ -725,15 +725,24 @@ bool is_safe_ocean(const struct civ_map *nmap, const struct tile *ptile) This function returns true if the tile at the given location can be "reclaimed" from ocean into land. This is the case only when there are a sufficient number of adjacent tiles that are not ocean. + + The obvious way to do this would be like in can_channel_land() below - + int land_tiles = count_terrain_class_near_tile(nmap, ptile, + FALSE, TRUE, TC_LAND); + But we want to count Inaccessible and "off-the-map" tiles as land tiles, + so do things differently. Need some extra float calculations to fix bug. + See HR #1278. ***********************************************************************/ bool can_reclaim_ocean(const struct civ_map *nmap, const struct tile *ptile) { - int land_tiles = 100 - count_terrain_class_near_tile(nmap, ptile, - FALSE, TRUE, - TC_OCEAN); + int num_surrounding_tiles = wld.map.num_valid_dirs; + float pct = terrain_control.ocean_reclaim_requirement_pct/100.0; + int land_tiles = num_surrounding_tiles - + count_terrain_class_near_tile(nmap, ptile, + FALSE, FALSE, TC_OCEAN); - return land_tiles >= terrain_control.ocean_reclaim_requirement_pct; + return land_tiles >= ceil(pct * num_surrounding_tiles); } /*******************************************************************//** -- 2.31.0