15 #define GETTEXT_DOMAIN "wesnoth-lib"
33 #include "formula/callable_objects.hpp"
37 #include <boost/range/adaptor/transformed.hpp>
40 #define ERR_NG LOG_STREAM(err, log_engine)
41 #define WRN_NG LOG_STREAM(warn, log_engine)
51 #pragma warning(disable:4413)
53 cfg_(
vconfig::unconstructed_vconfig()),
66 const bool flat_tod,
const size_t max_loop) :
79 max_loop_(original.max_loop_),
90 max_loop_(other.max_loop_),
106 parsed_terrain(nullptr),
107 adjacent_matches(nullptr),
108 adjacent_match_cache(),
114 bool operator() (std::pair<const std::string,const vconfig>
val) {
115 return val.first ==
"or";
165 if (!found)
return false;
193 vconfig::child_list::const_iterator
i, i_end = vis_filt.end();
194 for (i = vis_filt.begin(); i != i_end; ++
i) {
195 bool visible = (*i)[
"visible"].to_bool(
true);
196 bool respect_fog = (*i)[
"respect_fog"].to_bool(
true);
199 std::vector<int> sides = ssf.
get_teams();
202 for (
const int side : sides) {
204 bool viewer_sees = respect_fog ? !viewing_team.
fogged(loc) : !viewing_team.
shrouded(loc);
205 if (visible == viewer_sees) {
210 if (!found) {
return false;}
219 vconfig::child_list::const_iterator
i, i_end, i_begin = adj_cfgs.begin();
220 for (i = i_begin, i_end = adj_cfgs.end(); i != i_end; ++
i) {
222 vconfig::child_list::difference_type
index = i - i_begin;
223 std::vector<map_location::DIRECTION> dirs = (*i).has_attribute(
"adjacent")
225 std::vector<map_location::DIRECTION>::const_iterator j, j_end = dirs.end();
226 for (j = dirs.begin(); j != j_end; ++j) {
232 std::pair<terrain_filter, std::map<map_location,bool> > amc_pair(
234 std::map<map_location,bool>());
240 if(lookup == amc.end()) {
241 if(amc_filter(adj)) {
247 }
else if(lookup->second) {
253 if(amc.find(adj) != amc.end()) {
260 std::vector<std::pair<int,int> > counts = (*i).has_attribute(
"count")
272 if(!tod_type.empty() || !tod_id.empty()) {
282 if(!tod_type.empty()) {
283 const std::vector<std::string>& vals =
utils::split(tod_type);
285 if(
std::find(vals.begin(),vals.end(),unit_type::ALIGNMENT::enum_to_string(unit_type::ALIGNMENT::CHAOTIC)) == vals.end()) {
289 if(
std::find(vals.begin(),vals.end(),unit_type::ALIGNMENT::enum_to_string(unit_type::ALIGNMENT::LAWFUL)) == vals.end()) {
292 }
else if(
std::find(vals.begin(),vals.end(),unit_type::ALIGNMENT::enum_to_string(unit_type::ALIGNMENT::NEUTRAL)) == vals.end()) {
297 if(!tod_id.empty()) {
298 if(tod_id != tod.
id) {
299 if(
std::find(tod_id.begin(),tod_id.end(),
',') != tod_id.end() &&
300 std::search(tod_id.begin(),tod_id.end(),
301 tod.
id.begin(),tod.
id.end()) != tod_id.end()) {
302 const std::vector<std::string>& vals =
utils::split(tod_id);
303 if(
std::find(vals.begin(),vals.end(),tod.
id) == vals.end()) {
316 if(!filter_owner.
null()) {
317 if(!owner_side.
empty()) {
318 WRN_NG <<
"duplicate side information in a SLF, ignoring inline owner_side=" << std::endl;
323 const std::vector<int>& sides = ssf.
get_teams();
327 for(
const int side : sides) {
336 else if(!owner_side.
empty()) {
337 const int side_index = owner_side.
to_int(0) - 1;
366 if(
cfg_[
"x"] ==
"recall" &&
cfg_[
"y"] ==
"recall") {
369 std::set<map_location> hexes;
370 std::vector<map_location> loc_vec(1, loc);
373 size_t radius =
cfg_[
"radius"].to_size_t(0);
376 <<
", restricting\n";
380 hexes.insert(loc_vec.begin(), loc_vec.end());
388 size_t loop_count = 0;
389 std::set<map_location>::const_iterator
i;
390 for(i = hexes.begin(); i != hexes.end(); ++
i) {
396 while(cond != cond_end)
402 if(cond_name ==
"and")
407 else if(cond_name ==
"or")
412 else if(cond_name ==
"not")
422 std::set<map_location>::const_iterator temp =
i;
423 if(++temp != hexes.end()) {
443 template<
typename T,
typename F1,
typename F2,
typename F3>
447 if (f1(loc) && f2(loc) && f3(loc)) {
453 template<
typename T,
typename F1,
typename F2>
458 filter_final(
src, dest, filter, f1, f2, [loc2](
const map_location& loc) {
return loc == loc2; });
465 template<
typename T,
typename F1>
470 filter_special_loc(
src, dest, filter, f1, [&area](
const map_location& loc) {
return area.find(loc) != area.end(); });
482 filter_area(
src, dest, filter, [&xy_vector](
const map_location& loc) {
return std::find(xy_vector.begin(), xy_vector.end(), loc) != xy_vector.end(); });
497 std::set<map_location> match_set;
500 with_border =
cfg_[
"include_borders"].to_bool(with_border);
507 auto ar = gd->get_variable_access_read(
cfg_[
"find_in"]).as_array();
527 match_set.insert(loc2);
535 for (
int x = with_border ? 0 - bs : 0;
x <
w; ++
x) {
536 for (
int y = with_border ? 0 - bs : 0;
y <
h; ++
y) {
548 for (
unsigned i = 0;
i < adj_cfgs.size(); ++
i) {
549 std::set<map_location> adj_set;
561 while(loc_itor != match_set.end()) {
565 match_set.erase(loc_itor++);
572 int ors_left = std::count_if(cond, cond_end, cfg_isor());
573 while(cond != cond_end)
576 if(match_set.empty() && ors_left <= 0) {
584 if(cond_name ==
"and") {
585 std::set<map_location> intersect_hexes;
586 terrain_filter(cond_cfg, *
this).get_locations(intersect_hexes, with_border);
588 while(intersect_itor != match_set.end()) {
589 if(intersect_hexes.find(*intersect_itor) == intersect_hexes.end()) {
590 match_set.erase(*intersect_itor++);
597 else if(cond_name ==
"or") {
598 std::set<map_location> union_hexes;
599 terrain_filter(cond_cfg, *
this).get_locations(union_hexes, with_border);
602 while(insert_itor != union_hexes.end()) {
603 match_set.insert(*insert_itor++);
608 else if(cond_name ==
"not") {
609 std::set<map_location> removal_hexes;
610 terrain_filter(cond_cfg, *
this).get_locations(removal_hexes, with_border);
612 while(erase_itor != removal_hexes.end()) {
613 match_set.erase(*erase_itor++);
618 if(match_set.empty()) {
623 size_t radius =
cfg_[
"radius"].to_size_t(0);
626 <<
", restricting\n";
630 std::vector<map_location> xy_vector (match_set.begin(), match_set.end());
638 locs.insert(match_set.begin(), match_set.end());
648 delete parsed_terrain;
649 delete adjacent_matches;
std::vector< int > get_teams() const
std::function< int(lua_State *)> lua_function
virtual const display_context & get_disp_context() const =0
bool matches_range(const std::string &xloc, const std::string &yloc) const
variable_info_detail::maybe_const< vit, config::child_itors >::type as_array() const
might throw invalid_variablename_exception
bool shrouded(const map_location &loc) const
map_location operator()(const config &cfg) const
vconfig get_child() const
vconfig child(const std::string &key) const
Returns a child of *this whose key is key.
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
const time_of_day & get_time_of_day(int for_turn=0) const
Returns global time of day for the passed turn.
static void filter_final(T &&src, location_set &dest, const terrain_filter &, const F1 &f1, const F2 &f2, const F3 &f3)
all_children_iterator ordered_end() const
bool is_village(const map_location &loc) const
virtual bool operator()(const map_location &loc) const
int lawful_bonus
The % bonus lawful units receive.
GLuint const GLfloat * val
int village_owner(const map_location &loc) const
Given the location of a village, will return the 0-based index of the team that currently owns it...
static void filter_special_loc(T &&src, location_set &dest, const terrain_filter &filter, const F1 &f1, const F2 &f2)
std::vector< std::set< map_location > > * adjacent_matches
terrain_filter_cache cache_
GLint GLint GLint GLint GLint GLint y
static std::vector< DIRECTION > parse_directions(const std::string &str)
Parse_directions takes a comma-separated list, and filters out any invalid directions.
bool empty() const
Tests for an attribute that either was never set or was set to "".
Definitions for the interface to Wesnoth Markup Language (WML).
virtual const gamemap & map() const =0
Variant for storing WML attributes.
bool match(const map_location &loc) const
const tdata_cache & tdata() const
const filter_context * fc_
t_translation::t_match * parsed_terrain
Object which defines a time of day with associated bonuses, image, sounds etc.
This class stores all the data for a single 'side' (in game nomenclature).
child_list get_children(const std::string &key) const
This structure can be used for matching terrain strings.
GLubyte GLubyte GLubyte GLubyte w
int w() const
Effective map width.
t_translation::t_terrain number() const
bool has_child(const std::string &key) const
Returns whether or not *this has a child whose key is key.
const size_t max_loop
The maximum number of hexes on a map and items in an array and also used as maximum in wml loops...
Encapsulates the map of the game.
static const std::vector< DIRECTION > & default_dirs()
Default list of directions.
int border_size() const
Size of the map border.
bool operator()(const map_location &) const
virtual const unit_map & units() const =0
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
~terrain_filter()
Default implementation, but defined out-of-line for efficiency reasons.
Encapsulates the map of the game.
const terrain_type & get_terrain_info(const t_translation::t_terrain &terrain) const
std::vector< map_location > parse_location_range(const std::string &xvals, const std::string &yvals, bool with_border=false) const
Parses ranges of locations into a vector of locations, using this map's dimensions as bounds...
map_location special_location(const std::string &id) const
void get_locations(std::set< map_location > &locs, bool with_border=false) const
virtual const std::vector< team > & teams() const =0
std::stringstream & wml_error()
Use this logger to send errors due to deprecated WML.
int h() const
Effective map height.
std::vector< std::pair< int, int > > parse_ranges(std::string const &str)
const config & get_config() const
terrain_filter & operator=(const terrain_filter &other)
Information on a WML variable.
GLfloat GLfloat GLfloat GLfloat h
bool terrain_matches(const t_terrain &src, const t_terrain &dest)
Tests whether a specific terrain matches an expression, for matching rules see above.
GLint GLint GLint GLint GLint x
bool run_filter(char const *name, unit const &u)
Runs a script from a unit filter.
bool fogged(const map_location &loc) const
void get_tiles_radius(const map_location ¢er, size_t radius, std::set< map_location > &result)
Function that will add to result all locations within radius tiles of center (including center itself...
virtual const tod_manager & get_tod_man() const =0
const std::set< map_location > & get_area_by_id(const std::string &id) const
t_translation::t_terrain get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
bool on_board(const map_location &loc) const
Tell if a location is on the map.
const time_of_day get_illuminated_time_of_day(const unit_map &units, const gamemap &map, const map_location &loc, int for_turn=0) const
Returns time of day object for the passed turn at a location.
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
bool find(E event, F functor)
Tests whether an event handler is available.
virtual const game_data * get_game_data() const =0
static int cond(LexState *ls)
A variable-expanding proxy for the config class.
static lg::log_domain log_engine("engine")
Standard logging facilities (interface).
virtual game_lua_kernel * get_lua_kernel() const =0
boost::scoped_ptr< unit_filter > ufilter_
std::vector< std::pair< terrain_filter, std::map< map_location, bool > > > adjacent_match_cache
int to_int(int def=0) const
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.
terrain_filter(const vconfig &cfg, const filter_context *fc, const bool flat_tod=false, const size_t max_loop=game_config::max_loop)
unit_iterator find(size_t id)
static void filter_area(T &&src, location_set &dest, const terrain_filter &filter, const F1 &f1)
std::vector< vconfig > child_list
bool match_internal(const map_location &loc, const bool ignore_xy) const
A config object defines a single node in a WML file, with access to child nodes.
static void filter_xy(T &&src, location_set &dest, const terrain_filter &filter, bool with_border)
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)
std::set< map_location > location_set