aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormegamage <none@none>2009-04-30 16:13:57 -0500
committermegamage <none@none>2009-04-30 16:13:57 -0500
commiteb9328e4dbd5e136728f90ae794da1066688953f (patch)
tree824363814e84c5aa1b90ff51deb183e4e435de8b /src
parent83758cb2e07be8c8dab9dffed0cbba760260f952 (diff)
*Fix the calculation of isInLine.
--HG-- branch : trunk
Diffstat (limited to 'src')
-rw-r--r--src/game/Object.cpp7
-rw-r--r--src/game/Object.h1
-rw-r--r--src/game/Unit.cpp7
3 files changed, 11 insertions, 4 deletions
diff --git a/src/game/Object.cpp b/src/game/Object.cpp
index e7d07422c7a..fe3239e9d6b 100644
--- a/src/game/Object.cpp
+++ b/src/game/Object.cpp
@@ -1153,6 +1153,13 @@ float WorldObject::GetDistance2d(float x, float y) const
return ( dist > 0 ? dist : 0);
}
+float WorldObject::GetExactDistance2d(const float x, const float y) const
+{
+ float dx = GetPositionX() - x;
+ float dy = GetPositionY() - y;
+ return sqrt((dx*dx) + (dy*dy));
+}
+
float WorldObject::GetDistance(const float x, const float y, const float z) const
{
float dx = GetPositionX() - x;
diff --git a/src/game/Object.h b/src/game/Object.h
index 3840337e437..328df30492a 100644
--- a/src/game/Object.h
+++ b/src/game/Object.h
@@ -438,6 +438,7 @@ class TRINITY_DLL_SPEC WorldObject : public Object
float GetDistanceSq(const float &x, const float &y, const float &z) const;
float GetDistance2d(const WorldObject* obj) const;
float GetDistance2d(const float x, const float y) const;
+ float GetExactDistance2d(const float x, const float y) const;
float GetDistanceZ(const WorldObject* obj) const;
bool IsInMap(const WorldObject* obj) const { return GetMapId()==obj->GetMapId() && GetInstanceId()==obj->GetInstanceId(); }
bool IsWithinDistInMap(const WorldObject* obj, const float dist2compare, const bool is3D = true) const;
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index 1bda587f89e..756a1ac7d43 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -3525,10 +3525,9 @@ bool Unit::isInBack(Unit const* target, float distance, float arc) const
bool Unit::isInLine(Unit const* target, float distance) const
{
if(!HasInArc(M_PI, target) || !IsWithinDistInMap(target, distance)) return false;
- float width = (GetObjectSize() / 2 + target->GetObjectSize()) / 2;
- float angle = GetAngle(target);
- angle -= GetOrientation();
- return abs(sin(angle)) * distance < width;
+ float width = GetObjectSize() + target->GetObjectSize() * 0.5f;
+ float angle = GetAngle(target) - GetOrientation();
+ return abs(sin(angle)) * GetExactDistance2d(target->GetPositionX(), target->GetPositionY()) < width;
}
bool Unit::isInAccessiblePlaceFor(Creature const* c) const