GetMapSizeX() and GetMapSizeY()
Moderator: OpenTTD Developers
GetMapSizeX() and GetMapSizeY()
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?
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()
Yes, it is an interesting thing.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.)
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: GetMapSizeX() and GetMapSizeY()
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.
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()
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?
That makes much more sense. Thanks!
Perhaps I can update the wiki to describe this clearer?
Re: GetMapSizeX() and GetMapSizeY()
It is a good idea.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: GetMapSizeX() and GetMapSizeY()
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 uptracks 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?

OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Who is online
Users browsing this forum: No registered users and 7 guests