aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2017-07-13 17:49:48 +0200
committerShauren <shauren.trinity@gmail.com>2020-08-18 18:53:13 +0200
commit5f59be31b0dc8b8b58da06fded6ef91dc170e8b6 (patch)
tree52b986d8bf7d57985542412519579951ed99d52b /src
parent6e0be8b469726fff517a7a10ee155a2d01ad1fac (diff)
Core/AI: UnitAI::SelectTarget now applies offset BEFORE filtering by predicate (to match expected behavior). (#19975)
* Also some major code deduplication (SelectTarget now calls SelectTargetList). (cherry picked from commit 8d0633c842d474a843ec9f4bd45dcec3013bfd5d)
Diffstat (limited to 'src')
-rw-r--r--src/server/game/AI/CoreAI/UnitAI.h55
1 files changed, 4 insertions, 51 deletions
diff --git a/src/server/game/AI/CoreAI/UnitAI.h b/src/server/game/AI/CoreAI/UnitAI.h
index 4dd25592677..1f1a44c429d 100644
--- a/src/server/game/AI/CoreAI/UnitAI.h
+++ b/src/server/game/AI/CoreAI/UnitAI.h
@@ -172,54 +172,7 @@ class TC_GAME_API UnitAI
return nullptr;
std::list<Unit*> targetList;
- if (targetType == SELECT_TARGET_MAXDISTANCE || targetType == SELECT_TARGET_MINDISTANCE)
- {
- for (ThreatReference const* ref : mgr.GetUnsortedThreatList())
- {
- if (ref->IsOffline())
- continue;
-
- targetList.push_back(ref->GetVictim());
- }
- }
- else
- {
- Unit* currentVictim = mgr.GetCurrentVictim();
- if (currentVictim)
- targetList.push_back(currentVictim);
-
- for (ThreatReference const* ref : mgr.GetSortedThreatList())
- {
- if (ref->IsOffline())
- continue;
-
- Unit* thisTarget = ref->GetVictim();
- if (thisTarget != currentVictim)
- targetList.push_back(thisTarget);
- }
- }
-
- // filter by predicate
- targetList.remove_if([&predicate](Unit* target) { return !predicate(target); });
-
- // shortcut: the list certainly isn't gonna get any larger after this point
- if (targetList.size() <= offset)
- return nullptr;
-
- // 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);
-
- // then reverse the sorting for MIN sortings
- if (targetType == SELECT_TARGET_MINTHREAT)
- targetList.reverse();
-
- // now pop the first <offset> elements
- while (offset)
- {
- targetList.pop_front();
- --offset;
- }
+ SelectTargetList(targetList, mgr.GetThreatListSize(), targetType, offset, predicate);
// maybe nothing fulfills the predicate
if (targetList.empty())
@@ -288,9 +241,6 @@ class TC_GAME_API UnitAI
}
}
- // filter by predicate
- targetList.remove_if([&predicate](Unit* target) { return !predicate(target); });
-
// shortcut: the list isn't gonna get any larger
if (targetList.size() <= offset)
{
@@ -313,6 +263,9 @@ class TC_GAME_API UnitAI
--offset;
}
+ // then finally filter by predicate
+ targetList.remove_if([&predicate](Unit* target) { return !predicate(target); });
+
if (targetList.size() <= num)
return;