Skip to content

Commit

Permalink
AI configuration: new optional parameter mp_rank=
Browse files Browse the repository at this point in the history
This parameter determines in which order the available AIs are shown in the MP computer player selection menu. This can be used for eras, modifications or cores to change which AI is first in the list.
  • Loading branch information
mattsc committed Nov 18, 2018
1 parent fcc22a3 commit c731be5
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/ai/ais/ai_default_rca.cfg
Expand Up @@ -7,6 +7,7 @@
[ai]
id=ai_default_rca
description=_"Multiplayer_AI^Default AI (RCA)" # wmllint: no spellcheck
mp_rank=1010
# RCA := Register Candidate Action; more info at http://forums.wesnoth.org/viewtopic.php?p=419625#p419625
[stage]
id=main_loop
Expand Down
1 change: 1 addition & 0 deletions data/ai/ais/ai_experimental.cfg
Expand Up @@ -7,6 +7,7 @@
[ai]
id=experimental_ai
description=_"Multiplayer_AI^Experimental AI" # wmllint: no spellcheck
mp_rank=1000

[stage]
id=main_loop
Expand Down
1 change: 1 addition & 0 deletions data/ai/dev/ai_default_rca_alternate_recruiting.cfg
Expand Up @@ -8,6 +8,7 @@
[ai]
id=ai_default_rca_alternate_recruiting
description=_"Multiplayer_AI^Dev AI: Default AI (RCA) with Alternate Recruiting" # wmllint: no spellcheck
mp_rank=100
# RCA := Register Candidate Action; more info at http://forums.wesnoth.org/viewtopic.php?p=419625#p419625
[stage]
id=main_loop
Expand Down
1 change: 1 addition & 0 deletions data/ai/dev/formula_ai.cfg
Expand Up @@ -8,6 +8,7 @@
[ai]
id=formula_ai # id is needed to uniquely identify a MP AI, it is not needed in the scenario AI
description=_"Multiplayer_AI^Dev AI: Default + Experimental Recruitment (Formula AI)" # wmllint: no spellcheck
mp_rank=100
# this description is, again, needed for MP AI (it shows in AI list under this description

[stage]
Expand Down
1 change: 1 addition & 0 deletions data/ai/dev/formula_ai_poisoning.cfg
Expand Up @@ -7,6 +7,7 @@
[ai]
id=formula_ai_poisoning
description=_"Multiplayer_AI^Dev AI: Default + Poisoning (Formula AI)" # wmllint: no spellcheck
mp_rank=100
[stage]
id=main_loop
name=ai_default_rca::candidate_action_evaluation_loop
Expand Down
9 changes: 9 additions & 0 deletions src/ai/configuration.cpp
Expand Up @@ -69,6 +69,7 @@ void configuration::init(const config &game_config)

description desc;
desc.id=id;
desc.mp_rank=ai_configuration["mp_rank"].to_int(0);
desc.text = ai_configuration["description"].t_str();
desc.cfg=ai_configuration;

Expand All @@ -95,6 +96,7 @@ void extract_ai_configurations(std::map<std::string, description> &storage, cons
description desc;
desc.id=id;
desc.text = ai_configuration["description"].t_str();
desc.mp_rank = ai_configuration["mp_rank"].to_int(0);
desc.cfg=ai_configuration;

storage.emplace(id, desc);
Expand Down Expand Up @@ -143,6 +145,13 @@ std::vector<description*> configuration::get_available_ais()
add_if_not_hidden(&m_config.second);
}

// Sort by mp_rank. For same mp_rank, keep alphabetical order.
std::stable_sort(ais_list.begin(), ais_list.end(),
[](const description* a, const description* b) {
return a->mp_rank > b->mp_rank;
}
);

return ais_list;
}

Expand Down
2 changes: 2 additions & 0 deletions src/ai/configuration.hpp
Expand Up @@ -46,12 +46,14 @@ struct description {
description()
: text()
, id()
, mp_rank()
, cfg()
{
}

t_string text;
std::string id;
int mp_rank;
config cfg;
};

Expand Down

0 comments on commit c731be5

Please sign in to comment.