Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds a sandy margin to ocean beaches #70175

Merged
merged 14 commits into from
Dec 20, 2023
14 changes: 14 additions & 0 deletions data/json/furniture_and_terrain/terrain-liquids.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,20 @@
"connects_to": "WATER",
"examine_action": "water_source"
},
{
"type": "terrain",
"id": "t_swater_surf",
"name": "surf",
"description": "A broad area of fine sand, washed by waves coming in from the sea.",
"symbol": ".",
"color": "cyan",
"looks_like": "t_water_pool",
"move_cost": 4,
"connect_groups": [ "SAND", "WATER" ],
"connects_to": [ "SAND", "SANDMOUND", "SANDGLASS", "WATER" ],
"flags": [ "TRANSPARENT", "LIQUID", "NO_SCENT", "SWIMMABLE", "SALT_WATER", "DIGGABLE", "FLAT" ],
"examine_action": "water_source"
},
{
"type": "terrain",
"id": "t_water_pool",
Expand Down
3 changes: 2 additions & 1 deletion data/json/regional_map_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@
"ocean_start_north": 500,
"ocean_start_east": 10,
"ocean_start_west": 1000,
"ocean_start_south": 0
"ocean_start_south": 0,
"sandy_beach_width": 6
},
"overmap_ravine_settings": { "num_ravines": 0, "ravine_width": 3, "ravine_range": 45, "ravine_depth": -3 },
"overmap_forest_settings": {
Expand Down
3 changes: 2 additions & 1 deletion src/mapdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ ter_id t_null,
t_fungus_mound, t_fungus, t_shrub_fungal, t_tree_fungal, t_tree_fungal_young, t_marloss_tree,
// Water, lava, etc.
t_water_moving_dp, t_water_moving_sh, t_water_sh, t_water_dp, t_swater_sh, t_swater_dp,
t_water_pool, t_sewage,
t_swater_surf, t_water_pool, t_sewage,
t_lava,
// More embellishments than you can shake a stick at.
t_sandbox, t_slide, t_monkey_bars, t_backboard,
Expand Down Expand Up @@ -1066,6 +1066,7 @@ void set_ter_ids()
t_water_dp = ter_id( "t_water_dp" );
t_swater_sh = ter_id( "t_swater_sh" );
t_swater_dp = ter_id( "t_swater_dp" );
t_swater_surf = ter_id( "t_swater_surf" );
t_water_pool = ter_id( "t_water_pool" );
t_sewage = ter_id( "t_sewage" );
t_lava = ter_id( "t_lava" );
Expand Down
2 changes: 1 addition & 1 deletion src/mapdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ extern ter_id t_null,
t_fungus_mound, t_fungus, t_shrub_fungal, t_tree_fungal, t_tree_fungal_young, t_marloss_tree,
// Water, lava, etc.
t_water_moving_dp, t_water_moving_sh, t_water_sh, t_swater_sh, t_water_dp, t_swater_dp,
t_water_pool, t_sewage,
t_swater_surf, t_water_pool, t_sewage,
t_lava,
// More embellishments than you can shake a stick at.
t_sandbox, t_slide, t_monkey_bars, t_backboard,
Expand Down
83 changes: 71 additions & 12 deletions src/mapgen_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1874,7 +1874,7 @@ void mapgen_ocean_shore( mapgendata &dat )
const bool w_river_bank = is_river_bank( dat.west() );

// This is length we end up pushing things about by as a baseline.
const int sector_length = SEEX * 2 / 3;
const int sector_length = SEEX - 1;

// Define the corners of the map. These won't change.
static constexpr point nw_corner{};
Expand All @@ -1890,8 +1890,10 @@ void mapgen_ocean_shore( mapgendata &dat )
point sw = sw_corner;

std::vector<std::vector<point>> line_segments;

// This section is about pushing the straight N, S, E, or W borders inward when adjacent to an actual lake.
int ns_direction_adjust = 0;
int ew_direction_adjust = 0;
int sand_margin = dat.region.overmap_ocean.sandy_beach_width / 2;
// This section is about pushing the straight N, S, E, or W borders inward when adjacent to an actual ocean.
if( n_ocean ) {
nw.y += sector_length;
ne.y += sector_length;
Expand Down Expand Up @@ -1962,6 +1964,8 @@ void mapgen_ocean_shore( mapgendata &dat )

n.x += sector_length;
w.y += sector_length;
ns_direction_adjust -= sand_margin;
ew_direction_adjust -= sand_margin;

line_segments.push_back( { n, w } );
}
Expand All @@ -1977,6 +1981,9 @@ void mapgen_ocean_shore( mapgendata &dat )

n.x -= sector_length;
e.y += sector_length;
ns_direction_adjust -= sand_margin;
ew_direction_adjust += sand_margin;


line_segments.push_back( { n, e } );
}
Expand All @@ -1992,6 +1999,9 @@ void mapgen_ocean_shore( mapgendata &dat )

