terrain_filter.hpp

Go to the documentation of this file.
00001 /* $Id: terrain_filter.hpp 53711 2012-03-31 08:29:26Z boucman $ */
00002 /*
00003    Copyright (C) 2003 - 2012 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 as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
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 //terrain_filter: a class that implements the Standard Location Filter
00030 class terrain_filter : public xy_pred {
00031 public:
00032 
00033 #ifdef _MSC_VER
00034     // This constructor is required for MSVC 9 SP1 due to a bug there
00035     // see http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/34473b8c-0184-4750-a290-08558e4eda4e
00036     // other compilers don't need it.
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     /** Default implementation, but defined out-of-line for efficiency reasons. */
00044     ~terrain_filter();
00045 
00046     terrain_filter(const terrain_filter &other);
00047     terrain_filter& operator=(const terrain_filter &other);
00048 
00049     //match: returns true if and only if the given location matches this filter
00050     bool match(const map_location& loc) const;
00051     virtual bool operator()(const map_location& loc) { return this->match(loc); }
00052 
00053     //get_locations: gets all locations on the map that match this filter
00054     // @param locs - out parameter containing the results
00055     void get_locations(std::set<map_location>& locs, bool with_border=false) const;
00056 
00057     //restrict: limits the allowed radius size and also limits nesting
00058     // The purpose to limit the time spent for WML handling
00059     // Note: this feature is not fully implemented, e.g. SLF inside SUF inside SLF
00060     void restrict_size(const size_t max_loop) { max_loop_ = max_loop; }
00061 
00062     //flatten: use base time of day -- ignore illumination ability
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_; //config contains WML for a Standard Location Filter
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         //parsed_terrain: optimizes handling of terrain="..."
00083         t_translation::t_match *parsed_terrain;
00084 
00085         //adjacent_matches: optimize handling of [filter_adjacent_location] for get_locations()
00086         std::vector< std::set<map_location> > *adjacent_matches;
00087 
00088         //adjacent_match_cache: optimize handling of [filter_adjacent_location] for match()
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 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:11 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs