AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
MapMgr Class Reference

#include "MapMgr.h"

Public Member Functions

MapCreateBaseMap (uint32 mapId)
 
MapFindBaseNonInstanceMap (uint32 mapId) const
 
MapCreateMap (uint32 mapId, Player *player)
 
MapFindMap (uint32 mapId, uint32 instanceId) const
 
MapFindBaseMap (uint32 mapId) const
 
uint32 GetAreaId (uint32 phaseMask, uint32 mapid, float x, float y, float z) const
 
uint32 GetAreaId (uint32 phaseMask, uint32 mapid, Position const &pos) const
 
uint32 GetAreaId (uint32 phaseMask, WorldLocation const &loc) const
 
uint32 GetZoneId (uint32 phaseMask, uint32 mapid, float x, float y, float z) const
 
uint32 GetZoneId (uint32 phaseMask, uint32 mapid, Position const &pos) const
 
uint32 GetZoneId (uint32 phaseMask, WorldLocation const &loc) const
 
void GetZoneAndAreaId (uint32 phaseMask, uint32 &zoneid, uint32 &areaid, uint32 mapid, float x, float y, float z)
 
void Initialize (void)
 
void Update (uint32)
 
void SetMapUpdateInterval (uint32 t)
 
void UnloadAll ()
 

Static Public Member Functions

static MapMgrinstance ()
 
static bool ExistMapAndVMap (uint32 mapid, float x, float y)
 
static bool IsValidMAP (uint32 mapid, bool startUp)
 
static bool IsValidMapCoord (uint32 mapid, Position const &pos)
 
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)
 

GetInstanceIDs

Returns
vector of instance IDs
typedef std::unordered_map< uint32, Map * > MapMapType
 
typedef std::vector< bool > InstanceIds
 
std::mutex Lock
 
MapMapType i_maps
 
IntervalTimer i_timer [4]
 
uint8 mapUpdateStep
 
InstanceIds _instanceIds
 
uint32 _nextInstanceId
 
MapUpdater m_updater
 
std::vector< bool > GetInstanceIDs ()
 
void DoDelayedMovesAndRemoves ()
 
Map::EnterState PlayerCannotEnter (uint32 mapid, Player *player, bool loginCheck=false)
 
void InitializeVisibilityDistanceInfo ()
 
void GetNumInstances (uint32 &dungeons, uint32 &battlegrounds, uint32 &arenas)
 
void GetNumPlayersInInstances (uint32 &dungeons, uint32 &battlegrounds, uint32 &arenas, uint32 &spectators)
 
void InitInstanceIds ()
 
void RegisterInstanceId (uint32 instanceId)
 
uint32 GenerateInstanceId ()
 
MapUpdaterGetMapUpdater ()
 
template<typename Worker >
void DoForAllMaps (Worker &&worker)
 
template<typename Worker >
void DoForAllMapsWithMapId (uint32 mapId, Worker &&worker)
 
 MapMgr ()
 
 ~MapMgr ()
 
 MapMgr (const MapMgr &)
 
MapMgroperator= (const MapMgr &)
 

Detailed Description

Member Typedef Documentation

◆ InstanceIds

typedef std::vector<bool> MapMgr::InstanceIds
private

◆ MapMapType

typedef std::unordered_map<uint32, Map*> MapMgr::MapMapType
private

Constructor & Destructor Documentation

◆ MapMgr() [1/2]

MapMgr::MapMgr ( )
private
38{
40 mapUpdateStep = 0;
42}
@ CONFIG_INTERVAL_MAPUPDATE
Definition: IWorld.h:215
#define sWorld
Definition: World.h:444
void SetInterval(time_t interval)
Definition: Timer.h:179
IntervalTimer i_timer[4]
Definition: MapMgr.h:174
uint8 mapUpdateStep
Definition: MapMgr.h:175
uint32 _nextInstanceId
Definition: MapMgr.h:178

References _nextInstanceId, CONFIG_INTERVAL_MAPUPDATE, i_timer, mapUpdateStep, IntervalTimer::SetInterval(), and sWorld.

◆ ~MapMgr()

MapMgr::~MapMgr ( )
private
45{
46}

◆ MapMgr() [2/2]

MapMgr::MapMgr ( const MapMgr )
private

Member Function Documentation

◆ CreateBaseMap()

