Author: sapient
Date: Mon Apr 30 07:16:28 2007
New Revision: 17182
URL: http://svn.gna.org/viewcvs/wesnoth?rev=17182&view=rev
Log:
correct some logic errors and allow absence of x or y in multi-location filter
Modified:
trunk/src/map.cpp
trunk/src/map.hpp
Modified: trunk/src/map.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/map.cpp?rev=17182&r1=17181&r2=17182&view=diff
==============================================================================
--- trunk/src/map.cpp (original)
+++ trunk/src/map.cpp Mon Apr 30 07:16:28 2007
@@ -713,15 +713,35 @@
remove_from_border_cache(adj[n]);
}
-std::vector<gamemap::location> parse_location_range(const std::string& x,
const std::string& y)
+std::vector<gamemap::location> parse_location_range(const std::string& x,
const std::string& y,
+
const gamemap *const map)
{
std::vector<gamemap::location> res;
const std::vector<std::string> xvals = utils::split(x);
const std::vector<std::string> yvals = utils::split(y);
- for(unsigned int i = 0; i != minimum(xvals.size(),yvals.size()); ++i) {
- const std::pair<int,int> xrange = utils::parse_range(xvals[i]);
- const std::pair<int,int> yrange = utils::parse_range(yvals[i]);
+ for(unsigned int i = 0; i < xvals.size() || i < yvals.size(); ++i) {
+ std::pair<int,int> xrange, yrange;
+
+ //x
+ if(i < xvals.size()) {
+ xrange = utils::parse_range(xvals[i]);
+ } else if (map != NULL) {
+ xrange.first = 1;
+ xrange.second = map->x();
+ } else {
+ break;
+ }
+
+ //y
+ if(i < yvals.size()) {
+ yrange = utils::parse_range(yvals[i]);
+ } else if (map != NULL) {
+ yrange.first = 1;
+ yrange.second = map->y();
+ } else {
+ break;
+ }
for(int x = xrange.first; x <= xrange.second; ++x) {
for(int y = yrange.first; y <= yrange.second; ++y) {
@@ -729,7 +749,6 @@
}
}
}
-
return res;
}
@@ -760,20 +779,31 @@
const gamestatus& game_status, const unit_map& units, const
bool flat_tod,
const size_t max_loop) const
{
- std::vector<gamemap::location> xy_locs =
parse_location_range(filter["x"],filter["y"]);
+ std::vector<gamemap::location> xy_locs =
parse_location_range(filter["x"],filter["y"],this);
if(xy_locs.empty()) {
//consider all locations on the map
for(int x=0; x < x_; x++) {
for(int y=0; y < y_; y++) {
- locs.insert(location(x,y));
- }
- }
- } else {
- //handle radius
- const size_t radius = minimum<size_t>(max_loop,
- lexical_cast_default<size_t>(filter["radius"], 0));
- get_tiles_radius(*this, xy_locs, radius, locs);
- }
+ xy_locs.push_back(location(x,y));
+ }
+ }
+ }
+
+ //handle filter
+ std::vector<gamemap::location>::iterator loc_itor = xy_locs.begin();
+ while(loc_itor != xy_locs.end()) {
+ if(terrain_matches_internal(*loc_itor, filter, game_status,
units, flat_tod, true)) {
+ ++loc_itor;
+ } else {
+ loc_itor = xy_locs.erase(loc_itor);
+ }
+ }
+
+ //handle radius
+ const size_t radius = minimum<size_t>(max_loop,
+ lexical_cast_default<size_t>(filter["radius"], 0));
+ get_tiles_radius(*this, xy_locs, radius, locs);
+
//handle [not]
if(filter.has_child("not")) {
const vconfig::child_list& nots = filter.get_children("not");
@@ -786,7 +816,8 @@
}
}
}
- //restrict the potential number of locations to be filtered
+
+ //restrict the potential number of locations to be returned
if(locs.size() > max_loop + 1) {
std::set<gamemap::location>::iterator erase_itor = locs.begin();
for(int i=0; i < max_loop + 1; ++i) {
@@ -794,12 +825,4 @@
}
locs.erase(erase_itor, locs.end());
}
- std::set<gamemap::location>::iterator loc_itor = locs.begin();
- while(loc_itor != locs.end()) {
- if(terrain_matches_internal(*loc_itor, filter, game_status,
units, flat_tod, true)) {
- ++loc_itor;
- } else {
- locs.erase(loc_itor++);
- }
- }
-}
+}
Modified: trunk/src/map.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/map.hpp?rev=17182&r1=17181&r2=17182&view=diff
==============================================================================
--- trunk/src/map.hpp (original)
+++ trunk/src/map.hpp Mon Apr 30 07:16:28 2007
@@ -236,7 +236,9 @@
//a utility function which parses ranges of locations
//into a vector of locations
-std::vector<gamemap::location> parse_location_range(const std::string& xvals,
const std::string& yvals);
+std::vector<gamemap::location> parse_location_range(const std::string& xvals,
+
const std::string& yvals,
+
const gamemap *const map=NULL);
//dump a position on a stream for debug purposes
std::ostream &operator<<(std::ostream &s, gamemap::location const &l);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits