added vector<team> member to terrain_filter...

...(in preparation of gamestatus removal)
This commit is contained in:
Eugen Jiresch 2009-06-11 09:31:34 +00:00
parent 3842034843
commit 3934a3a087
7 changed files with 22 additions and 15 deletions

View File

@ -400,7 +400,7 @@ namespace game_events {
backwards_compat = backwards_compat && have_location.empty();
for(vconfig::child_list::const_iterator v = have_location.begin(); v != have_location.end(); ++v) {
std::set<map_location> res;
terrain_filter(*v, *rsrc.game_map, *rsrc.status_ptr, *units).get_locations(res);
terrain_filter(*v, *rsrc.game_map, *rsrc.status_ptr, *rsrc.teams, *units).get_locations(res);
std::vector<std::pair<int,int> > counts = (*v).has_attribute("count")
? utils::parse_ranges((*v)["count"]) : default_counts;
@ -572,7 +572,7 @@ static void toggle_shroud(const bool remove, const vconfig& cfg)
if (index < rsrc.teams->size()) {
std::set<map_location> locs;
terrain_filter filter(cfg, *rsrc.game_map, *rsrc.status_ptr, *rsrc.units);
terrain_filter filter(cfg, *rsrc.game_map, *rsrc.status_ptr, *rsrc.teams, *rsrc.units);
filter.restrict_size(game_config::max_loop);
filter.get_locations(locs);
@ -2659,9 +2659,9 @@ WML_HANDLER_FUNCTION(store_villages, /*event_info*/, cfg)
config temp_cfg(cfg.get_config());
temp_cfg["owner_side"] = temp_cfg["side"];
temp_cfg["side"] = "";
matches = terrain_filter(vconfig(temp_cfg), *rsrc.game_map, *rsrc.status_ptr, *rsrc.units).match(*j);
matches = terrain_filter(vconfig(temp_cfg), *rsrc.game_map, *rsrc.status_ptr, *rsrc.teams, *rsrc.units).match(*j);
} else {
matches = terrain_filter(cfg, *rsrc.game_map, *rsrc.status_ptr, *rsrc.units).match(*j);
matches = terrain_filter(cfg, *rsrc.game_map, *rsrc.status_ptr, *rsrc.teams, *rsrc.units).match(*j);
}
if(matches) {
config &loc_store = to_store.add_child(varinfo.key);
@ -2688,7 +2688,7 @@ WML_HANDLER_FUNCTION(store_locations, /*event_info*/, cfg)
}
std::set<map_location> res;
terrain_filter filter(cfg, *rsrc.game_map, *rsrc.status_ptr, *rsrc.units);
terrain_filter filter(cfg, *rsrc.game_map, *rsrc.status_ptr, *rsrc.teams, *rsrc.units);
filter.restrict_size(game_config::max_loop);
filter.get_locations(res);
@ -3343,7 +3343,7 @@ WML_HANDLER_FUNCTION(time_area, /*event_info*/, cfg)
id = ids;
}
std::set<map_location> locs;
terrain_filter filter(cfg, *game_events::resources->game_map, *status_ptr, *game_events::resources->units);
terrain_filter filter(cfg, *game_events::resources->game_map, *status_ptr, *game_events::resources->teams, *game_events::resources->units);
filter.restrict_size(game_config::max_loop);
filter.get_locations(locs);
config parsed_cfg = cfg.get_parsed_config();

View File

@ -920,7 +920,7 @@ void play_controller::expand_wml_commands(std::vector<std::string>& items)
if ((show_if.empty()
|| game_events::conditional_passed(&units_, vconfig(show_if)))
&& (filter_location.empty()
|| terrain_filter(vconfig(filter_location), map_, status_, units_)(hex))
|| terrain_filter(vconfig(filter_location), map_, status_, *(status_.teams), units_)(hex))
&& (!itor->second->needs_select
|| gamestate_.last_selected.valid()))
{

View File

@ -43,12 +43,13 @@ terrain_filter::terrain_filter():
#endif
terrain_filter::terrain_filter(const vconfig& cfg, const gamemap& map,
const gamestatus& game_status, const unit_map& units,
const gamestatus& game_status, const std::vector<team>& teams, const unit_map& units,
const bool flat_tod, const size_t max_loop) :
cfg_(cfg),
map_(map),
status_(game_status),
units_(units),
teams_(teams),
cache_(),
max_loop_(max_loop),
flat_(flat_tod)
@ -60,6 +61,7 @@ terrain_filter::terrain_filter(const vconfig& cfg, const terrain_filter& origina
map_(original.map_),
status_(original.status_),
units_(original.units_),
teams_(original.teams_),
cache_(),
max_loop_(original.max_loop_),
flat_(original.flat_)
@ -73,6 +75,7 @@ terrain_filter::terrain_filter(const terrain_filter& other) :
map_(other.map_),
status_(other.status_),
units_(other.units_),
teams_(other.teams_),
cache_(),
max_loop_(other.max_loop_),
flat_(other.flat_)
@ -253,8 +256,8 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x
const std::string& owner_side = t_owner_side;
if(!owner_side.empty()) {
const int side_index = lexical_cast_default<int>(owner_side,0) - 1;
assert(status_.teams != NULL);
if(village_owner(loc, *(status_.teams)) != side_index) {
assert(&teams_ != NULL);
if(village_owner(loc, teams_) != side_index) {
return false;
}
}

View File

@ -23,6 +23,8 @@ class gamestatus;
class unit;
class vconfig;
class unit_map;
class tod_manager;
class team;
//terrain_filter: a class that implements the Standard Location Filter
class terrain_filter : public xy_pred {
@ -33,7 +35,7 @@ public:
// other compilers don't need it.
terrain_filter();
#endif
terrain_filter(const vconfig& cfg, const gamemap& map, const gamestatus& game_status,
terrain_filter(const vconfig& cfg, const gamemap& map, const gamestatus& game_status, const std::vector<team>& teams,
const unit_map& units, const bool flat_tod=false, const size_t max_loop=MAX_MAP_AREA);
terrain_filter(const vconfig& cfg, const terrain_filter& original);
~terrain_filter() {};
@ -64,6 +66,7 @@ private:
const gamemap& map_;
const gamestatus& status_;
const unit_map& units_;
const std::vector<team>& teams_;
struct terrain_filter_cache {
terrain_filter_cache() :

View File

@ -1129,7 +1129,7 @@ bool unit::internal_matches_filter(const vconfig& cfg, const map_location& loc,
assert(gamestatus_ != NULL);
assert(units_ != NULL);
const vconfig& t_cfg = cfg.child("filter_location");
terrain_filter t_filter(t_cfg, *map_, *gamestatus_, *units_, use_flat_tod);
terrain_filter t_filter(t_cfg, *map_, *gamestatus_, *(gamestatus_->teams), *units_, use_flat_tod);
if(!t_filter.match(loc)) {
return false;
}

View File

@ -21,6 +21,7 @@
#include "unit.hpp"
#include "unit_abilities.hpp"
#include "terrain_filter.hpp"
#include "gamestatus.hpp"
@ -277,7 +278,7 @@ bool unit::ability_active(const std::string& ability,const config& cfg,const map
if (index == map_location::NDIRECTIONS) {
continue;
}
terrain_filter adj_filter(vconfig(i), *map_, *gamestatus_, *units_);
terrain_filter adj_filter(vconfig(i), *map_, *gamestatus_, *(gamestatus_->teams), *units_);
adj_filter.flatten(cache_illuminates(illuminates, ability));
if(!adj_filter.match(adjacent[index])) {
return false;
@ -689,7 +690,7 @@ bool attack_type::special_active(const config& cfg, bool self) const
map_location::parse_direction(j);
if (index == map_location::NDIRECTIONS)
continue;
terrain_filter adj_filter(vconfig(i), *map_, *game_status_, *unitmap_);
terrain_filter adj_filter(vconfig(i), *map_, *game_status_, *(game_status_->teams), *unitmap_);
if(!adj_filter.match(adjacent[index])) {
return false;
}

View File

@ -473,7 +473,7 @@ void wml_animation_internal(unit_animator & animator,const vconfig &cfg, const g
vconfig t_filter = cfg.child("facing");
map_location secondary_loc = map_location::null_location;
if(!t_filter.empty()) {
terrain_filter filter(t_filter,map,game_status,units);
terrain_filter filter(t_filter,map,game_status,*(game_status.teams),units);
std::set<map_location> locs;
filter.get_locations(locs);
if(!locs.empty()) {