GetMapSizeX() and GetMapSizeY()

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
tracks
Engineer
Engineer
Posts: 4
Joined: 28 Jun 2010 20:23
Location: Ithaca, NY, USA

GetMapSizeX() and GetMapSizeY()

Post 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?
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: GetMapSizeX() and GetMapSizeY()

Post 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.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: GetMapSizeX() and GetMapSizeY()

Post 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.
tracks
Engineer
Engineer
Posts: 4
Joined: 28 Jun 2010 20:23
Location: Ithaca, NY, USA

Re: GetMapSizeX() and GetMapSizeY()

Post 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?
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: GetMapSizeX() and GetMapSizeY()

Post by Kogut »

It is a good idea.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: GetMapSizeX() and GetMapSizeY()

Post 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.
tracks
Engineer
Engineer
Posts: 4
Joined: 28 Jun 2010 20:23
Location: Ithaca, NY, USA

Re: GetMapSizeX() and GetMapSizeY()

Post by tracks »

Done.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 10 guests