diff options
author | QAston <none@none> | 2009-04-07 20:40:00 +0200 |
---|---|---|
committer | QAston <none@none> | 2009-04-07 20:40:00 +0200 |
commit | 741b51cc471d8a3f897b7ded51e1d3122e3d8300 (patch) | |
tree | 3c579933847679c780be6b672e00d636a32690dd /src/game/Creature.cpp | |
parent | 26b856a5135f51372cb1b15de21a0e995cdb6435 (diff) | |
parent | c6b6a72956efdc10da8fac982db734b054984d08 (diff) |
*Merge
--HG--
branch : trunk
Diffstat (limited to 'src/game/Creature.cpp')
-rw-r--r-- | src/game/Creature.cpp | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 76537754b26..74ebe4406c8 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -139,7 +139,7 @@ m_deathTimer(0), m_respawnTime(0), m_respawnDelay(25), m_corpseDelay(60), m_resp m_gossipOptionLoaded(false), m_emoteState(0), m_defaultMovementType(IDLE_MOTION_TYPE), m_DBTableGuid(0), m_equipmentId(0), m_AlreadyCallAssistance(false), m_regenHealth(true), m_AI_locked(false), m_isDeadByDefault(false), m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL), -m_creatureInfo(NULL), m_reactState(REACT_AGGRESSIVE), m_formationID(0), m_summonMask(SUMMON_MASK_NONE) +m_creatureInfo(NULL), m_reactState(REACT_AGGRESSIVE), m_formation(NULL), m_summonMask(SUMMON_MASK_NONE) { m_regenTimer = 200; m_valuesCount = UNIT_END; @@ -174,18 +174,18 @@ void Creature::AddToWorld() { ObjectAccessor::Instance().AddObject(this); Unit::AddToWorld(); - AIM_Initialize(); SearchFormation(); + AIM_Initialize(); } } void Creature::RemoveFromWorld() { - ///- Remove the creature from the accessor if(IsInWorld()) { - if(m_formationID) - formation_mgr.DestroyGroup(m_formationID, GetGUID()); + // Clear formation info + if(m_formation) + formation_mgr.RemoveCreatureFromGroup(m_formation, this); Unit::RemoveFromWorld(); ObjectAccessor::Instance().RemoveObject(this); } @@ -193,16 +193,16 @@ void Creature::RemoveFromWorld() void Creature::SearchFormation() { - if(isPet()) + if(isSummon()) return; uint32 lowguid = GetDBTableGUIDLow(); + if(!lowguid) + return; - if(lowguid && CreatureGroupMap.find(lowguid) != CreatureGroupMap.end()) - { - m_formationID = CreatureGroupMap[lowguid]->leaderGUID; - formation_mgr.UpdateCreatureGroup(m_formationID, this); - } + CreatureGroupInfoType::iterator frmdata = CreatureGroupMap.find(lowguid); + if(frmdata != CreatureGroupMap.end()) + formation_mgr.AddCreatureToGroup(frmdata->second->leaderGUID, this); } void Creature::RemoveCorpse() @@ -611,7 +611,9 @@ bool Creature::AIM_Initialize(CreatureAI* ai) } UnitAI *oldAI = i_AI; - i_motionMaster.Initialize(); + + Motion_Initialize(); + i_AI = ai ? ai : FactorySelector::selectAI(this); if(oldAI) delete oldAI; IsAIEnabled = true; @@ -619,6 +621,21 @@ bool Creature::AIM_Initialize(CreatureAI* ai) return true; } +void Creature::Motion_Initialize() +{ + if(!m_formation) + i_motionMaster.Initialize(); + else if(m_formation->getLeader() == this) + { + m_formation->FormationReset(false); + i_motionMaster.Initialize(); + } + else if(m_formation->isFormed()) + i_motionMaster.MoveIdle(MOTION_SLOT_IDLE); //wait the order of leader + else + i_motionMaster.Initialize(); +} + bool Creature::Create (uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 team, const CreatureData *data) { SetMapId(map->GetId()); @@ -1654,6 +1671,10 @@ void Creature::setDeathState(DeathState s) return; Unit::setDeathState(CORPSE); + + //Dismiss group if is leader + if(m_formation && m_formation->getLeader() == this) + m_formation->FormationReset(true); } if(s == JUST_ALIVED) { @@ -1667,9 +1688,9 @@ void Creature::setDeathState(DeathState s) AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE); SetUInt32Value(UNIT_NPC_FLAGS, cinfo->npcflag); clearUnitState(UNIT_STAT_ALL_STATE); - i_motionMaster.Initialize(); SetMeleeDamageSchool(SpellSchools(cinfo->dmgschool)); LoadCreaturesAddon(true); + Motion_Initialize(); } } |