Map * MapMgr::CreateBaseMap ( uint32  mapId)
70{
71 Map* map = FindBaseMap(id);
72
73 if (!map)
74 {
75 std::lock_guard<std::mutex> guard(Lock);
76
77 map = FindBaseMap(id);
78 if (!map) // pussywizard: check again after acquiring mutex
79 {
80 MapEntry const* entry = sMapStore.LookupEntry(id);
81 ASSERT(entry);
82
83 if (entry->Instanceable())
84 map = new MapInstanced(id);
85 else
86 {
87 map = new Map(id, 0, REGULAR_DIFFICULTY);
88 map->LoadRespawnTimes();
89 map->LoadCorpseData();
90 }
91
92 i_maps[id] = map;
93 }
94 }
95
96 ASSERT(map);
97 return map;
98}
#define ASSERT
Definition: Errors.h:68
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
@ REGULAR_DIFFICULTY
Definition: DBCEnums.h:267
Definition: Map.h:313
void LoadRespawnTimes()
Definition: Map.cpp:3417
void LoadCorpseData()
Definition: Map.cpp:4014
Definition: MapInstanced.h:26
Map * FindBaseMap(uint32 mapId) const
Definition: MapMgr.h:45
std::mutex Lock
Definition: MapMgr.h:172
MapMapType i_maps
Definition: MapMgr.h:173
Definition: DBCStructure.h:1325
bool Instanceable() const
Definition: DBCStructure.h:1353

References ASSERT, FindBaseMap(), i_maps, MapEntry::Instanceable(), Map::LoadCorpseData(), Map::LoadRespawnTimes(), Lock, REGULAR_DIFFICULTY, and sMapStore.

Referenced by CreateMap(), GetAreaId(), GetZoneAndAreaId(), and GetZoneId().

◆ CreateMap()

Map * MapMgr::CreateMap ( uint32  mapId,
Player player 
)
109{
110 Map* m = CreateBaseMap(id);
111
112 if (m && m->Instanceable())
113 m = ((MapInstanced*)m)->CreateInstanceForPlayer(id, player);
114
115 return m;
116}
bool Instanceable() const
Definition: Map.h:447
Map * CreateBaseMap(uint32 mapId)
Definition: MapMgr.cpp:69

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

◆ DoDelayedMovesAndRemoves()

void MapMgr::DoDelayedMovesAndRemoves ( )
296{
297}

◆ DoForAllMaps()

template<typename Worker >
void MapMgr::DoForAllMaps ( Worker &&  worker)
184{
185 std::lock_guard<std::mutex> guard(Lock);
186
187 for (auto& mapPair : i_maps)
188 {
189 Map* map = mapPair.second;
190 if (MapInstanced* mapInstanced = map->ToMapInstanced())
191 {
192 MapInstanced::InstancedMaps& instances = mapInstanced->GetInstancedMaps();
193 for (auto& instancePair : instances)
194 worker(instancePair.second);
195 }
196 else
197 worker(map);
198 }
199}
MapInstanced * ToMapInstanced()
Definition: Map.h:543
std::unordered_map< uint32, Map * > InstancedMaps
Definition: MapInstanced.h:29

References i_maps, Lock, and Map::ToMapInstanced().

◆ DoForAllMapsWithMapId()

template<typename Worker >
void MapMgr::DoForAllMapsWithMapId ( uint32  mapId,
Worker &&  worker 
)
inline
203{
204 std::lock_guard<std::mutex> guard(Lock);
205
206 auto itr = i_maps.find(mapId);
207 if (itr != i_maps.end())
208 {
209 Map* map = itr->second;
210 if (MapInstanced* mapInstanced = map->ToMapInstanced())
211 {
212 MapInstanced::InstancedMaps& instances = mapInstanced->GetInstancedMaps();
213 for (auto& p : instances)
214 worker(p.second);
215 }
216 else
217 worker(map);
218 }
219}

References i_maps, Lock, and Map::ToMapInstanced().

◆ ExistMapAndVMap()

bool MapMgr::ExistMapAndVMap ( uint32  mapid,
float  x,
float  y 
)
static
300{
302
303 int gx = 63 - p.x_coord;
304 int gy = 63 - p.y_coord;
305
306 return Map::ExistMap(mapid, gx, gy) && Map::ExistVMap(mapid, gx, gy);
307}
GridCoord ComputeGridCoord(float x, float y)
Definition: GridDefines.h:186
Definition: GridDefines.h:86
uint32 x_coord
Definition: GridDefines.h:153
uint32 y_coord
Definition: GridDefines.h:154
static bool ExistVMap(uint32 mapid, int gx, int gy)
Definition: Map.cpp:116
static bool ExistMap(uint32 mapid, int gx, int gy)
Definition: Map.cpp:85

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

Referenced by World::SetInitialWorldSettings().

◆ FindBaseMap()

