OregonCore  revision be9e804-git
Your Favourite TBC server
MapManager Class Reference

#include <MapManager.h>

+ Inheritance diagram for MapManager:

Public Types

typedef std::set< Transport * > TransportSet
 
typedef std::map< uint32, TransportSetTransportMap
 

Public Member Functions

MapCreateMap (uint32 mapId, const WorldObject *obj, uint32 loginInstanceId=0)
 
Map const * CreateBaseMap (uint32 id) const
 
MapFindMap (uint32 mapid, uint32 instanceId=0) const
 
uint16 GetAreaFlag (uint32 mapid, float x, float y, float z) const
 
uint32 GetAreaId (uint32 mapid, float x, float y, float z)
 
uint32 GetZoneId (uint32 mapid, float x, float y, float z)
 
void Initialize (void)
 
void Update (time_t)
 
void SetGridCleanUpDelay (uint32 t)
 
void SetMapUpdateInterval (uint32 t)
 
void UnloadAll ()
 
void DoDelayedMovesAndRemoves ()
 
void LoadTransports ()
 
Map::EnterState PlayerCannotEnter (uint32 mapid, Player *player, bool loginCheck=false)
 
uint32 GenerateInstanceId ()
 
void InitMaxInstanceId ()
 
void InitializeVisibilityDistanceInfo ()
 
uint32 GetNumInstances ()
 
uint32 GetNumPlayersInInstances ()
 
MapUpdaterGetMapUpdater ()
 

Static Public Member Functions

static bool ExistMapAndVMap (uint32 mapid, float x, float y)
 
static bool IsValidMAP (uint32 mapid)
 
static bool IsValidMapCoord (uint32 mapid, float x, float y)
 
static bool IsValidMapCoord (uint32 mapid, float x, float y, float z)
 
static bool IsValidMapCoord (uint32 mapid, float x, float y, float z, float o)
 
static bool IsValidMapCoord (WorldLocation const &loc)
 
static float NormalizeOrientation (float o)
 
- Static Public Member Functions inherited from Oregon::Singleton< MapManager, Oregon::ClassLevelLockable< MapManager, ACE_Thread_Mutex > >
static MapManagerInstance ()
 

Public Attributes

TransportSet m_Transports
 
TransportMap m_TransportsByMap
 

Private Types

typedef UNORDERED_MAP< uint32, Map * > MapMapType
 
typedef std::pair< UNORDERED_MAP< uint32, Map * >::iterator, bool > MapMapPair
 
typedef Oregon::ClassLevelLockable< MapManager, ACE_Thread_Mutex >::Lock Guard
 

Private Member Functions

void checkAndCorrectGridStatesArray ()
 
 MapManager ()
 
 ~MapManager ()
 
 MapManager (const MapManager &)
 
MapManageroperator= (const MapManager &)
 
Map_createBaseMap (uint32 id)
 
Map_findMap (uint32 id) const
 

Private Attributes

GridStatei_GridStates [MAX_GRID_STATE]
 
int i_GridStateErrorCount
 
uint32 i_gridCleanUpDelay
 
MapMapType i_maps
 
IntervalTimer i_timer
 
uint32 i_MaxInstanceId
 
MapUpdater m_updater
 

Friends

class Oregon::OperatorNew< MapManager >
 

Additional Inherited Members

- Protected Member Functions inherited from Oregon::Singleton< MapManager, Oregon::ClassLevelLockable< MapManager, ACE_Thread_Mutex > >
 Singleton ()
 

Detailed Description

Definition at line 31 of file MapManager.h.

Member Typedef Documentation

typedef Oregon::ClassLevelLockable<MapManager, ACE_Thread_Mutex>::Lock MapManager::Guard
private

Definition at line 165 of file MapManager.h.

typedef std::pair<UNORDERED_MAP<uint32, Map*>::iterator, bool> MapManager::MapMapPair
private

Definition at line 36 of file MapManager.h.

Definition at line 35 of file MapManager.h.

Definition at line 129 of file MapManager.h.

typedef std::set<Transport*> MapManager::TransportSet

Definition at line 126 of file MapManager.h.

Constructor & Destructor Documentation

MapManager::MapManager ( )
private
MapManager::~MapManager ( )
private

Definition at line 42 of file MapManager.cpp.

References Map::DeleteStateMachine(), i_maps, and m_Transports.

43 {
44  for (MapMapType::iterator iter = i_maps.begin(); iter != i_maps.end(); ++iter)
45  delete iter->second;
46 
47  for (TransportSet::iterator i = m_Transports.begin(); i != m_Transports.end(); ++i)
48  delete *i;
49 
51 }
static void DeleteStateMachine()
Definition: Map.cpp:194
MapMapType i_maps
Definition: MapManager.h:167
TransportSet m_Transports
Definition: MapManager.h:127
MapManager::MapManager ( const MapManager )
private

Member Function Documentation

Map * MapManager::_createBaseMap ( uint32  id)
private

Definition at line 105 of file MapManager.cpp.

References _findMap(), ASSERT, DIFFICULTY_NORMAL, i_gridCleanUpDelay, i_maps, MapEntry::Instanceable(), and sMapStore.

Referenced by CreateBaseMap(), and CreateMap().

106 {
107  Map* m = _findMap(id);
108 
109  if (m == NULL)
110  {
111  Guard guard(*this);
112 
113  const MapEntry* entry = sMapStore.LookupEntry(id);
114  if (entry && entry->Instanceable())
115  m = new MapInstanced(id, i_gridCleanUpDelay);
116  else
117  m = new Map(id, i_gridCleanUpDelay, 0, DIFFICULTY_NORMAL);
118  i_maps[id] = m;
119  }
120 
121  ASSERT(m != NULL);
122  return m;
123 }
bool Instanceable() const
Definition: DBCStructure.h:554
Map * _findMap(uint32 id) const
Definition: MapManager.h:159
uint32 i_gridCleanUpDelay
Definition: MapManager.h:166
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
MapMapType i_maps
Definition: MapManager.h:167
Definition: Map.h:266
Oregon::ClassLevelLockable< MapManager, ACE_Thread_Mutex >::Lock Guard
Definition: MapManager.h:165
#define ASSERT
Definition: Errors.h:29
Map* MapManager::_findMap ( uint32  id) const
inlineprivate

Definition at line 159 of file MapManager.h.

References i_maps.

Referenced by _createBaseMap(), and FindMap().

160  {
161  MapMapType::const_iterator iter = i_maps.find(id);
162  return (iter == i_maps.end() ? NULL : iter->second);
163  }
MapMapType i_maps
Definition: MapManager.h:167
void MapManager::checkAndCorrectGridStatesArray ( )
private

Definition at line 79 of file MapManager.cpp.

References ASSERT, i_GridStateErrorCount, i_GridStates, MAX_GRID_STATE, and sLog.

Referenced by GetMapUpdater().

80 {
81  bool ok = true;
82  for (int i = 0; i < MAX_GRID_STATE; i++)
83  {
84  if (i_GridStates[i] != si_GridStates[i])
85  {
86  sLog.outError("MapManager::checkGridStates(), GridState: si_GridStates is currupt !!!");
87  ok = false;
89  }
90  #if 0 // OREGON_DEBUG
91  // inner class checking only when compiled with debug
92  if (!si_GridStates[i]->checkMagic())
93  {
94  ok = false;
95  si_GridStates[i]->setMagic();
96  }
97  #endif
98  }
99  if (!ok)
101  if (i_GridStateErrorCount > 2)
102  ASSERT(false); // force a crash. Too many errors
103 }
GridState * si_GridStates[]
Definition: Map.cpp:38
GridState * i_GridStates[MAX_GRID_STATE]
Definition: MapManager.h:149
#define sLog
Log class singleton.
Definition: Log.h:187
int i_GridStateErrorCount
Definition: MapManager.h:150
#define ASSERT
Definition: Errors.h:29
Map * MapManager::CreateMap ( uint32  mapId,
const WorldObject obj,
uint32  loginInstanceId = 0 
)

Definition at line 125 of file MapManager.cpp.

References _createBaseMap(), ASSERT, Object::GetTypeId(), Map::Instanceable(), and TYPEID_PLAYER.

Referenced by WorldSession::HandleMoveWorldportAckOpcode(), Player::LoadFromDB(), LoadTransports(), and Transport::TeleportTransport().

126 {
127  ASSERT(obj);
128  //if (!obj->IsInWorld()) sLog.outError("GetMap: called for map %d with object (typeid %d, guid %d, mapid %d, instanceid %d) who is not in world!", id, obj->GetTypeId(), obj->GetGUIDLow(), obj->GetMapId(), obj->GetInstanceId());
129  Map* m = _createBaseMap(id);
130 
131  if (m && (obj->GetTypeId() == TYPEID_PLAYER) && m->Instanceable())
132  m = ((MapInstanced*)m)->CreateInstanceForPlayer(id, (Player*)obj, loginInstanceId);
133 
134  return m;
135 }
uint8 GetTypeId() const
Definition: Object.h:192
Definition: Map.h:266
#define ASSERT
Definition: Errors.h:29
bool Instanceable() const
Definition: Map.h:422
Map * _createBaseMap(uint32 id)
Definition: MapManager.cpp:105
Definition: Player.h:923
void MapManager::DoDelayedMovesAndRemoves ( )

Definition at line 253 of file MapManager.cpp.

Referenced by NormalizeOrientation().

254 {
255 }
bool MapManager::ExistMapAndVMap ( uint32  mapid,
float  x,
float  y 
)
static

Definition at line 257 of file MapManager.cpp.

