*Implement spell casting on transports (no more out of range error, etc)
*Add MO transports to ObjectAccessor storage *Add functions Position::RelocateOffset and Position::GetPositionOffsetTo to help offset manipulations - BIG thanks to azazelkon for creating formulas! *Add function to output debug info for MovementInfo and SpellCastTargets *Throw ByteBufferException on incorrect packGUID read *Add rfinish function to finish bytebuffer read. --HG-- branch : trunk
This commit is contained in:
@@ -1144,6 +1144,13 @@ bool Position::HasInLine(const Unit * const target, float distance, float width)
|
||||
return abs(sin(angle)) * GetExactDist2d(target->GetPositionX(), target->GetPositionY()) < width;
|
||||
}
|
||||
|
||||
std::string Position::ToString() const
|
||||
{
|
||||
std::stringstream sstr;
|
||||
sstr << "X: " << m_positionX << " Y: " << m_positionY << " Z: " << m_positionZ << " O: " << m_orientation;
|
||||
return sstr.str();
|
||||
}
|
||||
|
||||
ByteBuffer &operator>>(ByteBuffer& buf, Position::PositionXYZOStreamer const & streamer)
|
||||
{
|
||||
float x, y, z, o;
|
||||
@@ -1175,6 +1182,39 @@ ByteBuffer & operator<<(ByteBuffer& buf, Position::PositionXYZOStreamer const &
|
||||
return buf;
|
||||
}
|
||||
|
||||
void MovementInfo::OutDebug()
|
||||
{
|
||||
sLog.outString("MOVEMENT INFO");
|
||||
sLog.outString("guid " UI64FMTD, guid);
|
||||
sLog.outString("flags %u", flags);
|
||||
sLog.outString("flags2 %u", flags2);
|
||||
sLog.outString("time %u current time %u", flags2, ::time(NULL));
|
||||
sLog.outString("position: `%s`", pos.ToString().c_str());
|
||||
if (flags & MOVEMENTFLAG_ONTRANSPORT)
|
||||
{
|
||||
sLog.outString("TRANSPORT:");
|
||||
sLog.outString("guid: " UI64FMTD, t_guid);
|
||||
sLog.outString("position: `%s`", t_pos.ToString().c_str());
|
||||
sLog.outString("seat: %i", t_seat);
|
||||
sLog.outString("time: %u", t_time);
|
||||
if (flags2 & MOVEMENTFLAG2_INTERPOLATED_MOVEMENT)
|
||||
sLog.outString("time2: %u", t_time2);
|
||||
}
|
||||
if ((flags & (MOVEMENTFLAG_SWIMMING | MOVEMENTFLAG_FLYING)) || (flags2 & MOVEMENTFLAG2_ALWAYS_ALLOW_PITCHING))
|
||||
{
|
||||
sLog.outString("pitch: %f", pitch);
|
||||
}
|
||||
sLog.outString("fallTime: %u", fallTime);
|
||||
if (flags & MOVEMENTFLAG_JUMPING)
|
||||
{
|
||||
sLog.outString("j_zspeed: %f j_sinAngle: %f j_cosAngle: %f j_xyspeed: %f", j_zspeed, j_sinAngle, j_cosAngle, j_xyspeed);
|
||||
}
|
||||
if (flags & MOVEMENTFLAG_SPLINE_ELEVATION)
|
||||
{
|
||||
sLog.outString("splineElevation: %f", splineElevation);
|
||||
}
|
||||
}
|
||||
|
||||
WorldObject::WorldObject()
|
||||
: WorldLocation(), m_InstanceId(0), m_phaseMask(PHASEMASK_NORMAL), m_currMap(NULL)
|
||||
, m_zoneScript(NULL)
|
||||
@@ -1400,6 +1440,25 @@ bool WorldObject::IsInRange3d(float x, float y, float z, float minRange, float m
|
||||
return distsq < maxdist * maxdist;
|
||||
}
|
||||
|
||||
void Position::RelocateOffset(const Position & offset)
|
||||
{
|
||||
m_positionX = GetPositionX() + (offset.GetPositionX() * cos(GetOrientation()) + offset.GetPositionY() * sin(GetOrientation() + M_PI));
|
||||
m_positionY = GetPositionY() + (offset.GetPositionY() * cos(GetOrientation()) + offset.GetPositionX() * sin(GetOrientation()));
|
||||
m_positionZ = GetPositionZ() + offset.GetPositionZ();
|
||||
m_orientation = GetOrientation() + offset.GetOrientation();
|
||||
}
|
||||
|
||||
void Position::GetPositionOffsetTo(const Position & endPos, Position & retOffset) const
|
||||
{
|
||||
float dx = endPos.GetPositionX() - GetPositionX();
|
||||
float dy = endPos.GetPositionY() - GetPositionY();
|
||||
|
||||
retOffset.m_positionX = dx * cos(GetOrientation()) + dy * sin(GetOrientation());
|
||||
retOffset.m_positionY = dy * cos(GetOrientation()) - dx * sin(GetOrientation());
|
||||
retOffset.m_positionZ = endPos.GetPositionZ() - GetPositionZ();
|
||||
retOffset.m_orientation = endPos.GetOrientation() - GetOrientation();
|
||||
}
|
||||
|
||||
float Position::GetAngle(const Position *obj) const
|
||||
{
|
||||
if (!obj) return 0;
|
||||
@@ -2473,3 +2532,10 @@ void WorldObject::BuildUpdate(UpdateDataMapType& data_map)
|
||||
|
||||
ClearUpdateMask(false);
|
||||
}
|
||||
|
||||
uint64 WorldObject::GetTransGUID() const
|
||||
{
|
||||
if (GetTransport())
|
||||
return GetTransport()->GetGUID();
|
||||
return 0;
|
||||
}
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#define CONTACT_DISTANCE 0.5f
|
||||
#define INTERACTION_DISTANCE 5.0f
|
||||
@@ -396,6 +397,7 @@ struct Position
|
||||
{ m_positionX = pos.m_positionX; m_positionY = pos.m_positionY; m_positionZ = pos.m_positionZ; m_orientation = pos.m_orientation; }
|
||||
void Relocate(const Position *pos)
|
||||
{ m_positionX = pos->m_positionX; m_positionY = pos->m_positionY; m_positionZ = pos->m_positionZ; m_orientation = pos->m_orientation; }
|
||||
void RelocateOffset(const Position &offset);
|
||||
void SetOrientation(float orientation)
|
||||
{ m_orientation = orientation; }
|
||||
|
||||
@@ -444,6 +446,8 @@ struct Position
|
||||
float GetExactDist(const Position *pos) const
|
||||
{ return sqrt(GetExactDistSq(pos)); }
|
||||
|
||||
void GetPositionOffsetTo(const Position & endPos, Position & retOffset) const;
|
||||
|
||||
float GetAngle(const Position *pos) const;
|
||||
float GetAngle(float x, float y) const;
|
||||
float GetRelativeAngle(const Position *pos) const
|
||||
@@ -461,6 +465,7 @@ struct Position
|
||||
{ return GetExactDistSq(pos) < dist * dist; }
|
||||
bool HasInArc(float arcangle, const Position *pos) const;
|
||||
bool HasInLine(const Unit *target, float distance, float width) const;
|
||||
std::string ToString() const;
|
||||
};
|
||||
ByteBuffer &operator>>(ByteBuffer& buf, Position::PositionXYZOStreamer const & streamer);
|
||||
ByteBuffer & operator<<(ByteBuffer& buf, Position::PositionXYZStreamer const & streamer);
|
||||
@@ -507,6 +512,7 @@ struct MovementInfo
|
||||
uint32 GetMovementFlags() { return flags; }
|
||||
void AddMovementFlag(uint32 flag) { flags |= flag; }
|
||||
bool HasMovementFlag(uint32 flag) const { return flags & flag; }
|
||||
void OutDebug();
|
||||
};
|
||||
|
||||
#define MAPID_INVALID 0xFFFFFFFF
|
||||
@@ -536,6 +542,8 @@ class GridObject
|
||||
|
||||
class WorldObject : public Object, public WorldLocation
|
||||
{
|
||||
protected:
|
||||
explicit WorldObject();
|
||||
public:
|
||||
virtual ~WorldObject();
|
||||
|
||||
@@ -767,11 +775,17 @@ class WorldObject : public Object, public WorldLocation
|
||||
|
||||
// Transports
|
||||
Transport *GetTransport() const { return m_transport; }
|
||||
virtual float GetTransOffsetX() const { return 0; }
|
||||
virtual float GetTransOffsetY() const { return 0; }
|
||||
virtual float GetTransOffsetZ() const { return 0; }
|
||||
virtual float GetTransOffsetO() const { return 0; }
|
||||
virtual uint32 GetTransTime() const { return 0; }
|
||||
virtual int8 GetTransSeat() const { return -1; }
|
||||
virtual uint64 GetTransGUID() const;
|
||||
void SetTransport(Transport *t) { m_transport = t; }
|
||||
|
||||
MovementInfo m_movementInfo;
|
||||
protected:
|
||||
explicit WorldObject();
|
||||
std::string m_name;
|
||||
bool m_isActive;
|
||||
ZoneScript *m_zoneScript;
|
||||
|
||||
@@ -105,6 +105,7 @@ void MapManager::LoadTransports()
|
||||
|
||||
//If we someday decide to use the grid to track transports, here:
|
||||
t->SetMap(sMapMgr.CreateMap(mapid, t, 0));
|
||||
t->AddToWorld();
|
||||
|
||||
for (TransportNPCSet::const_iterator i = m_TransportNPCMap[entry].begin(); i != m_TransportNPCMap[entry].end(); ++i)
|
||||
{
|
||||
@@ -506,10 +507,12 @@ void Transport::TeleportTransport(uint32 newMapid, float x, float y, float z)
|
||||
}
|
||||
m_NPCPassengerSet.clear();
|
||||
|
||||
RemoveFromWorld();
|
||||
ResetMap();
|
||||
Map * newMap = sMapMgr.CreateMap(newMapid, this, 0);
|
||||
SetMap(newMap);
|
||||
ASSERT (GetMap());
|
||||
AddToWorld();
|
||||
|
||||
if (oldMap != newMap)
|
||||
{
|
||||
|
||||
@@ -15642,6 +15642,16 @@ Creature *Unit::GetVehicleCreatureBase() const
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint64 Unit::GetTransGUID() const
|
||||
{
|
||||
if (GetVehicle())
|
||||
return GetVehicle()->GetBase()->GetGUID();
|
||||
if (GetTransport())
|
||||
return GetTransport()->GetGUID();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Unit::IsInPartyWith(Unit const *unit) const
|
||||
{
|
||||
if (this == unit)
|
||||
|
||||
@@ -1534,7 +1534,7 @@ class Unit : public WorldObject
|
||||
|
||||
CharmInfo* GetCharmInfo() { return m_charmInfo; }
|
||||
CharmInfo* InitCharmInfo();
|
||||
void DeleteCharmInfo();
|
||||
void DeleteCharmInfo();
|
||||
void UpdateCharmAI();
|
||||
//Player * GetMoverSource() const;
|
||||
Player * m_movedPlayer;
|
||||
@@ -1955,6 +1955,7 @@ class Unit : public WorldObject
|
||||
float GetTransOffsetO() const { return m_movementInfo.t_pos.GetOrientation(); }
|
||||
uint32 GetTransTime() const { return m_movementInfo.t_time; }
|
||||
int8 GetTransSeat() const { return m_movementInfo.t_seat; }
|
||||
uint64 GetTransGUID() const;
|
||||
|
||||
bool m_ControlledByPlayer;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user