Skip to content

Commit

Permalink
terrain_filter uses filter_context instead of resources
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jul 3, 2014
1 parent 35b23ec commit 18159f0
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 60 deletions.
5 changes: 3 additions & 2 deletions src/ai/composite/goal.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -165,7 +166,7 @@ void target_location_goal::on_create()
}
const config &criteria = cfg_.child("criteria");
if (criteria) {
filter_ptr_ = boost::shared_ptr<terrain_filter>(new terrain_filter(vconfig(criteria),*resources::units));
filter_ptr_ = boost::shared_ptr<terrain_filter>(new terrain_filter(vconfig(criteria),resources::filter_con));
}
}

Expand Down Expand Up @@ -221,7 +222,7 @@ void protect_goal::on_create()
}
const config &criteria = cfg_.child("criteria");
if (criteria) {
filter_ptr_ = boost::shared_ptr<terrain_filter>(new terrain_filter(vconfig(criteria),*resources::units));
filter_ptr_ = boost::shared_ptr<terrain_filter>(new terrain_filter(vconfig(criteria),resources::filter_con));
}


Expand Down
6 changes: 3 additions & 3 deletions src/ai/composite/value_translator.hpp
Expand Up @@ -179,10 +179,10 @@ class config_value_translator<terrain_filter> {
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)
Expand Down Expand Up @@ -442,7 +442,7 @@ class variant_value_translator<terrain_filter> {
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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ai/contexts.cpp
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ai/lua/lua_object.hpp
Expand Up @@ -138,7 +138,7 @@ inline boost::shared_ptr<terrain_filter> lua_object<terrain_filter>::to_type(lua
boost::shared_ptr<config> cfg = boost::shared_ptr<config>(new config());
boost::shared_ptr<vconfig> vcfg = boost::shared_ptr<vconfig>(new vconfig(*cfg));
luaW_tovconfig(L, n, *vcfg);
boost::shared_ptr<terrain_filter> tf = boost::shared_ptr<terrain_filter>(new terrain_filter(*vcfg, *resources::units));
boost::shared_ptr<terrain_filter> tf = boost::shared_ptr<terrain_filter>(new terrain_filter(*vcfg, resources::filter_con));
return tf;
}

Expand Down
6 changes: 3 additions & 3 deletions src/game_events/action_wml.cpp
Expand Up @@ -449,7 +449,7 @@ namespace { // Support functions

// Filter the locations.
std::set<map_location> 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.
Expand Down Expand Up @@ -485,7 +485,7 @@ namespace { // Support functions

// Filter the locations.
std::set<map_location> 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)
Expand Down Expand Up @@ -2398,7 +2398,7 @@ WML_HANDLER_FUNCTION(time_area, /*event_info*/, cfg)
id = ids;
}
std::set<map_location> 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);
Expand Down
2 changes: 1 addition & 1 deletion src/game_events/conditional_wml.cpp
Expand Up @@ -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<map_location> res;
terrain_filter(*v, *resources::units).get_locations(res);
terrain_filter(*v, resources::filter_con).get_locations(res);

std::vector<std::pair<int,int> > counts = (*v).has_attribute("count")
? utils::parse_ranges((*v)["count"]) : default_counts;
Expand Down
2 changes: 1 addition & 1 deletion src/game_events/menu_item.cpp
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/pathfind/teleport.cpp
Expand Up @@ -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);
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/scripting/lua.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -3163,7 +3164,7 @@ static int intf_get_locations(lua_State *L)
vconfig filter = luaW_checkvconfig(L, 1);

std::set<map_location> 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);
Expand Down Expand Up @@ -3195,7 +3196,7 @@ static int intf_get_villages(lua_State *L)
vconfig filter = luaW_checkvconfig(L, 1);

for(std::vector<map_location>::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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 18159f0

Please sign in to comment.