aboutsummaryrefslogtreecommitdiff
path: root/src/game/Unit.h
diff options
context:
space:
mode:
authorXanadu <none@none>2010-05-30 04:23:27 +0200
committerXanadu <none@none>2010-05-30 04:23:27 +0200
commit7fbeef3d09dac072aec046519a90d95f0572fcf6 (patch)
tree9808843d603e64ef863e823c89b764d0bab8dcf1 /src/game/Unit.h
parent14382dd1fe74c500d26b597e8de1498dcc30da68 (diff)
Cleaned up and unified various sort predicates and moved them to Trinity namespace, replaced priority queues with sorts and purged some unused code.
--HG-- branch : trunk
Diffstat (limited to 'src/game/Unit.h')
-rw-r--r--src/game/Unit.h53
1 files changed, 29 insertions, 24 deletions
diff --git a/src/game/Unit.h b/src/game/Unit.h
index 980e481e8d5..567fba03370 100644
--- a/src/game/Unit.h
+++ b/src/game/Unit.h
@@ -2083,31 +2083,36 @@ class Unit : public WorldObject
namespace Trinity
{
- template<class T>
- void RandomResizeList(std::list<T> &_list, uint32 _size)
+ // Binary predicate for sorting Units based on percent value of a power
+ class PowerPctOrderPred
{
- while (_list.size() > _size)
- {
- typename std::list<T>::iterator itr = _list.begin();
- advance(itr, urand(0, _list.size() - 1));
- _list.erase(itr);
- }
- }
-}
-
-// binary function to sort unit based on the distance to a reference unit
-struct TargetDistanceOrder : public std::binary_function<const Unit *, const Unit *, bool>
-{
- const Unit *me;
-
- // pUnit: the reference unit from which the distance is computed.
- TargetDistanceOrder(const Unit* pUnit) : me(pUnit) {};
-
- // functor for operator "<"
- bool operator()(const Unit* left, const Unit* right) const
+ public:
+ PowerPctOrderPred(Powers power, bool ascending = true) : m_power(power), m_ascending(ascending) {}
+ bool operator() (const Unit *a, const Unit *b) const
+ {
+ float rA = a->GetMaxPower(m_power) ? float(a->GetPower(m_power)) / float(a->GetMaxPower(m_power)) : 0.0f;
+ float rB = b->GetMaxPower(m_power) ? float(b->GetPower(m_power)) / float(b->GetMaxPower(m_power)) : 0.0f;
+ return m_ascending ? rA < rB : rA > rB;
+ }
+ private:
+ const Powers m_power;
+ const bool m_ascending;
+ };
+
+ // Binary predicate for sorting Units based on percent value of health
+ class HealthPctOrderPred
{
- return (me->GetExactDistSq(left) < me->GetExactDistSq(right));
- }
-};
+ public:
+ HealthPctOrderPred(bool ascending = true) : m_ascending(ascending) {}
+ bool operator() (const Unit *a, const Unit *b) const
+ {
+ float rA = a->GetMaxHealth() ? float(a->GetHealth()) / float(a->GetMaxHealth()) : 0.0f;
+ float rB = b->GetMaxHealth() ? float(b->GetHealth()) / float(b->GetMaxHealth()) : 0.0f;
+ return m_ascending ? rA < rB : rA > rB;
+ }
+ private:
+ const bool m_ascending;
+ };
+}
#endif