Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
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
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 }