572 {
573 std::list<Unit*> newTargets;
575
577
578
579 if (newTargets.empty())
580 {
581 if (!targets.empty())
582 {
583 while (1 < targets.size())
584 {
585 std::list<WorldObject*>::iterator itr = targets.begin();
586 advance(itr,
urand(0, targets.size() - 1));
587 targets.erase(itr);
588 }
589 }
590 return;
591 }
592
593
594 targets.clear();
595
596
597 std::list<Unit*>::iterator head = newTargets.begin();
598 advance(head,
urand(0, newTargets.size() - 1));
599 targets.push_back(*head);
600 }
uint32 urand(uint32 min, uint32 max)
Definition Random.cpp:44
Creature * ToCreature()
Definition Object.h:212
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:113
UnitAI * GetAI()
Definition Unit.h:699