aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game/PetAI.cpp46
-rw-r--r--src/game/PetAI.h3
2 files changed, 20 insertions, 29 deletions
diff --git a/src/game/PetAI.cpp b/src/game/PetAI.cpp
index 7c2889d1ef1..9515cbba46d 100644
--- a/src/game/PetAI.cpp
+++ b/src/game/PetAI.cpp
@@ -120,11 +120,14 @@ void PetAI::UpdateAI(const uint32 diff)
if(!me->GetCharmInfo())
return;
- if (m_creature->GetGlobalCooldown() == 0 && !m_creature->hasUnitState(UNIT_STAT_CASTING))
+ bool inCombat = me->getVictim();
+
+ //Autocast (casted only in combat)
+ if (inCombat && m_creature->GetGlobalCooldown() == 0 && !m_creature->hasUnitState(UNIT_STAT_CASTING))
{
- bool inCombat = me->getVictim();
+ typedef std::vector<std::pair<Unit*, Spell*> > TargetSpellList;
+ TargetSpellList targetSpellStore;
- //Autocast
for (uint8 i = 0; i < m_creature->GetPetAutoSpellSize(); ++i)
{
uint32 spellID = m_creature->GetPetAutoSpellOnPos(i);
@@ -136,22 +139,14 @@ void PetAI::UpdateAI(const uint32 diff)
continue;
// ignore some combinations of combat state and combat/noncombat spells
- if (!inCombat)
- {
- if (!IsPositiveSpell(spellInfo->Id))
- continue;
- }
- else
- {
- if (IsNonCombatSpell(spellInfo))
- continue;
- }
+ if (IsNonCombatSpell(spellInfo))
+ continue;
Spell *spell = new Spell(m_creature, spellInfo, false, 0);
- if(inCombat && !m_creature->hasUnitState(UNIT_STAT_FOLLOW) && spell->CanAutoCast(m_creature->getVictim()))
+ if (!m_creature->hasUnitState(UNIT_STAT_FOLLOW) && spell->CanAutoCast(m_creature->getVictim()))
{
- m_targetSpellStore.push_back(std::make_pair<Unit*, Spell*>(m_creature->getVictim(), spell));
+ targetSpellStore.push_back(std::make_pair<Unit*, Spell*>(m_creature->getVictim(), spell));
continue;
}
else
@@ -167,7 +162,7 @@ void PetAI::UpdateAI(const uint32 diff)
if(spell->CanAutoCast(Target))
{
- m_targetSpellStore.push_back(std::make_pair<Unit*, Spell*>(Target, spell));
+ targetSpellStore.push_back(std::make_pair<Unit*, Spell*>(Target, spell));
spellUsed = true;
break;
}
@@ -178,14 +173,14 @@ void PetAI::UpdateAI(const uint32 diff)
}
//found units to cast on to
- if(!m_targetSpellStore.empty())
+ if (!targetSpellStore.empty())
{
- uint32 index = urand(0, m_targetSpellStore.size() - 1);
+ uint32 index = urand(0, targetSpellStore.size() - 1);
- Spell* spell = m_targetSpellStore[index].second;
- Unit* target = m_targetSpellStore[index].first;
+ Spell* spell = targetSpellStore[index].second;
+ Unit* target = targetSpellStore[index].first;
- m_targetSpellStore.erase(m_targetSpellStore.begin() + index);
+ targetSpellStore.erase(targetSpellStore.begin() + index);
SpellCastTargets targets;
targets.setUnitTarget( target );
@@ -204,11 +199,10 @@ void PetAI::UpdateAI(const uint32 diff)
spell->prepare(&targets);
}
- while (!m_targetSpellStore.empty())
- {
- delete m_targetSpellStore.begin()->second;
- m_targetSpellStore.erase(m_targetSpellStore.begin());
- }
+
+ // deleted cached Spell objects
+ for(TargetSpellList::const_iterator itr = targetSpellStore.begin(); itr != targetSpellStore.end(); ++itr)
+ delete itr->second;
}
}
diff --git a/src/game/PetAI.h b/src/game/PetAI.h
index 67ce6edefe3..918259cd098 100644
--- a/src/game/PetAI.h
+++ b/src/game/PetAI.h
@@ -50,9 +50,6 @@ class TRINITY_DLL_DECL PetAI : public CreatureAI
bool inCombat;
std::set<uint64> m_AllySet;
uint32 m_updateAlliesTimer;
-
- typedef std::pair<Unit*, Spell*> TargetSpellPair;
- std::vector<TargetSpellPair> m_targetSpellStore;
};
#endif