Map * MapMgr::FindBaseMap ( uint32  mapId) const
inline
46 {
47 MapMapType::const_iterator iter = i_maps.find(mapId);
48 return (iter == i_maps.end() ? nullptr : iter->second);
49 }

References i_maps.

Referenced by CreateBaseMap(), FindBaseNonInstanceMap(), and FindMap().

◆ FindBaseNonInstanceMap()

Map * MapMgr::FindBaseNonInstanceMap ( uint32  mapId) const
101{
102 Map* map = FindBaseMap(mapId);
103 if (map && map->Instanceable())
104 return nullptr;
105 return map;
106}

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

◆ FindMap()

Map * MapMgr::FindMap ( uint32  mapId,
uint32  instanceId 
) const
119{
120 Map* map = FindBaseMap(mapid);
121 if (!map)
122 return nullptr;
123
124 if (!map->Instanceable())
125 return instanceId == 0 ? map : nullptr;
126
127 return ((MapInstanced*)map)->FindInstanceMap(instanceId);
128}

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

◆ GenerateInstanceId()

uint32 MapMgr::GenerateInstanceId ( )
405{
406 uint32 newInstanceId = _nextInstanceId;
407
408 // find the lowest available id starting from the current _nextInstanceId
409 while (_nextInstanceId < 0xFFFFFFFF && ++_nextInstanceId < _instanceIds.size() && _instanceIds[_nextInstanceId]);
410
411 if (_nextInstanceId == 0xFFFFFFFF)
412 {
413 LOG_ERROR("server.worldserver", "Instance ID overflow!! Can't continue, shutting down server. ");
415 }
416
417 return newInstanceId;
418}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:156
std::uint32_t uint32
Definition: Define.h:107
@ ERROR_EXIT_CODE
Definition: World.h:55
InstanceIds _instanceIds
Definition: MapMgr.h:177
static void StopNow(uint8 exitcode)
Definition: World.h:254

References _instanceIds, _nextInstanceId, ERROR_EXIT_CODE, LOG_ERROR, and World::StopNow().

◆ GetAreaId() [1/3]

uint32 MapMgr::GetAreaId ( uint32  phaseMask,
uint32  mapid,
float  x,
float  y,
float  z 
) const
inline
52 {
53 Map const* m = const_cast<MapMgr*>(this)->CreateBaseMap(mapid);
54 return m->GetAreaId(phaseMask, x, y, z);
55 }
uint32 GetAreaId(uint32 phaseMask, float x, float y, float z) const
Definition: Map.cpp:2147
Definition: MapMgr.h:36

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

◆ GetAreaId() [2/3]

uint32 MapMgr::GetAreaId ( uint32  phaseMask,
uint32  mapid,
Position const &  pos 
) const
inline
56{ return GetAreaId(phaseMask, mapid, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ()); }
uint32 GetAreaId(uint32 phaseMask, uint32 mapid, float x, float y, float z) const
Definition: MapMgr.h:51

References GetAreaId(), Position::GetPositionX(), Position::GetPositionY(), and Position::GetPositionZ().

Referenced by GetAreaId().

◆ GetAreaId() [3/3]

uint32 MapMgr::GetAreaId ( uint32  phaseMask,
WorldLocation const &  loc 
) const
inline
57{ return GetAreaId(phaseMask, loc.GetMapId(), loc); }

References GetAreaId(), and WorldLocation::GetMapId().

Referenced by GetAreaId().

◆ GetInstanceIDs()

std::vector< bool > MapMgr::GetInstanceIDs ( )
inline
136 {
137 return _instanceIds;
138 }

References _instanceIds.

◆ GetMapUpdater()

MapUpdater * MapMgr::GetMapUpdater ( )
inline
154{ return &m_updater; }
MapUpdater m_updater
Definition: MapMgr.h:179

References m_updater.

◆ GetNumInstances()

void MapMgr::GetNumInstances ( uint32 dungeons,
uint32 battlegrounds,
uint32 arenas 
)
339{
340 for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr)
341 {
342 Map* map = itr->second;
343 if (!map->Instanceable())
344 continue;
345 MapInstanced::InstancedMaps& maps = ((MapInstanced*)map)->GetInstancedMaps();
346 for (MapInstanced::InstancedMaps::iterator mitr = maps.begin(); mitr != maps.end(); ++mitr)
347 {
348 if (mitr->second->IsDungeon()) dungeons++;
349 else if (mitr->second->IsBattleground()) battlegrounds++;
350 else if (mitr->second->IsBattleArena()) arenas++;
351 }
352 }
353}

