aboutsummaryrefslogtreecommitdiff
path: root/src/game/Map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/Map.cpp')
-rw-r--r--src/game/Map.cpp46
1 files changed, 31 insertions, 15 deletions
diff --git a/src/game/Map.cpp b/src/game/Map.cpp
index 4d6c10107eb..93fd3e21e1b 100644
--- a/src/game/Map.cpp
+++ b/src/game/Map.cpp
@@ -127,14 +127,12 @@ void Map::LoadMap(int gx,int gy, bool reload)
if(GridMaps[gx][gy])
return;
- Map* baseMap = const_cast<Map*>(MapManager::Instance().CreateBaseMap(i_id));
-
// load grid map for base map
- if (!baseMap->GridMaps[gx][gy])
- baseMap->EnsureGridCreated(GridPair(63-gx,63-gy));
+ if (!m_parentMap->GridMaps[gx][gy])
+ m_parentMap->EnsureGridCreated(GridPair(63-gx,63-gy));
- ((MapInstanced*)(baseMap))->AddGridMapReference(GridPair(gx,gy));
- GridMaps[gx][gy] = baseMap->GridMaps[gx][gy];
+ ((MapInstanced*)(m_parentMap))->AddGridMapReference(GridPair(gx,gy));
+ GridMaps[gx][gy] = m_parentMap->GridMaps[gx][gy];
return;
}
@@ -187,11 +185,11 @@ void Map::DeleteStateMachine()
delete si_GridStates[GRID_STATE_REMOVAL];
}
-Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode)
+Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode, Map* _parent)
: i_mapEntry (sMapStore.LookupEntry(id)), i_spawnMode(SpawnMode),
i_id(id), i_InstanceId(InstanceId), m_unloadTimer(0),
m_activeNonPlayersIter(m_activeNonPlayers.end()),
- i_gridExpiry(expiry)
+ i_gridExpiry(expiry), m_parentMap(_parent ? _parent : this)
, i_lock(true)
{
m_notifyTimer.SetInterval(IN_MILISECONDS/2);
@@ -364,6 +362,13 @@ void Map::DeleteFromWorld(T* obj)
delete obj;
}
+template<>
+void Map::DeleteFromWorld(Player* pl)
+{
+ ObjectAccessor::Instance().RemoveObject(pl);
+ delete pl;
+}
+
template<class T>
void Map::AddNotifier(T*)
{
@@ -475,8 +480,7 @@ void Map::LoadGrid(float x, float y)
bool Map::Add(Player *player)
{
player->GetMapRef().link(this, player);
-
- player->SetInstanceId(GetInstanceId());
+ player->SetMap(this);
// update player state for other player and visa-versa
CellPair p = Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY());
@@ -504,6 +508,8 @@ Map::Add(T *obj)
return;
}
+ obj->SetMap(this);
+
Cell cell(p);
if(obj->isActiveObject())
EnsureGridLoadedAtEnter(cell);
@@ -800,8 +806,12 @@ void Map::Remove(Player *player, bool remove)
CellPair p = Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY());
if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
{
+ if(remove)
+ player->CleanupsBeforeDelete();
+
// invalid coordinates
player->RemoveFromWorld();
+ player->ResetMap();
if( remove )
DeleteFromWorld(player);
@@ -821,12 +831,16 @@ void Map::Remove(Player *player, bool remove)
NGridType *grid = getNGrid(cell.GridX(), cell.GridY());
assert(grid != NULL);
+ if(remove)
+ player->CleanupsBeforeDelete();
+
player->RemoveFromWorld();
RemoveFromGrid(player,grid,cell);
SendRemoveTransports(player);
UpdateObjectVisibility(player,cell,p);
+ player->ResetMap();
if( remove )
DeleteFromWorld(player);
}
@@ -870,6 +884,7 @@ Map::Remove(T *obj, bool remove)
UpdateObjectVisibility(obj,cell,p);
+ obj->ResetMap();
if( remove )
{
// if option set then object already saved at this moment
@@ -1166,7 +1181,8 @@ bool Map::UnloadGrid(const uint32 &x, const uint32 &y, bool unloadAll)
VMAP::VMapFactory::createOrGetVMapManager()->unloadMap(GetId(), gy, gx);
}
else
- ((MapInstanced*)(MapManager::Instance().CreateBaseMap(i_id)))->RemoveGridMapReference(GridPair(gx, gy));
+ ((MapInstanced*)m_parentMap)->RemoveGridMapReference(GridPair(gx, gy));
+
GridMaps[gx][gy] = NULL;
}
DEBUG_LOG("Unloading grid[%u,%u] for map %u finished", x,y, i_id);
@@ -2327,8 +2343,8 @@ template void Map::Remove(DynamicObject *, bool);
/* ******* Dungeon Instance Maps ******* */
-InstanceMap::InstanceMap(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode)
- : Map(id, expiry, InstanceId, SpawnMode),
+InstanceMap::InstanceMap(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode, Map* _parent)
+ : Map(id, expiry, InstanceId, SpawnMode, _parent),
m_resetAfterUnload(false), m_unloadWhenEmpty(false),
i_data(NULL), i_script_id(0)
{
@@ -2663,8 +2679,8 @@ uint32 InstanceMap::GetMaxPlayers() const
/* ******* Battleground Instance Maps ******* */
-BattleGroundMap::BattleGroundMap(uint32 id, time_t expiry, uint32 InstanceId)
- : Map(id, expiry, InstanceId, DIFFICULTY_NORMAL)
+BattleGroundMap::BattleGroundMap(uint32 id, time_t expiry, uint32 InstanceId, Map* _parent)
+ : Map(id, expiry, InstanceId, DIFFICULTY_NORMAL, _parent)
{
}