ai/formula/stage_side_formulas.cpp

Go to the documentation of this file.
00001 /* $Id: stage_side_formulas.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  * @file
00018  * Defines formula ai side formulas stage
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     ///@todo 1.7: serialize to config
00080     cfg.append(cfg_);
00081     return cfg;
00082 }
00083 
00084 } // 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:44 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs