TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MapInstanced Class Reference

#include <MapInstanced.h>

Public Types

typedef std::unordered_map
< uint32, Map * > 
InstancedMaps
 
- Public Types inherited from Map
enum  EnterState {
  CAN_ENTER = 0, CANNOT_ENTER_ALREADY_IN_MAP = 1, CANNOT_ENTER_NO_ENTRY, CANNOT_ENTER_UNINSTANCED_DUNGEON,
  CANNOT_ENTER_DIFFICULTY_UNAVAILABLE, CANNOT_ENTER_NOT_IN_RAID, CANNOT_ENTER_CORPSE_IN_DIFFERENT_INSTANCE, CANNOT_ENTER_INSTANCE_BIND_MISMATCH,
  CANNOT_ENTER_TOO_MANY_INSTANCES, CANNOT_ENTER_MAX_PLAYERS, CANNOT_ENTER_ZONE_IN_COMBAT, CANNOT_ENTER_UNSPECIFIED_REASON
}
 
typedef MapRefManager PlayerList
 
typedef
std::unordered_multimap
< ObjectGuid::LowType,
Creature * > 
CreatureBySpawnIdContainer
 
typedef
std::unordered_multimap
< ObjectGuid::LowType,
GameObject * > 
GameObjectBySpawnIdContainer
 
- Public Types inherited from GridRefManager< NGridType >
typedef
LinkedListHead::Iterator
< GridReference< NGridType > > 
iterator
 
- Public Types inherited from RefManager< GridRefManager< NGridType >, NGridType >
typedef
LinkedListHead::Iterator
< Reference< GridRefManager
< NGridType >, NGridType > > 
iterator
 
- Public Types inherited from LinkedListHead
typedef Iterator
< LinkedListElement
iterator
 

Public Member Functions

 MapInstanced (uint32 id, time_t expiry)
 
 ~MapInstanced ()
 
void Update (const uint32) override
 
void DelayedUpdate (const uint32 diff) override
 
void UnloadAll () override
 
EnterState CannotEnter (Player *) override
 
MapCreateInstanceForPlayer (const uint32 mapId, Player *player, uint32 loginInstanceId=0)
 
MapFindInstanceMap (uint32 instanceId) const
 
bool DestroyInstance (InstancedMaps::iterator &itr)
 
void AddGridMapReference (const GridCoord &p)
 
void RemoveGridMapReference (GridCoord const &p)
 
InstancedMapsGetInstancedMaps ()
 
virtual void InitVisibilityDistance () override
 
- Public Member Functions inherited from Map
 Map (uint32 id, time_t, uint32 InstanceId, uint8 SpawnMode, Map *_parent=NULL)
 
virtual ~Map ()
 
MapEntry constGetEntry () const
 
bool CanUnload (uint32 diff)
 
virtual bool AddPlayerToMap (Player *player, bool initPlayer=true)
 
virtual void RemovePlayerFromMap (Player *, bool)
 
template<class T >
bool AddToMap (T *)
 
template<class T >
void RemoveFromMap (T *, bool)
 
void VisitNearbyCellsOf (WorldObject *obj, TypeContainerVisitor< Trinity::ObjectUpdater, GridTypeMapContainer > &gridVisitor, TypeContainerVisitor< Trinity::ObjectUpdater, WorldTypeMapContainer > &worldVisitor)
 
float GetVisibilityRange () const
 
void PlayerRelocation (Player *, float x, float y, float z, float orientation)
 
void CreatureRelocation (Creature *creature, float x, float y, float z, float ang, bool respawnRelocationOnFail=true)
 
void GameObjectRelocation (GameObject *go, float x, float y, float z, float orientation, bool respawnRelocationOnFail=true)
 
void DynamicObjectRelocation (DynamicObject *go, float x, float y, float z, float orientation)
 
template<class T , class CONTAINER >
void Visit (const Cell &cell, TypeContainerVisitor< T, CONTAINER > &visitor)
 
bool IsRemovalGrid (float x, float y) const
 
bool IsGridLoaded (float x, float y) const
 
bool GetUnloadLock (const GridCoord &p) const
 
void SetUnloadLock (const GridCoord &p, bool on)
 
void LoadGrid (float x, float y)
 
bool UnloadGrid (NGridType &ngrid, bool pForce)
 
void ResetGridExpiry (NGridType &grid, float factor=1) const
 
