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 #include "map/location.hpp"
20 #include "units/ptr.hpp"
21 
22 class display_context;
23 class gamemap;
24 class team;
25 class terrain_type;
26 class unit;
27 class unit_type;
28 
29 namespace wfl
30 {
31 
33 {
34 public:
35  terrain_callable(const display_context& m, const map_location& loc);
36 
37  variant get_value(const std::string& key) const override;
38  void get_inputs(formula_input_vector& inputs) const override;
39 
40  int do_compare(const formula_callable* callable) const override;
41 
42 private:
44  const terrain_type& t_;
45  const int owner_;
46 };
47 
49 {
50 public:
51  explicit gamemap_callable(const display_context& g) : board_(g)
52  {}
53 
54  void get_inputs(formula_input_vector& inputs) const override;
55  variant get_value(const std::string& key) const override;
56 
57  const gamemap& get_gamemap() const;
58 
59 private:
61 };
62 
64 {
65 public:
66  explicit location_callable(const map_location& loc) : loc_(loc)
67  {
68  type_ = LOCATION_C;
69  }
70 
71  void serialize_to_string(std::string& str) const override;
72 
73  const map_location& loc() const { return loc_; }
74 
75 private:
77 
78  variant get_value(const std::string& key) const override;
79 
80  void get_inputs(formula_input_vector& inputs) const override;
81  int do_compare(const formula_callable* callable) const override;
82 };
83 
85 {
86 public:
87  explicit attack_type_callable(const attack_type& attack);
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);
109 
110  variant get_value(const std::string& key) const override;
111  void get_inputs(formula_input_vector& inputs) const override;
112 
113  int do_compare(const formula_callable* callable) const override;
114 
115  const unit& get_unit() const { return u_; }
116  const map_location& get_location() const { return loc_; }
117 
118 private:
120  const unit& u_;
121 };
122 
124 {
125 public:
126  explicit unit_type_callable(const unit_type& u) : u_(u)
127  {
128  type_ = UNIT_TYPE_C;
129  }
130 
131  variant get_value(const std::string& key) const override;
132  void get_inputs(formula_input_vector& inputs) const override;
133 
134  int do_compare(const formula_callable* callable) const override;
135 
136  const unit_type& get_unit_type() const { return u_; }
137 
138 private:
139  const unit_type& u_;
140 };
141 
143 {
144 public:
145  explicit config_callable(const config& c) : cfg_(c) {}
146 
147  variant get_value(const std::string& key) const override;
148  void get_inputs(formula_input_vector& inputs) const override;
149  int do_compare(const formula_callable* callable) const override;
150 
151  const config& get_config() const { return cfg_; }
152 
153 private:
154  const config& cfg_;
155 };
156 
158 {
159 public:
160  explicit team_callable(const team& t) : team_(t) {}
161 
162  void get_inputs(formula_input_vector& inputs) const override;
163  variant get_value(const std::string& key) const override;
164 
165  const team& get_team() const { return team_; }
166 
167 private:
168  const team& team_;
169 };
170 
172 {
173 public:
175  : key_(key), value_(value)
176  {}
177 
178  const std::string& key() const { return key_; }
179  variant value() const { return value_; }
180  variant execute_self(variant ctxt) override;
181 
182 private:
185  variant get_value(const std::string& key) const override;
186 
187  void get_inputs(formula_input_vector& inputs) const override;
188 };
189 
191 {
192 
193 public:
195  : main_(main)
196  , backup_()
197  , backup_formula_(backup)
198  {}
199 
200  const variant& get_main() const { return main_; }
201  const expression_ptr& get_backup() const { return backup_formula_; }
202 
203  void set_backup_result(const variant& v)
204  {
205  backup_ = v;
206  }
207 
208  variant execute_self(variant ctxt) override;
209 
210 private:
214  variant get_value(const std::string& key) const override;
215 
216  void get_inputs(formula_input_vector& inputs) const override;
217 };
218 
220 {
221 public:
223  : failed_callable_(callable)
225  , status_(status)
226  {}
227 
228 private:
231  const int status_;
232 
233  variant get_value(const std::string& key) const override;
234 
235  void get_inputs(formula_input_vector& inputs) const override;
236 };
237 
238 } // 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:100
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