Skip to content

Commit

Permalink
Merge pull request #77572 from sparr/optimize_possible_expansions
Browse files Browse the repository at this point in the history
Optimize search for possible expansion locations
  • Loading branch information
Maleclypse authored Nov 9, 2024
2 parents f29573a + 4c42f89 commit 34b9e8b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
35 changes: 15 additions & 20 deletions src/faction_camp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1410,12 +1410,23 @@ void basecamp::get_available_missions( mission_data &mission_key, map &here )
{
if( directions.size() < 8 ) {
bool free_non_field_found = false;
bool possible_expansion_found = false;

for( const auto &dir : base_camps::all_directions ) {
if( dir.first != base_camps::base_dir && expansions.find( dir.first ) == expansions.end() &&
overmap_buffer.ter_existing( omt_pos + dir.first ) != oter_id( "field" ) ) {
free_non_field_found = true;
break;
if( dir.first != base_camps::base_dir && expansions.find( dir.first ) == expansions.end() ) {
const oter_id &omt_ref = overmap_buffer.ter( omt_pos + dir.first );
if( !free_non_field_found && omt_ref != oter_id( "field" ) ) {
free_non_field_found = true;
}
if( !possible_expansion_found ) {
const std::optional<mapgen_arguments> *maybe_args =
overmap_buffer.mapgen_args( omt_pos + dir.first );
possible_expansion_found = recipe_group::has_recipes_by_id( "all_faction_base_expansions",
omt_ref, maybe_args );
}
if( free_non_field_found && possible_expansion_found ) {
break;
}
}
}

Expand Down Expand Up @@ -1451,22 +1462,6 @@ void basecamp::get_available_missions( mission_data &mission_key, map &here )
}
}

bool possible_expansion_found = false;

for( const auto &dir : base_camps::all_directions ) {
if( dir.first != base_camps::base_dir && expansions.find( dir.first ) == expansions.end() ) {
const oter_id &omt_ref = overmap_buffer.ter( omt_pos + dir.first );
const std::optional<mapgen_arguments> *maybe_args = overmap_buffer.mapgen_args(
omt_pos + dir.first );
const auto &pos_expansions = recipe_group::get_recipes_by_id( "all_faction_base_expansions",
omt_ref, maybe_args );
if( !pos_expansions.empty() ) {
possible_expansion_found = true;
break;
}
}
}

const mission_id miss_id = { Camp_Survey_Expansion, "", {}, base_dir };
comp_list npc_list = get_mission_workers( miss_id );
entry = string_format( _( "Notes:\n"
Expand Down
11 changes: 10 additions & 1 deletion src/recipe_groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,24 @@ std::map<recipe_id, translation> recipe_group::get_recipes_by_id( const std::str
return group.recipes;
}

bool recipe_group::has_recipes_by_id( const std::string &id,
const oter_id &omt_ter, const std::optional<mapgen_arguments> *maybe_args )
{
return !get_recipes_by_id( id, omt_ter, maybe_args, 1 ).empty();
}

std::map<recipe_id, translation> recipe_group::get_recipes_by_id( const std::string &id,
const oter_id &omt_ter, const std::optional<mapgen_arguments> *maybe_args )
const oter_id &omt_ter, const std::optional<mapgen_arguments> *maybe_args, const size_t limit )
{
std::map<recipe_id, translation> all_rec;
if( !recipe_groups_data.is_valid( group_id( id ) ) ) {
return all_rec;
}
const recipe_group_data &group = recipe_groups_data.obj( group_id( id ) );
for( const auto &recp : group.recipes ) {
if( limit > 0 && all_rec.size() >= limit ) {
break;
}
const auto &recp_terrain_it = group.om_terrains.find( recp.first );
if( recp_terrain_it == group.om_terrains.end() ) {
debugmsg( "Recipe %s doesn't specify 'om_terrains', use ANY instead if intended to work anywhere",
Expand Down
4 changes: 3 additions & 1 deletion src/recipe_groups.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ void reset();

std::map<recipe_id, translation> get_recipes_by_bldg( const std::string &bldg );
std::map<recipe_id, translation> get_recipes_by_id( const std::string &id );
bool has_recipes_by_id( const std::string &id, const oter_id &omt_ter,
const std::optional<mapgen_arguments> *maybe_args );
std::map<recipe_id, translation> get_recipes_by_id( const std::string &id, const oter_id &omt_ter,
const std::optional<mapgen_arguments> *maybe_args );
const std::optional<mapgen_arguments> *maybe_args, size_t limit = 0 );
std::string get_building_of_recipe( const std::string &recipe );
} // namespace recipe_group

Expand Down

0 comments on commit 34b9e8b

Please sign in to comment.