aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOvahlord <dreadkiller@gmx.de>2024-01-16 20:18:25 +0100
committerfunjoker <funjoker109@gmail.com>2024-01-29 21:46:45 +0100
commit8b6a1db20215ba54a43789c0f809152855fd2fbc (patch)
treeca948903670a0c61fac9ce6fa195dd5b6c1989d9
parent6be53574f81bc2f6705ef2b57487addd2127cea5 (diff)
Core/Units: moved health and power ordering predicates from Unit header into CommonPredicates (#29584)
(cherry picked from commit 2f6ed2c203b16a1d1e85f61a8b8e2cf3d1a4e784)
-rw-r--r--src/server/game/Entities/Unit/Unit.h56
-rw-r--r--src/server/game/Miscellaneous/CommonPredicates.cpp32
-rw-r--r--src/server/game/Miscellaneous/CommonPredicates.h29
-rw-r--r--src/server/scripts/Spells/spell_generic.cpp3
-rw-r--r--src/server/scripts/Spells/spell_item.cpp3
-rw-r--r--src/server/scripts/Spells/spell_paladin.cpp3
6 files changed, 67 insertions, 59 deletions
diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h
index 847e594b99c..b519213504a 100644
--- a/src/server/game/Entities/Unit/Unit.h
+++ b/src/server/game/Entities/Unit/Unit.h
@@ -1948,60 +1948,4 @@ class TC_GAME_API Unit : public WorldObject
bool _isCombatDisallowed;
};
-namespace Trinity
-{
- // Binary predicate for sorting Units based on percent value of a power
- class PowerPctOrderPred
- {
- public:
- PowerPctOrderPred(Powers power, bool ascending = true) : _power(power), _ascending(ascending) { }
-
- bool operator()(WorldObject const* objA, WorldObject const* objB) const
- {
- Unit const* a = objA->ToUnit();
- Unit const* b = objB->ToUnit();
- float rA = a ? a->GetPowerPct(_power) : 0.0f;
- float rB = b ? b->GetPowerPct(_power) : 0.0f;
- return _ascending ? rA < rB : rA > rB;
- }
-
- bool operator()(Unit const* a, Unit const* b) const
- {
- float rA = a->GetPowerPct(_power);
- float rB = b->GetPowerPct(_power);
- return _ascending ? rA < rB : rA > rB;
- }
-
- private:
- Powers const _power;
- bool const _ascending;
- };
-
- // Binary predicate for sorting Units based on percent value of health
- class HealthPctOrderPred
- {
- public:
- HealthPctOrderPred(bool ascending = true) : _ascending(ascending) { }
-
- bool operator()(WorldObject const* objA, WorldObject const* objB) const
- {
- Unit const* a = objA->ToUnit();
- Unit const* b = objB->ToUnit();
- float rA = (a && a->GetMaxHealth()) ? float(a->GetHealth()) / float(a->GetMaxHealth()) : 0.0f;
- float rB = (b && b->GetMaxHealth()) ? float(b->GetHealth()) / float(b->GetMaxHealth()) : 0.0f;
- return _ascending ? rA < rB : rA > rB;
- }
-
- bool operator() (Unit const* a, Unit const* 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 _ascending ? rA < rB : rA > rB;
- }
-
- private:
- bool const _ascending;
- };
-}
-
#endif
diff --git a/src/server/game/Miscellaneous/CommonPredicates.cpp b/src/server/game/Miscellaneous/CommonPredicates.cpp
index 834985b0a34..3ecbd776ff6 100644
--- a/src/server/game/Miscellaneous/CommonPredicates.cpp
+++ b/src/server/game/Miscellaneous/CommonPredicates.cpp
@@ -19,3 +19,35 @@
#include "Unit.h"
Trinity::Predicates::IsVictimOf::IsVictimOf(Unit const* attacker) : _victim(attacker ? attacker->GetVictim() : nullptr) { }
+
+bool Trinity::Predicates::PowerPctOrderPred::operator()(WorldObject const* objA, WorldObject const* objB) const
+{
+ Unit const* a = objA->ToUnit();
+ Unit const* b = objB->ToUnit();
+ float rA = a ? a->GetPowerPct(_power) : 0.0f;
+ float rB = b ? b->GetPowerPct(_power) : 0.0f;
+ return _ascending ? rA < rB : rA > rB;
+}
+
+bool Trinity::Predicates::PowerPctOrderPred::operator()(Unit const* a, Unit const* b) const
+{
+ float rA = a->GetPowerPct(_power);
+ float rB = b->GetPowerPct(_power);
+ return _ascending ? rA < rB : rA > rB;
+}
+
+bool Trinity::Predicates::HealthPctOrderPred::operator()(WorldObject const* objA, WorldObject const* objB) const
+{
+ Unit const* a = objA->ToUnit();
+ Unit const* b = objB->ToUnit();
+ float rA = (a && a->GetMaxHealth()) ? float(a->GetHealth()) / float(a->GetMaxHealth()) : 0.0f;
+ float rB = (b && b->GetMaxHealth()) ? float(b->GetHealth()) / float(b->GetMaxHealth()) : 0.0f;
+ return _ascending ? rA < rB : rA > rB;
+}
+
+bool Trinity::Predicates::HealthPctOrderPred::operator()(Unit const* a, Unit const* 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 _ascending ? rA < rB : rA > rB;
+}
diff --git a/src/server/game/Miscellaneous/CommonPredicates.h b/src/server/game/Miscellaneous/CommonPredicates.h
index 54040245972..f450c2e33f7 100644
--- a/src/server/game/Miscellaneous/CommonPredicates.h
+++ b/src/server/game/Miscellaneous/CommonPredicates.h
@@ -24,6 +24,8 @@
class Unit;
class WorldObject;
+enum Powers : int8;
+
namespace Trinity
{
namespace Predicates
@@ -38,6 +40,33 @@ namespace Trinity
WorldObject const* _victim;
};
+ /// Binary predicate for sorting Units based on percent value of a power
+ class TC_GAME_API PowerPctOrderPred
+ {
+ public:
+ PowerPctOrderPred(Powers power, bool ascending = true) : _power(power), _ascending(ascending) { }
+
+ bool operator()(WorldObject const* objA, WorldObject const* objB) const;
+ bool operator()(Unit const* a, Unit const* b) const;
+
+ private:
+ Powers const _power;
+ bool const _ascending;
+ };
+
+ /// Binary predicate for sorting Units based on percent value of health
+ class TC_GAME_API HealthPctOrderPred
+ {
+ public:
+ HealthPctOrderPred(bool ascending = true) : _ascending(ascending) { }
+
+ bool operator()(WorldObject const* objA, WorldObject const* objB) const;
+ bool operator() (Unit const* a, Unit const* b) const;
+
+ private:
+ bool const _ascending;
+ };
+
template <typename PRED>
class TC_GAME_API Inverter
{
diff --git a/src/server/scripts/Spells/spell_generic.cpp b/src/server/scripts/Spells/spell_generic.cpp
index 58a5770b025..58a81103a16 100644
--- a/src/server/scripts/Spells/spell_generic.cpp
+++ b/src/server/scripts/Spells/spell_generic.cpp
@@ -26,6 +26,7 @@
#include "Battleground.h"
#include "BattlePetMgr.h"
#include "CellImpl.h"
+#include "CommonPredicates.h"
#include "Containers.h"
#include "CreatureAI.h"
#include "DB2Stores.h"
@@ -2991,7 +2992,7 @@ class spell_gen_replenishment : public SpellScript
if (targets.size() > maxTargets)
{
- targets.sort(Trinity::PowerPctOrderPred(POWER_MANA));
+ targets.sort(Trinity::Predicates::PowerPctOrderPred(POWER_MANA));
targets.resize(maxTargets);
}
}
diff --git a/src/server/scripts/Spells/spell_item.cpp b/src/server/scripts/Spells/spell_item.cpp
index d65c4015c9a..0c687dc36c1 100644
--- a/src/server/scripts/Spells/spell_item.cpp
+++ b/src/server/scripts/Spells/spell_item.cpp
@@ -23,6 +23,7 @@
#include "ScriptMgr.h"
#include "Battleground.h"
+#include "CommonPredicates.h"
#include "Containers.h"
#include "Creature.h"
#include "CreatureAIImpl.h"
@@ -995,7 +996,7 @@ class spell_item_echoes_of_light : public SpellScript
if (targets.size() < 2)
return;
- targets.sort(Trinity::HealthPctOrderPred());
+ targets.sort(Trinity::Predicates::HealthPctOrderPred());
WorldObject* target = targets.front();
targets.clear();
diff --git a/src/server/scripts/Spells/spell_paladin.cpp b/src/server/scripts/Spells/spell_paladin.cpp
index 53cda732603..c16a8741558 100644
--- a/src/server/scripts/Spells/spell_paladin.cpp
+++ b/src/server/scripts/Spells/spell_paladin.cpp
@@ -24,6 +24,7 @@
#include "ScriptMgr.h"
#include "AreaTrigger.h"
#include "AreaTriggerAI.h"
+#include "CommonPredicates.h"
#include "Containers.h"
#include "DB2Stores.h"
#include "Group.h"
@@ -418,7 +419,7 @@ class spell_pal_glyph_of_holy_light : public SpellScript
if (targets.size() > maxTargets)
{
- targets.sort(Trinity::HealthPctOrderPred());
+ targets.sort(Trinity::Predicates::HealthPctOrderPred());
targets.resize(maxTargets);
}
}