terrain_filter.hpp

Go to the documentation of this file.
00001 /* $Id: terrain_filter.hpp 23842 2008-02-16 08:47:16Z mordante $ */
00002 /*
00003    Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
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 //terrain_filter: a class that implements the Standard Location Filter
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     //match: returns true if and only if the given location matches this filter
00039     bool match(const gamemap::location& loc);
00040     virtual bool operator()(const gamemap::location& loc) { return this->match(loc); }
00041 
00042     //get_locations: gets all locations on the map that match this filter
00043     // @param locs - out parameter containing the results
00044     void get_locations(std::set<gamemap::location>& locs);
00045 
00046     //restrict: limits the allowed radius size and also limits nesting
00047     // The purpose to limit the time spent for WML handling
00048     // Note: this feature is not fully implemented, e.g. SLF inside SUF inside SLF
00049     void restrict(const size_t max_loop) { max_loop_ = max_loop; }
00050 
00051     //flatten: use base time of day -- ignore illumination ability
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_; //config contains WML for a Standard Location Filter
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         //parsed_terrain: optimizes handling of terrain="..."
00070         t_translation::t_match *parsed_terrain; 
00071 
00072         //adjacent_matches: optimize handling of [filter_adjacent_location] for get_locations()
00073         std::vector< std::set<gamemap::location> > *adjacent_matches; 
00074 
00075         //adjacent_match_cache: optimize handling of [filter_adjacent_location] for match()
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 

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs