Skip to content

Commit 3dd1e0b

Browse files
committed
Allow inverting lake generation
To create archipelago-style maps.
1 parent 21139f2 commit 3dd1e0b

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

doc/JSON/REGION_SETTINGS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ are interpreted.
241241
| `lake_depth` | Depth of lakes, expressed in Z-levels (e.g. -1 to -10). |
242242
| `shore_extendable_overmap_terrain` | List of overmap terrains that can be extended to the shore if adjacent. |
243243
| `shore_extendable_overmap_terrain_aliases` | Overmap terrains to treat as different overmap terrain for extending shore. |
244+
| `invert_lakes` | Invert drawing of lakes. What would be a lake is land, what would be land is a lake. |
244245

245246
### Example
246247

src/overmap_water.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
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

src/regional_settings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ void region_settings_lake::load( const JsonObject &jo, std::string_view )
526526
shore_extendable_overmap_terrain, sid_reader );
527527
optional( jo, was_loaded, "shore_extendable_overmap_terrain_aliases",
528528
shore_extendable_overmap_terrain_aliases );
529+
optional( jo, was_loaded, "invert_lakes", invert_lakes, false );
529530
}
530531

531532
void shore_extendable_overmap_terrain_alias::deserialize( const JsonObject &jo )

src/regional_settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ struct region_settings_lake {
326326
int lake_depth = -5;
327327
std::vector<oter_str_id> shore_extendable_overmap_terrain;
328328
std::vector<shore_extendable_overmap_terrain_alias> shore_extendable_overmap_terrain_aliases;
329+
bool invert_lakes = false;
329330

330331
bool was_loaded = false;
331332
void load( const JsonObject &jo, std::string_view );

0 commit comments

Comments
 (0)