569 {
570 std::list<Unit*> newTargets;
572
574
575
576 if (newTargets.empty())
577 {
578 if (!targets.empty())
579 {
580 while (1 < targets.size())
581 {
582 std::list<WorldObject*>::iterator itr = targets.begin();
583 advance(itr,
urand(0, targets.size() - 1));
584 targets.erase(itr);
585 }
586 }
587 return;
588 }
589
590
591 targets.clear();
592
593
594 std::list<Unit*>::iterator head = newTargets.begin();
595 advance(head,
urand(0, newTargets.size() - 1));
596 targets.push_back(*head);
597 }
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