References i_maps, and Map::Instanceable().

◆ GetNumPlayersInInstances()

void MapMgr::GetNumPlayersInInstances ( uint32 dungeons,
uint32 battlegrounds,
uint32 arenas,
uint32 spectators 
)
356{
357 for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr)
358 {
359 Map* map = itr->second;
360 if (!map->Instanceable())
361 continue;
362 MapInstanced::InstancedMaps& maps = ((MapInstanced*)map)->GetInstancedMaps();
363 for (MapInstanced::InstancedMaps::iterator mitr = maps.begin(); mitr != maps.end(); ++mitr)
364 {
365 if (mitr->second->IsDungeon()) dungeons += ((InstanceMap*)mitr->second)->GetPlayers().getSize();
366 else if (mitr->second->IsBattleground()) battlegrounds += ((InstanceMap*)mitr->second)->GetPlayers().getSize();
367 else if (mitr->second->IsBattleArena())
368 {
369 uint32 spect = 0;
370 if (BattlegroundMap* bgmap = mitr->second->ToBattlegroundMap())
371 if (Battleground* bg = bgmap->GetBG())
372 spect = bg->GetSpectators().size();
373
374 arenas += ((InstanceMap*)mitr->second)->GetPlayers().getSize() - spect;
375 spectators += spect;
376 }
377 }
378 }
379}
HashMapHolder< Player >::MapType const & GetPlayers()
Definition: ObjectAccessor.cpp:78
Definition: Battleground.h:298
BattlegroundMap * ToBattlegroundMap()
Definition: Map.h:549
Definition: Map.h:819
Definition: Map.h:853

References i_maps, Map::Instanceable(), and Map::ToBattlegroundMap().

◆ GetZoneAndAreaId()

void MapMgr::GetZoneAndAreaId ( uint32  phaseMask,
uint32 zoneid,
uint32 areaid,
uint32  mapid,
float  x,
float  y,
float  z 
)
inline
68 {
69 Map const* m = const_cast<MapMgr*>(this)->CreateBaseMap(mapid);
70 m->GetZoneAndAreaId(phaseMask, zoneid, areaid, x, y, z);
71 }
void GetZoneAndAreaId(uint32 phaseMask, uint32 &zoneid, uint32 &areaid, float x, float y, float z) const
Definition: Map.cpp:2193

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

◆ GetZoneId() [1/3]

uint32 MapMgr::GetZoneId ( uint32  phaseMask,
uint32  mapid,
float  x,
float  y,
float  z 
) const
inline
60 {
61 Map const* m = const_cast<MapMgr*>(this)->CreateBaseMap(mapid);
62 return m->GetZoneId(phaseMask, x, y, z);
63 }
uint32 GetZoneId(uint32 phaseMask, float x, float y, float z) const
Definition: Map.cpp:2183

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

◆ GetZoneId() [2/3]

uint32 MapMgr::GetZoneId ( uint32  phaseMask,
uint32  mapid,
Position const &  pos 
) const
inline
64{ return GetZoneId(phaseMask, mapid, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ()); }
uint32 GetZoneId(uint32 phaseMask, uint32 mapid, float x, float y, float z) const
Definition: MapMgr.h:59

References Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), and GetZoneId().

Referenced by GetZoneId().

◆ GetZoneId() [3/3]

uint32 MapMgr::GetZoneId ( uint32  phaseMask,
WorldLocation const &  loc 
) const
inline
65{ return GetZoneId(phaseMask, loc.GetMapId(), loc); }

References WorldLocation::GetMapId(), and GetZoneId().

Referenced by GetZoneId().

◆ Initialize()

void MapMgr::Initialize ( void  )
55{
56 int num_threads(sWorld->getIntConfig(CONFIG_NUMTHREADS));
57
58 // Start mtmaps if needed
59 if (num_threads > 0)
60 m_updater.activate(num_threads);
61}
@ CONFIG_NUMTHREADS
Definition: IWorld.h:343
void activate(std::size_t num_threads)
Definition: MapUpdater.cpp:74

References MapUpdater::activate(), CONFIG_NUMTHREADS, m_updater, and sWorld.

◆ InitializeVisibilityDistanceInfo()

void MapMgr::InitializeVisibilityDistanceInfo ( )
64{
65 for (MapMapType::iterator iter = i_maps.begin(); iter != i_maps.end(); ++iter)
66 (*iter).second->InitVisibilityDistance();
67}

References i_maps.

◆ InitInstanceIds()

