Skip to content

Commit

Permalink
Hide AIs with hidden=yes from list of available AI options (fixes #2095)
Browse files Browse the repository at this point in the history
This is enough to hide them as AI options in the UI, but I don't know if other parts of the AI
engine need to know about this key.
  • Loading branch information
Vultraz committed Oct 10, 2017
1 parent 3c0e873 commit b2df837
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions data/ai/ais/idle_ai.cfg
Expand Up @@ -2,6 +2,7 @@
[ai]
id=idle_ai
description=_"Multiplayer_AI^Dev AI: Idle AI" # wmllint: no spellcheck
hidden=yes
# Needs to define at least one stage; otherwise, the default AI will be injected
# when used with [modify_side]switch_ai or when loading a mid-scenario save
[stage]
Expand Down
32 changes: 22 additions & 10 deletions src/ai/configuration.cpp
Expand Up @@ -114,20 +114,32 @@ void configuration::add_mod_ai_from_config(config::const_child_itors mods)
}
}

std::vector<description*> configuration::get_available_ais(){
std::vector<description*> configuration::get_available_ais()
{
std::vector<description*> ais_list;
for(description_map::iterator desc = ai_configurations_.begin(); desc!=ai_configurations_.end(); ++desc) {
ais_list.push_back(&desc->second);
DBG_AI_CONFIGURATION << "has ai with config: "<< std::endl << desc->second.cfg<< std::endl;

for(auto& a_config : ai_configurations_) {
ais_list.push_back(&a_config.second);
DBG_AI_CONFIGURATION << "has ai with config: "<< std::endl << a_config.second.cfg<< std::endl;
}
for(description_map::iterator desc = era_ai_configurations_.begin(); desc!=era_ai_configurations_.end(); ++desc) {
ais_list.push_back(&desc->second);
DBG_AI_CONFIGURATION << "has ai with config: "<< std::endl << desc->second.cfg<< std::endl;

for(auto& e_config : era_ai_configurations_) {
ais_list.push_back(&e_config.second);
DBG_AI_CONFIGURATION << "has ai with config: "<< std::endl << e_config.second.cfg<< std::endl;
}
for(description_map::iterator desc = mod_ai_configurations_.begin(); desc!=mod_ai_configurations_.end(); ++desc) {
ais_list.push_back(&desc->second);
DBG_AI_CONFIGURATION << "has ai with config: "<< std::endl << desc->second.cfg<< std::endl;

for(auto& m_config : mod_ai_configurations_) {
ais_list.push_back(&m_config.second);
DBG_AI_CONFIGURATION << "has ai with config: "<< std::endl << m_config.second.cfg<< std::endl;
}

// Remove any AIs marked hidden.
const auto new_end = std::remove_if(ais_list.begin(), ais_list.end(),

This comment has been minimized.

Copy link
@CelticMinstrel

CelticMinstrel Oct 11, 2017

Member

It seems to me that it makes more sense to just not add them in the first place rather than adding them and then removing them.

[](description* d) { return d->cfg["hidden"].to_bool(false); }
);

ais_list.erase(new_end, ais_list.end());

return ais_list;
}

Expand Down

0 comments on commit b2df837

Please sign in to comment.