Skip to content

Commit

Permalink
Improve Player movement branch squash
Browse files Browse the repository at this point in the history
  • Loading branch information
chaodhib committed Mar 18, 2019
1 parent 4d3ee3f commit f33964b
Show file tree
Hide file tree
Showing 40 changed files with 2,173 additions and 1,142 deletions.
2 changes: 2 additions & 0 deletions sql/updates/world/3.3.5/2017_XX_XX_XX_world_335.sql
@@ -0,0 +1,2 @@
-- remove wrong trigger on SV Hunter spell Disengage
DELETE FROM `spell_linked_spell` WHERE `spell_trigger`=781;
73 changes: 0 additions & 73 deletions src/server/game/Entities/Creature/Creature.cpp
Expand Up @@ -2771,22 +2771,6 @@ bool Creature::SetWalk(bool enable)
return true;
}

bool Creature::SetDisableGravity(bool disable, bool packetOnly/*=false*/)
{
//! It's possible only a packet is sent but moveflags are not updated
//! Need more research on this
if (!packetOnly && !Unit::SetDisableGravity(disable))
return false;

if (!movespline->Initialized())
return true;

WorldPacket data(disable ? SMSG_SPLINE_MOVE_GRAVITY_DISABLE : SMSG_SPLINE_MOVE_GRAVITY_ENABLE, 9);
data << GetPackGUID();
SendMessageToSet(&data, false);
return true;
}

bool Creature::SetSwim(bool enable)
{
if (!Unit::SetSwim(enable))
Expand All @@ -2801,63 +2785,6 @@ bool Creature::SetSwim(bool enable)
return true;
}

bool Creature::SetCanFly(bool enable, bool /*packetOnly = false */)
{
if (!Unit::SetCanFly(enable))
return false;

if (!movespline->Initialized())
return true;

WorldPacket data(enable ? SMSG_SPLINE_MOVE_SET_FLYING : SMSG_SPLINE_MOVE_UNSET_FLYING, 9);
data << GetPackGUID();
SendMessageToSet(&data, false);
return true;
}

bool Creature::SetWaterWalking(bool enable, bool packetOnly /* = false */)
{
if (!packetOnly && !Unit::SetWaterWalking(enable))
return false;

if (!movespline->Initialized())
return true;

WorldPacket data(enable ? SMSG_SPLINE_MOVE_WATER_WALK : SMSG_SPLINE_MOVE_LAND_WALK);
data << GetPackGUID();
SendMessageToSet(&data, true);
return true;
}

bool Creature::SetFeatherFall(bool enable, bool packetOnly /* = false */)
{
if (!packetOnly && !Unit::SetFeatherFall(enable))
return false;

if (!movespline->Initialized())
return true;

WorldPacket data(enable ? SMSG_SPLINE_MOVE_FEATHER_FALL : SMSG_SPLINE_MOVE_NORMAL_FALL);
data << GetPackGUID();
SendMessageToSet(&data, true);
return true;
}

bool Creature::SetHover(bool enable, bool packetOnly /*= false*/)
{
if (!packetOnly && !Unit::SetHover(enable))
return false;

if (!movespline->Initialized())
return true;

//! Not always a packet is sent
WorldPacket data(enable ? SMSG_SPLINE_MOVE_SET_HOVER : SMSG_SPLINE_MOVE_UNSET_HOVER, 9);
data << GetPackGUID();
SendMessageToSet(&data, false);
return true;
}

