Change syntax of fallback stage

I've done this avoid giving the illusion that it merely loads another composite AI definition by its ID.
It can, of course, still be used to do so, if that's really what you want, but normally it should not be needed.
This commit is contained in:
Celtic Minstrel 2016-02-29 23:07:41 -05:00 committed by mattsc
parent 7c9e24aa29
commit d0e3bc6a70
6 changed files with 18 additions and 14 deletions

View file

@ -24,6 +24,7 @@
#include "goal.hpp"
#include "property_handler.hpp"
#include "stage.hpp"
#include "ai/configuration.hpp"
#include "ai/manager.hpp"
#include "actions/attack.hpp"
#include "log.hpp"
@ -212,4 +213,12 @@ config ai_composite::to_config() const
return cfg;
}
config ai_composite::preparse_cfg(ai_context& ctx, const config& cfg)
{
config temp_cfg, parsed_cfg;
temp_cfg.add_child("ai", cfg);
configuration::parse_side_config(ctx.get_side(), temp_cfg, parsed_cfg);
return parsed_cfg;
}
} //end of namespace ai

View file

@ -106,6 +106,8 @@ public:
virtual std::string get_id() const;
virtual std::string get_name() const;
virtual std::string get_engine() const;
static config preparse_cfg(ai_context& ctx, const config& cfg);
protected:

View file

@ -84,9 +84,7 @@ void idle_ai::switch_side(side_number side)
config idle_ai::to_config() const
{
config cfg;
cfg["ai_algorithm"]= "idle_ai";
return cfg;
return config();
}

View file

@ -39,6 +39,7 @@ public:
void switch_side(side_number side);
int get_recursion_count() const;
virtual config to_config() const;
static config preparse_cfg(ai_context&, const config& cfg) {return cfg;}
private:
recursion_counter recursion_counter_;
};

View file

@ -115,7 +115,8 @@ public:
}
virtual ai_ptr get_new_instance( ai_context &context, const config &cfg){
ai_ptr a(new AI(context,cfg));
config preparsed_cfg = AI::preparse_cfg(context, cfg);
ai_ptr a(new AI(context,preparsed_cfg));
a->on_create();
return a;
}

View file

@ -40,15 +40,7 @@ fallback_to_other_ai::fallback_to_other_ai( ai_context &context, const config &c
void fallback_to_other_ai::on_create()
{
config ai_cfg = cfg_.child_or_empty("ai");
///@deprecated 1.9.3 backward-compatibility hack - try to update the old default ai config.
std::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);
}
}
fallback_ai_ = manager::create_transient_ai(cfg_["type"], cfg_.child_or_empty("params"), this);
}
@ -57,7 +49,8 @@ config fallback_to_other_ai::to_config() const
config cfg = stage::to_config();
if (fallback_ai_) {
cfg.add_child("ai",fallback_ai_->to_config());
cfg["type"] = cfg_["type"];
cfg.add_child("params",fallback_ai_->to_config());
}
return cfg;
}