From f86b8aa573f79577a5a991a58b65c6f69d33b262 Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 27 Oct 2014 21:36:16 -0500 Subject: [PATCH] Core/Phases: Added a new table, terrain_map_info, where you can bind a specific terrain swap to a map, and it will be sent to the player when he enters the map. ToDo: Add conditions support for this. ToDo: This data is already in the DBC (parentMapId) but is it complete? This way allows us an extra degree of freedom if / when we need to add extra information to this table. --- sql/updates/world/2014_10_27_00_world.sql | 10 +++++ src/server/game/Entities/Object/Object.cpp | 32 ++++++++++------ src/server/game/Entities/Object/Object.h | 1 + src/server/game/Globals/ObjectMgr.cpp | 44 +++++++++++++++++++++- src/server/game/Globals/ObjectMgr.h | 5 ++- src/server/game/Maps/Map.cpp | 3 ++ src/server/game/World/World.cpp | 3 ++ 7 files changed, 85 insertions(+), 13 deletions(-) diff --git a/sql/updates/world/2014_10_27_00_world.sql b/sql/updates/world/2014_10_27_00_world.sql index a5198c1776..cfcf96a0e7 100644 --- a/sql/updates/world/2014_10_27_00_world.sql +++ b/sql/updates/world/2014_10_27_00_world.sql @@ -1,9 +1,19 @@ DROP TABLE IF EXISTS `phase_definitions`; DROP TABLE IF EXISTS `phase_info`; DROP TABLE IF EXISTS `terrain_phase_info`; +DROP TABLE IF EXISTS `terrain_map_info`; + CREATE TABLE `terrain_phase_info`( `id` INT(10) NOT NULL, `terrainswapmap` INT(10) NOT NULL, `comment` VARCHAR(255), PRIMARY KEY (`id`, `terrainswapmap`) ); + +CREATE TABLE `terrain_map_info`( + `mapid` INT(10) NOT NULL, + `terrainswapmap` INT(10) NOT NULL, + `comment` VARCHAR(255), + PRIMARY KEY (`mapid`, `terrainswapmap`) +); + diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index f9c434fc43..09f2020c3c 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -2731,17 +2731,7 @@ void WorldObject::SetInPhase(uint32 id, bool update, bool apply) else _phases.erase(id); - // Clear all terrain swaps, will be rebuilt below - // Reason for this is, multiple phases can have the same terrain swap, we should not remove the swap if another phase still use it - _terrainSwaps.clear(); - - // Check all applied phases for terrain swap and add it only once - for (auto phaseId : _phases) - { - std::list& swaps = sObjectMgr->GetPhaseTerrainSwaps(phaseId); - for (auto swap : swaps) - _terrainSwaps.insert(swap); - } + RebuildTerrainSwaps(); if (update && IsInWorld()) UpdateObjectVisibility(); @@ -2914,3 +2904,23 @@ ObjectGuid WorldObject::GetTransGUID() const return GetTransport()->GetGUID(); return ObjectGuid::Empty; } + +void WorldObject::RebuildTerrainSwaps() +{ + // Clear all terrain swaps, will be rebuilt below + // Reason for this is, multiple phases can have the same terrain swap, we should not remove the swap if another phase still use it + _terrainSwaps.clear(); + + // Check all applied phases for terrain swap and add it only once + for (auto phaseId : _phases) + { + std::list& swaps = sObjectMgr->GetPhaseTerrainSwaps(phaseId); + for (auto swap : swaps) + _terrainSwaps.insert(swap); + } + + // Now insert the map terrain swaps + std::list& mapSwaps = sObjectMgr->GetMapTerrainSwaps(GetMapId()); + for (auto swap : mapSwaps) + _terrainSwaps.insert(swap); +} diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index 1acca131f8..5ee8f4f26f 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -593,6 +593,7 @@ class WorldObject : public Object, public WorldLocation virtual void SetPhaseMask(uint32 newPhaseMask, bool update); virtual void SetInPhase(uint32 id, bool update, bool apply); + void RebuildTerrainSwaps(); uint32 GetPhaseMask() const { return m_phaseMask; } bool InSamePhase(WorldObject const* obj) const; bool InSamePhase(uint32 phasemask) const { return (GetPhaseMask() & phasemask) != 0; } diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 100687e74d..538e02e14f 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -9226,8 +9226,49 @@ void ObjectMgr::LoadFactionChangeTitles() TC_LOG_INFO("server.loading", ">> Loaded %u faction change title pairs in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); } +void ObjectMgr::LoadTerrainMapInfo() +{ + _terrainMapInfoStore.clear(); + + uint32 oldMSTime = getMSTime(); + + // 0 1 + QueryResult result = WorldDatabase.Query("SELECT mapid, terrainswapmap FROM `terrain_map_info`"); + + if (!result) + { + TC_LOG_INFO("server.loading", ">> Loaded 0 terrain area infos. DB table `terrain_map_info` is empty."); + return; + } + + uint32 count = 0; + do + { + Field* fields = result->Fetch(); + + uint32 mapId = fields[0].GetUInt32(); + + MapEntry const* map = sMapStore.LookupEntry(mapId); + if (!map) + { + TC_LOG_ERROR("sql.sql", "Map %u defined in `terrain_map_info` does not exist, skipped.", mapId); + continue; + } + + uint32 terrainSwap = fields[1].GetUInt32(); + + _terrainMapInfoStore[mapId].push_back(terrainSwap); + + ++count; + } while (result->NextRow()); + + TC_LOG_INFO("server.loading", ">> Loaded %u terrain map infos in %u ms.", count, GetMSTimeDiffToNow(oldMSTime)); +} + void ObjectMgr::LoadTerrainPhaseInfo() { + _terrainPhaseInfoStore.clear(); + uint32 oldMSTime = getMSTime(); // 0 1 @@ -9249,7 +9290,7 @@ void ObjectMgr::LoadTerrainPhaseInfo() PhaseEntry const* phase = sPhaseStore.LookupEntry(phaseId); if (!phase) { - TC_LOG_ERROR("sql.sql", "Phase %u defined in `terrain_phase_info` does not exists, skipped.", phaseId); + TC_LOG_ERROR("sql.sql", "Phase %u defined in `terrain_phase_info` does not exist, skipped.", phaseId); continue; } @@ -9260,6 +9301,7 @@ void ObjectMgr::LoadTerrainPhaseInfo() ++count; } while (result->NextRow()); + TC_LOG_INFO("server.loading", ">> Loaded %u terrain phase infos in %u ms.", count, GetMSTimeDiffToNow(oldMSTime)); } diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index 41bfeb9f8a..12e358d3c0 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -1029,6 +1029,7 @@ class ObjectMgr void AddSpellToTrainer(uint32 entry, uint32 spell, uint32 spellCost, uint32 reqSkill, uint32 reqSkillValue, uint32 reqLevel); void LoadTerrainPhaseInfo(); + void LoadTerrainMapInfo(); std::string GeneratePetName(uint32 entry); uint32 GetBaseXP(uint8 level); @@ -1286,6 +1287,7 @@ class ObjectMgr } std::list& GetPhaseTerrainSwaps(uint32 phaseid) { return _terrainPhaseInfoStore[phaseid]; } + std::list& GetMapTerrainSwaps(uint32 mapid) { return _terrainMapInfoStore[mapid]; } // for wintergrasp only GraveYardContainer GraveYardStore; @@ -1403,6 +1405,7 @@ class ObjectMgr InstanceTemplateContainer _instanceTemplateStore; TerrainPhaseInfo _terrainPhaseInfoStore; + TerrainPhaseInfo _terrainMapInfoStore; private: void LoadScripts(ScriptsType type); @@ -1418,7 +1421,7 @@ class ObjectMgr PetLevelInfoContainer _petInfoStore; // [creature_id][level] void BuildPlayerLevelInfo(uint8 race, uint8 class_, uint8 level, PlayerLevelInfo* plinfo) const; - + PlayerInfo* _playerInfo[MAX_RACES][MAX_CLASSES]; typedef std::vector PlayerXPperLevel; // [level] diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index f5f9546b7b..1adf4fdcff 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -546,6 +546,9 @@ bool Map::AddToMap(T* obj) if (obj->isActiveObject()) AddToActive(obj); + obj->RebuildTerrainSwaps(); + obj->SendUpdatePhasing(); + //something, such as vehicle, needs to be update immediately //also, trigger needs to cast spell, if not update, cannot see visual obj->UpdateObjectVisibility(true); diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index 286d157141..3e35944574 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -1729,6 +1729,9 @@ void World::SetInitialWorldSettings() TC_LOG_INFO("server.loading", "Loading Terrain Phase definitions..."); sObjectMgr->LoadTerrainPhaseInfo(); + TC_LOG_INFO("server.loading", "Loading Terrain Map definitions..."); + sObjectMgr->LoadTerrainMapInfo(); + TC_LOG_INFO("server.loading", "Loading Conditions..."); sConditionMgr->LoadConditions();