99#include < vector>
1010
1111#include " coordinates.h"
12+ #include " cuboid_rectangle.h"
1213#include " debug.h"
1314#include " enums.h"
1415#include " flood_fill.h"
@@ -261,8 +262,14 @@ void overmap::place_lakes( const std::vector<const overmap *> &neighbor_overmaps
261262 double noise_threshold = settings_lake.noise_threshold_lake ;
262263 const int lake_depth = settings_lake.lake_depth ;
263264
265+ // For cases where lakes take up most or all of the map, we need to stop the flood-fill
266+ // from being unbounded. However, the bounds cannot be simply the overmap edges, or the
267+ // shorelines will not be generated properly.
268+ inclusive_rectangle<point_om_omt> considered_bounds ( point_om_omt ( -5 , -5 ),
269+ point_om_omt ( OMAPX + 5 , OMAPY + 5 ) );
264270 const auto is_lake = [&]( const point_om_omt & p ) {
265- return omt_lake_noise_threshold ( origin, p, noise_threshold );
271+ return considered_bounds.contains ( p ) &&
272+ settings_lake.invert_lakes ^ omt_lake_noise_threshold ( origin, p, noise_threshold );
266273 };
267274
268275 const oter_id lake_surface ( " lake_surface" );
@@ -281,7 +288,7 @@ void overmap::place_lakes( const std::vector<const overmap *> &neighbor_overmaps
281288 }
282289
283290 // It's a lake if it exceeds the noise threshold defined in the region settings.
284- if ( !omt_lake_noise_threshold ( origin, seed_point, noise_threshold ) ) {
291+ if ( !is_lake ( seed_point ) ) {
285292 continue ;
286293 }
287294
0 commit comments