696 {
697 std::list<Unit*> newTargets;
699
701
702
703 if (newTargets.empty())
704 {
705 if (!targets.empty())
706 {
707 while (1 < targets.size())
708 {
709 std::list<WorldObject*>::iterator itr = targets.begin();
710 advance(itr,
urand(0, targets.size() - 1));
711 targets.erase(itr);
712 }
713 }
714 return;
715 }
716
717
718 targets.clear();
719
720
721 std::list<Unit*>::iterator head = newTargets.begin();
722 advance(head,
urand(0, newTargets.size() - 1));
723 targets.push_back(*head);
724 }
uint32 urand(uint32 min, uint32 max)
Definition Random.cpp:44
Creature * ToCreature()
Definition Object.h:205
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:664