Updated Copyright year to 2013
[getmangos.git] / src / game / MapManager.h
blob3f0360128275fd9434873f92e8e7a42b12fc0de4
1 /*
2 * Copyright (C) 2005-2013 MaNGOS <http://getmangos.com/>
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_MAPMANAGER_H
20 #define MANGOS_MAPMANAGER_H
22 #include "Common.h"
23 #include "Platform/Define.h"
24 #include "Policies/Singleton.h"
25 #include "ace/Recursive_Thread_Mutex.h"
26 #include "Map.h"
27 #include "GridStates.h"
29 class Transport;
30 class BattleGround;
32 struct MANGOS_DLL_DECL MapID
34 explicit MapID(uint32 id) : nMapId(id), nInstanceId(0) {}
35 MapID(uint32 id, uint32 instid) : nMapId(id), nInstanceId(instid) {}
37 bool operator<(const MapID& val) const
39 if (nMapId == val.nMapId)
40 return nInstanceId < val.nInstanceId;
42 return nMapId < val.nMapId;
45 bool operator==(const MapID& val) const { return nMapId == val.nMapId && nInstanceId == val.nInstanceId; }
47 uint32 nMapId;
48 uint32 nInstanceId;
51 class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::ClassLevelLockable<MapManager, ACE_Recursive_Thread_Mutex> >
53 friend class MaNGOS::OperatorNew<MapManager>;
55 typedef ACE_Recursive_Thread_Mutex LOCK_TYPE;
56 typedef ACE_Guard<LOCK_TYPE> LOCK_TYPE_GUARD;
57 typedef MaNGOS::ClassLevelLockable<MapManager, ACE_Recursive_Thread_Mutex>::Lock Guard;
59 public:
60 typedef std::map<MapID, Map* > MapMapType;
62 Map* CreateMap(uint32, const WorldObject* obj);
63 Map* CreateBgMap(uint32 mapid, BattleGround* bg);
64 Map* FindMap(uint32 mapid, uint32 instanceId = 0) const;
66 void UpdateGridState(grid_state_t state, Map& map, NGridType& ngrid, GridInfo& ginfo, const uint32& x, const uint32& y, const uint32& t_diff);
68 // only const version for outer users
69 void DeleteInstance(uint32 mapid, uint32 instanceId);
71 void Initialize(void);
72 void Update(uint32);
74 void SetGridCleanUpDelay(uint32 t)
76 if (t < MIN_GRID_DELAY)
77 i_gridCleanUpDelay = MIN_GRID_DELAY;
78 else
79 i_gridCleanUpDelay = t;
82 void SetMapUpdateInterval(uint32 t)
84 if (t > MIN_MAP_UPDATE_DELAY)
85 t = MIN_MAP_UPDATE_DELAY;
87 i_timer.SetInterval(t);
88 i_timer.Reset();
91 // void LoadGrid(int mapid, int instId, float x, float y, const WorldObject* obj, bool no_unload = false);
92 void UnloadAll();
94 static bool ExistMapAndVMap(uint32 mapid, float x, float y);
95 static bool IsValidMAP(uint32 mapid);
97 static bool IsValidMapCoord(uint32 mapid, float x, float y)
99 return IsValidMAP(mapid) && MaNGOS::IsValidMapCoord(x, y);
102 static bool IsValidMapCoord(uint32 mapid, float x, float y, float z)
104 return IsValidMAP(mapid) && MaNGOS::IsValidMapCoord(x, y, z);
107 static bool IsValidMapCoord(uint32 mapid, float x, float y, float z, float o)
109 return IsValidMAP(mapid) && MaNGOS::IsValidMapCoord(x, y, z, o);
112 static bool IsValidMapCoord(WorldLocation const& loc)
114 return IsValidMapCoord(loc.mapid, loc.coord_x, loc.coord_y, loc.coord_z, loc.orientation);
117 void RemoveAllObjectsInRemoveList();
119 void LoadTransports();
121 typedef std::set<Transport*> TransportSet;
122 TransportSet m_Transports;
124 typedef std::map<uint32, TransportSet> TransportMap;
125 TransportMap m_TransportsByMap;
127 void InitializeVisibilityDistanceInfo();
129 /* statistics */
130 uint32 GetNumInstances();
131 uint32 GetNumPlayersInInstances();
134 // get list of all maps
135 const MapMapType& Maps() const { return i_maps; }
137 template<typename Do>
138 void DoForAllMapsWithMapId(uint32 mapId, Do& _do);
140 private:
142 // debugging code, should be deleted some day
143 GridState* si_GridStates[MAX_GRID_STATE];
144 int i_GridStateErrorCount;
146 private:
148 MapManager();
149 ~MapManager();
151 MapManager(const MapManager&);
152 MapManager& operator=(const MapManager&);
154 void InitStateMachine();
155 void DeleteStateMachine();
157 Map* CreateInstance(uint32 id, Player* player);
158 DungeonMap* CreateDungeonMap(uint32 id, uint32 InstanceId, Difficulty difficulty, DungeonPersistentState* save = NULL);
159 BattleGroundMap* CreateBattleGroundMap(uint32 id, uint32 InstanceId, BattleGround* bg);
161 uint32 i_gridCleanUpDelay;
162 MapMapType i_maps;
163 IntervalTimer i_timer;
166 template<typename Do>
167 inline void MapManager::DoForAllMapsWithMapId(uint32 mapId, Do& _do)
169 MapMapType::const_iterator start = i_maps.lower_bound(MapID(mapId, 0));
170 MapMapType::const_iterator end = i_maps.lower_bound(MapID(mapId + 1, 0));
171 for (MapMapType::const_iterator itr = start; itr != end; ++itr)
172 _do(itr->second);
175 #define sMapMgr MapManager::Instance()
177 #endif