mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-19 17:05:44 +01:00
*Update creature AI functions
--HG-- branch : trunk
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user