40#define WRN_NG LOG_STREAM(warn, log_engine)
43#define ERR_WML LOG_STREAM(err, log_wml)
49namespace builtin_conditions {
62 if(
i.hitpoints() > 0 && ufilt(
i)) {
70 if(
cfg[
"search_recall_list"].to_bool()) {
91 std::set<map_location> res;
96 return in_ranges<int>(res.size(), counts);
101 if(values[
"name"].blank()) {
103 ERR_WML <<
"[variable] with missing name=";
106 const std::string name = values[
"name"];
109 if(
auto n = values.get_config().attribute_count();
n > 2) {
110 lg::log_to_chat() <<
"[variable] name='" << name <<
"' found with multiple comparison attributes\n";
111 ERR_WML <<
"[variable] name='" << name <<
"' found with multiple comparison attributes";
113 lg::log_to_chat() <<
"[variable] name='" << name <<
"' found with no comparison attribute\n";
114 ERR_WML <<
"[variable] name='" << name <<
"' found with no comparison attribute";
117#define TEST_STR_ATTR(name, test) \
119 if (values.has_attribute(name)) { \
120 std::string attr_str = values[name].str(); \
121 std::string str_value = value.str(); \
126#define TEST_NUM_ATTR(name, test) \
128 if (values.has_attribute(name)) { \
129 double attr_num = values[name].to_double(); \
130 double num_value = value.to_double(); \
135#define TEST_BOL_ATTR(name, test) \
137 if (values.has_attribute(name)) { \
138 bool attr_bool = values[name].to_bool(); \
139 bool bool_value = value.to_bool(); \
147 TEST_NUM_ATTR(
"numerical_not_equals", num_value != attr_num);
150 TEST_NUM_ATTR(
"greater_than_equal_to", num_value >= attr_num);
153 TEST_BOL_ATTR(
"boolean_not_equals", bool_value != attr_bool);
154 TEST_STR_ATTR(
"contains", str_value.find(attr_str) != std::string::npos);
165 bool internal_conditional_passed(
const vconfig& cond)
174 static const std::set<std::string> skip
175 {
"then",
"else",
"elseif",
"not",
"and",
"or",
"do"};
177 for(
const auto& [key, filter] : cond.all_ordered()) {
194 bool matches = internal_conditional_passed(cond);
197 for(
const auto& [key, filter] : cond.
all_ordered()) {
203 else if(key ==
"or") {
207 else if(key ==
"not") {
Variant for storing WML attributes.
bool has_attribute(std::string_view key) const
virtual const std::vector< team > & teams() const override
virtual const unit_map & units() const override
virtual config::attribute_value get_variable_const(const std::string &varname) const
returns a blank attribute value if varname is no valid variable name.
std::size_t size() const
Get the number of units on the list.
This class stores all the data for a single 'side' (in game nomenclature).
recall_list_manager & recall_list()
std::string save_id_or_number() const
This class represents a single unit of a specific type.
A variable-expanding proxy for the config class.
boost::iterator_range< all_children_iterator > all_ordered() const
bool has_child(const std::string &key) const
Returns whether or not *this has a child whose key is key.
static lg::log_domain log_engine("engine")
#define TEST_BOL_ATTR(name, test)
#define TEST_NUM_ATTR(name, test)
#define TEST_STR_ATTR(name, test)
static lg::log_domain log_wml("wml")
Define conditionals for the game's events mechanism, a.k.a.
Definitions for the interface to Wesnoth Markup Language (WML).
Standard logging facilities (interface).
bool in_ranges(const Cmp c, const std::vector< std::pair< Cmp, Cmp > > &ranges)
std::vector< std::pair< int, int > > default_counts
bool variable_matches(const vconfig &values)
bool have_location(const vconfig &cfg)
bool have_unit(const vconfig &cfg)
bool conditional_passed(const vconfig &cond)
std::stringstream & log_to_chat()
Use this to show WML errors in the ingame chat.
game_lua_kernel * lua_kernel
filter_context * filter_con
bool contains(const Container &container, const Value &value)
Returns true iff value is found in container.
std::vector< std::pair< int, int > > parse_ranges_unsigned(const std::string &str)
Handles a comma-separated list of inputs to parse_range, in a context that does not expect negative v...
std::unique_ptr< MIX_Audio, decltype(&MIX_DestroyAudio)> value
static map_location::direction n