time_t GetGridExpiry (void) const
 
uint32 GetId (void) const
 
Map constGetParent () const
 
float GetHeight (float x, float y, float z, bool checkVMap=true, float maxSearchDist=DEFAULT_HEIGHT_SEARCH) const
 
float GetMinHeight (float x, float y) const
 
ZLiquidStatus getLiquidStatus (float x, float y, float z, uint8 ReqLiquidType, LiquidData *data=nullptr) const
 
uint32 GetAreaId (float x, float y, float z, bool *isOutdoors) const
 
bool GetAreaInfo (float x, float y, float z, uint32 &mogpflags, int32 &adtId, int32 &rootId, int32 &groupId) const
 
uint32 GetAreaId (float x, float y, float z) const
 
uint32 GetZoneId (float x, float y, float z) const
 
void GetZoneAndAreaId (uint32 &zoneid, uint32 &areaid, float x, float y, float z) const
 
bool IsOutdoors (float x, float y, float z) const
 
uint8 GetTerrainType (float x, float y) const
 
float GetWaterLevel (float x, float y) const
 
bool IsInWater (float x, float y, float z, LiquidData *data=nullptr) const
 
bool IsUnderWater (float x, float y, float z) const
 
void MoveAllCreaturesInMoveList ()
 
void MoveAllGameObjectsInMoveList ()
 
void MoveAllDynamicObjectsInMoveList ()
 
void RemoveAllObjectsInRemoveList ()
 
virtual void RemoveAllPlayers ()
 
bool CreatureRespawnRelocation (Creature *c, bool diffGridOnly)
 
bool GameObjectRespawnRelocation (GameObject *go, bool diffGridOnly)
 
bool CheckGridIntegrity (Creature *c, bool moved) const
 
uint32 GetInstanceId () const
 
uint8 GetSpawnMode () const
 
const char * GetMapName () const
 
Difficulty GetDifficultyID () const
 
MapDifficultyEntry constGetMapDifficulty () const
 
uint32 GetDifficultyLootBonusTreeMod () const
 
bool Instanceable () const
 
bool IsDungeon () const
 
bool IsNonRaidDungeon () const
 
bool IsRaid () const
 
bool IsRaidOrHeroicDungeon () const
 
bool IsHeroic () const
 
bool Is25ManRaid () const
 
bool IsBattleground () const
 
bool IsBattleArena () const
 
bool IsBattlegroundOrArena () const
 
bool IsGarrison () const
 
bool GetEntrancePos (int32 &mapid, float &x, float &y)
 
void AddObjectToRemoveList (WorldObject *obj)
 
void AddObjectToSwitchList (WorldObject *obj, bool on)
 
void UpdateObjectVisibility (WorldObject *obj, Cell cell, CellCoord cellpair)
 
void UpdateObjectsVisibilityFor (Player *player, Cell cell, CellCoord cellpair)
 
void resetMarkedCells ()
 
bool isCellMarked (uint32 pCellId)
 
void markCell (uint32 pCellId)
 
bool HavePlayers () const
 
uint32 GetPlayersCountExceptGMs () const
 
bool ActiveObjectsNearGrid (NGridType const &ngrid) const
 
void AddWorldObject (WorldObject *obj)
 
void RemoveWorldObject (WorldObject *obj)
 
void SendToPlayers (WorldPacket const *data) const
 
PlayerList constGetPlayers () const
 
void ScriptsStart (std::map< uint32, std::multimap< uint32, ScriptInfo > > const &scripts, uint32 id, Object *source, Object *target)
 Put scripts in the execution queue. More...
 
void ScriptCommandStart (ScriptInfo const &script, uint32 delay, Object *source, Object *target)
 
template<class T >
void AddToActive (T *obj)
 
template<class T >
void RemoveFromActive (T *obj)
 
template<class T >
void SwitchGridContainers (T *obj, bool on)
 
template<class NOTIFIER >
void VisitAll (const float &x, const float &y, float radius, NOTIFIER &notifier)
 
template<class NOTIFIER >
void VisitFirstFound (const float &x, const float &y, float radius, NOTIFIER &notifier)
 
template<class NOTIFIER >
void VisitWorld (const float &x, const float &y, float radius, NOTIFIER &notifier)
 
template<class NOTIFIER >
void VisitGrid (const float &x, const float &y, float radius, NOTIFIER &notifier)
 
void UpdateIteratorBack (Player *player)
 
TempSummonSummonCreature (uint32 entry, Position const &pos, SummonPropertiesEntry const *properties=NULL, uint32 duration=0, Unit *summoner=NULL, uint32 spellId=0, uint32 vehId=0)
 
void SummonCreatureGroup (uint8 group, std::list< TempSummon * > *list=NULL)
 
AreaTriggerGetAreaTrigger (ObjectGuid const &guid)
 
CorpseGetCorpse (ObjectGuid const &guid)
 
CreatureGetCreature (ObjectGuid const &guid)
 
DynamicObjectGetDynamicObject (ObjectGuid const &guid)
 
GameObjectGetGameObject (ObjectGuid const &guid)
 
PetGetPet (ObjectGuid const &guid)
 
TransportGetTransport (ObjectGuid const &guid)
 
MapStoredObjectTypesContainerGetObjectsStore ()
 
CreatureBySpawnIdContainerGetCreatureBySpawnIdStore ()
 
GameObjectBySpawnIdContainerGetGameObjectBySpawnIdStore ()
 
std::unordered_set< Corpse * >
const
GetCorpsesInCell (uint32 cellId) const
 
CorpseGetCorpseByPlayer (ObjectGuid const &ownerGuid) const
 
MapInstancedToMapInstanced ()
 
MapInstanced constToMapInstanced () const
 
InstanceMapToInstanceMap ()
 
InstanceMap constToInstanceMap () const
 
BattlegroundMapToBattlegroundMap ()
 
BattlegroundMap constToBattlegroundMap () const
 
float GetWaterOrGroundLevel (float x, float y, float z, float *ground=NULL, bool swim=false) const
 
float GetHeight (uint32 phasemask, float x, float y, float z, bool vmap=true, float maxSearchDist=DEFAULT_HEIGHT_SEARCH) const
 
bool isInLineOfSight (float x1, float y1, float z1, float x2, float y2, float z2, uint32 phasemask) const
 
void Balance ()
 
void RemoveGameObjectModel (const GameObjectModel &model)
 
void InsertGameObjectModel (const GameObjectModel &model)
 
bool ContainsGameObjectModel (const GameObjectModel &model) const
 
bool getObjectHitPos (uint32 phasemask, float x1, float y1, float z1, float x2, float y2, float z2, float &rx, float &ry, float &rz, float modifyDist)
 
virtual ObjectGuid::LowType GetOwnerGuildId (uint32=TEAM_OTHER) const
 
time_t GetLinkedRespawnTime (ObjectGuid guid) const
 
time_t GetCreatureRespawnTime (ObjectGuid::LowType dbGuid) const
 
time_t GetGORespawnTime (ObjectGuid::LowType dbGuid) const
 
void SaveCreatureRespawnTime (ObjectGuid::LowType dbGuid, time_t respawnTime)
 
void RemoveCreatureRespawnTime (ObjectGuid::LowType dbGuid)
 
void SaveGORespawnTime (ObjectGuid::LowType dbGuid, time_t respawnTime)
 
void RemoveGORespawnTime (ObjectGuid::LowType dbGuid)
 
void LoadRespawnTimes ()
 
void DeleteRespawnTimes ()
 
void LoadCorpseData ()
 
void DeleteCorpseData ()
 
void AddCorpse (Corpse *corpse)
 
void RemoveCorpse (Corpse *corpse)
 
CorpseConvertCorpseToBones (ObjectGuid const &ownerGuid, bool insignia=false)
 
void RemoveOldCorpses ()
 
void SendInitTransports (Player *player)
 
void SendRemoveTransports (Player *player)
 
void SendUpdateTransportVisibility (Player *player, std::set< uint32 > const &previousPhases)
 
void SendZoneDynamicInfo (Player *player)
 
void SetZoneMusic (uint32 zoneId, uint32 musicId)
 
void SetZoneWeather (uint32 zoneId, WeatherState weatherId, float weatherGrade)
 
void SetZoneOverrideLight (uint32 zoneId, uint32 lightId, uint32 fadeInTime)
 
void UpdateAreaDependentAuras ()
 
template<HighGuid high>
ObjectGuid::LowType GenerateLowGuid ()
 
void AddUpdateObject (Object *obj)
 
void RemoveUpdateObject (Object *obj)
 
template<>
void AddToGrid (Creature *obj, Cell const &cell)
 
template<>
void AddToGrid (GameObject *obj, Cell const &cell)
 
template<>
void AddToGrid (DynamicObject *obj, Cell const &cell)
 
template<>
void AddToGrid (Corpse *obj, Cell const &cell)
 
template<>
void SwitchGridContainers (Creature *obj, bool on)
 
template<>
void SwitchGridContainers (GameObject *obj, bool on)
 
template<>
void DeleteFromWorld (Player *player)
 
template<>
void DeleteFromWorld (Transport *transport)
 
template<>
void InitializeObject (Creature *obj)
 
template<>
void InitializeObject (GameObject *obj)
 
template<>
bool AddToMap (Transport *obj)
 
template<>
void RemoveFromMap (Transport *obj, bool remove)
 
template<>
void AddToActive (Creature *c)
 
template<>
void AddToActive (DynamicObject *d)
 
template<>
void RemoveFromActive (Creature *c)
 
template<>
void RemoveFromActive (DynamicObject *obj)
 
- Public Member Functions inherited from GridRefManager< NGridType >
GridReference< NGridType > * getFirst ()
 
GridReference< NGridType > * getLast ()
 
iterator begin ()
 
iterator end ()
 
iterator rbegin ()
 
iterator rend ()
 
- Public Member Functions inherited from RefManager< GridRefManager< NGridType >, NGridType >
 RefManager ()
 
virtual ~RefManager ()
 
Reference< GridRefManager
< NGridType >, NGridType > * 
getFirst ()
 
Reference< GridRefManager
< NGridType >, NGridType >
const
getFirst () const
 
Reference< GridRefManager
< NGridType >, NGridType > * 
getLast ()
 
Reference< GridRefManager
< NGridType >, NGridType >
const
getLast () const
 
iterator begin ()
 
iterator end ()
 
iterator rbegin ()
 
iterator rend ()
 
void clearReferences ()
 
- Public Member Functions inherited from LinkedListHead
 LinkedListHead ()
 
virtual ~LinkedListHead ()
 
bool isEmpty () const
 
LinkedListElementgetFirst ()
 
LinkedListElement constgetFirst () const
 
LinkedListElementgetLast ()
 
LinkedListElement constgetLast () const
 
void insertFirst (LinkedListElement *pElem)
 
void insertLast (LinkedListElement *pElem)
 
uint32 getSize () const
 
void incSize ()
 
void decSize ()
 

Private Member Functions

InstanceMapCreateInstance (uint32 InstanceId, InstanceSave *save, Difficulty difficulty)
 
BattlegroundMapCreateBattleground (uint32 InstanceId, Battleground *bg)
 
GarrisonMapCreateGarrison (uint32 instanceId, Player *owner)
 

Private Attributes

InstancedMaps m_InstancedMaps
 
uint16 GridMapReference [MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]
 

Friends

class MapManager
 

Additional Inherited Members

- Static Public Member Functions inherited from Map
static bool ExistMap (uint32 mapid, int gx, int gy)
 
static bool ExistVMap (uint32 mapid, int gx, int gy)
 
static void InitStateMachine ()
 
static void DeleteStateMachine ()
 
static void DeleteRespawnTimesInDB (uint16 mapId, uint32 instanceId)
 
- Public Attributes inherited from Map
CreatureGroupHolderType CreatureGroupHolder
 
- Protected Types inherited from Map
typedef std::set< WorldObject * > ActiveNonPlayers
 
typedef std::set< Transport * > TransportsContainer
 
- Protected Member Functions inherited from Map
void SetUnloadReferenceLock (const GridCoord &p, bool on)
 
virtual void LoadGridObjects (NGridType *grid, Cell const &cell)
 
- Protected Attributes inherited from Map
std::mutex _mapLock
 
std::mutex _gridLock
 
MapEntry consti_mapEntry
 
uint8 i_spawnMode
 
uint32 i_InstanceId
 
uint32 m_unloadTimer
 
float m_VisibleDistance
 
DynamicMapTree _dynamicTree
 
MapRefManager m_mapRefManager
 
MapRefManager::iterator m_mapRefIter
 
int32 m_VisibilityNotifyPeriod
 
ActiveNonPlayers m_activeNonPlayers
 
ActiveNonPlayers::iterator m_activeNonPlayersIter
 
TransportsContainer _transports
 
TransportsContainer::iterator _transportsUpdateIter
 

Member Typedef Documentation

