diff options
-rw-r--r-- | src/server/game/AI/CoreAI/UnitAI.h | 55 |
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 96acf8039c2..30a0575c3d2 100644 --- a/src/server/game/AI/CoreAI/UnitAI.h +++ b/src/server/game/AI/CoreAI/UnitAI.h @@ -171,54 +171,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()) @@ -287,9 +240,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) { @@ -312,6 +262,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; |