lua GetDistance might be broken

Come in here to talk about your sky-net style world-destroying super bots!

Moderator: Defcon moderators

User avatar
roflamingo
level3
level3
Posts: 404
Joined: Fri Jan 19, 2007 10:25 am

lua GetDistance might be broken

Postby roflamingo » Tue Feb 16, 2010 7:00 am

GetDistance (longitude1, latitude1, longitude2, latitude2)
Returns the ingame distance between the two given points (longitude1, latitude1) and (longitude2, latitude2).

Code: Select all

x1 = 12.5
 y1 = 4
 x2 = 12.5
 y2 = 4
 SendChat(GetDistance(x1, y1, x2, y2 ))


Returns 8.5. Should return 0.

I wrote a new function for this, use freely if desired:

Code: Select all

function GetRealDistance(x1,y1,x2,y2)
  dist = math.sqrt((x2-x1)^2 + (y2-y1)^2)
  return dist
  end
Last edited by roflamingo on Tue Feb 16, 2010 8:54 am, edited 1 time in total.
User avatar
trickser
level5
level5
Posts: 1823
Joined: Thu Mar 06, 2008 2:15 pm
Location: The Senate ; GMT+1
Contact:

Postby trickser » Tue Feb 16, 2010 8:32 am

use [code]Hello World[/code] tags
User avatar
roflamingo
level3
level3
Posts: 404
Joined: Fri Jan 19, 2007 10:25 am

Postby roflamingo » Tue Feb 16, 2010 8:52 am

Thx, and fixed
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Tue Feb 16, 2010 4:21 pm

I hadn't got so far as to use GetDistance(), but I tried it out and it does provide some strange results.

Code: Select all

SendChat(GetGameTick() / 10 .. " seconds")
   
   SendChat(GetDistance (siLos[1]:GetLongitude(), siLos[1]:GetLatitude(), siLos[2]:GetLongitude(), siLos[2]:GetLatitude())) <- find distance between Silo 1 and Silo 2

   SendChat(GetDistance (siLos[1]:GetLongitude(), siLos[1]:GetLatitude(), siLos[1]:GetLongitude(), siLos[1]:GetLatitude()))<- find distance between Silo 1 and Silo 1 (expect to be zero)

   SendChat(GetDistance ( -0.166700, 51.500000,  -74.000000, 40.750000) .. " London to New York") <- find distance between London and New York

   WhiteboardDraw(-0.166700, 51.500000,  -74.000000, 40.750000) <- Line from London to New York
   WhiteboardDraw(siLos[1]:GetLongitude(), siLos[1]:GetLatitude(), siLos[2]:GetLongitude(), siLos[2]:GetLatitude()) <- Line from Silo 1 to Silo 2
   WhiteboardDraw(siLos[1]:GetLongitude(), siLos[1]:GetLatitude(), siLos[1]:GetLongitude(), siLos[1]:GetLatitude()) <- Line from Silo 1 to Silo 1 (expect to see dot, or nothing)


Image

Clearly, my silos are not as far apart as New York and London are. :shock: Silo 1 and 2 are the bottom row, starting on the left. If you ignore the other whiteboard markings (squares), you can see the line from 1 to 2. Also, I didn't realize till now that London is basically zero Longitude on the grid. Hmm. :P (that cross is zero x, zero y, visual aid for me)

Edit: Oh yeah, I was on your server last night for a long time, where were you?!
User avatar
roflamingo
level3
level3
Posts: 404
Joined: Fri Jan 19, 2007 10:25 am

Postby roflamingo » Tue Feb 16, 2010 4:26 pm

Ya GetDistance has some things backwards that yield bad results. For the ultimate proof, use the function to find the distance between a city and itself....should be zero, but it isn't!

I thought I should mention it because you will likely use the function for planes, ships and nukes!


...
I had just fixed a bug and went to the gym. I came back and saw you had been on the server but had logged off....catch you later! :)
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Tue Feb 16, 2010 5:12 pm

I sent a message through the mailing list, so maybe somebody will notice and fix it.

Edit: And results...

Peter wrote:Indeed, it looks like the source code for the binding of GetDistance
and GetSailDistance is incorrect. It uses the value given as x2 in
place of y2 - the thunk_GetMapDistance function is using arguments 1,
2, 3, 3, whereas it should be using 1, 2, 3, 4:

static int thunk_GetMapDistance(lua_State *L)
{
lbot_pushnumber(L,
(g_pDefconInterface->*F)(static_cast<float>(luaL_checknumber(L, 1)),
static_cast<float>(luaL_checknumber(L, 2)),
static_cast<float>(luaL_checknumber(L, 3)),
static_cast<float>(luaL_checknumber(L, 3))));
return 1;
}

I'll try to fix this and put out a new version soon (though this may
not be until the weekend).


Regards,
Peter
User avatar
roflamingo
level3
level3
Posts: 404
Joined: Fri Jan 19, 2007 10:25 am

Postby roflamingo » Tue Feb 16, 2010 7:03 pm

Wow, that's great! Thanks for sending that through

Return to “AI Bots”

Who is online

Users browsing this forum: No registered users and 3 guests