void MapMgr::InitInstanceIds ( )
382{
383 _nextInstanceId = 1;
384
385 QueryResult result = CharacterDatabase.Query("SELECT MAX(id) FROM instance");
386 if (result)
387 {
388 uint32 maxId = (*result)[0].Get<uint32>();
389 _instanceIds.resize(maxId + 1);
390 }
391}
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:28
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21

References _instanceIds, _nextInstanceId, and CharacterDatabase.

◆ instance()

MapMgr * MapMgr::instance ( )
static
49{
50 static MapMgr instance;
51 return &instance;
52}
static MapMgr * instance()
Definition: MapMgr.cpp:48

References instance().

Referenced by instance(), and PlayerCannotEnter().

◆ IsValidMAP()

bool MapMgr::IsValidMAP ( uint32  mapid,
bool  startUp 
)
static
Todo:
: add check for battleground template
310{
311 MapEntry const* mEntry = sMapStore.LookupEntry(mapid);
312
313 if (startUp)
314 {
315 return mEntry != nullptr;
316 }
317 else
318 {
319 return mEntry && (!mEntry->IsDungeon() || sObjectMgr->GetInstanceTemplate(mapid));
320 }
321
323}
#define sObjectMgr
Definition: ObjectMgr.h:1623
bool IsDungeon() const
Definition: DBCStructure.h:1351

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

Referenced by IsValidMapCoord(), and ObjectMgr::LoadInstanceTemplate().

◆ IsValidMapCoord() [1/5]

static bool MapMgr::IsValidMapCoord ( uint32  mapid,
float  x,
float  y 
)
inlinestatic
97 {
98 return IsValidMAP(mapid, false) && Acore::IsValidMapCoord(x, y);
99 }
bool IsValidMapCoord(float c)
Definition: GridDefines.h:216
static bool IsValidMAP(uint32 mapid, bool startUp)
Definition: MapMgr.cpp:309

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

◆ IsValidMapCoord() [2/5]

static bool MapMgr::IsValidMapCoord ( uint32  mapid,
float  x,
float  y,
float  z 
)
inlinestatic
102 {
103 return IsValidMAP(mapid, false) && Acore::IsValidMapCoord(x, y, z);
104 }

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

◆ IsValidMapCoord() [3/5]

static bool MapMgr::IsValidMapCoord ( uint32  mapid,
float  x,
float  y,
float  z,
float  o 
)
inlinestatic
107 {
108 return IsValidMAP(mapid, false) && Acore::IsValidMapCoord(x, y, z, o);
109 }

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

◆ IsValidMapCoord() [4/5]

◆ IsValidMapCoord() [5/5]

static bool MapMgr::IsValidMapCoord ( WorldLocation const &  loc)
inlinestatic
112 {
113 return IsValidMapCoord(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), loc.GetOrientation());
114 }

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

◆ NormalizeOrientation()

static float MapMgr::NormalizeOrientation ( float  o)
inlinestatic
118 {
119 // fmod only supports positive numbers. Thus we have
120 // to emulate negative numbers
121 if (o < 0)
122 {
123 float mod = o * -1;
124 mod = std::fmod(mod, 2.0f * static_cast<float>(M_PI));
125 mod = -mod + 2.0f * static_cast<float>(M_PI);
126 return mod;
127 }
128 return std::fmod(o, 2.0f * static_cast<float>(M_PI));
129 }

◆ operator=()

MapMgr & MapMgr::operator= ( const MapMgr )
private

◆ PlayerCannotEnter()

