diff --git a/src/side_filter.cpp b/src/side_filter.cpp index fd2b3f3f416..e73022f9fc0 100644 --- a/src/side_filter.cpp +++ b/src/side_filter.cpp @@ -71,16 +71,7 @@ std::vector side_filter::get_teams() const static bool check_side_number(const team &t, const std::string &str) { - std::vector> ranges = utils::parse_ranges_unsigned(str); - int side_number = t.side(); - - std::vector>::const_iterator range, range_end = ranges.end(); - for (range = ranges.begin(); range != range_end; ++range) { - if(side_number >= range->first && side_number <= range->second) { - return true; - } - } - return false; + return in_ranges(t.side(), utils::parse_ranges_unsigned(str)); } bool side_filter::match_internal(const team &t) const diff --git a/src/units/filter.cpp b/src/units/filter.cpp index d8edbe9434c..aa8fb627434 100644 --- a/src/units/filter.cpp +++ b/src/units/filter.cpp @@ -604,12 +604,7 @@ void unit_filter_compound::fill(vconfig cfg) [](const config::attribute_value& c) { return utils::parse_ranges_unsigned(c.str()); }, [](const std::vector>& ranges, const unit_filter_args& args) { - for(auto cost : ranges) { - if(cost.first <= args.u.recall_cost() && args.u.recall_cost() <= cost.second) { - return true; - } - } - return false; + return in_ranges(args.u.recall_cost(), ranges); } ); @@ -617,12 +612,7 @@ void unit_filter_compound::fill(vconfig cfg) [](const config::attribute_value& c) { return utils::parse_ranges_unsigned(c.str()); }, [](const std::vector>& ranges, const unit_filter_args& args) { - for(auto lvl : ranges) { - if(lvl.first <= args.u.level() && args.u.level() <= lvl.second) { - return true; - } - } - return false; + return in_ranges(args.u.level(), ranges); } ); @@ -631,12 +621,7 @@ void unit_filter_compound::fill(vconfig cfg) [](const std::vector>& ranges, const unit_filter_args& args) { int actual_defense = args.u.defense_modifier(args.context().get_disp_context().map().get_terrain(args.loc)); - for(auto def : ranges) { - if(def.first <= actual_defense && actual_defense <= def.second) { - return true; - } - } - return false; + return in_ranges(actual_defense, ranges); } ); @@ -645,12 +630,7 @@ void unit_filter_compound::fill(vconfig cfg) [](const std::vector>& ranges, const unit_filter_args& args) { int actual_cost = args.u.movement_cost(args.context().get_disp_context().map().get_terrain(args.loc)); - for(auto cost : ranges) { - if(cost.first <= actual_cost && actual_cost <= cost.second) { - return true; - } - } - return false; + return in_ranges(actual_cost, ranges); } ); @@ -659,12 +639,7 @@ void unit_filter_compound::fill(vconfig cfg) [](const std::vector>& ranges, const unit_filter_args& args) { int actual_cost = args.u.vision_cost(args.context().get_disp_context().map().get_terrain(args.loc)); - for(auto cost : ranges) { - if(cost.first <= actual_cost && actual_cost <= cost.second) { - return true; - } - } - return false; + return in_ranges(actual_cost, ranges); } ); @@ -673,12 +648,7 @@ void unit_filter_compound::fill(vconfig cfg) [](const std::vector>& ranges, const unit_filter_args& args) { int actual_cost = args.u.jamming_cost(args.context().get_disp_context().map().get_terrain(args.loc)); - for(auto cost : ranges) { - if(cost.first <= actual_cost && actual_cost <= cost.second) { - return true; - } - } - return false; + return in_ranges(actual_cost, ranges); } );