X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frangecondition.h;h=a72fec2d1475db075baffbeb1ed46aa3979480e0;hb=746329e61ac9f26962af740b0b11dee716803521;hp=beba0dddbced73c49fa28273e25d43720bbacd9d;hpb=eac6a71e79797e6d37b620a91acb3c0541f1c07e;p=poefilter.git diff --git a/source/rangecondition.h b/source/rangecondition.h index beba0dd..a72fec2 100644 --- a/source/rangecondition.h +++ b/source/rangecondition.h @@ -21,7 +21,7 @@ public: virtual RangeCondition *clone() const; virtual bool can_merge(const Condition &, const CompoundCondition &) const; - virtual RangeCondition *merge(const std::vector &, const CompoundCondition &) const; + virtual RangeCondition *merge(const std::vector &, const CompoundCondition &) const; virtual bool is_viable() const { return min<=max; } virtual void add_lines(std::list &) const; }; @@ -52,7 +52,7 @@ typedef RangeCondition QualityCondition; struct ItemLevelTraits { typedef unsigned Type; - static unsigned get_min() { return 0; } + static unsigned get_min() { return 1; } static unsigned get_max() { return 100; } static const char *get_keyword() { return "ItemLevel"; } }; @@ -63,7 +63,7 @@ typedef RangeCondition ItemLevelCondition; struct DropLevelTraits { typedef unsigned Type; - static unsigned get_min() { return 0; } + static unsigned get_min() { return 1; } static unsigned get_max() { return 100; } static const char *get_keyword() { return "DropLevel"; } }; @@ -136,25 +136,45 @@ RangeCondition *RangeCondition::clone() const template bool RangeCondition::can_merge(const Condition &other, const CompoundCondition &parent) const { - return dynamic_cast *>(&other) && dynamic_cast(&parent); + const RangeCondition *other_range = dynamic_cast *>(&other); + if(!other_range) + return false; + + if(dynamic_cast(&parent)) + return true; + else if(dynamic_cast(&parent)) + return min<=other_range->max+1 && max+1>=other_range->min; + else + return false; } template -RangeCondition *RangeCondition::merge(const std::vector &conditions, const CompoundCondition &parent) const +RangeCondition *RangeCondition::merge(const std::vector &conditions, const CompoundCondition &parent) const { - if(dynamic_cast(&parent) && !conditions.empty()) + if(conditions.empty()) + return 0; + + bool intersect = dynamic_cast(&parent); + RangeCondition *result; + if(intersect) + result = new RangeCondition(Traits::get_min(), Traits::get_max()); + else + result = new RangeCondition(Traits::get_max(), Traits::get_min()); + for(std::vector::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) { - RangeCondition *result = new RangeCondition(Traits::get_min(), Traits::get_max()); - for(std::vector::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) + const RangeCondition *c = static_cast *>(*i); + if(intersect) { - const RangeCondition *c = static_cast *>(*i); result->min = std::max(result->min, c->min); result->max = std::min(result->max, c->max); } - return result; + else + { + result->min = std::min(result->min, c->min); + result->max = std::max(result->max, c->max); + } } - else - return 0; + return result; } template