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,15 +262,16 @@ 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
268- const oter_id lake_surface ( " lake_surface" );
269- const oter_id lake_shore ( " lake_shore" );
270- const oter_id lake_water_cube ( " lake_water_cube" );
271- const oter_id lake_bed ( " lake_bed" );
272-
273275 // We'll keep track of our visited lake points so we don't repeat the work.
274276 std::unordered_set<point_om_omt> visited;
275277
@@ -281,7 +283,7 @@ void overmap::place_lakes( const std::vector<const overmap *> &neighbor_overmaps
281283 }
282284
283285 // 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 ) ) {
286+ if ( !is_lake ( seed_point ) ) {
285287 continue ;
286288 }
287289
@@ -350,14 +352,14 @@ void overmap::place_lakes( const std::vector<const overmap *> &neighbor_overmaps
350352 }
351353 }
352354
353- ter_set ( tripoint_om_omt ( p, 0 ), shore ? lake_shore : lake_surface );
355+ ter_set ( tripoint_om_omt ( p, 0 ), shore ? settings_lake. shore : settings_lake. surface );
354356
355357 // If this is not a shore, we'll make our subsurface lake cubes and beds.
356358 if ( !shore ) {
357359 for ( int z = -1 ; z > lake_depth; z-- ) {
358- ter_set ( tripoint_om_omt ( p, z ), lake_water_cube );
360+ ter_set ( tripoint_om_omt ( p, z ), settings_lake. interior );
359361 }
360- ter_set ( tripoint_om_omt ( p, lake_depth ), lake_bed );
362+ ter_set ( tripoint_om_omt ( p, lake_depth ), settings_lake. bed );
361363 }
362364 }
363365 }
0 commit comments