38 #include "formula/callable_objects.hpp"
41 #include <boost/optional.hpp>
42 #include <boost/make_shared.hpp>
43 #include <boost/shared_ptr.hpp>
48 #define ERR_CF LOG_STREAM(err, log_config)
49 #define DBG_CF LOG_STREAM(debug, log_config)
53 return impl_->to_config();
62 return impl_->matches(u,loc,&u2);
86 std::vector<const unit *> ret;
90 if(max_matches == 0) {
139 while(cond != cond_end)
143 if(type.parse(cond_name)) {
150 static const int NUM_VALID_TAGS = 5;
151 static const std::string valid_tags[NUM_VALID_TAGS] = {
158 static const std::string*
const valid_tags_end = valid_tags + NUM_VALID_TAGS;
160 if (
std::find(valid_tags, valid_tags_end, cond_name) == valid_tags_end){
161 std::stringstream errmsg;
162 errmsg <<
"encountered a child [" << cond_name <<
"] of a standard unit filter, it is being ignored";
163 DBG_CF << errmsg.str() << std::endl;
198 return boost::make_shared<null_unit_filter_impl> (fc);
201 return boost::make_shared<null_unit_filter_impl> (fc);
203 return boost::make_shared<basic_unit_filter_impl>(vcfg, fc, flat_tod);
211 : max_matches_(static_cast<unsigned>(-1))
217 assert(
false &&
"attempt to instantiate a unit filter with a null filter context!");
246 case conditional::TYPE::AND:
249 case conditional::TYPE::OR:
261 if (!
vcfg[
"name"].blank() &&
vcfg[
"name"].t_str() != u.
name()) {
267 if (
std::find(id_list.begin(), id_list.end(), u.
id()) == id_list.end()) {
273 if (!
vcfg[
"speaker"].blank() &&
vcfg[
"speaker"].str() != u.
id()) {
279 FAIL(
"Encountered multiple [filter_location] children of a standard unit filter. "
280 "This is not currently supported and in all versions of wesnoth would have "
281 "resulted in the later children being ignored. You must use [and] or similar "
282 "to achieve the desired result.");
285 if (!filt.match(loc)) {
292 FAIL(
"Encountered multiple [filter_side] children of a standard unit filter. "
293 "This is not currently supported and in all versions of wesnoth would have "
294 "resulted in the later children being ignored. You must use [and] or similar "
295 "to achieve the desired result.");
298 if(!filt.match(u.
side()))
303 if (!
vcfg[
"x"].blank() || !
vcfg[
"y"].blank()){
304 if(
vcfg[
"x"] ==
"recall" &&
vcfg[
"y"] ==
"recall") {
348 if (!match)
return false;
361 if (!match)
return false;
366 if (
std::find(races.begin(), races.end(), u.
race()->
id()) == races.end()) {
378 if (
std::find(sides.begin(), sides.end(), u_side) == sides.end()) {
385 bool status_found =
false;
386 std::map<std::string, std::string> states_map = u.
get_states();
389 if (states_map[status] ==
"yes") {
402 bool has_weapon =
false;
403 const std::vector<attack_type>& attacks = u.
attacks();
404 for(std::vector<attack_type>::const_iterator
i = attacks.begin();
405 i != attacks.end(); ++
i) {
414 }
else if (!
vcfg[
"has_weapon"].blank()) {
416 bool has_weapon =
false;
417 const std::vector<attack_type>& attacks = u.
attacks();
418 for(std::vector<attack_type>::const_iterator
i = attacks.begin();
419 i != attacks.end(); ++
i) {
446 if (!
vcfg[
"level"].blank() &&
vcfg[
"level"].to_int(-1) != u.
level()) {
464 config fwml = wmlcfg.get_parsed_config();
469 if (std::distance(ai.first, ai.second) == 0 &&
470 std::distance(ci.first, ci.second) == 1 &&
471 ci.first->key ==
"variables") {
475 if (unit_cfg.
empty())
483 std::set<int> viewers;
487 std::vector<int> sides = ssf.
get_teams();
488 viewers.insert(sides.begin(), sides.end());
491 for (
const int viewer : viewers) {
494 bool unit_hidden = fogged || hiding;
495 if (vision[
"visible"].to_bool(
true) != unit_hidden) {
500 if (!found) {
return false;}
513 std::vector<map_location::DIRECTION> dirs;
514 if (i_adjacent.
blank()) {
520 std::vector<map_location::DIRECTION>::const_iterator j, j_end = dirs.end();
521 for (j = dirs.begin(); j != j_end; ++j) {
523 if (unit_itor == units.
end() || !filt(*unit_itor, u)) {
526 boost::optional<bool> is_enemy;
527 if (!adj_cfg[
"is_enemy"].blank()) {
528 is_enemy = adj_cfg[
"is_enemy"].to_bool();
530 if (!is_enemy || *is_enemy ==
544 if (!
vcfg[
"find_in"].blank()) {
550 bool found_id =
false;
553 if(
c[
"id"] == u.
id())
567 if (!
vcfg[
"formula"].blank()) {
573 callable.
add(
"other",
variant(secondary.get()));
588 if (!
vcfg[
"lua_function"].blank()) {
590 bool b = lk->run_filter(
vcfg[
"lua_function"].str().c_str(), u);
591 if (!b)
return false;
599 std::vector<const unit *> ret;
601 if (
matches(u, u.get_location(),
nullptr)) {
602 if(max_matches == 0) {
615 if (
matches(*u,u->get_location(),
nullptr)) {
616 return u.get_shared_ptr();
basic_unit_filter_impl(const vconfig &vcfg, const filter_context &fc, bool flat_tod)
std::vector< int > get_teams() const
static lg::log_domain log_config("config")
TYPE
UNSCALED : image will be drawn "as is" without changing size, even in case of redraw SCALED_TO_ZOOM :...
boost::intrusive_ptr< const unit > unit_const_ptr
const std::string & id() const
size_t count_children(const std::string &key) const
const map_location & get_location() const
bool matches(const config &filter) const
virtual const display_context & get_disp_context() const =0
bool matches_range(const std::string &xloc, const std::string &yloc) const
bool has_variation(const std::string &variation_id) const
std::pair< const_attribute_iterator, const_attribute_iterator > const_attr_itors
bool get_state(const std::string &state) const
This enum helps to evaluate conditional filters.
variable_info_detail::maybe_const< vit, config::child_itors >::type as_array() const
might throw invalid_variablename_exception
const t_string & name() const
The unit name for display.
unsigned attribute_count() const
Note: this function also counts the 'blank' attributes, so it might return more than one might expect...
int movement_cost(const t_translation::t_terrain &terrain) const
vconfig get_child() const
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
vconfig child(const std::string &key) const
Returns a child of *this whose key is key.
virtual std::vector< const unit * > all_matches_on_map(unsigned max_matches) const
config get_parsed_config() const
GLuint GLuint GLsizei GLenum type
#define MAKE_ENUM(NAME, CONTENT)
const filter_context & fc_
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
all_children_iterator ordered_end() const
virtual bool matches(const unit &, const map_location &, const unit *) const
virtual unit_const_ptr first_match_on_map() const
const std::string & id() const
unit_type_data unit_types
boost::shared_ptr< unit_filter_abstract_impl > impl_
void write(config &cfg) const
static std::vector< DIRECTION > parse_directions(const std::string &str)
Parse_directions takes a comma-separated list, and filters out any invalid directions.
bool internal_matches_filter(const unit &u, const map_location &loc, const unit *u2) const
Definitions for the interface to Wesnoth Markup Language (WML).
virtual const gamemap & map() const =0
GLsizei GLenum GLenum * types
Variant for storing WML attributes.
int defense_modifier(const t_translation::t_terrain &terrain) const
bool blank() const
Tests for an attribute that was never set.
const unit_type & type() const
The type of the unit (accounting for gender and variation).
GLdouble GLdouble GLdouble b
const std::string & type_id() const
The id of the type of the unit.
A small explanation about what's going on here: Each action has access to two game_info objects First...
The basic unit filter gives a generic implementation of the match fcn.
const filter_context & fc_
pointer get_shared_ptr() const
child_list get_children(const std::string &key) const
bool matches(const unit &u, const map_location &loc) const
Determine if *this matches filter at a specified location.
all_children_itors all_children_range() const
In-order iteration over all children.
virtual ~basic_unit_filter_impl()
bool has_child(const std::string &key) const
Returns whether or not *this has a child whose key is key.
unit_race::GENDER string_gender(const std::string &str, unit_race::GENDER def)
std::pair< all_children_iterator, all_children_iterator > all_children_itors
static const std::vector< DIRECTION > & default_dirs()
Default list of directions.
unit_race::GENDER gender() const
virtual const unit_map & units() const =0
const std::vector< attack_type > & attacks() const
bool invisible(const map_location &loc, bool see_all=true) const
Encapsulates the map of the game.
virtual std::vector< const unit * > all_matches_on_map(unsigned max_matches) const
virtual bool empty() const
virtual const std::vector< team > & teams() const =0
std::stringstream & wml_error()
Use this logger to send errors due to deprecated WML.
std::vector< unit_filter > cond_children_
std::vector< std::pair< int, int > > parse_ranges(std::string const &str)
null_unit_filter_impl(const filter_context &fc)
const std::map< std::string, std::string > get_states() const
const config & get_config() const
virtual unit_const_ptr first_match_on_map() const
const_attr_itors attribute_range() const
static boost::shared_ptr< unit_filter_abstract_impl > construct(const vconfig &vcfg, const filter_context &fc, bool flat_tod)
Forward declare the "construct" method which constructs an appropriate filter impl.
Information on a WML variable.
const std::string & variation() const
int main(int argc, char **argv)
unit_filter(const vconfig &cfg, const filter_context *fc, bool use_flat_tod=false)
Constructs a unit filter from a config and a context. This function should give the most efficient im...
t_translation::t_terrain get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
virtual bool matches(const unit &u, const map_location &loc, const unit *u2) const
Begin implementations of filter impl's.
bool on_board(const map_location &loc) const
Tell if a location is on the map.
const std::string & base_id() const
The id of the original type from which this (variation) descended.
bool find(E event, F functor)
Tests whether an event handler is available.
Null unit filter is built when the input config is null.
virtual const game_data * get_game_data() const =0
static int cond(LexState *ls)
unsigned all_children_count() const
A variable-expanding proxy for the config class.
Standard logging facilities (interface).
virtual game_lua_kernel * get_lua_kernel() const =0
static const char * match(MatchState *ms, const char *s, const char *p)
Container associating units to locations.
virtual ~null_unit_filter_impl()
const unit_type * find(const std::string &key, unit_type::BUILD_STATUS status=unit_type::FULL) const
Finds a unit_type by its id() and makes sure it is built to the specified level.
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
unit_iterator find(size_t id)
std::vector< conditional::TYPE > cond_child_types_
const std::string & get_role() const
GLuint GLdouble GLdouble u2
bool has_ability_by_id(const std::string &ability) const
A config object defines a single node in a WML file, with access to child nodes.
void make_safe() const
instruct the vconfig to make a private copy of its underlying data.
const unit_race * race() const
Never returns nullptr, but may point to the null race.
Defines the MAKE_ENUM macro.
GLsizei const GLcharARB ** string
std::string get_key() const
bool has_attribute(const std::string &key) const
< Synonym for operator[]
all_children_iterator ordered_begin() const
In-order iteration over all children.
bool in_ranges(const Cmp c, const std::vector< std::pair< Cmp, Cmp > > &ranges)