The Battle for Wesnoth  1.13.10+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 - 2017 by Yurii Chernyi <terraninfo@terraninfo.net>
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 
28 static lg::log_domain log_ai("ai/stage/side_formulas");
29 #define LOG_AI LOG_STREAM(info, log_ai)
30 #define WRN_AI LOG_STREAM(warn, log_ai)
31 #define ERR_AI LOG_STREAM(err, log_ai)
32 
33 namespace ai {
34 
36  : stage(context,cfg), cfg_(cfg), fai_(fai), move_formula_()
37 {
38 
39 }
40 
41 
43 {
44 }
45 
47 {
49  try {
50  if (move_formula_) {
51  while( !fai_.make_action(move_formula_,callable).is_empty() ) { }
52  } else {
53  WRN_AI << "Side formula skipped, maybe it's empty or incorrect" << std::endl;
54  }
55  }
56  catch(wfl::formula_error& e) {
57  if(e.filename == "formula") {
58  e.line = 0;
59  }
60  fai_.handle_exception( e, "Formula error");
61  }
62  return false;
63 }
64 
65 
67 {
69 }
70 
71 
73 {
74  config cfg = stage::to_config();
75  ///@todo 1.7: serialize to config
76  cfg.append(cfg_);
77  return cfg;
78 }
79 
80 } // end of namespace ai
Defines formula ai.
wfl::const_formula_ptr move_formula_
config to_config() const
serialize
wfl::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:143
void on_create()
Initialization.
void append(const config &cfg)
Append data from another config object to this one.
Definition: config.cpp:250
std::string filename
Definition: formula.hpp:107
void handle_exception(wfl::formula_error &e) const
Definition: ai.cpp:117
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:58
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:271
formula_callable_ptr fake_ptr()
Definition: callable.hpp:41
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:93
wfl::variant make_action(wfl::const_formula_ptr formula_, const wfl::formula_callable &variables)
Definition: ai.cpp:188
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")