diff options
Diffstat (limited to 'src/server/game/Movement/MotionMaster.cpp')
-rw-r--r-- | src/server/game/Movement/MotionMaster.cpp | 153 |
1 files changed, 84 insertions, 69 deletions
diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index 97149b6ae64..636e121c2ab 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -686,10 +686,12 @@ void MotionMaster::MoveCloserAndStop(uint32 id, Unit* target, float distance) else { // We are already close enough. We just need to turn toward the target without changing position. - Movement::MoveSplineInit init(_owner); - init.MoveTo(_owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZ()); - init.SetFacing(target); - Add(new GenericMovementGenerator(std::move(init), EFFECT_MOTION_TYPE, id)); + std::function<void(Movement::MoveSplineInit&)> initializer = [=, target = target->GetGUID()](Movement::MoveSplineInit& init) + { + init.MoveTo(_owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZ()); + init.SetFacing(target); + }; + Add(new GenericMovementGenerator(std::move(initializer), EFFECT_MOTION_TYPE, id)); } } @@ -697,24 +699,28 @@ void MotionMaster::MoveLand(uint32 id, Position const& pos, Optional<float> velo { TC_LOG_DEBUG("movement.motionmaster", "MotionMaster::MoveLand: '%s', landing point Id: %u (X: %f, Y: %f, Z: %f)", _owner->GetGUID().ToString().c_str(), id, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ()); - Movement::MoveSplineInit init(_owner); - init.MoveTo(PositionToVector3(pos), false); - init.SetAnimation(AnimTier::Ground); - if (velocity) - init.SetVelocity(*velocity); - Add(new GenericMovementGenerator(std::move(init), EFFECT_MOTION_TYPE, id)); + std::function<void(Movement::MoveSplineInit&)> initializer = [=](Movement::MoveSplineInit& init) + { + init.MoveTo(PositionToVector3(pos), false); + init.SetAnimation(AnimTier::Ground); + if (velocity) + init.SetVelocity(*velocity); + }; + Add(new GenericMovementGenerator(std::move(initializer), EFFECT_MOTION_TYPE, id)); } void MotionMaster::MoveTakeoff(uint32 id, Position const& pos, Optional<float> velocity /*= {}*/) { TC_LOG_DEBUG("movement.motionmaster", "MotionMaster::MoveTakeoff: '%s', landing point Id: %u (X: %f, Y: %f, Z: %f)", _owner->GetGUID().ToString().c_str(), id, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ()); - Movement::MoveSplineInit init(_owner); - init.MoveTo(PositionToVector3(pos), false); - init.SetAnimation(AnimTier::Hover); - if (velocity) - init.SetVelocity(*velocity); - Add(new GenericMovementGenerator(std::move(init), EFFECT_MOTION_TYPE, id)); + std::function<void(Movement::MoveSplineInit&)> initializer = [=](Movement::MoveSplineInit& init) + { + init.MoveTo(PositionToVector3(pos), false); + init.SetAnimation(AnimTier::Hover); + if (velocity) + init.SetVelocity(*velocity); + }; + Add(new GenericMovementGenerator(std::move(initializer), EFFECT_MOTION_TYPE, id)); } void MotionMaster::MoveCharge(float x, float y, float z, float speed /*= SPEED_CHARGE*/, uint32 id /*= EVENT_CHARGE*/, bool generatePath /*= false*/) @@ -771,13 +777,15 @@ void MotionMaster::MoveKnockbackFrom(float srcX, float srcY, float speedXY, floa // Use a mmap raycast to get a valid destination. _owner->MovePositionToFirstCollision(dest, dist, _owner->GetRelativeAngle(srcX, srcY) + float(M_PI)); - Movement::MoveSplineInit init(_owner); - init.MoveTo(dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ(), false); - init.SetParabolic(max_height, 0); - init.SetOrientationFixed(true); - init.SetVelocity(speedXY); + std::function<void(Movement::MoveSplineInit&)> initializer = [=](Movement::MoveSplineInit& init) + { + init.MoveTo(dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ(), false); + init.SetParabolic(max_height, 0); + init.SetOrientationFixed(true); + init.SetVelocity(speedXY); + }; - GenericMovementGenerator* movement = new GenericMovementGenerator(std::move(init), EFFECT_MOTION_TYPE, 0); + GenericMovementGenerator* movement = new GenericMovementGenerator(std::move(initializer), EFFECT_MOTION_TYPE, 0); movement->Priority = MOTION_PRIORITY_HIGHEST; movement->AddFlag(MOVEMENTGENERATOR_FLAG_PERSIST_ON_DEATH); Add(movement); @@ -814,14 +822,16 @@ void MotionMaster::MoveJump(float x, float y, float z, float o, float speedXY, f float moveTimeHalf = speedZ / Movement::gravity; float max_height = -Movement::computeFallElevation(moveTimeHalf, false, -speedZ); - Movement::MoveSplineInit init(_owner); - init.MoveTo(x, y, z, false); - init.SetParabolic(max_height, 0); - init.SetVelocity(speedXY); - if (hasOrientation) - init.SetFacing(o); + std::function<void(Movement::MoveSplineInit&)> initializer = [=](Movement::MoveSplineInit& init) + { + init.MoveTo(x, y, z, false); + init.SetParabolic(max_height, 0); + init.SetVelocity(speedXY); + if (hasOrientation) + init.SetFacing(o); + }; - GenericMovementGenerator* movement = new GenericMovementGenerator(std::move(init), EFFECT_MOTION_TYPE, id); + GenericMovementGenerator* movement = new GenericMovementGenerator(std::move(initializer), EFFECT_MOTION_TYPE, id); movement->Priority = MOTION_PRIORITY_HIGHEST; movement->BaseUnitState = UNIT_STATE_JUMPING; movement->AddFlag(MOVEMENTGENERATOR_FLAG_PERSIST_ON_DEATH); @@ -830,47 +840,47 @@ void MotionMaster::MoveJump(float x, float y, float z, float o, float speedXY, f void MotionMaster::MoveCirclePath(float x, float y, float z, float radius, bool clockwise, uint8 stepCount) { - float step = 2 * float(M_PI) / stepCount * (clockwise ? -1.0f : 1.0f); - Position const& pos = { x, y, z, 0.0f }; - float angle = pos.GetAbsoluteAngle(_owner->GetPositionX(), _owner->GetPositionY()); + std::function<void(Movement::MoveSplineInit&)> initializer = [=](Movement::MoveSplineInit& init) + { + float step = 2 * float(M_PI) / stepCount * (clockwise ? -1.0f : 1.0f); + Position const& pos = { x, y, z, 0.0f }; + float angle = pos.GetAbsoluteAngle(_owner->GetPositionX(), _owner->GetPositionY()); - Movement::MoveSplineInit init(_owner); + // add the owner's current position as starting point as it gets removed after entering the cycle + init.Path().push_back(G3D::Vector3(_owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZ())); - // add the owner's current position as starting point as it gets removed after entering the cycle - init.Path().push_back(G3D::Vector3(_owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZ())); + for (uint8 i = 0; i < stepCount; angle += step, ++i) + { + G3D::Vector3 point; + point.x = x + radius * cosf(angle); + point.y = y + radius * sinf(angle); - for (uint8 i = 0; i < stepCount; angle += step, ++i) - { - G3D::Vector3 point; - point.x = x + radius * cosf(angle); - point.y = y + radius * sinf(angle); + if (_owner->IsFlying()) + point.z = z; + else + point.z = _owner->GetMapHeight(point.x, point.y, z) + _owner->GetHoverOffset(); + + init.Path().push_back(point); + } if (_owner->IsFlying()) - point.z = z; + { + init.SetFly(); + init.SetCyclic(); + init.SetAnimation(AnimTier::Hover); + } else - point.z = _owner->GetMapHeight(point.x, point.y, z) + _owner->GetHoverOffset(); - - init.Path().push_back(point); - } - - if (_owner->IsFlying()) - { - init.SetFly(); - init.SetCyclic(); - init.SetAnimation(AnimTier::Hover); - } - else - { - init.SetWalk(true); - init.SetCyclic(); - } + { + init.SetWalk(true); + init.SetCyclic(); + } + }; - Add(new GenericMovementGenerator(std::move(init), EFFECT_MOTION_TYPE, 0)); + Add(new GenericMovementGenerator(std::move(initializer), EFFECT_MOTION_TYPE, 0)); } void MotionMaster::MoveSmoothPath(uint32 pointId, Position const* pathPoints, size_t pathSize, bool walk) { - Movement::MoveSplineInit init(_owner); Movement::PointsArray path; path.reserve(pathSize); std::transform(pathPoints, pathPoints + pathSize, std::back_inserter(path), [](Position const& point) @@ -878,14 +888,17 @@ void MotionMaster::MoveSmoothPath(uint32 pointId, Position const* pathPoints, si return G3D::Vector3(point.GetPositionX(), point.GetPositionY(), point.GetPositionZ()); }); - init.MovebyPath(path); - init.SetSmooth(); - init.SetWalk(walk); + std::function<void(Movement::MoveSplineInit&)> initializer = [=](Movement::MoveSplineInit& init) + { + init.MovebyPath(path); + init.SetSmooth(); + init.SetWalk(walk); + }; // This code is not correct // GenericMovementGenerator does not affect UNIT_STATE_ROAMING_MOVE // need to call PointMovementGenerator with various pointIds - Add(new GenericMovementGenerator(std::move(init), EFFECT_MOTION_TYPE, pointId)); + Add(new GenericMovementGenerator(std::move(initializer), EFFECT_MOTION_TYPE, pointId)); } void MotionMaster::MoveAlongSplineChain(uint32 pointId, uint16 dbChainId, bool walk) @@ -949,11 +962,13 @@ void MotionMaster::MoveFall(uint32 id/* = 0*/) return; } - Movement::MoveSplineInit init(_owner); - init.MoveTo(_owner->GetPositionX(), _owner->GetPositionY(), tz + _owner->GetHoverOffset(), false); - init.SetFall(); + std::function<void(Movement::MoveSplineInit&)> initializer = [=](Movement::MoveSplineInit& init) + { + init.MoveTo(_owner->GetPositionX(), _owner->GetPositionY(), tz + _owner->GetHoverOffset(), false); + init.SetFall(); + }; - GenericMovementGenerator* movement = new GenericMovementGenerator(std::move(init), EFFECT_MOTION_TYPE, id); + GenericMovementGenerator* movement = new GenericMovementGenerator(std::move(initializer), EFFECT_MOTION_TYPE, id); movement->Priority = MOTION_PRIORITY_HIGHEST; Add(movement); } @@ -1050,7 +1065,7 @@ void MotionMaster::MoveFormation(Unit* leader, float range, float angle, uint32 } } -void MotionMaster::LaunchMoveSpline(Movement::MoveSplineInit&& init, uint32 id/*= 0*/, MovementGeneratorPriority priority/* = MOTION_PRIORITY_NORMAL*/, MovementGeneratorType type/*= EFFECT_MOTION_TYPE*/) +void MotionMaster::LaunchMoveSpline(std::function<void(Movement::MoveSplineInit& init)>&& initializer, uint32 id/*= 0*/, MovementGeneratorPriority priority/* = MOTION_PRIORITY_NORMAL*/, MovementGeneratorType type/*= EFFECT_MOTION_TYPE*/) { if (IsInvalidMovementGeneratorType(type)) { @@ -1060,7 +1075,7 @@ void MotionMaster::LaunchMoveSpline(Movement::MoveSplineInit&& init, uint32 id/* TC_LOG_DEBUG("movement.motionmaster", "MotionMaster::LaunchMoveSpline: '%s', initiates spline Id: %u (Type: %u, Priority: %u)", _owner->GetGUID().ToString().c_str(), id, type, priority); - GenericMovementGenerator* movement = new GenericMovementGenerator(std::move(init), type, id); + GenericMovementGenerator* movement = new GenericMovementGenerator(std::move(initializer), type, id); movement->Priority = priority; Add(movement); } |