38 #define WRN_NG LOG_STREAM(warn, log_engine) 44 namespace builtin_conditions {
52 std::vector<std::pair<int,int>> counts = cfg.
has_attribute(
"count")
57 if(
i.hitpoints() > 0 && ufilt(
i)) {
59 if(counts == default_counts) {
65 if(cfg[
"search_recall_list"].to_bool()) {
67 if(counts == default_counts && match_count) {
71 if(counts == default_counts && match_count) {
86 std::set<map_location> res;
89 std::vector<std::pair<int,int>> counts = cfg.
has_attribute(
"count")
91 return in_ranges<int>(res.size(), counts);
96 const std::string
name = values[
"name"];
99 #define TEST_STR_ATTR(name, test) \ 101 if (values.has_attribute(name)) { \ 102 std::string attr_str = values[name].str(); \ 103 std::string str_value = value.str(); \ 104 if (!(test)) return false; \ 108 #define TEST_NUM_ATTR(name, test) \ 110 if (values.has_attribute(name)) { \ 111 double attr_num = values[name].to_double(); \ 112 double num_value = value.to_double(); \ 113 if (!(test)) return false; \ 117 #define TEST_BOL_ATTR(name, test) \ 119 if (values.has_attribute(name)) { \ 120 bool attr_bool = values[name].to_bool(); \ 121 bool bool_value = value.to_bool(); \ 122 if (!(test)) return false; \ 129 TEST_NUM_ATTR(
"numerical_not_equals", num_value != attr_num);
132 TEST_NUM_ATTR(
"greater_than_equal_to", num_value >= attr_num);
135 TEST_BOL_ATTR(
"boolean_not_equals", bool_value != attr_bool);
136 TEST_STR_ATTR(
"contains", str_value.find(attr_str) != std::string::npos);
146 bool internal_conditional_passed(
const vconfig&
cond)
155 static const std::set<std::string> skip
156 {
"then",
"else",
"elseif",
"not",
"and",
"or",
"do"};
158 for(
const auto& [key, filter] : cond.
all_ordered()) {
159 if(std::find(skip.begin(), skip.end(), key) == skip.end()) {
175 bool matches = internal_conditional_passed(cond);
178 for(
const auto& [key, filter] : cond.
all_ordered()) {
184 else if(key ==
"or") {
188 else if(key ==
"not") {
199 WRN_NG <<
"attempt to filter attack for an event with no attack data." << std::endl;
205 auto attack = std::make_shared<const attack_type>(cfg);
#define TEST_STR_ATTR(name, test)
This class represents a single unit of a specific type.
Variant for storing WML attributes.
bool have_location(const vconfig &cfg)
bool has_attribute(const std::string &key) const
< Synonym for operator[]
bool in_ranges(const Cmp c, const std::vector< std::pair< Cmp, Cmp >> &ranges)
std::string save_id_or_number() const
#define TEST_BOL_ATTR(name, test)
Definitions for the interface to Wesnoth Markup Language (WML).
bool have_unit(const vconfig &cfg)
This class stores all the data for a single 'side' (in game nomenclature).
std::vector< std::pair< int, int > > parse_ranges(const std::string &str)
std::vector< std::pair< int, int > > default_counts
filter_context * filter_con
config get_parsed_config() const
bool variable_matches(const vconfig &values)
static lg::log_domain log_engine("engine")
Define conditionals for the game's events mechanism, a.k.a.
bool matches_special_filter(const config &cfg, const vconfig &filter)
bool has_child(const std::string &key) const
Returns whether or not *this has a child whose key is key.
std::size_t size() const
Get the number of units on the list.
bool conditional_passed(const vconfig &cond)
virtual config::attribute_value get_variable_const(const std::string &varname) const
returns a blank attribute value if varname is no valid variable name.
static int cond(LexState *ls)
A variable-expanding proxy for the config class.
Standard logging facilities (interface).
recall_list_manager & recall_list()
game_lua_kernel * lua_kernel
A config object defines a single node in a WML file, with access to child nodes.
#define TEST_NUM_ATTR(name, test)
boost::iterator_range< all_children_iterator > all_ordered() const