566 {
567 std::list<Unit*> newTargets;
569
571
572
573 if (newTargets.empty())
574 {
575 if (!targets.empty())
576 {
577 while (1 < targets.size())
578 {
579 std::list<WorldObject*>::iterator itr = targets.begin();
580 advance(itr,
urand(0, targets.size() - 1));
581 targets.erase(itr);
582 }
583 }
584 return;
585 }
586
587
588 targets.clear();
589
590
591 std::list<Unit*>::iterator head = newTargets.begin();
592 advance(head,
urand(0, newTargets.size() - 1));
593 targets.push_back(*head);
594 }
uint32 urand(uint32 min, uint32 max)
Definition Random.cpp:44
Creature * ToCreature()
Definition Object.h:206
Unit * GetCaster()
Definition SpellScript.cpp:401
void SelectTargetList(std::list< Unit * > &targetList, uint32 num, SelectTargetMethod targetType, uint32 position=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
Select the best (up to) <num> targets (in <targetType> order) from the threat list that fulfill the f...
Definition UnitAI.cpp:117
UnitAI * GetAI()
Definition Unit.h:694