Page 1 of 1

GetMapSizeX() and GetMapSizeY()

Posted: 29 Jun 2010 21:30
by tracks
I'm rather new here, so please forgive my ignorance. I'm experimenting with my own AI and stumbled on a question. I spent a little time looking through past threads and trying to use search, but I couldn't find anything that answers the question.

This wiki page talks about map coordinates about half-way down: http://wiki.openttd.org/AI:Need_To_Know

It states the top-most tile is (1, 1) and the bottom-most tile is (Max_X, Max_Y).

Looking at the API, I assumed that AIMap.GetMapSizeX() would be equivalent to Max_X (and similarly for Max_Y). However, trying this out, I find that this expression:

AIMap.GetTileIndex(AIMap.GetMapSizeX(), AIMap.GetMapSizeY())

returns an invalid tile.

And, in fact, I could only get a valid tile by subtracting 2 from both size values. ie:

AIMap.GetTileIndex(AIMap.GetMapSizeX()-2, AIMap.GetMapSizeY()-2)

Looking around, I see other AI's doing this subtraction as well. So, my question is: is this the correct way to get the bottom tile (and the wiki is wrong)?

And does this mean that the real map size is 2 tiles shorter on each side than the specified size? That is, I specify 256x256, but I really get 254x254. (Which is 1020 tiles smaller.)

If this is the case, I'm curious about the rationale for why it is done this way?

Or am I completely in left field?

Re: GetMapSizeX() and GetMapSizeY()

Posted: 29 Jun 2010 21:33
by Kogut
tracks wrote:And does this mean that the real map size is 2 tiles shorter on each side than the specified size? That is, I specify 256x256, but I really get 254x254. (Which is 1020 tiles smaller.)
Yes, it is an interesting thing.

Re: GetMapSizeX() and GetMapSizeY()

Posted: 29 Jun 2010 21:42
by Rubidium
Then the wiki is wrong.

Furthermore depending on the settings the first buildable tile is 1,1 or 0,0 (based whether freeform_edges is enabled or not). Furthermore the last buildable tile is MapSize - 2.

This is due to an invisible row of tiles at the bottom of the map in all cases and at the top of the map in case freeform_edges is enabled. The tiles do actually exist, but are not buildable and therefor deemed invalid.

You should note that as such counting starts at 0,0 and thus (MapSizeX, MapSizeY) will be always outside of the bounds of the map.

Re: GetMapSizeX() and GetMapSizeY()

Posted: 29 Jun 2010 21:52
by tracks
I see. So I really do have a map of size 256x256. I just can't access the outer edges. (Modulo options.)

That makes much more sense. Thanks!

Perhaps I can update the wiki to describe this clearer?

Re: GetMapSizeX() and GetMapSizeY()

Posted: 29 Jun 2010 21:52
by Kogut
It is a good idea.

Re: GetMapSizeX() and GetMapSizeY()

Posted: 29 Jun 2010 22:26
by planetmaker
tracks wrote:I see. So I really do have a map of size 256x256. I just can't access the outer edges. (Modulo options.)

That makes much more sense. Thanks!

Perhaps I can update the wiki to describe this clearer?
Of course. Updating the wiki is always a good idea. And it's a wiki so that everyone can easily contribute. Besides it has an undo function and a history in case someone really screws up :-) - so no fear to go for it.

Re: GetMapSizeX() and GetMapSizeY()

Posted: 30 Jun 2010 04:26
by tracks
Done.