Hatelist crash fix

This commit is contained in:
SecretsOTheP
2014-04-20 20:54:21 -04:00
parent c16fe3c810
commit 8aa13b51f4
2 changed files with 12 additions and 0 deletions
+11
View File
@@ -445,6 +445,17 @@ Mob *HateList::GetMostHate(){
Mob *HateList::GetRandom()
{
int count = list.size();
if(count == 0) //If we don't have any entries it'll crash getting a random 0, -1 position.
return NULL;
if(count == 1) //No need to do all that extra work if we only have one hate entry
{
if(*list.begin()) // Just in case tHateEntry is invalidated somehow...
return (*list.begin())->ent;
return NULL;
}
auto iterator = list.begin();
int random = MakeRandomInt(0, count - 1);
for (int i = 0; i < random; i++)