ai/composite/engine.cpp

Go to the documentation of this file.
00001 /* $Id: engine.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  * AI Support engine - creating specific ai components from config
00018  * @file
00019  */
00020 
00021 #include "engine.hpp"
00022 #include "contexts.hpp"
00023 
00024 #include "../../foreach.hpp"
00025 #include "../../log.hpp"
00026 
00027 namespace ai {
00028 
00029 static lg::log_domain log_ai_engine("ai/engine");
00030 #define DBG_AI_ENGINE LOG_STREAM(debug, log_ai_engine)
00031 #define LOG_AI_ENGINE LOG_STREAM(info, log_ai_engine)
00032 #define ERR_AI_ENGINE LOG_STREAM(err, log_ai_engine)
00033 
00034 engine::engine( readonly_context &context, const config &cfg )
00035     : ai_(context)
00036     , ai_context_(NULL)
00037     , engine_(cfg["engine"])
00038     , id_(cfg["id"])
00039     , name_(cfg["name"])
00040 {
00041     LOG_AI_ENGINE << "side "<< ai_.get_side() << " : "<<" created engine with name=["<<name_<<"]"<<std::endl;
00042 }
00043 
00044 engine::~engine()
00045 {
00046 }
00047 
00048 
00049 void engine::parse_aspect_from_config( readonly_context &context, const config &cfg, const std::string &id, std::back_insert_iterator< std::vector< aspect_ptr > > b )
00050 {
00051     engine_ptr eng = context.get_engine_by_cfg(cfg);
00052     if (eng){
00053         //do not override that method in subclasses which cannot create aspects
00054         eng->do_parse_aspect_from_config(cfg, id, b);
00055     }
00056 }
00057 
00058 void engine::parse_candidate_action_from_config( rca_context &context, const config &cfg, std::back_insert_iterator<std::vector< candidate_action_ptr > > b )
00059 {
00060     engine_ptr eng = context.get_engine_by_cfg(cfg);
00061     if (eng){
00062         //do not override that method in subclasses which cannot create candidate actions
00063         eng->do_parse_candidate_action_from_config(context, cfg, b);
00064     }
00065 }
00066 
00067 void engine::parse_engine_from_config( readonly_context &context, const config &cfg, std::back_insert_iterator<std::vector< engine_ptr > > b )
00068 {
00069     engine_ptr eng = context.get_engine_by_cfg(cfg);
00070     if (eng){
00071         //do not override that method in subclasses which cannot create engines
00072         eng->do_parse_engine_from_config(cfg, b);
00073     }
00074 }
00075 
00076 
00077 void engine::parse_goal_from_config( readonly_context &context, const config &cfg, std::back_insert_iterator<std::vector< goal_ptr > > b )
00078 {
00079     engine_ptr eng = context.get_engine_by_cfg(cfg);
00080     if (eng){
00081         //do not override that method in subclasses which cannot create goals
00082         eng->do_parse_goal_from_config(cfg, b);
00083     }
00084 }
00085 
00086 
00087 void engine::parse_stage_from_config( ai_context &context, const config &cfg, std::back_insert_iterator<std::vector< stage_ptr > > b )
00088 {
00089     engine_ptr eng = context.get_engine_by_cfg(cfg);
00090     if (eng){
00091         //do not override that method in subclasses which cannot create stages
00092         eng->do_parse_stage_from_config(context, cfg, b);
00093     }
00094 }
00095 
00096 void engine::do_parse_aspect_from_config( const config &/*cfg*/, const std::string &/*id*/, std::back_insert_iterator< std::vector<aspect_ptr> > /*b*/ )
00097 {
00098 
00099 }
00100 
00101 
00102 void engine::do_parse_candidate_action_from_config( rca_context &/*context*/, const config &/*cfg*/, std::back_insert_iterator<std::vector< candidate_action_ptr > > /*b*/ ){
00103 
00104 }
00105 
00106 void engine::do_parse_engine_from_config( const config &/*cfg*/, std::back_insert_iterator<std::vector< engine_ptr > > /*b*/ ){
00107 
00108 }
00109 
00110 
00111 void engine::do_parse_goal_from_config( const config &/*cfg*/, std::back_insert_iterator<std::vector< goal_ptr > > /*b*/ ){
00112 
00113 }
00114 
00115 
00116 void engine::do_parse_stage_from_config( ai_context &/*context*/, const config &/*cfg*/, std::back_insert_iterator<std::vector< stage_ptr > > /*b*/ )
00117 {
00118 
00119 }
00120 
00121 std::string engine::evaluate(const std::string& /*str*/)
00122 {
00123     return "evaluate command is not implemented by this engine";
00124 }
00125 
00126 void engine::set_ai_context(ai_context_ptr ai_context)
00127 {
00128     ai_context_ = ai_context;
00129 }
00130 
00131 ai_context_ptr engine::get_ai_context()
00132 {
00133     return ai_context_;
00134 }
00135 
00136 config engine::to_config() const
00137 {
00138     config cfg;
00139     cfg["engine"] = engine_;
00140     cfg["name"] = get_name();
00141     return cfg;
00142 }
00143 
00144 readonly_context& engine::get_readonly_context()
00145 {
00146     return ai_;
00147 }
00148 
00149 
00150 } //end of namespace ai
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:28 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs