diff options
author | megamage <none@none> | 2009-04-14 19:54:49 -0500 |
---|---|---|
committer | megamage <none@none> | 2009-04-14 19:54:49 -0500 |
commit | 3a658002180e30de4e7037a14e2b4fc0788b5d40 (patch) | |
tree | f62abe1bfc8ec2fbf5fff81c5eb73c6cb1e99a04 /src/game/PetAI.cpp | |
parent | 4f4c6aeaf533419a7933e8ff0ee6f09d976a04b7 (diff) |
[7667] Add to CreatureAI field pointing to creature itself. Use it instead diff. fields in subclases. Author: VladimirMangos
Also send pointer to AI constructors ans mark constructors as explicit.
This changes allow move now some generic often used AI code to CreatureAI helper functions.
--HG--
branch : trunk
Diffstat (limited to 'src/game/PetAI.cpp')
-rw-r--r-- | src/game/PetAI.cpp | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/src/game/PetAI.cpp b/src/game/PetAI.cpp index 3ba66bd57a0..88327978de9 100644 --- a/src/game/PetAI.cpp +++ b/src/game/PetAI.cpp @@ -38,7 +38,7 @@ int PetAI::Permissible(const Creature *creature) return PERMIT_BASE_NO; } -PetAI::PetAI(Creature *c) : CreatureAI(c), i_pet(*c), i_tracker(TIME_INTERVAL_LOOK) +PetAI::PetAI(Creature *c) : CreatureAI(c), i_tracker(TIME_INTERVAL_LOOK) { m_AllySet.clear(); UpdateAllies(); @@ -51,46 +51,46 @@ void PetAI::EnterEvadeMode() bool PetAI::_needToStop() const { // This is needed for charmed creatures, as once their target was reset other effects can trigger threat - if(i_pet.isCharmed() && i_pet.getVictim() == i_pet.GetCharmer()) + if(m_creature->isCharmed() && m_creature->getVictim() == m_creature->GetCharmer()) return true; - return !i_pet.canAttack(i_pet.getVictim()); + return !m_creature->canAttack(m_creature->getVictim()); } void PetAI::_stopAttack() { - if( !i_pet.isAlive() ) + if( !m_creature->isAlive() ) { - DEBUG_LOG("Creature stoped attacking cuz his dead [guid=%u]", i_pet.GetGUIDLow()); - i_pet.GetMotionMaster()->Clear(); - i_pet.GetMotionMaster()->MoveIdle(); - i_pet.CombatStop(); - i_pet.getHostilRefManager().deleteReferences(); + DEBUG_LOG("Creature stoped attacking cuz his dead [guid=%u]", m_creature->GetGUIDLow()); + m_creature->GetMotionMaster()->Clear(); + m_creature->GetMotionMaster()->MoveIdle(); + m_creature->CombatStop(); + m_creature->getHostilRefManager().deleteReferences(); return; } - Unit* owner = i_pet.GetCharmerOrOwner(); + Unit* owner = m_creature->GetCharmerOrOwner(); - if(owner && i_pet.GetCharmInfo() && i_pet.GetCharmInfo()->HasCommandState(COMMAND_FOLLOW)) + if(owner && m_creature->GetCharmInfo() && m_creature->GetCharmInfo()->HasCommandState(COMMAND_FOLLOW)) { - i_pet.GetMotionMaster()->MoveFollow(owner,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE); + m_creature->GetMotionMaster()->MoveFollow(owner,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE); } else { - i_pet.clearUnitState(UNIT_STAT_FOLLOW); - i_pet.GetMotionMaster()->Clear(); - i_pet.GetMotionMaster()->MoveIdle(); + m_creature->clearUnitState(UNIT_STAT_FOLLOW); + m_creature->GetMotionMaster()->Clear(); + m_creature->GetMotionMaster()->MoveIdle(); } - i_pet.AttackStop(); + m_creature->AttackStop(); } void PetAI::UpdateAI(const uint32 diff) { - if (!i_pet.isAlive()) + if (!m_creature->isAlive()) return; - Unit* owner = i_pet.GetCharmerOrOwner(); + Unit* owner = m_creature->GetCharmerOrOwner(); if(m_updateAlliesTimer <= diff) // UpdateAllies self set update timer @@ -98,12 +98,12 @@ void PetAI::UpdateAI(const uint32 diff) else m_updateAlliesTimer -= diff; - // i_pet.getVictim() can't be used for check in case stop fighting, i_pet.getVictim() clear at Unit death etc. - if( i_pet.getVictim() ) + // m_creature->getVictim() can't be used for check in case stop fighting, m_creature->getVictim() clear at Unit death etc. + if( m_creature->getVictim() ) { if( _needToStop() ) { - DEBUG_LOG("Pet AI stoped attacking [guid=%u]", i_pet.GetGUIDLow()); + DEBUG_LOG("Pet AI stoped attacking [guid=%u]", m_creature->GetGUIDLow()); _stopAttack(); return; } @@ -114,26 +114,26 @@ void PetAI::UpdateAI(const uint32 diff) { if(me->isInCombat()) _stopAttack(); - else if(owner && i_pet.GetCharmInfo()) //no victim + else if(owner && m_creature->GetCharmInfo()) //no victim { - if(owner->isInCombat() && !(i_pet.HasReactState(REACT_PASSIVE) || i_pet.GetCharmInfo()->HasCommandState(COMMAND_STAY))) + if(owner->isInCombat() && !(m_creature->HasReactState(REACT_PASSIVE) || m_creature->GetCharmInfo()->HasCommandState(COMMAND_STAY))) AttackStart(owner->getAttackerForHelper()); - else if(i_pet.GetCharmInfo()->HasCommandState(COMMAND_FOLLOW) && !i_pet.hasUnitState(UNIT_STAT_FOLLOW)) - i_pet.GetMotionMaster()->MoveFollow(owner,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE); + else if(m_creature->GetCharmInfo()->HasCommandState(COMMAND_FOLLOW) && !m_creature->hasUnitState(UNIT_STAT_FOLLOW)) + m_creature->GetMotionMaster()->MoveFollow(owner,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE); } } if(!me->GetCharmInfo()) return; - if (i_pet.GetGlobalCooldown() == 0 && !i_pet.hasUnitState(UNIT_STAT_CASTING)) + if (m_creature->GetGlobalCooldown() == 0 && !m_creature->hasUnitState(UNIT_STAT_CASTING)) { bool inCombat = me->getVictim(); //Autocast - for (uint8 i = 0; i < i_pet.GetPetAutoSpellSize(); i++) + for (uint8 i = 0; i < m_creature->GetPetAutoSpellSize(); i++) { - uint32 spellID = i_pet.GetPetAutoSpellOnPos(i); + uint32 spellID = m_creature->GetPetAutoSpellOnPos(i); if (!spellID) continue; @@ -153,11 +153,11 @@ void PetAI::UpdateAI(const uint32 diff) continue; } - Spell *spell = new Spell(&i_pet, spellInfo, false, 0); + Spell *spell = new Spell(m_creature, spellInfo, false, 0); - if(inCombat && !i_pet.hasUnitState(UNIT_STAT_FOLLOW) && spell->CanAutoCast(i_pet.getVictim())) + if(inCombat && !m_creature->hasUnitState(UNIT_STAT_FOLLOW) && spell->CanAutoCast(m_creature->getVictim())) { - m_targetSpellStore.push_back(std::make_pair<Unit*, Spell*>(i_pet.getVictim(), spell)); + m_targetSpellStore.push_back(std::make_pair<Unit*, Spell*>(m_creature->getVictim(), spell)); continue; } else @@ -165,7 +165,7 @@ void PetAI::UpdateAI(const uint32 diff) bool spellUsed = false; for(std::set<uint64>::iterator tar = m_AllySet.begin(); tar != m_AllySet.end(); ++tar) { - Unit* Target = ObjectAccessor::GetUnit(i_pet,*tar); + Unit* Target = ObjectAccessor::GetUnit(*m_creature,*tar); //only buff targets that are in combat, unless the spell can only be cast while out of combat if(!Target) @@ -196,19 +196,19 @@ void PetAI::UpdateAI(const uint32 diff) SpellCastTargets targets; targets.setUnitTarget( target ); - if( !i_pet.HasInArc(M_PI, target) ) + if( !m_creature->HasInArc(M_PI, target) ) { - i_pet.SetInFront(target); + m_creature->SetInFront(target); if( target->GetTypeId() == TYPEID_PLAYER ) - i_pet.SendUpdateToPlayer( (Player*)target ); + m_creature->SendUpdateToPlayer( (Player*)target ); if(owner && owner->GetTypeId() == TYPEID_PLAYER) - i_pet.SendUpdateToPlayer( (Player*)owner ); + m_creature->SendUpdateToPlayer( (Player*)owner ); } - i_pet.AddCreatureSpellCooldown(spell->m_spellInfo->Id); - if(i_pet.isPet()) - ((Pet*)&i_pet)->CheckLearning(spell->m_spellInfo->Id); + m_creature->AddCreatureSpellCooldown(spell->m_spellInfo->Id); + if(m_creature->isPet()) + ((Pet*)m_creature)->CheckLearning(spell->m_spellInfo->Id); spell->prepare(&targets); } @@ -222,7 +222,7 @@ void PetAI::UpdateAI(const uint32 diff) void PetAI::UpdateAllies() { - Unit* owner = i_pet.GetCharmerOrOwner(); + Unit* owner = m_creature->GetCharmerOrOwner(); Group *pGroup = NULL; m_updateAlliesTimer = 10*IN_MILISECONDS; //update friendly targets every 10 seconds, lesser checks increase performance @@ -240,7 +240,7 @@ void PetAI::UpdateAllies() return; m_AllySet.clear(); - m_AllySet.insert(i_pet.GetGUID()); + m_AllySet.insert(m_creature->GetGUID()); if(pGroup) //add group { for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next()) |