From 47e9a3d25d2bd80ec824799f7d1881558d388236 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Sat, 5 Jul 2014 21:37:01 -0400 Subject: [PATCH] lua find_cost_map fcn uses unit_filter::all_matches_on_map fcn --- src/scripting/lua.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 064b4bba58ba..3de38dfd86c0 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1992,6 +1992,12 @@ static int intf_find_reach(lua_State *L) return 1; } +#ifdef HAVE_CXX11 +static bool intf_find_cost_map_helper(const unit * ptr) { + return ptr->get_location().valid(); +} +#endif + /** * Is called with one or more units and builds a cost map. * - Args 1,2: source location. (Or Arg 1: unit. Or Arg 1: table containing a filter) @@ -2018,17 +2024,18 @@ static int intf_find_cost_map(lua_State *L) } else if (!filter.null()) // 1. arg - filter { - unit_map &units = *resources::units; const unit_filter ufilt(filter, resources::filter_con); - for (unit_map::const_unit_iterator ui = units.begin(), ui_end = units.end(); - ui != ui_end; ++ui) - { - bool on_map = ui->get_location().valid(); - if (on_map && ufilt(*ui)) - { - real_units. push_back(&(*ui)); + + #ifdef HAVE_CXX11 + std::vector matches = ufilt.all_matches_on_map(); + std::copy_if(matches.begin(), matches.end(), std::back_inserter(real_units), &intf_find_cost_map_helper); + #else + BOOST_FOREACH(const unit * u, ufilt.all_matches_on_map()) { + if (u->get_location().valid()) { + real_units.push_back(u); } } + #endif } else // 1. + 2. arg - coordinates {