Author: sapient
Date: Wed Apr  4 06:54:27 2007
New Revision: 16585

URL: http://svn.gna.org/viewcvs/wesnoth?rev=16585&view=rev
Log:
more powerful [filter_location], now accepts radius=, [not], and [filter] to 
match units at the location

Modified:
    trunk/changelog
    trunk/src/map.cpp
    trunk/src/map.hpp
    trunk/src/play_controller.cpp
    trunk/src/unit.cpp
    trunk/src/unit_abilities.cpp

Modified: trunk/changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=16585&r1=16584&r2=16585&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Wed Apr  4 06:54:27 2007
@@ -84,6 +84,8 @@
      which the attack engine didn't expect (bug #8814)
    * new key for [time], sound=, to specify a list of sounds that can play
      when ToD changes
+   * more powerful [filter_location], now accepts radius=, [not], and 
+     [filter] to match units at the location
  * user interface:
    * new sounds for user interface events
    * added the option to show warnings about deprecated WML usage

Modified: trunk/src/map.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/map.cpp?rev=16585&r1=16584&r2=16585&view=diff
==============================================================================
--- trunk/src/map.cpp (original)
+++ trunk/src/map.cpp Wed Apr  4 06:54:27 2007
@@ -18,7 +18,7 @@
 #include "gamestatus.hpp"
 #include "log.hpp"
 #include "map.hpp"
-#include "pathutils.hpp"
+#include "pathfind.hpp"
 #include "util.hpp"
 #include "variable.hpp"
 #include "wassert.hpp"
@@ -567,7 +567,37 @@
        return true;
 }
 
