[9581] Fixed apply damage reduction to melee/ranged damage.
[getmangos.git] / src / game / PoolManager.h
blob5cdeeda7d362a6433e7fa52f3804789f271eeb47
1 /*
2 * Copyright (C) 2005-2010 MaNGOS <http://www.mangosproject.org/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOS_POOLHANDLER_H
20 #define MANGOS_POOLHANDLER_H
22 #include "Platform/Define.h"
23 #include "Policies/Singleton.h"
24 #include "Creature.h"
25 #include "GameObject.h"
27 struct PoolTemplateData
29 uint32 MaxLimit;
32 struct PoolObject
34 uint32 guid;
35 float chance;
36 PoolObject(uint32 _guid, float _chance): guid(_guid), chance(fabs(_chance)) {}
39 class Pool // for Pool of Pool case
43 typedef std::set<uint32> SpawnedPoolObjects;
44 typedef std::map<uint32,uint32> SpawnedPoolPools;
46 class SpawnedPoolData
48 public:
49 template<typename T>
50 bool IsSpawnedObject(uint32 db_guid_or_pool_id) const;
52 uint32 GetSpawnedObjects(uint32 pool_id) const;
54 template<typename T>
55 void AddSpawn(uint32 db_guid_or_pool_id, uint32 pool_id);
57 template<typename T>
58 void RemoveSpawn(uint32 db_guid_or_pool_id, uint32 pool_id);
59 private:
60 SpawnedPoolObjects mSpawnedCreatures;
61 SpawnedPoolObjects mSpawnedGameobjects;
62 SpawnedPoolPools mSpawnedPools;
65 template <class T>
66 class PoolGroup
68 typedef std::vector<PoolObject> PoolObjectList;
69 public:
70 explicit PoolGroup() : poolId(0) { }
71 void SetPoolId(uint32 pool_id) { poolId = pool_id; }
72 ~PoolGroup() {};
73 bool isEmpty() const { return ExplicitlyChanced.empty() && EqualChanced.empty(); }
74 void AddEntry(PoolObject& poolitem, uint32 maxentries);
75 bool CheckPool() const;
76 PoolObject* RollOne(SpawnedPoolData& spawns, uint32 triggerFrom);
77 void DespawnObject(SpawnedPoolData& spawns, uint32 guid=0);
78 void Despawn1Object(uint32 guid);
79 void SpawnObject(SpawnedPoolData& spawns, uint32 limit, uint32 triggerFrom, bool instantly);
81 void Spawn1Object(PoolObject* obj, bool instantly);
82 void ReSpawn1Object(PoolObject* obj);
83 void RemoveOneRelation(uint16 child_pool_id);
84 private:
85 uint32 poolId;
86 PoolObjectList ExplicitlyChanced;
87 PoolObjectList EqualChanced;
90 class PoolManager
92 public:
93 PoolManager();
94 ~PoolManager() {};
96 void LoadFromDB();
97 void Initialize();
99 template<typename T>
100 uint16 IsPartOfAPool(uint32 db_guid_or_pool_id) const;
102 template<typename T>
103 bool IsSpawnedObject(uint32 db_guid_or_pool_id) const { return mSpawnedData.IsSpawnedObject<T>(db_guid_or_pool_id); }
105 bool CheckPool(uint16 pool_id) const;
107 void SpawnPool(uint16 pool_id, bool instantly);
108 void DespawnPool(uint16 pool_id);
110 template<typename T>
111 void UpdatePool(uint16 pool_id, uint32 db_guid_or_pool_id);
113 protected:
114 template<typename T>
115 void SpawnPoolGroup(uint16 pool_id, uint32 db_guid_or_pool_id, bool instantly);
117 uint16 max_pool_id;
118 typedef std::vector<PoolTemplateData> PoolTemplateDataMap;
120 typedef std::vector<PoolGroup<Creature> > PoolGroupCreatureMap;
121 typedef std::vector<PoolGroup<GameObject> > PoolGroupGameObjectMap;
122 typedef std::vector<PoolGroup<Pool> > PoolGroupPoolMap;
123 typedef std::pair<uint32, uint16> SearchPair;
124 typedef std::map<uint32, uint16> SearchMap;
126 PoolTemplateDataMap mPoolTemplate;
127 PoolGroupCreatureMap mPoolCreatureGroups;
128 PoolGroupGameObjectMap mPoolGameobjectGroups;
129 PoolGroupPoolMap mPoolPoolGroups;
131 // static maps DB low guid -> pool id
132 SearchMap mCreatureSearchMap;
133 SearchMap mGameobjectSearchMap;
134 SearchMap mPoolSearchMap;
136 // dynamic data
137 SpawnedPoolData mSpawnedData;
140 #define sPoolMgr MaNGOS::Singleton<PoolManager>::Instance()
142 // Method that tell if the creature is part of a pool and return the pool id if yes
143 template<>
144 inline uint16 PoolManager::IsPartOfAPool<Creature>(uint32 db_guid) const
146 SearchMap::const_iterator itr = mCreatureSearchMap.find(db_guid);
147 if (itr != mCreatureSearchMap.end())
148 return itr->second;
150 return 0;
153 // Method that tell if the gameobject is part of a pool and return the pool id if yes
154 template<>
155 inline uint16 PoolManager::IsPartOfAPool<GameObject>(uint32 db_guid) const
157 SearchMap::const_iterator itr = mGameobjectSearchMap.find(db_guid);
158 if (itr != mGameobjectSearchMap.end())
159 return itr->second;
161 return 0;
164 // Method that tell if the pool is part of another pool and return the pool id if yes
165 template<>
166 inline uint16 PoolManager::IsPartOfAPool<Pool>(uint32 pool_id) const
168 SearchMap::const_iterator itr = mPoolSearchMap.find(pool_id);
169 if (itr != mPoolSearchMap.end())
170 return itr->second;
172 return 0;
175 #endif