40 #define WRN_NG LOG_STREAM(warn, log_engine)
43 #define ERR_WML LOG_STREAM(err, log_wml)
49 namespace builtin_conditions {
57 std::vector<std::pair<int,int>> counts = cfg.
has_attribute(
"count")
62 if(
i.hitpoints() > 0 && ufilt(
i)) {
70 if(cfg[
"search_recall_list"].to_bool()) {
91 std::set<map_location> res;
94 std::vector<std::pair<int,int>> counts = cfg.
has_attribute(
"count")
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"];
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()) {
178 if(std::find(skip.begin(), skip.end(), key) == skip.end()) {
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.
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.
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