[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / MapManager.h
blob677c26120c23880b44506a4af86ebed852010cb2
1 /*
2 * Copyright (C) 2005-2009 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 "Platform/Define.h"
23 #include "Policies/Singleton.h"
24 #include "zthread/Mutex.h"
25 #include "Common.h"
26 #include "Map.h"
27 #include "GridStates.h"
29 class Transport;
31 class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::ClassLevelLockable<MapManager, ZThread::Mutex> >
34 friend class MaNGOS::OperatorNew<MapManager>;
35 typedef UNORDERED_MAP<uint32, Map*> MapMapType;
36 typedef std::pair<UNORDERED_MAP<uint32, Map*>::iterator, bool> MapMapPair;
38 public:
40 Map* GetMap(uint32, const WorldObject* obj);
41 Map* FindMap(uint32 mapid) { return _findMap(mapid); }
42 Map* FindMap(uint32 mapid, uint32 instanceId);
44 // only const version for outer users
45 Map const* GetBaseMap(uint32 id) const { return const_cast<MapManager*>(this)->_GetBaseMap(id); }
46 void DeleteInstance(uint32 mapid, uint32 instanceId);
48 uint16 GetAreaFlag(uint32 mapid, float x, float y, float z) const
50 Map const* m = GetBaseMap(mapid);
51 return m->GetAreaFlag(x, y, z);
53 uint32 GetAreaId(uint32 mapid, float x, float y, float z) const { return Map::GetAreaId(GetAreaFlag(mapid, x, y, z),mapid); }
54 uint32 GetZoneId(uint32 mapid, float x, float y, float z) const { return Map::GetZoneId(GetAreaFlag(mapid, x, y, z),mapid); }
56 void Initialize(void);
57 void Update(uint32);
59 void SetGridCleanUpDelay(uint32 t)
61 if( t < MIN_GRID_DELAY )
62 i_gridCleanUpDelay = MIN_GRID_DELAY;
63 else
64 i_gridCleanUpDelay = t;
67 void SetMapUpdateInterval(uint32 t)
69 if( t > MIN_MAP_UPDATE_DELAY )
70 t = MIN_MAP_UPDATE_DELAY;
72 i_timer.SetInterval(t);
73 i_timer.Reset();
76 void LoadGrid(int mapid, float x, float y, const WorldObject* obj, bool no_unload = false);
77 void UnloadAll();
79 static bool ExistMapAndVMap(uint32 mapid, float x, float y);
80 static bool IsValidMAP(uint32 mapid);
82 static bool IsValidMapCoord(uint32 mapid, float x,float y)
84 return IsValidMAP(mapid) && MaNGOS::IsValidMapCoord(x,y);
87 static bool IsValidMapCoord(uint32 mapid, float x,float y,float z)
89 return IsValidMAP(mapid) && MaNGOS::IsValidMapCoord(x,y,z);
92 static bool IsValidMapCoord(uint32 mapid, float x,float y,float z,float o)
94 return IsValidMAP(mapid) && MaNGOS::IsValidMapCoord(x,y,z,o);
97 static bool IsValidMapCoord(WorldLocation const& loc)
99 return IsValidMapCoord(loc.mapid,loc.x,loc.y,loc.z,loc.o);
102 void DoDelayedMovesAndRemoves();
104 void LoadTransports();
106 typedef std::set<Transport *> TransportSet;
107 TransportSet m_Transports;
109 typedef std::map<uint32, TransportSet> TransportMap;
110 TransportMap m_TransportsByMap;
112 bool CanPlayerEnter(uint32 mapid, Player* player);
113 void RemoveBonesFromMap(uint32 mapid, uint64 guid, float x, float y);
114 uint32 GenerateInstanceId() { return ++i_MaxInstanceId; }
115 void InitMaxInstanceId();
117 /* statistics */
118 uint32 GetNumInstances();
119 uint32 GetNumPlayersInInstances();
121 private:
122 // debugging code, should be deleted some day
123 void checkAndCorrectGridStatesArray(); // just for debugging to find some memory overwrites
124 GridState* i_GridStates[MAX_GRID_STATE]; // shadow entries to the global array in Map.cpp
125 int i_GridStateErrorCount;
126 private:
127 MapManager();
128 ~MapManager();
130 MapManager(const MapManager &);
131 MapManager& operator=(const MapManager &);
133 Map* _GetBaseMap(uint32 id);
134 Map* _findMap(uint32 id) const
136 MapMapType::const_iterator iter = i_maps.find(id);
137 return (iter == i_maps.end() ? NULL : iter->second);
140 typedef MaNGOS::ClassLevelLockable<MapManager, ZThread::Mutex>::Lock Guard;
141 uint32 i_gridCleanUpDelay;
142 MapMapType i_maps;
143 IntervalTimer i_timer;
145 uint32 i_MaxInstanceId;
147 #endif