TrinityCore
PoolMgr.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITY_POOLHANDLER_H
19#define TRINITY_POOLHANDLER_H
20
21#include "Define.h"
22#include "SpawnData.h"
23#include <map>
24#include <memory>
25#include <set>
26#include <unordered_map>
27#include <vector>
28
29class Creature;
30class GameObject;
31class Map;
32class Quest;
33
35{
38};
39
41{
43 float chance;
44 PoolObject(uint64 _guid, float _chance);
45};
46
47class Pool // for Pool of Pool case
48{
49};
50
51typedef std::set<uint64> SpawnedPoolObjects;
52typedef std::map<uint64, uint32> SpawnedPoolPools;
53
55{
56 public:
57 explicit SpawnedPoolData(Map* owner);
59
60 SpawnedPoolData(SpawnedPoolData const& right) = delete;
62 SpawnedPoolData& operator=(SpawnedPoolData const& right) = delete;
64
65 Map* GetMap() const { return mOwner; }
66
67 template<typename T>
68 bool IsSpawnedObject(uint64 db_guid_or_pool_id) const;
69
70 bool IsSpawnedObject(SpawnObjectType type, uint64 db_guid_or_pool_id) const;
71
72 uint32 GetSpawnedObjects(uint32 pool_id) const;
73
74 template<typename T>
75 void AddSpawn(uint64 db_guid_or_pool_id, uint32 pool_id);
76
77 template<typename T>
78 void RemoveSpawn(uint64 db_guid_or_pool_id, uint32 pool_id);
79 private:
84};
85
86template <class T>
88{
89 typedef std::vector<PoolObject> PoolObjectList;
90 public:
91 explicit PoolGroup();
93
94 PoolGroup(PoolGroup const& right) = delete;
95 PoolGroup(PoolGroup&& right) = delete;
96 PoolGroup& operator=(PoolGroup const& right) = delete;
97 PoolGroup& operator=(PoolGroup&& right) = delete;
98
99 void SetPoolId(uint32 pool_id) { poolId = pool_id; }
100 bool isEmpty() const { return ExplicitlyChanced.empty() && EqualChanced.empty(); }
101 bool isEmptyDeepCheck() const;
102 void AddEntry(PoolObject& poolitem, uint32 maxentries);
103 bool CheckPool() const;
104 void DespawnObject(SpawnedPoolData& spawns, uint64 guid=0, bool alwaysDeleteRespawnTime = false);
105 void Despawn1Object(SpawnedPoolData& spawns, uint64 guid, bool alwaysDeleteRespawnTime = false, bool saveRespawnTime = true);
106 void SpawnObject(SpawnedPoolData& spawns, uint32 limit, uint64 triggerFrom);
108
111 void RemoveOneRelation(uint32 child_pool_id);
112 uint32 GetPoolId() const { return poolId; }
113 private:
117};
118
120{
121 private:
124
125 public:
126 PoolMgr(PoolMgr const& right) = delete;
127 PoolMgr(PoolMgr&& right) = delete;
128 PoolMgr& operator=(PoolMgr const& right) = delete;
129 PoolMgr& operator=(PoolMgr&& right) = delete;
130
131 static PoolMgr* instance();
132
133 void LoadFromDB();
134
135 void Initialize();
136
137 template<typename T>
138 uint32 IsPartOfAPool(uint64 db_guid_or_pool_id) const;
139 uint32 IsPartOfAPool(SpawnObjectType type, uint64 spawnId) const;
140
141 template<typename T>
142 bool IsSpawnedObject(SpawnedPoolData& spawnedPoolData, uint64 db_guid_or_pool_id) const { return spawnedPoolData.IsSpawnedObject<T>(db_guid_or_pool_id); }
143
144 bool IsEmpty(uint32 pool_id) const;
145 bool CheckPool(uint32 pool_id) const;
146
147 void SpawnPool(SpawnedPoolData& spawnedPoolData, uint32 pool_id);
148 void DespawnPool(SpawnedPoolData& spawnedPoolData, uint32 pool_id, bool alwaysDeleteRespawnTime = false);
149
150 template<typename T>
151 void UpdatePool(SpawnedPoolData& spawnedPoolData, uint32 pool_id, uint64 db_guid_or_pool_id);
152 void UpdatePool(SpawnedPoolData& spawnedPoolData, uint32 pool_id, SpawnObjectType type, uint64 spawnId);
153
154 std::unique_ptr<SpawnedPoolData> InitPoolsForMap(Map* map);
155
156 PoolTemplateData const* GetPoolTemplate(uint16 pool_id) const;
157
158 private:
159 template<typename T>
160 void SpawnPool(SpawnedPoolData& spawnedPoolData, uint32 pool_id, uint64 db_guid_or_pool_id);
161
162 typedef std::unordered_map<uint32, PoolTemplateData> PoolTemplateDataMap;
163 typedef std::unordered_map<uint32, PoolGroup<Creature>> PoolGroupCreatureMap;
164 typedef std::unordered_map<uint32, PoolGroup<GameObject>> PoolGroupGameObjectMap;
165 typedef std::unordered_map<uint32, PoolGroup<Pool>> PoolGroupPoolMap;
166 typedef std::pair<uint64, uint32> SearchPair;
167 typedef std::map<uint64, uint32> SearchMap;
168
176 std::unordered_map<uint32, std::vector<uint32>> mAutoSpawnPoolsPerMap;
177};
178
179#define sPoolMgr PoolMgr::instance()
180
181// Method that tell if the creature is part of a pool and return the pool id if yes
182template<>
183inline uint32 PoolMgr::IsPartOfAPool<Creature>(uint64 db_guid) const
184{
185 SearchMap::const_iterator itr = mCreatureSearchMap.find(db_guid);
186 if (itr != mCreatureSearchMap.end())
187 return itr->second;
188
189 return 0;
190}
191
192// Method that tell if the gameobject is part of a pool and return the pool id if yes
193template<>
194inline uint32 PoolMgr::IsPartOfAPool<GameObject>(uint64 db_guid) const
195{
196 SearchMap::const_iterator itr = mGameobjectSearchMap.find(db_guid);
197 if (itr != mGameobjectSearchMap.end())
198 return itr->second;
199
200 return 0;
201}
202
203// Method that tell if the pool is part of another pool and return the pool id if yes
204template<>
205inline uint32 PoolMgr::IsPartOfAPool<Pool>(uint64 pool_id) const
206{
207 SearchMap::const_iterator itr = mPoolSearchMap.find(pool_id);
208 if (itr != mPoolSearchMap.end())
209 return itr->second;
210
211 return 0;
212}
213
214#endif
#define TC_GAME_API
Definition: Define.h:123
int32_t int32
Definition: Define.h:138
uint64_t uint64
Definition: Define.h:141
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
std::set< uint64 > SpawnedPoolObjects
Definition: PoolMgr.h:51
std::map< uint64, uint32 > SpawnedPoolPools
Definition: PoolMgr.h:52
SpawnObjectType
Definition: SpawnData.h:33
Definition: Map.h:189
void SetPoolId(uint32 pool_id)
Definition: PoolMgr.h:99
void ReSpawn1Object(SpawnedPoolData &spawns, PoolObject *obj)
void Despawn1Object(SpawnedPoolData &spawns, uint64 guid, bool alwaysDeleteRespawnTime=false, bool saveRespawnTime=true)
PoolGroup(PoolGroup const &right)=delete
void RemoveOneRelation(uint32 child_pool_id)
PoolGroup & operator=(PoolGroup const &right)=delete
void Spawn1Object(SpawnedPoolData &spawns, PoolObject *obj)
PoolObjectList ExplicitlyChanced
Definition: PoolMgr.h:115
PoolGroup & operator=(PoolGroup &&right)=delete
uint32 GetPoolId() const
Definition: PoolMgr.h:112
PoolGroup(PoolGroup &&right)=delete
uint32 poolId
Definition: PoolMgr.h:114
void RemoveRespawnTimeFromDB(SpawnedPoolData &spawns, uint64 guid)
std::vector< PoolObject > PoolObjectList
Definition: PoolMgr.h:89
PoolObjectList EqualChanced
Definition: PoolMgr.h:116
bool isEmpty() const
Definition: PoolMgr.h:100
std::pair< uint64, uint32 > SearchPair
Definition: PoolMgr.h:166
void SpawnPool(SpawnedPoolData &spawnedPoolData, uint32 pool_id, uint64 db_guid_or_pool_id)
PoolMgr(PoolMgr &&right)=delete
std::unordered_map< uint32, PoolGroup< Creature > > PoolGroupCreatureMap
Definition: PoolMgr.h:163
PoolMgr(PoolMgr const &right)=delete
std::unordered_map< uint32, PoolTemplateData > PoolTemplateDataMap
Definition: PoolMgr.h:162
PoolMgr & operator=(PoolMgr &&right)=delete
bool IsSpawnedObject(SpawnedPoolData &spawnedPoolData, uint64 db_guid_or_pool_id) const
Definition: PoolMgr.h:142
PoolGroupCreatureMap mPoolCreatureGroups
Definition: PoolMgr.h:170
PoolGroupPoolMap mPoolPoolGroups
Definition: PoolMgr.h:172
std::unordered_map< uint32, PoolGroup< GameObject > > PoolGroupGameObjectMap
Definition: PoolMgr.h:164
SearchMap mGameobjectSearchMap
Definition: PoolMgr.h:174
PoolTemplateDataMap mPoolTemplate
Definition: PoolMgr.h:169
std::unordered_map< uint32, std::vector< uint32 > > mAutoSpawnPoolsPerMap
Definition: PoolMgr.h:176
PoolMgr & operator=(PoolMgr const &right)=delete
std::unordered_map< uint32, PoolGroup< Pool > > PoolGroupPoolMap
Definition: PoolMgr.h:165
uint32 IsPartOfAPool(uint64 db_guid_or_pool_id) const
SearchMap mPoolSearchMap
Definition: PoolMgr.h:175
std::map< uint64, uint32 > SearchMap
Definition: PoolMgr.h:167
PoolGroupGameObjectMap mPoolGameobjectGroups
Definition: PoolMgr.h:171
SearchMap mCreatureSearchMap
Definition: PoolMgr.h:173
Definition: PoolMgr.h:48
SpawnedPoolObjects mSpawnedCreatures
Definition: PoolMgr.h:81
SpawnedPoolObjects mSpawnedGameobjects
Definition: PoolMgr.h:82
SpawnedPoolData(SpawnedPoolData const &right)=delete
SpawnedPoolData(SpawnedPoolData &&right)=delete
Map * GetMap() const
Definition: PoolMgr.h:65
SpawnedPoolData & operator=(SpawnedPoolData const &right)=delete
Map * mOwner
Definition: PoolMgr.h:80
void AddSpawn(uint64 db_guid_or_pool_id, uint32 pool_id)
bool IsSpawnedObject(uint64 db_guid_or_pool_id) const
void RemoveSpawn(uint64 db_guid_or_pool_id, uint32 pool_id)
SpawnedPoolPools mSpawnedPools
Definition: PoolMgr.h:83
SpawnedPoolData & operator=(SpawnedPoolData &&right)=delete
uint64 guid
Definition: PoolMgr.h:42
float chance
Definition: PoolMgr.h:43
PoolObject(uint64 _guid, float _chance)
Definition: PoolMgr.cpp:28
uint32 MaxLimit
Definition: PoolMgr.h:36