typedef std::unordered_map< uint32, Map*> MapInstanced::InstancedMaps

Constructor & Destructor Documentation

MapInstanced::MapInstanced ( uint32  id,
time_t  expiry 
)
31  : Map(id, expiry, 0, DIFFICULTY_NORMAL)
32 {
33  // fill with zero
35 }
uint16 GridMapReference[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]
Definition: MapInstanced.h:75
#define MAX_NUMBER_OF_GRIDS
Definition: GridDefines.h:37
Map(uint32 id, time_t, uint32 InstanceId, uint8 SpawnMode, Map *_parent=NULL)
Definition: Map.cpp:227
uint16_t uint16
Definition: Define.h:151
Definition: DBCEnums.h:405
MapInstanced::~MapInstanced ( )
inline
35 { }

Member Function Documentation

void MapInstanced::AddGridMapReference ( const GridCoord p)
inline
53  {
56  }
uint16 GridMapReference[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]
Definition: MapInstanced.h:75
#define MAX_NUMBER_OF_GRIDS
Definition: GridDefines.h:37
void SetUnloadReferenceLock(const GridCoord &p, bool on)
Definition: Map.h:634
uint32 y_coord
Definition: GridDefines.h:156
uint32 x_coord
Definition: GridDefines.h:155
CoordPair< MAX_NUMBER_OF_GRIDS > GridCoord
Definition: GridDefines.h:171

+ Here is the call graph for this function:

Map::EnterState MapInstanced::CannotEnter ( Player )
overridevirtual

Reimplemented from Map.

305 {
306  //ABORT();
307  return CAN_ENTER;
308 }
Definition: Map.h:373
BattlegroundMap * MapInstanced::CreateBattleground ( uint32  InstanceId,
Battleground bg 
)
private
246 {
247  // load/create a map
248  std::lock_guard<std::mutex> lock(_mapLock);
249 
250  TC_LOG_DEBUG("maps", "MapInstanced::CreateBattleground: map bg %d for %d created.", InstanceId, GetId());
251 
252  BattlegroundMap* map = new BattlegroundMap(GetId(), GetGridExpiry(), InstanceId, this, DIFFICULTY_NONE);
254  map->SetBG(bg);
255  bg->SetBgMap(map);
256 
257  m_InstancedMaps[InstanceId] = map;
258  return map;
259 }
Definition: DBCEnums.h:404
bool IsBattlegroundOrArena() const
Definition: Map.h:403
void SetBG(Battleground *bg)
Definition: Map.h:805
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
uint32 GetId(void) const
Definition: Map.h:325
Definition: Map.h:790
void SetBgMap(BattlegroundMap *map)
Definition: Battleground.h:355
std::mutex _mapLock
Definition: Map.h:637
#define ASSERT
Definition: Errors.h:55
InstancedMaps m_InstancedMaps
Definition: MapInstanced.h:73
time_t GetGridExpiry(void) const
Definition: Map.h:324

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

GarrisonMap * MapInstanced::CreateGarrison ( uint32  instanceId,
Player owner 
)
private
262 {
263  std::lock_guard<std::mutex> lock(_mapLock);
264 
265  GarrisonMap* map = new GarrisonMap(GetId(), GetGridExpiry(), instanceId, this, owner->GetGUID());
266  ASSERT(map->IsGarrison());
267 
268  m_InstancedMaps[instanceId] = map;
269  return map;
270 }
bool IsGarrison() const
Definition: Map.h:404
Definition: GarrisonMap.h:26
uint32 GetId(void) const
Definition: Map.h:325
std::mutex _mapLock
Definition: Map.h:637
#define ASSERT
Definition: Errors.h:55
InstancedMaps m_InstancedMaps
Definition: MapInstanced.h:73
time_t GetGridExpiry(void) const
Definition: Map.h:324

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

