diff options
author | ccrs <ccrs@users.noreply.github.com> | 2016-07-18 20:30:58 +0200 |
---|---|---|
committer | joschiwald <joschiwald.trinity@gmail.com> | 2017-02-05 21:14:04 +0100 |
commit | 297c0a9b9e40180b6fc978137b71b18a525743ff (patch) | |
tree | 32b117a6fe4475144692c58195631143783112db /src | |
parent | 7a2a8059c9a5fdec2e8a3d1cbd90688d3ec4753f (diff) |
Core/UnitAI: #17309 follow-up (#17608)
* Core/UnitAI: SelectTarget correction
Set CurrentVictim as first element on targetList if necessary, which is then filled with the threatlist elements that satisfy the predicate.
(cherry picked from commit b008b677ad98b1b0246bcf1fcf246ca17930cdc2)
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/AI/CoreAI/UnitAI.h | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/server/game/AI/CoreAI/UnitAI.h b/src/server/game/AI/CoreAI/UnitAI.h index 15fba06df1b..2ca49653b50 100644 --- a/src/server/game/AI/CoreAI/UnitAI.h +++ b/src/server/game/AI/CoreAI/UnitAI.h @@ -151,15 +151,23 @@ class TC_GAME_API UnitAI return nullptr; std::list<Unit*> targetList; - Unit* currentVictim = me->getThreatManager().getCurrentVictim()->getTarget(); + Unit* currentVictim = nullptr; + if (auto currentVictimReference = me->getThreatManager().getCurrentVictim()) + { + currentVictim = currentVictimReference->getTarget(); - // Current victim always goes first - if (predicate(currentVictim)) - targetList.push_back(currentVictim); + // Current victim always goes first + if (currentVictim && predicate(currentVictim)) + targetList.push_back(currentVictim); + } for (ThreatContainer::StorageType::const_iterator itr = threatlist.begin(); itr != threatlist.end(); ++itr) - if ((*itr)->getTarget() != currentVictim && predicate((*itr)->getTarget())) + { + if (currentVictim != nullptr && (*itr)->getTarget() != currentVictim && predicate((*itr)->getTarget())) targetList.push_back((*itr)->getTarget()); + else if (currentVictim == nullptr && predicate((*itr)->getTarget())) + targetList.push_back((*itr)->getTarget()); + } if (position >= targetList.size()) return nullptr; |