OregonCore  revision fb2a440-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:210
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:922
void MapManager::DoDelayedMovesAndRemoves ( )

Definition at line 252 of file MapManager.cpp.

Referenced by NormalizeOrientation().

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

Definition at line 256 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().

257 {
259 
260  int gx = (MAX_NUMBER_OF_GRIDS - 1) - p.x_coord;
261  int gy = (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord;
262 
263  return Map::ExistMap(mapid, gx, gy) && Map::ExistVMap(mapid, gx, gy);
264 }
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 296 of file MapManager.cpp.

References i_maps, and Map::Instanceable().

Referenced by GenerateInstanceId().

297 {
298  Guard guard(*this);
299 
300  uint32 ret = 0;
301  for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr)
302  {
303  Map* map = itr->second;
304  if (!map->Instanceable())
305  continue;
306  MapInstanced::InstancedMaps& maps = ((MapInstanced*)map)->GetInstancedMaps();
307  for (MapInstanced::InstancedMaps::iterator mitr = maps.begin(); mitr != maps.end(); ++mitr)
308  if (mitr->second->IsDungeon()) ret++;
309  }
310  return ret;
311 }
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 313 of file MapManager.cpp.

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

Referenced by GenerateInstanceId().

314 {
315  Guard guard(*this);
316 
317  uint32 ret = 0;
318  for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr)
319  {
320  Map* map = itr->second;
321  if (!map->Instanceable())
322  continue;
323  MapInstanced::InstancedMaps& maps = ((MapInstanced*)map)->GetInstancedMaps();
324  for (MapInstanced::InstancedMaps::iterator mitr = maps.begin(); mitr != maps.end(); ++mitr)
325  if (mitr->second->IsDungeon())
326  ret += ((InstanceMap*)mitr->second)->GetPlayers().getSize();
327  }
328  return ret;
329 }
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:287
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 287 of file MapManager.cpp.

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

Referenced by GenerateInstanceId(), and Initialize().

288 {
289  i_MaxInstanceId = 0;
290 
291  QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT MAX(id) FROM instance");
292  if (result)
293  i_MaxInstanceId = result->Fetch()[0].GetUInt32();
294 }
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 266 of file MapManager.cpp.

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

Referenced by IsValidMapCoord(), and SetMapUpdateInterval().

267 {
268  MapEntry const* mEntry = sMapStore.LookupEntry(mapid);
269  return mEntry && (!mEntry->Instanceable() || sObjectMgr.GetInstanceTemplate(mapid));
270 }
bool Instanceable() const
Definition: DBCStructure.h:554
#define sObjectMgr
Definition: ObjectMgr.h:1285
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:266
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:266
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:1954
#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:1285
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 InstanceTemplate::access_id, 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  InstanceTemplate const* instance = sObjectMgr.GetInstanceTemplate(mapid);
163  if (!instance)
165 
166  //The player has a heroic mode and tries to enter into instance which has no a heroic mode
167  if (!entry->SupportsHeroicMode() && player->GetDifficulty() == DIFFICULTY_HEROIC)
169 
170  //Bypass checks for GMs
171  if (player->IsGameMaster())
172  return Map::CAN_ENTER;
173 
174  const char* mapName = entry->name[player->GetSession()->GetSessionDbcLocale()];
175 
176  Group* group = player->GetGroup();
177  if (entry->IsRaid()) // can only enter in a raid group
178  if ((!group || !group->isRaidGroup()) && !sWorld.getConfig(CONFIG_INSTANCE_IGNORE_RAID))
180 
181 
182  if (!player->IsAlive())
183  {
184  if (Corpse* corpse = player->GetCorpse())
185  {
186  // let enter in ghost mode in instance that connected to inner instance with corpse
187  uint32 instance_map = corpse->GetMapId();
188  do
189  {
190  if (instance_map == mapid)
191  break;
192 
193  InstanceTemplate const* instance = sObjectMgr.GetInstanceTemplate(instance_map);
194  instance_map = instance ? instance->parent : 0;
195  }
196  while (instance_map);
197 
198  if (!instance_map)
200 
201  sLog.outDebug("MAP: Player '%s' has corpse in instance '%s' and can enter", player->GetName(), mapName);
202  }
203  else
204  sLog.outDebug("Map::CanEnter - player '%s' is dead but doesn't have a corpse!", player->GetName());
205  }
206 
207  //Get instance where player's group is bound & its map
208  if (!loginCheck && group)
209  {
210  InstanceGroupBind* boundInstance = group->GetBoundInstance(entry);
211  if (boundInstance && boundInstance->save)
212  if (Map* boundMap = MapManager::Instance().FindMap(mapid, boundInstance->save->GetInstanceId()))
213  if (Map::EnterState denyReason = boundMap->CannotEnter(player))
214  return denyReason;
215  }
216 
217  // @todo Implement 5 dungeons per hour limit
218 
219  if (player->Satisfy(sObjectMgr.GetAccessRequirement(instance->access_id), mapid, true))
220  return Map::CAN_ENTER;
221  else
223 }
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:1009
LocaleConstant GetSessionDbcLocale() const
Definition: WorldSession.h:233
DungeonDifficulty GetDifficulty()
Definition: Player.h:1870
#define sObjectMgr
Definition: ObjectMgr.h:1285
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:4328
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:704
bool Satisfy(AccessRequirement const *, uint32 target_map, bool report=false)
Definition: Player.cpp:16051
EnterState
Definition: Map.h:399
WorldSession * GetSession() const
Definition: Player.h:1944
#define sWorld
Definition: World.h:860
InstanceGroupBind * GetBoundInstance(Player *player)
Definition: Group.cpp:1591
uint32 access_id
Definition: Map.h:236
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 272 of file MapManager.cpp.

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

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

273 {
274  for (MapMapType::iterator iter = i_maps.begin(); iter != i_maps.end(); ++iter)
275  iter->second->UnloadAll();
276 
277  while (!i_maps.empty())
278  {
279  delete i_maps.begin()->second;
280  i_maps.erase(i_maps.begin());
281  }
282 
283  if (m_updater.activated())
285 }
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 225 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().

226 {
227  i_timer.Update(diff);
228  if (!i_timer.Passed())
229  return;
230 
231  MapMapType::iterator iter = i_maps.begin();
232  for (; iter != i_maps.end(); ++iter)
233  {
234  if (m_updater.activated())
235  m_updater.schedule_update(*iter->second, i_timer.GetCurrent());
236  else
237  iter->second->Update(i_timer.GetCurrent());
238  }
239  if (m_updater.activated())
240  m_updater.wait();
241 
242  for (iter = i_maps.begin(); iter != i_maps.end(); ++iter)
243  iter->second->DelayedUpdate(uint32(i_timer.GetCurrent()));
244 
246  for (TransportSet::iterator iter = m_Transports.begin(); iter != m_Transports.end(); ++iter)
247  (*iter)->Update(i_timer.GetCurrent());
248 
249  i_timer.SetCurrent(0);
250 }
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: