Author: sapient
Date: Mon Apr 30 04:47:49 2007
New Revision: 17178
URL: http://svn.gna.org/viewcvs/wesnoth?rev=17178&view=rev
Log:
[store_locations] now uses the standard location filter instead of its own code
Modified:
trunk/src/game_events.cpp
trunk/src/map.cpp
trunk/src/map.hpp
Modified: trunk/src/game_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.cpp?rev=17178&r1=17177&r2=17178&view=diff
==============================================================================
--- trunk/src/game_events.cpp (original)
+++ trunk/src/game_events.cpp Mon Apr 30 04:47:49 2007
@@ -1960,7 +1960,6 @@
* - terrain: if present, filter the village types against this list of
terrain types
*/
else if(cmd == "store_villages" ) {
- //TODO - add wildcard support
log_scope("store_villages");
std::string variable = cfg["variable"];
if (variable.empty()) {
@@ -1991,48 +1990,20 @@
}
else if(cmd == "store_locations" ) {
- //TODO - add wildcard support
log_scope("store_locations");
std::string variable = cfg["variable"];
if (variable.empty()) {
variable="location";
}
- std::string wml_terrain = cfg["terrain"];
- std::string x = cfg["x"];
- std::string y = cfg["y"];
- std::string radius_str = cfg["radius"];
- wassert(state_of_game != NULL);
- const t_translation::t_list& terrain =
t_translation::read_list(wml_terrain);
-
- const vconfig unit_filter = cfg.child("filter");
-
state_of_game->clear_variable_cfg(variable);
- std::vector<gamemap::location> locs = parse_location_range(x,y);
- if(locs.size() > MaxLoop) {
- locs.resize(MaxLoop);
- }
-
- const size_t radius =
minimum<size_t>(MaxLoop,lexical_cast_default<size_t>(radius_str));
std::set<gamemap::location> res;
- get_tiles_radius(*game_map, locs, radius, res);
-
- size_t added = 0;
- for(std::set<gamemap::location>::const_iterator j =
res.begin(); j != res.end() && added != MaxLoop; ++j) {
- if (!terrain.empty()) {
- const t_translation::t_letter c =
game_map->get_terrain(*j);
- if(std::find(terrain.begin(), terrain.end(), c)
== terrain.end())
- continue;
- }
- if (!unit_filter.null()) {
- const unit_map::const_iterator u =
units->find(*j);
- if (u == units->end() ||
!game_events::unit_matches_filter(u, unit_filter))
- continue;
- }
+ game_map->get_locations(res, cfg, *status_ptr, *units, false,
MaxLoop);
+
+ for(std::set<gamemap::location>::const_iterator j =
res.begin(); j != res.end(); ++j) {
config &loc_store =
state_of_game->add_variable_cfg(variable);
j->write(loc_store);
game_map->write_terrain(*j, loc_store);
- ++added;
}
}
Modified: trunk/src/map.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/map.cpp?rev=17178&r1=17177&r2=17178&view=diff
==============================================================================
--- trunk/src/map.cpp (original)
+++ trunk/src/map.cpp Mon Apr 30 04:47:49 2007
@@ -593,7 +593,8 @@
}
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
+ const gamestatus& game_status, const unit_map& units, const
bool flat_tod,
+ const bool ignore_xy) const
{
const int terrain_format = lexical_cast_default(cfg["terrain_format"],
-1);
@@ -611,7 +612,7 @@
}
//Allow filtering on location ranges
- if(!cfg["x"].empty() || !cfg["y"].empty()){
+ if(!ignore_xy && !(cfg["x"].empty() && cfg["y"].empty())){
if(!loc.matches_range(cfg["x"], cfg["y"])) {
return false;
}
@@ -754,3 +755,51 @@
return terrainFrequencyCache_;
}
+
+void gamemap::get_locations(std::set<gamemap::location>& locs, const vconfig&
filter,
+ 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"]);
+ 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);
+ }
+ //handle [not]
+ if(filter.has_child("not")) {
+ const vconfig::child_list& nots = filter.get_children("not");
+ for(vconfig::child_list::const_iterator i = nots.begin(); i !=
nots.end(); ++i) {
+ std::set<gamemap::location> removal_hexes;
+ get_locations(removal_hexes, *i, game_status, units,
flat_tod, max_loop);
+ std::set<gamemap::location>::iterator erase_itor =
removal_hexes.begin();
+ while(erase_itor != removal_hexes.end()) {
+ locs.erase(*erase_itor++);
+ }
+ }
+ }
+ //restrict the potential number of locations to be filtered
+ if(locs.size() > max_loop + 1) {
+ std::set<gamemap::location>::iterator erase_itor = locs.begin();
+ for(int i=0; i < max_loop + 1; ++i) {
+ ++erase_itor;
+ }
+ 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=17178&r1=17177&r2=17178&view=diff
==============================================================================
--- trunk/src/map.hpp (original)
+++ trunk/src/map.hpp Mon Apr 30 04:47:49 2007
@@ -26,6 +26,7 @@
#include <map>
#include <string>
#include <vector>
+#include <set>
#define MAX_MAP_AREA 65536
@@ -179,8 +180,14 @@
//shortcut to get_terrain_info(get_terrain(loc))
const terrain_type& get_terrain_info(const location &loc) const
{ return get_terrain_info(get_terrain(loc)); }
- //
+
+ //the terrain filter, also known as "standard location filter" or SLF
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 all locations that match a given terrain filter
+ void get_locations(std::set<location>& locs, const vconfig& filter,
const gamestatus& game_status, const unit_map& units,
const bool flat_tod=false, const size_t
max_loop=MAX_MAP_AREA) const;
@@ -211,7 +218,8 @@
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;
+ const gamestatus& game_status, const unit_map& units,
+ const bool flat_tod=false, const bool ignore_xy=false)
const;
int num_starting_positions() const
{ return
sizeof(startingPositions_)/sizeof(*startingPositions_); }
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits