2010-10-07 12:41:56 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2008-2010 TrinityCore <http://www.trinitycore.org/>
|
|
|
|
|
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
* option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
|
* more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-10-02 16:23:55 -05:00
|
|
|
*/
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-14 11:57:03 -05:00
|
|
|
#ifndef TRINITY_MAPMANAGER_H
|
|
|
|
|
#define TRINITY_MAPMANAGER_H
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-06-07 09:04:14 -06:00
|
|
|
#include "Define.h"
|
2010-08-21 02:27:12 +02:00
|
|
|
#include <ace/Singleton.h>
|
|
|
|
|
#include <ace/Thread_Mutex.h>
|
2008-10-02 16:23:55 -05:00
|
|
|
#include "Common.h"
|
|
|
|
|
#include "Map.h"
|
2010-06-08 23:44:55 +02:00
|
|
|
#include "GridStates.h"
|
2009-12-17 07:34:00 +01:00
|
|
|
#include "MapUpdater.h"
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
class Transport;
|
2010-07-30 21:54:46 -07:00
|
|
|
struct TransportCreatureProto;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-06-25 00:18:01 +02:00
|
|
|
class MapManager
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2010-06-25 00:18:01 +02:00
|
|
|
friend class ACE_Singleton<MapManager, ACE_Thread_Mutex>;
|
2008-11-10 06:53:00 -06:00
|
|
|
typedef UNORDERED_MAP<uint32, Map*> MapMapType;
|
|
|
|
|
typedef std::pair<UNORDERED_MAP<uint32, Map*>::iterator, bool> MapMapPair;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
public:
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-08-01 00:20:32 +02:00
|
|
|
Map* CreateMap(uint32, const WorldObject* obj, uint32 instanceId);
|
2009-06-16 11:19:59 -05:00
|
|
|
Map const* CreateBaseMap(uint32 id) const { return const_cast<MapManager*>(this)->_createBaseMap(id); }
|
|
|
|
|
Map* FindMap(uint32 mapid, uint32 instanceId = 0) const;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-01-20 19:59:43 -06:00
|
|
|
uint16 GetAreaFlag(uint32 mapid, float x, float y, float z) const
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2009-06-16 11:19:59 -05:00
|
|
|
Map const* m = CreateBaseMap(mapid);
|
2009-01-02 11:03:43 -06:00
|
|
|
return m->GetAreaFlag(x, y, z);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-03-11 16:17:37 -06:00
|
|
|
uint32 GetAreaId(uint32 mapid, float x, float y, float z) const
|
|
|
|
|
{
|
|
|
|
|
return Map::GetAreaIdByAreaFlag(GetAreaFlag(mapid, x, y, z),mapid);
|
|
|
|
|
}
|
|
|
|
|
uint32 GetZoneId(uint32 mapid, float x, float y, float z) const
|
|
|
|
|
{
|
|
|
|
|
return Map::GetZoneIdByAreaFlag(GetAreaFlag(mapid, x, y, z),mapid);
|
|
|
|
|
}
|
|
|
|
|
void GetZoneAndAreaId(uint32& zoneid, uint32& areaid, uint32 mapid, float x, float y, float z)
|
|
|
|
|
{
|
|
|
|
|
Map::GetZoneAndAreaIdByAreaFlag(zoneid,areaid,GetAreaFlag(mapid, x, y, z),mapid);
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
void Initialize(void);
|
2009-01-21 16:18:57 -06:00
|
|
|
void Update(uint32);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-01-20 19:59:43 -06:00
|
|
|
void SetGridCleanUpDelay(uint32 t)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2010-04-07 22:59:46 +02:00
|
|
|
if (t < MIN_GRID_DELAY)
|
2008-10-02 16:23:55 -05:00
|
|
|
i_gridCleanUpDelay = MIN_GRID_DELAY;
|
|
|
|
|
else
|
|
|
|
|
i_gridCleanUpDelay = t;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-01-20 19:59:43 -06:00
|
|
|
void SetMapUpdateInterval(uint32 t)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2010-04-07 22:59:46 +02:00
|
|
|
if (t > MIN_MAP_UPDATE_DELAY)
|
2008-10-02 16:23:55 -05:00
|
|
|
t = MIN_MAP_UPDATE_DELAY;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
i_timer.SetInterval(t);
|
|
|
|
|
i_timer.Reset();
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-06-16 11:19:59 -05:00
|
|
|
//void LoadGrid(int mapid, int instId, float x, float y, const WorldObject* obj, bool no_unload = false);
|
2008-10-02 16:23:55 -05:00
|
|
|
void UnloadAll();
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
static bool ExistMapAndVMap(uint32 mapid, float x, float y);
|
|
|
|
|
static bool IsValidMAP(uint32 mapid);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
static bool IsValidMapCoord(uint32 mapid, float x,float y)
|
|
|
|
|
{
|
2008-10-14 11:57:03 -05:00
|
|
|
return IsValidMAP(mapid) && Trinity::IsValidMapCoord(x,y);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
static bool IsValidMapCoord(uint32 mapid, float x,float y,float z)
|
|
|
|
|
{
|
2008-10-14 11:57:03 -05:00
|
|
|
return IsValidMAP(mapid) && Trinity::IsValidMapCoord(x,y,z);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
static bool IsValidMapCoord(uint32 mapid, float x,float y,float z,float o)
|
|
|
|
|
{
|
2008-10-14 11:57:03 -05:00
|
|
|
return IsValidMAP(mapid) && Trinity::IsValidMapCoord(x,y,z,o);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-02-10 01:06:39 -06:00
|
|
|
static bool IsValidMapCoord(WorldLocation const& loc)
|
|
|
|
|
{
|
2009-08-29 14:58:45 -05:00
|
|
|
return IsValidMapCoord(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), loc.GetOrientation());
|
2009-02-10 01:06:39 -06:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-06-24 17:32:50 +02:00
|
|
|
// modulos a radian orientation to the range of 0..2PI
|
|
|
|
|
static float NormalizeOrientation(float o)
|
|
|
|
|
{
|
|
|
|
|
// fmod only supports positive numbers. Thus we have
|
|
|
|
|
// to emulate negative numbers
|
2010-06-24 23:59:42 +02:00
|
|
|
if (o < 0)
|
2010-06-24 17:32:50 +02:00
|
|
|
{
|
|
|
|
|
float mod = o *-1;
|
2010-06-24 23:59:42 +02:00
|
|
|
mod = fmod(mod, 2.0f * static_cast<float>(M_PI));
|
2010-08-22 12:39:39 -07:00
|
|
|
mod = -mod + 2.0f * static_cast<float>(M_PI);
|
2010-06-24 17:32:50 +02:00
|
|
|
return mod;
|
|
|
|
|
}
|
2010-06-24 23:59:42 +02:00
|
|
|
return fmod(o, 2.0f * static_cast<float>(M_PI));
|
2010-06-24 17:32:50 +02:00
|
|
|
}
|
|
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
void DoDelayedMovesAndRemoves();
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
void LoadTransports();
|
2010-07-30 21:54:46 -07:00
|
|
|
void LoadTransportNPCs();
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
typedef std::set<Transport *> TransportSet;
|
|
|
|
|
TransportSet m_Transports;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
typedef std::map<uint32, TransportSet> TransportMap;
|
|
|
|
|
TransportMap m_TransportsByMap;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-07-30 21:54:46 -07:00
|
|
|
typedef std::set<TransportCreatureProto *> TransportNPCSet;
|
|
|
|
|
TransportNPCSet m_TransportNPCs;
|
|
|
|
|
typedef std::map<uint32, TransportNPCSet> TransportNPCMap;
|
|
|
|
|
TransportNPCMap m_TransportNPCMap;
|
|
|
|
|
|
2010-05-04 18:25:30 +02:00
|
|
|
bool CanPlayerEnter(uint32 mapid, Player* player, bool loginCheck = false);
|
2009-01-20 19:59:43 -06:00
|
|
|
uint32 GenerateInstanceId() { return ++i_MaxInstanceId; }
|
2008-10-02 16:23:55 -05:00
|
|
|
void InitMaxInstanceId();
|
2009-09-27 02:24:25 -07:00
|
|
|
void InitializeVisibilityDistanceInfo();
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
/* statistics */
|
|
|
|
|
uint32 GetNumInstances();
|
|
|
|
|
uint32 GetNumPlayersInInstances();
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
private:
|
|
|
|
|
// debugging code, should be deleted some day
|
|
|
|
|
void checkAndCorrectGridStatesArray(); // just for debugging to find some memory overwrites
|
|
|
|
|
GridState* i_GridStates[MAX_GRID_STATE]; // shadow entries to the global array in Map.cpp
|
|
|
|
|
int i_GridStateErrorCount;
|
|
|
|
|
private:
|
|
|
|
|
MapManager();
|
|
|
|
|
~MapManager();
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
MapManager(const MapManager &);
|
|
|
|
|
MapManager& operator=(const MapManager &);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-06-16 11:19:59 -05:00
|
|
|
Map* _createBaseMap(uint32 id);
|
2008-10-02 16:23:55 -05:00
|
|
|
Map* _findMap(uint32 id) const
|
|
|
|
|
{
|
|
|
|
|
MapMapType::const_iterator iter = i_maps.find(id);
|
|
|
|
|
return (iter == i_maps.end() ? NULL : iter->second);
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-06-25 00:18:01 +02:00
|
|
|
ACE_Thread_Mutex Lock;
|
2008-10-02 16:23:55 -05:00
|
|
|
uint32 i_gridCleanUpDelay;
|
|
|
|
|
MapMapType i_maps;
|
|
|
|
|
IntervalTimer i_timer;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
uint32 i_MaxInstanceId;
|
2009-12-17 07:34:00 +01:00
|
|
|
MapUpdater m_updater;
|
2008-10-02 16:23:55 -05:00
|
|
|
};
|
2010-06-25 00:18:01 +02:00
|
|
|
#define sMapMgr (*ACE_Singleton<MapManager, ACE_Thread_Mutex>::instance())
|
2008-10-02 16:23:55 -05:00
|
|
|
#endif
|