Map::EnterState MapMgr::PlayerCannotEnter ( uint32  mapid,
Player player,
bool  loginCheck = false 
)
Todo:
: this is not a good place to send the message
131{
132 MapEntry const* entry = sMapStore.LookupEntry(mapid);
133 if (!entry)
135
136 if (!entry->IsDungeon())
137 return Map::CAN_ENTER;
138
139 InstanceTemplate const* instance = sObjectMgr->GetInstanceTemplate(mapid);
140 if (!instance)
142
143 Difficulty targetDifficulty, requestedDifficulty;
144 targetDifficulty = requestedDifficulty = player->GetDifficulty(entry->IsRaid());
145 // Get the highest available difficulty if current setting is higher than the instance allows
146 MapDifficulty const* mapDiff = GetDownscaledMapDifficultyData(entry->MapID, targetDifficulty);
147 if (!mapDiff)
148 {
149 player->SendTransferAborted(mapid, TRANSFER_ABORT_DIFFICULTY, requestedDifficulty);
151 }
152
153 //Bypass checks for GMs
154 if (player->IsGameMaster())
155 return Map::CAN_ENTER;
156
157 char const* mapName = entry->name[player->GetSession()->GetSessionDbcLocale()];
158
159 if (!sScriptMgr->CanEnterMap(player, entry, instance, mapDiff, loginCheck))
161
162 Group* group = player->GetGroup();
163 if (entry->IsRaid())
164 {
165 // can only enter in a raid group
166 if ((!group || !group->isRaidGroup()) && !sWorld->getBoolConfig(CONFIG_INSTANCE_IGNORE_RAID))
167 {
168 // probably there must be special opcode, because client has this string constant in GlobalStrings.lua
171 LOG_DEBUG("maps", "MAP: Player '{}' must be in a raid group to enter instance '{}'", player->GetName(), mapName);
173 }
174 }
175
176 // xinef: dont allow LFG Group to enter other instance that is selected
177 if (group)
178 if (group->isLFGGroup())
179 if (!sLFGMgr->inLfgDungeonMap(group->GetGUID(), mapid, targetDifficulty))
180 {
183 }
184
185 if (!player->IsAlive())
186 {
187 if (player->HasCorpse())
188 {
189 // let enter in ghost mode in instance that connected to inner instance with corpse
190 uint32 corpseMap = player->GetCorpseLocation().GetMapId();
191 do
192 {
193 if (corpseMap == mapid)
194 break;
195
196 InstanceTemplate const* corpseInstance = sObjectMgr->GetInstanceTemplate(corpseMap);
197 corpseMap = corpseInstance ? corpseInstance->Parent : 0;
198 } while (corpseMap);
199
200 if (!corpseMap)
201 {
203 player->GetSession()->SendPacket(&data);
204 LOG_DEBUG("maps", "MAP: Player '{}' does not have a corpse in instance '{}' and cannot enter.", player->GetName(), mapName);
206 }
207 LOG_DEBUG("maps", "MAP: Player '{}' has corpse in instance '{}' and can enter.", player->GetName(), mapName);
208 }
209 else
210 {
211 LOG_DEBUG("maps", "Map::PlayerCannotEnter - player '{}' is dead but does not have a corpse!", player->GetName());
212 }
213 }
214
215 // if map exists - check for being full, etc.
216 if (!loginCheck) // for login this is done by the calling function
217 {
218 uint32 destInstId = sInstanceSaveMgr->PlayerGetDestinationInstanceId(player, mapid, targetDifficulty);
219 if (destInstId)
220 if (Map* boundMap = sMapMgr->FindMap(mapid, destInstId))
221 if (Map::EnterState denyReason = boundMap->CannotEnter(player, loginCheck))
222 return denyReason;
223 }
224
225 // players are only allowed to enter 5 instances per hour
226 if (entry->IsNonRaidDungeon() && (!group || !group->isLFGGroup() || !group->IsLfgRandomInstance()))
227 {
228 uint32 instaceIdToCheck = 0;
229 if (InstanceSave* save = sInstanceSaveMgr->PlayerGetInstanceSave(player->GetGUID(), mapid, player->GetDifficulty(entry->IsRaid())))
230 instaceIdToCheck = save->GetInstanceId();
231
232 // instaceIdToCheck can be 0 if save not found - means no bind so the instance is new
233 if (!player->CheckInstanceCount(instaceIdToCheck))
234 {
237 }
238 }
239
240 //Other requirements
241 return player->Satisfy(sObjectMgr->GetAccessRequirement(mapid, targetDifficulty), mapid, true) ? Map::CAN_ENTER : Map::CANNOT_ENTER_UNSPECIFIED_REASON;
242}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:168
#define sScriptMgr
Definition: ScriptMgr.h:708
#define sInstanceSaveMgr
Definition: InstanceSaveMgr.h:202
#define sMapMgr
Definition: MapMgr.h:221
#define sLFGMgr
Definition: LFGMgr.h:641
MapDifficulty const * GetDownscaledMapDifficultyData(uint32 mapId, Difficulty &difficulty)
Definition: DBCStores.cpp:767
@ CONFIG_INSTANCE_IGNORE_RAID
Definition: IWorld.h:90
@ LANG_INSTANCE_RAID_GROUP_ONLY
Definition: Language.h:1053
@ TRANSFER_ABORT_TOO_MANY_INSTANCES
Definition: Player.h:787
@ TRANSFER_ABORT_DIFFICULTY
Definition: Player.h:790
@ TRANSFER_ABORT_MAP_NOT_ALLOWED
Definition: Player.h:798
Difficulty
Definition: DBCEnums.h:266
@ SMSG_CORPSE_NOT_IN_INSTANCE
Definition: Opcodes.h:1316
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:109
std::string const & GetName() const
Definition: Object.h:458
uint32 GetMapId() const
Definition: Position.h:276
Difficulty GetDifficulty(bool isRaid) const
Definition: Player.h:1900
bool HasCorpse() const
Definition: Player.h:2018
bool CheckInstanceCount(uint32 instanceId) const
Definition: PlayerStorage.cpp:6986
WorldSession * GetSession() const
Definition: Player.h:1978
WorldLocation GetCorpseLocation() const
Definition: Player.h:2019
Group * GetGroup()
Definition: Player.h:2448
bool IsGameMaster() const
Definition: Player.h:1158
bool Satisfy(DungeonProgressionRequirements const *ar, uint32 target_map, bool report=false)
Definition: PlayerStorage.cpp:6711
void SendTransferAborted(uint32 mapid, TransferAbortReason reason, uint8 arg=0)
Definition: Player.cpp:11713
bool IsAlive() const
Definition: Unit.h:1204
Definition: Group.h:169
bool isLFGGroup(bool restricted=false) const
Definition: Group.cpp:2265
bool IsLfgRandomInstance() const
Definition: Group.h:314
ObjectGuid GetGUID() const
Definition: Group.cpp:2306
bool isRaidGroup() const
Definition: Group.cpp:2271
Definition: InstanceSaveMgr.h:56
Definition: Map.h:274
uint32 Parent
Definition: Map.h:275
EnterState
Definition: Map.h:423
@ CANNOT_ENTER_CORPSE_IN_DIFFERENT_INSTANCE
Definition: Map.h:430
@ CANNOT_ENTER_TOO_MANY_INSTANCES
Definition: Map.h:432
@ CAN_ENTER
Definition: Map.h:424
@ CANNOT_ENTER_UNSPECIFIED_REASON
Definition: Map.h:435
@ CANNOT_ENTER_NO_ENTRY
Definition: Map.h:426
@ CANNOT_ENTER_DIFFICULTY_UNAVAILABLE
Definition: Map.h:428
@ CANNOT_ENTER_UNINSTANCED_DUNGEON
Definition: Map.h:427
@ CANNOT_ENTER_NOT_IN_RAID
Definition: Map.h:429
Definition: WorldPacket.h:27
void SendAreaTriggerMessage(const char *Text,...) ATTR_PRINTF(2
Definition: MiscHandler.cpp:691
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition: WorldSession.cpp:214
LocaleConstant GetSessionDbcLocale() const
Definition: WorldSession.h:497
char const * GetAcoreString(uint32 entry) const
Definition: WorldSession.cpp:790
bool IsNonRaidDungeon() const
Definition: DBCStructure.h:1352
uint32 MapID
Definition: DBCStructure.h:1326
char const * name[16]
Definition: DBCStructure.h:1331
bool IsRaid() const
Definition: DBCStructure.h:1354
Definition: DBCStructure.h:2222

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_TOO_MANY_INSTANCES, Map::CANNOT_ENTER_UNINSTANCED_DUNGEON, Map::CANNOT_ENTER_UNSPECIFIED_REASON, Player::CheckInstanceCount(), CONFIG_INSTANCE_IGNORE_RAID, WorldSession::GetAcoreString(), Player::GetCorpseLocation(), Player::GetDifficulty(), GetDownscaledMapDifficultyData(), Player::GetGroup(), Group::GetGUID(), Object::GetGUID(), WorldLocation::GetMapId(), WorldObject::GetName(), Player::GetSession(), WorldSession::GetSessionDbcLocale(), Player::HasCorpse(), instance(), Unit::IsAlive(), MapEntry::IsDungeon(), Player::IsGameMaster(), Group::isLFGGroup(), Group::IsLfgRandomInstance(), MapEntry::IsNonRaidDungeon(), MapEntry::IsRaid(), Group::isRaidGroup(), LANG_INSTANCE_RAID_GROUP_ONLY, LOG_DEBUG, MapEntry::MapID, MapEntry::name, InstanceTemplate::Parent, Player::Satisfy(), WorldSession::SendAreaTriggerMessage(), WorldSession::SendPacket(), Player::SendTransferAborted(), sInstanceSaveMgr, sLFGMgr, sMapMgr, sMapStore, SMSG_CORPSE_NOT_IN_INSTANCE, sObjectMgr, sScriptMgr, sWorld, TRANSFER_ABORT_DIFFICULTY, TRANSFER_ABORT_MAP_NOT_ALLOWED, and TRANSFER_ABORT_TOO_MANY_INSTANCES.

◆ RegisterInstanceId()

void MapMgr::RegisterInstanceId ( uint32  instanceId)
394{
395 // Allocation was done in InitInstanceIds()
396 _instanceIds[instanceId] = true;
397
398 // Instances are pulled in ascending order from db and _nextInstanceId is initialized with 1,
399 // so if the instance id is used, increment
400 if (_nextInstanceId == instanceId)
402}

References _instanceIds, and _nextInstanceId.

◆ SetMapUpdateInterval()

void MapMgr::SetMapUpdateInterval ( uint32  t)
inline
77 {
80
81 i_timer[3].SetInterval(t);
82 i_timer[3].Reset();
83 }
#define MIN_MAP_UPDATE_DELAY
Definition: GridDefines.h:42
void Reset()
Definition: Timer.h:166

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

◆ UnloadAll()

void MapMgr::UnloadAll ( )
326{
327 for (MapMapType::iterator iter = i_maps.begin(); iter != i_maps.end();)
328 {
329 iter->second->UnloadAll();
330 delete iter->second;
331 i_maps.erase(iter++);
332 }
333
334 if (m_updater.activated())
336}
bool activated()
Definition: MapUpdater.cpp:128
void deactivate()
Definition: MapUpdater.cpp:83

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

◆ Update()

void MapMgr::Update ( uint32  diff)
245{
246 for (uint8 i = 0; i < 4; ++i)
247 i_timer[i].Update(diff);
248
249 // pussywizard: lfg compatibles update, schedule before maps so it is processed from the very beginning
250 //if (mapUpdateStep == 0)
251 {
252 if (m_updater.activated())
253 {
255 }
256 else
257 {
258 sLFGMgr->Update(diff, 1);
259 }
260 }
261
262 MapMapType::iterator iter = i_maps.begin();
263 for (; iter != i_maps.end(); ++iter)
264 {
265 bool full = mapUpdateStep < 3 && ((mapUpdateStep == 0 && !iter->second->IsBattlegroundOrArena() && !iter->second->IsDungeon()) || (mapUpdateStep == 1 && iter->second->IsBattlegroundOrArena()) || (mapUpdateStep == 2 && iter->second->IsDungeon()));
266 if (m_updater.activated())
267 m_updater.schedule_update(*iter->second, uint32(full ? i_timer[mapUpdateStep].GetCurrent() : 0), diff);
268 else
269 iter->second->Update(uint32(full ? i_timer[mapUpdateStep].GetCurrent() : 0), diff);
270 }
271
272 if (m_updater.activated())
273 m_updater.wait();
274
275 if (mapUpdateStep < 3)
276 {
277 for (iter = i_maps.begin(); iter != i_maps.end(); ++iter)
278 {
279 bool full = ((mapUpdateStep == 0 && !iter->second->IsBattlegroundOrArena() && !iter->second->IsDungeon()) || (mapUpdateStep == 1 && iter->second->IsBattlegroundOrArena()) || (mapUpdateStep == 2 && iter->second->IsDungeon()));
280 if (full)
281 iter->second->DelayedUpdate(uint32(i_timer[mapUpdateStep].GetCurrent()));
282 }
283
286 }
287
288 if (mapUpdateStep == 3 && i_timer[3].Passed())
289 {
290 mapUpdateStep = 0;
291 i_timer[3].SetCurrent(0);
292 }
293}
std::uint8_t uint8
Definition: Define.h:109
void SetCurrent(time_t current)
Definition: Timer.h:174
void Update(uint32)
Definition: MapMgr.cpp:244
void schedule_lfg_update(uint32 diff)
Definition: MapUpdater.cpp:119
void wait()
Definition: MapUpdater.cpp:100
void schedule_update(Map &map, uint32 diff, uint32 s_diff)
Definition: MapUpdater.cpp:110

References MapUpdater::activated(), i_maps, i_timer, m_updater, mapUpdateStep, MapUpdater::schedule_lfg_update(), MapUpdater::schedule_update(), IntervalTimer::SetCurrent(), sLFGMgr, Update(), and MapUpdater::wait().

Referenced by Update().

Member Data Documentation

◆ _instanceIds

InstanceIds MapMgr::_instanceIds
private

◆ _nextInstanceId

uint32 MapMgr::_nextInstanceId
private

◆ i_maps

◆ i_timer

IntervalTimer MapMgr::i_timer[4]
private

◆ Lock

std::mutex MapMgr::Lock
private

◆ m_updater

MapUpdater MapMgr::m_updater
private

◆ mapUpdateStep

uint8 MapMgr::mapUpdateStep
private

Referenced by MapMgr(), and Update().