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 identical omts spawning over themselves #68324

Merged
merged 1 commit into from
Sep 28, 2023
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
12 changes: 9 additions & 3 deletions src/overmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2889,10 +2889,16 @@ void overmap::ter_set( const tripoint_om_omt &p, const oter_id &id )

oter_id &val = layer[p.z() + OVERMAP_DEPTH].terrain[p.xy()];
if( id->has_flag( oter_flags::requires_predecessor ) ) {
const oter_type_id id_type = id->get_type_id();
// Stops linear fallback_predecessor maps (roads etc) spawning over themselves
if( !( id_type->is_linear() && id_type == val->get_type_id() ) ) {
predecessors_[p].push_back( val );
std::vector<oter_id> &om_predecessors = predecessors_[p];
if( om_predecessors.empty() || !val->is_linear() ) {
om_predecessors.push_back( val );
} else {
// Collapse and keep the last linear oter of matching type
oter_id &last_predecessor = om_predecessors.back();
if( last_predecessor->get_type_id() == val->get_type_id() ) {
last_predecessor = val;
}
}
}
val = id;
Expand Down
24 changes: 23 additions & 1 deletion src/savegame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,30 @@ void overmap::unserialize( const JsonObject &jsobj )
} else if( name == "predecessors" ) {
std::vector<std::pair<tripoint_om_omt, std::vector<oter_id>>> flattened_predecessors;
om_member.read( flattened_predecessors, true );
std::vector<oter_id> deduped_predecessors;
for( std::pair<tripoint_om_omt, std::vector<oter_id>> &p : flattened_predecessors ) {
predecessors_.insert( std::move( p ) );
// TODO remove after 0.H release.
// JSONizing roads caused some bad mapgen data to get saved to disk. Repeated redundant linear
// type omts were all saved. The new logic only pushes a linear predecessor if the predecessors
// list is empty or the incoming omt is not linear. Fixup bad saves to conform.
deduped_predecessors.reserve( p.second.size() );
for( const oter_id &id : p.second ) {
if( deduped_predecessors.empty() || !id->is_linear() ) {
deduped_predecessors.push_back( id );
} else {
oter_id &last_predecessor = deduped_predecessors.back();
if( last_predecessor->get_type_id() == id->get_type_id() ) {
last_predecessor = id;
} else {
deduped_predecessors.push_back( id );
}
}
}
predecessors_.insert_or_assign( p.first, std::move( deduped_predecessors ) );

// Reuse allocations because it's a good habit.
deduped_predecessors = std::move( p.second );
deduped_predecessors.clear();
}
}
}
Expand Down