OregonCore  revision fb2a440-git
Your Favourite TBC server
PoolMgr.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore 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 _POOLMGR_H
19 #define _POOLMGR_H
20 
21 #include "Platform/Define.h"
22 #include "Policies/Singleton.h"
23 #include "Creature.h"
24 #include "GameObject.h"
25 #include "QuestDef.h"
26 
28 {
30 };
31 
32 struct PoolObject
33 {
35  float chance;
36  PoolObject(uint32 _guid, float _chance) : guid(_guid), chance(std::fabs(_chance)) { }
37 };
38 
39 class Pool // for Pool of Pool case
40 {
41 };
42 
43 typedef std::set<uint32> ActivePoolObjects;
44 typedef std::map<uint32, uint32> ActivePoolPools;
45 
47 {
48  public:
49  template<typename T>
50  bool IsActiveObject(uint32 db_guid_or_pool_id) const;
51 
52  uint32 GetActiveObjectCount(uint32 pool_id) const;
53 
54  template<typename T>
55  void ActivateObject(uint32 db_guid_or_pool_id, uint32 pool_id);
56 
57  template<typename T>
58  void RemoveObject(uint32 db_guid_or_pool_id, uint32 pool_id);
59 
60  ActivePoolObjects GetActiveQuests() const { return mActiveQuests; } // a copy of the set
61  private:
66 };
67 
68 template <class T>
69 class PoolGroup
70 {
71  typedef std::vector<PoolObject> PoolObjectList;
72  public:
73  explicit PoolGroup() : poolId(0) { }
74  void SetPoolId(uint32 pool_id) { poolId = pool_id; }
75  ~PoolGroup() { };
76  bool isEmpty() const { return ExplicitlyChanced.empty() && EqualChanced.empty(); }
77  void AddEntry(PoolObject& poolitem, uint32 maxentries);
78  bool CheckPool() const;
79  PoolObject* RollOne(ActivePoolData& spawns, uint32 triggerFrom);
80  void DespawnObject(ActivePoolData& spawns, uint32 guid = 0);;
81  void Despawn1Object(uint32 guid);
82  void SpawnObject(ActivePoolData& spawns, uint32 limit, uint32 triggerFrom);
83 
84  void Spawn1Object(PoolObject* obj);
85  void ReSpawn1Object(PoolObject* obj);
86  void RemoveOneRelation(uint32 child_pool_id);
88  {
89  if (EqualChanced.empty())
90  return 0;
91  return EqualChanced.front().guid;
92  }
93  uint32 GetPoolId() const { return poolId; }
94  private:
96  PoolObjectList ExplicitlyChanced;
97  PoolObjectList EqualChanced;
98 };
99 
100 typedef std::multimap<uint32, uint32> PooledQuestRelation;
101 typedef std::pair<PooledQuestRelation::const_iterator, PooledQuestRelation::const_iterator> PooledQuestRelationBounds;
102 typedef std::pair<PooledQuestRelation::iterator, PooledQuestRelation::iterator> PooledQuestRelationBoundsNC;
103 
104 class PoolMgr
105 {
106  public:
107  PoolMgr();
108  ~PoolMgr() { };
109 
110  void LoadFromDB();
111  void LoadQuestPools();
112  void SaveQuestsToDB();
113 
114  void Initialize();
115 
116  template<typename T>
117  uint32 IsPartOfAPool(uint32 db_guid_or_pool_id) const;
118 
119  template<typename T>
120  bool IsSpawnedObject(uint32 db_guid_or_pool_id) const { return mSpawnedData.IsActiveObject<T>(db_guid_or_pool_id); }
121 
122  bool CheckPool(uint32 pool_id) const;
123 
124  void SpawnPool(uint32 pool_id);
125  void DespawnPool(uint32 pool_id);
126 
127  template<typename T>
128  void UpdatePool(uint32 pool_id, uint32 db_guid_or_pool_id);
129 
130  void ChangeDailyQuests();
131 
134 
135  protected:
136  template<typename T>
137  void SpawnPool(uint32 pool_id, uint32 db_guid_or_pool_id);
138 
140  typedef std::vector<PoolTemplateData> PoolTemplateDataMap;
141  typedef std::vector<PoolGroup<Creature> > PoolGroupCreatureMap;
142  typedef std::vector<PoolGroup<GameObject> > PoolGroupGameObjectMap;
143  typedef std::vector<PoolGroup<Pool> > PoolGroupPoolMap;
144  typedef std::vector<PoolGroup<Quest> > PoolGroupQuestMap;
145  typedef std::pair<uint32, uint32> SearchPair;
146  typedef std::map<uint32, uint32> SearchMap;
147 
148  PoolTemplateDataMap mPoolTemplate;
149  PoolGroupCreatureMap mPoolCreatureGroups;
150  PoolGroupGameObjectMap mPoolGameobjectGroups;
151  PoolGroupPoolMap mPoolPoolGroups;
152  PoolGroupQuestMap mPoolQuestGroups;
155  SearchMap mPoolSearchMap;
156  SearchMap mQuestSearchMap;
157 
158  // dynamic data
160 };
161 
162 #define sPoolMgr Oregon::Singleton<PoolMgr>::Instance()
163 
164 // Method that tell if the creature is part of a pool and return the pool id if yes
165 template<>
166 inline uint32 PoolMgr::IsPartOfAPool<Creature>(uint32 db_guid) const
167 {
168  SearchMap::const_iterator itr = mCreatureSearchMap.find(db_guid);
169  if (itr != mCreatureSearchMap.end())
170  return itr->second;
171 
172  return 0;
173 }
174 
175 // Method that tell if the gameobject is part of a pool and return the pool id if yes
176 template<>
177 inline uint32 PoolMgr::IsPartOfAPool<GameObject>(uint32 db_guid) const
178 {
179  SearchMap::const_iterator itr = mGameobjectSearchMap.find(db_guid);
180  if (itr != mGameobjectSearchMap.end())
181  return itr->second;
182 
183  return 0;
184 }
185 
186 // Method that tell if the quest is part of another pool and return the pool id if yes
187 template<>
188 inline uint32 PoolMgr::IsPartOfAPool<Quest>(uint32 pool_id) const
189 {
190  SearchMap::const_iterator itr = mQuestSearchMap.find(pool_id);
191  if (itr != mQuestSearchMap.end())
192  return itr->second;
193 
194  return 0;
195 }
196 
197 // Method that tell if the pool is part of another pool and return the pool id if yes
198 template<>
199 inline uint32 PoolMgr::IsPartOfAPool<Pool>(uint32 pool_id) const
200 {
201  SearchMap::const_iterator itr = mPoolSearchMap.find(pool_id);
202  if (itr != mPoolSearchMap.end())
203  return itr->second;
204 
205  return 0;
206 }
207 
208 #endif
PooledQuestRelation mQuestGORelation
Definition: PoolMgr.h:133
~PoolGroup()
Definition: PoolMgr.h:75
std::vector< PoolGroup< GameObject > > PoolGroupGameObjectMap
Definition: PoolMgr.h:142
PoolGroup()
Definition: PoolMgr.h:73
SearchMap mCreatureSearchMap
Definition: PoolMgr.h:153
SearchMap mGameobjectSearchMap
Definition: PoolMgr.h:154
std::pair< PooledQuestRelation::iterator, PooledQuestRelation::iterator > PooledQuestRelationBoundsNC
Definition: PoolMgr.h:102
PoolObjectList EqualChanced
Definition: PoolMgr.h:97
PoolObjectList ExplicitlyChanced
Definition: PoolMgr.h:96
uint32 max_pool_id
Definition: PoolMgr.h:139
std::map< uint32, uint32 > SearchMap
Definition: PoolMgr.h:146
std::multimap< uint32, uint32 > PooledQuestRelation
Definition: PoolMgr.h:100
PooledQuestRelation mQuestCreatureRelation
Definition: PoolMgr.h:132
STL namespace.
PoolGroupPoolMap mPoolPoolGroups
Definition: PoolMgr.h:151
PoolGroupQuestMap mPoolQuestGroups
Definition: PoolMgr.h:152
std::vector< PoolGroup< Creature > > PoolGroupCreatureMap
Definition: PoolMgr.h:141
std::pair< uint32, uint32 > SearchPair
Definition: PoolMgr.h:145
ActivePoolObjects mSpawnedCreatures
Definition: PoolMgr.h:62
PoolObject(uint32 _guid, float _chance)
Definition: PoolMgr.h:36
bool isEmpty() const
Definition: PoolMgr.h:76
~PoolMgr()
Definition: PoolMgr.h:108
Definition: PoolMgr.h:39
PoolTemplateDataMap mPoolTemplate
Definition: PoolMgr.h:148
ActivePoolPools mSpawnedPools
Definition: PoolMgr.h:65
ActivePoolObjects mSpawnedGameobjects
Definition: PoolMgr.h:63
ActivePoolData mSpawnedData
Definition: PoolMgr.h:159
ActivePoolObjects mActiveQuests
Definition: PoolMgr.h:64
std::vector< PoolGroup< Quest > > PoolGroupQuestMap
Definition: PoolMgr.h:144
std::map< uint32, uint32 > ActivePoolPools
Definition: PoolMgr.h:44
std::pair< PooledQuestRelation::const_iterator, PooledQuestRelation::const_iterator > PooledQuestRelationBounds
Definition: PoolMgr.h:101
uint32 GetFirstEqualChancedObjectId()
Definition: PoolMgr.h:87
std::vector< PoolGroup< Pool > > PoolGroupPoolMap
Definition: PoolMgr.h:143
uint32 MaxLimit
Definition: PoolMgr.h:29
std::vector< PoolObject > PoolObjectList
Definition: PoolMgr.h:71
PoolGroupCreatureMap mPoolCreatureGroups
Definition: PoolMgr.h:149
bool IsSpawnedObject(uint32 db_guid_or_pool_id) const
Definition: PoolMgr.h:120
float chance
Definition: PoolMgr.h:35
std::vector< PoolTemplateData > PoolTemplateDataMap
Definition: PoolMgr.h:140
ACE_UINT32 uint32
Definition: Define.h:71
ActivePoolObjects GetActiveQuests() const
Definition: PoolMgr.h:60
void SetPoolId(uint32 pool_id)
Definition: PoolMgr.h:74
uint32 guid
Definition: PoolMgr.h:34
PoolGroupGameObjectMap mPoolGameobjectGroups
Definition: PoolMgr.h:150
SearchMap mQuestSearchMap
Definition: PoolMgr.h:156
SearchMap mPoolSearchMap
Definition: PoolMgr.h:155
std::set< uint32 > ActivePoolObjects
Definition: PoolMgr.h:43
uint32 GetPoolId() const
Definition: PoolMgr.h:93
uint32 poolId
Definition: PoolMgr.h:95