s.x += sector_length;
w.y -= sector_length;
ns_direction_adjust += sand_margin;
ew_direction_adjust -= sand_margin;


line_segments.push_back( { s, w } );
}
Expand All @@ -2007,6 +2017,9 @@ void mapgen_ocean_shore( mapgendata &dat )

s.x -= sector_length;
e.y -= sector_length;
ns_direction_adjust += sand_margin;
ew_direction_adjust += sand_margin;


line_segments.push_back( { s, e } );
}
Expand All @@ -2017,19 +2030,24 @@ void mapgen_ocean_shore( mapgendata &dat )
// at the map boundaries, but have subsequently been perturbed by the adjacent terrains.
// Let's look at them and see which ones differ from their original state and should
// form our shoreline.

if( nw.y != nw_corner.y || ne.y != ne_corner.y ) {
ns_direction_adjust -= sand_margin * 2;
line_segments.push_back( { nw, ne } );
}

if( ne.x != ne_corner.x || se.x != se_corner.x ) {
ew_direction_adjust += sand_margin * 2;
line_segments.push_back( { ne, se } );
}

if( se.y != se_corner.y || sw.y != sw_corner.y ) {
ns_direction_adjust += sand_margin * 2;
line_segments.push_back( { se, sw } );
}

if( sw.x != sw_corner.x || nw.x != nw_corner.x ) {
ew_direction_adjust -= sand_margin * 2;
line_segments.push_back( { sw, nw } );
}

