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
00022 #include "stage_side_formulas.hpp"
00023 #include "ai.hpp"
00024
00025 #include "../../foreach.hpp"
00026 #include "../../formula.hpp"
00027 #include "../../formula_function.hpp"
00028 #include "../../log.hpp"
00029 #include <boost/lexical_cast.hpp>
00030
00031 static lg::log_domain log_ai("ai/stage/side_formulas");
00032 #define LOG_AI LOG_STREAM(info, log_ai)
00033 #define WRN_AI LOG_STREAM(warn, log_ai)
00034 #define ERR_AI LOG_STREAM(err, log_ai)
00035
00036 namespace ai {
00037
00038 stage_side_formulas::stage_side_formulas(ai_context &context, const config &cfg, formula_ai &fai)
00039 : stage(context,cfg), cfg_(cfg), fai_(fai), move_formula_()
00040 {
00041
00042 }
00043
00044
00045 stage_side_formulas::~stage_side_formulas()
00046 {
00047 }
00048
00049 bool stage_side_formulas::do_play_stage()
00050 {
00051 game_logic::map_formula_callable callable(&fai_);
00052 callable.add_ref();
00053 try {
00054 if (move_formula_) {
00055 while( !fai_.make_action(move_formula_,callable).is_empty() ) { }
00056 } else {
00057 WRN_AI << "Side formula skipped, maybe it's empty or incorrect" << std::endl;
00058 }
00059 }
00060 catch(game_logic::formula_error& e) {
00061 if(e.filename == "formula") {
00062 e.line = 0;
00063 }
00064 fai_.handle_exception( e, "Formula error");
00065 }
00066 return false;
00067 }
00068
00069
00070 void stage_side_formulas::on_create()
00071 {
00072 move_formula_ = fai_.create_optional_formula(cfg_["move"]);
00073 }
00074
00075
00076 config stage_side_formulas::to_config() const
00077 {
00078 config cfg = stage::to_config();
00079
00080 cfg.append(cfg_);
00081 return cfg;
00082 }
00083
00084 }