TrinityCore
Loading...
Searching...
No Matches
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 "Creature.h"
23#include "GameObject.h"
24#include "SpawnData.h"
25
30
32{
34 float chance;
35 PoolObject(ObjectGuid::LowType _guid, float _chance) : guid(_guid), chance(std::fabs(_chance)) { }
36};
37
38class Pool // for Pool of Pool case
39{
40};
41
42typedef std::set<ObjectGuid::LowType> ActivePoolObjects;
43typedef std::map<uint32, uint32> ActivePoolPools;
44
46{
47 public:
48 template<typename T>
49 bool IsActiveObject(uint32 db_guid_or_pool_id) const;
50
51 uint32 GetActiveObjectCount(uint32 pool_id) const;
52
53 template<typename T>
54 void ActivateObject(uint32 db_guid_or_pool_id, uint32 pool_id);
55
56 template<typename T>
57 void RemoveObject(uint32 db_guid_or_pool_id, uint32 pool_id);
58 private:
62};
63
64template <class T>
66{
67 typedef std::vector<PoolObject> PoolObjectList;
68 public:
69 explicit PoolGroup() : poolId(0) { }
70 void SetPoolId(uint32 pool_id) { poolId = pool_id; }
72 bool isEmpty() const { return ExplicitlyChanced.empty() && EqualChanced.empty(); }
73 void AddEntry(PoolObject& poolitem, uint32 maxentries);
74 bool CheckPool() const;
75 void DespawnObject(ActivePoolData& spawns, ObjectGuid::LowType guid, bool alwaysDeleteRespawnTime = false);
76 void DespawnAllObjects(ActivePoolData& spawns, bool alwaysDeleteRespawnTime = false);
77 void Despawn1Object(ObjectGuid::LowType guid, bool alwaysDeleteRespawnTime = false, bool saveRespawnTime = true);
78 void SpawnObject(ActivePoolData& spawns, uint32 limit, uint32 triggerFrom);
80
82 void RemoveOneRelation(uint32 child_pool_id);
84 {
85 if (EqualChanced.empty())
86 return 0;
87 return EqualChanced.front().guid;
88 }
89 uint32 GetPoolId() const { return poolId; }
90 private:
94};
95
97{
98 private:
99 PoolMgr();
100 ~PoolMgr() { };
101
102 public:
103 static PoolMgr* instance();
104
105 void LoadFromDB();
106
107 void Initialize();
108
109 template<typename T>
110 uint32 IsPartOfAPool(uint32 db_guid_or_pool_id) const;
111 uint32 IsPartOfAPool(SpawnObjectType type, ObjectGuid::LowType spawnId) const;
112
113 template<typename T>
114 bool IsSpawnedObject(uint32 db_guid_or_pool_id) const { return mSpawnedData.IsActiveObject<T>(db_guid_or_pool_id); }
115
116 bool CheckPool(uint32 pool_id) const;
117
118 void SpawnPool(uint32 pool_id);
119 void DespawnPool(uint32 pool_id, bool alwaysDeleteRespawnTime = false);
120
121 template<typename T>
122 void UpdatePool(uint32 pool_id, uint32 db_guid_or_pool_id);
123 void UpdatePool(uint32 pool_id, SpawnObjectType type, ObjectGuid::LowType spawnId);
124
125 private:
126 template<typename T>
127 void SpawnPool(uint32 pool_id, uint32 db_guid_or_pool_id);
128
129 typedef std::unordered_map<uint32, PoolTemplateData> PoolTemplateDataMap;
130 typedef std::unordered_map<uint32, PoolGroup<Creature>> PoolGroupCreatureMap;
131 typedef std::unordered_map<uint32, PoolGroup<GameObject>> PoolGroupGameObjectMap;
132 typedef std::unordered_map<uint32, PoolGroup<Pool>> PoolGroupPoolMap;
133 typedef std::pair<uint32, uint32> SearchPair;
134 typedef std::map<uint32, uint32> SearchMap;
135
143
144 // dynamic data
146};
147
148#define sPoolMgr PoolMgr::instance()
149
150// Method that tell if the creature is part of a pool and return the pool id if yes
151template<>
152inline uint32 PoolMgr::IsPartOfAPool<Creature>(uint32 db_guid) const
153{
154 SearchMap::const_iterator itr = mCreatureSearchMap.find(db_guid);
155 if (itr != mCreatureSearchMap.end())
156 return itr->second;
157
158 return 0;
159}
160
161// Method that tell if the gameobject is part of a pool and return the pool id if yes
162template<>
163inline uint32 PoolMgr::IsPartOfAPool<GameObject>(uint32 db_guid) const
164{
165 SearchMap::const_iterator itr = mGameobjectSearchMap.find(db_guid);
166 if (itr != mGameobjectSearchMap.end())
167 return itr->second;
168
169 return 0;
170}
171
172// Method that tell if the pool is part of another pool and return the pool id if yes
173template<>
174inline uint32 PoolMgr::IsPartOfAPool<Pool>(uint32 pool_id) const
175{
176 SearchMap::const_iterator itr = mPoolSearchMap.find(pool_id);
177 if (itr != mPoolSearchMap.end())
178 return itr->second;
179
180 return 0;
181}
182
183#endif
#define TC_GAME_API
Definition Define.h:114
uint32_t uint32
Definition Define.h:133
std::set< ObjectGuid::LowType > ActivePoolObjects
Definition PoolMgr.h:42
std::map< uint32, uint32 > ActivePoolPools
Definition PoolMgr.h:43
SpawnObjectType
Definition SpawnData.h:30
bool IsActiveObject(uint32 db_guid_or_pool_id) const
void RemoveObject(uint32 db_guid_or_pool_id, uint32 pool_id)
ActivePoolObjects mSpawnedCreatures
Definition PoolMgr.h:59
ActivePoolPools mSpawnedPools
Definition PoolMgr.h:61
void ActivateObject(uint32 db_guid_or_pool_id, uint32 pool_id)
ActivePoolObjects mSpawnedGameobjects
Definition PoolMgr.h:60
uint32 LowType
Definition ObjectGuid.h:142
void SetPoolId(uint32 pool_id)
Definition PoolMgr.h:70
uint32 GetFirstEqualChancedObjectId()
Definition PoolMgr.h:83
void RemoveOneRelation(uint32 child_pool_id)
PoolObjectList ExplicitlyChanced
Definition PoolMgr.h:92
PoolGroup()
Definition PoolMgr.h:69
void Spawn1Object(PoolObject *obj)
uint32 GetPoolId() const
Definition PoolMgr.h:89
~PoolGroup()
Definition PoolMgr.h:71
uint32 poolId
Definition PoolMgr.h:91
void Despawn1Object(ObjectGuid::LowType guid, bool alwaysDeleteRespawnTime=false, bool saveRespawnTime=true)
std::vector< PoolObject > PoolObjectList
Definition PoolMgr.h:67
PoolObjectList EqualChanced
Definition PoolMgr.h:93
void RemoveRespawnTimeFromDB(ObjectGuid::LowType guid)
bool isEmpty() const
Definition PoolMgr.h:72
std::pair< uint32, uint32 > SearchPair
Definition PoolMgr.h:133
std::map< uint32, uint32 > SearchMap
Definition PoolMgr.h:134
std::unordered_map< uint32, PoolGroup< Creature > > PoolGroupCreatureMap
Definition PoolMgr.h:130
std::unordered_map< uint32, PoolTemplateData > PoolTemplateDataMap
Definition PoolMgr.h:129
PoolGroupCreatureMap mPoolCreatureGroups
Definition PoolMgr.h:137
~PoolMgr()
Definition PoolMgr.h:100
PoolGroupPoolMap mPoolPoolGroups
Definition PoolMgr.h:139
uint32 IsPartOfAPool(uint32 db_guid_or_pool_id) const
std::unordered_map< uint32, PoolGroup< GameObject > > PoolGroupGameObjectMap
Definition PoolMgr.h:131
SearchMap mGameobjectSearchMap
Definition PoolMgr.h:141
PoolTemplateDataMap mPoolTemplate
Definition PoolMgr.h:136
void SpawnPool(uint32 pool_id, uint32 db_guid_or_pool_id)
std::unordered_map< uint32, PoolGroup< Pool > > PoolGroupPoolMap
Definition PoolMgr.h:132
SearchMap mPoolSearchMap
Definition PoolMgr.h:142
PoolGroupGameObjectMap mPoolGameobjectGroups
Definition PoolMgr.h:138
ActivePoolData mSpawnedData
Definition PoolMgr.h:145
bool IsSpawnedObject(uint32 db_guid_or_pool_id) const
Definition PoolMgr.h:114
SearchMap mCreatureSearchMap
Definition PoolMgr.h:140
Definition PoolMgr.h:39
STL namespace.
ObjectGuid::LowType guid
Definition PoolMgr.h:33
PoolObject(ObjectGuid::LowType _guid, float _chance)
Definition PoolMgr.h:35
float chance
Definition PoolMgr.h:34
uint32 MaxLimit
Definition PoolMgr.h:28