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

Fix connections sometimes failing to gen on cityless overmaps #74329

Merged
merged 3 commits into from
Jun 7, 2024
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
62 changes: 33 additions & 29 deletions src/overmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down Expand Up @@ -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() };
Expand Down Expand Up @@ -3142,6 +3129,16 @@ 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 {
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 {};
Expand Down Expand Up @@ -5165,12 +5162,19 @@ void overmap::place_roads( const overmap *north, const overmap *east, const over

std::vector<point_om_omt> 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<int>( 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.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 ) );
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.
Expand Down
4 changes: 3 additions & 1 deletion src/overmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class overmap
std::vector<shared_ptr_fast<npc>> get_npcs( const std::function<bool( const npc & )>
&predicate )
const;

point_om_omt get_fallback_road_connection_point() const;
private:
friend class overmapbuffer;

Expand All @@ -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<point_om_omt> fallback_road_connection_point; // NOLINT(cata-serialize)

std::array<map_layer, OVERMAP_LAYERS> layer;
std::unordered_map<tripoint_abs_omt, scent_trace> scents;
Expand Down
Loading