From e135d35551fce3e3d3db17d9cbcf3237eb7eb71d Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Sat, 5 Oct 2019 06:30:55 +0200 Subject: [PATCH] Core/Movement: implement cyclic path motion master helper to allow creatures to move along hardcoded spline points that are perfect circles --- src/server/game/Movement/MotionMaster.cpp | 26 +++++++++++++++++++++++ src/server/game/Movement/MotionMaster.h | 1 + 2 files changed, 27 insertions(+) diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index 11d1e1cd28f..5eb591e9934 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -512,6 +512,32 @@ void MotionMaster::MoveCirclePath(float x, float y, float z, float radius, bool init.Launch(); } +void MotionMaster::MoveCyclicPath(Position const* pathPoints, size_t pathSize, bool walk /*= false*/, bool fly /*= false*/, float velocity /*= 0.0f*/) +{ + Movement::MoveSplineInit init(_owner); + Movement::PointsArray path; + path.reserve(pathSize); + std::transform(pathPoints, pathPoints + pathSize, std::back_inserter(path), [](Position const& point) + { + return G3D::Vector3(point.GetPositionX(), point.GetPositionY(), point.GetPositionZ()); + }); + + if (fly) + { + init.SetFly(); + init.SetUncompressed(); + } + + if (velocity > 0.0f) + init.SetVelocity(velocity); + + init.MovebyPath(path); + init.SetSmooth(); + init.SetWalk(walk); + init.SetCyclic(); + init.Launch(); +} + void MotionMaster::MoveSmoothPath(uint32 pointId, Position const* pathPoints, size_t pathSize, bool walk /*= false*/, bool fly /*= false*/, float velocity /*= 0.0f*/) { Movement::MoveSplineInit init(_owner); diff --git a/src/server/game/Movement/MotionMaster.h b/src/server/game/Movement/MotionMaster.h index b9ec6dbb2f8..d0c0f12017f 100644 --- a/src/server/game/Movement/MotionMaster.h +++ b/src/server/game/Movement/MotionMaster.h @@ -185,6 +185,7 @@ class TC_GAME_API MotionMaster } void MoveJump(float x, float y, float z, float o, float speedXY, float speedZ, uint32 id = EVENT_JUMP, bool hasOrientation = false); void MoveCirclePath(float x, float y, float z, float radius, bool clockwise, uint8 stepCount); + void MoveCyclicPath(Position const* pathPoints, size_t pathSize, bool walk = false, bool fly = false, float velocity = 0.0f); void MoveSmoothPath(uint32 pointId, Position const* pathPoints, size_t pathSize, bool walk = false, bool fly = false, float velocity = 0.0f); // Walk along spline chain stored in DB (script_spline_chain_meta and script_spline_chain_waypoints) void MoveAlongSplineChain(uint32 pointId, uint16 dbChainId, bool walk);