Skip to content
Browse files

[11918] Let creatures evade when the enemy is unreachable

This commit is not great, but will be improved hopefully soon.
However it seems that it doesn't really cause problems, it is just not as good as it should be!
  • Loading branch information...
1 parent 07989b7 commit 649b48823c4c4c983075ca6981309eb2f7ab39b9 sixsixnine committed with Schmoozerd Jan 30, 2012
Showing with 36 additions and 2 deletions.
  1. +9 −1 src/game/ThreatManager.cpp
  2. +26 −0 src/game/Unit.cpp
  3. +1 −1 src/shared/revision_nr.h
View
10 src/game/ThreatManager.cpp
@@ -252,7 +252,15 @@ HostileReference* ThreatContainer::addThreat(Unit* pVictim, float pThreat)
void ThreatContainer::modifyThreatPercent(Unit *pVictim, int32 pPercent)
{
if(HostileReference* ref = getReferenceByTarget(pVictim))
- ref->addThreatPercent(pPercent);
+ {
+ if(pPercent < -100)
+ {
+ ref->removeReference();
+ delete ref;
+ }
+ else
+ ref->addThreatPercent(pPercent);
+ }
}
//============================================================
View
26 src/game/Unit.cpp
@@ -8666,6 +8666,32 @@ bool Unit::SelectHostileTarget()
SetInFront(target);
if (oldTarget != target)
((Creature*)this)->AI()->AttackStart(target);
+
+ // check if currently selected target is reachable
+ // NOTE: path alrteady generated from AttackStart()
+ if(!GetMotionMaster()->operator->()->IsReachable())
+ {
+ // remove all taunts
+ RemoveSpellsCausingAura(SPELL_AURA_MOD_TAUNT);
+
+ if(m_ThreatManager.getThreatList().size() < 2)
+ {
+ // only one target in list, we have to evade after timer
+ // TODO: make timer - inside Creature class
+ ((Creature*)this)->AI()->EnterEvadeMode();
+ }
+ else
+ {
+ // remove unreachable target from our threat list
+ // next iteration we will select next possible target
+ m_HostileRefManager.deleteReference(target);
+ m_ThreatManager.modifyThreatPercent(target, -101);
+
+ _removeAttacker(target);
+ }
+
+ return false;
+ }
}
return true;
}
View
2 src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
- #define REVISION_NR "11917"
+ #define REVISION_NR "11918"
#endif // __REVISION_NR_H__

0 comments on commit 649b488

Please sign in to comment.
Something went wrong with that request. Please try again.