References Oregon::ComputeGridCoord(), Map::ExistMap(), Map::ExistVMap(), MAX_NUMBER_OF_GRIDS, CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

Referenced by World::SetInitialWorldSettings(), and SetMapUpdateInterval().

258 {
260 
261  int gx = (MAX_NUMBER_OF_GRIDS - 1) - p.x_coord;
262  int gy = (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord;
263 
264  return Map::ExistMap(mapid, gx, gy) && Map::ExistVMap(mapid, gx, gy);
265 }
static bool ExistVMap(uint32 mapid, int gx, int gy)
Definition: Map.cpp:84
#define MAX_NUMBER_OF_GRIDS
Definition: GridDefines.h:33
uint32 y_coord
Definition: GridDefines.h:142
uint32 x_coord
Definition: GridDefines.h:141
static bool ExistMap(uint32 mapid, int gx, int gy)
Definition: Map.cpp:57
GridCoord ComputeGridCoord(float x, float y)
Definition: GridDefines.h:162
Map * MapManager::FindMap ( uint32  mapid,
uint32  instanceId = 0 
) const

Definition at line 137 of file MapManager.cpp.

References _findMap(), and Map::Instanceable().

Referenced by CreateBaseMap(), MapInstanced::CreateInstanceForPlayer(), Creature::GetLinkedCreatureRespawnTime(), Player::GetNextQuest(), PlayerCannotEnter(), FlightPathMovementGenerator::PreloadEndGrid(), Player::PrepareQuestMenu(), Group::ResetInstances(), Player::ResetInstances(), and InstanceSave::SaveToDB().

138 {
139  Map* map = _findMap(mapid);
140  if (!map)
141  return NULL;
142 
143  if (!map->Instanceable())
144  return instanceId == 0 ? map : NULL;
145 
146  return ((MapInstanced*)map)->FindInstanceMap(instanceId);
147 }
Map * _findMap(uint32 id) const
Definition: MapManager.h:159
Definition: Map.h:266
bool Instanceable() const
Definition: Map.h:422
uint32 MapManager::GenerateInstanceId ( )
inline
uint16 MapManager::GetAreaFlag ( uint32  mapid,
float  x,
float  y,
float  z 
) const
inline

Definition at line 47 of file MapManager.h.

References CreateBaseMap(), and Map::GetAreaFlag().

Referenced by GetAreaId(), and GetZoneId().

48  {
49  Map const* m = CreateBaseMap(mapid);
50  return m->GetAreaFlag(x, y, z);
51  }
Map const * CreateBaseMap(uint32 id) const
Definition: MapManager.h:41
Definition: Map.h:266
uint16 GetAreaFlag(float x, float y, float z, bool *isOutdoors=0) const
Definition: Map.cpp:1682
uint32 MapManager::GetAreaId ( uint32  mapid,
float  x,
float  y,
float  z 
)
inline

Definition at line 52 of file MapManager.h.

References GetAreaFlag(), and Map::GetAreaId().

53  {
54  return Map::GetAreaId(GetAreaFlag(mapid, x, y, z), mapid);
55  }
uint16 GetAreaFlag(uint32 mapid, float x, float y, float z) const
Definition: MapManager.h:47
static uint32 GetAreaId(uint16 areaflag, uint32 map_id)
Definition: Map.cpp:1822
MapUpdater* MapManager::GetMapUpdater ( )
inline

Definition at line 144 of file MapManager.h.

References checkAndCorrectGridStatesArray(), and m_updater.

Referenced by MapInstanced::Update().

144 { return &m_updater; }
MapUpdater m_updater
Definition: MapManager.h:171
uint32 MapManager::GetNumInstances ( )

Definition at line 297 of file MapManager.cpp.

References i_maps, and Map::Instanceable().

Referenced by GenerateInstanceId().

298 {
299  Guard guard(*this);
300 
301  uint32 ret = 0;
302  for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr)
303  {
304  Map* map = itr->second;
305  if (!map->Instanceable())
306  continue;
307  MapInstanced::InstancedMaps& maps = ((MapInstanced*)map)->GetInstancedMaps();
308  for (MapInstanced::InstancedMaps::iterator mitr = maps.begin(); mitr != maps.end(); ++mitr)
309  if (mitr->second->IsDungeon()) ret++;
310  }
311  return ret;
312 }
UNORDERED_MAP< uint32, Map * > InstancedMaps
Definition: MapInstanced.h:28
MapMapType i_maps
Definition: MapManager.h:167
Definition: Map.h:266
Oregon::ClassLevelLockable< MapManager, ACE_Thread_Mutex >::Lock Guard
Definition: MapManager.h:165
bool Instanceable() const
Definition: Map.h:422
ACE_UINT32 uint32
Definition: Define.h:71
uint32 MapManager::GetNumPlayersInInstances ( )

Definition at line 314 of file MapManager.cpp.

References LinkedListHead::getSize(), i_maps, and Map::Instanceable().

Referenced by GenerateInstanceId().

315 {
316  Guard guard(*this);
317 
318  uint32 ret = 0;
319  for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr)
320  {
321  Map* map = itr->second;
322  if (!map->Instanceable())
323  continue;
324  MapInstanced::InstancedMaps& maps = ((MapInstanced*)map)->GetInstancedMaps();
325  for (MapInstanced::InstancedMaps::iterator mitr = maps.begin(); mitr != maps.end(); ++mitr)
326  if (mitr->second->IsDungeon())
327  ret += ((InstanceMap*)mitr->second)->GetPlayers().getSize();
328  }
329  return ret;
330 }
UNORDERED_MAP< uint32, Map * > InstancedMaps
Definition: MapInstanced.h:28
uint32 getSize() const
Definition: LinkedList.h:115
MapMapType i_maps
Definition: MapManager.h:167
Definition: Map.h:266
Oregon::ClassLevelLockable< MapManager, ACE_Thread_Mutex >::Lock Guard
Definition: MapManager.h:165
bool Instanceable() const
Definition: Map.h:422
ACE_UINT32 uint32
Definition: Define.h:71
uint32 MapManager::GetZoneId ( uint32  mapid,
float  x,
float  y,
float  z 
)
inline

Definition at line 56 of file MapManager.h.

References GetAreaFlag(), Map::GetZoneId(), Initialize(), and Update().

Referenced by ObjectMgr::GetClosestGraveYard(), SocialMgr::GetFriendInfo(), Player::GetZoneIdFromDB(), ChatHandler::HandleNameTeleCommand(), WorldSession::HandleRequestPartyMemberStatsOpcode(), and WorldSession::HandleWhoOpcode().

57  {
58  return Map::GetZoneId(GetAreaFlag(mapid, x, y, z), mapid);
59  }
uint16 GetAreaFlag(uint32 mapid, float x, float y, float z) const
Definition: MapManager.h:47
static uint32 GetZoneId(uint16 areaflag, uint32 map_id)
Definition: Map.cpp:1832
void MapManager::Initialize ( void  )

Definition at line 53 of file MapManager.cpp.

References MapUpdater::activate(), CONFIG_NUMTHREADS, i_GridStateErrorCount, i_GridStates, InitMaxInstanceId(), Map::InitStateMachine(), m_updater, MAX_GRID_STATE, and sWorld.

Referenced by GetZoneId(), and World::SetInitialWorldSettings().

54 {
56 
57  // debugging code, should be deleted some day
58  {
59  for (uint8 i = 0; i < MAX_GRID_STATE; ++i)
61 
63  }
64  int num_threads(sWorld.getConfig(CONFIG_NUMTHREADS));
65  // Start mtmaps if needed.
66  if (num_threads > 0 && m_updater.activate(num_threads) == -1)
67  abort();
68 
70 }
int activate(size_t num_threads)
Definition: MapUpdater.cpp:79
GridState * si_GridStates[]
Definition: Map.cpp:38
GridState * i_GridStates[MAX_GRID_STATE]
Definition: MapManager.h:149
MapUpdater m_updater
Definition: MapManager.h:171
ACE_UINT8 uint8
Definition: Define.h:73
int i_GridStateErrorCount
Definition: MapManager.h:150
#define sWorld
Definition: World.h:860
static void InitStateMachine()
Definition: Map.cpp:186
void InitMaxInstanceId()
Definition: MapManager.cpp:288
void MapManager::InitializeVisibilityDistanceInfo ( )

Definition at line 72 of file MapManager.cpp.

References i_maps.

Referenced by GenerateInstanceId(), and ChatHandler::HandleReloadConfigCommand().

73 {
74  for (MapMapType::iterator iter = i_maps.begin(); iter != i_maps.end(); ++iter)
75  (*iter).second->InitVisibilityDistance();
76 }
MapMapType i_maps
Definition: MapManager.h:167
void MapManager::InitMaxInstanceId ( )

Definition at line 288 of file MapManager.cpp.

References CharacterDatabase, i_MaxInstanceId, and Database::Query().

Referenced by GenerateInstanceId(), and Initialize().

289 {
290  i_MaxInstanceId = 0;
291 
292  QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT MAX(id) FROM instance");
293  if (result)
294  i_MaxInstanceId = result->Fetch()[0].GetUInt32();
295 }
uint32 i_MaxInstanceId
Definition: MapManager.h:170
QueryResult_AutoPtr Query(const char *sql)
Definition: Database.cpp:383
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
DatabaseType CharacterDatabase
Accessor to the character database.
Definition: Main.cpp:54
bool MapManager::IsValidMAP ( uint32  mapid)
static

Definition at line 267 of file MapManager.cpp.

References MapEntry::Instanceable(), sMapStore, and sObjectMgr.

Referenced by IsValidMapCoord(), and SetMapUpdateInterval().