InstanceMap * MapInstanced::CreateInstance ( uint32  InstanceId,
InstanceSave save,
Difficulty  difficulty 
)
private
209 {
210  // load/create a map
211  std::lock_guard<std::mutex> lock(_mapLock);
212 
213  // make sure we have a valid map id
214  const MapEntry* entry = sMapStore.LookupEntry(GetId());
215  if (!entry)
216  {
217  TC_LOG_ERROR("maps", "CreateInstance: no entry for map %d", GetId());
218  ABORT();
219  }
220  const InstanceTemplate* iTemplate = sObjectMgr->GetInstanceTemplate(GetId());
221  if (!iTemplate)
222  {
223  TC_LOG_ERROR("maps", "CreateInstance: no instance template for map %d", GetId());
224  ABORT();
225  }
226 
227  // some instances only have one difficulty
228  GetDownscaledMapDifficultyData(GetId(), difficulty);
229 
230  TC_LOG_DEBUG("maps", "MapInstanced::CreateInstance: %s map instance %d for %d created with difficulty %s", save ? "" : "new ", InstanceId, GetId(), difficulty ? "heroic" : "normal");
231 
232  InstanceMap* map = new InstanceMap(GetId(), GetGridExpiry(), InstanceId, difficulty, this);
233  ASSERT(map->IsDungeon());
234 
235  map->LoadRespawnTimes();
236  map->LoadCorpseData();
237 
238  bool load_data = save != NULL;
239  map->CreateInstanceData(load_data);
240 
241  m_InstancedMaps[InstanceId] = map;
242  return map;
243 }
Definition: Map.h:222
Definition: DBCStructure.h:830
arena_t NULL
Definition: jemalloc_internal.h:624
bool IsDungeon() const
Definition: Map.h:395
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
#define sObjectMgr
Definition: ObjectMgr.h:1567
MapDifficultyEntry const * GetDownscaledMapDifficultyData(uint32 mapId, Difficulty &difficulty)
Definition: DBCStores.cpp:737
uint32 GetId(void) const
Definition: Map.h:325
void CreateInstanceData(bool load)
Definition: Map.cpp:3240
Definition: Map.h:758
std::mutex _mapLock
Definition: Map.h:637
void LoadCorpseData()
Definition: Map.cpp:3700
DBCStorage< MapEntry > sMapStore(Mapfmt)
#define ABORT
Definition: Errors.h:56
#define ASSERT
Definition: Errors.h:55
InstancedMaps m_InstancedMaps
Definition: MapInstanced.h:73
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
void LoadRespawnTimes()
Definition: Map.cpp:3630
time_t GetGridExpiry(void) const
Definition: Map.h:324

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Map * MapInstanced::CreateInstanceForPlayer ( const uint32  mapId,
Player player,
uint32  loginInstanceId = 0 
)
115 {
116  if (GetId() != mapId || !player)
117  return nullptr;
118 
119  Map* map = nullptr;
120  uint32 newInstanceId = 0; // instanceId of the resulting map
121 
122  if (IsBattlegroundOrArena())
123  {
124  // instantiate or find existing bg map for player
125  // the instance id is set in battlegroundid
126  newInstanceId = player->GetBattlegroundId();
127  if (!newInstanceId)
128  return nullptr;
129 
130  map = sMapMgr->FindMap(mapId, newInstanceId);
131  if (!map)
132  {
133  if (Battleground* bg = player->GetBattleground())
134  map = CreateBattleground(newInstanceId, bg);
135  else
136  {
137  player->TeleportToBGEntryPoint();
138  return nullptr;
139  }
140  }
141  }
142  else if (!IsGarrison())
143  {
144  InstancePlayerBind* pBind = player->GetBoundInstance(GetId(), player->GetDifficultyID(GetEntry()));
145  InstanceSave* pSave = pBind ? pBind->save : nullptr;
146 
147  // priority:
148  // 1. player's permanent bind
149  // 2. player's current instance id if this is at login
150  // 3. group's current bind
151  // 4. player's current bind
152  if (!pBind || !pBind->perm)
153  {
154  if (loginInstanceId) // if the player has a saved instance id on login, we either use this instance or relocate him out (return null)
155  {
156  map = FindInstanceMap(loginInstanceId);
157  return (map && map->GetId() == GetId()) ? map : nullptr; // is this check necessary? or does MapInstanced only find instances of itself?
158  }
159 
160  InstanceGroupBind* groupBind = nullptr;
161  Group* group = player->GetGroup();
162  // use the player's difficulty setting (it may not be the same as the group's)
163  if (group)
164  {
165  groupBind = group->GetBoundInstance(this);
166  if (groupBind)
167  {
168  // solo saves should be reset when entering a group's instance
169  player->UnbindInstance(GetId(), player->GetDifficultyID(GetEntry()));
170  pSave = groupBind->save;
171  }
172  }
173  }
174  if (pSave)
175  {
176  // solo/perm/group
177  newInstanceId = pSave->GetInstanceId();
178  map = FindInstanceMap(newInstanceId);
179  // it is possible that the save exists but the map doesn't
180  if (!map)
181  map = CreateInstance(newInstanceId, pSave, pSave->GetDifficultyID());
182  }
183  else
184  {
185  // if no instanceId via group members or instance saves is found
186  // the instance will be created for the first time
187  newInstanceId = sMapMgr->GenerateInstanceId();
188 
189  Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficultyID(GetEntry()) : player->GetDifficultyID(GetEntry());
190  //Seems it is now possible, but I do not know if it should be allowed
191  //ASSERT(!FindInstanceMap(NewInstanceId));
192  map = FindInstanceMap(newInstanceId);
193  if (!map)
194  map = CreateInstance(newInstanceId, NULL, diff);
195  }
196  }
197  else
198  {
199  newInstanceId = player->GetGUID().GetCounter();
200  map = FindInstanceMap(newInstanceId);
201  if (!map)
202  map = CreateGarrison(newInstanceId, player);
203  }
204 
205  return map;
206 }
InstanceSave * save
Definition: Group.h:170
bool IsBattlegroundOrArena() const
Definition: Map.h:403
Difficulty
Definition: DBCEnums.h:402
Map * FindInstanceMap(uint32 instanceId) const
Definition: MapInstanced.h:45
GarrisonMap * CreateGarrison(uint32 instanceId, Player *owner)
Definition: MapInstanced.cpp:261
Definition: Group.h:168
bool IsGarrison() const
Definition: Map.h:404
arena_t NULL
Definition: jemalloc_internal.h:624
InstanceMap * CreateInstance(uint32 InstanceId, InstanceSave *save, Difficulty difficulty)
Definition: MapInstanced.cpp:208
uint32 GetId(void) const
Definition: Map.h:325
BattlegroundMap * CreateBattleground(uint32 InstanceId, Battleground *bg)
Definition: MapInstanced.cpp:245
uint32_t uint32
Definition: Define.h:150
MapEntry const * GetEntry() const
Definition: Map.h:266
Definition: Map.h:259
Definition: InstanceSaveMgr.h:44
Difficulty GetDifficultyID() const
Definition: InstanceSaveMgr.h:121
#define sMapMgr
Definition: MapManager.h:194
Definition: Battleground.h:235
InstanceGroupBind * GetBoundInstance(Player *player)
Definition: Group.cpp:2191
uint32 GetInstanceId() const
Definition: InstanceSaveMgr.h:64
Definition: Group.h:191

