The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
callable_objects.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2017 by David White <dave@whitevine.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 #pragma once
16 
17 #include "formula/callable.hpp"
18 #include "formula/formula.hpp"
19 
20 #include "units/unit.hpp"
21 
22 class team;
23 class terrain_type;
24 class display_context;
25 
26 namespace wfl
27 {
28 
30 {
31 public:
32  terrain_callable(const display_context& m, const map_location& loc);
33 
34  variant get_value(const std::string& key) const override;
35  void get_inputs(formula_input_vector& inputs) const override;
36 
37  int do_compare(const formula_callable* callable) const override;
38 
39 private:
41  const terrain_type& t_;
42  const int owner_;
43 };
44 
46 {
47 public:
48  explicit gamemap_callable(const display_context& g) : board_(g)
49  {}
50 
51  void get_inputs(formula_input_vector& inputs) const override;
52  variant get_value(const std::string& key) const override;
53 
54  const gamemap& get_gamemap() const;
55 
56 private:
58 };
59 
61 {
62 public:
63  explicit location_callable(const map_location& loc) : loc_(loc)
64  {
65  type_ = LOCATION_C;
66  }
67 
68  void serialize_to_string(std::string& str) const override;
69 
70  const map_location& loc() const { return loc_; }
71 
72 private:
74 
75  variant get_value(const std::string& key) const override;
76 
77  void get_inputs(formula_input_vector& inputs) const override;
78  int do_compare(const formula_callable* callable) const override;
79 };
80 
82 {
83 public:
84  explicit attack_type_callable(const attack_type& attack) : att_(attack.shared_from_this())
85  {
87  }
88 
89  variant get_value(const std::string& key) const override;
90  void get_inputs(formula_input_vector& inputs) const override;
91 
92  int do_compare(const formula_callable* callable) const override;
93 
94  const attack_type& get_attack_type() const { return *att_; }
95 
96 private:
98 };
99 
101 {
102 public:
103  unit_callable(const map_location& loc, const unit& u) : loc_(loc), u_(u)
104  {
105  type_ = UNIT_C;
106  }
107 
108  explicit unit_callable(const unit &u) : loc_(u.get_location()), u_(u)
109  {
110  type_ = UNIT_C;
111  }
112 
113  variant get_value(const std::string& key) const override;
114  void get_inputs(formula_input_vector& inputs) const override;
115 
116  int do_compare(const formula_callable* callable) const override;
117 
118  const unit& get_unit() const { return u_; }
119  const map_location& get_location() const { return loc_; }
120 
121 private:
123  const unit& u_;
124 };
125 
127 {
128 public:
129  explicit unit_type_callable(const unit_type& u) : u_(u)
130  {
131  type_ = UNIT_TYPE_C;
132  }
133 
134  variant get_value(const std::string& key) const override;
135  void get_inputs(formula_input_vector& inputs) const override;
136 
137  int do_compare(const formula_callable* callable) const override;
138 
139  const unit_type& get_unit_type() const { return u_; }
140 
141 private:
142  const unit_type& u_;
143 };
144 
146 {
147 public:
148  explicit config_callable(const config& c) : cfg_(c) {}
149 
150  variant get_value(const std::string& key) const override;
151  void get_inputs(formula_input_vector& inputs) const override;
152  int do_compare(const formula_callable* callable) const override;
153 
154  const config& get_config() const { return cfg_; }
155 
156 private:
157  const config& cfg_;
158 };
159 
161 {
162 public:
163  explicit team_callable(const team& t) : team_(t) {}
164 
165  void get_inputs(formula_input_vector& inputs) const override;
166  variant get_value(const std::string& key) const override;
167 
168  const team& get_team() const { return team_; }
169 
170 private:
171  const team& team_;
172 };
173 
175 {
176 public:
178  : key_(key), value_(value)
179  {}
180 
181  const std::string& key() const { return key_; }
182  variant value() const { return value_; }
183  variant execute_self(variant ctxt) override;
184 
185 private:
188  variant get_value(const std::string& key) const override;
189 
190  void get_inputs(formula_input_vector& inputs) const override;
191 };
192 
194 {
195 
196 public:
198  : main_(main)
199  , backup_()
200  , backup_formula_(backup)
201  {}
202 
203  const variant& get_main() const { return main_; }
204  const expression_ptr& get_backup() const { return backup_formula_; }
205 
206  void set_backup_result(const variant& v)
207  {
208  backup_ = v;
209  }
210 
211  variant execute_self(variant ctxt) override;
212 
213 private:
217  variant get_value(const std::string& key) const override;
218 
219  void get_inputs(formula_input_vector& inputs) const override;
220 };
221 
223 {
224 public:
226  : failed_callable_(callable)
228  , status_(status)
229  {}
230 
231 private:
234  const int status_;
235 
236  variant get_value(const std::string& key) const override;
237 
238  void get_inputs(formula_input_vector& inputs) const override;
239 };
240 
241 } // namespace wfl
variant get_value(const std::string &key) const override
std::vector< char_t > string
const std::string & key() const
set_var_callable(const std::string &key, const variant &value)
void get_inputs(formula_input_vector &inputs) const override
safe_call_result(const_formula_callable_ptr callable, int status, const map_location &loc=map_location())
const attack_type & get_attack_type() const
const map_location & get_location() const
void get_inputs(formula_input_vector &inputs) const override
This class represents a single unit of a specific type.
Definition: unit.hpp:101
variant get_value(const std::string &key) const override
const gamemap & get_gamemap() const
team_callable(const team &t)
variant get_value(const std::string &key) const override
const display_context & board_
std::vector< formula_input > formula_input_vector
config_callable(const config &c)
unit_type_callable(const unit_type &u)
void get_inputs(formula_input_vector &inputs) const override
formula_input_vector inputs() const
Definition: callable.hpp:62
void get_inputs(formula_input_vector &inputs) const override
void get_inputs(formula_input_vector &inputs) const override
std::shared_ptr< formula_expression > expression_ptr
Definition: formula.hpp:28
A single unit type that the player may recruit.
Definition: types.hpp:43
const_formula_callable_ptr failed_callable_
variant get_value(const std::string &key) const override
void get_inputs(formula_input_vector &inputs) const override
variant execute_self(variant ctxt) override
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:44
int do_compare(const formula_callable *callable) const override
void set_backup_result(const variant &v)
const variant & get_main() const
gamemap_callable(const display_context &g)
attack_type_callable(const attack_type &attack)
int do_compare(const formula_callable *callable) const override
Encapsulates the map of the game.
Definition: map.hpp:34
int do_compare(const formula_callable *callable) const override
const config & get_config() const
void serialize_to_string(std::string &str) const override
const unit & get_unit() const
variant get_value(const std::string &key) const override
void get_inputs(formula_input_vector &inputs) const override
const map_location & loc_
variant get_value(const std::string &key) const override
void get_inputs(formula_input_vector &inputs) const override
const expression_ptr & get_backup() const
Encapsulates the map of the game.
Definition: location.hpp:40
int do_compare(const formula_callable *callable) const override
int main()
void get_inputs(formula_input_vector &inputs) const override
void get_inputs(formula_input_vector &inputs) const override
variant get_value(const std::string &key) const override
double g
Definition: astarsearch.cpp:64
const map_location loc_
variant get_value(const std::string &key) const override
unit_callable(const map_location &loc, const unit &u)
const terrain_type & t_
std::shared_ptr< const formula_callable > const_formula_callable_ptr
variant get_value(const std::string &key) const override
location_callable(const map_location &loc)
const unit_type & get_unit_type() const
double t
Definition: astarsearch.cpp:64
Definition: contexts.hpp:42
int do_compare(const formula_callable *callable) const override
const map_location & loc() const
variant get_value(const std::string &key) const override
variant execute_self(variant ctxt) override
terrain_callable(const display_context &m, const map_location &loc)
void get_inputs(formula_input_vector &inputs) const override
int do_compare(const formula_callable *callable) const override
variant get_value(const std::string &key) const override
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
mock_char c
const map_location current_unit_location_
std::shared_ptr< const attack_type > const_attack_ptr
Definition: ptr.hpp:37
safe_call_callable(const variant &main, const expression_ptr &backup)
const team & get_team() const
unit_callable(const unit &u)