mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-07 21:58:36 +00:00
Log useful error messages (and don't crash) when creating a goal with the wrong engine
This commit is contained in:
parent
852a25593e
commit
08b11139a1
@ -106,7 +106,7 @@ void engine_cpp::do_parse_goal_from_config(const config &cfg, std::back_insert_i
|
||||
return;
|
||||
}
|
||||
goal_ptr new_goal = f->second->get_new_instance(ai_,cfg);
|
||||
if (!new_goal) {
|
||||
if (!new_goal || !new_goal->ok()) {
|
||||
ERR_AI_ENGINE_CPP << "side "<<ai_.get_side()<< " : UNABLE TO CREATE goal["<<cfg["name"]<<"]"<< std::endl;
|
||||
DBG_AI_ENGINE_CPP << "config snippet contains: " << std::endl << cfg << std::endl;
|
||||
return;
|
||||
|
@ -351,7 +351,7 @@ void engine_lua::do_parse_goal_from_config(const config &cfg, std::back_insert_i
|
||||
}
|
||||
goal_ptr new_goal = f->second->get_new_instance(ai_,cfg);
|
||||
new_goal->on_create(lua_ai_context_);
|
||||
if (!new_goal) {
|
||||
if (!new_goal || !new_goal->ok()) {
|
||||
ERR_AI_LUA << "side "<<ai_.get_side()<< " : UNABLE TO CREATE goal["<<cfg["name"]<<"]"<< std::endl;
|
||||
DBG_AI_LUA << "config snippet contains: " << std::endl << cfg << std::endl;
|
||||
return;
|
||||
|
@ -49,7 +49,7 @@ static lg::log_domain log_ai_goal("ai/goal");
|
||||
#define ERR_AI_GOAL LOG_STREAM(err, log_ai_goal)
|
||||
|
||||
goal::goal(readonly_context &context, const config &cfg)
|
||||
: readonly_context_proxy(), cfg_(cfg)
|
||||
: readonly_context_proxy(), cfg_(cfg), ok_(true)
|
||||
{
|
||||
init_readonly_context_proxy(context);
|
||||
}
|
||||
@ -58,10 +58,18 @@ goal::goal(readonly_context &context, const config &cfg)
|
||||
|
||||
void goal::on_create()
|
||||
{
|
||||
LOG_AI_GOAL << "side " << get_side() << " : " << " created goal with name=[" << cfg_["name"] << "]" << std::endl;
|
||||
}
|
||||
|
||||
void goal::on_create(boost::shared_ptr<ai::lua_ai_context>)
|
||||
{
|
||||
unrecognized();
|
||||
}
|
||||
|
||||
void goal::unrecognized()
|
||||
{
|
||||
ERR_AI_GOAL << "side " << get_side() << " : " << " tried to create goal with name=[" << cfg_["name"] << "], but the [" << cfg_["engine"] << "] engine did not recognize that type of goal. " << std::endl;
|
||||
ok_ = false;
|
||||
}
|
||||
|
||||
|
||||
@ -105,6 +113,12 @@ bool goal::redeploy(const config &cfg)
|
||||
}
|
||||
|
||||
|
||||
bool goal::ok() const
|
||||
{
|
||||
return ok_;
|
||||
}
|
||||
|
||||
|
||||
bool goal::active() const
|
||||
{
|
||||
return is_active(cfg_["time_of_day"],cfg_["turns"]);
|
||||
@ -114,6 +128,11 @@ bool goal::active() const
|
||||
void target_unit_goal::on_create()
|
||||
{
|
||||
goal::on_create();
|
||||
if (cfg_["engine"] != "cpp") {
|
||||
unrecognized();
|
||||
value_ = 0;
|
||||
return;
|
||||
}
|
||||
if (const config::attribute_value *v = cfg_.get("value")) {
|
||||
try {
|
||||
value_ = boost::lexical_cast<double>(*v);
|
||||
@ -156,6 +175,11 @@ target_unit_goal::target_unit_goal(readonly_context &context, const config &cfg)
|
||||
void target_location_goal::on_create()
|
||||
{
|
||||
goal::on_create();
|
||||
if (cfg_["engine"] != "cpp") {
|
||||
unrecognized();
|
||||
value_ = 0;
|
||||
return;
|
||||
}
|
||||
if (cfg_.has_attribute("value")) {
|
||||
try {
|
||||
value_ = boost::lexical_cast<double>(cfg_["value"]);
|
||||
@ -200,6 +224,11 @@ target_location_goal::target_location_goal(readonly_context &context, const conf
|
||||
void protect_goal::on_create()
|
||||
{
|
||||
goal::on_create();
|
||||
if (cfg_["engine"] != "cpp") {
|
||||
unrecognized();
|
||||
value_ = 0;
|
||||
return;
|
||||
}
|
||||
if (const config::attribute_value *v = cfg_.get("value")) {
|
||||
try {
|
||||
value_ = boost::lexical_cast<double>(*v);
|
||||
@ -319,7 +348,7 @@ lua_goal::lua_goal(readonly_context &context, const config &cfg)
|
||||
}
|
||||
else
|
||||
{
|
||||
// report failure
|
||||
ERR_AI_GOAL << "side " << get_side() << " : Error creating Lua goal (missing code= key)" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,6 +69,7 @@ public:
|
||||
|
||||
|
||||
bool active() const;
|
||||
bool ok() const;
|
||||
|
||||
virtual std::string get_id() const;
|
||||
virtual std::string get_name() const;
|
||||
@ -78,8 +79,9 @@ public:
|
||||
|
||||
|
||||
protected:
|
||||
void unrecognized();
|
||||
config cfg_;
|
||||
|
||||
bool ok_;
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user