From 7cb61f625955248c83d6737545a77bdcde1a952f Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 8 Mar 2015 16:33:56 +0200 Subject: [PATCH] Fix mangos GetDist methods - no exact dist methods on mangos based --- WorldObjectMethods.h | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/WorldObjectMethods.h b/WorldObjectMethods.h index 420276a..68b2e52 100644 --- a/WorldObjectMethods.h +++ b/WorldObjectMethods.h @@ -468,16 +468,25 @@ namespace LuaWorldObject */ int GetExactDistance(Eluna* /*E*/, lua_State* L, WorldObject* obj) { + float x, y, z; + obj->GetPosition(x, y, z); WorldObject* target = Eluna::CHECKOBJ(L, 2, false); if (target && target->IsInWorld()) - Eluna::Push(L, obj->GetExactDist(target)); + { + float x2, y2, z2; + target->GetPosition(x2, y2, z2); + x -= x2; + y -= y2; + z -= z2; + } else { - float X = Eluna::CHECKVAL(L, 2); - float Y = Eluna::CHECKVAL(L, 3); - float Z = Eluna::CHECKVAL(L, 4); - Eluna::Push(L, obj->GetExactDist(X, Y, Z)); + x -= Eluna::CHECKVAL(L, 2); + y -= Eluna::CHECKVAL(L, 3); + z -= Eluna::CHECKVAL(L, 4); } + + Eluna::Push(L, std::sqrt(x*x + y*y + z*z)); return 1; } @@ -525,15 +534,23 @@ namespace LuaWorldObject */ int GetExactDistance2d(Eluna* /*E*/, lua_State* L, WorldObject* obj) { + float x, y, z; + obj->GetPosition(x, y, z); WorldObject* target = Eluna::CHECKOBJ(L, 2, false); if (target && target->IsInWorld()) - Eluna::Push(L, obj->GetExactDist2d(target)); + { + float x2, y2, z2; + target->GetPosition(x2, y2, z2); + x -= x2; + y -= y2; + } else { - float X = Eluna::CHECKVAL(L, 2); - float Y = Eluna::CHECKVAL(L, 3); - Eluna::Push(L, obj->GetExactDist2d(X, Y)); + x -= Eluna::CHECKVAL(L, 2); + y -= Eluna::CHECKVAL(L, 3); } + + Eluna::Push(L, std::sqrt(x*x + y*y)); return 1; }