Author Topic: Latitude/Longitude from X/Y.... Finally!  (Read 2235 times)

0 Members and 1 Guest are viewing this topic.

Offline altiricTopic starter

  • Jr. Member
  • **
  • Posts: 81
  • Activity:
    0%
  • Reputation Power: 2
  • altiric has no influence.
  • Respect: +4
  • Referrals: 1
    • View Profile
Latitude/Longitude from X/Y.... Finally!
« on: August 28, 2021, 01:47:41 PM »
0
This has been an idea of mine (and im sure many others) for quite some time. I was just never able to actually hammer it out til now. I was writing up an area recognition routine for my new hunting script and ran into a few issues. Through the process of resolving it, i stumbled across this solution! First i came up with a way to return N/E/W/S or NE/NW/SE/SW/etc from one location to another (character position to an object). I then set the object to lord british's throne, figure out how many steps and in which direction i am, an boom! a couple calculations/guesses later and i had my data. This is a quick and dirty example of finding long/lat simple based off an X/Y coordinate!

Code: [Select]
gosub Header
repeat
  if #CHARPOSX <> %LastX || #CHARPOSY <> %LastY
  {
    set %LastX #CHARPOSX
    set %LastY #CHARPOSY
    set %xyz #CHARPOSX , X , #SPC , #CHARPOSY , Y , #SPC , #CHARPOSZ , Z
    menu set xyz %xyz
  }
  gosub FindLongLat #CHARPOSX #CHARPOSY
  wait 5
until #FALSE

sub FindLongLat
  set %long_dir
  set %lat_dir
  set %CenterX 1323
  set %CenterY 1624
  set %long_time 3168
  set %lat_time 2531
  set %FindX %1
  set %FindY %2
  set %fx ( %FindX - %CenterX )
  set %fy ( %FindY - %CenterY )
  set #RESULT #FALSE
  if %fy > 0
    set %long_dir %long_dir , S
  else
    set %long_dir %long_dir , N
  set %steps %fy ABS
  if %fx > 0
    set %lat_dir %lat_dir , E
  else
    set %lat_dir %lat_dir , W
  set %steps2 %fx ABS

  set %seconds ( ( %steps * %long_time ) )   ;3165
  set %seconds2 ( ( %steps2 * %lat_time ) ) ;2531
  set %lathrs ( %seconds / ( 60 * 60 ) / 10 )
  set %latmin ( ( %seconds / 600 ) - ( %lathrs * 60 ) )
  set %lonhrs ( %seconds2 / ( 60 * 60 ) / 10 )
  set %lonmin ( ( %seconds2 / 600 ) - ( %lonhrs * 60 ) )

  menu set longlat %lathrs , o , #SPC , %latmin , ' , %long_dir , #SPC , %lonhrs , o , #SPC , %lonmin , ' , %lat_dir
return %return

sub Header
menu Clear
menu Window Title Altiric's Sextant
menu Window Size 275 50 ;250 245
menu font name Verdana
  menu font align right
menu text lab1 85 5 Sextant:
menu text lab2 85 20 XYZ:
  menu font align left
  menu text longlat 90 5
  menu text xyz 90 20
  menu Show 500 270
return

