ai/testing/stage_fallback.cpp

Go to the documentation of this file.
00001 /* $Id: stage_fallback.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2009 - 2012 by Yurii Chernyi <terraninfo@terraninfo.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 /**
00017  * Stage: fallback to other AI
00018  * @file
00019  */
00020 
00021 #include "stage_fallback.hpp"
00022 
00023 #include "../configuration.hpp"
00024 #include "../manager.hpp"
00025 #include "../composite/ai.hpp"
00026 #include "../../foreach.hpp"
00027 #include "../../log.hpp"
00028 
00029 namespace ai {
00030 
00031 namespace testing_ai_default {
00032 
00033 static lg::log_domain log_ai_testing_stage_fallback("ai/stage/fallback");
00034 #define DBG_AI_TESTING_STAGE_FALLBACK LOG_STREAM(debug, log_ai_testing_stage_fallback)
00035 #define LOG_AI_TESTING_STAGE_FALLBACK LOG_STREAM(info, log_ai_testing_stage_fallback)
00036 #define ERR_AI_TESTING_STAGE_FALLBACK LOG_STREAM(err, log_ai_testing_stage_fallback)
00037 
00038 fallback_to_other_ai::fallback_to_other_ai( ai_context &context, const config &cfg )
00039     : stage(context,cfg), cfg_(cfg), fallback_ai_()
00040 {
00041 }
00042 
00043 void fallback_to_other_ai::on_create()
00044 {
00045     config ai_cfg = cfg_.child_or_empty("ai");
00046     ///@deprecated 1.9.3 backward-compatibility hack - try to update the old default ai config.
00047     std::string ai_algorithm = ai_cfg["ai_algorithm"];
00048     if ((ai_algorithm.empty()) || (ai_algorithm=="default_ai")) {
00049         if (configuration::parse_side_config(get_side(),cfg_,ai_cfg)) {
00050                 fallback_ai_ = manager::create_transient_ai("", ai_cfg, this);
00051         }
00052     }
00053 
00054 }
00055 
00056 
00057 config fallback_to_other_ai::to_config() const
00058 {
00059     config cfg = stage::to_config();
00060 
00061     if (fallback_ai_) {
00062         cfg.add_child("ai",fallback_ai_->to_config());
00063     }
00064     return cfg;
00065 }
00066 
00067 bool fallback_to_other_ai::do_play_stage()
00068 {
00069     if (fallback_ai_) {
00070         LOG_AI_TESTING_STAGE_FALLBACK << "side "<<get_side()<<" : falling back to "<<fallback_ai_->describe_self()<<std::endl;
00071         fallback_ai_->new_turn();
00072         fallback_ai_->play_turn();
00073     } else {
00074         ERR_AI_TESTING_STAGE_FALLBACK << "side "<<get_side()<<" : UNABLE TO FALLBACK, fallback ai is NULL"<<std::endl;
00075     }
00076     return false;
00077 }
00078 
00079 fallback_to_other_ai::~fallback_to_other_ai()
00080 {
00081 }
00082 
00083 } // end of namespace testing_ai_default
00084 
00085 } // end of namespace ai
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:45 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs