Add basic support for NPCs on transports; DB data required.
Currently no support for combat while the transport is in motion. Based on a patch by Socolin. Fixes issue #168 --HG-- branch : trunk
This commit is contained in:
@@ -1151,6 +1151,7 @@ WorldObject::WorldObject()
|
||||
, m_name("")
|
||||
, m_notifyflags(0), m_executed_notifies(0)
|
||||
{
|
||||
m_transport = NULL;
|
||||
}
|
||||
|
||||
void WorldObject::SetWorldObject(bool on)
|
||||
@@ -1235,6 +1236,22 @@ float WorldObject::GetDistanceZ(const WorldObject* obj) const
|
||||
|
||||
bool WorldObject::_IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D) const
|
||||
{
|
||||
float sizefactor = GetObjectSize() + obj->GetObjectSize();
|
||||
float maxdist = dist2compare + sizefactor;
|
||||
|
||||
if (m_transport && obj->GetTransport() && obj->GetTransport()->GetGUIDLow() == m_transport->GetGUIDLow())
|
||||
{
|
||||
float dtx = m_movementInfo.t_x - obj->m_movementInfo.t_x;
|
||||
float dty = m_movementInfo.t_y - obj->m_movementInfo.t_y;
|
||||
float disttsq = dtx * dtx + dty * dty;
|
||||
if (is3D)
|
||||
{
|
||||
float dtz = m_movementInfo.t_z - obj->m_movementInfo.t_z;
|
||||
disttsq += dtz * dtz;
|
||||
}
|
||||
return disttsq < (maxdist * maxdist);
|
||||
}
|
||||
|
||||
float dx = GetPositionX() - obj->GetPositionX();
|
||||
float dy = GetPositionY() - obj->GetPositionY();
|
||||
float distsq = dx*dx + dy*dy;
|
||||
@@ -1243,8 +1260,6 @@ bool WorldObject::_IsWithinDist(WorldObject const* obj, float dist2compare, bool
|
||||
float dz = GetPositionZ() - obj->GetPositionZ();
|
||||
distsq += dz*dz;
|
||||
}
|
||||
float sizefactor = GetObjectSize() + obj->GetObjectSize();
|
||||
float maxdist = dist2compare + sizefactor;
|
||||
|
||||
return distsq < maxdist * maxdist;
|
||||
}
|
||||
|
||||
@@ -115,9 +115,46 @@ class Vehicle;
|
||||
class CreatureAI;
|
||||
class ZoneScript;
|
||||
class Unit;
|
||||
class Transport;
|
||||
|
||||
typedef UNORDERED_MAP<Player*, UpdateData> UpdateDataMapType;
|
||||
|
||||
struct MovementInfo
|
||||
{
|
||||
// common
|
||||
uint64 guid;
|
||||
uint32 flags;
|
||||
uint16 unk1;
|
||||
uint32 time;
|
||||
float x, y, z, o;
|
||||
// transport
|
||||
uint64 t_guid;
|
||||
float t_x, t_y, t_z, t_o;
|
||||
uint32 t_time;
|
||||
int8 t_seat;
|
||||
// swimming and unknown
|
||||
float s_pitch;
|
||||
// last fall time
|
||||
uint32 fallTime;
|
||||
// jumping
|
||||
float j_zspeed, j_sinAngle, j_cosAngle, j_xyspeed;
|
||||
// spline
|
||||
float u_unk1;
|
||||
|
||||
MovementInfo()
|
||||
{
|
||||
flags = 0;
|
||||
time = t_time = fallTime = 0;
|
||||
unk1 = 0;
|
||||
x = y = z = o = t_x = t_y = t_z = t_o = s_pitch = j_zspeed = j_sinAngle = j_cosAngle = j_xyspeed = u_unk1 = 0.0f;
|
||||
t_guid = 0;
|
||||
}
|
||||
|
||||
uint32 GetMovementFlags() { return flags; }
|
||||
void AddMovementFlag(uint32 flag) { flags |= flag; }
|
||||
bool HasMovementFlag(uint32 flag) const { return flags & flag; }
|
||||
};
|
||||
|
||||
class Object
|
||||
{
|
||||
public:
|
||||
@@ -696,12 +733,21 @@ class WorldObject : public Object, public WorldLocation
|
||||
|
||||
bool m_isWorldObject;
|
||||
uint32 LastUsedScriptID;
|
||||
|
||||
// Transports
|
||||
Transport *GetTransport() const { return m_transport; }
|
||||
void SetTransport(Transport *t) { m_transport = t; }
|
||||
|
||||
MovementInfo m_movementInfo;
|
||||
protected:
|
||||
explicit WorldObject();
|
||||
std::string m_name;
|
||||
bool m_isActive;
|
||||
ZoneScript *m_zoneScript;
|
||||
|
||||
// transports
|
||||
Transport *m_transport;
|
||||
|
||||
//these functions are used mostly for Relocate() and Corpse/Player specific stuff...
|
||||
//use them ONLY in LoadFromDB()/Create() funcs and nowhere else!
|
||||
//mapId/instanceId should be set in SetMap() function!
|
||||
|
||||
Reference in New Issue
Block a user