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:211
#define sWorld
Definition: World.h:443
void SetInterval(time_t interval)
Definition: Timer.h:179
IntervalTimer i_timer[4]
Definition: MapMgr.h:172
uint8 mapUpdateStep
Definition: MapMgr.h:173
uint32 _nextInstanceId
Definition: MapMgr.h:176

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
@ REGULAR_DIFFICULTY
Definition: DBCEnums.h:267
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
Definition: Map.h:311
void LoadRespawnTimes()
Definition: Map.cpp:3420
void LoadCorpseData()
Definition: Map.cpp:4017
Definition: MapInstanced.h:26
Map * FindBaseMap(uint32 mapId) const
Definition: MapMgr.h:43
std::mutex Lock
Definition: MapMgr.h:170
MapMapType i_maps
Definition: MapMgr.h:171
Definition: DBCStructure.h:1324
bool Instanceable() const
Definition: DBCStructure.h:1352

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:445
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)
182{
183 std::lock_guard<std::mutex> guard(Lock);
184
185 for (auto& mapPair : i_maps)
186 {
187 Map* map = mapPair.second;
188 if (MapInstanced* mapInstanced = map->ToMapInstanced())
189 {
190 MapInstanced::InstancedMaps& instances = mapInstanced->GetInstancedMaps();
191 for (auto& instancePair : instances)
192 worker(instancePair.second);
193 }
194 else
195 worker(map);
196 }
197}
MapInstanced * ToMapInstanced()
Definition: Map.h:541
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
201{
202 std::lock_guard<std::mutex> guard(Lock);
203
204 auto itr = i_maps.find(mapId);
205 if (itr != i_maps.end())
206 {
207 Map* map = itr->second;
208 if (MapInstanced* mapInstanced = map->ToMapInstanced())
209 {
210 MapInstanced::InstancedMaps& instances = mapInstanced->GetInstancedMaps();
211 for (auto& p : instances)
212 worker(p.second);
213 }
214 else
215 worker(map);
216 }
217}

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:185
Definition: GridDefines.h:85
uint32 x_coord
Definition: GridDefines.h:152
uint32 y_coord
Definition: GridDefines.h:153
static bool ExistVMap(uint32 mapid, int gx, int gy)
Definition: Map.cpp:119
static bool ExistMap(uint32 mapid, int gx, int gy)
Definition: Map.cpp:88

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
44 {
45 MapMapType::const_iterator iter = i_maps.find(mapId);
46 return (iter == i_maps.end() ? nullptr : iter->second);
47 }

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:157
std::uint32_t uint32
Definition: Define.h:107
@ ERROR_EXIT_CODE
Definition: World.h:54
InstanceIds _instanceIds
Definition: MapMgr.h:175
static void StopNow(uint8 exitcode)
Definition: World.h:253

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
50 {
51 Map const* m = const_cast<MapMgr*>(this)->CreateBaseMap(mapid);
52 return m->GetAreaId(phaseMask, x, y, z);
53 }
uint32 GetAreaId(uint32 phaseMask, float x, float y, float z) const
Definition: Map.cpp:2150
Definition: MapMgr.h:34

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

◆ GetAreaId() [2/3]

uint32 MapMgr::GetAreaId ( uint32  phaseMask,
uint32  mapid,
Position const &  pos 
) const
inline
54{ 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:49

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
55{ return GetAreaId(phaseMask, loc.GetMapId(), loc); }

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

Referenced by GetAreaId().

◆ GetInstanceIDs()

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

References _instanceIds.

◆ GetMapUpdater()

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

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:75
Definition: Battleground.h:303
BattlegroundMap * ToBattlegroundMap()
Definition: Map.h:547
Definition: Map.h:817
Definition: Map.h:851

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
66 {
67 Map const* m = const_cast<MapMgr*>(this)->CreateBaseMap(mapid);
68 m->GetZoneAndAreaId(phaseMask, zoneid, areaid, x, y, z);
69 }
void GetZoneAndAreaId(uint32 phaseMask, uint32 &zoneid, uint32 &areaid, float x, float y, float z) const
Definition: Map.cpp:2196

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

◆ GetZoneId() [1/3]

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

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

◆ GetZoneId() [2/3]

uint32 MapMgr::GetZoneId ( uint32  phaseMask,
uint32  mapid,
Position const &  pos 
) const
inline
62{ 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:57

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
63{ 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:340
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:27
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:1635
bool IsDungeon() const
Definition: DBCStructure.h:1350

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
95 {
96 return IsValidMAP(mapid, false) && Acore::IsValidMapCoord(x, y);
97 }
bool IsValidMapCoord(float c)
Definition: GridDefines.h:215
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
100 {
101 return IsValidMAP(mapid, false) && Acore::IsValidMapCoord(x, y, z);
102 }

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

◆ IsValidMapCoord() [3/5]

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

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

◆ IsValidMapCoord() [4/5]

◆ IsValidMapCoord() [5/5]

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

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

◆ NormalizeOrientation()

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

◆ 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:169
Difficulty
Definition: DBCEnums.h:266
#define sMapMgr
Definition: MapMgr.h:219
#define sInstanceSaveMgr
Definition: InstanceSaveMgr.h:202
@ LANG_INSTANCE_RAID_GROUP_ONLY
Definition: Language.h:1053
#define sLFGMgr
Definition: LFGMgr.h:641
@ CONFIG_INSTANCE_IGNORE_RAID
Definition: IWorld.h:85
@ TRANSFER_ABORT_TOO_MANY_INSTANCES
Definition: Player.h:792
@ TRANSFER_ABORT_DIFFICULTY
Definition: Player.h:795
@ TRANSFER_ABORT_MAP_NOT_ALLOWED
Definition: Player.h:803
MapDifficulty const * GetDownscaledMapDifficultyData(uint32 mapId, Difficulty &difficulty)
Definition: DBCStores.cpp:767
#define sScriptMgr
Definition: ScriptMgr.h:709
@ SMSG_CORPSE_NOT_IN_INSTANCE
Definition: Opcodes.h:1316
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:112
std::string const & GetName() const
Definition: Object.h:463
uint32 GetMapId() const
Definition: Position.h:275
Difficulty GetDifficulty(bool isRaid) const
Definition: Player.h:1920
bool HasCorpse() const
Definition: Player.h:2038
bool CheckInstanceCount(uint32 instanceId) const
Definition: PlayerStorage.cpp:6981
WorldSession * GetSession() const
Definition: Player.h:1998
WorldLocation GetCorpseLocation() const
Definition: Player.h:2039
Group * GetGroup()
Definition: Player.h:2468
bool IsGameMaster() const
Definition: Player.h:1175
bool Satisfy(DungeonProgressionRequirements const *ar, uint32 target_map, bool report=false)
Definition: PlayerStorage.cpp:6706
void SendTransferAborted(uint32 mapid, TransferAbortReason reason, uint8 arg=0)
Definition: Player.cpp:11749
bool IsAlive() const
Definition: Unit.h:1654
Definition: Group.h:169
bool isLFGGroup(bool restricted=false) const
Definition: Group.cpp:2261
bool IsLfgRandomInstance() const
Definition: Group.h:314
ObjectGuid GetGUID() const
Definition: Group.cpp:2302
bool isRaidGroup() const
Definition: Group.cpp:2267
Definition: InstanceSaveMgr.h:56
Definition: Map.h:272
uint32 Parent
Definition: Map.h:273
EnterState
Definition: Map.h:421
@ CANNOT_ENTER_CORPSE_IN_DIFFERENT_INSTANCE
Definition: Map.h:428
@ CANNOT_ENTER_TOO_MANY_INSTANCES
Definition: Map.h:430
@ CAN_ENTER
Definition: Map.h:422
@ CANNOT_ENTER_UNSPECIFIED_REASON
Definition: Map.h:433
@ CANNOT_ENTER_NO_ENTRY
Definition: Map.h:424
@ CANNOT_ENTER_DIFFICULTY_UNAVAILABLE
Definition: Map.h:426
@ CANNOT_ENTER_UNINSTANCED_DUNGEON
Definition: Map.h:425
@ CANNOT_ENTER_NOT_IN_RAID
Definition: Map.h:427
Definition: WorldPacket.h:26
void SendAreaTriggerMessage(const char *Text,...) ATTR_PRINTF(2
Definition: MiscHandler.cpp:692
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:794
bool IsNonRaidDungeon() const
Definition: DBCStructure.h:1351
uint32 MapID
Definition: DBCStructure.h:1325
char const * name[16]
Definition: DBCStructure.h:1330
bool IsRaid() const
Definition: DBCStructure.h:1353
Definition: DBCStructure.h:2221

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
75 {
78
79 i_timer[3].SetInterval(t);
80 i_timer[3].Reset();
81 }
#define MIN_MAP_UPDATE_DELAY
Definition: GridDefines.h:41
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().