Core/Maps: Use FindMap instead of CreateBaseMap in places where the intent was to check for a existing map (and a loaded grid on that map)

This commit is contained in:
Shauren
2020-07-18 12:07:02 +02:00
committed by Ovahlord
parent 52612cc145
commit 9d5848ec6e
4 changed files with 44 additions and 51 deletions

View File

@@ -766,16 +766,8 @@ bool BfGraveyard::HasNpc(ObjectGuid guid)
Creature* Battlefield::SpawnCreature(uint32 entry, Position const& pos)
{
//Get map object
Map* map = sMapMgr->CreateBaseMap(m_MapId);
if (!map)
{
TC_LOG_ERROR("bg.battlefield", "Battlefield::SpawnCreature: Can't create creature entry: %u, map not found.", entry);
return nullptr;
}
Creature* creature = new Creature();
if (!creature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map, entry, pos))
if (!creature->Create(m_Map->GenerateLowGuid<HighGuid::Unit>(), m_Map, entry, pos))
{
TC_LOG_ERROR("bg.battlefield", "Battlefield::SpawnCreature: Can't create creature entry: %u", entry);
delete creature;
@@ -784,7 +776,7 @@ Creature* Battlefield::SpawnCreature(uint32 entry, Position const& pos)
creature->SetHomePosition(pos);
// Set creature in world
map->AddToMap(creature);
m_Map->AddToMap(creature);
creature->setActive(true);
creature->SetFarVisible(true);
@@ -794,17 +786,12 @@ Creature* Battlefield::SpawnCreature(uint32 entry, Position const& pos)
// Method for spawning gameobject on map
GameObject* Battlefield::SpawnGameObject(uint32 entry, Position const& pos, QuaternionData const& rot)
{
// Get map object
Map* map = sMapMgr->CreateBaseMap(m_MapId);
if (!map)
return nullptr;
// Create gameobject
GameObject* go = nullptr;
if (sObjectMgr->GetGameObjectTypeByEntry(entry) == GAMEOBJECT_TYPE_TRANSPORT)
{
go = new Transport();
if (!go->Create(map->GenerateLowGuid<HighGuid::Transport>(), entry, map, pos, rot, 255, GO_STATE_READY))
if (!go->Create(m_Map->GenerateLowGuid<HighGuid::Transport>(), entry, m_Map, pos, rot, 255, GO_STATE_READY))
{
TC_LOG_ERROR("bg.battlefield", "Battlefield::SpawnGameObject: Gameobject template %u could not be found in the database! Battlefield has not been created!", entry);
TC_LOG_ERROR("bg.battlefield", "Battlefield::SpawnGameObject: Could not create gameobject template %u! Battlefield has not been created!", entry);
@@ -815,7 +802,7 @@ GameObject* Battlefield::SpawnGameObject(uint32 entry, Position const& pos, Quat
else
{
go = new GameObject();
if (!go->Create(map->GenerateLowGuid<HighGuid::GameObject>(), entry, map, pos, rot, 255, GO_STATE_READY))
if (!go->Create(m_Map->GenerateLowGuid<HighGuid::GameObject>(), entry, m_Map, pos, rot, 255, GO_STATE_READY))
{
TC_LOG_ERROR("bg.battlefield", "Battlefield::SpawnGameObject: Gameobject template %u could not be found in the database! Battlefield has not been created!", entry);
TC_LOG_ERROR("bg.battlefield", "Battlefield::SpawnGameObject: Could not create gameobject template %u! Battlefield has not been created!", entry);
@@ -825,7 +812,7 @@ GameObject* Battlefield::SpawnGameObject(uint32 entry, Position const& pos, Quat
}
// Add to world
map->AddToMap(go);
m_Map->AddToMap(go);
go->setActive(true);
go->SetFarVisible(true);

View File

@@ -410,7 +410,7 @@ bool BattlefieldWG::SetupBattlefield()
m_BattleId = BATTLEFIELD_BATTLEID_WG;
m_ZoneId = BATTLEFIELD_WG_ZONEID;
m_MapId = BATTLEFIELD_WG_MAPID;
m_Map = sMapMgr->FindMap(m_MapId, 0);
m_Map = sMapMgr->CreateBaseMap(m_MapId);
InitStalker(BATTLEFIELD_WG_NPC_STALKER, WintergraspStalkerPos);

View File

@@ -1260,15 +1260,18 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
sObjectMgr->AddCreatureToGrid(*itr, data);
// Spawn if necessary (loaded grids only)
Map* map = sMapMgr->CreateBaseMap(data->mapId);
map->RemoveRespawnTime(SPAWN_TYPE_CREATURE, *itr);
// We use spawn coords to spawn
if (!map->Instanceable() && map->IsGridLoaded(data->spawnPoint))
Map* map = sMapMgr->FindMap(data->mapId, 0);
if (map)
{
Creature* creature = new Creature();
//TC_LOG_DEBUG("misc", "Spawning creature %u", *itr);
if (!creature->LoadFromDB(*itr, map, true, false))
delete creature;
map->RemoveRespawnTime(SPAWN_TYPE_CREATURE, *itr);
// We use spawn coords to spawn
if (!map->Instanceable() && map->IsGridLoaded(data->spawnPoint))
{
Creature* creature = new Creature();
//TC_LOG_DEBUG("misc", "Spawning creature %u", *itr);
if (!creature->LoadFromDB(*itr, map, true, false))
delete creature;
}
}
}
}
@@ -1288,24 +1291,27 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
sObjectMgr->AddGameobjectToGrid(*itr, data);
// Spawn if necessary (loaded grids only)
// this base map checked as non-instanced and then only existed
Map* map = sMapMgr->CreateBaseMap(data->mapId);
map->RemoveRespawnTime(SPAWN_TYPE_GAMEOBJECT, *itr);
// We use current coords to unspawn, not spawn coords since creature can have changed grid
if (!map->Instanceable() && map->IsGridLoaded(data->spawnPoint))
Map* map = sMapMgr->FindMap(data->mapId, 0);
if (map)
{
GameObject* pGameobject = nullptr;
if (sObjectMgr->GetGameObjectTypeByEntry(data->id) == GAMEOBJECT_TYPE_TRANSPORT)
pGameobject = new Transport();
else
pGameobject = new GameObject();
//TC_LOG_DEBUG("misc", "Spawning gameobject %u", *itr);
/// @todo find out when it is add to map
if (!pGameobject->LoadFromDB(*itr, map, false))
delete pGameobject;
else
map->RemoveRespawnTime(SPAWN_TYPE_GAMEOBJECT, *itr);
// We use current coords to unspawn, not spawn coords since creature can have changed grid
if (!map->Instanceable() && map->IsGridLoaded(data->spawnPoint))
{
if (pGameobject->isSpawnedByDefault())
map->AddToMap(pGameobject);
GameObject* pGameobject = nullptr;
if (sObjectMgr->GetGameObjectTypeByEntry(data->id) == GAMEOBJECT_TYPE_TRANSPORT)
pGameobject = new Transport();
else
pGameobject = new GameObject();
//TC_LOG_DEBUG("misc", "Spawning gameobject %u", *itr);
/// @todo find out when it is add to map
if (!pGameobject->LoadFromDB(*itr, map, false))
delete pGameobject;
else
{
if (pGameobject->isSpawnedByDefault())
map->AddToMap(pGameobject);
}
}
}
}

View File

@@ -175,8 +175,8 @@ void PoolGroup<Creature>::Despawn1Object(ObjectGuid::LowType guid, bool alwaysDe
{
sObjectMgr->RemoveCreatureFromGrid(guid, data);
Map* map = sMapMgr->CreateBaseMap(data->mapId);
if (!map->Instanceable())
Map* map = sMapMgr->FindMap(data->mapId, 0);
if (map && !map->Instanceable())
{
auto creatureBounds = map->GetCreatureBySpawnIdStore().equal_range(guid);
for (auto itr = creatureBounds.first; itr != creatureBounds.second; )
@@ -202,8 +202,8 @@ void PoolGroup<GameObject>::Despawn1Object(ObjectGuid::LowType guid, bool always
{
sObjectMgr->RemoveGameobjectFromGrid(guid, data);
Map* map = sMapMgr->CreateBaseMap(data->mapId);
if (!map->Instanceable())
Map* map = sMapMgr->FindMap(data->mapId, 0);
if (map && !map->Instanceable())
{
auto gameObjectBounds = map->GetGameObjectBySpawnIdStore().equal_range(guid);
for (auto itr = gameObjectBounds.first; itr != gameObjectBounds.second; )
@@ -324,9 +324,9 @@ void PoolGroup<Creature>::Spawn1Object(PoolObject* obj)
sObjectMgr->AddCreatureToGrid(obj->guid, data);
// Spawn if necessary (loaded grids only)
Map* map = sMapMgr->CreateBaseMap(data->mapId);
Map* map = sMapMgr->FindMap(data->mapId, 0);
// We use spawn coords to spawn
if (!map->Instanceable() && map->IsGridLoaded(data->spawnPoint))
if (map && !map->Instanceable() && map->IsGridLoaded(data->spawnPoint))
{
Creature* creature = new Creature();
//TC_LOG_DEBUG("pool", "Spawning creature %u", guid);
@@ -348,9 +348,9 @@ void PoolGroup<GameObject>::Spawn1Object(PoolObject* obj)
sObjectMgr->AddGameobjectToGrid(obj->guid, data);
// Spawn if necessary (loaded grids only)
// this base map checked as non-instanced and then only existed
Map* map = sMapMgr->CreateBaseMap(data->mapId);
Map* map = sMapMgr->FindMap(data->mapId, 0);
// We use current coords to unspawn, not spawn coords since creature can have changed grid
if (!map->Instanceable() && map->IsGridLoaded(data->spawnPoint))
if (map && !map->Instanceable() && map->IsGridLoaded(data->spawnPoint))
{
GameObject* pGameobject = nullptr;
if (sObjectMgr->GetGameObjectTypeByEntry(data->id) == GAMEOBJECT_TYPE_TRANSPORT)