-bool gamemap::terrain_matches_filter(const gamemap::location& loc, const 
config& cfg, 
+bool gamemap::terrain_matches_filter(const gamemap::location& loc, const 
vconfig& cfg, 
+               const gamestatus& game_status, const unit_map& units, const 
bool flat_tod,
+               const size_t max_loop) const
+{
+       //handle radius
+       const size_t radius = minimum<size_t>(max_loop,
+               lexical_cast_default<size_t>(cfg["radius"]));
+       std::set<gamemap::location> hexes;
+       std::vector<gamemap::location> loc_vec(1, loc);
+       get_tiles_radius(*this, loc_vec, radius, hexes);
+
+       size_t loop_count = 0;
+       bool matches = false;
+       std::set<gamemap::location>::const_iterator i;
+       for(i = hexes.begin(); i != hexes.end() && loop_count <= max_loop && 
!matches; ++i) {
+               matches = terrain_matches_internal(*i, cfg, game_status, units, 
flat_tod);
+               ++loop_count;
+       }
+       if(!matches) return false;
+
+       //handle [not]
+       const vconfig::child_list& nots = cfg.get_children("not");
+       for(vconfig::child_list::const_iterator j = nots.begin(); j != 
nots.end(); ++j) {
+               if(terrain_matches_filter(loc, *j, game_status, units, 
flat_tod, max_loop)) {
+                       return false;
+               }
+       }
+       return true;
+}
+
+bool gamemap::terrain_matches_internal(const gamemap::location& loc, const 
vconfig& cfg, 
                const gamestatus& game_status, const unit_map& units, const 
bool flat_tod) const
 {
        /* *
@@ -626,6 +656,14 @@
                }
        }
 
+       //Allow filtering on unit
+       if(cfg.has_child("filter")) {
+               const config& unit_filter = cfg.child("filter").get_config();
+               const unit_map::const_iterator u = units.find(loc);
+               if (u == units.end() || !u->second.matches_filter(unit_filter, 
loc, flat_tod))
+                       return false;
+       }
+
        const std::string& tod_type = cfg["time_of_day"];
        const std::string& tod_id = cfg["time_of_day_id"];
        static config const dummy_cfg;

Modified: trunk/src/map.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/map.hpp?rev=16585&r1=16584&r2=16585&view=diff
==============================================================================
--- trunk/src/map.hpp (original)
+++ trunk/src/map.hpp Wed Apr  4 06:54:27 2007
@@ -26,6 +26,8 @@
 #include <map>
 #include <string>
 #include <vector>
+
+#define MAX_MAP_AREA   65536
 
 //class which encapsulates the map of the game. Although the game is hexagonal,
 //the map is stored as a grid. Each type of terrain is represented by a letter.
@@ -178,8 +180,9 @@
        const terrain_type& get_terrain_info(const location &loc) const
                { return get_terrain_info(get_terrain(loc)); }
        //
-       bool terrain_matches_filter(const location& loc, const config& cfg, 
-                       const gamestatus& game_status, const unit_map& units, 
const bool flat_tod=false) const;
+       bool terrain_matches_filter(const location& loc, const vconfig& cfg, 
+                       const gamestatus& game_status, const unit_map& units,
+                       const bool flat_tod=false, const size_t 
max_loop=MAX_MAP_AREA) const;
 
        //gets the list of terrains
        const t_translation::t_list& get_terrain_list() const
@@ -207,6 +210,8 @@
        location startingPositions_[STARTING_POSITIONS];
        
 private:
+       bool terrain_matches_internal(const location& loc, const vconfig& cfg, 
+                       const gamestatus& game_status, const unit_map& units, 
const bool flat_tod=false) const;
        int num_starting_positions() const
                { return 
sizeof(startingPositions_)/sizeof(*startingPositions_); }
 

Modified: trunk/src/play_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/play_controller.cpp?rev=16585&r1=16584&r2=16585&view=diff
==============================================================================
--- trunk/src/play_controller.cpp (original)
+++ trunk/src/play_controller.cpp Wed Apr  4 06:54:27 2007
@@ -796,7 +796,7 @@
                                if ((show_if.empty() 
                                        || 
game_events::conditional_passed(&units_, &show_if))
                                && (location_filter.empty() 
-                                       || map_.terrain_matches_filter(hex, 
vconfig(&location_filter).get_parsed_config(), status_, units_)))
+                                       || map_.terrain_matches_filter(hex, 
&location_filter, status_, units_)))
                                {
                                        wml_commands_.push_back(itor->second);
                                        std::string newitem = 
itor->second->description;

Modified: trunk/src/unit.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=16585&r1=16584&r2=16585&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Wed Apr  4 06:54:27 2007
@@ -777,7 +777,7 @@
                wassert(map_ != NULL);
                wassert(gamestatus_ != NULL);
                wassert(units_ != NULL);
-               bool res = 
map_->terrain_matches_filter(loc,*filter_location,*gamestatus_,*units_,use_flat_tod);
+               bool res = 
map_->terrain_matches_filter(loc,filter_location,*gamestatus_,*units_,use_flat_tod);
                if(res == false) {
                        return false;
                }

Modified: trunk/src/unit_abilities.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_abilities.cpp?rev=16585&r1=16584&r2=16585&view=diff
==============================================================================
--- trunk/src/unit_abilities.cpp (original)
+++ trunk/src/unit_abilities.cpp Wed Apr  4 06:54:27 2007
@@ -14,9 +14,10 @@
 #include "unit.hpp"
 #include "unit_abilities.hpp"
 
-#include "wassert.hpp"
 #include "log.hpp"
 #include "pathutils.hpp"
+#include "variable.hpp"
+#include "wassert.hpp"
 
 #include <deque>
 
@@ -322,7 +323,7 @@
                                if(index != gamemap::location::NDIRECTIONS) {
                                        wassert(map_ != NULL);
                                        wassert(gamestatus_ != NULL);
-                                       
if(!map_->terrain_matches_filter(adjacent[index],**i,*gamestatus_,*units_,ability=="illuminates"))
 {
+                                       
if(!map_->terrain_matches_filter(adjacent[index],*i,*gamestatus_,*units_,ability=="illuminates",0))
 {
                                                return false;
                                        }
                                }
@@ -749,7 +750,7 @@
                                if(index != gamemap::location::NDIRECTIONS) {
                                        wassert(map_ != NULL);
                                        wassert(game_status_ != NULL);
-                                       
if(!map_->terrain_matches_filter(adjacent[index],**i,*game_status_,*unitmap_)) {
+                                       
if(!map_->terrain_matches_filter(adjacent[index],*i,*game_status_,*unitmap_,false,0))
 {
                                                return false;
                                        }
                                }


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to