From e0a1c5fa1a9ef8cc6d54f368d7a1f4be507ae2d4 Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Sat, 8 Feb 2020 23:33:02 +0100 Subject: [PATCH] Core/Objects: use detour raycasts for unit based MovePositionToFirstCollision calls --- src/server/game/Entities/Object/Object.cpp | 40 ++++++++++++++-------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index c2c9beb11fc..1fd0a89399f 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -24,6 +24,7 @@ #include "Common.h" #include "Creature.h" #include "DynamicTree.h" +#include "G3DPosition.hpp" #include "GameTime.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" @@ -37,6 +38,7 @@ #include "Opcodes.h" #include "OutdoorPvPMgr.h" #include "PhasingHandler.h" +#include "PathGenerator.h" #include "Player.h" #include "SharedDefines.h" #include "SpellAuraEffects.h" @@ -2573,22 +2575,32 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float dist = std::sqrt((pos.m_positionX - destx)*(pos.m_positionX - destx) + (pos.m_positionY - desty)*(pos.m_positionY - desty)); } - float step = dist / 10.0f; - - for (uint8 j = 0; j < 10; ++j) + if (Unit const* unit = ToUnit()) { - // do not allow too big z changes - if (std::fabs(pos.m_positionZ - destz) > 6.0f) + PathGenerator path(unit); + path.CalculatePath(destx, desty, destz, false, true); + pos.Relocate(Vector3ToPosition(path.GetPath().back())); + } + else + { + // To-do: move non-unit cases to detour raycasts as well + float step = dist / 10.0f; + + for (uint8 j = 0; j < 10; ++j) { - destx -= step * std::cos(angle); - desty -= step * std::sin(angle); - UpdateAllowedPositionZ(destx, desty, destz); - } - // we have correct destz now - else - { - pos.Relocate(destx, desty, destz); - break; + // do not allow too big z changes + if (std::fabs(pos.m_positionZ - destz) > 6.0f) + { + destx -= step * std::cos(angle); + desty -= step * std::sin(angle); + UpdateAllowedPositionZ(destx, desty, destz); + } + // we have correct destz now + else + { + pos.Relocate(destx, desty, destz); + break; + } } }