The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
stage_side_formulas.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Yurii Chernyi <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  * Defines formula ai side formulas stage
18  */
19 
20 
22 #include "ai/formula/ai.hpp"
23 
24 #include "formula/formula.hpp"
25 #include "formula/function.hpp"
26 #include "log.hpp"
27 #include <boost/lexical_cast.hpp>
28 
29 static lg::log_domain log_ai("ai/stage/side_formulas");
30 #define LOG_AI LOG_STREAM(info, log_ai)
31 #define WRN_AI LOG_STREAM(warn, log_ai)
32 #define ERR_AI LOG_STREAM(err, log_ai)
33 
34 namespace ai {
35 
37  : stage(context,cfg), cfg_(cfg), fai_(fai), move_formula_()
38 {
39 
40 }
41 
42 
44 {
45 }
46 
48 {
50  callable.add_ref();
51  try {
52  if (move_formula_) {
53  while( !fai_.make_action(move_formula_,callable).is_empty() ) { }
54  } else {
55  WRN_AI << "Side formula skipped, maybe it's empty or incorrect" << std::endl;
56  }
57  }
59  if(e.filename == "formula") {
60  e.line = 0;
61  }
62  fai_.handle_exception( e, "Formula error");
63  }
64  return false;
65 }
66 
67 
69 {
71 }
72 
73 
75 {
76  config cfg = stage::to_config();
77  ///@todo 1.7: serialize to config
78  cfg.append(cfg_);
79  return cfg;
80 }
81 
82 } // end of namespace ai
Defines formula ai.
config to_config() const
serialize
game_logic::formula_ptr create_optional_formula(const std::string &formula_string)
Create a new formula from the string, using the symbol table which is stored in the AI...
Definition: ai.cpp:148
void on_create()
Initialization.
void append(const config &cfg)
Append data from another config object to this one.
Definition: config.cpp:566
game_logic::const_formula_ptr move_formula_
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:57
variant make_action(game_logic::const_formula_ptr formula_, const game_logic::formula_callable &variables)
Definition: ai.cpp:194
virtual config to_config() const
serialize
Definition: stage.cpp:66
bool do_play_stage()
Play the turn - implementation.
bool is_empty() const
Definition: variant.cpp:511
Stage which executes side formulas.
Standard logging facilities (interface).
#define e
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
stage_side_formulas(ai_context &context, const config &cfg, formula_ai &fai)
#define WRN_AI
static lg::log_domain log_ai("ai/stage/side_formulas")
void handle_exception(game_logic::formula_error &e) const
Definition: ai.cpp:122