Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/JSON/REGION_SETTINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ are interpreted.
| `lake_depth` | Depth of lakes, expressed in Z-levels (e.g. -1 to -10). |
| `shore_extendable_overmap_terrain` | List of overmap terrains that can be extended to the shore if adjacent. |
| `shore_extendable_overmap_terrain_aliases` | Overmap terrains to treat as different overmap terrain for extending shore. |
| `invert_lakes` | Invert drawing of lakes. What would be a lake is land, what would be land is a lake. |
| `shore_ter` | Overmap terrain id of shore terrain place on boundary with land. |
| `surface_ter` | Overmap terrain id of surface terrain, placed on z = 0. |
| `interior_ter` | Overmap terrain id of interior terrain, placed between surface terrain and bed terrain. |
| `bed_ter` | Overmap terrain id of bed terrain, placed on bottom of the lake. |

### Example

Expand Down
22 changes: 12 additions & 10 deletions src/overmap_water.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <vector>

#include "coordinates.h"
#include "cuboid_rectangle.h"
#include "debug.h"
#include "enums.h"
#include "flood_fill.h"
Expand Down Expand Up @@ -261,15 +262,16 @@ void overmap::place_lakes( const std::vector<const overmap *> &neighbor_overmaps
double noise_threshold = settings_lake.noise_threshold_lake;
const int lake_depth = settings_lake.lake_depth;

// For cases where lakes take up most or all of the map, we need to stop the flood-fill
// from being unbounded. However, the bounds cannot be simply the overmap edges, or the
// shorelines will not be generated properly.
inclusive_rectangle<point_om_omt> considered_bounds( point_om_omt( -5, -5 ),
point_om_omt( OMAPX + 5, OMAPY + 5 ) );
const auto is_lake = [&]( const point_om_omt & p ) {
return omt_lake_noise_threshold( origin, p, noise_threshold );
return considered_bounds.contains( p ) &&
settings_lake.invert_lakes ^ omt_lake_noise_threshold( origin, p, noise_threshold );
};

const oter_id lake_surface( "lake_surface" );
const oter_id lake_shore( "lake_shore" );
const oter_id lake_water_cube( "lake_water_cube" );
const oter_id lake_bed( "lake_bed" );

// We'll keep track of our visited lake points so we don't repeat the work.
std::unordered_set<point_om_omt> visited;

Expand All @@ -281,7 +283,7 @@ void overmap::place_lakes( const std::vector<const overmap *> &neighbor_overmaps
}

// It's a lake if it exceeds the noise threshold defined in the region settings.
if( !omt_lake_noise_threshold( origin, seed_point, noise_threshold ) ) {
if( !is_lake( seed_point ) ) {
continue;
}

Expand Down Expand Up @@ -350,14 +352,14 @@ void overmap::place_lakes( const std::vector<const overmap *> &neighbor_overmaps
}
}

ter_set( tripoint_om_omt( p, 0 ), shore ? lake_shore : lake_surface );
ter_set( tripoint_om_omt( p, 0 ), shore ? settings_lake.shore : settings_lake.surface );

// If this is not a shore, we'll make our subsurface lake cubes and beds.
if( !shore ) {
for( int z = -1; z > lake_depth; z-- ) {
ter_set( tripoint_om_omt( p, z ), lake_water_cube );
ter_set( tripoint_om_omt( p, z ), settings_lake.interior );
}
ter_set( tripoint_om_omt( p, lake_depth ), lake_bed );
ter_set( tripoint_om_omt( p, lake_depth ), settings_lake.bed );
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/regional_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

class mapgendata;

static const oter_str_id oter_lake_bed( "lake_bed" );
static const oter_str_id oter_lake_shore( "lake_shore" );
static const oter_str_id oter_lake_surface( "lake_surface" );
static const oter_str_id oter_lake_water_cube( "lake_water_cube" );

static const weighted_string_id_reader<overmap_special_id, int> building_bin_reader( 1 );
static const weighted_string_id_reader<furn_id, int> furn_reader( 1 );
static const weighted_string_id_reader<ter_id, int> ter_reader( 1 );
Expand Down Expand Up @@ -516,6 +521,13 @@ void region_settings_overmap_connection::deserialize( const JsonObject &jo )
optional( jo, was_loaded, "inter_city_road_connection", inter_city_road_connection );
}

region_settings_lake::region_settings_lake() :
surface( oter_lake_surface ),
shore( oter_lake_shore ),
interior( oter_lake_water_cube ),
bed( oter_lake_bed )
{}

void region_settings_lake::load( const JsonObject &jo, std::string_view )
{
optional( jo, was_loaded, "noise_threshold_lake", noise_threshold_lake );
Expand All @@ -526,6 +538,11 @@ void region_settings_lake::load( const JsonObject &jo, std::string_view )
shore_extendable_overmap_terrain, sid_reader );
optional( jo, was_loaded, "shore_extendable_overmap_terrain_aliases",
shore_extendable_overmap_terrain_aliases );
optional( jo, was_loaded, "invert_lakes", invert_lakes, false );
optional( jo, was_loaded, "surface_ter", surface, oter_lake_surface );
optional( jo, was_loaded, "shore_ter", shore, oter_lake_shore );
optional( jo, was_loaded, "interior_ter", interior, oter_lake_water_cube );
optional( jo, was_loaded, "bed_ter", bed, oter_lake_bed );
}

void shore_extendable_overmap_terrain_alias::deserialize( const JsonObject &jo )
Expand Down
7 changes: 6 additions & 1 deletion src/regional_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,21 @@ struct region_settings_lake {
double noise_threshold_lake = 0.25;
int lake_size_min = 20;
int lake_depth = -5;
oter_str_id surface;
oter_str_id shore;
oter_str_id interior;
oter_str_id bed;
std::vector<oter_str_id> shore_extendable_overmap_terrain;
std::vector<shore_extendable_overmap_terrain_alias> shore_extendable_overmap_terrain_aliases;
bool invert_lakes = false;

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

static void load_region_settings_lake( const JsonObject &jo, const std::string &src );
static void reset();
region_settings_lake() = default;
region_settings_lake();
};

struct region_settings_ocean {
Expand Down
Loading