float Creature::GetAggroRange(Unit const* target) const
{
// Determines the aggro range for creatures (usually pets), used mainly for aggressive pet target selection.
Expand Down
5 changes: 0 additions & 5 deletions src/server/game/Entities/Creature/Creature.h
Expand Up @@ -139,12 +139,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
CreatureAI* AI() const { return reinterpret_cast<CreatureAI*>(GetAI()); }

bool SetWalk(bool enable) override;
bool SetDisableGravity(bool disable, bool packetOnly = false) override;
bool SetSwim(bool enable) override;
bool SetCanFly(bool enable, bool packetOnly = false) override;
bool SetWaterWalking(bool enable, bool packetOnly = false) override;
bool SetFeatherFall(bool enable, bool packetOnly = false) override;
bool SetHover(bool enable, bool packetOnly = false) override;

uint32 GetShieldBlockValue() const override;

Expand Down
7 changes: 6 additions & 1 deletion src/server/game/Entities/Object/MovementInfo.h
Expand Up @@ -85,12 +85,17 @@ struct MovementInfo
bool HasMovementFlag(uint32 flag) const { return (flags & flag) != 0; }

uint16 GetExtraMovementFlags() const { return flags2; }
void SetExtraMovementFlags(uint16 flag) { flags2 = flag; }
void AddExtraMovementFlag(uint16 flag) { flags2 |= flag; }
void RemoveExtraMovementFlag(uint16 flag) { flags2 &= ~flag; }
bool HasExtraMovementFlag(uint16 flag) const { return (flags2 & flag) != 0; }

void SetFallTime(uint32 val) { fallTime = val; }

void OutDebug();
void OutDebug() const;

void WriteContentIntoPacket(ByteBuffer* data, bool includeGuid = false) const;
void FillContentFromPacket(ByteBuffer* data, bool includeGuid = false);
};

#endif // MovementInfo_h__
146 changes: 141 additions & 5 deletions src/server/game/Entities/Object/Object.cpp
Expand Up @@ -319,7 +319,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
if (flags & UPDATEFLAG_LIVING)
{
ASSERT(unit);
unit->BuildMovementPacket(data);
unit->GetMovementInfo().WriteContentIntoPacket(data);

*data << unit->GetSpeed(MOVE_WALK)
<< unit->GetSpeed(MOVE_RUN)
Expand All @@ -332,7 +332,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
<< unit->GetSpeed(MOVE_PITCH_RATE);

// 0x08000000
if (unit->m_movementInfo.GetMovementFlags() & MOVEMENTFLAG_SPLINE_ENABLED)
if (unit->GetMovementInfo().GetMovementFlags() & MOVEMENTFLAG_SPLINE_ENABLED)
Movement::PacketBuilder::WriteCreate(*unit->movespline, *data);
}
else
Expand Down Expand Up @@ -933,7 +933,7 @@ std::string Object::GetDebugInfo() const
return sstr.str();
}

void MovementInfo::OutDebug()
void MovementInfo::OutDebug() const
{
TC_LOG_DEBUG("misc", "MOVEMENT INFO");
TC_LOG_DEBUG("misc", "%s", guid.ToString().c_str());
Expand Down Expand Up @@ -963,6 +963,80 @@ void MovementInfo::OutDebug()
TC_LOG_DEBUG("misc", "splineElevation: %f", splineElevation);
}

void MovementInfo::WriteContentIntoPacket(ByteBuffer * data, bool includeGuid /* = false*/) const
{
if (includeGuid)
*data << guid.WriteAsPacked();
*data << flags;
*data << flags2;
*data << time;
*data << TaggedPosition<Position::XYZO>(pos);

if (HasMovementFlag(MOVEMENTFLAG_ONTRANSPORT))
{
*data << transport.guid.WriteAsPacked();
*data << TaggedPosition<Position::XYZO>(transport.pos);
*data << transport.time;
*data << transport.seat;

if (HasExtraMovementFlag(MOVEMENTFLAG2_INTERPOLATED_MOVEMENT))
*data << transport.time2;
}

if (HasMovementFlag(MovementFlags(MOVEMENTFLAG_SWIMMING | MOVEMENTFLAG_FLYING)) || HasExtraMovementFlag(MOVEMENTFLAG2_ALWAYS_ALLOW_PITCHING))
*data << pitch;

*data << fallTime;

if (HasMovementFlag(MOVEMENTFLAG_FALLING))
{
*data << jump.zspeed;
*data << jump.cosAngle;
*data << jump.sinAngle;
*data << jump.xyspeed;
}

if (HasMovementFlag(MOVEMENTFLAG_SPLINE_ELEVATION))
*data << splineElevation;
}

