diff options
| author | Peter Keresztes Schmidt <carbenium@outlook.com> | 2020-06-16 23:08:56 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2022-01-06 21:53:27 +0100 |
| commit | c4098897a8d2f6cc55dd6434eb3b6f5468791f2a (patch) | |
| tree | 0acb69db4226dafc872dcd734c0d867d04718455 /src/server/game | |
| parent | aa409f8993f3ee5e90dd64511f34504ebafec7d1 (diff) | |
game/AI: Convert SelectAggroTarget to enum class (#24818)
* game/AI: Convert SelectAggroTarget to enum class
* game/AI: Rename SelectAggroTarget to SelectTargetMethod
(cherry picked from commit 418c3b1fd50664aad035bd975a65281e82ba2dea)
Diffstat (limited to 'src/server/game')
| -rw-r--r-- | src/server/game/AI/CoreAI/UnitAI.cpp | 8 | ||||
| -rw-r--r-- | src/server/game/AI/CoreAI/UnitAI.h | 59 | ||||
| -rw-r--r-- | src/server/game/AI/PlayerAI/PlayerAI.cpp | 2 | ||||
| -rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedCreature.cpp | 4 | ||||
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartScript.cpp | 18 |
5 files changed, 48 insertions, 43 deletions
diff --git a/src/server/game/AI/CoreAI/UnitAI.cpp b/src/server/game/AI/CoreAI/UnitAI.cpp index 642ac34a675..ee019e4e0a9 100644 --- a/src/server/game/AI/CoreAI/UnitAI.cpp +++ b/src/server/game/AI/CoreAI/UnitAI.cpp @@ -103,12 +103,12 @@ bool UnitAI::DoSpellAttackIfReady(uint32 spellId) return false; } -Unit* UnitAI::SelectTarget(SelectAggroTarget targetType, uint32 position, float dist, bool playerOnly, bool withTank, int32 aura) +Unit* UnitAI::SelectTarget(SelectTargetMethod targetType, uint32 position, float dist, bool playerOnly, bool withTank, int32 aura) { return SelectTarget(targetType, position, DefaultTargetSelector(me, dist, playerOnly, withTank, aura)); } -void UnitAI::SelectTargetList(std::list<Unit*>& targetList, uint32 num, SelectAggroTarget targetType, uint32 offset, float dist, bool playerOnly, bool withTank, int32 aura) +void UnitAI::SelectTargetList(std::list<Unit*>& targetList, uint32 num, SelectTargetMethod targetType, uint32 offset, float dist, bool playerOnly, bool withTank, int32 aura) { SelectTargetList(targetList, num, targetType, offset, DefaultTargetSelector(me, dist, playerOnly, withTank, aura)); } @@ -134,7 +134,7 @@ SpellCastResult UnitAI::DoCast(uint32 spellId) if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId, me->GetMap()->GetDifficultyID())) { bool playerOnly = spellInfo->HasAttribute(SPELL_ATTR3_ONLY_TARGET_PLAYERS); - target = SelectTarget(SELECT_TARGET_RANDOM, 0, spellInfo->GetMaxRange(false), playerOnly); + target = SelectTarget(SelectTargetMethod::Random, 0, spellInfo->GetMaxRange(false), playerOnly); } break; } @@ -155,7 +155,7 @@ SpellCastResult UnitAI::DoCast(uint32 spellId) if (!spellInfo->HasAuraInterruptFlag(SpellAuraInterruptFlags::NOT_VICTIM) && targetSelector(me->GetVictim())) target = me->GetVictim(); else - target = SelectTarget(SELECT_TARGET_RANDOM, 0, targetSelector); + target = SelectTarget(SelectTargetMethod::Random, 0, targetSelector); } break; } diff --git a/src/server/game/AI/CoreAI/UnitAI.h b/src/server/game/AI/CoreAI/UnitAI.h index 0f9817cb5aa..4d660a4289d 100644 --- a/src/server/game/AI/CoreAI/UnitAI.h +++ b/src/server/game/AI/CoreAI/UnitAI.h @@ -35,7 +35,7 @@ T* EnsureAI(U* ai) T* cast_ai = dynamic_cast<T*>(ai); ASSERT(cast_ai); return cast_ai; -}; +} class Player; class Quest; @@ -47,14 +47,14 @@ enum Difficulty : uint8; enum MovementGeneratorType : uint8; enum SpellEffIndex : uint8; -//Selection method used by SelectTarget -enum SelectAggroTarget +// Selection method used by SelectTarget +enum class SelectTargetMethod { - SELECT_TARGET_RANDOM = 0, // just pick a random target - SELECT_TARGET_MAXTHREAT, // prefer targets higher in the threat list - SELECT_TARGET_MINTHREAT, // prefer targets lower in the threat list - SELECT_TARGET_MAXDISTANCE, // prefer targets further from us - SELECT_TARGET_MINDISTANCE // prefer targets closer to us + Random, // just pick a random target + MaxThreat, // prefer targets higher in the threat list + MinThreat, // prefer targets lower in the threat list + MaxDistance, // prefer targets further from us + MinDistance // prefer targets closer to us }; // default predicate function to select target based on distance, player and/or aura criteria @@ -161,18 +161,21 @@ class TC_GAME_API UnitAI virtual ObjectGuid GetGUID(int32 /*id*/ = 0) const { return ObjectGuid::Empty; } // Select the best target (in <targetType> order) from the threat list that fulfill the following: - // - Not among the first <offset> entries in <targetType> order (or MAXTHREAT order, if <targetType> is RANDOM). + // - Not among the first <offset> entries in <targetType> order (or SelectTargetMethod::MaxThreat order, + // if <targetType> is SelectTargetMethod::Random). // - Within at most <dist> yards (if dist > 0.0f) // - At least -<dist> yards away (if dist < 0.0f) // - Is a player (if playerOnly = true) // - Not the current tank (if withTank = false) // - Has aura with ID <aura> (if aura > 0) // - Does not have aura with ID -<aura> (if aura < 0) - Unit* SelectTarget(SelectAggroTarget targetType, uint32 offset = 0, float dist = 0.0f, bool playerOnly = false, bool withTank = true, int32 aura = 0); + Unit* SelectTarget(SelectTargetMethod targetType, uint32 offset = 0, float dist = 0.0f, bool playerOnly = false, bool withTank = true, int32 aura = 0); + // Select the best target (in <targetType> order) satisfying <predicate> from the threat list. - // If <offset> is nonzero, the first <offset> entries in <targetType> order (or MAXTHREAT order, if <targetType> is RANDOM) are skipped. + // If <offset> is nonzero, the first <offset> entries in <targetType> order (or SelectTargetMethod::MaxThreat + // order, if <targetType> is SelectTargetMethod::Random) are skipped. template<class PREDICATE> - Unit* SelectTarget(SelectAggroTarget targetType, uint32 offset, PREDICATE const& predicate) + Unit* SelectTarget(SelectTargetMethod targetType, uint32 offset, PREDICATE const& predicate) { ThreatManager& mgr = GetThreatManager(); // shortcut: if we ignore the first <offset> elements, and there are at most <offset> elements, then we ignore ALL elements @@ -188,12 +191,12 @@ class TC_GAME_API UnitAI switch (targetType) { - case SELECT_TARGET_MAXTHREAT: - case SELECT_TARGET_MINTHREAT: - case SELECT_TARGET_MAXDISTANCE: - case SELECT_TARGET_MINDISTANCE: + case SelectTargetMethod::MaxThreat: + case SelectTargetMethod::MinThreat: + case SelectTargetMethod::MaxDistance: + case SelectTargetMethod::MinDistance: return targetList.front(); - case SELECT_TARGET_RANDOM: + case SelectTargetMethod::Random: return Trinity::Containers::SelectRandomContainerElement(targetList); default: return nullptr; @@ -201,7 +204,8 @@ class TC_GAME_API UnitAI } // Select the best (up to) <num> targets (in <targetType> order) from the threat list that fulfill the following: - // - Not among the first <offset> entries in <targetType> order (or MAXTHREAT order, if <targetType> is RANDOM). + // - Not among the first <offset> entries in <targetType> order (or SelectTargetMethod::MaxThreat order, + // if <targetType> is SelectTargetMethod::Random). // - Within at most <dist> yards (if dist > 0.0f) // - At least -<dist> yards away (if dist < 0.0f) // - Is a player (if playerOnly = true) @@ -209,12 +213,13 @@ class TC_GAME_API UnitAI // - Has aura with ID <aura> (if aura > 0) // - Does not have aura with ID -<aura> (if aura < 0) // The resulting targets are stored in <targetList> (which is cleared first). - void SelectTargetList(std::list<Unit*>& targetList, uint32 num, SelectAggroTarget targetType, uint32 offset = 0, float dist = 0.0f, bool playerOnly = false, bool withTank = true, int32 aura = 0); + void SelectTargetList(std::list<Unit*>& targetList, uint32 num, SelectTargetMethod targetType, uint32 offset = 0, float dist = 0.0f, bool playerOnly = false, bool withTank = true, int32 aura = 0); // Select the best (up to) <num> targets (in <targetType> order) satisfying <predicate> from the threat list and stores them in <targetList> (which is cleared first). - // If <offset> is nonzero, the first <offset> entries in <targetType> order (or MAXTHREAT order, if <targetType> is RANDOM) are skipped. + // If <offset> is nonzero, the first <offset> entries in <targetType> order (or SelectTargetMethod::MaxThreat + // order, if <targetType> is SelectTargetMethod::Random) are skipped. template <class PREDICATE> - void SelectTargetList(std::list<Unit*>& targetList, uint32 num, SelectAggroTarget targetType, uint32 offset, PREDICATE const& predicate) + void SelectTargetList(std::list<Unit*>& targetList, uint32 num, SelectTargetMethod targetType, uint32 offset, PREDICATE const& predicate) { targetList.clear(); ThreatManager& mgr = GetThreatManager(); @@ -222,7 +227,7 @@ class TC_GAME_API UnitAI if (mgr.GetThreatListSize() <= offset) return; - if (targetType == SELECT_TARGET_MAXDISTANCE || targetType == SELECT_TARGET_MINDISTANCE) + if (targetType == SelectTargetMethod::MaxDistance || targetType == SelectTargetMethod::MinDistance) { for (ThreatReference const* ref : mgr.GetUnsortedThreatList()) { @@ -256,12 +261,12 @@ class TC_GAME_API UnitAI return; } - // right now, list is unsorted for DISTANCE types - re-sort by MAXDISTANCE - if (targetType == SELECT_TARGET_MAXDISTANCE || targetType == SELECT_TARGET_MINDISTANCE) - SortByDistance(targetList, targetType == SELECT_TARGET_MINDISTANCE); + // right now, list is unsorted for DISTANCE types - re-sort by SelectTargetMethod::MaxDistance + if (targetType == SelectTargetMethod::MaxDistance || targetType == SelectTargetMethod::MinDistance) + SortByDistance(targetList, targetType == SelectTargetMethod::MinDistance); // now the list is MAX sorted, reverse for MIN types - if (targetType == SELECT_TARGET_MINTHREAT) + if (targetType == SelectTargetMethod::MinThreat) targetList.reverse(); // ignore the first <offset> elements @@ -277,7 +282,7 @@ class TC_GAME_API UnitAI if (targetList.size() <= num) return; - if (targetType == SELECT_TARGET_RANDOM) + if (targetType == SelectTargetMethod::Random) Trinity::Containers::RandomResize(targetList, num); else targetList.resize(num); diff --git a/src/server/game/AI/PlayerAI/PlayerAI.cpp b/src/server/game/AI/PlayerAI/PlayerAI.cpp index d41a1292a19..8fe52f0226c 100644 --- a/src/server/game/AI/PlayerAI/PlayerAI.cpp +++ b/src/server/game/AI/PlayerAI/PlayerAI.cpp @@ -693,7 +693,7 @@ Unit* SimpleCharmedPlayerAI::SelectAttackTarget() const if (Unit* charmer = me->GetCharmer()) { if (UnitAI* charmerAI = charmer->GetAI()) - return charmerAI->SelectTarget(SELECT_TARGET_RANDOM, 0, ValidTargetSelectPredicate(this)); + return charmerAI->SelectTarget(SelectTargetMethod::Random, 0, ValidTargetSelectPredicate(this)); return charmer->GetVictim(); } return nullptr; diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index 7b73dcc833c..c67b1ba81d4 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -641,7 +641,7 @@ void WorldBossAI::_JustDied() void WorldBossAI::_JustEngagedWith() { - Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 0.0f, true); + Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 0.0f, true); if (target) AttackStart(target); } @@ -649,7 +649,7 @@ void WorldBossAI::_JustEngagedWith() void WorldBossAI::JustSummoned(Creature* summon) { summons.Summon(summon); - Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 0.0f, true); + Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 0.0f, true); if (target) summon->AI()->AttackStart(target); } diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index 80397529bbf..d01ab7ab8c8 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -2686,10 +2686,10 @@ void SmartScript::GetTargets(ObjectVector& targets, SmartScriptHolder const& e, { if (e.target.hostilRandom.powerType) { - if (Unit* u = me->AI()->SelectTarget(SELECT_TARGET_MAXTHREAT, 1, PowerUsersSelector(me, Powers(e.target.hostilRandom.powerType - 1), float(e.target.hostilRandom.maxDist), e.target.hostilRandom.playerOnly != 0))) + if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::MaxThreat, 1, PowerUsersSelector(me, Powers(e.target.hostilRandom.powerType - 1), float(e.target.hostilRandom.maxDist), e.target.hostilRandom.playerOnly != 0))) targets.push_back(u); } - else if (Unit* u = me->AI()->SelectTarget(SELECT_TARGET_MAXTHREAT, 1, float(e.target.hostilRandom.maxDist), e.target.hostilRandom.playerOnly != 0)) + else if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::MaxThreat, 1, float(e.target.hostilRandom.maxDist), e.target.hostilRandom.playerOnly != 0)) targets.push_back(u); } break; @@ -2698,10 +2698,10 @@ void SmartScript::GetTargets(ObjectVector& targets, SmartScriptHolder const& e, { if (e.target.hostilRandom.powerType) { - if (Unit* u = me->AI()->SelectTarget(SELECT_TARGET_MINTHREAT, 0, PowerUsersSelector(me, Powers(e.target.hostilRandom.powerType - 1), float(e.target.hostilRandom.maxDist), e.target.hostilRandom.playerOnly != 0))) + if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::MinThreat, 0, PowerUsersSelector(me, Powers(e.target.hostilRandom.powerType - 1), float(e.target.hostilRandom.maxDist), e.target.hostilRandom.playerOnly != 0))) targets.push_back(u); } - else if (Unit* u = me->AI()->SelectTarget(SELECT_TARGET_MINTHREAT, 0, float(e.target.hostilRandom.maxDist), e.target.hostilRandom.playerOnly != 0)) + else if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::MinThreat, 0, float(e.target.hostilRandom.maxDist), e.target.hostilRandom.playerOnly != 0)) targets.push_back(u); } break; @@ -2710,10 +2710,10 @@ void SmartScript::GetTargets(ObjectVector& targets, SmartScriptHolder const& e, { if (e.target.hostilRandom.powerType) { - if (Unit* u = me->AI()->SelectTarget(SELECT_TARGET_RANDOM, 0, PowerUsersSelector(me, Powers(e.target.hostilRandom.powerType - 1), float(e.target.hostilRandom.maxDist), e.target.hostilRandom.playerOnly != 0))) + if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::Random, 0, PowerUsersSelector(me, Powers(e.target.hostilRandom.powerType - 1), float(e.target.hostilRandom.maxDist), e.target.hostilRandom.playerOnly != 0))) targets.push_back(u); } - else if (Unit* u = me->AI()->SelectTarget(SELECT_TARGET_RANDOM, 0, float(e.target.hostilRandom.maxDist), e.target.hostilRandom.playerOnly != 0)) + else if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::Random, 0, float(e.target.hostilRandom.maxDist), e.target.hostilRandom.playerOnly != 0)) targets.push_back(u); } break; @@ -2722,17 +2722,17 @@ void SmartScript::GetTargets(ObjectVector& targets, SmartScriptHolder const& e, { if (e.target.hostilRandom.powerType) { - if (Unit* u = me->AI()->SelectTarget(SELECT_TARGET_RANDOM, 1, PowerUsersSelector(me, Powers(e.target.hostilRandom.powerType - 1), float(e.target.hostilRandom.maxDist), e.target.hostilRandom.playerOnly != 0))) + if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::Random, 1, PowerUsersSelector(me, Powers(e.target.hostilRandom.powerType - 1), float(e.target.hostilRandom.maxDist), e.target.hostilRandom.playerOnly != 0))) targets.push_back(u); } - else if (Unit* u = me->AI()->SelectTarget(SELECT_TARGET_RANDOM, 1, float(e.target.hostilRandom.maxDist), e.target.hostilRandom.playerOnly != 0)) + else if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::Random, 1, float(e.target.hostilRandom.maxDist), e.target.hostilRandom.playerOnly != 0)) targets.push_back(u); } break; case SMART_TARGET_FARTHEST: if (me) { - if (Unit* u = me->AI()->SelectTarget(SELECT_TARGET_MAXDISTANCE, 0, FarthestTargetSelector(me, float(e.target.farthest.maxDist), e.target.farthest.playerOnly != 0, e.target.farthest.isInLos != 0))) + if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::MaxDistance, 0, FarthestTargetSelector(me, float(e.target.farthest.maxDist), e.target.farthest.playerOnly != 0, e.target.farthest.isInLos != 0))) targets.push_back(u); } break; |
