16 #define GETTEXT_DOMAIN "wesnoth-lib"
36 #include "formula/callable_objects.hpp"
41 #define ERR_NG LOG_STREAM(err, log_engine_sf)
44 #define ERR_WML LOG_STREAM(err, log_wml)
57 : cfg_(
vconfig::empty_vconfig()), flat_(flat_tod), side_string_(side_string), fc_(fc)
65 std::vector<int> result;
68 result.push_back(
t.side());
79 std::vector<std::pair<int,int>>::const_iterator range, range_end = ranges.end();
80 for (range = ranges.begin(); range != range_end; ++range) {
81 if(
side_number >= range->first && side_number <= range->second) {
109 if (!cfg_team_name.
blank()) {
110 const std::string& that_team_name = cfg_team_name;
111 const std::string& this_team_name =
t.team_name();
113 if(std::find(this_team_name.begin(), this_team_name.end(),
',') == this_team_name.end()) {
114 if(this_team_name != that_team_name)
return false;
117 const std::vector<std::string>& these_team_names =
utils::split(this_team_name);
118 bool search_futile =
true;
119 for(
const std::string& this_single_team_name : these_team_names) {
120 if(this_single_team_name == that_team_name) {
121 search_futile =
false;
125 if(search_futile)
return false;
138 if (u.side() !=
t.side()) {
146 if(!found && ufilt_cfg[
"search_recall_list"].to_bool(
false)) {
148 scoped_recall_unit this_unit(
"this_unit",
t.save_id_or_number(),
t.recall_list().find_index(u->id()));
161 if(!enemy_of.
null()) {
165 if(teams.empty())
return false;
166 for(
const int side : teams) {
173 if(!allied_with.
null()) {
177 if(teams.empty())
return false;
178 for(
const int side : teams) {
185 if(!has_enemy.
null()) {
190 for(
const int side : teams) {
197 if (!found)
return false;
201 if(!has_ally.
null()) {
206 for(
const int side : teams) {
213 if (!found)
return false;
218 if (!cfg_controller.
blank())
221 ERR_NG <<
"ignoring controller= in SSF due to danger of OOS errors";
246 lg::log_to_chat() <<
"Formula error in side filter: " <<
e.type <<
" at " <<
e.filename <<
':' <<
e.line <<
")\n";
247 ERR_WML <<
"Formula error in side filter: " <<
e.type <<
" at " <<
e.filename <<
':' <<
e.line <<
")";
283 else if(key ==
"or") {
287 else if(key ==
"not") {
Variant for storing WML attributes.
bool blank() const
Tests for an attribute that was never set.
const team & get_team(int side) const
This getter takes a 1-based side number, not a 0-based team number.
virtual const std::vector< team > & teams() const =0
virtual const unit_map & units() const =0
virtual const display_context & get_disp_context() const =0
virtual game_lua_kernel * get_lua_kernel() const =0
bool run_filter(char const *name, const unit &u)
Runs a script from a unit filter.
std::unique_ptr< side_filter > has_ally_filter_
std::vector< int > get_teams() const
const filter_context * fc_
The filter context for this filter.
bool match(const team &t) const
bool match_internal(const team &t) const
std::unique_ptr< side_filter > allied_filter_
std::unique_ptr< side_filter > has_enemy_filter_
std::unique_ptr< side_filter > enemy_filter_
side_filter(const std::string &side_string, const filter_context *fc, bool flat_tod=false)
std::unique_ptr< unit_filter > ufilter_
This class stores all the data for a single 'side' (in game nomenclature).
bool is_enemy(int n) const
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[]
vconfig child(const std::string &key) const
Returns a child of *this whose key is key.
const vconfig & make_safe() const
instruct the vconfig to make a private copy of its underlying data.
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.
bool as_bool() const
Returns a boolean state of the variant value.
Standard logging facilities (interface).
std::stringstream & log_to_chat()
Use this to show WML errors in the ingame chat.
std::function< int(lua_State *)> lua_function
play_controller * controller
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::vector< std::string > split(const config_attribute_value &val)
std::shared_ptr< const unit > unit_const_ptr
static lg::log_domain log_engine_sf("engine/side_filter")
static bool check_side_number(const team &t, const std::string &str)
static lg::log_domain log_wml("wml")
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.