From 069711b4131d98c3af40681f9802fcd3088f1013 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:04:52 +0100 Subject: [PATCH 1/3] Add fallback_road_connection_point --- src/overmap.cpp | 63 ++++++++++++++++++++++++++----------------------- src/overmap.h | 4 +++- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/src/overmap.cpp b/src/overmap.cpp index da860f93a491a..20f4f0f27c2d6 100644 --- a/src/overmap.cpp +++ b/src/overmap.cpp @@ -1443,22 +1443,14 @@ struct fixed_overmap_special_data : overmap_special_data { if( initial_dir != cube_direction::last ) { initial_dir = initial_dir + dir; } + // TODO: JSONification of logic + don't treat non roads like roads + point_om_omt target; if( cit ) { - om.build_connection( cit.pos, rp.xy(), elem.p.z, *elem.connection, - must_be_unexplored, initial_dir ); - } - // if no city present, search for nearby road within 50 tiles and make - // connection to it instead - else { - for( const tripoint_om_omt &nearby_point : closest_points_first( rp, 50 ) ) { - if( om.check_ot( "road", ot_match_type::contains, nearby_point ) ) { - om.build_connection( - nearby_point.xy(), rp.xy(), elem.p.z, *elem.connection, - must_be_unexplored, initial_dir ); - break; - } - } + target = cit.pos; + } else { + target = om.get_fallback_road_connection_point(); } + om.build_connection( target, rp.xy(), elem.p.z, *elem.connection, must_be_unexplored, initial_dir ); } } @@ -2614,24 +2606,19 @@ struct mutable_overmap_special_data : overmap_special_data { } // Deal with connections + // TODO: JSONification of logic + don't treat non roads like roads + deduplicate with fixed data for( const placed_connection &elem : connections_placed ) { const tripoint_om_omt &pos = elem.where.p; cube_direction connection_dir = elem.where.dir; + point_om_omt target; if( cit ) { - om.build_connection( cit.pos, pos.xy(), pos.z(), *elem.connection, - must_be_unexplored, connection_dir ); - } - // if no city present, search for nearby road within 50 tiles and make connection to it instead - else { - for( const tripoint_om_omt &nearby_point : closest_points_first( pos, 50 ) ) { - if( om.check_ot( "road", ot_match_type::contains, nearby_point ) ) { - om.build_connection( - nearby_point.xy(), pos.xy(), pos.z(), *elem.connection, - must_be_unexplored, connection_dir ); - } - } + target = cit.pos; + } else { + target = om.get_fallback_road_connection_point(); } + om.build_connection( target, pos.xy(), pos.z(), *elem.connection, must_be_unexplored, + connection_dir ); } return { result, unresolved.all_used() }; @@ -3142,6 +3129,17 @@ bool overmap::is_marked_dangerous( const tripoint_om_omt &p ) const return false; } +point_om_omt overmap::get_fallback_road_connection_point() const +{ + if( fallback_road_connection_point ) { + return *fallback_road_connection_point; + } else { + debugmsg( "fallback_road_connection_point wasn't set" ); + return point_om_omt( rng( OMAPX / 4, ( 3 * OMAPX ) / 4 ), + rng( OMAPY / 4, ( 3 * OMAPY ) / 4 ) ); + } +} + const std::string &overmap::note( const tripoint_om_omt &p ) const { static const std::string fallback {}; @@ -5165,12 +5163,19 @@ void overmap::place_roads( const overmap *north, const overmap *east, const over std::vector road_points; // cities and roads_out together // Compile our master list of roads; it's less messy if roads_out is first - road_points.reserve( roads_out.size() + cities.size() ); + road_points.reserve( roads_out.size() + std::max( 1, static_cast( cities.size() ) ) ); for( const auto &elem : roads_out ) { road_points.emplace_back( elem.xy() ); } - for( const city &elem : cities ) { - road_points.emplace_back( elem.pos ); + if( cities.size() == 0 ) { + // If there's no cities in the overmap chose a random central point that special's road connections should path to + fallback_road_connection_point = point_om_omt( rng( OMAPX / 4, ( 3 * OMAPX ) / 4 ), + rng( OMAPY / 4, ( 3 * OMAPY ) / 4 ) ); + road_points.emplace_back( *fallback_road_connection_point ); + } else { + for( const city &elem : cities ) { + road_points.emplace_back( elem.pos ); + } } // And finally connect them via roads. diff --git a/src/overmap.h b/src/overmap.h index 149ba7b0884dd..64c04fdd2a01f 100644 --- a/src/overmap.h +++ b/src/overmap.h @@ -337,7 +337,7 @@ class overmap std::vector> get_npcs( const std::function &predicate ) const; - + point_om_omt get_fallback_road_connection_point() const; private: friend class overmapbuffer; @@ -347,6 +347,8 @@ class overmap // overmap::seen and overmap::explored bool nullbool = false; // NOLINT(cata-serialize) point_abs_om loc; // NOLINT(cata-serialize) + // Random point used for special connections if there's no cities on the overmap, joins to all roads_out + std::optional fallback_road_connection_point; std::array layer; std::unordered_map scents; From 6397fb1ce921aff65d5aa0c51afb8d9f948d768c Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Wed, 5 Jun 2024 17:59:35 +0100 Subject: [PATCH 2/3] Appease our clang overlords --- src/overmap.cpp | 2 +- src/overmap.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/overmap.cpp b/src/overmap.cpp index 20f4f0f27c2d6..a394791963d60 100644 --- a/src/overmap.cpp +++ b/src/overmap.cpp @@ -5167,7 +5167,7 @@ void overmap::place_roads( const overmap *north, const overmap *east, const over for( const auto &elem : roads_out ) { road_points.emplace_back( elem.xy() ); } - if( cities.size() == 0 ) { + if( cities.empty() ) { // If there's no cities in the overmap chose a random central point that special's road connections should path to fallback_road_connection_point = point_om_omt( rng( OMAPX / 4, ( 3 * OMAPX ) / 4 ), rng( OMAPY / 4, ( 3 * OMAPY ) / 4 ) ); diff --git a/src/overmap.h b/src/overmap.h index 64c04fdd2a01f..1659b86d7055a 100644 --- a/src/overmap.h +++ b/src/overmap.h @@ -348,7 +348,7 @@ class overmap bool nullbool = false; // NOLINT(cata-serialize) point_abs_om loc; // NOLINT(cata-serialize) // Random point used for special connections if there's no cities on the overmap, joins to all roads_out - std::optional fallback_road_connection_point; + std::optional fallback_road_connection_point; // NOLINT(cata-serialize) std::array layer; std::unordered_map scents; From ce77ca301e156c90b3d75cb4e580aba78801ce28 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Wed, 5 Jun 2024 20:41:28 +0100 Subject: [PATCH 3/3] No error message bc of forced special placements not using cities regardless of them being present --- src/overmap.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/overmap.cpp b/src/overmap.cpp index a394791963d60..d4dbdd942bb00 100644 --- a/src/overmap.cpp +++ b/src/overmap.cpp @@ -3134,7 +3134,6 @@ point_om_omt overmap::get_fallback_road_connection_point() const if( fallback_road_connection_point ) { return *fallback_road_connection_point; } else { - debugmsg( "fallback_road_connection_point wasn't set" ); return point_om_omt( rng( OMAPX / 4, ( 3 * OMAPX ) / 4 ), rng( OMAPY / 4, ( 3 * OMAPY ) / 4 ) ); }