void MovementInfo::FillContentFromPacket(ByteBuffer * data, bool includeGuid /* = false*/)
{
if(includeGuid)
*data >> guid.ReadAsPacked();
*data >> flags;
*data >> flags2;
*data >> time;
*data >> pos.PositionXYZOStream();

if (HasMovementFlag(MOVEMENTFLAG_ONTRANSPORT))
{
*data >> transport.guid.ReadAsPacked();
*data >> transport.pos.PositionXYZOStream();
*data >> transport.time;
*data >> transport.seat;

if (HasExtraMovementFlag(MOVEMENTFLAG2_INTERPOLATED_MOVEMENT))
*data >> transport.time2;
}

if (HasMovementFlag(MovementFlags(MOVEMENTFLAG_SWIMMING | MOVEMENTFLAG_FLYING)) || (HasExtraMovementFlag(MOVEMENTFLAG2_ALWAYS_ALLOW_PITCHING)))
*data >> pitch;

*data >> fallTime;

if (HasMovementFlag(MOVEMENTFLAG_FALLING))
{
*data >> jump.zspeed;
*data >> jump.cosAngle;
*data >> jump.sinAngle;
*data >> jump.xyspeed;
}

if (HasMovementFlag(MOVEMENTFLAG_SPLINE_ELEVATION))
*data >> splineElevation;
}

WorldObject::WorldObject(bool isWorldObject) : Object(), WorldLocation(), LastUsedScriptID(0),
m_movementInfo(), m_name(), m_isActive(false), m_isFarVisible(false), m_isWorldObject(isWorldObject), m_zoneScript(nullptr),
m_transport(nullptr), m_zoneId(0), m_areaId(0), m_staticFloorZ(VMAP_INVALID_HEIGHT), m_currMap(nullptr), m_InstanceId(0),
Expand Down Expand Up @@ -1737,8 +1811,7 @@ void Object::ForceValuesUpdateAtIndex(uint32 i)
void Unit::BuildHeartBeatMsg(WorldPacket* data) const
{
data->Initialize(MSG_MOVE_HEARTBEAT, 32);
*data << GetPackGUID();
BuildMovementPacket(data);
GetMovementInfo().WriteContentIntoPacket(data, true);
}

void WorldObject::SendMessageToSet(WorldPacket const* data, bool self) const
Expand Down Expand Up @@ -3493,6 +3566,69 @@ std::string WorldObject::GetDebugInfo() const
return sstr.str();
}

void WorldObject::SetTransport(Transport* transport)
{
if (transport)
{
m_movementInfo.transport.guid = transport->GetGUID();
// could it be possible to initialize the rest of the transport data (seat, time, offset) here?
AddUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT);
}
else // if(!m_vehicle) ?
{
m_movementInfo.transport.Reset();
RemoveUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT);
}

m_transport = transport;
}

MovementInfo WorldObject::GetMovementInfo() const
{
MovementInfo mInfo;
mInfo.guid = GetGUID();
mInfo.SetMovementFlags(GetUnitMovementFlags());
mInfo.SetExtraMovementFlags(GetExtraUnitMovementFlags());
mInfo.time = m_movementInfo.time;
mInfo.pos.Relocate
(
GetPositionX(),
GetPositionY(),
GetPositionZ(),
GetOrientation()
);

if (GetUnitMovementFlags() & MOVEMENTFLAG_ONTRANSPORT)
{
mInfo.transport.guid = GetTransGUID();
mInfo.transport.pos.Relocate(GetTransOffsetX(), GetTransOffsetY(), GetTransOffsetZ(), GetTransOffsetO());
mInfo.transport.time = GetTransTime();
mInfo.transport.seat = GetTransSeat();

if (GetExtraUnitMovementFlags() & MOVEMENTFLAG2_INTERPOLATED_MOVEMENT)
mInfo.transport.time2 = m_movementInfo.transport.time2;
}

if ((GetUnitMovementFlags() & (MOVEMENTFLAG_SWIMMING | MOVEMENTFLAG_FLYING))
|| (m_movementInfo.flags2 & MOVEMENTFLAG2_ALWAYS_ALLOW_PITCHING))
mInfo.pitch = m_movementInfo.pitch;

mInfo.SetFallTime(m_movementInfo.fallTime);

if (GetUnitMovementFlags() & MOVEMENTFLAG_FALLING)
{
mInfo.jump.zspeed = m_movementInfo.jump.zspeed;
mInfo.jump.sinAngle = m_movementInfo.jump.sinAngle;
mInfo.jump.cosAngle = m_movementInfo.jump.cosAngle;
mInfo.jump.xyspeed = m_movementInfo.jump.xyspeed;
}

if (GetUnitMovementFlags() & MOVEMENTFLAG_SPLINE_ELEVATION)
mInfo.splineElevation = m_movementInfo.splineElevation;

return mInfo;
}

template TC_GAME_API void WorldObject::GetGameObjectListWithEntryInGrid(std::list<GameObject*>&, uint32, float) const;
template TC_GAME_API void WorldObject::GetGameObjectListWithEntryInGrid(std::deque<GameObject*>&, uint32, float) const;
template TC_GAME_API void WorldObject::GetGameObjectListWithEntryInGrid(std::vector<GameObject*>&, uint32, float) const;
Expand Down
28 changes: 25 additions & 3 deletions src/server/game/Entities/Object/Object.h
Expand Up @@ -488,6 +488,21 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation

uint32 LastUsedScriptID;


void SetFallTime(uint32 time) { m_movementInfo.SetFallTime(time); }

void AddUnitMovementFlag(uint32 f) { m_movementInfo.flags |= f; }
void RemoveUnitMovementFlag(uint32 f) { m_movementInfo.flags &= ~f; }
bool HasUnitMovementFlag(uint32 f) const { return (m_movementInfo.flags & f) == f; }
uint32 GetUnitMovementFlags() const { return m_movementInfo.flags; }
void SetUnitMovementFlags(uint32 f) { m_movementInfo.flags = f; }

void AddExtraUnitMovementFlag(uint16 f) { m_movementInfo.flags2 |= f; }
void RemoveExtraUnitMovementFlag(uint16 f) { m_movementInfo.flags2 &= ~f; }
bool HasExtraUnitMovementFlag(uint16 f) const { return (m_movementInfo.flags2 & f) == f; }
uint16 GetExtraUnitMovementFlags() const { return m_movementInfo.flags2; }
void SetExtraUnitMovementFlags(uint16 f) { m_movementInfo.flags2 = f; }

// Transports
Transport* GetTransport() const { return m_transport; }
float GetTransOffsetX() const { return m_movementInfo.transport.pos.GetPositionX(); }
Expand All @@ -498,16 +513,21 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
uint32 GetTransTime() const { return m_movementInfo.transport.time; }
int8 GetTransSeat() const { return m_movementInfo.transport.seat; }
virtual ObjectGuid GetTransGUID() const;
void SetTransport(Transport* t) { m_transport = t; }

MovementInfo m_movementInfo;
void SetTransport(Transport* t);
void SetTransOffset(float x, float y, float z, float o = 0.0f) { m_movementInfo.transport.pos.Relocate(x, y, z, o); }
void SetTransTime(uint32 time) { m_movementInfo.transport.time = time; }
void SetTransSeat(int8 seat) { m_movementInfo.transport.seat = seat; }
void SetTransGUID(ObjectGuid guid) { m_movementInfo.transport.guid = guid; }

virtual float GetStationaryX() const { return GetPositionX(); }
virtual float GetStationaryY() const { return GetPositionY(); }
virtual float GetStationaryZ() const { return GetPositionZ(); }
virtual float GetStationaryO() const { return GetOrientation(); }

float GetFloorZ() const;
// Return the current positional/physical state of the object
MovementInfo GetMovementInfo() const;
virtual float ComputeCollisionHeight() const { return 0.0f; }
virtual float GetCollisionHeight() const { return 0.0f; }

float GetMapWaterOrGroundLevel(float x, float y, float z, float* ground = nullptr) const;
Expand All @@ -526,6 +546,8 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
bool const m_isWorldObject;
ZoneScript* m_zoneScript;

MovementInfo m_movementInfo;

// transports
Transport* m_transport;

Expand Down

0 comments on commit f33964b

Please sign in to comment.