diff options
-rw-r--r-- | src/actormanager.cpp | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/src/actormanager.cpp b/src/actormanager.cpp index d30ddbc3a..674239da0 100644 --- a/src/actormanager.cpp +++ b/src/actormanager.cpp @@ -1305,6 +1305,7 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing, } Being *const being = static_cast<Being*>(*i); + int priority = defaultPriorityIndex; if (filtered) { // Skip ignored @@ -1313,11 +1314,18 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing, { continue; } + + const StringIntMapCIter prioIter + = priorityMobsMap.find(being->getName()); + + if (prioIter != priorityMobsMap.end()) + priority = prioIter->second; + // if (default) is in ignore list, then only attack // those in priority or general attack list. if (ignoreDefault && attackMobs.find(being->getName()) == attackMobs.end() - && priorityMobs.find(being->getName()) == priorityMobs.end()) + && prioIter == priorityMobsMap.end()) { continue; } @@ -1349,9 +1357,8 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing, continue; } -// logger->log("being name:" + being->getName()); -// logger->log("index:" + toString(index)); -// logger->log("d:" + toString(d)); + //logger->log("being prio:%3d, dist^2:%3d, name: '%s'", + // priority, distSq, being->getName().c_str()); if (!filtered) { @@ -1363,20 +1370,14 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing, } else { - int w2 = defaultPriorityIndex; if (closestBeing != nullptr) { - const StringIntMapCIter it2 = priorityMobsMap.find( - being->getName()); - if (it2 != priorityMobsMap.end()) - w2 = (*it2).second; - - if ((w2 < closestPriority && distSq <= maxDistSq) || - (w2 == closestPriority && distSq < closestDistSq)) + if ((priority < closestPriority && distSq <= maxDistSq) || + (priority == closestPriority && distSq < closestDistSq)) { closestBeing = being; closestDistSq = distSq; - closestPriority = w2; + closestPriority = priority; continue; } } @@ -1385,12 +1386,7 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing, { closestBeing = being; closestDistSq = distSq; - const StringIntMapCIter it1 = priorityMobsMap.find( - being->getName()); - if (it1 != priorityMobsMap.end()) - closestPriority = it1->second; - else - closestPriority = defaultPriorityIndex; + closestPriority = priority; } } } |