ai/composite/stage.cpp

Go to the documentation of this file.
00001 /* $Id: stage.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 of a composite AI
00018  * @file
00019  */
00020 
00021 #include "ai.hpp"
00022 #include "engine.hpp"
00023 #include "stage.hpp"
00024 #include "../contexts.hpp"
00025 #include "../../foreach.hpp"
00026 #include "../../log.hpp"
00027 #include "../../resources.hpp"
00028 #include "../../tod_manager.hpp"
00029 #include <map>
00030 #include <string>
00031 
00032 namespace ai {
00033 
00034 static lg::log_domain log_ai_stage("ai/stage");
00035 #define DBG_AI_STAGE LOG_STREAM(debug, log_ai_stage)
00036 #define LOG_AI_STAGE LOG_STREAM(info, log_ai_stage)
00037 #define ERR_AI_STAGE LOG_STREAM(err, log_ai_stage)
00038 
00039 // =======================================================================
00040 // COMPOSITE AI STAGE
00041 // =======================================================================
00042 
00043 stage::stage( ai_context &context, const config &cfg )
00044     : recursion_counter_(context.get_recursion_count()), cfg_(cfg)
00045 {
00046     init_ai_context_proxy(context);
00047 }
00048 
00049 void stage::on_create()
00050 {
00051     LOG_AI_STAGE << "side "<< get_side() << " : "<<" created stage with name=["<<cfg_["name"]<<"]"<<std::endl;
00052 }
00053 
00054 stage::~stage()
00055 {
00056 }
00057 
00058 bool stage::play_stage()
00059 {
00060     return do_play_stage();
00061 }
00062 
00063 int stage::get_recursion_count() const
00064 {
00065     return recursion_counter_.get_count();
00066 }
00067 
00068 config stage::to_config() const
00069 {
00070     config cfg;
00071     cfg["engine"] = cfg_["engine"];
00072     cfg["name"] = cfg_["name"];
00073     cfg["id"] = cfg_["id"];
00074     return cfg;
00075 }
00076 
00077 std::string stage::get_id() const
00078 {
00079     return cfg_["id"];
00080 }
00081 
00082 std::string stage::get_engine() const
00083 {
00084     return cfg_["engine"];
00085 }
00086 
00087 std::string stage::get_name() const
00088 {
00089     return cfg_["name"];
00090 }
00091 
00092 
00093 
00094 
00095 // =======================================================================
00096 // COMPOSITE AI IDLE STAGE
00097 // =======================================================================
00098 
00099 
00100 idle_stage::idle_stage( ai_context &context, const config &cfg )
00101     : stage(context,cfg)
00102 {
00103 }
00104 
00105 idle_stage::~idle_stage()
00106 {
00107 }
00108 
00109 bool idle_stage::do_play_stage(){
00110     LOG_AI_STAGE << "Turn " << resources::tod_manager->turn() << ": playing idle stage for side: "<< get_side() << std::endl;
00111     return false;
00112 }
00113 
00114 // =======================================================================
00115 // COMPOSITE AI MINISTAGE
00116 // =======================================================================
00117 
00118 ministage::ministage(const config &cfg)
00119     : cfg_(cfg),stage_()
00120 {
00121 }
00122 
00123 ministage::~ministage()
00124 {
00125 }
00126 
00127 
00128 stage_ptr ministage::get_stage_ptr(ai_context &context)
00129 {
00130     if (stage_) {
00131         return stage_;
00132     }
00133 
00134     std::vector<stage_ptr> stages;
00135     engine::parse_stage_from_config(context,cfg_,std::back_inserter(stages));
00136     if (stages.empty()) {
00137         return stage_ptr();
00138     }
00139     stage_ = stages.front();
00140     return stage_;
00141 }
00142 
00143 config ministage::to_config() const
00144 {
00145     if (!stage_) {
00146         return cfg_;
00147     }
00148     return stage_->to_config();
00149 }
00150 
00151 
00152 
00153 } //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:43 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs