GetMapSizeX() and GetMapSizeY()
Posted: 29 Jun 2010 21:30
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?