From cad41332bae629aeddf8c658efcf48c7df362d60 Mon Sep 17 00:00:00 2001 From: Giacomo Pozzoni Date: Thu, 20 Feb 2020 21:29:46 +0100 Subject: [PATCH] Core/PathGenerator: Fix path generator returning shortcuts when start and end are on the same polygon (#24036) * Core/PathGenerator: Fix path generator returning shortcuts when start and end are on the same polygon Fix path generator returning shortcuts when start and end are on the same polygon by handling this case as if start and end were on 2 different polygons. This will ensure BuildPointPath() gets called which calls FindSmoothPath(), making sure each step is not longer than SMOOTH_PATH_STEP_SIZE (4 yards) * Change ingame cast error message to SPELL_FAILED_NOPATH from SPELL_FAILED_OUT_OF_RANGE if the generated path is too long --- src/server/game/Movement/PathGenerator.cpp | 9 +++----- src/server/game/Spells/Spell.cpp | 2 +- src/tools/mmaps_generator/MapBuilder.cpp | 26 +++++++++++++--------- src/tools/mmaps_generator/MapBuilder.h | 1 + 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/server/game/Movement/PathGenerator.cpp b/src/server/game/Movement/PathGenerator.cpp index 88a4cd341a3..af1eb271eb2 100644 --- a/src/server/game/Movement/PathGenerator.cpp +++ b/src/server/game/Movement/PathGenerator.cpp @@ -247,7 +247,7 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con // *** poly path generating logic *** // start and end are on same polygon - // just need to move in straight line + // handle this case as if they were 2 different polygons, building a line path split in some few points if (startPoly == endPoly) { TC_LOG_DEBUG("maps.mmaps", "++ BuildPolyPath :: (startPoly == endPoly)"); @@ -255,11 +255,8 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con BuildShortcut(); _pathPolyRefs[0] = startPoly; - _polyLength = 1; - - _type = farFromPoly ? PATHFIND_INCOMPLETE : PATHFIND_NORMAL; - TC_LOG_DEBUG("maps.mmaps", "++ BuildPolyPath :: path type %d", _type); - return; + _pathPolyRefs[1] = endPoly; + _polyLength = 2; } // look for startPoly/endPoly in current path diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index b699a065b58..7e66c1a823e 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -5714,7 +5714,7 @@ SpellCastResult Spell::CheckCast(bool strict, uint32* param1 /*= nullptr*/, uint // first try with raycast, if it fails fall back to normal path bool result = m_preGeneratedPath->CalculatePath(target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), false, false); if (m_preGeneratedPath->GetPathType() & PATHFIND_SHORT) - return SPELL_FAILED_OUT_OF_RANGE; + return SPELL_FAILED_NOPATH; else if (!result || m_preGeneratedPath->GetPathType() & (PATHFIND_NOPATH | PATHFIND_INCOMPLETE)) return SPELL_FAILED_NOPATH; else if (m_preGeneratedPath->IsInvalidDestinationZ(target)) // Check position z, if not in a straight line diff --git a/src/tools/mmaps_generator/MapBuilder.cpp b/src/tools/mmaps_generator/MapBuilder.cpp index f2f51832a24..3490789f600 100644 --- a/src/tools/mmaps_generator/MapBuilder.cpp +++ b/src/tools/mmaps_generator/MapBuilder.cpp @@ -881,16 +881,8 @@ namespace MMAP return static_cast(m_mapid) != mapID; if (m_skipContinents) - switch (mapID) - { - case 0: - case 1: - case 530: - case 571: - return true; - default: - break; - } + if (isContinentMap(mapID)) + return true; if (m_skipJunkMaps) switch (mapID) @@ -992,6 +984,20 @@ namespace MMAP } } + bool MapBuilder::isContinentMap(uint32 mapID) + { + switch (mapID) + { + case 0: + case 1: + case 530: + case 571: + return true; + default: + return false; + } + } + /**************************************************************************/ bool MapBuilder::shouldSkipTile(uint32 mapID, uint32 tileX, uint32 tileY) { diff --git a/src/tools/mmaps_generator/MapBuilder.h b/src/tools/mmaps_generator/MapBuilder.h index b7ad8cb04b4..753ce8c7237 100644 --- a/src/tools/mmaps_generator/MapBuilder.h +++ b/src/tools/mmaps_generator/MapBuilder.h @@ -143,6 +143,7 @@ namespace MMAP bool shouldSkipMap(uint32 mapID); bool isTransportMap(uint32 mapID); + bool isContinentMap(uint32 mapID); bool shouldSkipTile(uint32 mapID, uint32 tileX, uint32 tileY); rcConfig GetMapSpecificConfig(uint32 mapID, float bmin[3], float bmax[3], const TileConfig &tileConfig);