Fix ScriptedAI::SelectUnit to support SELECT_TARGET_NEAREST and SELECT_TARGET_FARTHEST.
Remove duplicate select target function CreatureEventAI::SelectUnit. --HG-- branch : trunk
This commit is contained in:
@@ -296,19 +296,6 @@ enum ChatType
|
|||||||
CHAT_TYPE_ZONE_YELL = 6
|
CHAT_TYPE_ZONE_YELL = 6
|
||||||
};
|
};
|
||||||
|
|
||||||
//Selection method used by SelectTarget (CreatureEventAI)
|
|
||||||
enum AttackingTarget
|
|
||||||
{
|
|
||||||
ATTACKING_TARGET_RANDOM = 0, //Just selects a random target
|
|
||||||
ATTACKING_TARGET_TOPAGGRO, //Selects targes from top aggro to bottom
|
|
||||||
ATTACKING_TARGET_BOTTOMAGGRO, //Selects targets from bottom aggro to top
|
|
||||||
/* not implemented
|
|
||||||
ATTACKING_TARGET_RANDOM_PLAYER, //Just selects a random target (player only)
|
|
||||||
ATTACKING_TARGET_TOPAGGRO_PLAYER, //Selects targes from top aggro to bottom (player only)
|
|
||||||
ATTACKING_TARGET_BOTTOMAGGRO_PLAYER, //Selects targets from bottom aggro to top (player only)
|
|
||||||
*/
|
|
||||||
};
|
|
||||||
|
|
||||||
// GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some platform
|
// GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some platform
|
||||||
#if defined( __GNUC__ )
|
#if defined( __GNUC__ )
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
|||||||
@@ -1121,37 +1121,6 @@ void CreatureEventAI::UpdateAI(const uint32 diff)
|
|||||||
DoMeleeAttackIfReady();
|
DoMeleeAttackIfReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Unit* CreatureEventAI::SelectUnit(AttackingTarget target, uint32 position)
|
|
||||||
{
|
|
||||||
//ThreatList m_threatlist;
|
|
||||||
std::list<HostileReference*>& m_threatlist = m_creature->getThreatManager().getThreatList();
|
|
||||||
std::list<HostileReference*>::iterator i = m_threatlist.begin();
|
|
||||||
std::list<HostileReference*>::reverse_iterator r = m_threatlist.rbegin();
|
|
||||||
|
|
||||||
if (position >= m_threatlist.size() || !m_threatlist.size())
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
switch (target)
|
|
||||||
{
|
|
||||||
case ATTACKING_TARGET_RANDOM:
|
|
||||||
{
|
|
||||||
advance ( i , position + (rand() % (m_threatlist.size() - position ) ));
|
|
||||||
return Unit::GetUnit(*m_creature,(*i)->getUnitGuid());
|
|
||||||
}
|
|
||||||
case ATTACKING_TARGET_TOPAGGRO:
|
|
||||||
{
|
|
||||||
advance ( i , position);
|
|
||||||
return Unit::GetUnit(*m_creature,(*i)->getUnitGuid());
|
|
||||||
}
|
|
||||||
case ATTACKING_TARGET_BOTTOMAGGRO:
|
|
||||||
{
|
|
||||||
advance ( r , position);
|
|
||||||
return Unit::GetUnit(*m_creature,(*r)->getUnitGuid());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline uint32 CreatureEventAI::GetRandActionParam(uint32 rnd, uint32 param1, uint32 param2, uint32 param3)
|
inline uint32 CreatureEventAI::GetRandActionParam(uint32 rnd, uint32 param1, uint32 param2, uint32 param3)
|
||||||
{
|
{
|
||||||
switch (rnd % 3)
|
switch (rnd % 3)
|
||||||
@@ -1183,13 +1152,13 @@ inline Unit* CreatureEventAI::GetTargetByType(uint32 Target, Unit* pActionInvoke
|
|||||||
case TARGET_T_HOSTILE:
|
case TARGET_T_HOSTILE:
|
||||||
return m_creature->getVictim();
|
return m_creature->getVictim();
|
||||||
case TARGET_T_HOSTILE_SECOND_AGGRO:
|
case TARGET_T_HOSTILE_SECOND_AGGRO:
|
||||||
return SelectUnit(ATTACKING_TARGET_TOPAGGRO,1);
|
return SelectTarget(SELECT_TARGET_TOPAGGRO,1);
|
||||||
case TARGET_T_HOSTILE_LAST_AGGRO:
|
case TARGET_T_HOSTILE_LAST_AGGRO:
|
||||||
return SelectUnit(ATTACKING_TARGET_BOTTOMAGGRO,0);
|
return SelectTarget(SELECT_TARGET_BOTTOMAGGRO,0);
|
||||||
case TARGET_T_HOSTILE_RANDOM:
|
case TARGET_T_HOSTILE_RANDOM:
|
||||||
return SelectUnit(ATTACKING_TARGET_RANDOM,0);
|
return SelectTarget(SELECT_TARGET_RANDOM,0);
|
||||||
case TARGET_T_HOSTILE_RANDOM_NOT_TOP:
|
case TARGET_T_HOSTILE_RANDOM_NOT_TOP:
|
||||||
return SelectUnit(ATTACKING_TARGET_RANDOM,1);
|
return SelectTarget(SELECT_TARGET_RANDOM,1);
|
||||||
case TARGET_T_ACTION_INVOKER:
|
case TARGET_T_ACTION_INVOKER:
|
||||||
return pActionInvoker;
|
return pActionInvoker;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -610,7 +610,6 @@ class CreatureEventAI : public CreatureAI
|
|||||||
inline uint32 GetRandActionParam(uint32 rnd, uint32 param1, uint32 param2, uint32 param3);
|
inline uint32 GetRandActionParam(uint32 rnd, uint32 param1, uint32 param2, uint32 param3);
|
||||||
inline int32 GetRandActionParam(uint32 rnd, int32 param1, int32 param2, int32 param3);
|
inline int32 GetRandActionParam(uint32 rnd, int32 param1, int32 param2, int32 param3);
|
||||||
inline Unit* GetTargetByType(uint32 Target, Unit* pActionInvoker);
|
inline Unit* GetTargetByType(uint32 Target, Unit* pActionInvoker);
|
||||||
inline Unit* SelectUnit(AttackingTarget target, uint32 position);
|
|
||||||
|
|
||||||
void DoScriptText(int32 textEntry, WorldObject* pSource, Unit* target);
|
void DoScriptText(int32 textEntry, WorldObject* pSource, Unit* target);
|
||||||
bool CanCast(Unit* Target, SpellEntry const *Spell, bool Triggered);
|
bool CanCast(Unit* Target, SpellEntry const *Spell, bool Triggered);
|
||||||
|
|||||||
@@ -191,6 +191,9 @@ Unit* ScriptedAI::SelectUnit(SelectAggroTarget pTarget, uint32 uiPosition)
|
|||||||
advance (ritr , uiPosition);
|
advance (ritr , uiPosition);
|
||||||
return Unit::GetUnit((*m_creature),(*ritr)->getUnitGuid());
|
return Unit::GetUnit((*m_creature),(*ritr)->getUnitGuid());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return UnitAI::SelectTarget(pTarget, uiPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user