diff options
Diffstat (limited to 'src/game/ThreatManager.cpp')
| -rw-r--r-- | src/game/ThreatManager.cpp | 35 | 
1 files changed, 23 insertions, 12 deletions
diff --git a/src/game/ThreatManager.cpp b/src/game/ThreatManager.cpp index 0e902c05864..a78dfc09373 100644 --- a/src/game/ThreatManager.cpp +++ b/src/game/ThreatManager.cpp @@ -267,26 +267,36 @@ HostilReference* ThreatContainer::selectNextVictim(Creature* pAttacker, HostilRe  {      HostilReference* currentRef = NULL;      bool found = false; -     +    bool noPriorityTargetFound = false; +      std::list<HostilReference*>::iterator lastRef = iThreatList.end();      lastRef--; -     -    for(std::list<HostilReference*>::iterator iter = iThreatList.begin(); iter != iThreatList.end() && !found; ++iter) + +    for(std::list<HostilReference*>::iterator iter = iThreatList.begin(); iter != iThreatList.end() && !found;)      {          currentRef = (*iter);          Unit* target = currentRef->getTarget();          assert(target);                                     // if the ref has status online the target must be there ! -         -        // some units are preferred in comparison to others -        if(iter != lastRef && (target->IsImmunedToDamage(pAttacker->GetMeleeDamageSchoolMask(), false) || -                target->hasUnitState(UNIT_STAT_CONFUSED) -                ) ) + +        // some units are prefered in comparison to others +        if(!noPriorityTargetFound && (target->IsImmunedToDamage(pAttacker->GetMeleeDamageSchoolMask()) || target->hasNegativeAuraWithInterruptFlag(AURA_INTERRUPT_FLAG_DAMAGE)) )          { -            // current victim is a second choice target, so don't compare threat with it below -            if(currentRef == pCurrentVictim) -                pCurrentVictim = NULL; -            continue; +            if(iter != lastRef) +            { +                // current victim is a second choice target, so don't compare threat with it below +                if(currentRef == pCurrentVictim) +                    pCurrentVictim = NULL; +                ++iter; +                continue; +            } +            else +            { +                // if we reached to this point, everyone in the threatlist is a second choice target. In such a situation the target with the highest threat should be attacked. +                noPriorityTargetFound = true; +                iter = iThreatList.begin(); +                continue; +            }          }          if(!pAttacker->IsOutOfThreatArea(target))           // skip non attackable currently targets @@ -314,6 +324,7 @@ HostilReference* ThreatContainer::selectNextVictim(Creature* pAttacker, HostilRe                  break;              }          } +        ++iter;      }      if(!found)          currentRef = NULL;  | 