+ Here is the call graph for this function:

void MapInstanced::DelayedUpdate ( const uint32  diff)
overridevirtual

Reimplemented from Map.

78 {
79  for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
80  i->second->DelayedUpdate(diff);
81 
82  Map::DelayedUpdate(diff); // this may be removed
83 }
virtual void DelayedUpdate(const uint32 diff)
Definition: Map.cpp:2774
InstancedMaps m_InstancedMaps
Definition: MapInstanced.h:73

+ Here is the call graph for this function:

bool MapInstanced::DestroyInstance ( InstancedMaps::iterator &  itr)
274 {
275  itr->second->RemoveAllPlayers();
276  if (itr->second->HavePlayers())
277  {
278  ++itr;
279  return false;
280  }
281 
282  itr->second->UnloadAll();
283  // should only unload VMaps if this is the last instance and grid unloading is enabled
284  if (m_InstancedMaps.size() <= 1 && sWorld->getBoolConfig(CONFIG_GRID_UNLOAD))
285  {
286  VMAP::VMapFactory::createOrGetVMapManager()->unloadMap(itr->second->GetId());
287  MMAP::MMapFactory::createOrGetMMapManager()->unloadMap(itr->second->GetId());
288  // in that case, unload grids of the base map, too
289  // so in the next map creation, (EnsureGridCreated actually) VMaps will be reloaded
290  Map::UnloadAll();
291  }
292 
293  // Free up the instance id and allow it to be reused for bgs and arenas (other instances are handled in the InstanceSaveMgr)
294  if (itr->second->IsBattlegroundOrArena())
295  sMapMgr->FreeInstanceId(itr->second->GetInstanceId());
296 
297  // erase map
298  delete itr->second;
299  m_InstancedMaps.erase(itr++);
300 
301  return true;
302 }
virtual void unloadMap(unsigned int pMapId, int x, int y)=0
Definition: World.h:104
#define sWorld
Definition: World.h:887
bool unloadMap(uint32 mapId, int32 x, int32 y)
Definition: MMapManager.cpp:289
virtual void UnloadAll()
Definition: Map.cpp:1614
#define sMapMgr
Definition: MapManager.h:194
static IVMapManager * createOrGetVMapManager()
Definition: VMapFactory.cpp:28
static MMapManager * createOrGetMMapManager()
Definition: MMapFactory.cpp:28
InstancedMaps m_InstancedMaps
Definition: MapInstanced.h:73

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Map* MapInstanced::FindInstanceMap ( uint32  instanceId) const
inline
46  {
47  InstancedMaps::const_iterator i = m_InstancedMaps.find(instanceId);
48  return(i == m_InstancedMaps.end() ? nullptr : i->second);
49  }
InstancedMaps m_InstancedMaps
Definition: MapInstanced.h:73

