Core/Movement: Use MonsterMoveStop spline type to stop movement instead of sending movement to current position
This commit is contained in:
1 parent
c3e1443a13
commit
e7590abce7
11 files changed
+141
-92
No files matched your search
@@ -376,12 +376,13 @@ void Unit::MonsterMoveWithSpeed(float x, float y, float z, float speed)
|
||||
init.Launch();
|
||||
}
|
||||
|
||||
enum MovementIntervals
|
||||
{
|
||||
POSITION_UPDATE_DELAY = 400,
|
||||
};
|
||||
|
||||
void Unit::UpdateSplineMovement(uint32 t_diff)
|
||||
{
|
||||
enum{
|
||||
POSITION_UPDATE_DELAY = 400,
|
||||
};
|
||||
|
||||
if (movespline->Finalized())
|
||||
return;
|
||||
|
||||
@@ -393,30 +394,32 @@ void Unit::UpdateSplineMovement(uint32 t_diff)
|
||||
|
||||
m_movesplineTimer.Update(t_diff);
|
||||
if (m_movesplineTimer.Passed() || arrived)
|
||||
UpdateSplinePosition();
|
||||
}
|
||||
|
||||
void Unit::UpdateSplinePosition()
|
||||
{
|
||||
m_movesplineTimer.Reset(POSITION_UPDATE_DELAY);
|
||||
Movement::Location loc = movespline->ComputePosition();
|
||||
if (GetTransGUID())
|
||||
{
|
||||
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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user