diff options
-rw-r--r-- | src/bindings/scripts/include/sc_creature.cpp | 18 | ||||
-rw-r--r-- | src/bindings/scripts/include/sc_creature.h | 49 | ||||
-rw-r--r-- | src/game/CreatureAI.cpp | 2 |
3 files changed, 55 insertions, 14 deletions
diff --git a/src/bindings/scripts/include/sc_creature.cpp b/src/bindings/scripts/include/sc_creature.cpp index 1942fdadd71..258c7627dce 100644 --- a/src/bindings/scripts/include/sc_creature.cpp +++ b/src/bindings/scripts/include/sc_creature.cpp @@ -118,15 +118,7 @@ void ScriptedAI::EnterEvadeMode() m_creature->SetLootRecipient(NULL); if(m_creature->isAlive()) - { - if(Unit* owner = m_creature->GetOwner()) - { - if(owner->isAlive()) - m_creature->GetMotionMaster()->MoveFollow(owner,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE); - } - else - m_creature->GetMotionMaster()->MoveTargetedHome(); - } + m_creature->GetMotionMaster()->MoveTargetedHome(); Reset(); } @@ -288,7 +280,7 @@ Unit* ScriptedAI::SelectUnit(SelectAggroTarget targetType, uint32 position, floa std::list<HostilReference*>::iterator itr = m_threatlist.begin(); for(; itr!= m_threatlist.end(); ++itr) { - Unit *target = Unit::GetUnit(*m_creature, (*itr)->getUnitGuid()); + Unit *target = (*itr)->getTarget(); if(!target || playerOnly && target->GetTypeId() != TYPEID_PLAYER || dist && !m_creature->IsWithinCombatRange(target, dist)) @@ -334,7 +326,7 @@ Unit* ScriptedAI::SelectUnit(SelectAggroTarget targetType, uint32 position, floa advance(i, position + rand()%(m_threatlist.size() - position)); } - target = Unit::GetUnit(*m_creature,(*i)->getUnitGuid()); + target = (*i)->getTarget(); if(!target || playerOnly && target->GetTypeId() != TYPEID_PLAYER || dist && !m_creature->IsWithinCombatRange(target, dist)) @@ -360,7 +352,7 @@ void ScriptedAI::SelectUnitList(std::list<Unit*> &targetList, uint32 num, Select std::list<HostilReference*>::iterator itr = m_threatlist.begin(); for(; itr!= m_threatlist.end(); ++itr) { - Unit *target = Unit::GetUnit(*m_creature, (*itr)->getUnitGuid()); + Unit *target = (*itr)->getTarget(); if(!target || playerOnly && target->GetTypeId() != TYPEID_PLAYER || dist && !m_creature->IsWithinCombatRange(target, dist)) @@ -393,7 +385,7 @@ void ScriptedAI::SelectUnitList(std::list<Unit*> &targetList, uint32 num, Select advance(i, rand()%m_threatlist.size()); } - target = Unit::GetUnit(*m_creature,(*i)->getUnitGuid()); + target = (*i)->getTarget(); m_threatlist.erase(i); if(!target || playerOnly && target->GetTypeId() != TYPEID_PLAYER diff --git a/src/bindings/scripts/include/sc_creature.h b/src/bindings/scripts/include/sc_creature.h index dfdb23eeb14..638b6926a27 100644 --- a/src/bindings/scripts/include/sc_creature.h +++ b/src/bindings/scripts/include/sc_creature.h @@ -13,6 +13,55 @@ #define HEROIC(n,h) (HeroicMode ? h : n) +template<class T> +inline +const T& RAND(const T& v1, const T& v2) +{ + return rand()%2 ? v1 : v2; +} + +template<class T> +inline +const T& RAND(const T& v1, const T& v2, const T& v3) +{ + switch(rand()%3) + { + default: + case 0: return v1; + case 1: return v2; + case 2: return v3; + } +} + +template<class T> +inline +const T& RAND(const T& v1, const T& v2, const T& v3, const T& v4) +{ + switch(rand()%4) + { + default: + case 0: return v1; + case 1: return v2; + case 2: return v3; + case 3: return v4; + } +} + +template<class T> +inline +const T& RAND(const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) +{ + switch(rand()%4) + { + default: + case 0: return v1; + case 1: return v2; + case 2: return v3; + case 3: return v4; + case 4: return v5; + } +} + float GetSpellMaxRangeForHostile(uint32 id); class SummonList : private std::list<uint64> diff --git a/src/game/CreatureAI.cpp b/src/game/CreatureAI.cpp index 6f0b5949236..5fd35150b52 100644 --- a/src/game/CreatureAI.cpp +++ b/src/game/CreatureAI.cpp @@ -98,7 +98,7 @@ void CreatureAI::DoZoneInCombat(Creature* creature) } } - if (!creature->CanHaveThreatList() || creature->getThreatManager().isThreatListEmpty()) + if (!creature->CanHaveThreatList() || !creature->getVictim()) { sLog.outError("DoZoneInCombat called for creature that either cannot have threat list or has empty threat list (creature entry = %d)", creature->GetTypeId() == TYPEID_UNIT ? ((Creature*)creature)->GetEntry() : 0); return; |