673 {
674 std::list<Unit*> newTargets;
676
678
679
680 if (newTargets.empty())
681 {
682 if (!targets.empty())
683 {
684 while (1 < targets.size())
685 {
686 std::list<WorldObject*>::iterator itr = targets.begin();
687 advance(itr,
urand(0, targets.size() - 1));
688 targets.erase(itr);
689 }
690 }
691 return;
692 }
693
694
695 targets.clear();
696
697
698 std::list<Unit*>::iterator head = newTargets.begin();
699 advance(head,
urand(0, newTargets.size() - 1));
700 targets.push_back(*head);
701 }
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:115
UnitAI * GetAI()
Definition Unit.h:678