From ce4c9cb2aeca0000e6ec7cccf5ae0951ad1e1266 Mon Sep 17 00:00:00 2001 From: megamage Date: Fri, 13 Mar 2009 17:48:57 -0600 Subject: *Allow not to switch to charmed AI for some scripts. --HG-- branch : trunk --- src/game/Creature.cpp | 7 ++++++- src/game/CreatureAI.cpp | 7 ++++++- src/game/Unit.cpp | 2 +- src/game/Unit.h | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index df56a3ac27f..8a5e6e52018 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -484,7 +484,12 @@ void Creature::Update(uint32 diff) break; // if creature is charmed, switch to charmed AI - UpdateCharmAI(); + if(NeedChangeAI) + { + UpdateCharmAI(); + NeedChangeAI = false; + IsAIEnabled = true; + } if(!IsInEvadeMode() && IsAIEnabled) { diff --git a/src/game/CreatureAI.cpp b/src/game/CreatureAI.cpp index 2d7eeeb18ff..9d9a3fc3a63 100644 --- a/src/game/CreatureAI.cpp +++ b/src/game/CreatureAI.cpp @@ -63,7 +63,12 @@ void UnitAI::DoMeleeAttackIfReady() void PlayerAI::OnCharmed(bool apply) { me->IsAIEnabled = apply; } //Disable CreatureAI when charmed -void CreatureAI::OnCharmed(bool apply) { /*me->IsAIEnabled = !apply;*/ } +void CreatureAI::OnCharmed(bool apply) +{ + //me->IsAIEnabled = !apply;*/ + me->NeedChangeAI = true; + me->IsAIEnabled = false; +} void CreatureAI::MoveInLineOfSight(Unit *who) { diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 886020459b1..76a2cb264d4 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -151,7 +151,7 @@ bool IsPassiveStackableSpell( uint32 spellId ) Unit::Unit() : WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostilRefManager(this) -, m_IsInNotifyList(false), m_Notified(false), IsAIEnabled(false) +, m_IsInNotifyList(false), m_Notified(false), IsAIEnabled(false), NeedChangeAI(false) , i_AI(NULL), i_disabledAI(NULL) { m_objectType |= TYPEMASK_UNIT; diff --git a/src/game/Unit.h b/src/game/Unit.h index d3455d83baa..f980692ef7b 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -1422,7 +1422,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject uint32 GetReducedThreatPercent() { return m_reducedThreatPercent; } Unit *GetMisdirectionTarget() { return m_misdirectionTargetGUID ? GetUnit(*this, m_misdirectionTargetGUID) : NULL; } - bool IsAIEnabled; + bool IsAIEnabled, NeedChangeAI; protected: explicit Unit (); -- cgit v1.2.3