From 9b9873a074e05cde37a7e67362c7bc3b367dc01f Mon Sep 17 00:00:00 2001 From: NoFantasy Date: Thu, 17 Sep 2009 21:51:18 +0200 Subject: [PATCH] [8507] Check amount of spawned pools before decrement to avoid unexpected result. Also rename variable to more meaningful name. Signed-off-by: NoFantasy --- src/game/PoolHandler.cpp | 13 ++++++++----- src/game/PoolHandler.h | 2 +- src/shared/revision_nr.h | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/game/PoolHandler.cpp b/src/game/PoolHandler.cpp index 6e6a71312..2acab75ed 100644 --- a/src/game/PoolHandler.cpp +++ b/src/game/PoolHandler.cpp @@ -31,7 +31,7 @@ INSTANTIATE_SINGLETON_1(PoolHandler); template PoolGroup::PoolGroup() { - Spawned = 0; + m_SpawnedPoolAmount = 0; } // Method to add a gameobject/creature guid to the proper list depending on pool type and chance value @@ -112,7 +112,9 @@ void PoolGroup::DespawnObject(uint32 guid) Despawn1Object(EqualChanced[i].guid); EqualChanced[i].spawned = false; - Spawned--; + + if (m_SpawnedPoolAmount > 0) + --m_SpawnedPoolAmount; } } } @@ -186,14 +188,14 @@ void PoolGroup::SpawnObject(uint32 limit, bool cache) Despawn1Object(CacheValue); CacheValue = Spawn1Object(roll); } - else if (limit < EqualChanced.size() && Spawned < limit) + else if (limit < EqualChanced.size() && m_SpawnedPoolAmount < limit) { std::vector IndexList; for (size_t i = 0; i < EqualChanced.size(); ++i) if (!EqualChanced[i].spawned) IndexList.push_back(i); - while (Spawned < limit && IndexList.size() > 0) + while (m_SpawnedPoolAmount < limit && IndexList.size() > 0) { uint32 roll = urand(1, IndexList.size()) - 1; uint32 index = IndexList[roll]; @@ -207,7 +209,8 @@ void PoolGroup::SpawnObject(uint32 limit, bool cache) EqualChanced[index].spawned = ReSpawn1Object(EqualChanced[index].guid); if (EqualChanced[index].spawned) - ++Spawned; // limited group use the Spawned variable to store the number of actualy spawned creatures + ++m_SpawnedPoolAmount; // limited group use the Spawned variable to store the number of actualy spawned creatures + std::vector::iterator itr = IndexList.begin()+roll; IndexList.erase(itr); } diff --git a/src/game/PoolHandler.h b/src/game/PoolHandler.h index 8b6c82d11..7efdae480 100644 --- a/src/game/PoolHandler.h +++ b/src/game/PoolHandler.h @@ -59,7 +59,7 @@ class PoolGroup uint32 CacheValue; // Store the guid of the removed creature/gameobject during a pool update PoolObjectList ExplicitlyChanced; PoolObjectList EqualChanced; - uint32 Spawned; // Used to know the number of spawned objects + uint32 m_SpawnedPoolAmount; // Used to know the number of spawned objects }; class Pool // for Pool of Pool case diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 833cca0de..4e7b7a18c 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "8506" + #define REVISION_NR "8507" #endif // __REVISION_NR_H__