Skip to content

Commit

Permalink
AI: move default algorithm definition from C++ to WML
Browse files Browse the repository at this point in the history
Among other things this now allows defining cores that have a different default AI.
  • Loading branch information
mattsc committed Nov 16, 2018
1 parent f901a0f commit 073f70b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions data/_main.cfg
Expand Up @@ -38,6 +38,7 @@
{campaigns/}

[ais]
default_ai_algorithm=ai_default_rca
[default_config]
{ai/utils/default_config.cfg}
[/default_config]
Expand Down
7 changes: 6 additions & 1 deletion src/ai/configuration.cpp
Expand Up @@ -49,6 +49,10 @@ void configuration::init(const config &game_config)
ERR_AI_CONFIGURATION << "Missing AI [default_config]. Therefore, default_config_ set to empty." << std::endl;
default_config_.clear();
}
default_ai_algorithm_ = ais["default_ai_algorithm"].str();
if (default_ai_algorithm_.empty()) {
ERR_AI_CONFIGURATION << "Missing default_ai_algorithm. This will result in no AI being loaded by default." << std::endl;
}


for (const config &ai_configuration : ais.child_range("ai")) {
Expand Down Expand Up @@ -166,6 +170,7 @@ configuration::description_map configuration::ai_configurations_ = configuration
configuration::description_map configuration::era_ai_configurations_ = configuration::description_map();
configuration::description_map configuration::mod_ai_configurations_ = configuration::description_map();
config configuration::default_config_ = config();
std::string configuration::default_ai_algorithm_;

bool configuration::get_side_config_from_file(const std::string& file, config& cfg ){
try {
Expand Down Expand Up @@ -359,7 +364,7 @@ void configuration::expand_simplified_aspects(side_number side, config &cfg) {
}
}
if (algorithm.empty() && !parsed_config.has_child("stage")) {
base_config = get_ai_config_for("ai_default_rca");
base_config = get_ai_config_for(default_ai_algorithm_);
}
for (const config::any_child &child : parsed_config.all_children_range()) {
base_config.add_child(child.key, child.cfg);
Expand Down
1 change: 1 addition & 0 deletions src/ai/configuration.hpp
Expand Up @@ -120,6 +120,7 @@ class configuration {
static description_map era_ai_configurations_;
static description_map mod_ai_configurations_;
static config default_config_;
static std::string default_ai_algorithm_;

};

Expand Down

0 comments on commit 073f70b

Please sign in to comment.