diff --git a/src/game/Object.cpp b/src/game/Object.cpp index 1478ff971..20601091f 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -1114,16 +1114,25 @@ float WorldObject::GetDistanceZ(const WorldObject* obj) const return ( dist > 0 ? dist : 0); } -bool WorldObject::IsWithinDist(float x, float y, float z, float dist2compare, bool is3D) const +bool WorldObject::IsWithinDist(float x, float y, float z, float dist2compare) const +{ + float dx = GetPositionX() - x; + float dy = GetPositionY() - y; + float dz = GetPositionZ() - z; + float distsq = dx*dx + dy*dy + dz*dz; + + float sizefactor = GetObjectSize(); + float maxdist = dist2compare + sizefactor; + + return distsq < maxdist * maxdist; +} + +bool WorldObject::IsWithinDist2d(float x, float y, float dist2compare) const { float dx = GetPositionX() - x; float dy = GetPositionY() - y; float distsq = dx*dx + dy*dy; - if(is3D) - { - float dz = GetPositionZ() - z; - distsq += dz*dz; - } + float sizefactor = GetObjectSize(); float maxdist = dist2compare + sizefactor; @@ -1185,12 +1194,16 @@ bool WorldObject::GetDistanceOrder(WorldObject const* obj1, WorldObject const* o return distsq1 < distsq2; } -bool WorldObject::IsInRange(WorldObject const* obj, float minRange, float maxRange) const +bool WorldObject::IsInRange(WorldObject const* obj, float minRange, float maxRange, bool is3D /* = true */) const { float dx = GetPositionX() - obj->GetPositionX(); float dy = GetPositionY() - obj->GetPositionY(); - float dz = GetPositionZ() - obj->GetPositionZ(); - float distsq = dx*dx + dy*dy + dz*dz; + float distsq = dx*dx + dy*dy; + if(is3D) + { + float dz = GetPositionZ() - obj->GetPositionZ(); + distsq += dz*dz; + } float sizefactor = GetObjectSize() + obj->GetObjectSize(); @@ -1218,6 +1231,23 @@ bool WorldObject::IsInRange2d(float x, float y, float minRange, float maxRange) return distsq < maxdist * maxdist; } +bool WorldObject::IsInRange(float x, float y, float z, float minRange, float maxRange) const +{ + float dx = GetPositionX() - x; + float dy = GetPositionY() - y; + float dz = GetPositionZ() - z; + float distsq = dx*dx + dy*dy + dz*dz; + + float sizefactor = GetObjectSize(); + + float mindist = minRange + sizefactor; + if(distsq < mindist * mindist) + return false; + + float maxdist = maxRange + sizefactor; + return distsq < maxdist * maxdist; +} + float WorldObject::GetAngle(const WorldObject* obj) const { if(!obj) return 0; diff --git a/src/game/Object.h b/src/game/Object.h index e9953d797..f77ceeead 100644 --- a/src/game/Object.h +++ b/src/game/Object.h @@ -433,7 +433,8 @@ class MANGOS_DLL_SPEC WorldObject : public Object return IsInWorld() && obj->IsInWorld() && GetMapId()==obj->GetMapId() && GetInstanceId()==obj->GetInstanceId() && InSamePhase(obj); } - bool IsWithinDist(float x, float y, float z, float dist2compare, bool is3D = true) const; + bool IsWithinDist(float x, float y, float z, float dist2compare) const; + bool IsWithinDist2d(float x, float y, float dist2compare) const; bool _IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D) const; bool IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D = true) const // use only if you will sure about placing both object at same map @@ -447,8 +448,9 @@ class MANGOS_DLL_SPEC WorldObject : public Object bool IsWithinLOS(float x, float y, float z) const; bool IsWithinLOSInMap(const WorldObject* obj) const; bool GetDistanceOrder(WorldObject const* obj1, WorldObject const* obj2, bool is3D = true) const; - bool IsInRange(WorldObject const* obj, float minRange, float maxRange) 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; + bool IsInRange(float x, float y, float z, float minRange, float maxRange) const; float GetAngle( const WorldObject* obj ) const; float GetAngle( const float x, const float y ) const; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index c2ab7f32e..709a95ae9 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "7827" + #define REVISION_NR "7828" #endif // __REVISION_NR_H__