add a workaround to convert old usages of 'fallback to default ai'...

...to 'fallback to rca ai'
This commit is contained in:
Iurii Chernyi 2010-04-29 21:24:50 +00:00
parent 90dbf9cdeb
commit 5a4e32bb55
6 changed files with 27 additions and 52 deletions

View File

@ -1,14 +0,0 @@
#textdomain wesnoth
[ai]
id=default # id is needed uniquely identify a MP AI, it is not needed in the scenario AI
description=_"Multiplayer_AI^Default AI" # this description is, again, needed for MP AI (it shows in AI list under this description
version=10703 # no spaces here, version should be parsed as int. This version marker is a sign that ALL snippets of AI are written using new syntax
[stage] #this is a stage. Each turn is: 'foreach stage in stages, play it'
engine=cpp #cpp engine is default engine, so it can be omitted. other engines include fai (formula AI engine). Engine is a thing that parses this config snippet (in this case, 'stage' is parsed by cpp engine).
id=fallback #id is an optional parameter to uniquely identify a stage. It will be needed when [modify_ai] tag will be created
name=testing_ai_default::fallback # 'name' is used by cpp engine to find out 'what stage shall be created?'. in this case, this is fallback stage. See src/ai/registry.cpp or http://www.wesnoth.org/wiki/Ai_Module#AI_Config_Format for a list
[ai] # this is fallback stage specific parameter - it holds parameters of the AI to which we fall back in this fallback stage
ai_algorithm=default_ai # that means 'fall back to default c++-based AI'
[/ai]
[/stage]
[/ai]

View File

@ -2,16 +2,21 @@
[ai]
id=formula_ai # id is needed to uniquely identify a MP AI, it is not needed in the scenario AI
description=Formula AI dev# this description is, again, needed for MP AI (it shows in AI list under this description
version=10703 # no spaces here, version should be parsed as int. This version marker is a sign that ALL snippets of AI are written using new syntax
version=10710 # no spaces here, version should be parsed as int. This version marker is a sign that ALL snippets of AI are written using new syntax
{AI_SIMPLE_FORMULA_AI_EXPERIMENTAL_RECRUITMENT}
[stage] #this is a stage. Each turn is: 'foreach stage in stages, play it'
engine=cpp #cpp engine is default engine, so it can be omitted. other engines include fai (formula AI engine). Engine is a thing that parses this config snippet (in this case, 'stage' is parsed by cpp engine).
id=fallback #id is an optional parameter to uniquely identify a stage. It will be needed when [modify_ai] tag will be created
name=testing_ai_default::fallback # 'name' is used by cpp engine to find out 'what stage shall be created?'. in this case, this is fallback stage. See src/ai/registry.cpp or http://www.wesnoth.org/wiki/Ai_Module#AI_Config_Format for a list
[ai] # this is fallback stage specific parameter - it holds parameters of the AI to which we fall back in this fallback stage
ai_algorithm=default_ai # that means 'fall back to default c++-based AI'
[/ai]
[stage]
id=main_loop
name=testing_ai_default::candidate_action_evaluation_loop
{AI_CA_GOTO}
{AI_CA_RECRUITMENT}
{AI_CA_MOVE_LEADER_TO_GOALS}
{AI_CA_MOVE_LEADER_TO_KEEP}
{AI_CA_COMBAT}
{AI_CA_HEALING}
{AI_CA_VILLAGES}
{AI_CA_RETREAT}
{AI_CA_MOVE_TO_TARGETS}
[/stage]
[/ai]

View File

@ -1,6 +1,5 @@
#textdomain wesnoth
#note: as fai engine is temporary disabled, this example will not work atm, it will work again soon
[ai]
id=default_ai_poisoning
description= Default AI with poisoning formula
@ -20,11 +19,4 @@
action="{ai/formula/poisoner_attack.fai}"
[/candidate_action]
[/stage]
[stage] #as candidate action evaluation loop ends when all actions score <=0, this stage is needed to play the rest of the turn
engine=cpp
name=testing_ai_default::fallback
[ai] # this is fallback stage specific parameter - it holds parameters of the AI to which we fall back in this fallback stage
ai_algorithm = default_ai # that means 'fall back to default c++-based AI'
[/ai]
[/stage]
[/ai]

View File

@ -39,18 +39,10 @@
[event]
name=preload
first_time_only=no
[set_variable]
name=test_path_to_ai
value=ai/ais/default_ai.cfg
[/set_variable]
[set_variable]
name=test_path_to_idle_ai
value=ai/dev/idle_ai.cfg
[/set_variable]
[set_variable]
name=test_path_to_default_ai
value=ai/ais/default_ai.cfg
[/set_variable]
[set_variable]
name=test_path_to_formula_ai
value=ai/ais/formula_ai.cfg
@ -186,15 +178,6 @@
[/set_variable]
[/command]
[/option]
[option]
message="My AI is DEFAULT AI, and it strikes fear into the hearts of mortals."
[command]
[set_variable]
name=test_path_to_ai
value=$test_path_to_default_ai
[/set_variable]
[/command]
[/option]
[option]
message="I am the king of FORMULA AI, and I will use its vast powers for world domination."
[command]

View File

@ -39,8 +39,8 @@ namespace ai {
// AIs
// =======================================================================
static register_ai_factory<ai_default> ai_factory_default("");
static register_ai_factory<ai_default> ai_default_ai_factory("default_ai");
static register_ai_factory<ai_composite> ai_factory_default("");
static register_ai_factory<ai_composite> ai_default_ai_factory("default_ai");
static register_ai_factory<ai2> ai2_ai_factory("ai2");
static register_ai_factory<idle_ai> ai_idle_ai_factory("idle_ai");
//static register_ai_factory<formula_ai> ai_formula_ai_factory("formula_ai");

View File

@ -19,6 +19,7 @@
#include "stage_fallback.hpp"
#include "../configuration.hpp"
#include "../manager.hpp"
#include "../composite/ai.hpp"
#include "../../foreach.hpp"
@ -40,14 +41,22 @@ fallback_to_other_ai::fallback_to_other_ai( ai_context &context, const config &c
void fallback_to_other_ai::on_create()
{
const config ai_cfg = cfg_.child_or_empty("ai");
fallback_ai_ = manager::create_transient_ai(ai_cfg["ai_algorithm"], ai_cfg, this);
config ai_cfg = cfg_.child_or_empty("ai");
//@todo 1.9.3 backward-compatability hack - try to update the old default ai config. remove in 1.9.3
config::proxy_string ai_algorithm = ai_cfg["ai_algorithm"];
if ((ai_algorithm.empty()) || (ai_algorithm=="default_ai")) {
if (configuration::parse_side_config(get_side(),cfg_,ai_cfg)) {
fallback_ai_ = manager::create_transient_ai("", ai_cfg, this);
}
}
}
config fallback_to_other_ai::to_config() const
{
config cfg = stage::to_config();
if (fallback_ai_) {
cfg.add_child("ai",fallback_ai_->to_config());
}