Skip to content

Commit 74aa340

Browse files
authored
Merge pull request #83293 from ehughsbaird/lakes-forever
Allow inverting lake generation, specifying generated lake terrains
2 parents 5d4115f + 42b9748 commit 74aa340

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

doc/JSON/REGION_SETTINGS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ 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. |
245+
| `shore_ter` | Overmap terrain id of shore terrain place on boundary with land. |
246+
| `surface_ter` | Overmap terrain id of surface terrain, placed on z = 0. |
247+
| `interior_ter` | Overmap terrain id of interior terrain, placed between surface terrain and bed terrain. |
248+
| `bed_ter` | Overmap terrain id of bed terrain, placed on bottom of the lake. |
244249

245250
### Example
246251

src/overmap_water.cpp

Lines changed: 12 additions & 10 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,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
}

src/regional_settings.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121

2222
class mapgendata;
2323

24+
static const oter_str_id oter_lake_bed( "lake_bed" );
25+
static const oter_str_id oter_lake_shore( "lake_shore" );
26+
static const oter_str_id oter_lake_surface( "lake_surface" );
27+
static const oter_str_id oter_lake_water_cube( "lake_water_cube" );
28+
2429
static const weighted_string_id_reader<overmap_special_id, int> building_bin_reader( 1 );
2530
static const weighted_string_id_reader<furn_id, int> furn_reader( 1 );
2631
static const weighted_string_id_reader<ter_id, int> ter_reader( 1 );
@@ -516,6 +521,13 @@ void region_settings_overmap_connection::deserialize( const JsonObject &jo )
516521
optional( jo, was_loaded, "inter_city_road_connection", inter_city_road_connection );
517522
}
518523

524+
region_settings_lake::region_settings_lake() :
525+
surface( oter_lake_surface ),
526+
shore( oter_lake_shore ),
527+
interior( oter_lake_water_cube ),
528+
bed( oter_lake_bed )
529+
{}
530+
519531
void region_settings_lake::load( const JsonObject &jo, std::string_view )
520532
{
521533
optional( jo, was_loaded, "noise_threshold_lake", noise_threshold_lake );
@@ -526,6 +538,11 @@ void region_settings_lake::load( const JsonObject &jo, std::string_view )
526538
shore_extendable_overmap_terrain, sid_reader );
527539
optional( jo, was_loaded, "shore_extendable_overmap_terrain_aliases",
528540
shore_extendable_overmap_terrain_aliases );
541+
optional( jo, was_loaded, "invert_lakes", invert_lakes, false );
542+
optional( jo, was_loaded, "surface_ter", surface, oter_lake_surface );
543+
optional( jo, was_loaded, "shore_ter", shore, oter_lake_shore );
544+
optional( jo, was_loaded, "interior_ter", interior, oter_lake_water_cube );
545+
optional( jo, was_loaded, "bed_ter", bed, oter_lake_bed );
529546
}
530547

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

src/regional_settings.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,21 @@ struct region_settings_lake {
324324
double noise_threshold_lake = 0.25;
325325
int lake_size_min = 20;
326326
int lake_depth = -5;
327+
oter_str_id surface;
328+
oter_str_id shore;
329+
oter_str_id interior;
330+
oter_str_id bed;
327331
std::vector<oter_str_id> shore_extendable_overmap_terrain;
328332
std::vector<shore_extendable_overmap_terrain_alias> shore_extendable_overmap_terrain_aliases;
333+
bool invert_lakes = false;
329334

330335
bool was_loaded = false;
331336
void load( const JsonObject &jo, std::string_view );
332337
void finalize();
333338

334339
static void load_region_settings_lake( const JsonObject &jo, const std::string &src );
335340
static void reset();
336-
region_settings_lake() = default;
341+
region_settings_lake();
337342
};
338343

339344
struct region_settings_ocean {

0 commit comments

Comments
 (0)