[10041] Use for spell 49145 and ranks for decrease SPELL_DIRECT_DAMAGE damage.
[getmangos.git] / src / game / MapManager.h
blobc48f821ba79180bf12f538371d8f11e1b758cc18
1 /*
2 * Copyright (C) 2005-2010 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 "ace/Thread_Mutex.h"
25 #include "Common.h"
26 #include "Map.h"
27 #include "GridStates.h"
29 class Transport;
30 class BattleGround;
32 class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::ClassLevelLockable<MapManager, ACE_Thread_Mutex> >
35 friend class MaNGOS::OperatorNew<MapManager>;
36 typedef UNORDERED_MAP<uint32, Map*> MapMapType;
37 typedef std::pair<UNORDERED_MAP<uint32, Map*>::iterator, bool> MapMapPair;
39 public:
41 Map* CreateMap(uint32, const WorldObject* obj);
42 Map* CreateBgMap(uint32 mapid, BattleGround* bg);
43 Map const* CreateBaseMap(uint32 id) const { return const_cast<MapManager*>(this)->_createBaseMap(id); }
44 Map* FindMap(uint32 mapid, uint32 instanceId = 0) const;
46 void UpdateGridState(grid_state_t state, Map& map, NGridType& ngrid, GridInfo& ginfo, const uint32 &x, const uint32 &y, const uint32 &t_diff);
48 // only const version for outer users
49 void DeleteInstance(uint32 mapid, uint32 instanceId);
51 uint16 GetAreaFlag(uint32 mapid, float x, float y, float z) const
53 Map const* m = CreateBaseMap(mapid);
54 return m->GetAreaFlag(x, y, z);
56 uint32 GetAreaId(uint32 mapid, float x, float y, float z) const
58 return Map::GetAreaIdByAreaFlag(GetAreaFlag(mapid, x, y, z),mapid);
60 uint32 GetZoneId(uint32 mapid, float x, float y, float z) const
62 return Map::GetZoneIdByAreaFlag(GetAreaFlag(mapid, x, y, z),mapid);
64 void GetZoneAndAreaId(uint32& zoneid, uint32& areaid, uint32 mapid, float x, float y, float z)
66 Map::GetZoneAndAreaIdByAreaFlag(zoneid,areaid,GetAreaFlag(mapid, x, y, z),mapid);
69 void Initialize(void);
70 void Update(uint32);
72 void SetGridCleanUpDelay(uint32 t)
74 if( t < MIN_GRID_DELAY )
75 i_gridCleanUpDelay = MIN_GRID_DELAY;
76 else
77 i_gridCleanUpDelay = t;
80 void SetMapUpdateInterval(uint32 t)
82 if( t > MIN_MAP_UPDATE_DELAY )
83 t = MIN_MAP_UPDATE_DELAY;
85 i_timer.SetInterval(t);
86 i_timer.Reset();
89 //void LoadGrid(int mapid, int instId, float x, float y, const WorldObject* obj, bool no_unload = false);
90 void UnloadAll();
92 static bool ExistMapAndVMap(uint32 mapid, float x, float y);
93 static bool IsValidMAP(uint32 mapid);
95 static bool IsValidMapCoord(uint32 mapid, float x,float y)
97 return IsValidMAP(mapid) && MaNGOS::IsValidMapCoord(x,y);
100 static bool IsValidMapCoord(uint32 mapid, float x,float y,float z)
102 return IsValidMAP(mapid) && MaNGOS::IsValidMapCoord(x,y,z);
105 static bool IsValidMapCoord(uint32 mapid, float x,float y,float z,float o)
107 return IsValidMAP(mapid) && MaNGOS::IsValidMapCoord(x,y,z,o);
110 static bool IsValidMapCoord(WorldLocation const& loc)
112 return IsValidMapCoord(loc.mapid,loc.coord_x,loc.coord_y,loc.coord_z,loc.orientation);
115 void RemoveAllObjectsInRemoveList();
117 void LoadTransports();
119 typedef std::set<Transport *> TransportSet;
120 TransportSet m_Transports;
122 typedef std::map<uint32, TransportSet> TransportMap;
123 TransportMap m_TransportsByMap;
125 bool CanPlayerEnter(uint32 mapid, Player* player);
126 uint32 GenerateInstanceId() { return ++i_MaxInstanceId; }
127 void InitMaxInstanceId();
128 void InitializeVisibilityDistanceInfo();
130 /* statistics */
131 uint32 GetNumInstances();
132 uint32 GetNumPlayersInInstances();
134 private:
136 // debugging code, should be deleted some day
137 GridState* si_GridStates[MAX_GRID_STATE];
138 int i_GridStateErrorCount;
140 private:
142 MapManager();
143 ~MapManager();
145 MapManager(const MapManager &);
146 MapManager& operator=(const MapManager &);
148 void InitStateMachine();
149 void DeleteStateMachine();
151 Map* _createBaseMap(uint32 id);
152 Map* _findMap(uint32 id) const
154 MapMapType::const_iterator iter = i_maps.find(id);
155 return (iter == i_maps.end() ? NULL : iter->second);
158 typedef MaNGOS::ClassLevelLockable<MapManager, ACE_Thread_Mutex>::Lock Guard;
159 uint32 i_gridCleanUpDelay;
160 MapMapType i_maps;
161 IntervalTimer i_timer;
163 uint32 i_MaxInstanceId;
166 #define sMapMgr MapManager::Instance()
168 #endif