mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
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:
@@ -789,21 +789,13 @@ 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;
|
||||
}
|
||||
|
||||
if (!sObjectMgr->GetCreatureTemplate(entry))
|
||||
{
|
||||
TC_LOG_ERROR("bg.battlefield", "Battlefield::SpawnCreature: entry %u does not exist.", entry);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Creature* creature = Creature::CreateCreature(entry, map, pos);
|
||||
Creature* creature = Creature::CreateCreature(entry, m_Map, pos);
|
||||
if (!creature)
|
||||
{
|
||||
TC_LOG_ERROR("bg.battlefield", "Battlefield::SpawnCreature: Can't create creature entry: %u", entry);
|
||||
@@ -813,7 +805,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);
|
||||
|
||||
return creature;
|
||||
@@ -822,14 +814,6 @@ 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)
|
||||
{
|
||||
TC_LOG_ERROR("bg.battlefield", "Battlefield::SpawnGameObject: Can't create GameObject (Entry: %u). Map not found.", entry);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!sObjectMgr->GetGameObjectTemplate(entry))
|
||||
{
|
||||
TC_LOG_ERROR("bg.battlefield", "Battlefield::SpawnGameObject: GameObject template %u not found in database! Battlefield not created!", entry);
|
||||
@@ -837,7 +821,7 @@ GameObject* Battlefield::SpawnGameObject(uint32 entry, Position const& pos, Quat
|
||||
}
|
||||
|
||||
// Create gameobject
|
||||
GameObject* go = GameObject::CreateGameObject(entry, map, pos, rot, 255, GO_STATE_READY);
|
||||
GameObject* go = GameObject::CreateGameObject(entry, m_Map, pos, rot, 255, GO_STATE_READY);
|
||||
if (!go)
|
||||
{
|
||||
TC_LOG_ERROR("bg.battlefield", "Battlefield::SpawnGameObject: Could not create gameobject template %u! Battlefield has not been created!", entry);
|
||||
@@ -845,7 +829,7 @@ GameObject* Battlefield::SpawnGameObject(uint32 entry, Position const& pos, Quat
|
||||
}
|
||||
|
||||
// Add to world
|
||||
map->AddToMap(go);
|
||||
m_Map->AddToMap(go);
|
||||
go->setActive(true);
|
||||
|
||||
return go;
|
||||
|
||||
@@ -1215,9 +1215,9 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
|
||||
sObjectMgr->AddCreatureToGrid(*itr, 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->posX, data->posY))
|
||||
if (map && !map->Instanceable() && map->IsGridLoaded(data->posX, data->posY))
|
||||
Creature::CreateCreatureFromDB(*itr, map);
|
||||
}
|
||||
}
|
||||
@@ -1237,9 +1237,9 @@ 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* 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->posX, data->posY))
|
||||
if (map && !map->Instanceable() && map->IsGridLoaded(data->posX, data->posY))
|
||||
{
|
||||
if (GameObject* go = GameObject::CreateGameObjectFromDB(*itr, map, false))
|
||||
{
|
||||
|
||||
@@ -228,8 +228,8 @@ void PoolGroup<Creature>::Despawn1Object(uint64 guid)
|
||||
{
|
||||
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;)
|
||||
@@ -250,8 +250,8 @@ void PoolGroup<GameObject>::Despawn1Object(uint64 guid)
|
||||
{
|
||||
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;)
|
||||
@@ -385,9 +385,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->posX, data->posY))
|
||||
if (map && !map->Instanceable() && map->IsGridLoaded(data->posX, data->posY))
|
||||
Creature::CreateCreatureFromDB(obj->guid, map);
|
||||
}
|
||||
}
|
||||
@@ -401,9 +401,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->posX, data->posY))
|
||||
if (map && !map->Instanceable() && map->IsGridLoaded(data->posX, data->posY))
|
||||
{
|
||||
if (GameObject* go = GameObject::CreateGameObjectFromDB(obj->guid, map, false))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user