Jump to content

function to help generate an array of valid geoIDs

Recommended Posts

Ok bare with me because I have no idea what this is actually called. If someone knows I will update the title.

I am working on a site that will act as an out-of-game marketplace for in-game items. I want to ensure that the player is within the zone of the market in-game so I need an easy way to generate an array of valid coordinates the player could be within to access the market. Ideally i would like to run a function with a parameter specifying the radius of a square and another of the player's current geoID. Basic geometry would help if the geoID's were, in my mind, easier to predict. here is problem:

Going North: geoID's increase by 512 points
Going East: geoID's increase by 1
Going South: geoID's decrease by 512
Going West geoID's decrease by 1

I realize this is more of a math question then PHP but I have no idea where to start to account for the odd increase.

//Generate the exchangeArea array of a 5x5 square around the centeral id specified in param2.
$exchangeArea = getExchangeArea(3,117053149);

//if player geoID equals one of the values in the exchangeArea array return true else false

function getExchangeArea(int radius, int geoID)

I have attached a graphic showing all the geoIDs for the above example. Ignore the geoAlt that is just they players Y axis.
So there is no confusion, North on this diagram is the right side of the image. Making the top West.

Any help on where to begin, even if its helping me identify keywords to search on for this kind of formula, algorithm, equation... what ever it's called, would be greatly appreciated.

Trade Post.png

Share this post

Link to post
Share on other sites

If you have specific increments for the different directions, then you just need to identify the first column for each row and then go 5 spaces over for each row.  So starting from the center you go up 2 and left 2 for the top left corner, and just go from there.  From the top left corner you just keep going down 1 to get the start of each of the 5 rows, and from each of those positions you go right 4 spots to get each square.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...