268 {
269  MapEntry const* mEntry = sMapStore.LookupEntry(mapid);
270  return mEntry && (!mEntry->Instanceable() || sObjectMgr.GetInstanceTemplate(mapid));
271 }
bool Instanceable() const
Definition: DBCStructure.h:554
#define sObjectMgr
Definition: ObjectMgr.h:1317
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
static bool MapManager::IsValidMapCoord ( uint32  mapid,
float  x,
float  y,
float  z 
)
inlinestatic

Definition at line 92 of file MapManager.h.

References IsValidMAP(), and Oregon::IsValidMapCoord().

93  {
94  return IsValidMAP(mapid) && Oregon::IsValidMapCoord(x, y, z);
95  }
bool IsValidMapCoord(float c)
Definition: GridDefines.h:192
static bool IsValidMAP(uint32 mapid)
Definition: MapManager.cpp:267
static bool MapManager::IsValidMapCoord ( uint32  mapid,
float  x,
float  y,
float  z,
float  o 
)
inlinestatic

Definition at line 97 of file MapManager.h.

References IsValidMAP(), and Oregon::IsValidMapCoord().

98  {
99  return IsValidMAP(mapid) && Oregon::IsValidMapCoord(x, y, z, o);
100  }
bool IsValidMapCoord(float c)
Definition: GridDefines.h:192
static bool IsValidMAP(uint32 mapid)
Definition: MapManager.cpp:267
static bool MapManager::IsValidMapCoord ( WorldLocation const &  loc)
inlinestatic

Definition at line 102 of file MapManager.h.

References WorldLocation::GetMapId(), Position::GetOrientation(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), and IsValidMapCoord().

103  {
104  return IsValidMapCoord(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), loc.GetOrientation());
105  }
static bool IsValidMapCoord(uint32 mapid, float x, float y)
Definition: MapManager.h:87
void MapManager::LoadTransports ( )

Definition at line 26 of file Transports.cpp.

References Transport::Create(), CreateMap(), GAMEOBJECT_TYPE_MO_TRANSPORT, Transport::GenerateWaypoints(), Field::GetCppString(), Oregon::Singleton< MapManager, Oregon::ClassLevelLockable< MapManager, ACE_Thread_Mutex > >::Instance(), Transport::m_period, m_Transports, m_TransportsByMap, Transport::m_WayPoints, GameObjectInfo::moTransport, Database::Query(), WorldObject::SetMap(), sLog, sObjectMgr, GameObjectInfo::type, and WorldDatabase.

Referenced by NormalizeOrientation(), and World::SetInitialWorldSettings().

27 {
28  QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, name, period FROM transports");
29 
30  uint32 count = 0;
31 
32  if (!result)
33  {
34  sLog.outString(">> Loaded %u transports", count);
35  return;
36  }
37 
38  do
39  {
40  Transport* t = new Transport;
41 
42  Field* fields = result->Fetch();
43 
44  uint32 entry = fields[0].GetUInt32();
45  std::string name = fields[1].GetCppString();
46  t->m_period = fields[2].GetUInt32();
47 
48  const GameObjectInfo* goinfo = sObjectMgr.GetGameObjectInfo(entry);
49 
50  if (!goinfo)
51  {
52  sLog.outErrorDb("Transport ID:%u, Name: %s, will not be loaded, gameobject_template missing", entry, name.c_str());
53  delete t;
54  continue;
55  }
56 
57  if (goinfo->type != GAMEOBJECT_TYPE_MO_TRANSPORT)
58  {
59  sLog.outErrorDb("Transport ID:%u, Name: %s, will not be loaded, gameobject_template type wrong", entry, name.c_str());
60  delete t;
61  continue;
62  }
63 
64  // sLog.outString("Loading transport %d between %s, %s", entry, name.c_str(), goinfo->name);
65 
66  std::set<uint32> mapsUsed;
67 
68  if (!t->GenerateWaypoints(goinfo->moTransport.taxiPathId, mapsUsed))
69  // skip transports with empty waypoints list
70  {
71  sLog.outErrorDb("Transport (path id %u) path size = 0. Transport ignored, check DBC files or transport GO data0 field.", goinfo->moTransport.taxiPathId);
72  delete t;
73  continue;
74  }
75 
76  float x, y, z, o;
77  uint32 mapid;
78  x = t->m_WayPoints[0].x;
79  y = t->m_WayPoints[0].y;
80  z = t->m_WayPoints[0].z;
81  mapid = t->m_WayPoints[0].mapid;
82  o = 1;
83 
84  // creates the Gameobject
85  if (!t->Create(entry, mapid, x, y, z, o, 100, 0))
86  {
87  delete t;
88  continue;
89  }
90 
91  m_Transports.insert(t);
92 
93  for (std::set<uint32>::iterator i = mapsUsed.begin(); i != mapsUsed.end(); ++i)
94  m_TransportsByMap[*i].insert(t);
95 
96  //If we someday decide to use the grid to track transports, here:
97  t->SetMap(MapManager::Instance().CreateMap(mapid, t, 0));
98 
99  //t->GetMap()->Add<GameObject>((GameObject* )t);
100 
101  ++count;
102  }
103  while (result->NextRow());
104 
105  sLog.outString(">> Loaded %u transports", count);
106 
107  // check transport data DB integrity
108  result = WorldDatabase.Query("SELECT gameobject.guid,gameobject.id,transports.name FROM gameobject,transports WHERE gameobject.id = transports.entry");
109  if (result) // wrong data found
110  {
111  do
112  {
113  Field* fields = result->Fetch();
114 
115  uint32 guid = fields[0].GetUInt32();
116  uint32 entry = fields[1].GetUInt32();
117  std::string name = fields[2].GetCppString();
118  sLog.outErrorDb("Transport %u '%s' has record (GUID: %u) in gameobject. Transports MUST NOT have any records in gameobject or its behavior will be unpredictable/bugged.", entry, name.c_str(), guid);
119  }
120  while (result->NextRow());
121  }
122 }
bool GenerateWaypoints(uint32 pathid, std::set< uint32 > &mapids)
Definition: Transports.cpp:191
WayPointMap m_WayPoints
Definition: Transports.h:74
DatabaseType WorldDatabase
Accessor to the world database.
Definition: Main.cpp:53
Definition: Field.h:24
virtual void SetMap(Map *map)
Definition: Object.cpp:1981
#define sLog
Log class singleton.
Definition: Log.h:187
struct GameObjectInfo::@59::@74 moTransport
QueryResult_AutoPtr Query(const char *sql)
Definition: Database.cpp:383
#define sObjectMgr
Definition: ObjectMgr.h:1317
std::string GetCppString() const
Definition: Field.h:52
bool Create(uint32 guidlow, uint32 mapid, float x, float y, float z, float ang, uint32 animprogress, uint32 dynflags)
Definition: Transports.cpp:130
TransportMap m_TransportsByMap
Definition: MapManager.h:130
Map * CreateMap(uint32 mapId, const WorldObject *obj, uint32 loginInstanceId=0)
Definition: MapManager.cpp:125
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
uint32 m_period
Definition: Transports.h:76
TransportSet m_Transports
Definition: MapManager.h:127
ACE_UINT32 uint32
Definition: Define.h:71
static float MapManager::NormalizeOrientation ( float  o)
inlinestatic

Definition at line 108 of file MapManager.h.

References DoDelayedMovesAndRemoves(), and LoadTransports().

109  {
110  // fmod only supports positive numbers. Thus we have
111  // to emulate negative numbers
112  if (o < 0)
113  {
114  float mod = o * -1;
115  mod = fmod(mod, 2.0f * static_cast<float>(M_PI));
116  mod = -mod + 2.0f * M_PI;
117  return mod;
118  }
119  return fmod(o, 2.0f * static_cast<float>(M_PI));
120  }
MapManager& MapManager::operator= ( const MapManager )
private
Map::EnterState MapManager::PlayerCannotEnter ( uint32  mapid,
Player player,
bool  loginCheck = false 
)

Definition at line 153 of file MapManager.cpp.

References Map::CAN_ENTER, Map::CANNOT_ENTER_CORPSE_IN_DIFFERENT_INSTANCE, Map::CANNOT_ENTER_DIFFICULTY_UNAVAILABLE, Map::CANNOT_ENTER_NO_ENTRY, Map::CANNOT_ENTER_NOT_IN_RAID, Map::CANNOT_ENTER_UNINSTANCED_DUNGEON, Map::CANNOT_ENTER_UNSPECIFIED_REASON, CONFIG_INSTANCE_IGNORE_RAID, DIFFICULTY_HEROIC, FindMap(), Group::GetBoundInstance(), Player::GetCorpse(), Player::GetDifficulty(), Player::GetGroup(), InstanceSave::GetInstanceId(), WorldObject::GetName(), Player::GetSession(), WorldSession::GetSessionDbcLocale(), Oregon::Singleton< MapManager, Oregon::ClassLevelLockable< MapManager, ACE_Thread_Mutex > >::Instance(), Unit::IsAlive(), MapEntry::IsDungeon(), Player::IsGameMaster(), MapEntry::IsRaid(), Group::isRaidGroup(), MapEntry::name, InstanceTemplate::parent, Player::Satisfy(), InstanceGroupBind::save, sLog, sMapStore, sObjectMgr, MapEntry::SupportsHeroicMode(), and sWorld.

Referenced by WorldSession::HandleAreaTriggerOpcode().

154 {
155  const MapEntry* entry = sMapStore.LookupEntry(mapid);
156  if (!entry)
158 
159  if (!entry->IsDungeon())
160  return Map::CAN_ENTER;
161 
162  //Other requirements
163  if (!player->Satisfy(sObjectMgr.GetAccessRequirement(mapid), mapid, true))
165 
166  InstanceTemplate const* instance = sObjectMgr.GetInstanceTemplate(mapid);
167  if (!instance)
169 
170  //The player has a heroic mode and tries to enter into instance which has no a heroic mode
171  if (!entry->SupportsHeroicMode() && player->GetDifficulty() == DIFFICULTY_HEROIC)
173 
174  //Bypass checks for GMs
175  if (player->IsGameMaster())
176  return Map::CAN_ENTER;
177 
178  const char* mapName = entry->name[player->GetSession()->GetSessionDbcLocale()];
179 
180  Group* group = player->GetGroup();
181  if (entry->IsRaid()) // can only enter in a raid group
182  if ((!group || !group->isRaidGroup()) && !sWorld.getConfig(CONFIG_INSTANCE_IGNORE_RAID))
184 
185 
186  if (!player->IsAlive())
187  {
188  if (Corpse* corpse = player->GetCorpse())
189  {
190  // let enter in ghost mode in instance that connected to inner instance with corpse
191  uint32 instance_map = corpse->GetMapId();
192  do
193  {
194  if (instance_map == mapid)
195  break;
196 
197  InstanceTemplate const* instance = sObjectMgr.GetInstanceTemplate(instance_map);
198  instance_map = instance ? instance->parent : 0;
199  }
200  while (instance_map);
201 
202  if (!instance_map)
204 
205  sLog.outDebug("MAP: Player '%s' has corpse in instance '%s' and can enter", player->GetName(), mapName);
206  }
207  else
208  sLog.outDebug("Map::CanEnter - player '%s' is dead but doesn't have a corpse!", player->GetName());
209  }
210 
211  //Get instance where player's group is bound & its map
212  if (!loginCheck && group)
213  {
214  InstanceGroupBind* boundInstance = group->GetBoundInstance(entry);
215  if (boundInstance && boundInstance->save)
216  if (Map* boundMap = MapManager::Instance().FindMap(mapid, boundInstance->save->GetInstanceId()))
217  if (Map::EnterState denyReason = boundMap->CannotEnter(player))
218  return denyReason;
219  }
220 
221  // @todo Implement 5 dungeons per hour limit
222 
223  return Map::CAN_ENTER;
224 }
InstanceSave * save
Definition: Group.h:145
Group * GetGroup()
Definition: Player.h:2577
Definition: Corpse.h:48
bool isRaidGroup() const
Definition: Group.h:210
#define sLog
Log class singleton.
Definition: Log.h:187
bool IsGameMaster() const
Definition: Player.h:1010
LocaleConstant GetSessionDbcLocale() const
Definition: WorldSession.h:233
DungeonDifficulty GetDifficulty()
Definition: Player.h:1873
#define sObjectMgr
Definition: ObjectMgr.h:1317
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
uint32 GetInstanceId()
bool IsAlive() const
Definition: Unit.h:1336
bool IsDungeon() const
Definition: DBCStructure.h:550
Corpse * GetCorpse() const
Definition: Player.cpp:4321
Definition: Map.h:266
Map * FindMap(uint32 mapid, uint32 instanceId=0) const
Definition: MapManager.cpp:137
bool IsRaid() const
Definition: DBCStructure.h:558
uint32 parent
Definition: Map.h:233
const char * GetName() const
Definition: Object.h:680
bool Satisfy(AccessRequirement const *, uint32 target_map, bool report=false)
Definition: Player.cpp:16053
EnterState
Definition: Map.h:399
WorldSession * GetSession() const
Definition: Player.h:1947
#define sWorld
Definition: World.h:860
InstanceGroupBind * GetBoundInstance(Player *player)
Definition: Group.cpp:1591
ACE_UINT32 uint32
Definition: Define.h:71
bool SupportsHeroicMode() const
Definition: DBCStructure.h:574
char * name[16]
Definition: DBCStructure.h:518
Definition: Group.h:154
void MapManager::SetGridCleanUpDelay ( uint32  t)
inline

Definition at line 64 of file MapManager.h.

References i_gridCleanUpDelay, and MIN_GRID_DELAY.

Referenced by World::LoadConfigSettings().

65  {
66  if (t < MIN_GRID_DELAY)
68  else
70  }
#define MIN_GRID_DELAY
Definition: GridDefines.h:40
uint32 i_gridCleanUpDelay
Definition: MapManager.h:166
void MapManager::SetMapUpdateInterval ( uint32  t)
inline

Definition at line 72 of file MapManager.h.

References ExistMapAndVMap(), i_timer, IsValidMAP(), MIN_MAP_UPDATE_DELAY, IntervalTimer::Reset(), IntervalTimer::SetInterval(), and UnloadAll().

Referenced by World::LoadConfigSettings().

73  {
74  if (t > MIN_MAP_UPDATE_DELAY)
76 
78  i_timer.Reset();
79  }
void SetInterval(time_t interval)
Definition: Timer.h:122
#define MIN_MAP_UPDATE_DELAY
Definition: GridDefines.h:41
void Reset()
Definition: Timer.h:113
IntervalTimer i_timer
Definition: MapManager.h:168
void MapManager::UnloadAll ( )

Definition at line 273 of file MapManager.cpp.

References MapUpdater::activated(), MapUpdater::deactivate(), i_maps, and m_updater.

Referenced by Master::Run(), and SetMapUpdateInterval().

274 {
275  for (MapMapType::iterator iter = i_maps.begin(); iter != i_maps.end(); ++iter)
276  iter->second->UnloadAll();
277 
278  while (!i_maps.empty())
279  {
280  delete i_maps.begin()->second;
281  i_maps.erase(i_maps.begin());
282  }
283 
284  if (m_updater.activated())
286 }
int deactivate()
Definition: MapUpdater.cpp:84
MapMapType i_maps
Definition: MapManager.h:167
MapUpdater m_updater
Definition: MapManager.h:171
bool activated()
Definition: MapUpdater.cpp:118
void MapManager::Update ( time_t  diff)

Definition at line 226 of file MapManager.cpp.

References MapUpdater::activated(), IntervalTimer::GetCurrent(), i_maps, i_timer, Oregon::Singleton< ObjectAccessor, Oregon::ClassLevelLockable< ObjectAccessor, ACE_Thread_Mutex > >::Instance(), m_Transports, m_updater, IntervalTimer::Passed(), MapUpdater::schedule_update(), IntervalTimer::SetCurrent(), IntervalTimer::Update(), ObjectAccessor::Update(), and MapUpdater::wait().

Referenced by GetZoneId(), and World::Update().

227 {
228  i_timer.Update(diff);
229  if (!i_timer.Passed())
230  return;
231 
232  MapMapType::iterator iter = i_maps.begin();
233  for (; iter != i_maps.end(); ++iter)
234  {
235  if (m_updater.activated())
236  m_updater.schedule_update(*iter->second, i_timer.GetCurrent());
237  else
238  iter->second->Update(i_timer.GetCurrent());
239  }
240  if (m_updater.activated())
241  m_updater.wait();
242 
243  for (iter = i_maps.begin(); iter != i_maps.end(); ++iter)
244  iter->second->DelayedUpdate(uint32(i_timer.GetCurrent()));
245 
247  for (TransportSet::iterator iter = m_Transports.begin(); iter != m_Transports.end(); ++iter)
248  (*iter)->Update(i_timer.GetCurrent());
249 
250  i_timer.SetCurrent(0);
251 }
int wait()
Definition: MapUpdater.cpp:91
time_t GetCurrent() const
Definition: Timer.h:130
void Update(time_t diff)
Definition: Timer.h:104
int schedule_update(Map &map, ACE_UINT32 diff)
Definition: MapUpdater.cpp:101
bool Passed()
Definition: Timer.h:109
MapMapType i_maps
Definition: MapManager.h:167
MapUpdater m_updater
Definition: MapManager.h:171
void Update(uint32 diff)
TransportSet m_Transports
Definition: MapManager.h:127
void SetCurrent(time_t current)
Definition: Timer.h:118
ACE_UINT32 uint32
Definition: Define.h:71
bool activated()
Definition: MapUpdater.cpp:118
IntervalTimer i_timer
Definition: MapManager.h:168

Friends And Related Function Documentation

friend class Oregon::OperatorNew< MapManager >
friend

Definition at line 34 of file MapManager.h.

Member Data Documentation

uint32 MapManager::i_gridCleanUpDelay
private

Definition at line 166 of file MapManager.h.

Referenced by _createBaseMap(), MapManager(), and SetGridCleanUpDelay().

int MapManager::i_GridStateErrorCount
private

Definition at line 150 of file MapManager.h.

Referenced by checkAndCorrectGridStatesArray(), and Initialize().

GridState* MapManager::i_GridStates[MAX_GRID_STATE]
private

Definition at line 149 of file MapManager.h.

Referenced by checkAndCorrectGridStatesArray(), and Initialize().

uint32 MapManager::i_MaxInstanceId
private

Definition at line 170 of file MapManager.h.

Referenced by GenerateInstanceId(), and InitMaxInstanceId().

IntervalTimer MapManager::i_timer
private

Definition at line 168 of file MapManager.h.

Referenced by MapManager(), SetMapUpdateInterval(), and Update().

TransportMap MapManager::m_TransportsByMap
MapUpdater MapManager::m_updater
private

Definition at line 171 of file MapManager.h.

Referenced by GetMapUpdater(), Initialize(), UnloadAll(), and Update().


The documentation for this class was generated from the following files: