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"
25 #include "GameObject.h"
27 struct PoolTemplateData
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
;
50 bool IsSpawnedObject(uint32 db_guid_or_pool_id
) const;
52 uint32
GetSpawnedObjects(uint32 pool_id
) const;
55 void AddSpawn(uint32 db_guid_or_pool_id
, uint32 pool_id
);
58 void RemoveSpawn(uint32 db_guid_or_pool_id
, uint32 pool_id
);
60 SpawnedPoolObjects mSpawnedCreatures
;
61 SpawnedPoolObjects mSpawnedGameobjects
;
62 SpawnedPoolPools mSpawnedPools
;
68 typedef std::vector
<PoolObject
> PoolObjectList
;
70 explicit PoolGroup() : poolId(0) { }
71 void SetPoolId(uint32 pool_id
) { poolId
= pool_id
; }
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
);
81 void Spawn1Object(PoolObject
* obj
);
82 void ReSpawn1Object(PoolObject
* obj
);
83 void RemoveOneRelation(uint16 child_pool_id
);
86 PoolObjectList ExplicitlyChanced
;
87 PoolObjectList EqualChanced
;
100 uint16
IsPartOfAPool(uint32 db_guid_or_pool_id
) const;
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
);
108 void DespawnPool(uint16 pool_id
);
111 void UpdatePool(uint16 pool_id
, uint32 db_guid_or_pool_id
);
115 void SpawnPool(uint16 pool_id
, uint32 db_guid_or_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
;
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
144 inline uint16
PoolManager::IsPartOfAPool
<Creature
>(uint32 db_guid
) const
146 SearchMap::const_iterator itr
= mCreatureSearchMap
.find(db_guid
);
147 if (itr
!= mCreatureSearchMap
.end())
153 // Method that tell if the gameobject is part of a pool and return the pool id if yes
155 inline uint16
PoolManager::IsPartOfAPool
<GameObject
>(uint32 db_guid
) const
157 SearchMap::const_iterator itr
= mGameobjectSearchMap
.find(db_guid
);
158 if (itr
!= mGameobjectSearchMap
.end())
164 // Method that tell if the pool is part of another pool and return the pool id if yes
166 inline uint16
PoolManager::IsPartOfAPool
<Pool
>(uint32 pool_id
) const
168 SearchMap::const_iterator itr
= mPoolSearchMap
.find(pool_id
);
169 if (itr
!= mPoolSearchMap
.end())