Refactor Creature::SelectNearestTarget(float dist)
This function is used in many scripts to find the nearest enemy within the given distance. However, it had an implicit limit to the ATTACK_DISTANCE. so in many case the "dist" was in fact just ignored. In other case, the ATTACK_DISTANCE is required. So 2 functions are necessary to avoid ambiguities. The refactoring is the split of the function in 2: SelectNearestTarget and SelectNearestTargetInAttackDistance. --HG-- branch : trunk
This commit is contained in:
@@ -258,12 +258,11 @@ struct boss_twinemperorsAI : public ScriptedAI
|
||||
{
|
||||
AfterTeleport = false;
|
||||
me->clearUnitState(UNIT_STAT_STUNNED);
|
||||
Unit *nearu = me->SelectNearestTarget(100);
|
||||
//DoYell(nearu->GetName(), LANG_UNIVERSAL, 0);
|
||||
if (nearu)
|
||||
if (Unit *nearu = me->SelectNearestTarget(100))
|
||||
{
|
||||
//DoYell(nearu->GetName(), LANG_UNIVERSAL, 0);
|
||||
AttackStart(nearu);
|
||||
me->getThreatManager().addThreat(nearu, 10000);
|
||||
me->AddThreat(nearu, 10000);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -236,6 +236,16 @@ struct boss_four_horsemenAI : public BossAI
|
||||
nextWP = id + 1;
|
||||
}
|
||||
|
||||
// switch to "who" if nearer than current target.
|
||||
void SelectNearestTarget(Unit *who)
|
||||
{
|
||||
if (me->getVictim() && me->GetDistanceOrder(who, me->getVictim()) && me->canAttack(who))
|
||||
{
|
||||
me->getThreatManager().modifyThreatPercent(me->getVictim(), -100);
|
||||
me->AddThreat(who, 1000000.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void MoveInLineOfSight(Unit *who)
|
||||
{
|
||||
BossAI::MoveInLineOfSight(who);
|
||||
|
||||
@@ -408,7 +408,7 @@ struct boss_alarAI : public ScriptedAI
|
||||
else
|
||||
{
|
||||
Unit *pTarget = NULL;
|
||||
pTarget = me->SelectNearestTarget(5);
|
||||
pTarget = me->SelectNearestTargetInAttackDistance(5);
|
||||
if (pTarget)
|
||||
me->AI()->AttackStart(pTarget);
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user