00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef TERRAIN_FILTER_H_INCLUDED
00016 #define TERRAIN_FILTER_H_INCLUDED
00017
00018 #include "map.hpp"
00019 #include "pathfind.hpp"
00020
00021 class config;
00022 class gamestatus;
00023 class unit;
00024 class vconfig;
00025 class unit_map;
00026
00027
00028 class terrain_filter : public xy_pred {
00029 public:
00030 terrain_filter(const vconfig& cfg, const gamemap& map, const gamestatus& game_status,
00031 const unit_map& units, const bool flat_tod=false, const size_t max_loop=MAX_MAP_AREA);
00032 terrain_filter(const vconfig& cfg, const terrain_filter& original);
00033 ~terrain_filter() {};
00034
00035 terrain_filter(const terrain_filter &other);
00036 terrain_filter& operator=(const terrain_filter &other);
00037
00038
00039 bool match(const gamemap::location& loc);
00040 virtual bool operator()(const gamemap::location& loc) { return this->match(loc); }
00041
00042
00043
00044 void get_locations(std::set<gamemap::location>& locs);
00045
00046
00047
00048
00049 void restrict(const size_t max_loop) { max_loop_ = max_loop; }
00050
00051
00052 void flatten(const bool flat_tod=true) { flat_ = flat_tod; }
00053
00054 private:
00055 bool match_internal(const gamemap::location& loc, const bool ignore_xy);
00056
00057 const vconfig& cfg_;
00058 const gamemap& map_;
00059 const gamestatus& status_;
00060 const unit_map& units_;
00061
00062 struct terrain_filter_cache {
00063 terrain_filter_cache() : parsed_terrain(NULL), adjacent_matches(NULL) {}
00064 ~terrain_filter_cache() {
00065 delete parsed_terrain;
00066 delete adjacent_matches;
00067 }
00068
00069
00070 t_translation::t_match *parsed_terrain;
00071
00072
00073 std::vector< std::set<gamemap::location> > *adjacent_matches;
00074
00075
00076 std::vector< std::pair<terrain_filter, std::map<gamemap::location,bool> > > adjacent_match_cache;
00077 };
00078
00079 terrain_filter_cache cache_;
00080 size_t max_loop_;
00081 bool flat_;
00082 };
00083
00084 #endif
00085