From 2aedc345fcdbe2e80c22e2a7f5ef2d0bd837c437 Mon Sep 17 00:00:00 2001 From: ratkosrb Date: Tue, 12 Jan 2021 13:59:33 +0200 Subject: [PATCH] Teleport creatures back to spawn on evade if no path. --- src/game/Movement/HomeMovementGenerator.cpp | 24 ++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/game/Movement/HomeMovementGenerator.cpp b/src/game/Movement/HomeMovementGenerator.cpp index 33c1aa5cf..f8c247032 100644 --- a/src/game/Movement/HomeMovementGenerator.cpp +++ b/src/game/Movement/HomeMovementGenerator.cpp @@ -43,18 +43,32 @@ void HomeMovementGenerator::_setTargetLocation(Creature & owner) owner.ModifyAuraState(AURA_STATE_HEALTHLESS_10_PERCENT, false); owner.ModifyAuraState(AURA_STATE_HEALTHLESS_5_PERCENT, false); - Movement::MoveSplineInit init(owner, "HomeMovementGenerator"); + float x, y, z, o; + bool setFacing = false; // at apply we can select more nice return points base at current movegen if (owner.GetMotionMaster()->empty() || !owner.GetMotionMaster()->top()->GetResetPosition(owner, x, y, z)) { owner.GetRespawnCoord(x, y, z, &o); - init.SetFacing(o); + setFacing = true; } - init.MoveTo(x, y, z, MOVE_PATHFINDING | MOVE_FORCE_DESTINATION); - init.SetWalk(false); - init.Launch(); + PathFinder path(&owner); + path.calculate(x, y, z, true); + if ((path.getPathType() & PATHFIND_NORMAL) && !((path.getPathType() & PATHFIND_NOT_USING_PATH) && (path.getPathType() & PATHFIND_DEST_FORCED))) + { + Movement::MoveSplineInit init(owner, "HomeMovementGenerator"); + + if (setFacing) + init.SetFacing(o); + + init.Move(&path); + init.SetWalk(false); + init.Launch(); + } + else // too far away or no path + owner.NearTeleportTo(x, y, z, o); + arrived = false; owner.ClearUnitState(UNIT_STAT_ALL_DYN_STATES);