Expand All @@ -2039,32 +2057,69 @@ void mapgen_ocean_shore( mapgendata &dat )
// It buffers the points a bit for a thicker line. It also clears any furniture that might
// be in the location as a result of our extending adjacent mapgen.
const auto draw_shallow_water = [&]( const point & from, const point & to ) {
point from_mod = from;
point to_mod = to;
if( from.x != 0 && from.x != SEEX * 2 - 1 ) {
from_mod.x += ew_direction_adjust;
}
if( from.y != 0 && from.y != SEEX * 2 - 1 ) {
from_mod.y += ns_direction_adjust;
}
if( to.x != 0 && to.x != SEEX * 2 - 1 ) {
to_mod.x += ew_direction_adjust;
}
if( to.y != 0 && to.y != SEEX * 2 - 1 ) {
to_mod.y += ns_direction_adjust;
}
std::vector<point> points = line_to( from_mod, to_mod );
for( point &p : points ) {
for( const point &bp : closest_points_first( p, sand_margin ) ) {
if( !map_boundaries.contains( bp ) ) {
continue;
}
m->ter_set( bp, t_swater_sh );
m->furn_set( bp, f_null );
}
}
};
// This will draw our sandy beach coastline from the "from" point to the "to" point.
const auto draw_sand = [&]( const point & from, const point & to ) {
std::vector<point> points = line_to( from, to );
for( point &p : points ) {
for( const point &bp : closest_points_first( p, 1 ) ) {
for( const point &bp : closest_points_first( p, sand_margin ) ) {
if( !map_boundaries.contains( bp ) ) {
continue;
}
// Use t_null for now instead of t_water_sh, because sometimes our extended terrain
// has put down a t_water_sh, and we need to be able to flood-fill over that.
// Use t_null for now instead of t_sand, because sometimes our extended terrain
// has put down a t_sand, and we need to be able to flood-fill over that.
m->ter_set( bp, t_null );
m->furn_set( bp, f_null );
}
for( const point &bp : closest_points_first( p, sand_margin + 1 ) ) {
if( !map_boundaries.contains( bp ) ) {
continue;
}
if( m->ter( bp ) == t_swater_sh ){
I-am-Erk marked this conversation as resolved.
Show resolved Hide resolved
m->ter_set( bp, t_swater_surf );
}
}
}
};

// Given two points, return a point that is midway between the two points and then
// jittered by a random amount in proportion to the length of the line segment.
const auto jittered_midpoint = [&]( const point & from, const point & to ) {
const int jitter = rl_dist( from, to ) / 4;
const int jitter = rl_dist( from, to ) / 5;
const point midpoint( ( from.x + to.x ) / 2 + rng( -jitter, jitter ),
( from.y + to.y ) / 2 + rng( -jitter, jitter ) );
return midpoint;
};

// For each of our valid shoreline line segments, generate a slightly more interesting
// set of line segments by splitting the line into four segments with jittered
// midpoints, and then draw shallow water for four each of those.
// midpoints.
// Draw water after the sand to make sure we don't get too much sand. Everyone hates sand,
// it's coarse and - you know what, never mind.
for( auto &ls : line_segments ) {
const point mp1 = jittered_midpoint( ls[0], ls[1] );
const point mp2 = jittered_midpoint( ls[0], mp1 );
Expand All @@ -2074,6 +2129,10 @@ void mapgen_ocean_shore( mapgendata &dat )
draw_shallow_water( mp2, mp1 );
draw_shallow_water( mp1, mp3 );
draw_shallow_water( mp3, ls[1] );
draw_sand( ls[0], mp2 );
draw_sand( mp2, mp1 );
draw_sand( mp1, mp3 );
draw_sand( mp3, ls[1] );
}

// Now that we've done our ground mapgen and laid down a contiguous shoreline of shallow water,
Expand All @@ -2085,7 +2144,7 @@ void mapgen_ocean_shore( mapgendata &dat )
if( !map_boundaries.contains( p ) ) {
return false;
}
return m->ter( p ) != t_null;
return m->ter( p ) != t_null && m->ter( p ) != t_swater_sh && m->ter( p ) != t_swater_surf;
};

const auto fill_deep_water = [&]( const point & starting_point ) {
Expand Down Expand Up @@ -2115,9 +2174,9 @@ void mapgen_ocean_shore( mapgendata &dat )
fill_deep_water( se_corner );
}

// We previously placed our shallow water but actually did a t_null instead to make sure that we didn't
// pick up shallow water from our extended terrain. Now turn those nulls into t_swater_sh.
m->translate( t_null, t_swater_sh );
// We previously placed our sand but actually did a t_null instead to make sure that we didn't
// pick up sand from our extended terrain. Now turn those nulls into t_sand.
m->translate( t_null, t_sand );
}

void mapgen_ravine_edge( mapgendata &dat )
Expand Down
2 changes: 2 additions & 0 deletions src/regional_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ static void load_overmap_ocean_settings( const JsonObject &jo,
overmap_ocean_settings.ocean_start_west, !overlay );
read_and_set_or_throw<int>( overmap_ocean_settings_jo, "ocean_start_south",
overmap_ocean_settings.ocean_start_south, !overlay );
read_and_set_or_throw<int>( overmap_ocean_settings_jo, "sandy_beach_width",
overmap_ocean_settings.sandy_beach_width, !overlay );
}
}

Expand Down
1 change: 1 addition & 0 deletions src/regional_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ struct overmap_ocean_settings {
int ocean_start_east = 10;
int ocean_start_west = 0;
int ocean_start_south = 0;
int sandy_beach_width = 2;
overmap_ocean_settings() = default;
};

Expand Down
Loading