diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 935db93b0ad..cbfb2e45864 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -174,6 +174,11 @@ void Creature::AddToWorld() GetMap()->GetObjectsStore().insert(GetObjectGuid(), (Creature*)this); Unit::AddToWorld(); + + // Make active if required + std::set const* mapList = sWorld.getConfigForceLoadMapIds(); + if ((mapList && mapList->find(GetMapId()) != mapList->end()) /*|| FlagsExtra & ACTIVE*/) + SetActiveObjectState(true); } void Creature::RemoveFromWorld() diff --git a/src/game/Map.h b/src/game/Map.h index 4f8b6806d78..03f8020dfbc 100644 --- a/src/game/Map.h +++ b/src/game/Map.h @@ -188,7 +188,6 @@ class MANGOS_DLL_SPEC Map : public GridRefManager MapDifficultyEntry const* GetMapDifficulty() const; // dependent from map difficulty bool Instanceable() const { return i_mapEntry && i_mapEntry->Instanceable(); } - // NOTE: this duplicate of Instanceable(), but Instanceable() can be changed when BG also will be instanceable bool IsDungeon() const { return i_mapEntry && i_mapEntry->IsDungeon(); } bool IsRaid() const { return i_mapEntry && i_mapEntry->IsRaid(); } bool IsNonRaidDungeon() const { return i_mapEntry && i_mapEntry->IsNonRaidDungeon(); } @@ -196,6 +195,7 @@ class MANGOS_DLL_SPEC Map : public GridRefManager bool IsBattleGround() const { return i_mapEntry && i_mapEntry->IsBattleGround(); } bool IsBattleArena() const { return i_mapEntry && i_mapEntry->IsBattleArena(); } bool IsBattleGroundOrArena() const { return i_mapEntry && i_mapEntry->IsBattleGroundOrArena(); } + bool IsContinent() const { return i_mapEntry && i_mapEntry->IsContinent(); } // can't be NULL for loaded map MapPersistentState* GetPersistentState() const { return m_persistentState; } diff --git a/src/game/MapManager.cpp b/src/game/MapManager.cpp index 72ba79927da..23d7c9188c2 100644 --- a/src/game/MapManager.cpp +++ b/src/game/MapManager.cpp @@ -102,6 +102,8 @@ Map* MapManager::CreateMap(uint32 id, const WorldObject* obj) MANGOS_ASSERT(obj && obj->GetTypeId() == TYPEID_PLAYER); // create DungeonMap object m = CreateInstance(id, (Player*)obj); + // Load active objects for this map + sObjectMgr.LoadActiveEntities(m); } else { diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 483aceb3d89..09f2de91426 100755 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -9076,6 +9076,49 @@ void ObjectMgr::LoadVendorTemplates() sLog.outErrorDb("Table `npc_vendor_template` has vendor template %u not used by any vendors ", *vItr); } +/* This function is supposed to take care of three things: + * 1) Load Transports on Map or on Continents + * 2) Load Active Npcs on Map or Continents + * 3) Load Everything dependend on config setting LoadAllGridsOnMaps + * + * This function is currently WIP, hence many things are only existing as draft. + */ +void ObjectMgr::LoadActiveEntities(Map* _map) +{ + // Special case on startup - load continents + if (!_map) + { + uint32 continents[] = {0, 1, 530, 571}; + for (int i = 0; i < countof(continents); ++i) + { + _map = sMapMgr.FindMap(continents[i]); + if (!_map) + _map = sMapMgr.CreateMap(continents[i], NULL); + + if (_map) + LoadActiveEntities(_map); + else + sLog.outError("ObjectMgr::LoadActiveEntities - Unable to create Map %u", continents[i]); + } + + return; + } + + // Load active objects for _map + std::set const* mapList = sWorld.getConfigForceLoadMapIds(); + if (mapList && mapList->find(_map->GetId()) != mapList->end()) + { + for (CreatureDataMap::const_iterator itr = mCreatureDataMap.begin(); itr != mCreatureDataMap.end(); ++itr) + { + if (itr->second.mapid == _map->GetId()) + _map->ForceLoadGrid(itr->second.posX, itr->second.posY); + } + } + //else // Normal case - Load all npcs that are active + + // Load Transports on Map _map +} + void ObjectMgr::LoadNpcGossips() { m_mCacheNpcTextIdMap.clear(); diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index 580c537a727..6e629c2134f 100755 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -137,7 +137,7 @@ struct MangosStringLocale uint32 Emote; }; -typedef UNORDERED_MAP CreatureDataMap; +typedef UNORDERED_MAP CreatureDataMap; typedef CreatureDataMap::value_type CreatureDataPair; class FindCreatureData @@ -757,6 +757,9 @@ class ObjectMgr void LoadTrainerTemplates(); void LoadTrainers() { LoadTrainers("npc_trainer", false); } + /// @param _map Map* of the map for which to load active entities. If NULL active entities on continents are loaded + void LoadActiveEntities(Map* _map); + void LoadVehicleAccessory(); std::string GeneratePetName(uint32 entry); diff --git a/src/game/World.cpp b/src/game/World.cpp index a37098af021..acccdb3d4a9 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -1455,6 +1455,10 @@ void World::SetInitialWorldSettings() m_timers[WUPDATE_EVENTS].SetInterval(nextGameEvent); // depend on next event sLog.outString(); + sLog.outString("Loading grids for active creatures or transports..."); + sObjectMgr.LoadActiveEntities(NULL); + sLog.outString(); + // Delete all characters which have been deleted X days before Player::DeleteOldCharacters(); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index f905db46975..a9a3b171b0c 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "12782" + #define REVISION_NR "12783" #endif // __REVISION_NR_H__