From 5f27e465fb672d40597e255878d62be5aa0b2ac5 Mon Sep 17 00:00:00 2001 From: Jason Jones Date: Fri, 15 Dec 2023 12:15:38 -0900 Subject: [PATCH 1/2] Fix lake shore mapgen corner case In my original implementation, I overlooked the scenario where a lake shore was bounded on the cardinal directions by river banks and had a lake on the diagonal that bounded the river banks. As a result, the mapgen would not draw any shoreline and just fill the whole location with water. There are still lots of weird interactions at the confluence of lakes and rivers but this fixes the most egregious one. --- src/mapgen_functions.cpp | 68 +++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/src/mapgen_functions.cpp b/src/mapgen_functions.cpp index 0dda8365dba74..a923565267736 100644 --- a/src/mapgen_functions.cpp +++ b/src/mapgen_functions.cpp @@ -1605,12 +1605,23 @@ void mapgen_lake_shore( mapgendata &dat ) if( n_lake && w_lake ) { nw.x += sector_length / 2; nw.y += sector_length / 2; - } else if( n_shore && w_shore ) { + } else if( ( n_shore || n_river_bank ) && ( w_shore || w_river_bank ) ) { point n = nw_corner; point w = nw_corner; - n.x += sector_length; - w.y += sector_length; + n.x += sector_length * ( n_river_bank ? 2 : 1 ); + w.y += sector_length * ( w_river_bank ? 2 : 1 ); + + n.y += n_river_bank ? sector_length / 2 : 0; + w.x += w_river_bank ? sector_length / 2 : 0; + + if( w_river_bank ) { + line_segments.push_back( { sw, w } ); + } + + if( n_river_bank ) { + line_segments.push_back( { n, ne } ); + } line_segments.push_back( { n, w } ); } @@ -1620,12 +1631,23 @@ void mapgen_lake_shore( mapgendata &dat ) if( n_lake && e_lake ) { ne.x -= sector_length / 2; ne.y += sector_length / 2; - } else if( n_shore && e_shore ) { + } else if( ( n_shore || n_river_bank ) && ( e_shore || e_river_bank ) ) { point n = ne_corner; point e = ne_corner; - n.x -= sector_length; - e.y += sector_length; + n.x -= sector_length * ( n_river_bank ? 2 : 1 ); + e.y += sector_length * ( e_river_bank ? 2 : 1 ); + + n.y += n_river_bank ? sector_length / 2 : 0; + e.x -= e_river_bank ? sector_length / 2 : 0; + + if( e_river_bank ) { + line_segments.push_back( { se, e } ); + } + + if( n_river_bank ) { + line_segments.push_back( { n, nw } ); + } line_segments.push_back( { n, e } ); } @@ -1635,12 +1657,23 @@ void mapgen_lake_shore( mapgendata &dat ) if( s_lake && w_lake ) { sw.x += sector_length / 2; sw.y -= sector_length / 2; - } else if( s_shore && w_shore ) { + } else if( ( s_shore || s_river_bank ) && ( w_shore || w_river_bank ) ) { point s = sw_corner; point w = sw_corner; - s.x += sector_length; - w.y -= sector_length; + s.x += sector_length * ( s_river_bank ? 2 : 1 ); + w.y -= sector_length * ( w_river_bank ? 2 : 1 ); + + s.y -= s_river_bank ? sector_length / 2 : 0; + w.x += w_river_bank ? sector_length / 2 : 0; + + if( w_river_bank ) { + line_segments.push_back( { nw, w } ); + } + + if( s_river_bank ) { + line_segments.push_back( { s, se } ); + } line_segments.push_back( { s, w } ); } @@ -1650,12 +1683,23 @@ void mapgen_lake_shore( mapgendata &dat ) if( s_lake && e_lake ) { se.x -= sector_length / 2; se.y -= sector_length / 2; - } else if( s_shore && e_shore ) { + } else if( ( s_shore || s_river_bank ) && ( e_shore || e_river_bank ) ) { point s = se_corner; point e = se_corner; - s.x -= sector_length; - e.y -= sector_length; + s.x -= sector_length * ( s_river_bank ? 2 : 1 ); + e.y -= sector_length * ( e_river_bank ? 2 : 1 ); + + s.y -= s_river_bank ? sector_length / 2 : 0; + e.x -= e_river_bank ? sector_length / 2 : 0; + + if( e_river_bank ) { + line_segments.push_back( { ne, e } ); + } + + if( s_river_bank ) { + line_segments.push_back( { s, sw } ); + } line_segments.push_back( { s, e } ); } From 7d9c490cf56fa2260e7ebe12b738c3d650d05309 Mon Sep 17 00:00:00 2001 From: Jason Jones Date: Fri, 15 Dec 2023 12:30:08 -0900 Subject: [PATCH 2/2] Fix corner case in ocean shore code that was derived from lake shore --- src/mapgen_functions.cpp | 68 +++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/src/mapgen_functions.cpp b/src/mapgen_functions.cpp index a923565267736..15ac16262078b 100644 --- a/src/mapgen_functions.cpp +++ b/src/mapgen_functions.cpp @@ -2000,12 +2000,23 @@ void mapgen_ocean_shore( mapgendata &dat ) if( n_ocean && w_ocean ) { nw.x += sector_length / 2; nw.y += sector_length / 2; - } else if( n_shore && w_shore ) { + } else if( ( n_shore || n_river_bank ) && ( w_shore || w_river_bank ) ) { point n = nw_corner; point w = nw_corner; - n.x += sector_length; - w.y += sector_length; + n.x += sector_length * ( n_river_bank ? 2 : 1 ); + w.y += sector_length * ( w_river_bank ? 2 : 1 ); + + n.y += n_river_bank ? sector_length / 2 : 0; + w.x += w_river_bank ? sector_length / 2 : 0; + + if( w_river_bank ) { + line_segments.push_back( { sw, w } ); + } + + if( n_river_bank ) { + line_segments.push_back( { n, ne } ); + } line_segments.push_back( { n, w } ); } @@ -2015,12 +2026,23 @@ void mapgen_ocean_shore( mapgendata &dat ) if( n_ocean && e_ocean ) { ne.x -= sector_length / 2; ne.y += sector_length / 2; - } else if( n_shore && e_shore ) { + } else if( ( n_shore || n_river_bank ) && ( e_shore || e_river_bank ) ) { point n = ne_corner; point e = ne_corner; - n.x -= sector_length; - e.y += sector_length; + n.x -= sector_length * ( n_river_bank ? 2 : 1 ); + e.y += sector_length * ( e_river_bank ? 2 : 1 ); + + n.y += n_river_bank ? sector_length / 2 : 0; + e.x -= e_river_bank ? sector_length / 2 : 0; + + if( e_river_bank ) { + line_segments.push_back( { se, e } ); + } + + if( n_river_bank ) { + line_segments.push_back( { n, nw } ); + } line_segments.push_back( { n, e } ); } @@ -2030,12 +2052,23 @@ void mapgen_ocean_shore( mapgendata &dat ) if( s_ocean && w_ocean ) { sw.x += sector_length / 2; sw.y -= sector_length / 2; - } else if( s_shore && w_shore ) { + } else if( ( s_shore || s_river_bank ) && ( w_shore || w_river_bank ) ) { point s = sw_corner; point w = sw_corner; - s.x += sector_length; - w.y -= sector_length; + s.x += sector_length * ( s_river_bank ? 2 : 1 ); + w.y -= sector_length * ( w_river_bank ? 2 : 1 ); + + s.y -= s_river_bank ? sector_length / 2 : 0; + w.x += w_river_bank ? sector_length / 2 : 0; + + if( w_river_bank ) { + line_segments.push_back( { nw, w } ); + } + + if( s_river_bank ) { + line_segments.push_back( { s, se } ); + } line_segments.push_back( { s, w } ); } @@ -2045,12 +2078,23 @@ void mapgen_ocean_shore( mapgendata &dat ) if( s_ocean && e_ocean ) { se.x -= sector_length / 2; se.y -= sector_length / 2; - } else if( s_shore && e_shore ) { + } else if( ( s_shore || s_river_bank ) && ( e_shore || e_river_bank ) ) { point s = se_corner; point e = se_corner; - s.x -= sector_length; - e.y -= sector_length; + s.x -= sector_length * ( s_river_bank ? 2 : 1 ); + e.y -= sector_length * ( e_river_bank ? 2 : 1 ); + + s.y -= s_river_bank ? sector_length / 2 : 0; + e.x -= e_river_bank ? sector_length / 2 : 0; + + if( e_river_bank ) { + line_segments.push_back( { ne, e } ); + } + + if( s_river_bank ) { + line_segments.push_back( { s, sw } ); + } line_segments.push_back( { s, e } ); }