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 28, 2023
1 parent df2cf04 commit 820e036
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
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

0 comments on commit 820e036

Please sign in to comment.