diff options
author | Shauren <shauren.trinity@gmail.com> | 2022-12-31 18:22:40 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2022-12-31 18:22:40 +0100 |
commit | 704142f15a51055c4fa064b1286b65d78b795e05 (patch) | |
tree | cccebbe29c3c7bf96fc90e0a1e6f34f19cda206e | |
parent | 2c044ea9f558d5b181d56f1e318c7c96396f69d7 (diff) |
Core/Maps: Fixed retrieving terrain info when on child maps
-rw-r--r-- | src/server/game/Entities/Object/Object.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Handlers/QueryHandler.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Maps/Map.cpp | 28 | ||||
-rw-r--r-- | src/server/game/Maps/TerrainMgr.cpp | 105 | ||||
-rw-r--r-- | src/server/game/Maps/TerrainMgr.h | 42 | ||||
-rw-r--r-- | src/server/game/Movement/PathGenerator.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Phasing/PhasingHandler.cpp | 6 | ||||
-rw-r--r-- | src/server/game/Phasing/PhasingHandler.h | 2 | ||||
-rw-r--r-- | src/server/scripts/Commands/cs_go.cpp | 8 | ||||
-rw-r--r-- | src/server/scripts/Commands/cs_mmaps.cpp | 6 |
10 files changed, 98 insertions, 105 deletions
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index c40c3cac6ff..78d04e6f14a 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -3484,7 +3484,7 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float // Unit is flying, check for potential collision via vmaps if (path.GetPathType() & PATHFIND_NOT_USING_PATH) { - col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(PhasingHandler::GetTerrainMapId(GetPhaseShift(), GetMap()->GetTerrain(), pos.m_positionX, pos.m_positionY), + col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(PhasingHandler::GetTerrainMapId(GetPhaseShift(), GetMapId(), GetMap()->GetTerrain(), pos.m_positionX, pos.m_positionY), pos.m_positionX, pos.m_positionY, pos.m_positionZ + halfHeight, destx, desty, destz + halfHeight, destx, desty, destz, -0.5f); diff --git a/src/server/game/Handlers/QueryHandler.cpp b/src/server/game/Handlers/QueryHandler.cpp index bc117d6e305..fb19c43a322 100644 --- a/src/server/game/Handlers/QueryHandler.cpp +++ b/src/server/game/Handlers/QueryHandler.cpp @@ -151,7 +151,7 @@ void WorldSession::HandleQueryCorpseLocation(WorldPackets::Query::QueryCorpseLoc mapID = corpseMapEntry->CorpseMapID; x = corpseMapEntry->Corpse.X; y = corpseMapEntry->Corpse.Y; - z = entranceTerrain->GetStaticHeight(player->GetPhaseShift(), x, y, MAX_HEIGHT); + z = entranceTerrain->GetStaticHeight(player->GetPhaseShift(), mapID, x, y, MAX_HEIGHT); } } } diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 102bf08b15e..00f22869440 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -1665,74 +1665,74 @@ void Map::UnloadAll() void Map::GetFullTerrainStatusForPosition(PhaseShift const& phaseShift, float x, float y, float z, PositionFullTerrainStatus& data, map_liquidHeaderTypeFlags reqLiquidType, float collisionHeight) { - m_terrain->GetFullTerrainStatusForPosition(phaseShift, x, y, z, data, reqLiquidType, collisionHeight, &_dynamicTree); + m_terrain->GetFullTerrainStatusForPosition(phaseShift, GetId(), x, y, z, data, reqLiquidType, collisionHeight, &_dynamicTree); } ZLiquidStatus Map::GetLiquidStatus(PhaseShift const& phaseShift, float x, float y, float z, map_liquidHeaderTypeFlags ReqLiquidType, LiquidData* data, float collisionHeight) { - return m_terrain->GetLiquidStatus(phaseShift, x, y, z, ReqLiquidType, data, collisionHeight); + return m_terrain->GetLiquidStatus(phaseShift, GetId(), x, y, z, ReqLiquidType, data, collisionHeight); } bool Map::GetAreaInfo(PhaseShift const& phaseShift, float x, float y, float z, uint32& mogpflags, int32& adtId, int32& rootId, int32& groupId) { - return m_terrain->GetAreaInfo(phaseShift, x, y, z, mogpflags, adtId, rootId, groupId, &_dynamicTree); + return m_terrain->GetAreaInfo(phaseShift, GetId(), x, y, z, mogpflags, adtId, rootId, groupId, &_dynamicTree); } uint32 Map::GetAreaId(PhaseShift const& phaseShift, float x, float y, float z) { - return m_terrain->GetAreaId(phaseShift, x, y, z, &_dynamicTree); + return m_terrain->GetAreaId(phaseShift, GetId(), x, y, z, &_dynamicTree); } uint32 Map::GetZoneId(PhaseShift const& phaseShift, float x, float y, float z) { - return m_terrain->GetZoneId(phaseShift, x, y, z, &_dynamicTree); + return m_terrain->GetZoneId(phaseShift, GetId(), x, y, z, &_dynamicTree); } void Map::GetZoneAndAreaId(PhaseShift const& phaseShift, uint32& zoneid, uint32& areaid, float x, float y, float z) { - return m_terrain->GetZoneAndAreaId(phaseShift, zoneid, areaid, x, y, z, &_dynamicTree); + return m_terrain->GetZoneAndAreaId(phaseShift, GetId(), zoneid, areaid, x, y, z, &_dynamicTree); } float Map::GetMinHeight(PhaseShift const& phaseShift, float x, float y) { - return m_terrain->GetMinHeight(phaseShift, x, y); + return m_terrain->GetMinHeight(phaseShift, GetId(), x, y); } float Map::GetGridHeight(PhaseShift const& phaseShift, float x, float y) { - return m_terrain->GetGridHeight(phaseShift, x, y); + return m_terrain->GetGridHeight(phaseShift, GetId(), x, y); } float Map::GetStaticHeight(PhaseShift const& phaseShift, float x, float y, float z, bool checkVMap, float maxSearchDist) { - return m_terrain->GetStaticHeight(phaseShift, x, y, z, checkVMap, maxSearchDist); + return m_terrain->GetStaticHeight(phaseShift, GetId(), x, y, z, checkVMap, maxSearchDist); } float Map::GetWaterLevel(PhaseShift const& phaseShift, float x, float y) { - return m_terrain->GetWaterLevel(phaseShift, x, y); + return m_terrain->GetWaterLevel(phaseShift, GetId(), x, y); } bool Map::IsInWater(PhaseShift const& phaseShift, float x, float y, float z, LiquidData* data) { - return m_terrain->IsInWater(phaseShift, x, y, z, data); + return m_terrain->IsInWater(phaseShift, GetId(), x, y, z, data); } bool Map::IsUnderWater(PhaseShift const& phaseShift, float x, float y, float z) { - return m_terrain->IsUnderWater(phaseShift, x, y, z); + return m_terrain->IsUnderWater(phaseShift, GetId(), x, y, z); } float Map::GetWaterOrGroundLevel(PhaseShift const& phaseShift, float x, float y, float z, float* ground, bool swim, float collisionHeight) { - return m_terrain->GetWaterOrGroundLevel(phaseShift, x, y, z, ground, swim, collisionHeight, &_dynamicTree); + return m_terrain->GetWaterOrGroundLevel(phaseShift, GetId(), x, y, z, ground, swim, collisionHeight, &_dynamicTree); } bool Map::isInLineOfSight(PhaseShift const& phaseShift, float x1, float y1, float z1, float x2, float y2, float z2, LineOfSightChecks checks, VMAP::ModelIgnoreFlags ignoreFlags) const { if ((checks & LINEOFSIGHT_CHECK_VMAP) - && !VMAP::VMapFactory::createOrGetVMapManager()->isInLineOfSight(PhasingHandler::GetTerrainMapId(phaseShift, m_terrain.get(), x1, y1), x1, y1, z1, x2, y2, z2, ignoreFlags)) + && !VMAP::VMapFactory::createOrGetVMapManager()->isInLineOfSight(PhasingHandler::GetTerrainMapId(phaseShift, GetId(), m_terrain.get(), x1, y1), x1, y1, z1, x2, y2, z2, ignoreFlags)) return false; if (sWorld->getBoolConfig(CONFIG_CHECK_GOBJECT_LOS) && (checks & LINEOFSIGHT_CHECK_GOBJECT) && !_dynamicTree.isInLineOfSight({ x1, y1, z1 }, { x2, y2, z2 }, phaseShift)) diff --git a/src/server/game/Maps/TerrainMgr.cpp b/src/server/game/Maps/TerrainMgr.cpp index d9a8ba549ff..cbab36ca703 100644 --- a/src/server/game/Maps/TerrainMgr.cpp +++ b/src/server/game/Maps/TerrainMgr.cpp @@ -21,6 +21,7 @@ #include "DynamicTree.h" #include "GridMap.h" #include "Log.h" +#include "Memory.h" #include "MMapFactory.h" #include "PhasingHandler.h" #include "Random.h" @@ -50,29 +51,26 @@ void TerrainInfo::DiscoverGridMapFiles() { std::string tileListName = Trinity::StringFormat("%smaps/%04u.tilelist", sWorld->GetDataPath().c_str(), GetId()); // tile list is optional - if (FILE* tileList = fopen(tileListName.c_str(), "rb")) + if (auto tileList = Trinity::make_unique_ptr_with_deleter(fopen(tileListName.c_str(), "rb"), &::fclose)) { u_map_magic mapMagic = { }; uint32 versionMagic = { }; uint32 build; char tilesData[MAX_NUMBER_OF_GRIDS * MAX_NUMBER_OF_GRIDS] = { }; - if (fread(mapMagic.data(), mapMagic.size(), 1, tileList) == 1 + if (fread(mapMagic.data(), mapMagic.size(), 1, tileList.get()) == 1 && mapMagic == MapMagic - && fread(&versionMagic, sizeof(versionMagic), 1, tileList) == 1 + && fread(&versionMagic, sizeof(versionMagic), 1, tileList.get()) == 1 && versionMagic == MapVersionMagic - && fread(&build, sizeof(build), 1, tileList) == 1 - && fread(&tilesData[0], MAX_NUMBER_OF_GRIDS * MAX_NUMBER_OF_GRIDS, 1, tileList) == 1) + && fread(&build, sizeof(build), 1, tileList.get()) == 1 + && fread(&tilesData[0], MAX_NUMBER_OF_GRIDS * MAX_NUMBER_OF_GRIDS, 1, tileList.get()) == 1) { _gridFileExists = std::bitset<MAX_NUMBER_OF_GRIDS* MAX_NUMBER_OF_GRIDS>(tilesData, std::size(tilesData)); - fclose(tileList); return; } - - fclose(tileList); } - for (uint32 gx = 0; gx < MAX_NUMBER_OF_GRIDS; ++gx) - for (uint32 gy = 0; gy < MAX_NUMBER_OF_GRIDS; ++gy) + for (int32 gx = 0; gx < MAX_NUMBER_OF_GRIDS; ++gx) + for (int32 gy = 0; gy < MAX_NUMBER_OF_GRIDS; ++gy) _gridFileExists[GetBitsetIndex(gx, gy)] = ExistMap(GetId(), gx, gy, false); } @@ -81,7 +79,7 @@ bool TerrainInfo::ExistMap(uint32 mapid, int32 gx, int32 gy, bool log /*= true*/ std::string fileName = Trinity::StringFormat("%smaps/%04u_%02u_%02u.map", sWorld->GetDataPath().c_str(), mapid, gx, gy); bool ret = false; - FILE* file = fopen(fileName.c_str(), "rb"); + auto file = Trinity::make_unique_ptr_with_deleter(fopen(fileName.c_str(), "rb"), &::fclose); if (!file) { if (log) @@ -92,8 +90,8 @@ bool TerrainInfo::ExistMap(uint32 mapid, int32 gx, int32 gy, bool log /*= true*/ } else { - map_fileheader header; - if (fread(&header, sizeof(header), 1, file) == 1) + map_fileheader header{ }; + if (fread(&header, sizeof(header), 1, file.get()) == 1) { if (header.mapMagic != MapMagic || header.versionMagic != MapVersionMagic) { @@ -104,7 +102,6 @@ bool TerrainInfo::ExistMap(uint32 mapid, int32 gx, int32 gy, bool log /*= true*/ else ret = true; } - fclose(file); } return ret; @@ -299,13 +296,13 @@ static bool IsInWMOInterior(uint32 mogpFlags) return (mogpFlags & 0x2000) != 0; } -void TerrainInfo::GetFullTerrainStatusForPosition(PhaseShift const& phaseShift, float x, float y, float z, PositionFullTerrainStatus& data, map_liquidHeaderTypeFlags reqLiquidType, float collisionHeight, DynamicMapTree const* dynamicMapTree) +void TerrainInfo::GetFullTerrainStatusForPosition(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, PositionFullTerrainStatus& data, map_liquidHeaderTypeFlags reqLiquidType, float collisionHeight, DynamicMapTree const* dynamicMapTree) { VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager(); VMAP::AreaAndLiquidData vmapData; VMAP::AreaAndLiquidData dynData; VMAP::AreaAndLiquidData* wmoData = nullptr; - uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, this, x, y); + uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, mapId, this, x, y); GridMap* gmap = GetGrid(terrainMapId, x, y); vmgr->getAreaAndLiquidData(terrainMapId, x, y, z, AsUnderlyingType(reqLiquidType), vmapData); if (dynamicMapTree) @@ -443,7 +440,7 @@ void TerrainInfo::GetFullTerrainStatusForPosition(PhaseShift const& phaseShift, } } -ZLiquidStatus TerrainInfo::GetLiquidStatus(PhaseShift const& phaseShift, float x, float y, float z, map_liquidHeaderTypeFlags ReqLiquidType, LiquidData* data, float collisionHeight) +ZLiquidStatus TerrainInfo::GetLiquidStatus(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, map_liquidHeaderTypeFlags ReqLiquidType, LiquidData* data, float collisionHeight) { ZLiquidStatus result = LIQUID_MAP_NO_WATER; VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager(); @@ -452,7 +449,7 @@ ZLiquidStatus TerrainInfo::GetLiquidStatus(PhaseShift const& phaseShift, float x uint32 liquid_type = 0; uint32 mogpFlags = 0; bool useGridLiquid = true; - uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, this, x, y); + uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, mapId, this, x, y); if (vmgr->GetLiquidLevel(terrainMapId, x, y, z, AsUnderlyingType(ReqLiquidType), liquid_level, ground_level, liquid_type, mogpFlags)) { useGridLiquid = !IsInWMOInterior(mogpFlags); @@ -473,7 +470,7 @@ ZLiquidStatus TerrainInfo::GetLiquidStatus(PhaseShift const& phaseShift, float x if (liquid_type && liquid_type < 21) { - if (AreaTableEntry const* area = sAreaTableStore.LookupEntry(GetAreaId(phaseShift, x, y, z))) + if (AreaTableEntry const* area = sAreaTableStore.LookupEntry(GetAreaId(phaseShift, mapId, x, y, z))) { uint32 overrideLiquid = area->LiquidTypeID[liquidFlagType]; if (!overrideLiquid && area->ParentAreaID) @@ -535,12 +532,12 @@ ZLiquidStatus TerrainInfo::GetLiquidStatus(PhaseShift const& phaseShift, float x return result; } -bool TerrainInfo::GetAreaInfo(PhaseShift const& phaseShift, float x, float y, float z, uint32& mogpflags, int32& adtId, int32& rootId, int32& groupId, DynamicMapTree const* dynamicMapTree) +bool TerrainInfo::GetAreaInfo(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, uint32& mogpflags, int32& adtId, int32& rootId, int32& groupId, DynamicMapTree const* dynamicMapTree) { float vmap_z = z; float dynamic_z = z; float check_z = z; - uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, this, x, y); + uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, mapId, this, x, y); VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager(); uint32 vflags; int32 vadtId; @@ -583,16 +580,16 @@ bool TerrainInfo::GetAreaInfo(PhaseShift const& phaseShift, float x, float y, fl return false; } -uint32 TerrainInfo::GetAreaId(PhaseShift const& phaseShift, float x, float y, float z, DynamicMapTree const* dynamicMapTree) +uint32 TerrainInfo::GetAreaId(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, DynamicMapTree const* dynamicMapTree) { uint32 mogpFlags; int32 adtId, rootId, groupId; float vmapZ = z; - bool hasVmapArea = GetAreaInfo(phaseShift, x, y, vmapZ, mogpFlags, adtId, rootId, groupId, dynamicMapTree); + bool hasVmapArea = GetAreaInfo(phaseShift, mapId, x, y, vmapZ, mogpFlags, adtId, rootId, groupId, dynamicMapTree); uint32 gridAreaId = 0; float gridMapHeight = INVALID_HEIGHT; - if (GridMap* gmap = GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, this, x, y), x, y)) + if (GridMap* gmap = GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, mapId, this, x, y), x, y)) { gridAreaId = gmap->getArea(x, y); gridMapHeight = gmap->getHeight(x, y); @@ -619,9 +616,9 @@ uint32 TerrainInfo::GetAreaId(PhaseShift const& phaseShift, float x, float y, fl return areaId; } -uint32 TerrainInfo::GetZoneId(PhaseShift const& phaseShift, float x, float y, float z, DynamicMapTree const* dynamicMapTree) +uint32 TerrainInfo::GetZoneId(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, DynamicMapTree const* dynamicMapTree) { - uint32 areaId = GetAreaId(phaseShift, x, y, z, dynamicMapTree); + uint32 areaId = GetAreaId(phaseShift, mapId, x, y, z, dynamicMapTree); if (AreaTableEntry const* area = sAreaTableStore.LookupEntry(areaId)) if (area->ParentAreaID) return area->ParentAreaID; @@ -629,36 +626,36 @@ uint32 TerrainInfo::GetZoneId(PhaseShift const& phaseShift, float x, float y, fl return areaId; } -void TerrainInfo::GetZoneAndAreaId(PhaseShift const& phaseShift, uint32& zoneid, uint32& areaid, float x, float y, float z, DynamicMapTree const* dynamicMapTree) +void TerrainInfo::GetZoneAndAreaId(PhaseShift const& phaseShift, uint32 mapId, uint32& zoneid, uint32& areaid, float x, float y, float z, DynamicMapTree const* dynamicMapTree) { - areaid = zoneid = GetAreaId(phaseShift, x, y, z, dynamicMapTree); + areaid = zoneid = GetAreaId(phaseShift, mapId, x, y, z, dynamicMapTree); if (AreaTableEntry const* area = sAreaTableStore.LookupEntry(areaid)) if (area->ParentAreaID) zoneid = area->ParentAreaID; } -float TerrainInfo::GetMinHeight(PhaseShift const& phaseShift, float x, float y) +float TerrainInfo::GetMinHeight(PhaseShift const& phaseShift, uint32 mapId, float x, float y) { - if (GridMap const* grid = GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, this, x, y), x, y)) + if (GridMap const* grid = GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, mapId, this, x, y), x, y)) return grid->getMinHeight(x, y); return -500.0f; } -float TerrainInfo::GetGridHeight(PhaseShift const& phaseShift, float x, float y) +float TerrainInfo::GetGridHeight(PhaseShift const& phaseShift, uint32 mapId, float x, float y) { - if (GridMap* gmap = GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, this, x, y), x, y)) + if (GridMap* gmap = GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, mapId, this, x, y), x, y)) return gmap->getHeight(x, y); return VMAP_INVALID_HEIGHT_VALUE; } -float TerrainInfo::GetStaticHeight(PhaseShift const& phaseShift, float x, float y, float z, bool checkVMap /*= true*/, float maxSearchDist /*= DEFAULT_HEIGHT_SEARCH*/) +float TerrainInfo::GetStaticHeight(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, bool checkVMap /*= true*/, float maxSearchDist /*= DEFAULT_HEIGHT_SEARCH*/) { // find raw .map surface under Z coordinates float mapHeight = VMAP_INVALID_HEIGHT_VALUE; - uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, this, x, y); - float gridHeight = GetGridHeight(phaseShift, x, y); + uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, mapId, this, x, y); + float gridHeight = GetGridHeight(phaseShift, mapId, x, y); if (G3D::fuzzyGe(z, gridHeight - GROUND_HEIGHT_TOLERANCE)) mapHeight = gridHeight; @@ -692,32 +689,32 @@ float TerrainInfo::GetStaticHeight(PhaseShift const& phaseShift, float x, float return mapHeight; // explicitly use map data } -float TerrainInfo::GetWaterLevel(PhaseShift const& phaseShift, float x, float y) +float TerrainInfo::GetWaterLevel(PhaseShift const& phaseShift, uint32 mapId, float x, float y) { - if (GridMap* gmap = GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, this, x, y), x, y)) + if (GridMap* gmap = GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, mapId, this, x, y), x, y)) return gmap->getLiquidLevel(x, y); - else - return 0; + + return 0; } -bool TerrainInfo::IsInWater(PhaseShift const& phaseShift, float x, float y, float pZ, LiquidData* data) +bool TerrainInfo::IsInWater(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float pZ, LiquidData* data) { LiquidData liquid_status; LiquidData* liquid_ptr = data ? data : &liquid_status; - return (GetLiquidStatus(phaseShift, x, y, pZ, map_liquidHeaderTypeFlags::AllLiquids, liquid_ptr) & (LIQUID_MAP_IN_WATER | LIQUID_MAP_UNDER_WATER)) != 0; + return (GetLiquidStatus(phaseShift, mapId, x, y, pZ, map_liquidHeaderTypeFlags::AllLiquids, liquid_ptr) & (LIQUID_MAP_IN_WATER | LIQUID_MAP_UNDER_WATER)) != 0; } -bool TerrainInfo::IsUnderWater(PhaseShift const& phaseShift, float x, float y, float z) +bool TerrainInfo::IsUnderWater(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z) { - return (GetLiquidStatus(phaseShift, x, y, z, map_liquidHeaderTypeFlags::Water | map_liquidHeaderTypeFlags::Ocean) & LIQUID_MAP_UNDER_WATER) != 0; + return (GetLiquidStatus(phaseShift, mapId, x, y, z, map_liquidHeaderTypeFlags::Water | map_liquidHeaderTypeFlags::Ocean) & LIQUID_MAP_UNDER_WATER) != 0; } -float TerrainInfo::GetWaterOrGroundLevel(PhaseShift const& phaseShift, float x, float y, float z, float* ground /*= nullptr*/, bool /*swim = false*/, float collisionHeight /*= DEFAULT_COLLISION_HEIGHT*/, DynamicMapTree const* dynamicMapTree /*= nullptr*/) +float TerrainInfo::GetWaterOrGroundLevel(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, float* ground /*= nullptr*/, bool /*swim = false*/, float collisionHeight /*= DEFAULT_COLLISION_HEIGHT*/, DynamicMapTree const* dynamicMapTree /*= nullptr*/) { - if (GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, this, x, y), x, y)) + if (GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, mapId, this, x, y), x, y)) { // we need ground level (including grid height version) for proper return water level in point - float ground_z = GetStaticHeight(phaseShift, x, y, z + Z_OFFSET_FIND_HEIGHT, true, 50.0f); + float ground_z = GetStaticHeight(phaseShift, mapId, x, y, z + Z_OFFSET_FIND_HEIGHT, true, 50.0f); if (dynamicMapTree) ground_z = std::max(ground_z, dynamicMapTree->getHeight(x, y, z + Z_OFFSET_FIND_HEIGHT, 50.0f, phaseShift)); @@ -726,7 +723,7 @@ float TerrainInfo::GetWaterOrGroundLevel(PhaseShift const& phaseShift, float x, LiquidData liquid_status; - ZLiquidStatus res = GetLiquidStatus(phaseShift, x, y, ground_z, map_liquidHeaderTypeFlags::AllLiquids, &liquid_status, collisionHeight); + ZLiquidStatus res = GetLiquidStatus(phaseShift, mapId, x, y, ground_z, map_liquidHeaderTypeFlags::AllLiquids, &liquid_status, collisionHeight); switch (res) { case LIQUID_MAP_ABOVE_WATER: @@ -741,13 +738,9 @@ float TerrainInfo::GetWaterOrGroundLevel(PhaseShift const& phaseShift, float x, return VMAP_INVALID_HEIGHT_VALUE; } -TerrainMgr::TerrainMgr() -{ -} +TerrainMgr::TerrainMgr() = default; -TerrainMgr::~TerrainMgr() -{ -} +TerrainMgr::~TerrainMgr() = default; TerrainMgr& TerrainMgr::Instance() { @@ -802,21 +795,21 @@ void TerrainMgr::Update(uint32 diff) uint32 TerrainMgr::GetAreaId(PhaseShift const& phaseShift, uint32 mapid, float x, float y, float z) { if (std::shared_ptr<TerrainInfo> t = LoadTerrain(mapid)) - return t->GetAreaId(phaseShift, x, y, z); + return t->GetAreaId(phaseShift, mapid, x, y, z); return 0; } uint32 TerrainMgr::GetZoneId(PhaseShift const& phaseShift, uint32 mapid, float x, float y, float z) { if (std::shared_ptr<TerrainInfo> t = LoadTerrain(mapid)) - return t->GetZoneId(phaseShift, x, y, z); + return t->GetZoneId(phaseShift, mapid, x, y, z); return 0; } void TerrainMgr::GetZoneAndAreaId(PhaseShift const& phaseShift, uint32& zoneid, uint32& areaid, uint32 mapid, float x, float y, float z) { if (std::shared_ptr<TerrainInfo> t = LoadTerrain(mapid)) - t->GetZoneAndAreaId(phaseShift, zoneid, areaid, x, y, z); + t->GetZoneAndAreaId(phaseShift, mapid, zoneid, areaid, x, y, z); } std::shared_ptr<TerrainInfo> TerrainMgr::LoadTerrainImpl(uint32 mapId) diff --git a/src/server/game/Maps/TerrainMgr.h b/src/server/game/Maps/TerrainMgr.h index 54b9192109b..638319d7f1d 100644 --- a/src/server/game/Maps/TerrainMgr.h +++ b/src/server/game/Maps/TerrainMgr.h @@ -74,27 +74,27 @@ private: public: void CleanUpGrids(uint32 diff); - void GetFullTerrainStatusForPosition(PhaseShift const& phaseShift, float x, float y, float z, PositionFullTerrainStatus& data, map_liquidHeaderTypeFlags reqLiquidType = map_liquidHeaderTypeFlags::AllLiquids, float collisionHeight = 2.03128f, DynamicMapTree const* dynamicMapTree = nullptr); // DEFAULT_COLLISION_HEIGHT in Object.h - ZLiquidStatus GetLiquidStatus(PhaseShift const& phaseShift, float x, float y, float z, map_liquidHeaderTypeFlags ReqLiquidType, LiquidData* data = nullptr, float collisionHeight = 2.03128f); // DEFAULT_COLLISION_HEIGHT in Object.h - - bool GetAreaInfo(PhaseShift const& phaseShift, float x, float y, float z, uint32& mogpflags, int32& adtId, int32& rootId, int32& groupId, DynamicMapTree const* dynamicMapTree = nullptr); - uint32 GetAreaId(PhaseShift const& phaseShift, float x, float y, float z, DynamicMapTree const* dynamicMapTree = nullptr); - uint32 GetAreaId(PhaseShift const& phaseShift, Position const& pos, DynamicMapTree const* dynamicMapTree = nullptr) { return GetAreaId(phaseShift, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), dynamicMapTree); } - uint32 GetZoneId(PhaseShift const& phaseShift, float x, float y, float z, DynamicMapTree const* dynamicMapTree = nullptr); - uint32 GetZoneId(PhaseShift const& phaseShift, Position const& pos, DynamicMapTree const* dynamicMapTree = nullptr) { return GetZoneId(phaseShift, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), dynamicMapTree); } - void GetZoneAndAreaId(PhaseShift const& phaseShift, uint32& zoneid, uint32& areaid, float x, float y, float z, DynamicMapTree const* dynamicMapTree = nullptr); - void GetZoneAndAreaId(PhaseShift const& phaseShift, uint32& zoneid, uint32& areaid, Position const& pos, DynamicMapTree const* dynamicMapTree = nullptr) { GetZoneAndAreaId(phaseShift, zoneid, areaid, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), dynamicMapTree); } - - float GetMinHeight(PhaseShift const& phaseShift, float x, float y); - float GetGridHeight(PhaseShift const& phaseShift, float x, float y); - float GetStaticHeight(PhaseShift const& phaseShift, float x, float y, float z, bool checkVMap = true, float maxSearchDist = DEFAULT_HEIGHT_SEARCH); - float GetStaticHeight(PhaseShift const& phaseShift, Position const& pos, bool checkVMap = true, float maxSearchDist = DEFAULT_HEIGHT_SEARCH) { return GetStaticHeight(phaseShift, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), checkVMap, maxSearchDist); } - - float GetWaterLevel(PhaseShift const& phaseShift, float x, float y); - bool IsInWater(PhaseShift const& phaseShift, float x, float y, float z, LiquidData* data = nullptr); - bool IsUnderWater(PhaseShift const& phaseShift, float x, float y, float z); - - float GetWaterOrGroundLevel(PhaseShift const& phaseShift, float x, float y, float z, float* ground = nullptr, bool swim = false, float collisionHeight = 2.03128f, DynamicMapTree const* dynamicMapTree = nullptr); // DEFAULT_COLLISION_HEIGHT in Object.h + void GetFullTerrainStatusForPosition(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, PositionFullTerrainStatus& data, map_liquidHeaderTypeFlags reqLiquidType = map_liquidHeaderTypeFlags::AllLiquids, float collisionHeight = 2.03128f, DynamicMapTree const* dynamicMapTree = nullptr); // DEFAULT_COLLISION_HEIGHT in Object.h + ZLiquidStatus GetLiquidStatus(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, map_liquidHeaderTypeFlags ReqLiquidType, LiquidData* data = nullptr, float collisionHeight = 2.03128f); // DEFAULT_COLLISION_HEIGHT in Object.h + + bool GetAreaInfo(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, uint32& mogpflags, int32& adtId, int32& rootId, int32& groupId, DynamicMapTree const* dynamicMapTree = nullptr); + uint32 GetAreaId(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, DynamicMapTree const* dynamicMapTree = nullptr); + uint32 GetAreaId(PhaseShift const& phaseShift, uint32 mapId, Position const& pos, DynamicMapTree const* dynamicMapTree = nullptr) { return GetAreaId(phaseShift, mapId, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), dynamicMapTree); } + uint32 GetZoneId(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, DynamicMapTree const* dynamicMapTree = nullptr); + uint32 GetZoneId(PhaseShift const& phaseShift, uint32 mapId, Position const& pos, DynamicMapTree const* dynamicMapTree = nullptr) { return GetZoneId(phaseShift, mapId, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), dynamicMapTree); } + void GetZoneAndAreaId(PhaseShift const& phaseShift, uint32 mapId, uint32& zoneid, uint32& areaid, float x, float y, float z, DynamicMapTree const* dynamicMapTree = nullptr); + void GetZoneAndAreaId(PhaseShift const& phaseShift, uint32 mapId, uint32& zoneid, uint32& areaid, Position const& pos, DynamicMapTree const* dynamicMapTree = nullptr) { GetZoneAndAreaId(phaseShift, mapId, zoneid, areaid, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), dynamicMapTree); } + + float GetMinHeight(PhaseShift const& phaseShift, uint32 mapId, float x, float y); + float GetGridHeight(PhaseShift const& phaseShift, uint32 mapId, float x, float y); + float GetStaticHeight(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, bool checkVMap = true, float maxSearchDist = DEFAULT_HEIGHT_SEARCH); + float GetStaticHeight(PhaseShift const& phaseShift, uint32 mapId, Position const& pos, bool checkVMap = true, float maxSearchDist = DEFAULT_HEIGHT_SEARCH) { return GetStaticHeight(phaseShift, mapId, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), checkVMap, maxSearchDist); } + + float GetWaterLevel(PhaseShift const& phaseShift, uint32 mapId, float x, float y); + bool IsInWater(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, LiquidData* data = nullptr); + bool IsUnderWater(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z); + + float GetWaterOrGroundLevel(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, float* ground = nullptr, bool swim = false, float collisionHeight = 2.03128f, DynamicMapTree const* dynamicMapTree = nullptr); // DEFAULT_COLLISION_HEIGHT in Object.h private: static constexpr int32 GetBitsetIndex(int32 gx, int32 gy) { return gx * MAX_NUMBER_OF_GRIDS + gy; } diff --git a/src/server/game/Movement/PathGenerator.cpp b/src/server/game/Movement/PathGenerator.cpp index 9214b7ea2cd..c101b32c3a7 100644 --- a/src/server/game/Movement/PathGenerator.cpp +++ b/src/server/game/Movement/PathGenerator.cpp @@ -38,7 +38,7 @@ PathGenerator::PathGenerator(WorldObject const* owner) : TC_LOG_DEBUG("maps.mmaps", "++ PathGenerator::PathGenerator for %s", _source->GetGUID().ToString().c_str()); - uint32 mapId = PhasingHandler::GetTerrainMapId(_source->GetPhaseShift(), _source->GetMap()->GetTerrain(), _source->GetPositionX(), _source->GetPositionY()); + uint32 mapId = PhasingHandler::GetTerrainMapId(_source->GetPhaseShift(), _source->GetMapId(), _source->GetMap()->GetTerrain(), _source->GetPositionX(), _source->GetPositionY()); if (DisableMgr::IsPathfindingEnabled(_source->GetMapId())) { MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager(); diff --git a/src/server/game/Phasing/PhasingHandler.cpp b/src/server/game/Phasing/PhasingHandler.cpp index 01f996a5a11..ad2395fcb21 100644 --- a/src/server/game/Phasing/PhasingHandler.cpp +++ b/src/server/game/Phasing/PhasingHandler.cpp @@ -574,10 +574,10 @@ bool PhasingHandler::InDbPhaseShift(WorldObject const* object, uint8 phaseUseFla return object->GetPhaseShift().CanSee(phaseShift); } -uint32 PhasingHandler::GetTerrainMapId(PhaseShift const& phaseShift, TerrainInfo const* terrain, float x, float y) +uint32 PhasingHandler::GetTerrainMapId(PhaseShift const& phaseShift, uint32 mapId, TerrainInfo const* terrain, float x, float y) { if (phaseShift.VisibleMapIds.empty()) - return terrain->GetId(); + return mapId; if (phaseShift.VisibleMapIds.size() == 1) return phaseShift.VisibleMapIds.begin()->first; @@ -590,7 +590,7 @@ uint32 PhasingHandler::GetTerrainMapId(PhaseShift const& phaseShift, TerrainInfo if (terrain->HasChildTerrainGridFile(visibleMap.first, gx, gy)) return visibleMap.first; - return terrain->GetId(); + return mapId; } void PhasingHandler::SetAlwaysVisible(WorldObject* object, bool apply, bool updateVisibility) diff --git a/src/server/game/Phasing/PhasingHandler.h b/src/server/game/Phasing/PhasingHandler.h index 779cae19821..6da249558a7 100644 --- a/src/server/game/Phasing/PhasingHandler.h +++ b/src/server/game/Phasing/PhasingHandler.h @@ -65,7 +65,7 @@ public: static void InitDbVisibleMapId(PhaseShift& phaseShift, int32 visibleMapId); static bool InDbPhaseShift(WorldObject const* object, uint8 phaseUseFlags, uint16 phaseId, uint32 phaseGroupId); - static uint32 GetTerrainMapId(PhaseShift const& phaseShift, TerrainInfo const* terrain, float x, float y); + static uint32 GetTerrainMapId(PhaseShift const& phaseShift, uint32 mapId, TerrainInfo const* terrain, float x, float y); static void SetAlwaysVisible(WorldObject* object, bool apply, bool updateVisibility); static void SetInversed(WorldObject* object, bool apply, bool updateVisibility); diff --git a/src/server/scripts/Commands/cs_go.cpp b/src/server/scripts/Commands/cs_go.cpp index f41ce09aa2a..fc78d8dc93d 100644 --- a/src/server/scripts/Commands/cs_go.cpp +++ b/src/server/scripts/Commands/cs_go.cpp @@ -232,7 +232,7 @@ public: player->SaveRecallPosition(); // save only in non-flight case std::shared_ptr<TerrainInfo> terrain = sTerrainMgr.LoadTerrain(mapId); - float z = std::max(terrain->GetStaticHeight(PhasingHandler::GetEmptyPhaseShift(), x, y, MAX_HEIGHT), terrain->GetWaterLevel(PhasingHandler::GetEmptyPhaseShift(), x, y)); + float z = std::max(terrain->GetStaticHeight(PhasingHandler::GetEmptyPhaseShift(), mapId, x, y, MAX_HEIGHT), terrain->GetWaterLevel(PhasingHandler::GetEmptyPhaseShift(), mapId, x, y)); player->TeleportTo(mapId, x, y, z, player->GetOrientation()); return true; @@ -291,7 +291,7 @@ public: player->SaveRecallPosition(); // save only in non-flight case std::shared_ptr<TerrainInfo> terrain = sTerrainMgr.LoadTerrain(mapId); - z = std::max(terrain->GetStaticHeight(PhasingHandler::GetEmptyPhaseShift(), x, y, MAX_HEIGHT), terrain->GetWaterLevel(PhasingHandler::GetEmptyPhaseShift(), x, y)); + z = std::max(terrain->GetStaticHeight(PhasingHandler::GetEmptyPhaseShift(), mapId, x, y, MAX_HEIGHT), terrain->GetWaterLevel(PhasingHandler::GetEmptyPhaseShift(), mapId, x, y)); player->TeleportTo(mapId, x, y, z, 0.0f); return true; @@ -365,7 +365,7 @@ public: else player->SaveRecallPosition(); // save only in non-flight case - float z = std::max(terrain->GetStaticHeight(PhasingHandler::GetEmptyPhaseShift(), x, y, MAX_HEIGHT), terrain->GetWaterLevel(PhasingHandler::GetEmptyPhaseShift(), x, y)); + float z = std::max(terrain->GetStaticHeight(PhasingHandler::GetEmptyPhaseShift(), zoneEntry->ContinentID, x, y, MAX_HEIGHT), terrain->GetWaterLevel(PhasingHandler::GetEmptyPhaseShift(), zoneEntry->ContinentID, x, y)); player->TeleportTo(zoneEntry->ContinentID, x, y, z, player->GetOrientation()); return true; @@ -394,7 +394,7 @@ public: return false; } std::shared_ptr<TerrainInfo> terrain = sTerrainMgr.LoadTerrain(mapId); - z = std::max(terrain->GetStaticHeight(PhasingHandler::GetEmptyPhaseShift(), x, y, MAX_HEIGHT), terrain->GetWaterLevel(PhasingHandler::GetEmptyPhaseShift(), x, y)); + z = std::max(terrain->GetStaticHeight(PhasingHandler::GetEmptyPhaseShift(), mapId, x, y, MAX_HEIGHT), terrain->GetWaterLevel(PhasingHandler::GetEmptyPhaseShift(), mapId, x, y)); } return DoTeleport(handler, { x, y, *z, o.value_or(0.0f) }, mapId); diff --git a/src/server/scripts/Commands/cs_mmaps.cpp b/src/server/scripts/Commands/cs_mmaps.cpp index ad43389593e..0477a2d1e54 100644 --- a/src/server/scripts/Commands/cs_mmaps.cpp +++ b/src/server/scripts/Commands/cs_mmaps.cpp @@ -142,7 +142,7 @@ public: handler->PSendSysMessage("tileloc [%i, %i]", gy, gx); // calculate navmesh tile location - uint32 terrainMapId = PhasingHandler::GetTerrainMapId(player->GetPhaseShift(), player->GetMap()->GetTerrain(), x, y); + uint32 terrainMapId = PhasingHandler::GetTerrainMapId(player->GetPhaseShift(), player->GetMapId(), player->GetMap()->GetTerrain(), x, y); dtNavMesh const* navmesh = MMAP::MMapFactory::createOrGetMMapManager()->GetNavMesh(terrainMapId); dtNavMeshQuery const* navmeshquery = MMAP::MMapFactory::createOrGetMMapManager()->GetNavMeshQuery(terrainMapId, player->GetInstanceId()); if (!navmesh || !navmeshquery) @@ -193,7 +193,7 @@ public: static bool HandleMmapLoadedTilesCommand(ChatHandler* handler, char const* /*args*/) { Player* player = handler->GetSession()->GetPlayer(); - uint32 terrainMapId = PhasingHandler::GetTerrainMapId(player->GetPhaseShift(), player->GetMap()->GetTerrain(), player->GetPositionX(), player->GetPositionY()); + uint32 terrainMapId = PhasingHandler::GetTerrainMapId(player->GetPhaseShift(), player->GetMapId(), player->GetMap()->GetTerrain(), player->GetPositionX(), player->GetPositionY()); dtNavMesh const* navmesh = MMAP::MMapFactory::createOrGetMMapManager()->GetNavMesh(terrainMapId); dtNavMeshQuery const* navmeshquery = MMAP::MMapFactory::createOrGetMMapManager()->GetNavMeshQuery(terrainMapId, player->GetInstanceId()); if (!navmesh || !navmeshquery) @@ -219,7 +219,7 @@ public: static bool HandleMmapStatsCommand(ChatHandler* handler, char const* /*args*/) { Player* player = handler->GetSession()->GetPlayer(); - uint32 terrainMapId = PhasingHandler::GetTerrainMapId(player->GetPhaseShift(), player->GetMap()->GetTerrain(), player->GetPositionX(), player->GetPositionY()); + uint32 terrainMapId = PhasingHandler::GetTerrainMapId(player->GetPhaseShift(), player->GetMapId(), player->GetMap()->GetTerrain(), player->GetPositionX(), player->GetPositionY()); handler->PSendSysMessage("mmap stats:"); handler->PSendSysMessage(" global mmap pathfinding is %sabled", DisableMgr::IsPathfindingEnabled(player->GetMapId()) ? "en" : "dis"); |