Always consider border hexes when filtering locations

This commit is contained in:
Charles Dang 2015-01-04 18:08:27 +11:00
parent 3f40d2f6e7
commit dc807a0ab6
4 changed files with 21 additions and 21 deletions

View file

@ -391,7 +391,7 @@ namespace { // Support functions
// Filter the locations.
std::set<map_location> locs;
const terrain_filter t_filter(cfg, resources::filter_con);
t_filter.get_locations(locs, true);
t_filter.get_locations(locs);
// Loop through sides.
BOOST_FOREACH(const int &side_num, sides)

View file

@ -818,7 +818,7 @@ int game_lua_kernel::intf_shroud_op(lua_State *L, bool place_shroud)
// Filter the locations.
std::set<map_location> locs;
const terrain_filter filter(cfg, &game_state_);
filter.get_locations(locs, true);
filter.get_locations(locs);
BOOST_FOREACH(const int &side_num, sides)
{
@ -1828,7 +1828,7 @@ int game_lua_kernel::intf_find_cost_map(lua_State *L)
}
filter_context & fc = game_state_;
const terrain_filter t_filter(filter, &fc);
t_filter.get_locations(location_set, true);
t_filter.get_locations(location_set);
++arg;
// build cost_map
@ -2557,7 +2557,7 @@ int game_lua_kernel::intf_get_locations(lua_State *L)
std::set<map_location> res;
filter_context & fc = game_state_;
const terrain_filter t_filter(filter, &fc);
t_filter.get_locations(res, true);
t_filter.get_locations(res);
lua_createtable(L, res.size(), 0);
int i = 1;
@ -3428,7 +3428,7 @@ int game_lua_kernel::intf_add_time_area(lua_State * L)
std::set<map_location> locs;
const terrain_filter filter(cfg, &game_state_);
filter.get_locations(locs, true);
filter.get_locations(locs);
config parsed_cfg = cfg.get_parsed_config();
tod_man().add_time_area(id, locs, parsed_cfg);
LOG_LUA << "event WML inserted time_area '" << id << "'\n";

View file

@ -398,7 +398,7 @@ bool terrain_filter::match(const map_location& loc) const
return false;
}
void terrain_filter::get_locations(std::set<map_location>& locs, bool with_border) const
void terrain_filter::get_locations(std::set<map_location>& locs) const
{
std::set<map_location> match_set;
@ -409,10 +409,10 @@ void terrain_filter::get_locations(std::set<map_location>& locs, bool with_borde
//consider all locations on the map
int bs = fc_->get_disp_context().map().border_size();
int w = with_border ? fc_->get_disp_context().map().w() + bs : fc_->get_disp_context().map().w();
int h = with_border ? fc_->get_disp_context().map().h() + bs : fc_->get_disp_context().map().h();
for (int x = with_border ? 0 - bs : 0; x < w; ++x) {
for (int y = with_border ? 0 - bs : 0; y < h; ++y) {
int w = fc_->get_disp_context().map().w() + bs;
int h = fc_->get_disp_context().map().h() + bs;
for (int x = 0 - bs; x < w; ++x) {
for (int y = 0 - bs; y < h; ++y) {
match_set.insert(map_location(x,y));
}
}
@ -424,7 +424,7 @@ void terrain_filter::get_locations(std::set<map_location>& locs, bool with_borde
&& !cfg_.has_attribute("area") ) {
std::vector<map_location> xy_vector;
xy_vector = fc_->get_disp_context().map().parse_location_range(cfg_["x"], cfg_["y"], with_border);
xy_vector = fc_->get_disp_context().map().parse_location_range(cfg_["x"], cfg_["y"], true);
match_set.insert(xy_vector.begin(), xy_vector.end());
} else
@ -466,7 +466,7 @@ void terrain_filter::get_locations(std::set<map_location>& locs, bool with_borde
&& !cfg_.has_attribute("area") ) {
std::vector<map_location> xy_vector;
xy_vector = fc_->get_disp_context().map().parse_location_range(cfg_["x"], cfg_["y"], with_border);
xy_vector = fc_->get_disp_context().map().parse_location_range(cfg_["x"], cfg_["y"], true);
match_set.insert(xy_vector.begin(), xy_vector.end());
// remove any locations not found in the specified variable
@ -497,7 +497,7 @@ void terrain_filter::get_locations(std::set<map_location>& locs, bool with_borde
&& cfg_.has_attribute("area") ) {
std::vector<map_location> xy_vector;
xy_vector = fc_->get_disp_context().map().parse_location_range(cfg_["x"], cfg_["y"], with_border);
xy_vector = fc_->get_disp_context().map().parse_location_range(cfg_["x"], cfg_["y"], true);
const std::set<map_location>& area = fc_->get_tod_man().get_area_by_id(cfg_["area"]);
BOOST_FOREACH(const map_location& loc, xy_vector) {
@ -539,7 +539,7 @@ void terrain_filter::get_locations(std::set<map_location>& locs, bool with_borde
&& cfg_.has_attribute("area") ) {
const std::vector<map_location>& xy_vector =
fc_->get_disp_context().map().parse_location_range(cfg_["x"], cfg_["y"], with_border);
fc_->get_disp_context().map().parse_location_range(cfg_["x"], cfg_["y"], true);
std::set<map_location> xy_set(xy_vector.begin(), xy_vector.end());
const std::set<map_location>& area = fc_->get_tod_man().get_area_by_id(cfg_["area"]);
@ -572,7 +572,7 @@ void terrain_filter::get_locations(std::set<map_location>& locs, bool with_borde
for (unsigned i = 0; i < adj_cfgs.size(); ++i) {
std::set<map_location> adj_set;
/* GCC-3.3 doesn't like operator[] so use at(), which has the same result */
terrain_filter(adj_cfgs.at(i), *this).get_locations(adj_set, with_border);
terrain_filter(adj_cfgs.at(i), *this).get_locations(adj_set);
cache_.adjacent_matches->push_back(adj_set);
if(i >= max_loop_ && i+1 < adj_cfgs.size()) {
ERR_NG << "terrain_filter: loop count greater than " << max_loop_
@ -607,7 +607,7 @@ void terrain_filter::get_locations(std::set<map_location>& locs, bool with_borde
//handle [and]
if(cond_name == "and") {
std::set<map_location> intersect_hexes;
terrain_filter(cond_cfg, *this).get_locations(intersect_hexes, with_border);
terrain_filter(cond_cfg, *this).get_locations(intersect_hexes);
std::set<map_location>::iterator intersect_itor = match_set.begin();
while(intersect_itor != match_set.end()) {
if(intersect_hexes.find(*intersect_itor) == intersect_hexes.end()) {
@ -620,7 +620,7 @@ void terrain_filter::get_locations(std::set<map_location>& locs, bool with_borde
//handle [or]
else if(cond_name == "or") {
std::set<map_location> union_hexes;
terrain_filter(cond_cfg, *this).get_locations(union_hexes, with_border);
terrain_filter(cond_cfg, *this).get_locations(union_hexes);
//match_set.insert(union_hexes.begin(), union_hexes.end()); //doesn't compile on MSVC
std::set<map_location>::iterator insert_itor = union_hexes.begin();
while(insert_itor != union_hexes.end()) {
@ -631,7 +631,7 @@ void terrain_filter::get_locations(std::set<map_location>& locs, bool with_borde
//handle [not]
else if(cond_name == "not") {
std::set<map_location> removal_hexes;
terrain_filter(cond_cfg, *this).get_locations(removal_hexes, with_border);
terrain_filter(cond_cfg, *this).get_locations(removal_hexes);
std::set<map_location>::iterator erase_itor = removal_hexes.begin();
while(erase_itor != removal_hexes.end()) {
match_set.erase(*erase_itor++);
@ -654,9 +654,9 @@ void terrain_filter::get_locations(std::set<map_location>& locs, bool with_borde
std::vector<map_location> xy_vector (match_set.begin(), match_set.end());
if(cfg_.has_child("filter_radius")) {
terrain_filter r_filter(cfg_.child("filter_radius"), *this);
get_tiles_radius(fc_->get_disp_context().map(), xy_vector, radius, locs, with_border, r_filter);
get_tiles_radius(fc_->get_disp_context().map(), xy_vector, radius, locs, true, r_filter);
} else {
get_tiles_radius(fc_->get_disp_context().map(), xy_vector, radius, locs, with_border);
get_tiles_radius(fc_->get_disp_context().map(), xy_vector, radius, locs, true);
}
} else {
locs.insert(match_set.begin(), match_set.end());

View file

@ -55,7 +55,7 @@ public:
//get_locations: gets all locations on the map that match this filter
// @param locs - out parameter containing the results
void get_locations(std::set<map_location>& locs, bool with_border=false) const;
void get_locations(std::set<map_location>& locs) const;
//restrict: limits the allowed radius size and also limits nesting
// The purpose to limit the time spent for WML handling