aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2018-03-03 15:39:19 +0100
committerShauren <shauren.trinity@gmail.com>2018-03-25 19:28:36 +0300
commit8f53ba385474e51b4e2ebf29e33d7661a2848669 (patch)
tree2c3a2ee08d085b096996fdfd349097b151e783f6 /src/server
parent3743d042017d72435d2ff8135f66808988beaf9e (diff)
Core/Phasing: Rewrite GetTerrainMapId
Diffstat (limited to 'src/server')
-rw-r--r--src/server/game/Entities/Object/Object.cpp3
-rw-r--r--src/server/game/Maps/Map.cpp22
-rw-r--r--src/server/game/Maps/Map.h3
-rw-r--r--src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp9
-rw-r--r--src/server/game/Movement/PathGenerator.cpp13
-rw-r--r--src/server/game/Phasing/PhaseShift.cpp29
-rw-r--r--src/server/game/Phasing/PhaseShift.h1
-rw-r--r--src/server/game/Phasing/PhasingHandler.cpp26
-rw-r--r--src/server/game/Phasing/PhasingHandler.h3
9 files changed, 57 insertions, 52 deletions
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp
index 7d27d573cac..5745b9ab5db 100644
--- a/src/server/game/Entities/Object/Object.cpp
+++ b/src/server/game/Entities/Object/Object.cpp
@@ -2822,7 +2822,8 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float
}
destz = NormalizeZforCollision(this, destx, desty, pos.GetPositionZ());
- bool col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(GetPhaseShift().GetTerrainMapId(GetMapId(), pos.m_positionX, pos.m_positionY), pos.m_positionX, pos.m_positionY, pos.m_positionZ + 0.5f, destx, desty, destz + 0.5f, destx, desty, destz, -0.5f);
+ bool col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(PhasingHandler::GetTerrainMapId(GetPhaseShift(), GetMap(), pos.m_positionX, pos.m_positionY),
+ pos.m_positionX, pos.m_positionY, pos.m_positionZ + 0.5f, destx, desty, destz + 0.5f, destx, desty, destz, -0.5f);
// collision occured
if (col)
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index 0e161abdf98..0872ace1ac5 100644
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -2550,13 +2550,19 @@ GridMap* Map::GetGrid(uint32 mapId, float x, float y)
EnsureGridCreated(GridCoord((MAX_NUMBER_OF_GRIDS - 1) - gx, (MAX_NUMBER_OF_GRIDS - 1) - gy));
GridMap* grid = GridMaps[gx][gy];
- auto childMapItr = std::find_if(m_childTerrainMaps->begin(), m_childTerrainMaps->end(), [mapId](Map* childTerrainMap) {return childTerrainMap->GetId() == mapId; });
+ auto childMapItr = std::find_if(m_childTerrainMaps->begin(), m_childTerrainMaps->end(), [mapId](Map* childTerrainMap) { return childTerrainMap->GetId() == mapId; });
if (childMapItr != m_childTerrainMaps->end() && (*childMapItr)->GridMaps[gx][gy]->fileExists())
grid = (*childMapItr)->GridMaps[gx][gy];
return grid;
}
+bool Map::HasGrid(uint32 mapId, int32 gx, int32 gy) const
+{
+ auto childMapItr = std::find_if(m_childTerrainMaps->begin(), m_childTerrainMaps->end(), [mapId](Map* childTerrainMap) { return childTerrainMap->GetId() == mapId; });
+ return childMapItr != m_childTerrainMaps->end() && (*childMapItr)->GridMaps[gx][gy] && (*childMapItr)->GridMaps[gx][gy]->fileExists();
+}
+
float Map::GetWaterOrGroundLevel(PhaseShift const& phaseShift, float x, float y, float z, float* ground /*= nullptr*/, bool /*swim = false*/) const
{
if (const_cast<Map*>(this)->GetGrid(x, y))
@@ -2579,7 +2585,7 @@ float Map::GetStaticHeight(PhaseShift const& phaseShift, float x, float y, float
{
// find raw .map surface under Z coordinates
float mapHeight = VMAP_INVALID_HEIGHT_VALUE;
- uint32 terrainMapId = phaseShift.GetTerrainMapId(GetId(), x, y);
+ uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, this, x, y);
if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(terrainMapId, x, y))
{
float gridHeight = gmap->getHeight(x, y);
@@ -2672,7 +2678,7 @@ bool Map::IsOutdoors(PhaseShift const& phaseShift, float x, float y, float z) co
bool Map::GetAreaInfo(PhaseShift const& phaseShift, float x, float y, float z, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const
{
float vmap_z = z;
- uint32 terrainMapId = phaseShift.GetTerrainMapId(GetId(), x, y);
+ uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, this, x, y);
VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager();
if (vmgr->getAreaInfo(terrainMapId, x, y, vmap_z, flags, adtId, rootId, groupId))
{
@@ -2711,7 +2717,7 @@ uint32 Map::GetAreaId(PhaseShift const& phaseShift, float x, float y, float z, b
if (!areaId)
{
- if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(phaseShift.GetTerrainMapId(GetId(), x, y), x, y))
+ if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, this, x, y), x, y))
areaId = gmap->getArea(x, y);
// this used while not all *.map files generated (instances)
@@ -2754,7 +2760,7 @@ void Map::GetZoneAndAreaId(PhaseShift const& phaseShift, uint32& zoneid, uint32&
uint8 Map::GetTerrainType(PhaseShift const& phaseShift, float x, float y) const
{
- if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(phaseShift.GetTerrainMapId(GetId(), x, y), x, y))
+ if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, this, x, y), x, y))
return gmap->getTerrainType(x, y);
else
return 0;
@@ -2767,7 +2773,7 @@ ZLiquidStatus Map::getLiquidStatus(PhaseShift const& phaseShift, float x, float
float liquid_level = INVALID_HEIGHT;
float ground_level = INVALID_HEIGHT;
uint32 liquid_type = 0;
- uint32 terrainMapId = phaseShift.GetTerrainMapId(GetId(), x, y);
+ uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, this, x, y);
if (vmgr->GetLiquidLevel(terrainMapId, x, y, z, ReqLiquidType, liquid_level, ground_level, liquid_type))
{
TC_LOG_DEBUG("maps", "getLiquidStatus(): vmap liquid level: %f ground: %f type: %u", liquid_level, ground_level, liquid_type);
@@ -2848,7 +2854,7 @@ ZLiquidStatus Map::getLiquidStatus(PhaseShift const& phaseShift, float x, float
float Map::GetWaterLevel(PhaseShift const& phaseShift, float x, float y) const
{
- if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(phaseShift.GetTerrainMapId(GetId(), x, y), x, y))
+ if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(PhasingHandler::GetTerrainMapId(phaseShift, this, x, y), x, y))
return gmap->getLiquidLevel(x, y);
else
return 0;
@@ -2856,7 +2862,7 @@ float Map::GetWaterLevel(PhaseShift const& phaseShift, float x, float y) const
bool Map::isInLineOfSight(PhaseShift const& phaseShift, float x1, float y1, float z1, float x2, float y2, float z2) const
{
- return VMAP::VMapFactory::createOrGetVMapManager()->isInLineOfSight(phaseShift.GetTerrainMapId(GetId(), x1, x2), x1, y1, z1, x2, y2, z2)
+ return VMAP::VMapFactory::createOrGetVMapManager()->isInLineOfSight(PhasingHandler::GetTerrainMapId(phaseShift, this, x1, y1), x1, y1, z1, x2, y2, z2)
&& _dynamicTree.isInLineOfSight({ x1, y1, z1 }, { x2, y2, z2 }, phaseShift);
}
diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h
index b2a0cb91551..5a256482d71 100644
--- a/src/server/game/Maps/Map.h
+++ b/src/server/game/Maps/Map.h
@@ -324,6 +324,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
time_t GetGridExpiry() const { return i_gridExpiry; }
+ bool HasGrid(uint32 mapId, int32 gx, int32 gy) const;
static bool ExistMap(uint32 mapid, int gx, int gy);
static bool ExistVMap(uint32 mapid, int gx, int gy);
@@ -631,8 +632,6 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
void setNGrid(NGridType* grid, uint32 x, uint32 y);
void ScriptsProcess();
- void UpdateActiveCells(const float &x, const float &y, const uint32 t_diff);
-
void SendObjectUpdates();
protected:
diff --git a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp
index 210de91f8b0..c4cd065ccbf 100644
--- a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp
+++ b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp
@@ -23,6 +23,7 @@
#include "ObjectAccessor.h"
#include "MoveSplineInit.h"
#include "MoveSpline.h"
+#include "PhasingHandler.h"
#include "Player.h"
#include "VMapFactory.h"
@@ -51,11 +52,9 @@ void FleeingMovementGenerator<T>::_setTargetLocation(T* owner)
// Add LOS check for target point
Position mypos = owner->GetPosition();
- bool isInLOS = VMAP::VMapFactory::createOrGetVMapManager()->isInLineOfSight(owner->GetPhaseShift().GetTerrainMapId(owner->GetMapId(), mypos.m_positionX, mypos.m_positionY),
- mypos.m_positionX,
- mypos.m_positionY,
- mypos.m_positionZ + 2.0f,
- x, y, z + 2.0f);
+ bool isInLOS = VMAP::VMapFactory::createOrGetVMapManager()->isInLineOfSight(
+ PhasingHandler::GetTerrainMapId(owner->GetPhaseShift(), owner->GetMap(), mypos.m_positionX, mypos.m_positionY),
+ mypos.m_positionX, mypos.m_positionY, mypos.m_positionZ + 2.0f, x, y, z + 2.0f);
if (!isInLOS)
{
i_nextCheckTime.Reset(200);
diff --git a/src/server/game/Movement/PathGenerator.cpp b/src/server/game/Movement/PathGenerator.cpp
index 16cfe366f4e..4c89bb99e2c 100644
--- a/src/server/game/Movement/PathGenerator.cpp
+++ b/src/server/game/Movement/PathGenerator.cpp
@@ -18,15 +18,16 @@
*/
#include "PathGenerator.h"
-#include "Map.h"
#include "Creature.h"
-#include "MMapFactory.h"
-#include "MMapManager.h"
-#include "Log.h"
-#include "DisableMgr.h"
#include "DetourCommon.h"
#include "DetourNavMeshQuery.h"
+#include "DisableMgr.h"
+#include "Log.h"
+#include "MMapFactory.h"
+#include "MMapManager.h"
+#include "Map.h"
#include "Metric.h"
+#include "PhasingHandler.h"
////////////////// PathGenerator //////////////////
PathGenerator::PathGenerator(const Unit* owner) :
@@ -39,7 +40,7 @@ PathGenerator::PathGenerator(const Unit* owner) :
TC_LOG_DEBUG("maps", "++ PathGenerator::PathGenerator for %s", _sourceUnit->GetGUID().ToString().c_str());
- uint32 mapId = _sourceUnit->GetPhaseShift().GetTerrainMapId(_sourceUnit->GetMapId(), _sourceUnit->GetPositionX(), _sourceUnit->GetPositionY());
+ uint32 mapId = PhasingHandler::GetTerrainMapId(_sourceUnit->GetPhaseShift(), _sourceUnit->GetMap(), _sourceUnit->GetPositionX(), _sourceUnit->GetPositionY());
if (DisableMgr::IsPathfindingEnabled(_sourceUnit->GetMapId()))
{
MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager();
diff --git a/src/server/game/Phasing/PhaseShift.cpp b/src/server/game/Phasing/PhaseShift.cpp
index d543ccd1f22..b2885ae15bb 100644
--- a/src/server/game/Phasing/PhaseShift.cpp
+++ b/src/server/game/Phasing/PhaseShift.cpp
@@ -17,8 +17,6 @@
#include "PhaseShift.h"
#include "Containers.h"
-#include "GridDefines.h"
-#include "VMapFactory.h"
bool PhaseShift::AddPhase(uint32 phaseId, PhaseFlags flags, std::vector<Condition*> const* areaConditions, int32 references /*= 1*/)
{
@@ -147,33 +145,6 @@ bool PhaseShift::CanSee(PhaseShift const& other) const
return checkInversePhaseShift(other, *this);
}
-uint32 PhaseShift::GetTerrainMapId(uint32 realMapId, float x, float y) const
-{
- if (VisibleMapIds.empty())
- return realMapId;
-
- if (VisibleMapIds.size() == 1)
- return VisibleMapIds.begin()->first;
-
- GridCoord gridCoord = Trinity::ComputeGridCoord(x, y);
- int32 gx = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.x_coord;
- int32 gy = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.y_coord;
-
- int32 minDistance = std::numeric_limits<int32>::max();
- uint32 terrainMapId;
- for (auto itr = VisibleMapIds.begin(); itr != VisibleMapIds.end(); ++itr)
- {
- int32 dist = VMAP::VMapFactory::createOrGetVMapManager()->GetDistanceToClosestPrimaryTile(itr->first, gx, gy);
- if (dist < minDistance)
- {
- minDistance = dist;
- terrainMapId = itr->first;
- }
- }
-
- return terrainMapId;
-}
-
void PhaseShift::ModifyPhasesReferences(PhaseContainer::iterator itr, int32 references)
{
itr->References += references;
diff --git a/src/server/game/Phasing/PhaseShift.h b/src/server/game/Phasing/PhaseShift.h
index ca38614ed45..8755868ae9d 100644
--- a/src/server/game/Phasing/PhaseShift.h
+++ b/src/server/game/Phasing/PhaseShift.h
@@ -101,7 +101,6 @@ public:
void ClearPhases();
bool CanSee(PhaseShift const& other) const;
- uint32 GetTerrainMapId(uint32 realMapId, float x, float y) const;
protected:
friend class PhasingHandler;
diff --git a/src/server/game/Phasing/PhasingHandler.cpp b/src/server/game/Phasing/PhasingHandler.cpp
index 44f0a9ff753..549093fecba 100644
--- a/src/server/game/Phasing/PhasingHandler.cpp
+++ b/src/server/game/Phasing/PhasingHandler.cpp
@@ -469,6 +469,32 @@ bool PhasingHandler::InDbPhaseShift(WorldObject const* object, uint8 phaseUseFla
return object->GetPhaseShift().CanSee(phaseShift);
}
+uint32 PhasingHandler::GetTerrainMapId(PhaseShift const& phaseShift, Map const* map, float x, float y)
+{
+ if (phaseShift.VisibleMapIds.empty())
+ return map->GetId();
+
+ if (phaseShift.VisibleMapIds.size() == 1)
+ return phaseShift.VisibleMapIds.begin()->first;
+
+ GridCoord gridCoord = Trinity::ComputeGridCoord(x, y);
+ int32 gx = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.x_coord;
+ int32 gy = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.y_coord;
+
+ int32 gxbegin = std::max(gx - 1, 0);
+ int32 gxend = std::min(gx + 1, MAX_NUMBER_OF_GRIDS);
+ int32 gybegin = std::max(gy - 1, 0);
+ int32 gyend = std::min(gy + 1, MAX_NUMBER_OF_GRIDS);
+
+ for (auto itr = phaseShift.VisibleMapIds.rbegin(); itr != phaseShift.VisibleMapIds.rend(); ++itr)
+ for (int32 gxi = gxbegin; gxi < gxend; ++gxi)
+ for (int32 gyi = gybegin; gyi < gyend; ++gyi)
+ if (map->HasGrid(itr->first, gxi, gyi))
+ return itr->first;
+
+ return map->GetId();
+}
+
void PhasingHandler::SetAlwaysVisible(PhaseShift& phaseShift, bool apply)
{
if (apply)
diff --git a/src/server/game/Phasing/PhasingHandler.h b/src/server/game/Phasing/PhasingHandler.h
index 9ee408ad26c..95f4357b30c 100644
--- a/src/server/game/Phasing/PhasingHandler.h
+++ b/src/server/game/Phasing/PhasingHandler.h
@@ -22,6 +22,7 @@
#include <string>
class ChatHandler;
+class Map;
class PhaseShift;
class Player;
class WorldObject;
@@ -60,6 +61,8 @@ 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, Map const* map, float x, float y);
+
static void SetAlwaysVisible(PhaseShift& phaseShift, bool apply);
static void SetInversed(PhaseShift& phaseShift, bool apply);