From 1fbfc6da645058a6da3073dafde0e6bca621e31c Mon Sep 17 00:00:00 2001 From: megamage Date: Thu, 12 Mar 2009 14:15:44 -0600 Subject: *Assign possessed AI and pet AI to charmed creatures. --HG-- branch : trunk --- src/game/Unit.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/game/Unit.cpp') diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index d7b3305c55d..e3e11c2e840 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -47,6 +47,8 @@ #include "CellImpl.h" #include "Path.h" #include "CreatureGroups.h" +#include "PetAI.h" +#include "NullCreatureAI.h" #include @@ -150,6 +152,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) +, i_AI(NULL), i_disabledAI(NULL) { m_objectType |= TYPEMASK_UNIT; m_objectTypeId = TYPEID_UNIT; @@ -11250,10 +11253,38 @@ void Unit::CleanupsBeforeDelete() RemoveFromWorld(); } +void Unit::UpdateCharmAI() +{ + if(GetTypeId() == TYPEID_PLAYER) + return; + + if(i_disabledAI) // disabled AI must be primary AI + { + if(!isCharmed()) + { + if(i_AI) delete i_AI; + i_AI = i_disabledAI; + i_disabledAI = NULL; + } + } + else + { + if(isCharmed()) + { + i_disabledAI = i_AI; + if(isPossessed()) + i_AI = new PossessedAI((Creature*)this); + else + i_AI = new PetAI((Creature*)this); + } + } +} + CharmInfo* Unit::InitCharmInfo() { if(!m_charmInfo) m_charmInfo = new CharmInfo(this); + return m_charmInfo; } -- cgit v1.2.3