39 #define WRN_NG LOG_STREAM(warn, log_engine)
42 #define ERR_WML LOG_STREAM(err, log_wml)
48 namespace builtin_conditions {
56 std::vector<std::pair<int,int>> counts = cfg.
has_attribute(
"count")
61 if(
i.hitpoints() > 0 && ufilt(
i)) {
69 if(cfg[
"search_recall_list"].to_bool()) {
90 std::set<map_location> res;
93 std::vector<std::pair<int,int>> counts = cfg.
has_attribute(
"count")
95 return in_ranges<int>(res.size(), counts);
100 if(values[
"name"].
blank()) {
102 ERR_WML <<
"[variable] with missing name=";
105 const std::string name = values[
"name"];
109 lg::log_to_chat() <<
"[variable] name='" << name <<
"' found with multiple comparison attributes\n";
110 ERR_WML <<
"[variable] name='" << name <<
"' found with multiple comparison attributes";
112 lg::log_to_chat() <<
"[variable] name='" << name <<
"' found with no comparison attribute\n";
113 ERR_WML <<
"[variable] name='" << name <<
"' found with no comparison attribute";
116 #define TEST_STR_ATTR(name, test) \
118 if (values.has_attribute(name)) { \
119 std::string attr_str = values[name].str(); \
120 std::string str_value = value.str(); \
125 #define TEST_NUM_ATTR(name, test) \
127 if (values.has_attribute(name)) { \
128 double attr_num = values[name].to_double(); \
129 double num_value = value.to_double(); \
134 #define TEST_BOL_ATTR(name, test) \
136 if (values.has_attribute(name)) { \
137 bool attr_bool = values[name].to_bool(); \
138 bool bool_value = value.to_bool(); \
146 TEST_NUM_ATTR(
"numerical_not_equals", num_value != attr_num);
149 TEST_NUM_ATTR(
"greater_than_equal_to", num_value >= attr_num);
152 TEST_BOL_ATTR(
"boolean_not_equals", bool_value != attr_bool);
153 TEST_STR_ATTR(
"contains", str_value.find(attr_str) != std::string::npos);
164 bool internal_conditional_passed(
const vconfig& cond)
173 static const std::set<std::string> skip
174 {
"then",
"else",
"elseif",
"not",
"and",
"or",
"do"};
176 for(
const auto& [key, filter] : cond.
all_ordered()) {
177 if(std::find(skip.begin(), skip.end(), key) == skip.end()) {
193 bool matches = internal_conditional_passed(cond);
196 for(
const auto& [key, filter] : cond.
all_ordered()) {
202 else if(key ==
"or") {
206 else if(key ==
"not") {
Variant for storing WML attributes.
std::size_t attribute_count() const
Count the number of non-blank attributes.
virtual config::attribute_value get_variable_const(const std::string &varname) const
returns a blank attribute value if varname is no valid variable name.
This class stores all the data for a single 'side' (in game nomenclature).
std::string save_id_or_number() const
recall_list_manager & recall_list()
This class represents a single unit of a specific type.
A variable-expanding proxy for the config class.
bool has_attribute(const std::string &key) const
< Synonym for operator[]
const config & get_config() const
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
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
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...
static map_location::direction n