diff options
Diffstat (limited to 'src/game/UnitAI.cpp')
-rw-r--r-- | src/game/UnitAI.cpp | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/src/game/UnitAI.cpp b/src/game/UnitAI.cpp index 728e6f36916..a295d2d29b7 100644 --- a/src/game/UnitAI.cpp +++ b/src/game/UnitAI.cpp @@ -17,31 +17,26 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - #include "UnitAI.h" #include "Player.h" #include "Creature.h" #include "SpellAuras.h" #include "SpellMgr.h" #include "CreatureAIImpl.h" - void UnitAI::AttackStart(Unit *victim) { if(victim && me->Attack(victim, true)) me->GetMotionMaster()->MoveChase(victim); } - void UnitAI::AttackStartCaster(Unit *victim, float dist) { if(victim && me->Attack(victim, false)) me->GetMotionMaster()->MoveChase(victim, dist); } - void UnitAI::DoMeleeAttackIfReady() { if(me->hasUnitState(UNIT_STAT_CASTING)) return; - //Make sure our attack is ready and we aren't currently casting before checking distance if (me->isAttackReady()) { @@ -62,12 +57,10 @@ void UnitAI::DoMeleeAttackIfReady() } } } - bool UnitAI::DoSpellAttackIfReady(uint32 spell) { if(me->hasUnitState(UNIT_STAT_CASTING)) return true; - if(me->isAttackReady()) { if(me->IsWithinCombatRange(me->getVictim(), GetSpellMaxRange(spell, false))) @@ -80,15 +73,12 @@ bool UnitAI::DoSpellAttackIfReady(uint32 spell) } return true; } - inline bool SelectTargetHelper(const Unit * me, const Unit * target, const bool &playerOnly, const float &dist, const int32 &aura) { if(playerOnly && (!target || target->GetTypeId() != TYPEID_PLAYER)) return false; - if(dist && (!me || !target || !me->IsWithinCombatRange(target, dist))) return false; - if(aura) { if(aura > 0) @@ -102,10 +92,8 @@ inline bool SelectTargetHelper(const Unit * me, const Unit * target, const bool return false; } } - return true; } - struct TargetDistanceOrder : public std::binary_function<const Unit *, const Unit *, bool> { const Unit * me; @@ -116,7 +104,6 @@ struct TargetDistanceOrder : public std::binary_function<const Unit *, const Uni return (me->GetExactDistSq(_Left) < me->GetExactDistSq(_Right)); } }; - Unit* UnitAI::SelectTarget(SelectAggroTarget targetType, uint32 position, float dist, bool playerOnly, int32 aura) { if(targetType == SELECT_TARGET_NEAREST || targetType == SELECT_TARGET_FARTHEST) @@ -124,17 +111,13 @@ Unit* UnitAI::SelectTarget(SelectAggroTarget targetType, uint32 position, float std::list<HostilReference*> &m_threatlist = me->getThreatManager().getThreatList(); if(position >= m_threatlist.size()) return NULL; - std::list<Unit*> targetList; for(std::list<HostilReference*>::iterator itr = m_threatlist.begin(); itr!= m_threatlist.end(); ++itr) if(SelectTargetHelper(me, (*itr)->getTarget(), playerOnly, dist, aura)) targetList.push_back((*itr)->getTarget()); - if(position >= targetList.size()) return NULL; - targetList.sort(TargetDistanceOrder(me)); - if(targetType == SELECT_TARGET_NEAREST) { std::list<Unit*>::iterator i = targetList.begin(); @@ -176,17 +159,14 @@ Unit* UnitAI::SelectTarget(SelectAggroTarget targetType, uint32 position, float } } } - if(SelectTargetHelper(me, (*i)->getTarget(), playerOnly, dist, aura)) return (*i)->getTarget(); else m_threatlist.erase(i); } } - return NULL; } - void UnitAI::SelectTargetList(std::list<Unit*> &targetList, uint32 num, SelectAggroTarget targetType, float dist, bool playerOnly, int32 aura) { if(targetType == SELECT_TARGET_NEAREST || targetType == SELECT_TARGET_FARTHEST) @@ -194,11 +174,9 @@ void UnitAI::SelectTargetList(std::list<Unit*> &targetList, uint32 num, SelectAg std::list<HostilReference*> &m_threatlist = me->getThreatManager().getThreatList(); if(m_threatlist.empty()) return; - for(std::list<HostilReference*>::iterator itr = m_threatlist.begin(); itr!= m_threatlist.end(); ++itr) if(SelectTargetHelper(me, (*itr)->getTarget(), playerOnly, dist, aura)) targetList.push_back((*itr)->getTarget()); - targetList.sort(TargetDistanceOrder(me)); targetList.resize(num); if(targetType == SELECT_TARGET_FARTHEST) @@ -221,7 +199,6 @@ void UnitAI::SelectTargetList(std::list<Unit*> &targetList, uint32 num, SelectAg if(targetType == SELECT_TARGET_RANDOM) advance(i, rand()%m_threatlist.size()); } - if(SelectTargetHelper(me, (*i)->getTarget(), playerOnly, dist, aura)) { targetList.push_back((*i)->getTarget()); @@ -231,12 +208,10 @@ void UnitAI::SelectTargetList(std::list<Unit*> &targetList, uint32 num, SelectAg } } } - float UnitAI::DoGetSpellMaxRange(uint32 spellId, bool positive) { return GetSpellMaxRange(spellId, positive); } - void UnitAI::DoCast(uint32 spellId) { Unit *target = NULL; @@ -270,36 +245,28 @@ void UnitAI::DoCast(uint32 spellId) break; } } - if(target) me->CastSpell(target, spellId, false); } - #define UPDATE_TARGET(a) {if(AIInfo->target<a) AIInfo->target=a;} - void UnitAI::FillAISpellInfo() { AISpellInfo = new AISpellInfoType[GetSpellStore()->GetNumRows()]; - AISpellInfoType *AIInfo = AISpellInfo; const SpellEntry * spellInfo; - for(uint32 i = 0; i < GetSpellStore()->GetNumRows(); ++i, ++AIInfo) { spellInfo = GetSpellStore()->LookupEntry(i); if(!spellInfo) continue; - if(spellInfo->Attributes & SPELL_ATTR_CASTABLE_WHILE_DEAD) AIInfo->condition = AICOND_DIE; else if(IsPassiveSpell(i) || GetSpellDuration(spellInfo) == -1) AIInfo->condition = AICOND_AGGRO; else AIInfo->condition = AICOND_COMBAT; - if(AIInfo->cooldown < spellInfo->RecoveryTime) AIInfo->cooldown = spellInfo->RecoveryTime; - if(!GetSpellMaxRange(spellInfo, false)) UPDATE_TARGET(AITARGET_SELF) else @@ -307,13 +274,11 @@ void UnitAI::FillAISpellInfo() for(uint32 j = 0; j < 3; ++j) { uint32 targetType = spellInfo->EffectImplicitTargetA[j]; - if(targetType == TARGET_UNIT_TARGET_ENEMY || targetType == TARGET_DST_TARGET_ENEMY) UPDATE_TARGET(AITARGET_VICTIM) else if(targetType == TARGET_UNIT_AREA_ENEMY_DST) UPDATE_TARGET(AITARGET_ENEMY) - if(spellInfo->Effect[j] == SPELL_EFFECT_APPLY_AURA) { if(targetType == TARGET_UNIT_TARGET_ENEMY) @@ -329,14 +294,11 @@ void UnitAI::FillAISpellInfo() AIInfo->maxRange = srange->maxRangeHostile * 3 / 4; } } - //Enable PlayerAI when charmed void PlayerAI::OnCharmed(bool apply) { me->IsAIEnabled = apply; } - void SimpleCharmedAI::UpdateAI(const uint32 /*diff*/) { Creature *charmer = (Creature*)me->GetCharmer(); - //kill self if charm aura has infinite duration if(charmer->IsInEvadeMode()) { @@ -348,10 +310,8 @@ void SimpleCharmedAI::UpdateAI(const uint32 /*diff*/) return; } } - if(!charmer->isInCombat()) me->GetMotionMaster()->MoveFollow(charmer, PET_FOLLOW_DIST, me->GetFollowAngle()); - Unit *target = me->getVictim(); if(!target || !charmer->canAttack(target)) AttackStart(charmer->SelectNearestTarget()); |