aboutsummaryrefslogtreecommitdiff
path: root/src/game/PetAI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/PetAI.cpp')
-rw-r--r--src/game/PetAI.cpp98
1 files changed, 44 insertions, 54 deletions
diff --git a/src/game/PetAI.cpp b/src/game/PetAI.cpp
index 75c1aa06c20..7851ee6773f 100644
--- a/src/game/PetAI.cpp
+++ b/src/game/PetAI.cpp
@@ -1,7 +1,7 @@
/*
- * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
+ * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
- * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
+ * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,7 +22,7 @@
#include "Errors.h"
#include "Pet.h"
#include "Player.h"
-#include "Database/DBCStores.h"
+#include "DBCStores.h"
#include "Spell.h"
#include "ObjectAccessor.h"
#include "SpellMgr.h"
@@ -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,43 @@ 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())
- return;
-
- Unit* owner = i_pet.GetCharmerOrOwner();
+ Unit* owner = m_creature->GetCharmerOrOwner();
if(m_updateAlliesTimer <= diff)
// UpdateAllies self set update timer
@@ -98,42 +95,37 @@ 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;
}
DoMeleeAttackIfReady();
}
- else
+ else if(owner && m_creature->GetCharmInfo()) //no victim
{
- if(me->isInCombat())
- _stopAttack();
- else if(owner && i_pet.GetCharmInfo()) //no victim
- {
- if(owner->isInCombat() && !(i_pet.HasReactState(REACT_PASSIVE) || i_pet.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);
- }
+ if(owner->isInCombat() && !(m_creature->HasReactState(REACT_PASSIVE) || m_creature->GetCharmInfo()->HasCommandState(COMMAND_STAY)))
+ AttackStart(owner->getAttackerForHelper());
+ 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,19 +145,19 @@ 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
{
bool spellUsed = false;
- for(std::set<uint64>::iterator tar = m_AllySet.begin(); tar != m_AllySet.end(); ++tar)
+ for(std::set<uint64>::const_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 +188,17 @@ 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);
spell->prepare(&targets);
}
@@ -222,10 +212,10 @@ void PetAI::UpdateAI(const uint32 diff)
void PetAI::UpdateAllies()
{
- Unit* owner = i_pet.GetCharmerOrOwner();
+ Unit* owner = m_creature->GetCharmerOrOwner();
Group *pGroup = NULL;
- m_updateAlliesTimer = 10000; //update friendly targets every 10 seconds, lesser checks increase performance
+ m_updateAlliesTimer = 10*IN_MILISECONDS; //update friendly targets every 10 seconds, lesser checks increase performance
if(!owner)
return;
@@ -240,7 +230,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())