diff --git a/src/server/game/Battlefield/Battlefield.cpp b/src/server/game/Battlefield/Battlefield.cpp index 4e93c26d7f0..77532b4aa0c 100644 --- a/src/server/game/Battlefield/Battlefield.cpp +++ b/src/server/game/Battlefield/Battlefield.cpp @@ -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(), map, entry, pos)) + if (!creature->Create(m_Map->GenerateLowGuid(), 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(), entry, map, pos, rot, 255, GO_STATE_READY)) + if (!go->Create(m_Map->GenerateLowGuid(), 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(), entry, map, pos, rot, 255, GO_STATE_READY)) + if (!go->Create(m_Map->GenerateLowGuid(), 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); diff --git a/src/server/game/Battlefield/Zones/BattlefieldWG.cpp b/src/server/game/Battlefield/Zones/BattlefieldWG.cpp index c7e62b07603..f7d57bf9510 100644 --- a/src/server/game/Battlefield/Zones/BattlefieldWG.cpp +++ b/src/server/game/Battlefield/Zones/BattlefieldWG.cpp @@ -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); diff --git a/src/server/game/Events/GameEventMgr.cpp b/src/server/game/Events/GameEventMgr.cpp index e52500839dd..88cdb42f7ad 100644 --- a/src/server/game/Events/GameEventMgr.cpp +++ b/src/server/game/Events/GameEventMgr.cpp @@ -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); + } } } } diff --git a/src/server/game/Pools/PoolMgr.cpp b/src/server/game/Pools/PoolMgr.cpp index e174f58507b..33c5241a498 100644 --- a/src/server/game/Pools/PoolMgr.cpp +++ b/src/server/game/Pools/PoolMgr.cpp @@ -175,8 +175,8 @@ void PoolGroup::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::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::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::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)