Merge branch 'master' of https://github.com/azerothcore/azerothcore-wotlk into dir-restructure

This commit is contained in:
Yehonal
2017-12-21 11:26:43 +01:00
445 changed files with 49192 additions and 15431 deletions

View File

@@ -1095,9 +1095,13 @@ bool WorldObject::IsWithinLOSInMap(const WorldObject* obj) const
if (!IsInMap(obj))
return false;
float ox, oy, oz;
obj->GetPosition(ox, oy, oz);
return IsWithinLOS(ox, oy, oz);
float x, y, z;
if (obj->GetTypeId() == TYPEID_PLAYER)
obj->GetPosition(x, y, z);
else
obj->GetHitSpherePointFor(GetPosition(), x, y, z);
return IsWithinLOS(x, y, z);
}
bool WorldObject::IsWithinLOS(float ox, float oy, float oz) const
@@ -1107,11 +1111,36 @@ bool WorldObject::IsWithinLOS(float ox, float oy, float oz) const
VMAP::IVMapManager* vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
return vMapManager->isInLineOfSight(GetMapId(), x, y, z+2.0f, ox, oy, oz+2.0f);*/
if (IsInWorld())
return GetMap()->isInLineOfSight(GetPositionX(), GetPositionY(), GetPositionZ()+2.f, ox, oy, oz+2.f, GetPhaseMask());
{
float x, y, z;
if (GetTypeId() == TYPEID_PLAYER)
GetPosition(x, y, z);
else
GetHitSpherePointFor({ ox, oy, oz }, x, y, z);
return GetMap()->isInLineOfSight(x, y, z + 2.0f, ox, oy, oz + 2.0f, GetPhaseMask());
}
return true;
}
Position WorldObject::GetHitSpherePointFor(Position const& dest) const
{
G3D::Vector3 vThis(GetPositionX(), GetPositionY(), GetPositionZ());
G3D::Vector3 vObj(dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ());
G3D::Vector3 contactPoint = vThis + (vObj - vThis).directionOrZero() * std::min(dest.GetExactDist(this), GetObjectSize());
return Position(contactPoint.x, contactPoint.y, contactPoint.z, GetAngle(contactPoint.x, contactPoint.y));
}
void WorldObject::GetHitSpherePointFor(Position const& dest, float& x, float& y, float& z) const
{
Position pos = GetHitSpherePointFor(dest);
x = pos.GetPositionX();
y = pos.GetPositionY();
z = pos.GetPositionZ();
}
bool WorldObject::GetDistanceOrder(WorldObject const* obj1, WorldObject const* obj2, bool is3D /* = true */) const
{
float dx1 = GetPositionX() - obj1->GetPositionX();
@@ -2402,123 +2431,33 @@ void WorldObject::GetNearPoint(WorldObject const* searcher, float &x, float &y,
else
UpdateAllowedPositionZ(x, y, z);
/*
// if detection disabled, return first point
if (!sWorld->getIntConfig(CONFIG_DETECT_POS_COLLISION))
{
UpdateGroundPositionZ(x, y, z); // update to LOS height if available
if (!sWorld->getBoolConfig(CONFIG_DETECT_POS_COLLISION))
return;
}
// or remember first point
// return if the point is already in LoS
if (IsWithinLOS(x, y, z))
return;
// remember first point
float first_x = x;
float first_y = y;
bool first_los_conflict = false; // first point LOS problems
float first_z = z;
// prepare selector for work
ObjectPosSelector selector(GetPositionX(), GetPositionY(), GetObjectSize(), distance2d+searcher_size);
// adding used positions around object
// loop in a circle to look for a point in LoS using small steps
for (float angle = float(M_PI) / 8; angle < float(M_PI) * 2; angle += float(M_PI) / 8)
{
CellCoord p(Trinity::ComputeCellCoord(GetPositionX(), GetPositionY()));
Cell cell(p);
cell.SetNoCreate();
Trinity::NearUsedPosDo u_do(*this, searcher, absAngle, selector);
Trinity::WorldObjectWorker<Trinity::NearUsedPosDo> worker(this, u_do);
TypeContainerVisitor<Trinity::WorldObjectWorker<Trinity::NearUsedPosDo>, GridTypeMapContainer > grid_obj_worker(worker);
TypeContainerVisitor<Trinity::WorldObjectWorker<Trinity::NearUsedPosDo>, WorldTypeMapContainer > world_obj_worker(worker);
CellLock<GridReadGuard> cell_lock(cell, p);
cell_lock->Visit(cell_lock, grid_obj_worker, *GetMap(), *this, distance2d);
cell_lock->Visit(cell_lock, world_obj_worker, *GetMap(), *this, distance2d);
}
// maybe can just place in primary position
if (selector.CheckOriginal())
{
UpdateGroundPositionZ(x, y, z); // update to LOS height if available
if (IsWithinLOS(x, y, z))
return;
first_los_conflict = true; // first point have LOS problems
}
float angle; // candidate of angle for free pos
// special case when one from list empty and then empty side preferred
if (selector.FirstAngle(angle))
{
GetNearPoint2D(x, y, distance2d, absAngle+angle);
GetNearPoint2D(x, y, distance2d + searcher_size, absAngle + angle);
z = GetPositionZ();
UpdateGroundPositionZ(x, y, z); // update to LOS height if available
UpdateAllowedPositionZ(x, y, z);
if (IsWithinLOS(x, y, z))
return;
}
// set first used pos in lists
selector.InitializeAngle();
// select in positions after current nodes (selection one by one)
while (selector.NextAngle(angle)) // angle for free pos
{
GetNearPoint2D(x, y, distance2d, absAngle+angle);
z = GetPositionZ();
UpdateGroundPositionZ(x, y, z); // update to LOS height if available
if (IsWithinLOS(x, y, z))
return;
}
// BAD NEWS: not free pos (or used or have LOS problems)
// Attempt find _used_ pos without LOS problem
if (!first_los_conflict)
{
x = first_x;
y = first_y;
UpdateGroundPositionZ(x, y, z); // update to LOS height if available
return;
}
// special case when one from list empty and then empty side preferred
if (selector.IsNonBalanced())
{
if (!selector.FirstAngle(angle)) // _used_ pos
{
GetNearPoint2D(x, y, distance2d, absAngle+angle);
z = GetPositionZ();
UpdateGroundPositionZ(x, y, z); // update to LOS height if available
if (IsWithinLOS(x, y, z))
return;
}
}
// set first used pos in lists
selector.InitializeAngle();
// select in positions after current nodes (selection one by one)
while (selector.NextUsedAngle(angle)) // angle for used pos but maybe without LOS problem
{
GetNearPoint2D(x, y, distance2d, absAngle+angle);
z = GetPositionZ();
UpdateGroundPositionZ(x, y, z); // update to LOS height if available
if (IsWithinLOS(x, y, z))
return;
}
// BAD BAD NEWS: all found pos (free and used) have LOS problem :(
// still not in LoS, give up and return first position found
x = first_x;
y = first_y;
UpdateGroundPositionZ(x, y, z); // update to LOS height if available
*/
z = first_z;
}
bool WorldObject::GetClosePoint(float &x, float &y, float &z, float size, float distance2d, float angle, const WorldObject* forWho, bool force) const

View File

@@ -365,6 +365,17 @@ class Object
struct Position
{
Position(float x = 0, float y = 0, float z = 0, float o = 0)
: m_positionX(x), m_positionY(y), m_positionZ(z), m_orientation(NormalizeOrientation(o)) { }
Position(Position const& loc) { Relocate(loc); }
struct PositionXYStreamer
{
explicit PositionXYStreamer(Position& pos) : Pos(&pos) { }
Position* Pos;
};
struct PositionXYZStreamer
{
explicit PositionXYZStreamer(Position& pos) : m_pos(&pos) {}
@@ -382,19 +393,38 @@ struct Position
float m_positionZ;
float m_orientation;
bool operator==(Position const &a);
inline bool operator!=(Position const &a)
{
return !(operator==(a));
}
void Relocate(float x, float y)
{ m_positionX = x; m_positionY = y;}
{
m_positionX = x; m_positionY = y;
}
void Relocate(float x, float y, float z)
{ m_positionX = x; m_positionY = y; m_positionZ = z; }
{
m_positionX = x; m_positionY = y; m_positionZ = z;
}
void Relocate(float x, float y, float z, float orientation)
{ m_positionX = x; m_positionY = y; m_positionZ = z; m_orientation = orientation; }
{
m_positionX = x; m_positionY = y; m_positionZ = z; m_orientation = 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; }
{
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; }
{
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; }
{
m_orientation = orientation;
}
float GetPositionX() const { return m_positionX; }
float GetPositionY() const { return m_positionY; }
@@ -402,17 +432,26 @@ struct Position
float GetOrientation() const { return m_orientation; }
void GetPosition(float &x, float &y) const
{ x = m_positionX; y = m_positionY; }
{
x = m_positionX; y = m_positionY;
}
void GetPosition(float &x, float &y, float &z) const
{ x = m_positionX; y = m_positionY; z = m_positionZ; }
{
x = m_positionX; y = m_positionY; z = m_positionZ;
}
void GetPosition(float &x, float &y, float &z, float &o) const
{ x = m_positionX; y = m_positionY; z = m_positionZ; o = m_orientation; }
{
x = m_positionX; y = m_positionY; z = m_positionZ; o = m_orientation;
}
void GetPosition(Position* pos) const
{
if (pos)
pos->Relocate(m_positionX, m_positionY, m_positionZ, m_orientation);
}
Position GetPosition() const { return *this; }
Position::PositionXYZStreamer PositionXYZStream()
{
return PositionXYZStreamer(*this);
@@ -425,39 +464,65 @@ struct Position
bool IsPositionValid() const;
float GetExactDist2dSq(float x, float y) const
{ float dx = m_positionX - x; float dy = m_positionY - y; return dx*dx + dy*dy; }
{
float dx = m_positionX - x; float dy = m_positionY - y; return dx*dx + dy*dy;
}
float GetExactDist2d(const float x, const float y) const
{ return sqrt(GetExactDist2dSq(x, y)); }
{
return sqrt(GetExactDist2dSq(x, y));
}
float GetExactDist2dSq(const Position* pos) const
{ float dx = m_positionX - pos->m_positionX; float dy = m_positionY - pos->m_positionY; return dx*dx + dy*dy; }
{
float dx = m_positionX - pos->m_positionX; float dy = m_positionY - pos->m_positionY; return dx*dx + dy*dy;
}
float GetExactDist2d(const Position* pos) const
{ return sqrt(GetExactDist2dSq(pos)); }
{
return sqrt(GetExactDist2dSq(pos));
}
float GetExactDistSq(float x, float y, float z) const
{ float dz = m_positionZ - z; return GetExactDist2dSq(x, y) + dz*dz; }
{
float dz = m_positionZ - z; return GetExactDist2dSq(x, y) + dz*dz;
}
float GetExactDist(float x, float y, float z) const
{ return sqrt(GetExactDistSq(x, y, z)); }
{
return sqrt(GetExactDistSq(x, y, z));
}
float GetExactDistSq(const Position* pos) const
{ float dx = m_positionX - pos->m_positionX; float dy = m_positionY - pos->m_positionY; float dz = m_positionZ - pos->m_positionZ; return dx*dx + dy*dy + dz*dz; }
{
float dx = m_positionX - pos->m_positionX; float dy = m_positionY - pos->m_positionY; float dz = m_positionZ - pos->m_positionZ; return dx*dx + dy*dy + dz*dz;
}
float GetExactDist(const Position* pos) const
{ return sqrt(GetExactDistSq(pos)); }
{
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
{ return GetAngle(pos) - m_orientation; }
{
return GetAngle(pos) - m_orientation;
}
float GetRelativeAngle(float x, float y) const { return GetAngle(x, y) - m_orientation; }
void GetSinCos(float x, float y, float &vsin, float &vcos) const;
bool IsInDist2d(float x, float y, float dist) const
{ return GetExactDist2dSq(x, y) < dist * dist; }
{
return GetExactDist2dSq(x, y) < dist * dist;
}
bool IsInDist2d(const Position* pos, float dist) const
{ return GetExactDist2dSq(pos) < dist * dist; }
{
return GetExactDist2dSq(pos) < dist * dist;
}
bool IsInDist(float x, float y, float z, float dist) const
{ return GetExactDistSq(x, y, z) < dist * dist; }
{
return GetExactDistSq(x, y, z) < dist * dist;
}
bool IsInDist(const Position* pos, float dist) const
{ return GetExactDistSq(pos) < dist * dist; }
{
return GetExactDistSq(pos) < dist * dist;
}
bool IsWithinBox(const Position& center, float xradius, float yradius, float zradius) const;
bool HasInArc(float arcangle, const Position* pos, float targetRadius = 0.0f) const;
@@ -479,10 +544,13 @@ struct Position
return fmod(o, 2.0f * static_cast<float>(M_PI));
}
};
ByteBuffer& operator>>(ByteBuffer& buf, Position::PositionXYZOStreamer const& streamer);
ByteBuffer& operator<<(ByteBuffer& buf, Position::PositionXYStreamer const& streamer);
ByteBuffer& operator >> (ByteBuffer& buf, Position::PositionXYStreamer const& streamer);
ByteBuffer& operator<<(ByteBuffer& buf, Position::PositionXYZStreamer const& streamer);
ByteBuffer& operator>>(ByteBuffer& buf, Position::PositionXYZStreamer const& streamer);
ByteBuffer& operator >> (ByteBuffer& buf, Position::PositionXYZStreamer const& streamer);
ByteBuffer& operator<<(ByteBuffer& buf, Position::PositionXYZOStreamer const& streamer);
ByteBuffer& operator >> (ByteBuffer& buf, Position::PositionXYZOStreamer const& streamer);
struct MovementInfo
{
@@ -785,6 +853,8 @@ class WorldObject : public Object, public WorldLocation
}
bool IsWithinLOS(float x, float y, float z) const;
bool IsWithinLOSInMap(const WorldObject* obj) const;
Position GetHitSpherePointFor(Position const& dest) const;
void GetHitSpherePointFor(Position const& dest, float& x, float& y, float& z) const;
bool GetDistanceOrder(WorldObject const* obj1, WorldObject const* obj2, bool is3D = true) const;
bool IsInRange(WorldObject const* obj, float minRange, float maxRange, bool is3D = true) const;
bool IsInRange2d(float x, float y, float minRange, float maxRange) const;