mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-15 23:34:01 +00:00
Simplify WML filter checks with in_ranges (closes #9083)
We don't want the main change from that PR, but we do want the cleanup.
This commit is contained in:
parent
cce8c7a410
commit
6625aa42d2
|
@ -71,16 +71,7 @@ std::vector<int> side_filter::get_teams() const
|
|||
|
||||
static bool check_side_number(const team &t, const std::string &str)
|
||||
{
|
||||
std::vector<std::pair<int,int>> ranges = utils::parse_ranges_unsigned(str);
|
||||
int side_number = t.side();
|
||||
|
||||
std::vector<std::pair<int,int>>::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
|
||||
|
|
|
@ -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<std::pair<int,int>>& 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<std::pair<int,int>>& 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<std::pair<int,int>>& 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<std::pair<int,int>>& 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<std::pair<int,int>>& 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<std::pair<int,int>>& 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);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user