diff options
author | Shauren <shauren.trinity@gmail.com> | 2018-02-24 22:35:27 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2018-03-25 19:28:36 +0300 |
commit | bea7faa8f9d48894d836c7205b98e36126734d56 (patch) | |
tree | df32e1a56518cb43445c5e708a6a855917bf6c62 /src/server/game/Phasing/PhaseShift.cpp | |
parent | 4798d9ce7abd86be381af086763d8dbc9ed67ef3 (diff) |
Core/Entities: Take terrain swaps into account when calculating LoS/height/area
Diffstat (limited to 'src/server/game/Phasing/PhaseShift.cpp')
-rw-r--r-- | src/server/game/Phasing/PhaseShift.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/server/game/Phasing/PhaseShift.cpp b/src/server/game/Phasing/PhaseShift.cpp index b2885ae15bb..d543ccd1f22 100644 --- a/src/server/game/Phasing/PhaseShift.cpp +++ b/src/server/game/Phasing/PhaseShift.cpp @@ -17,6 +17,8 @@ #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*/) { @@ -145,6 +147,33 @@ 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; |