diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/server/game/Entities/Unit/Unit.cpp | 62 | ||||
-rwxr-xr-x | src/server/game/Entities/Unit/Unit.h | 1 | ||||
-rwxr-xr-x | src/server/game/Handlers/NPCHandler.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Movement/Spline/MoveSpline.cpp | 9 | ||||
-rw-r--r-- | src/server/game/Movement/Spline/MoveSpline.h | 29 | ||||
-rw-r--r-- | src/server/game/Movement/Spline/MoveSplineFlag.h | 5 | ||||
-rw-r--r-- | src/server/game/Movement/Spline/MoveSplineInit.cpp | 35 | ||||
-rw-r--r-- | src/server/game/Movement/Spline/MoveSplineInit.h | 4 | ||||
-rw-r--r-- | src/server/game/Movement/Spline/MovementPacketBuilder.cpp | 8 | ||||
-rw-r--r-- | src/server/game/Movement/Spline/MovementPacketBuilder.h | 1 | ||||
-rw-r--r-- | src/server/game/Movement/Spline/MovementUtil.cpp | 77 |
11 files changed, 141 insertions, 92 deletions
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 9d924230a76..06b082de155 100755 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -376,12 +376,13 @@ void Unit::MonsterMoveWithSpeed(float x, float y, float z, float speed) init.Launch(); } -void Unit::UpdateSplineMovement(uint32 t_diff) +enum MovementIntervals { - enum{ - POSITION_UPDATE_DELAY = 400, - }; + POSITION_UPDATE_DELAY = 400, +}; +void Unit::UpdateSplineMovement(uint32 t_diff) +{ if (movespline->Finalized()) return; @@ -393,30 +394,32 @@ void Unit::UpdateSplineMovement(uint32 t_diff) m_movesplineTimer.Update(t_diff); if (m_movesplineTimer.Passed() || arrived) - { - m_movesplineTimer.Reset(POSITION_UPDATE_DELAY); - Movement::Location loc = movespline->ComputePosition(); + UpdateSplinePosition(); +} - if (GetTransGUID()) +void Unit::UpdateSplinePosition() +{ + m_movesplineTimer.Reset(POSITION_UPDATE_DELAY); + Movement::Location loc = movespline->ComputePosition(); + if (GetTransGUID()) + { + Position& pos = m_movementInfo.t_pos; + pos.m_positionX = loc.x; + pos.m_positionY = loc.y; + pos.m_positionZ = loc.z; + pos.m_orientation = loc.orientation; + if (Unit* vehicle = GetVehicleBase()) { - Position& pos = m_movementInfo.t_pos; - pos.m_positionX = loc.x; - pos.m_positionY = loc.y; - pos.m_positionZ = loc.z; - pos.m_orientation = loc.orientation; - if (Unit* vehicle = GetVehicleBase()) - { - loc.x += vehicle->GetPositionX(); - loc.y += vehicle->GetPositionY(); - loc.z += vehicle->GetPositionZMinusOffset(); - loc.orientation = vehicle->GetOrientation(); - } - else if (Transport* trans = GetTransport()) - trans->CalculatePassengerPosition(loc.x, loc.y, loc.z, loc.orientation); + loc.x += vehicle->GetPositionX(); + loc.y += vehicle->GetPositionY(); + loc.z += vehicle->GetPositionZMinusOffset(); + loc.orientation = vehicle->GetOrientation(); } - - UpdatePosition(loc.x, loc.y, loc.z, loc.orientation); + else if (Transport* trans = GetTransport()) + trans->CalculatePassengerPosition(loc.x, loc.y, loc.z, loc.orientation); } + + UpdatePosition(loc.x, loc.y, loc.z, loc.orientation); } void Unit::DisableSpline() @@ -15180,14 +15183,13 @@ void Unit::StopMoving() { ClearUnitState(UNIT_STATE_MOVING); - // not need send any packets if not in world - if (!IsInWorld()) + // not need send any packets if not in world or not moving + if (!IsInWorld() || movespline->Finalized()) return; - Movement::MoveSplineInit init(*this); - init.MoveTo(GetPositionX(), GetPositionY(), GetPositionZMinusOffset()); - init.SetFacing(GetOrientation()); - init.Launch(); + // Update position using old spline + UpdateSplinePosition(); + Movement::MoveSplineInit(*this).Stop(); } void Unit::SendMovementFlagUpdate() diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 7a0b97b90ef..96ee32274ef 100755 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -2326,6 +2326,7 @@ class Unit : public WorldObject bool HandleAuraRaidProcFromCharge(AuraEffect* triggeredByAura); void UpdateSplineMovement(uint32 t_diff); + void UpdateSplinePosition(); // player or player's pet float GetCombatRatingReduction(CombatRating cr) const; diff --git a/src/server/game/Handlers/NPCHandler.cpp b/src/server/game/Handlers/NPCHandler.cpp index 651d616a15f..32636d51f49 100755 --- a/src/server/game/Handlers/NPCHandler.cpp +++ b/src/server/game/Handlers/NPCHandler.cpp @@ -322,9 +322,7 @@ void WorldSession::HandleGossipHelloOpcode(WorldPacket & recvData) // GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); if (unit->isArmorer() || unit->isCivilian() || unit->isQuestGiver() || unit->isServiceProvider() || unit->isGuard()) - { unit->StopMoving(); - } // If spiritguide, no need for gossip menu, just put player into resurrect queue if (unit->isSpiritGuide()) diff --git a/src/server/game/Movement/Spline/MoveSpline.cpp b/src/server/game/Movement/Spline/MoveSpline.cpp index c020dc2a653..164b65c067d 100644 --- a/src/server/game/Movement/Spline/MoveSpline.cpp +++ b/src/server/game/Movement/Spline/MoveSpline.cpp @@ -171,6 +171,13 @@ void MoveSpline::Initialize(const MoveSplineInitArgs& args) vertical_acceleration = 0.f; effect_start_time = 0; + // Check if its a stop spline + if (args.flags.done) + { + spline.clear(); + return; + } + init_spline(args); // init parabolic / animation @@ -264,7 +271,7 @@ MoveSpline::UpdateResult MoveSpline::_updateState(int32& ms_time_diff) { point_Idx = spline.first(); time_passed = time_passed % Duration(); - result = Result_NextSegment; + result = Result_NextCycle; } else { diff --git a/src/server/game/Movement/Spline/MoveSpline.h b/src/server/game/Movement/Spline/MoveSpline.h index d4b19b21634..56f2670a04b 100644 --- a/src/server/game/Movement/Spline/MoveSpline.h +++ b/src/server/game/Movement/Spline/MoveSpline.h @@ -41,7 +41,8 @@ namespace Movement { public: typedef Spline<int32> MySpline; - enum UpdateResult{ + enum UpdateResult + { Result_None = 0x01, Result_Arrived = 0x02, Result_NextCycle = 0x04, @@ -70,27 +71,27 @@ namespace Movement void init_spline(const MoveSplineInitArgs& args); protected: - const MySpline::ControlArray& getPath() const { return spline.getPoints();} + const MySpline::ControlArray& getPath() const { return spline.getPoints(); } void computeParabolicElevation(float& el) const; void computeFallElevation(float& el) const; UpdateResult _updateState(int32& ms_time_diff); - int32 next_timestamp() const { return spline.length(point_Idx+1);} - int32 segment_time_elapsed() const { return next_timestamp()-time_passed;} - int32 Duration() const { return spline.length();} - int32 timeElapsed() const { return Duration() - time_passed;} - int32 timePassed() const { return time_passed;} + int32 next_timestamp() const { return spline.length(point_Idx+1); } + int32 segment_time_elapsed() const { return next_timestamp()-time_passed; } + int32 Duration() const { return spline.length(); } + int32 timeElapsed() const { return Duration() - time_passed; } + int32 timePassed() const { return time_passed; } public: - const MySpline& _Spline() const { return spline;} - int32 _currentSplineIdx() const { return point_Idx;} + const MySpline& _Spline() const { return spline; } + int32 _currentSplineIdx() const { return point_Idx; } void _Finalize(); void _Interrupt() { splineflags.done = true;} public: void Initialize(const MoveSplineInitArgs&); - bool Initialized() const { return !spline.empty();} + bool Initialized() const { return !spline.empty(); } explicit MoveSpline(); @@ -112,11 +113,11 @@ namespace Movement Location ComputePosition() const; - uint32 GetId() const { return m_Id;} + uint32 GetId() const { return m_Id; } bool Finalized() const { return splineflags.done; } - bool isCyclic() const { return splineflags.cyclic;} - const Vector3 FinalDestination() const { return Initialized() ? spline.getPoint(spline.last()) : Vector3();} - const Vector3 CurrentDestination() const { return Initialized() ? spline.getPoint(point_Idx+1) : Vector3();} + bool isCyclic() const { return splineflags.cyclic; } + const Vector3 FinalDestination() const { return Initialized() ? spline.getPoint(spline.last()) : Vector3(); } + const Vector3 CurrentDestination() const { return Initialized() ? spline.getPoint(point_Idx+1) : Vector3(); } int32 currentPathIdx() const; std::string ToString() const; diff --git a/src/server/game/Movement/Spline/MoveSplineFlag.h b/src/server/game/Movement/Spline/MoveSplineFlag.h index 40c07f14440..89e76faeea3 100644 --- a/src/server/game/Movement/Spline/MoveSplineFlag.h +++ b/src/server/game/Movement/Spline/MoveSplineFlag.h @@ -33,7 +33,8 @@ namespace Movement class MoveSplineFlag { public: - enum eFlags{ + enum eFlags + { None = 0x00000000, // x00-x07 used as animation Ids storage in pair with Animation flag Unknown0 = 0x00000008, // NOT VERIFIED @@ -73,7 +74,7 @@ namespace Movement // flags that shouldn't be appended into SMSG_MONSTER_MOVE\SMSG_MONSTER_MOVE_TRANSPORT packet, should be more probably Mask_No_Monster_Move = Mask_Final_Facing | Mask_Animations | Done, // Unused, not suported flags - Mask_Unused = No_Spline|Enter_Cycle|Frozen|Unknown0|FallingSlow|Unknown2|Unknown3|Unknown4|SmoothGroundPath|Unknown6|Unknown7|Unknown8|Unknown9, + Mask_Unused = No_Spline|Enter_Cycle|Frozen|Unknown0|Unknown2|Unknown3|Unknown4|Unknown6|Unknown7|Unknown8|Unknown9, }; inline uint32& raw() { return (uint32&)*this; } diff --git a/src/server/game/Movement/Spline/MoveSplineInit.cpp b/src/server/game/Movement/Spline/MoveSplineInit.cpp index 8d0e67b769f..7d91e82096e 100644 --- a/src/server/game/Movement/Spline/MoveSplineInit.cpp +++ b/src/server/game/Movement/Spline/MoveSplineInit.cpp @@ -60,12 +60,10 @@ namespace Movement { MoveSpline& move_spline = *unit.movespline; - bool transport = false; Location real_position(unit.GetPositionX(), unit.GetPositionY(), unit.GetPositionZMinusOffset(), unit.GetOrientation()); // Elevators also use MOVEMENTFLAG_ONTRANSPORT but we do not keep track of their position changes if (unit.GetTransGUID()) { - transport = true; real_position.x = unit.GetTransOffsetX(); real_position.y = unit.GetTransOffsetY(); real_position.z = unit.GetTransOffsetZ(); @@ -102,13 +100,14 @@ namespace Movement if (moveFlags & MOVEMENTFLAG_ROOT) moveFlags &= ~MOVEMENTFLAG_MASK_MOVING; - unit.m_movementInfo.SetMovementFlags((MovementFlags)moveFlags); + unit.m_movementInfo.SetMovementFlags(moveFlags); move_spline.Initialize(args); - WorldPacket data(!transport ? SMSG_MONSTER_MOVE : SMSG_MONSTER_MOVE_TRANSPORT, 64); + WorldPacket data(SMSG_MONSTER_MOVE, 64); data.append(unit.GetPackGUID()); - if (transport) + if (unit.GetTransGUID()) { + data.SetOpcode(SMSG_MONSTER_MOVE_TRANSPORT); data.appendPackGUID(unit.GetTransGUID()); data << int8(unit.GetTransSeat()); } @@ -117,6 +116,32 @@ namespace Movement unit.SendMessageToSet(&data, true); } + void MoveSplineInit::Stop() + { + MoveSpline& move_spline = *unit.movespline; + + // No need to stop if we are not moving + if (move_spline.Finalized()) + return; + + Location loc = move_spline.ComputePosition(); + args.flags = MoveSplineFlag::Done; + unit.m_movementInfo.RemoveMovementFlag(MOVEMENTFLAG_FORWARD); + move_spline.Initialize(args); + + WorldPacket data(SMSG_MONSTER_MOVE, 64); + data.append(unit.GetPackGUID()); + if (unit.GetTransGUID()) + { + data.SetOpcode(SMSG_MONSTER_MOVE_TRANSPORT); + data.appendPackGUID(unit.GetTransGUID()); + data << int8(unit.GetTransSeat()); + } + + PacketBuilder::WriteStopMovement(loc, args.splineId, data); + unit.SendMessageToSet(&data, true); + } + MoveSplineInit::MoveSplineInit(Unit& m) : unit(m) { args.splineId = splineIdGen.NewId(); diff --git a/src/server/game/Movement/Spline/MoveSplineInit.h b/src/server/game/Movement/Spline/MoveSplineInit.h index 053be4e334a..77e34c22b5b 100644 --- a/src/server/game/Movement/Spline/MoveSplineInit.h +++ b/src/server/game/Movement/Spline/MoveSplineInit.h @@ -58,6 +58,10 @@ namespace Movement */ void Launch(); + /* Final pass of initialization that stops movement. + */ + void Stop(); + /* Adds movement by parabolic trajectory * @param amplitude - the maximum height of parabola, value could be negative and positive * @param start_time - delay between movement starting time and beginning to move by parabolic trajectory diff --git a/src/server/game/Movement/Spline/MovementPacketBuilder.cpp b/src/server/game/Movement/Spline/MovementPacketBuilder.cpp index aab96a630fa..4e16b2a6801 100644 --- a/src/server/game/Movement/Spline/MovementPacketBuilder.cpp +++ b/src/server/game/Movement/Spline/MovementPacketBuilder.cpp @@ -88,6 +88,14 @@ namespace Movement } } + void PacketBuilder::WriteStopMovement(Vector3 const& pos, uint32 splineId, ByteBuffer& data) + { + data << uint8(0); // sets/unsets MOVEMENTFLAG2_UNK7 (0x40) + data << pos; + data << splineId; + data << uint8(MonsterMoveStop); + } + void WriteLinearPath(const Spline<int32>& spline, ByteBuffer& data) { uint32 last_idx = spline.getPointCount() - 3; diff --git a/src/server/game/Movement/Spline/MovementPacketBuilder.h b/src/server/game/Movement/Spline/MovementPacketBuilder.h index a6e4e4d5d04..87a25dd0fdf 100644 --- a/src/server/game/Movement/Spline/MovementPacketBuilder.h +++ b/src/server/game/Movement/Spline/MovementPacketBuilder.h @@ -31,6 +31,7 @@ namespace Movement public: static void WriteMonsterMove(const MoveSpline& mov, WorldPacket& data); + static void WriteStopMovement(Vector3 const& loc, uint32 splineId, ByteBuffer& data); static void WriteCreateBits(MoveSpline const& moveSpline, ByteBuffer& data); static void WriteCreateData(MoveSpline const& moveSpline, ByteBuffer& data); }; diff --git a/src/server/game/Movement/Spline/MovementUtil.cpp b/src/server/game/Movement/Spline/MovementUtil.cpp index 63790c8c83f..86fcd26fad7 100644 --- a/src/server/game/Movement/Spline/MovementUtil.cpp +++ b/src/server/game/Movement/Spline/MovementUtil.cpp @@ -27,31 +27,31 @@ namespace Movement /// Velocity bounds that makes fall speed limited float terminalVelocity = 60.148003f; - float terminalSavefallVelocity = 7.f; + float terminalSafefallVelocity = 7.f; - const float terminal_length = float(terminalVelocity * terminalVelocity) / (2.f * gravity); - const float terminal_savefall_length = (terminalSavefallVelocity * terminalSavefallVelocity) / (2.f * gravity); - const float terminalFallTime = float(terminalVelocity/gravity); // the time that needed to reach terminalVelocity + const float terminal_length = float(terminalVelocity * terminalVelocity) / (2.0f * gravity); + const float terminal_safefall_length = (terminalSafefallVelocity * terminalSafefallVelocity) / (2.0f * gravity); + const float terminalFallTime = float(terminalVelocity / gravity); // the time that needed to reach terminalVelocity float computeFallTime(float path_length, bool isSafeFall) { - if (path_length < 0.f) - return 0.f; + if (path_length < 0.0f) + return 0.0f; float time; - if ( isSafeFall ) + if (isSafeFall) { - if (path_length >= terminal_savefall_length) - time = (path_length - terminal_savefall_length)/terminalSavefallVelocity + terminalSavefallVelocity/gravity; + if (path_length >= terminal_safefall_length) + time = (path_length - terminal_safefall_length) / terminalSafefallVelocity + terminalSafefallVelocity / gravity; else - time = sqrtf(2.f * path_length/gravity); + time = sqrtf(2.0f * path_length / gravity); } else { if (path_length >= terminal_length) - time = (path_length - terminal_length)/terminalVelocity + terminalFallTime; + time = (path_length - terminal_length) / terminalVelocity + terminalFallTime; else - time = sqrtf(2.f * path_length/gravity); + time = sqrtf(2.0f * path_length / gravity); } return time; @@ -62,20 +62,21 @@ namespace Movement float termVel; float result; - if ( isSafeFall ) - termVel = terminalSavefallVelocity; + if (isSafeFall) + termVel = terminalSafefallVelocity; else termVel = terminalVelocity; - if ( start_velocity > termVel ) + if (start_velocity > termVel) start_velocity = termVel; float terminal_time = terminalFallTime - start_velocity / gravity; // the time that needed to reach terminalVelocity - if ( t_passed > terminal_time ) + if (t_passed > terminal_time) { - result = terminalVelocity*(t_passed - terminal_time) + - start_velocity*terminal_time + gravity*terminal_time*terminal_time*0.5f; + result = terminalVelocity * (t_passed - terminal_time) + + start_velocity * terminal_time + + gravity * terminal_time * terminal_time*0.5f; } else result = t_passed * (start_velocity + t_passed * gravity * 0.5f); @@ -101,7 +102,7 @@ namespace Movement #define STR(x) #x - const char* g_MovementFlag_names[]= + char const* g_MovementFlag_names[] = { STR(Forward ),// 0x00000001, STR(Backward ),// 0x00000002, @@ -136,25 +137,25 @@ namespace Movement STR(Local_Dirty ),// 0x20000000 STR(None31 ),// 0x40000000 STR(None32 ),// 0x80000000 - STR(Unk1 ), - STR(Unk2 ), - STR(Unk3 ), - STR(Fullspeedturning ), - STR(Fullspeedpitching ), - STR(Allow_Pitching ), - STR(Unk4 ), - STR(Unk5 ), - STR(Unk6 ), - STR(Unk7 ), - STR(Interp_Move ), - STR(Interp_Turning ), - STR(Interp_Pitching ), - STR(Unk8 ), - STR(Unk9 ), - STR(Unk10 ), + STR(Unk1 ), + STR(Unk2 ), + STR(Unk3 ), + STR(Fullspeedturning ), + STR(Fullspeedpitching ), + STR(Allow_Pitching ), + STR(Unk4 ), + STR(Unk5 ), + STR(Unk6 ), + STR(Unk7 ), + STR(Interp_Move ), + STR(Interp_Turning ), + STR(Interp_Pitching ), + STR(None8 ), + STR(None9 ), + STR(None10 ), }; - const char * g_SplineFlag_names[32]= + char const* g_SplineFlag_names[32] = { STR(AnimBit1 ),// 0x00000001, STR(AnimBit2 ),// 0x00000002, @@ -191,11 +192,11 @@ namespace Movement }; template<class Flags, int N> - void print_flags(Flags t, const char* (&names)[N], std::string& str) + void print_flags(Flags t, char const* (&names)[N], std::string& str) { for (int i = 0; i < N; ++i) { - if ((t & (Flags)(1 << i)) && names[i] != NULL) + if ((t & Flags(1 << i)) && names[i] != NULL) str.append(" ").append(names[i]); } } |