+ Here is the caller graph for this function:

InstancedMaps& MapInstanced::GetInstancedMaps ( )
inline
65 { return m_InstancedMaps; }
InstancedMaps m_InstancedMaps
Definition: MapInstanced.h:73
void MapInstanced::InitVisibilityDistance ( )
overridevirtual

Reimplemented from Map.

38 {
39  if (m_InstancedMaps.empty())
40  return;
41  //initialize visibility distances for all instance copies
42  for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
43  {
44  (*i).second->InitVisibilityDistance();
45  }
46 }
InstancedMaps m_InstancedMaps
Definition: MapInstanced.h:73
void MapInstanced::RemoveGridMapReference ( GridCoord const p)
inline
59  {
60  --GridMapReference[p.x_coord][p.y_coord];
61  if (!GridMapReference[p.x_coord][p.y_coord])
62  SetUnloadReferenceLock(GridCoord((MAX_NUMBER_OF_GRIDS - 1) - p.x_coord, (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord), false);
63  }
uint16 GridMapReference[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]
Definition: MapInstanced.h:75
#define MAX_NUMBER_OF_GRIDS
Definition: GridDefines.h:37
void SetUnloadReferenceLock(const GridCoord &p, bool on)
Definition: Map.h:634
CoordPair< MAX_NUMBER_OF_GRIDS > GridCoord
Definition: GridDefines.h:171

+ Here is the call graph for this function:

void MapInstanced::UnloadAll ( )
overridevirtual

Reimplemented from Map.

94 {
95  // Unload instanced maps
96  for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
97  i->second->UnloadAll();
98 
99  // Delete the maps only after everything is unloaded to prevent crashes
100  for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
101  delete i->second;
102 
103  m_InstancedMaps.clear();
104 
105  // Unload own grids (just dummy(placeholder) grids, neccesary to unload GridMaps!)
106  Map::UnloadAll();
107 }
virtual void UnloadAll()
Definition: Map.cpp:1614
InstancedMaps m_InstancedMaps
Definition: MapInstanced.h:73

+ Here is the call graph for this function:

void MapInstanced::Update ( const uint32  t)
overridevirtual

Reimplemented from Map.

49 {
50  // take care of loaded GridMaps (when unused, unload it!)
51  Map::Update(t);
52 
53  // update the instanced maps
54  InstancedMaps::iterator i = m_InstancedMaps.begin();
55 
56  while (i != m_InstancedMaps.end())
57  {
58  if (i->second->CanUnload(t))
59  {
60  if (!DestroyInstance(i)) // iterator incremented
61  {
62  //m_unloadTimer
63  }
64  }
65  else
66  {
67  // update only here, because it may schedule some bad things before delete
68  if (sMapMgr->GetMapUpdater()->activated())
69  sMapMgr->GetMapUpdater()->schedule_update(*i->second, t);
70  else
71  i->second->Update(t);
72  ++i;
73  }
74  }
75 }
bool DestroyInstance(InstancedMaps::iterator &itr)
Definition: MapInstanced.cpp:273
virtual void Update(const uint32)
Definition: Map.cpp:682
#define sMapMgr
Definition: MapManager.h:194
InstancedMaps m_InstancedMaps
Definition: MapInstanced.h:73

+ Here is the call graph for this function:

Friends And Related Function Documentation

friend class MapManager
friend

Member Data Documentation

uint16 MapInstanced::GridMapReference[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]
private
InstancedMaps MapInstanced::m_InstancedMaps
private

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