Skip to content

Commit

Permalink
Fix identical omts spawning over themselves
Browse files Browse the repository at this point in the history
  • Loading branch information
akrieger committed Sep 25, 2023
1 parent 95360a3 commit 84b9403
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/savegame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,26 @@ 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.
// Deduplicate identical/redundant linear predecessors
// Prior versions of mapgen would cause things like roads to 'spawn over' themselves
// This would cause city roads with every tile either occupied by monster or wrecks
// that would even spawn over themselves.
deduped_predecessors.reserve( p.second.size() );
for( const oter_id &id : p.second ) {
oter_type_str_id oti = id->get_type_id();
if( !oti->is_linear() || ( deduped_predecessors.empty() ||
deduped_predecessors.back()->get_type_id() != id->get_type_id() ) ) {
deduped_predecessors.emplace_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

0 comments on commit 84b9403

Please sign in to comment.