Skip to content

Commit

Permalink
Don't crash when forest mapgen requests groundcover from a biome with…
Browse files Browse the repository at this point in the history
… no groundcover.
  • Loading branch information
akrieger committed Apr 12, 2024
1 parent 8b4c779 commit 9069c27
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/mapgen_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ void mapgen_forest( mapgendata &dat )
// In order to feather (blend) this overmap tile with adjacent ones, the general composition thereof must be known.
// This can be calculated once from dat.t_nesw, and stored here:
std::array<const forest_biome *, 8> adjacent_biomes;
for( int d = 0; d < 7; d++ ) {
for( int d = 0; d <= 7; d++ ) {
auto lookup = dat.region.forest_composition.biomes.find( dat.t_nesw[d]->get_type_id() );
if( lookup != dat.region.forest_composition.biomes.end() ) {
adjacent_biomes[d] = &( lookup->second );
Expand Down Expand Up @@ -1187,7 +1187,12 @@ void mapgen_forest( mapgendata &dat )
return *dat.region.default_groundcover.pick();
default:
if( adjacent_biomes[feather_selection] != nullptr ) {
return *adjacent_biomes[feather_selection]->groundcover.pick();
const ter_id *cover = adjacent_biomes[feather_selection]->groundcover.pick();
if( cover ) {
return *cover;
}
// Adjacent biome has no groundcover, use the region default.
return *dat.region.default_groundcover.pick();
} else {
return *dat.region.default_groundcover.pick();
}
Expand Down
21 changes: 14 additions & 7 deletions src/regional_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,26 @@ static void load_forest_mapgen_settings( const JsonObject &jo,
if( forest_biome_ter_keys.empty() ) {
forest_biome_jo.throw_error( "Biome is not associated with any terrains." );
}
std::string first_ter = forest_biome_ter_keys.get_string( 0 );
load_forest_biome( forest_biome_jo, forest_mapgen_settings.unfinalized_biomes[first_ter],
overlay );
for( size_t biome_ter_idx = 1; biome_ter_idx < forest_biome_ter_keys.size(); biome_ter_idx++ ) {
std::string default_ter_name = member.name();
auto default_ter_it = forest_mapgen_settings.unfinalized_biomes.find( default_ter_name );
if( default_ter_it == forest_mapgen_settings.unfinalized_biomes.end() ) {
forest_biome_jo.throw_error( "Terrain " + default_ter_name +
" is not defined, cannot be used for forest biome." );
}
forest_biome &default_ter = default_ter_it->second;
load_forest_biome( forest_biome_jo, default_ter, overlay );
for( size_t biome_ter_idx = 0; biome_ter_idx < forest_biome_ter_keys.size(); biome_ter_idx++ ) {
std::string biome_ter_name = forest_biome_ter_keys.get_string( biome_ter_idx );
if( biome_ter_name == default_ter_name ) {
continue;
}
forest_mapgen_settings.unfinalized_biomes.insert( std::pair<std::string, forest_biome>
( forest_biome_ter_keys.get_string( biome_ter_idx ),
forest_mapgen_settings.unfinalized_biomes[first_ter] ) );
( forest_biome_ter_keys.get_string( biome_ter_idx ), default_ter ) );
}
} else {
load_forest_biome( forest_biome_jo, forest_mapgen_settings.unfinalized_biomes[member.name()],
overlay );
}

}
}
}
Expand Down

0 comments on commit 9069c27

Please sign in to comment.