this will only work in Tram/Fel unless you update the center X/Y to the different maps.[
« Last Edit: August 28, 2021, 01:51:07 PM by altiric »

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13301
  • Activity:
    0%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Latitude/Longitude from X/Y.... Finally!
« Reply #1 on: September 02, 2021, 07:49:22 PM »
0
Don't you love how you have to add excessive parenthesis in order to get EasyUO to compute correctly?  :P
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline altiricTopic starter

  • Jr. Member
  • **
  • Posts: 81
  • Activity:
    0%
  • Reputation Power: 2
  • altiric has no influence.
  • Respect: +4
  • Referrals: 1
    • View Profile
Re: Latitude/Longitude from X/Y.... Finally!
« Reply #2 on: September 03, 2021, 03:59:05 AM »
0
Been slacking lately, was about to work this one into something, got into dabbling with orionuo and really enjoying it. Not only the scripting features, but the smoothness of the opengl rendering at 60fps is just beautiful! Java abilities are subpar, but working with the Orion extensions has really cut the learning curve. Just a few days in and I'm able to put together far more powerful(and faster) scripts.

Offline Gaderian

  • Elite
  • *
  • *
  • Posts: 486
  • Activity:
    0%
  • Reputation Power: 10
  • Gaderian barely matters.Gaderian barely matters.
  • Respect: +50
  • Referrals: 3
    • View Profile
Re: Latitude/Longitude from X/Y.... Finally!
« Reply #3 on: September 04, 2021, 03:13:15 PM »
0
Have you tried testing in other land mass other than Felucca/Trammel?
How accurate is it in the southern seas where the north/south flips?

I did my own project that will work in all the land masses and I can do the southern parts of Fel/Tram, but I often end up with my best being within 1 degree.
Theoretically you can go to 180o 0' north or south, but then it has to flip to 179o XX' north or south. It is along this line that I spent a lot of time trying to prove that it was perfectly accurate and in agreement with an in game sextant. I do not remember if I ever finished that or not, but it is good enough.

I expanded it to project my location in a mini-map of the landmass - similar to what you could get from UO Automap or similar products. I originally used it for sailing, but now use it to help me run/navigate to places.
"Go ahead ask me: 'Should I use hard waits or timers?'"
You say:"Should I"
Gaderian:"Timers!"
You Say:"use hard waits or timers?"

The serious side of timer use is illustrated here: http://www.scriptuo.com/index.php?topic=12094.msg101926#msg101926

However, every time I go back and look at this [AutoLooter] script, I realize I had wrote it in my zen state of EUO scripting - so it makes my brain hurt.

Offline altiricTopic starter

  • Jr. Member
  • **
  • Posts: 81
  • Activity:
    0%
  • Reputation Power: 2
  • altiric has no influence.
  • Respect: +4
  • Referrals: 1
    • View Profile
Re: Latitude/Longitude from X/Y.... Finally!
« Reply #4 on: September 06, 2021, 11:52:25 AM »
0
I have not added anything for the rollover, a simple if %latt_hrs>180 should be all that needs. I also set it up to allow for the center point to to be variable. A clicloc to set the center x/y will fix that. While I had it running, passing through Luna I did notice the coords were bang on as is though. It was going to be the start of my area identifier, comparing lower x/y and upper x/y with #charpos and returning a name. Knowing my direction would let me set the same uppwer/lower x/y the same for squares no matter where they are located. Then bases on my n/e/w/s dir I can find which x/y to compare in the square.

I have been dabbling in other clients the last couple weeks and they have really taken my attention though. The possibilities of client.walkto on crossuo/Orion are epic. Everything just runs a lot faster and I have so much more information to play with. I still have 2 large scripts and a bundle of snippets I would like to wrap up to try and boost by rep a little, ill get back to them soon though!

Offline Gaderian

  • Elite
  • *
  • *
  • Posts: 486
  • Activity:
    0%
  • Reputation Power: 10
  • Gaderian barely matters.Gaderian barely matters.
  • Respect: +50
  • Referrals: 3
    • View Profile
Re: Latitude/Longitude from X/Y.... Finally!
« Reply #5 on: September 07, 2021, 03:14:57 PM »
0
A few years ago, I did my own version of this. However, it has it's own issues, so don't take this as harsh criticism, but trying to shed more light on how it all works.

All map areas other than T2A have the same calculations - so it should work in Tokuno, Malas, Ilshenar and Ter Mur/Eodon.
Here is how I determine if I am in T2A or not to reset the offset (what is the Lord British throne tile in Fel/Tram Britannia):
Code: easyuo
  1.  if ( #curskind = 0 || #curskind = 1 ) && ( #charposx > 5120 && #charposx <= 6144 && #charposy >= 2300 && #charposy <= 4096 )
  2.   {
  3.   set %XOffset 5936
  4.   set %YOffset 3112
  5.   }
  6.  else
  7.   {
  8.   set %Xoffset 1323
  9.   set %YOffset 1624
  10.   }

All the maps are based on 5120 wide = 360 degrees while 4096 high = 360 degrees

Lands that are not Fel/Tram have smaller maps but the math is the same (except for T2A has a different offset).

Here is a very simple calculation that works in most lands but is off by a minute. I think the value it is off by is related to rounding/truncating the value. It doesn't work in T2A because of the different offset.

I tried it with your formula  and it works really well if you modify for that difference.

Both of ours had issues with correctness. Mine was very messy trying to make it work 100%.
Here is a simple method that works everywhere except T2A. it is off by a minute in many locations - I think it has to do with rounding rules in various quadrants.

Code: easyuo
  1. set %xlocation #charposx + 1237 ; 1237 moves from brit's throne to the center of map
  2. set %ylocation #charposy + 424 ; 424 moves from brit's throne to center of map
  3. ; Next check are we above 5120 for X or 4096 for y? if so, then readjust:
  4. if %xlocation > 5120
  5.  set %xlocation %xlocation - 5120
  6. if %ylocation > 4096
  7.  set %ylocation %ylocation - 4096
  8. ; Now xlocation and ylocation are in the right quadrant for creating the latitude and longitude references
  9. if %xlocation < 2560
  10.   set %xdir W
  11. else
  12.  set %xdir E
  13. if %ylocation < 2048
  14.  set %ydir N
  15. else
  16.  set %ydir S
  17. set %xlocation %xlocation - 2560 abs
  18. set %ylocation %ylocation - 2048 abs
  19. set %lontemp  %xlocation * 180 * 60 / 2560 ; 180 deg * 60 min / tiles equal to 180 deg E/W
  20. set %lattemp  %ylocation * 180 * 60 / 2048 ; 180 deg * 60 min / tiles equal to 180 deg N/S
  21. set %longdeg %lontemp / 60
  22. set %longmin %lontemp % 60
  23. set %latdeg %lattemp / 60
  24. set %latmin %lattemp % 60
  25. display ok %latdeg , #spc , %latmin , %ydir , #spc , %longdeg , #spc , %longmin , %xdir
  26. halt

"Go ahead ask me: 'Should I use hard waits or timers?'"
You say:"Should I"
Gaderian:"Timers!"
You Say:"use hard waits or timers?"

The serious side of timer use is illustrated here: http://www.scriptuo.com/index.php?topic=12094.msg101926#msg101926

However, every time I go back and look at this [AutoLooter] script, I realize I had wrote it in my zen state of EUO scripting - so it makes my brain hurt.

Tags: