diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index bcab2f2a6..616b8db38 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -375,9 +375,9 @@ void Creature::Update(uint32 diff) //Call AI respawn virtual function i_AI->JustRespawned(); - uint16 poolid = sPoolMgr.IsPartOfAPool(GetGUIDLow(), GetTypeId()); + uint16 poolid = GetDBTableGUIDLow() ? sPoolMgr.IsPartOfAPool(GetDBTableGUIDLow()) : 0; if (poolid) - sPoolMgr.UpdatePool(poolid, GetGUIDLow(), TYPEID_UNIT); + sPoolMgr.UpdatePool(poolid, GetDBTableGUIDLow()); else GetMap()->Add(this); } diff --git a/src/game/GameEventMgr.cpp b/src/game/GameEventMgr.cpp index e9f670a3d..3bcc3d395 100644 --- a/src/game/GameEventMgr.cpp +++ b/src/game/GameEventMgr.cpp @@ -580,11 +580,7 @@ void GameEventMgr::GameEventSpawn(int16 event_id) } for (IdList::iterator itr = mGameEventPoolIds[internal_event_id].begin();itr != mGameEventPoolIds[internal_event_id].end();++itr) - { - sPoolMgr.SpawnPool(*itr, 0, 0); - sPoolMgr.SpawnPool(*itr, 0, TYPEID_GAMEOBJECT); - sPoolMgr.SpawnPool(*itr, 0, TYPEID_UNIT); - } + sPoolMgr.SpawnPool(*itr); } void GameEventMgr::GameEventUnspawn(int16 event_id) diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp index b227e208b..e73b79389 100644 --- a/src/game/GameObject.cpp +++ b/src/game/GameObject.cpp @@ -258,9 +258,9 @@ void GameObject::Update(uint32 /*p_time*/) return; } // respawn timer - uint16 poolid = sPoolMgr.IsPartOfAPool(GetGUIDLow(), TYPEID_GAMEOBJECT); + uint16 poolid = GetDBTableGUIDLow() ? sPoolMgr.IsPartOfAPool(GetDBTableGUIDLow()) : 0; if (poolid) - sPoolMgr.UpdatePool(poolid, GetGUIDLow(), TYPEID_GAMEOBJECT); + sPoolMgr.UpdatePool(poolid, GetDBTableGUIDLow()); else GetMap()->Add(this); break; @@ -473,9 +473,9 @@ void GameObject::Delete() SetGoState(GO_STATE_READY); SetUInt32Value(GAMEOBJECT_FLAGS, GetGOInfo()->flags); - uint16 poolid = sPoolMgr.IsPartOfAPool(GetGUIDLow(), TYPEID_GAMEOBJECT); + uint16 poolid = GetDBTableGUIDLow() ? sPoolMgr.IsPartOfAPool(GetDBTableGUIDLow()) : 0; if (poolid) - sPoolMgr.UpdatePool(poolid, GetGUIDLow(), TYPEID_GAMEOBJECT); + sPoolMgr.UpdatePool(poolid, GetDBTableGUIDLow()); else AddObjectToRemoveList(); } diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index a091dac3c..8a378611b 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -472,8 +472,8 @@ bool ChatHandler::HandleGameObjectTargetCommand(const char* args) z = fields[4].GetFloat(); o = fields[5].GetFloat(); mapid = fields[6].GetUInt16(); - pool_id = sPoolMgr.IsPartOfAPool(lowguid, TYPEID_GAMEOBJECT); - if (!pool_id || (pool_id && sPoolMgr.IsSpawnedObject(pool_id, lowguid, TYPEID_GAMEOBJECT))) + pool_id = sPoolMgr.IsPartOfAPool(lowguid); + if (!pool_id || (pool_id && sPoolMgr.IsSpawnedObject(pool_id, lowguid))) found = true; } while( result->NextRow() && (!found) ); diff --git a/src/game/PoolManager.cpp b/src/game/PoolManager.cpp index 434e246a7..c8abdf63f 100644 --- a/src/game/PoolManager.cpp +++ b/src/game/PoolManager.cpp @@ -303,9 +303,7 @@ bool PoolGroup::Spawn1Object(uint32 guid) template <> bool PoolGroup::Spawn1Object(uint32 child_pool_id) { - sPoolMgr.SpawnPool(child_pool_id, 0, 0); - sPoolMgr.SpawnPool(child_pool_id, 0, TYPEID_GAMEOBJECT); - sPoolMgr.SpawnPool(child_pool_id, 0, TYPEID_UNIT); + sPoolMgr.SpawnPool(child_pool_id); return true; } @@ -634,9 +632,7 @@ void PoolManager::Initialize() sLog.outErrorDb("Pool Id (%u) has all creatures or gameobjects with explicit chance sum <>100 and no equal chance defined. The pool system cannot pick one to spawn.", pool_entry); continue; } - SpawnPool(pool_entry, 0, 0); - SpawnPool(pool_entry, 0, TYPEID_GAMEOBJECT); - SpawnPool(pool_entry, 0, TYPEID_UNIT); + SpawnPool(pool_entry); count++; } while (result->NextRow()); delete result; @@ -646,23 +642,37 @@ void PoolManager::Initialize() } // Call to spawn a pool, if cache if true the method will spawn only if cached entry is different -// If it's same, the gameobject/creature is respawned only (added back to map) -void PoolManager::SpawnPool(uint16 pool_id, uint32 guid, uint32 type) +// If it's same, the creature is respawned only (added back to map) +template<> +void PoolManager::SpawnPool(uint16 pool_id, uint32 db_guid) { - switch (type) - { - case TYPEID_UNIT: - if (!mPoolCreatureGroups[pool_id].isEmpty()) - mPoolCreatureGroups[pool_id].SpawnObject(mPoolTemplate[pool_id].MaxLimit, guid); - break; - case TYPEID_GAMEOBJECT: - if (!mPoolGameobjectGroups[pool_id].isEmpty()) - mPoolGameobjectGroups[pool_id].SpawnObject(mPoolTemplate[pool_id].MaxLimit, guid); - break; - default: - if (!mPoolPoolGroups[pool_id].isEmpty()) - mPoolPoolGroups[pool_id].SpawnObject(mPoolTemplate[pool_id].MaxLimit, guid); - } + if (!mPoolCreatureGroups[pool_id].isEmpty()) + mPoolCreatureGroups[pool_id].SpawnObject(mPoolTemplate[pool_id].MaxLimit, db_guid); +} + +// Call to spawn a pool, if cache if true the method will spawn only if cached entry is different +// If it's same, the gameobject is respawned only (added back to map) +template<> +void PoolManager::SpawnPool(uint16 pool_id, uint32 db_guid) +{ + if (!mPoolGameobjectGroups[pool_id].isEmpty()) + mPoolGameobjectGroups[pool_id].SpawnObject(mPoolTemplate[pool_id].MaxLimit, db_guid); +} + +// Call to spawn a pool, if cache if true the method will spawn only if cached entry is different +// If it's same, the pool is respawned only +template<> +void PoolManager::SpawnPool(uint16 pool_id, uint32 sub_pool_id) +{ + if (!mPoolPoolGroups[pool_id].isEmpty()) + mPoolPoolGroups[pool_id].SpawnObject(mPoolTemplate[pool_id].MaxLimit, sub_pool_id); +} + +void PoolManager::SpawnPool( uint16 pool_id ) +{ + SpawnPool(pool_id, 0); + SpawnPool(pool_id, 0); + SpawnPool(pool_id, 0); } // Call to despawn a pool, all gameobjects/creatures in this pool are removed @@ -678,41 +688,6 @@ void PoolManager::DespawnPool(uint16 pool_id) mPoolPoolGroups[pool_id].DespawnObject(); } -// Call to update the pool when a gameobject/creature part of pool [pool_id] is ready to respawn -// Here we cache only the creature/gameobject whose guid is passed as parameter -// Then the spawn pool call will use this cache to decide -void PoolManager::UpdatePool(uint16 pool_id, uint32 guid, uint32 type) -{ - if (uint16 motherpoolid = IsPartOfAPool(pool_id, 0)) - SpawnPool(motherpoolid, 0, 0); - else - SpawnPool(pool_id, guid, type); -} - -// Method that tell if the gameobject/creature is part of a pool and return the pool id if yes -uint16 PoolManager::IsPartOfAPool(uint32 guid, uint32 type) const -{ - if (type == 0) // pool of pool - { - SearchMap::const_iterator itr = mPoolSearchMap.find(guid); - if (itr != mPoolSearchMap.end()) - return itr->second; - } - else if (type == TYPEID_GAMEOBJECT) - { - SearchMap::const_iterator itr = mGameobjectSearchMap.find(guid); - if (itr != mGameobjectSearchMap.end()) - return itr->second; - } - else // creature - { - SearchMap::const_iterator itr = mCreatureSearchMap.find(guid); - if (itr != mCreatureSearchMap.end()) - return itr->second; - } - return 0; -} - // Method that check chance integrity of the creatures and gameobjects in this pool bool PoolManager::CheckPool(uint16 pool_id) const { @@ -722,15 +697,45 @@ bool PoolManager::CheckPool(uint16 pool_id) const mPoolPoolGroups[pool_id].CheckPool(); } -// Method that tell if a creature or gameobject in pool_id is spawned currently -bool PoolManager::IsSpawnedObject(uint16 pool_id, uint32 guid, uint32 type) const +// Method that tell if a creature in pool_id is spawned currently +template<> +bool PoolManager::IsSpawnedObject(uint16 pool_id, uint32 db_guid) const { if (pool_id > max_pool_id) return false; - if (type == 0) - return mPoolPoolGroups[pool_id].IsSpawnedObject(guid); - else if (type == TYPEID_GAMEOBJECT) - return mPoolGameobjectGroups[pool_id].IsSpawnedObject(guid); - else - return mPoolCreatureGroups[pool_id].IsSpawnedObject(guid); + return mPoolCreatureGroups[pool_id].IsSpawnedObject(db_guid); } + +// Method that tell if a gameobject in pool_id is spawned currently +template<> +bool PoolManager::IsSpawnedObject(uint16 pool_id, uint32 db_guid) const +{ + if (pool_id > max_pool_id) + return false; + return mPoolGameobjectGroups[pool_id].IsSpawnedObject(db_guid); +} + +// Method that tell if a pool in pool_id is spawned currently +template<> +bool PoolManager::IsSpawnedObject(uint16 pool_id, uint32 sub_pool_id) const +{ + if (pool_id > max_pool_id) + return false; + return mPoolPoolGroups[pool_id].IsSpawnedObject(sub_pool_id); +} + +// Call to update the pool when a gameobject/creature part of pool [pool_id] is ready to respawn +// Here we cache only the creature/gameobject whose guid is passed as parameter +// Then the spawn pool call will use this cache to decide +template +void PoolManager::UpdatePool(uint16 pool_id, uint32 db_guid_or_pool_id) +{ + if (uint16 motherpoolid = IsPartOfAPool(pool_id)) + SpawnPool(motherpoolid, 0); + else + SpawnPool(pool_id, db_guid_or_pool_id); +} + +template void PoolManager::UpdatePool(uint16 pool_id, uint32 db_guid_or_pool_id); +template void PoolManager::UpdatePool(uint16 pool_id, uint32 db_guid_or_pool_id); +template void PoolManager::UpdatePool(uint16 pool_id, uint32 db_guid_or_pool_id); diff --git a/src/game/PoolManager.h b/src/game/PoolManager.h index 14a33f255..01e333358 100644 --- a/src/game/PoolManager.h +++ b/src/game/PoolManager.h @@ -70,16 +70,28 @@ class PoolManager public: PoolManager(); ~PoolManager() {}; + void LoadFromDB(); - uint16 IsPartOfAPool(uint32 guid, uint32 type) const; - bool IsSpawnedObject(uint16 pool_id, uint32 guid, uint32 type) const; - bool CheckPool(uint16 pool_id) const; - void SpawnPool(uint16 pool_id, uint32 guid, uint32 type); - void DespawnPool(uint16 pool_id); - void UpdatePool(uint16 pool_id, uint32 guid, uint32 type); void Initialize(); + template + uint16 IsPartOfAPool(uint32 db_guid_or_pool_id) const; + + template + bool IsSpawnedObject(uint16 pool_id, uint32 db_guid_or_pool_id) const; + + bool CheckPool(uint16 pool_id) const; + + void SpawnPool(uint16 pool_id); + void DespawnPool(uint16 pool_id); + + template + void UpdatePool(uint16 pool_id, uint32 db_guid_or_pool_id); + protected: + template + void SpawnPool(uint16 pool_id, uint32 db_guid_or_pool_id); + uint16 max_pool_id; typedef std::vector PoolTemplateDataMap; typedef std::vector > PoolGroupCreatureMap; @@ -92,6 +104,8 @@ class PoolManager PoolGroupCreatureMap mPoolCreatureGroups; PoolGroupGameObjectMap mPoolGameobjectGroups; PoolGroupPoolMap mPoolPoolGroups; + + // static maps DB low guid -> pool id SearchMap mCreatureSearchMap; SearchMap mGameobjectSearchMap; SearchMap mPoolSearchMap; @@ -99,4 +113,38 @@ class PoolManager }; #define sPoolMgr MaNGOS::Singleton::Instance() + +// Method that tell if the creature is part of a pool and return the pool id if yes +template<> +inline uint16 PoolManager::IsPartOfAPool(uint32 db_guid) const +{ + SearchMap::const_iterator itr = mCreatureSearchMap.find(db_guid); + if (itr != mCreatureSearchMap.end()) + return itr->second; + + return 0; +} + +// Method that tell if the gameobject is part of a pool and return the pool id if yes +template<> +inline uint16 PoolManager::IsPartOfAPool(uint32 db_guid) const +{ + SearchMap::const_iterator itr = mGameobjectSearchMap.find(db_guid); + if (itr != mGameobjectSearchMap.end()) + return itr->second; + + return 0; +} + +// Method that tell if the pool is part of another pool and return the pool id if yes +template<> +inline uint16 PoolManager::IsPartOfAPool(uint32 pool_id) const +{ + SearchMap::const_iterator itr = mPoolSearchMap.find(pool_id); + if (itr != mPoolSearchMap.end()) + return itr->second; + + return 0; +} + #endif diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index c7dab97d1..3c074d5ce 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 "9145" + #define REVISION_NR "9146" #endif // __REVISION_NR_H__