Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TERRAIN_FILTER_H_INCLUDED
00017 #define TERRAIN_FILTER_H_INCLUDED
00018
00019 #include "game_config.hpp"
00020 #include "pathutils.hpp"
00021 #include "terrain_translation.hpp"
00022 #include "variable.hpp"
00023
00024 class config;
00025 class unit;
00026 class unit_map;
00027 class team;
00028
00029
00030 class terrain_filter : public xy_pred {
00031 public:
00032
00033 #ifdef _MSC_VER
00034
00035
00036
00037 terrain_filter();
00038 #endif
00039
00040 terrain_filter(const vconfig& cfg,
00041 const unit_map& units, const bool flat_tod=false, const size_t max_loop=game_config::max_loop);
00042 terrain_filter(const vconfig& cfg, const terrain_filter& original);
00043
00044 ~terrain_filter();
00045
00046 terrain_filter(const terrain_filter &other);
00047 terrain_filter& operator=(const terrain_filter &other);
00048
00049
00050 bool match(const map_location& loc) const;
00051 virtual bool operator()(const map_location& loc) { return this->match(loc); }
00052
00053
00054
00055 void get_locations(std::set<map_location>& locs, bool with_border=false) const;
00056
00057
00058
00059
00060 void restrict_size(const size_t max_loop) { max_loop_ = max_loop; }
00061
00062
00063 void flatten(const bool flat_tod=true) { flat_ = flat_tod; }
00064
00065 config to_config() const;
00066 private:
00067 bool match_internal(const map_location& loc, const bool ignore_xy) const;
00068
00069 const vconfig cfg_;
00070 const unit_map& units_;
00071
00072 struct terrain_filter_cache {
00073 terrain_filter_cache() :
00074 parsed_terrain(NULL),
00075 adjacent_matches(NULL),
00076 adjacent_match_cache()
00077 {
00078 }
00079
00080 ~terrain_filter_cache();
00081
00082
00083 t_translation::t_match *parsed_terrain;
00084
00085
00086 std::vector< std::set<map_location> > *adjacent_matches;
00087
00088
00089 std::vector< std::pair<terrain_filter, std::map<map_location,bool> > > adjacent_match_cache;
00090 };
00091
00092 mutable terrain_filter_cache cache_;
00093 size_t max_loop_;
00094 bool flat_;
00095 };
00096
00097 #endif
00098