The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
callable_objects.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2014 - 2025
3 by David White <dave@whitevine.net>
4 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY.
12
13 See the COPYING file for more details.
14*/
15
16#pragma once
17
18#include "color.hpp"
19#include "formula/callable.hpp"
20#include "formula/formula.hpp"
21#include "map/location.hpp"
22#include "units/ptr.hpp"
23
24class display_context;
25class gamemap;
26class team;
27class terrain_type;
28class unit;
29class unit_type;
30namespace game_events {struct queued_event;}
31
32namespace wfl
33{
34
35/** An object representing the state of the game, providing access to the map and basic information */
37{
38public:
39 // Currently it accesses all its state through the resources namespace, so nothing is passed into it.
40
41 void get_inputs(formula_input_vector& inputs) const override;
42 variant get_value(const std::string& key) const override;
43};
44
45/** An object representing the state of the current event; equivalent to Lua's wesnoth.current.event_context */
47{
48public:
50
51 void get_inputs(formula_input_vector& inputs) const override;
52 variant get_value(const std::string& key) const override;
53private:
55 mutable std::shared_ptr<attack_type> first_weapon, second_weapon;
56};
57
59{
60public:
62
63 variant get_value(const std::string& key) const override;
64 void get_inputs(formula_input_vector& inputs) const override;
65
66 int do_compare(const formula_callable* callable) const override;
67
68 const terrain_type& get_terrain_type() const { return t_; }
69
70private:
73 const int owner_;
74};
75
77{
78public:
80 {}
81
82 void get_inputs(formula_input_vector& inputs) const override;
83 variant get_value(const std::string& key) const override;
84
85 const gamemap& get_gamemap() const;
86
87private:
89};
90
92{
93public:
95 {
97 }
98
99 /** Inherited from formula_callable. */
100 std::string serialize_to_string() const override;
101
102 const map_location& loc() const { return loc_; }
103
104private:
106
107 variant get_value(const std::string& key) const override;
108
109 void get_inputs(formula_input_vector& inputs) const override;
110 int do_compare(const formula_callable* callable) const override;
111};
112
114{
115public:
116 explicit attack_type_callable(const attack_type& attack);
117
118 variant get_value(const std::string& key) const override;
119 void get_inputs(formula_input_vector& inputs) const override;
120
121 int do_compare(const formula_callable* callable) const override;
122
123 const attack_type& get_attack_type() const { return *att_; }
124
125private:
127};
128
130{
131public:
132 unit_callable(const map_location& loc, const unit& u) : loc_(loc), u_(u)
133 {
134 type_ = UNIT_C;
135 }
136
137 explicit unit_callable(const unit &u);
138
139 variant get_value(const std::string& key) const override;
140 void get_inputs(formula_input_vector& inputs) const override;
141
142 int do_compare(const formula_callable* callable) const override;
143
144 const unit& get_unit() const { return u_; }
145 const map_location& get_location() const { return loc_; }
146
147private:
149 const unit& u_;
150};
151
153{
154public:
155 explicit unit_type_callable(const unit_type& u) : u_(u)
156 {
158 }
159
160 variant get_value(const std::string& key) const override;
161 void get_inputs(formula_input_vector& inputs) const override;
162
163 int do_compare(const formula_callable* callable) const override;
164
165 const unit_type& get_unit_type() const { return u_; }
166
167private:
168 const unit_type& u_;
169};
170
172{
173public:
174 explicit config_callable(const config& c) : cfg_(c) {}
175
176 variant get_value(const std::string& key) const override;
177 void get_inputs(formula_input_vector& inputs) const override;
178 int do_compare(const formula_callable* callable) const override;
179
180 const config& get_config() const { return cfg_; }
181
182private:
183 const config& cfg_;
184};
185
187{
188public:
189 explicit team_callable(const team& t) : team_(t) {}
190
191 void get_inputs(formula_input_vector& inputs) const override;
192 variant get_value(const std::string& key) const override;
193
194 const team& get_team() const { return team_; }
195
196private:
197 const team& team_;
198};
199
200
202{
203public:
205 : clr_(clr)
206 {}
207
208 void get_inputs(formula_input_vector& inputs) const override;
209 variant get_value(const std::string& key) const override;
210
211 const color_t get_color() const { return clr_; }
212
213private:
215};
216
217
218
220{
221public:
222 set_var_callable(const std::string& key, const variant& value)
223 : key_(key), value_(value)
224 {}
225
226 const std::string& key() const { return key_; }
227 variant value() const { return value_; }
228 variant execute_self(variant ctxt) override;
229
230private:
231 std::string key_;
233 variant get_value(const std::string& key) const override;
234
235 void get_inputs(formula_input_vector& inputs) const override;
236};
237
239{
240
241public:
243 : main_(main)
244 , backup_()
245 , backup_formula_(backup)
246 {}
247
248 const variant& get_main() const { return main_; }
249 const expression_ptr& get_backup() const { return backup_formula_; }
250
252 {
253 backup_ = v;
254 }
255
256 variant execute_self(variant ctxt) override;
257
258private:
262 variant get_value(const std::string& key) const override;
263
264 void get_inputs(formula_input_vector& inputs) const override;
265};
266
268{
269public:
271 : failed_callable_(callable)
273 , status_(status)
274 {}
275
276private:
279 const int status_;
280
281 variant get_value(const std::string& key) const override;
282
283 void get_inputs(formula_input_vector& inputs) const override;
284};
285
286} // namespace wfl
map_location loc
Definition move.cpp:172
double t
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
Abstract class for exposing game data that doesn't depend on the GUI, however which for historical re...
Encapsulates the map of the game.
Definition map.hpp:176
This class stores all the data for a single 'side' (in game nomenclature).
Definition team.hpp:74
A single unit type that the player may recruit.
Definition types.hpp:43
This class represents a single unit of a specific type.
Definition unit.hpp:39
int do_compare(const formula_callable *callable) const override
variant get_value(const std::string &key) const override
const attack_type & get_attack_type() const
void get_inputs(formula_input_vector &inputs) const override
variant get_value(const std::string &key) const override
const color_t get_color() const
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
int do_compare(const formula_callable *callable) const override
const config & get_config() const
config_callable(const config &c)
An object representing the state of the current event; equivalent to Lua's wesnoth....
void get_inputs(formula_input_vector &inputs) const override
variant get_value(const std::string &key) const override
std::shared_ptr< attack_type > second_weapon
const game_events::queued_event & event_info
std::shared_ptr< attack_type > first_weapon
event_callable(const game_events::queued_event &event)
formula_input_vector inputs() const
Definition callable.hpp:63
const display_context & board_
const gamemap & get_gamemap() const
void get_inputs(formula_input_vector &inputs) const override
gamemap_callable(const display_context &g)
variant get_value(const std::string &key) const override
An object representing the state of the game, providing access to the map and basic information.
variant get_value(const std::string &key) const override
void get_inputs(formula_input_vector &inputs) const override
location_callable(const map_location &loc)
const map_location & loc() const
void get_inputs(formula_input_vector &inputs) const override
std::string serialize_to_string() const override
Inherited from formula_callable.
int do_compare(const formula_callable *callable) const override
variant get_value(const std::string &key) const override
void set_backup_result(const variant &v)
variant execute_self(variant ctxt) override
const expression_ptr & get_backup() const
safe_call_callable(const variant &main, const expression_ptr &backup)
const variant & get_main() const
variant get_value(const std::string &key) const override
void get_inputs(formula_input_vector &inputs) const override
const map_location current_unit_location_
void get_inputs(formula_input_vector &inputs) const override
const_formula_callable_ptr failed_callable_
safe_call_result(const_formula_callable_ptr callable, int status, const map_location &loc=map_location())
variant get_value(const std::string &key) const override
void get_inputs(formula_input_vector &inputs) const override
variant get_value(const std::string &key) const override
const std::string & key() const
variant execute_self(variant ctxt) override
set_var_callable(const std::string &key, const variant &value)
team_callable(const team &t)
void get_inputs(formula_input_vector &inputs) const override
variant get_value(const std::string &key) const override
const team & get_team() const
variant get_value(const std::string &key) const override
const terrain_type & get_terrain_type() const
const terrain_type & t_
void get_inputs(formula_input_vector &inputs) const override
const map_location loc_
int do_compare(const formula_callable *callable) const override
const unit & get_unit() const
variant get_value(const std::string &key) const override
const map_location & loc_
const map_location & get_location() const
void get_inputs(formula_input_vector &inputs) const override
unit_callable(const map_location &loc, const unit &u)
int do_compare(const formula_callable *callable) const override
const unit_type & get_unit_type() const
variant get_value(const std::string &key) const override
unit_type_callable(const unit_type &u)
int do_compare(const formula_callable *callable) const override
void get_inputs(formula_input_vector &inputs) const override
Domain specific events.
std::vector< formula_input > formula_input_vector
std::shared_ptr< formula_expression > expression_ptr
Definition formula.hpp:29
std::shared_ptr< const formula_callable > const_formula_callable_ptr
std::shared_ptr< const attack_type > const_attack_ptr
Definition ptr.hpp:34
int main(int, char **)
Definition sdl3.cpp:25
The basic class for representing 8-bit RGB or RGBA colour values.
Definition color.hpp:51
Encapsulates the map of the game.
Definition location.hpp:46
#define g
#define c