[7915] Implement more stricted checks and limitations at loading creature addon data.
[getmangos.git] / src / game / PoolHandler.h
blob35e18c2d58cbd5912344c73b3234d63129e082b0
1 /*
2 * Copyright (C) 2005-2009 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 bool spawned;
37 PoolObject(uint32 _guid, float _chance): guid(_guid), chance(fabs(_chance)), spawned(false) {}
40 template <class T>
41 class PoolGroup
43 public:
44 PoolGroup();
45 ~PoolGroup() {};
46 bool isEmpty() { return ExplicitlyChanced.size()==0 && EqualChanced.size()==0; }
47 void AddEntry(PoolObject& poolitem, uint32 maxentries);
48 bool CheckPool(void);
49 uint32 RollOne(void);
50 bool IsSpawnedObject(uint32 guid);
51 void DespawnObject(uint32 guid=0);
52 void Despawn1Object(uint32 guid);
53 void SpawnObject(uint32 limit, bool cache=false);
54 bool Spawn1Object(uint32 guid);
55 bool ReSpawn1Object(uint32 guid);
56 void RemoveOneRelation(uint16 child_pool_id);
57 private:
58 typedef std::vector<PoolObject> PoolObjectList;
59 uint32 CacheValue; // Store the guid of the removed creature/gameobject during a pool update
60 PoolObjectList ExplicitlyChanced;
61 PoolObjectList EqualChanced;
62 uint32 Spawned; // Used to know the number of spawned objects
65 class Pool // for Pool of Pool case
69 class PoolHandler
71 public:
72 PoolHandler();
73 ~PoolHandler() {};
74 void LoadFromDB();
75 uint16 IsPartOfAPool(uint32 guid, uint32 type);
76 bool IsSpawnedObject(uint16 pool_id, uint32 guid, uint32 type);
77 bool CheckPool(uint16 pool_id);
78 void SpawnPool(uint16 pool_id, bool cache=false);
79 void DespawnPool(uint16 pool_id);
80 void UpdatePool(uint16 pool_id, uint32 guid, uint32 type);
81 void Initialize();
83 protected:
84 bool isSystemInit;
85 uint16 max_pool_id;
86 typedef std::vector<PoolTemplateData> PoolTemplateDataMap;
87 typedef std::vector<PoolGroup<Creature> > PoolGroupCreatureMap;
88 typedef std::vector<PoolGroup<GameObject> > PoolGroupGameObjectMap;
89 typedef std::vector<PoolGroup<Pool> > PoolGroupPoolMap;
90 typedef std::pair<uint32, uint16> SearchPair;
91 typedef std::map<uint32, uint16> SearchMap;
93 PoolTemplateDataMap mPoolTemplate;
94 PoolGroupCreatureMap mPoolCreatureGroups;
95 PoolGroupGameObjectMap mPoolGameobjectGroups;
96 PoolGroupPoolMap mPoolPoolGroups;
97 SearchMap mCreatureSearchMap;
98 SearchMap mGameobjectSearchMap;
99 SearchMap mPoolSearchMap;
103 #define poolhandler MaNGOS::Singleton<PoolHandler>::Instance()
104 #endif