diff --git a/src/ai/composite/goal.cpp b/src/ai/composite/goal.cpp index c8f24263afb9..b8e39eeac279 100644 --- a/src/ai/composite/goal.cpp +++ b/src/ai/composite/goal.cpp @@ -24,6 +24,7 @@ #include "ai/lua/core.hpp" #include "ai/lua/lua_object.hpp" #include "ai/manager.hpp" +#include "filter_context.hpp" #include "game_board.hpp" #include "log.hpp" #include "map_location.hpp" @@ -165,7 +166,7 @@ void target_location_goal::on_create() } const config &criteria = cfg_.child("criteria"); if (criteria) { - filter_ptr_ = boost::shared_ptr(new terrain_filter(vconfig(criteria),*resources::units)); + filter_ptr_ = boost::shared_ptr(new terrain_filter(vconfig(criteria),resources::filter_con)); } } @@ -221,7 +222,7 @@ void protect_goal::on_create() } const config &criteria = cfg_.child("criteria"); if (criteria) { - filter_ptr_ = boost::shared_ptr(new terrain_filter(vconfig(criteria),*resources::units)); + filter_ptr_ = boost::shared_ptr(new terrain_filter(vconfig(criteria),resources::filter_con)); } diff --git a/src/ai/composite/value_translator.hpp b/src/ai/composite/value_translator.hpp index 8a72c690b8f4..b66703e30402 100644 --- a/src/ai/composite/value_translator.hpp +++ b/src/ai/composite/value_translator.hpp @@ -179,10 +179,10 @@ class config_value_translator { static terrain_filter cfg_to_value(const config &cfg) { if (const config &v = cfg.child("value")) { - return terrain_filter(vconfig(v), *resources::units); + return terrain_filter(vconfig(v), resources::filter_con); } static config c("not"); - return terrain_filter(vconfig(c),*resources::units); + return terrain_filter(vconfig(c),resources::filter_con); } static void cfg_to_value(const config &cfg, terrain_filter &value) @@ -442,7 +442,7 @@ class variant_value_translator { static terrain_filter variant_to_value(const variant &var) { static config c("not"); - terrain_filter value(vconfig(c),*resources::units); + terrain_filter value(vconfig(c),resources::filter_con); variant_to_value(var,value); return value; } diff --git a/src/ai/contexts.cpp b/src/ai/contexts.cpp index 809bbe4e281a..2e0b96b6cc36 100644 --- a/src/ai/contexts.cpp +++ b/src/ai/contexts.cpp @@ -608,7 +608,7 @@ const terrain_filter& readonly_context_impl::get_avoid() const } config cfg; cfg.add_child("not"); - static terrain_filter tf(vconfig(cfg),*resources::units); + static terrain_filter tf(vconfig(cfg),resources::filter_con); return tf; } diff --git a/src/ai/lua/lua_object.hpp b/src/ai/lua/lua_object.hpp index d6385e83c9d8..87947c225325 100644 --- a/src/ai/lua/lua_object.hpp +++ b/src/ai/lua/lua_object.hpp @@ -138,7 +138,7 @@ inline boost::shared_ptr lua_object::to_type(lua boost::shared_ptr cfg = boost::shared_ptr(new config()); boost::shared_ptr vcfg = boost::shared_ptr(new vconfig(*cfg)); luaW_tovconfig(L, n, *vcfg); - boost::shared_ptr tf = boost::shared_ptr(new terrain_filter(*vcfg, *resources::units)); + boost::shared_ptr tf = boost::shared_ptr(new terrain_filter(*vcfg, resources::filter_con)); return tf; } diff --git a/src/game_events/action_wml.cpp b/src/game_events/action_wml.cpp index cf8d2ec149cc..0c225c7b1a3e 100644 --- a/src/game_events/action_wml.cpp +++ b/src/game_events/action_wml.cpp @@ -449,7 +449,7 @@ namespace { // Support functions // Filter the locations. std::set locs; - const terrain_filter t_filter(cfg, *resources::units); + const terrain_filter t_filter(cfg, resources::filter_con); t_filter.get_locations(locs, true); // Loop through sides. @@ -485,7 +485,7 @@ namespace { // Support functions // Filter the locations. std::set locs; - const terrain_filter filter(cfg, *resources::units); + const terrain_filter filter(cfg, resources::filter_con); filter.get_locations(locs, true); BOOST_FOREACH(const int &side_num, sides) @@ -2398,7 +2398,7 @@ WML_HANDLER_FUNCTION(time_area, /*event_info*/, cfg) id = ids; } std::set locs; - const terrain_filter filter(cfg, *resources::units); + const terrain_filter filter(cfg, resources::filter_con); filter.get_locations(locs, true); config parsed_cfg = cfg.get_parsed_config(); resources::tod_manager->add_time_area(id, locs, parsed_cfg); diff --git a/src/game_events/conditional_wml.cpp b/src/game_events/conditional_wml.cpp index ba41a0a09287..249b94e34031 100644 --- a/src/game_events/conditional_wml.cpp +++ b/src/game_events/conditional_wml.cpp @@ -114,7 +114,7 @@ namespace { // Support functions backwards_compat = backwards_compat && have_location.empty(); for(vconfig::child_list::const_iterator v = have_location.begin(); v != have_location.end(); ++v) { std::set res; - terrain_filter(*v, *resources::units).get_locations(res); + terrain_filter(*v, resources::filter_con).get_locations(res); std::vector > counts = (*v).has_attribute("count") ? utils::parse_ranges((*v)["count"]) : default_counts; diff --git a/src/game_events/menu_item.cpp b/src/game_events/menu_item.cpp index 0f1bcbb3ac54..c3cc7919fe80 100644 --- a/src/game_events/menu_item.cpp +++ b/src/game_events/menu_item.cpp @@ -171,7 +171,7 @@ bool wml_menu_item::can_show(const map_location & hex) const // Failing the [fiter_location] tag means no show. if ( !filter_location_.empty() && - !terrain_filter(filter_location_, *resources::units)(hex) ) + !terrain_filter(filter_location_, resources::filter_con)(hex) ) return false; // Failing to have a required selection means no show. diff --git a/src/pathfind/teleport.cpp b/src/pathfind/teleport.cpp index d4fdefac3fad..aef34495cd1b 100644 --- a/src/pathfind/teleport.cpp +++ b/src/pathfind/teleport.cpp @@ -80,10 +80,10 @@ void teleport_group::get_teleport_pair( scoped_xy_unit teleport_unit("teleport_unit", loc.x, loc.y, *resources::units); - terrain_filter source_filter(source, *units); + terrain_filter source_filter(source, resources::filter_con); source_filter.get_locations(reversed_ ? loc_pair.second : loc_pair.first); - terrain_filter target_filter(target, *units); + terrain_filter target_filter(target, resources::filter_con); target_filter.get_locations(reversed_ ? loc_pair.first : loc_pair.second); } } diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 316234215ed3..4cfb15b7dde9 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -41,6 +41,7 @@ #include "config.hpp" // for config, etc #include "display_chat_manager.hpp" // for clear_chat_messages #include "filesystem.hpp" // for get_wml_location +#include "filter_context.hpp" #include "font.hpp" // for LABEL_COLOR #include "game_board.hpp" // for game_board #include "game_classification.hpp" // for game_classification, etc @@ -2119,7 +2120,7 @@ static int intf_find_cost_map(lua_State *L) { filter = vconfig(config(), true); } - const terrain_filter t_filter(filter, *resources::units); + const terrain_filter t_filter(filter, resources::filter_con); t_filter.get_locations(location_set, true); ++arg; @@ -3163,7 +3164,7 @@ static int intf_get_locations(lua_State *L) vconfig filter = luaW_checkvconfig(L, 1); std::set res; - const terrain_filter t_filter(filter, *resources::units); + const terrain_filter t_filter(filter, resources::filter_con); t_filter.get_locations(res, true); lua_createtable(L, res.size(), 0); @@ -3195,7 +3196,7 @@ static int intf_get_villages(lua_State *L) vconfig filter = luaW_checkvconfig(L, 1); for(std::vector::const_iterator it = locs.begin(); it != locs.end(); ++it) { - bool matches = terrain_filter(filter, *resources::units).match(*it); + bool matches = terrain_filter(filter, resources::filter_con).match(*it); if (matches) { lua_createtable(L, 2, 0); lua_pushinteger(L, it->x + 1); @@ -3226,7 +3227,7 @@ static int intf_match_location(lua_State *L) return 1; } - const terrain_filter t_filter(filter, *resources::units); + const terrain_filter t_filter(filter, resources::filter_con); lua_pushboolean(L, t_filter.match(map_location(x, y))); return 1; } diff --git a/src/terrain_filter.cpp b/src/terrain_filter.cpp index d8c05221adc1..3a429425ff89 100644 --- a/src/terrain_filter.cpp +++ b/src/terrain_filter.cpp @@ -17,10 +17,11 @@ #include "global.hpp" #include "config.hpp" +#include "display_context.hpp" +#include "filter_context.hpp" #include "game_board.hpp" #include "log.hpp" #include "map.hpp" -#include "resources.hpp" #include "side_filter.hpp" #include "team.hpp" #include "terrain_filter.hpp" @@ -46,7 +47,7 @@ terrain_filter::~terrain_filter() #pragma warning(disable:4413) terrain_filter::terrain_filter(): cfg_(vconfig::unconstructed_vconfig()), - units_(unit_map()), + fc_(NULL), cache_(), max_loop_(), flat_() @@ -57,10 +58,10 @@ terrain_filter::terrain_filter(): #endif -terrain_filter::terrain_filter(const vconfig& cfg, const unit_map& units, +terrain_filter::terrain_filter(const vconfig& cfg, const filter_context * fc, const bool flat_tod, const size_t max_loop) : cfg_(cfg), - units_(units), + fc_(fc), cache_(), max_loop_(max_loop), flat_(flat_tod) @@ -69,7 +70,7 @@ terrain_filter::terrain_filter(const vconfig& cfg, const unit_map& units, terrain_filter::terrain_filter(const vconfig& cfg, const terrain_filter& original) : cfg_(cfg), - units_(original.units_), + fc_(original.fc_), cache_(), max_loop_(original.max_loop_), flat_(original.flat_) @@ -80,7 +81,7 @@ terrain_filter::terrain_filter(const terrain_filter& other) : xy_pred(), // We should construct this too, since it has no datamembers // use the default constructor. cfg_(other.cfg_), - units_(other.units_), + fc_(other.fc_), cache_(), max_loop_(other.max_loop_), flat_(other.flat_) @@ -109,7 +110,7 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x { //Filter Areas if (cfg_.has_attribute("area") && - resources::tod_manager->get_area_by_id(cfg_["area"]).count(loc) == 0) + fc_->get_tod_man().get_area_by_id(cfg_["area"]).count(loc) == 0) return false; if(cfg_.has_attribute("terrain")) { @@ -117,7 +118,7 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x cache_.parsed_terrain = new t_translation::t_match(cfg_["terrain"]); } if(!cache_.parsed_terrain->is_empty) { - const t_translation::t_terrain letter = resources::gameboard->map().get_terrain_info(loc).number(); + const t_translation::t_terrain letter = fc_->get_disp_context().map().get_terrain_info(loc).number(); if(!t_translation::terrain_matches(letter, *cache_.parsed_terrain)) { return false; } @@ -153,8 +154,8 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x //Allow filtering on unit if(cfg_.has_child("filter")) { const vconfig& unit_filter = cfg_.child("filter"); - const unit_map::const_iterator u = units_.find(loc); - if (u == units_.end() || !unit_filter::matches_filter(unit_filter, *u, loc, resources::filter_con, flat_)) + const unit_map::const_iterator u = fc_->get_disp_context().units().find(loc); + if (u == fc_->get_disp_context().units().end() || !unit_filter::matches_filter(unit_filter, *u, loc, fc_, flat_)) return false; } @@ -166,11 +167,11 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x bool visible = (*i)["visible"].to_bool(true); bool respect_fog = (*i)["respect_fog"].to_bool(true); - side_filter ssf(*i, resources::filter_con); + side_filter ssf(*i, fc_); std::vector sides = ssf.get_teams(); BOOST_FOREACH(const int side, sides) { - const team &viewing_team = resources::teams->at(side - 1); + const team &viewing_team = fc_->get_disp_context().teams().at(side - 1); bool viewer_sees = respect_fog ? !viewing_team.fogged(loc) : !viewing_team.shrouded(loc); if (visible != viewer_sees) { return false; @@ -193,7 +194,7 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x std::vector::const_iterator j, j_end = dirs.end(); for (j = dirs.begin(); j != j_end; ++j) { map_location &adj = adjacent[*j]; - if (resources::gameboard->map().on_board(adj)) { + if (fc_->get_disp_context().map().on_board(adj)) { if(cache_.adjacent_matches == NULL) { while(index >= std::distance(cache_.adjacent_match_cache.begin(), cache_.adjacent_match_cache.end())) { const vconfig& adj_cfg = adj_cfgs[cache_.adjacent_match_cache.size()]; @@ -242,9 +243,9 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x time_of_day tod; if(flat_) { - tod = resources::tod_manager->get_time_of_day(loc); + tod = fc_->get_tod_man().get_time_of_day(loc); } else { - tod = resources::tod_manager->get_illuminated_time_of_day(resources::gameboard->units(), resources::gameboard->map(),loc); + tod = fc_->get_tod_man().get_illuminated_time_of_day(fc_->get_disp_context().units(), fc_->get_disp_context().map(),loc); } if(!tod_type.empty()) { @@ -285,15 +286,15 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x if(!owner_side.empty()) { WRN_NG << "duplicate side information in a SLF, ignoring inline owner_side=" << std::endl; } - if(!resources::gameboard->map().is_village(loc)) + if(!fc_->get_disp_context().map().is_village(loc)) return false; - side_filter ssf(filter_owner, resources::filter_con); + side_filter ssf(filter_owner, fc_); const std::vector& sides = ssf.get_teams(); bool found = false; - if(sides.empty() && resources::gameboard->village_owner(loc) == -1) + if(sides.empty() && fc_->get_disp_context().village_owner(loc) == -1) found = true; BOOST_FOREACH(const int side, sides) { - if(resources::teams->at(side - 1).owns_village(loc)) { + if(fc_->get_disp_context().teams().at(side - 1).owns_village(loc)) { found = true; break; } @@ -303,7 +304,7 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x } else if(!owner_side.empty()) { const int side_index = owner_side.to_int(0) - 1; - if(resources::gameboard->village_owner(loc) != side_index) { + if(fc_->get_disp_context().village_owner(loc) != side_index) { return false; } } @@ -314,7 +315,7 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x bool terrain_filter::match(const map_location& loc) const { if(cfg_["x"] == "recall" && cfg_["y"] == "recall") { - return !resources::gameboard->map().on_board(loc); + return !fc_->get_disp_context().map().on_board(loc); } std::set hexes; std::vector loc_vec(1, loc); @@ -330,9 +331,9 @@ bool terrain_filter::match(const map_location& loc) const hexes.insert(loc_vec.begin(), loc_vec.end()); else if ( cfg_.has_child("filter_radius") ) { terrain_filter r_filter(cfg_.child("filter_radius"), *this); - get_tiles_radius(resources::gameboard->map(), loc_vec, radius, hexes, false, r_filter); + get_tiles_radius(fc_->get_disp_context().map(), loc_vec, radius, hexes, false, r_filter); } else { - get_tiles_radius(resources::gameboard->map(), loc_vec, radius, hexes); + get_tiles_radius(fc_->get_disp_context().map(), loc_vec, radius, hexes); } size_t loop_count = 0; @@ -390,9 +391,9 @@ void terrain_filter::get_locations(std::set& locs, bool with_borde && !cfg_.has_attribute("area") ) { //consider all locations on the map - int bs = resources::gameboard->map().border_size(); - int w = with_border ? resources::gameboard->map().w() + bs : resources::gameboard->map().w(); - int h = with_border ? resources::gameboard->map().h() + bs : resources::gameboard->map().h(); + 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) { match_set.insert(map_location(x,y)); @@ -406,7 +407,7 @@ void terrain_filter::get_locations(std::set& locs, bool with_borde && !cfg_.has_attribute("area") ) { std::vector xy_vector; - xy_vector = resources::gameboard->map().parse_location_range(cfg_["x"], cfg_["y"], with_border); + xy_vector = fc_->get_disp_context().map().parse_location_range(cfg_["x"], cfg_["y"], with_border); match_set.insert(xy_vector.begin(), xy_vector.end()); } else @@ -435,7 +436,7 @@ void terrain_filter::get_locations(std::set& locs, bool with_borde && !cfg_.has_attribute("find_in") && cfg_.has_attribute("area") ) { - const std::set& area = resources::tod_manager->get_area_by_id(cfg_["area"]); + const std::set& area = fc_->get_tod_man().get_area_by_id(cfg_["area"]); match_set.insert(area.begin(), area.end()); } else @@ -445,7 +446,7 @@ void terrain_filter::get_locations(std::set& locs, bool with_borde && !cfg_.has_attribute("area") ) { std::vector xy_vector; - xy_vector = resources::gameboard->map().parse_location_range(cfg_["x"], cfg_["y"], with_border); + xy_vector = fc_->get_disp_context().map().parse_location_range(cfg_["x"], cfg_["y"], with_border); match_set.insert(xy_vector.begin(), xy_vector.end()); // remove any locations not found in the specified variable @@ -478,8 +479,8 @@ void terrain_filter::get_locations(std::set& locs, bool with_borde && cfg_.has_attribute("area") ) { std::vector xy_vector; - xy_vector = resources::gameboard->map().parse_location_range(cfg_["x"], cfg_["y"], with_border); - const std::set& area = resources::tod_manager->get_area_by_id(cfg_["area"]); + xy_vector = fc_->get_disp_context().map().parse_location_range(cfg_["x"], cfg_["y"], with_border); + const std::set& area = fc_->get_tod_man().get_area_by_id(cfg_["area"]); BOOST_FOREACH(const map_location& loc, xy_vector) { if (area.count(loc) != 0) @@ -492,7 +493,7 @@ void terrain_filter::get_locations(std::set& locs, bool with_borde && cfg_.has_attribute("find_in") && cfg_.has_attribute("area") ) { - const std::set& area = resources::tod_manager->get_area_by_id(cfg_["area"]); + const std::set& area = fc_->get_tod_man().get_area_by_id(cfg_["area"]); //use content of find_in as starting set variable_info vi(cfg_["find_in"], false, variable_info::TYPE_CONTAINER); @@ -517,10 +518,10 @@ void terrain_filter::get_locations(std::set& locs, bool with_borde && cfg_.has_attribute("area") ) { const std::vector& xy_vector = - resources::gameboard->map().parse_location_range(cfg_["x"], cfg_["y"], with_border); + fc_->get_disp_context().map().parse_location_range(cfg_["x"], cfg_["y"], with_border); std::set xy_set(xy_vector.begin(), xy_vector.end()); - const std::set& area = resources::tod_manager->get_area_by_id(cfg_["area"]); + const std::set& area = fc_->get_tod_man().get_area_by_id(cfg_["area"]); //use content of find_in as starting set variable_info vi(cfg_["find_in"], false, variable_info::TYPE_CONTAINER); @@ -630,9 +631,9 @@ void terrain_filter::get_locations(std::set& locs, bool with_borde std::vector 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(resources::gameboard->map(), xy_vector, radius, locs, with_border, r_filter); + get_tiles_radius(fc_->get_disp_context().map(), xy_vector, radius, locs, with_border, r_filter); } else { - get_tiles_radius(resources::gameboard->map(), xy_vector, radius, locs, with_border); + get_tiles_radius(fc_->get_disp_context().map(), xy_vector, radius, locs, with_border); } } else { locs.insert(match_set.begin(), match_set.end()); diff --git a/src/terrain_filter.hpp b/src/terrain_filter.hpp index 864c3b2429c2..3f3039cbb92e 100644 --- a/src/terrain_filter.hpp +++ b/src/terrain_filter.hpp @@ -21,6 +21,7 @@ #include "variable.hpp" class config; +class filter_context; class unit; class unit_map; class team; @@ -37,7 +38,7 @@ class terrain_filter : public xy_pred { #endif terrain_filter(const vconfig& cfg, - const unit_map& units, const bool flat_tod=false, const size_t max_loop=game_config::max_loop); + const filter_context * fc, const bool flat_tod=false, const size_t max_loop=game_config::max_loop); terrain_filter(const vconfig& cfg, const terrain_filter& original); /** Default implementation, but defined out-of-line for efficiency reasons. */ ~terrain_filter(); @@ -66,7 +67,7 @@ class terrain_filter : public xy_pred { bool match_internal(const map_location& loc, const bool ignore_xy) const; const vconfig cfg_; //config contains WML for a Standard Location Filter - const unit_map& units_; + const filter_context * fc_; struct terrain_filter_cache { terrain_filter_cache() : diff --git a/src/unit_abilities.cpp b/src/unit_abilities.cpp index c7a54357f3b8..7a02686f3104 100644 --- a/src/unit_abilities.cpp +++ b/src/unit_abilities.cpp @@ -328,7 +328,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), units); + terrain_filter adj_filter(vconfig(i), resources::filter_con); adj_filter.flatten(illuminates); if(!adj_filter.match(adjacent[index])) { return false; @@ -898,7 +898,7 @@ bool attack_type::special_active(const config& special, AFFECTS whom, map_location::parse_direction(j); if (index == map_location::NDIRECTIONS) continue; - terrain_filter adj_filter(vconfig(i), units); + terrain_filter adj_filter(vconfig(i), resources::filter_con); if(!adj_filter.match(adjacent[index])) { return false; } diff --git a/src/unit_display.cpp b/src/unit_display.cpp index d61e5d0dfb34..1a46437d3a5b 100644 --- a/src/unit_display.cpp +++ b/src/unit_display.cpp @@ -827,7 +827,7 @@ void wml_animation_internal(unit_animator &animator, const vconfig &cfg, const m vconfig t_filter = cfg.child("facing"); map_location secondary_loc = map_location::null_location(); if(!t_filter.empty()) { - terrain_filter filter(t_filter, *resources::units); + terrain_filter filter(t_filter, resources::filter_con); std::set locs; filter.get_locations(locs); if (!locs.empty() && u->get_location() != *locs.begin()) { diff --git a/src/unit_filter.cpp b/src/unit_filter.cpp index 488d5e5b754a..492c4f105e97 100644 --- a/src/unit_filter.cpp +++ b/src/unit_filter.cpp @@ -117,7 +117,7 @@ bool internal_matches_filter(const vconfig& cfg, const unit & u, const map_locat if(cfg.has_child("filter_location")) { assert(fc != NULL); const vconfig& t_cfg = cfg.child("filter_location"); - terrain_filter t_filter(t_cfg, fc->get_disp_context().units(), use_flat_tod); + terrain_filter t_filter(t_cfg, fc, use_flat_tod); if(!t_filter.match(loc)) { return false; }