OpenTTD
Functions
Rows and columns in the viewport

Columns are vertical sections of the viewport that are half a tile wide. More...

Functions

static int GetTileColumnFromTileCoord (Point tile_coord)
 Given a tile coordinate as returned by TileX / TileY, this returns its column.
static Point GetNorthernEndOfColumn (Point tile)
 Returns the position of the tile at the northern end of the column of the given tile.
static Point GetSouthernEndOfColumnWithLimit (Point tile, uint limit)
 Returns the position of the tile at the southern end of the column of the given tile, if it is within the given limit expressed in number of tiles.
static Point GetSouthernEndOfColumn (Point tile)
 Returns the position of the tile at the southern end of the column of the given tile.
int GetRowAtTile (int viewport_y, Point tile, bool bridge_correct)
 Given a tile coordinate assuming height zero, this returns the row actually painted at this tile coordinate if one recognizes height.
static Point GetBottomTileOfColumn (Point upper_tile, Point lower_right_tile)
 Returns the bottom tile of the column of upper_tile shown on the viewport, given upper_tile and the lower right tile shown on the viewport.

Detailed Description

Columns are vertical sections of the viewport that are half a tile wide.

The origin, i.e. column 0, is through the northern and southern most tile. This means that the column of e.g. Tile(0, 0) and Tile(100, 100) are in column number 0. The negative columns are towards the left of the screen, or towards the west, whereas the positive ones are towards respectively the right and east. With half a tile wide is meant that the next column of tiles directly west or east of the centre line are respectively column -1 and 1. Their tile centers are only half a tile from the center of their adjoining tile when looking only at the X-coordinate.

*        ╳        *
*       ╱ ╲       *
*      ╳ 0 ╳      *
*     ╱ ╲ ╱ ╲     *
*    ╳-1 ╳ 1 ╳    *
*   ╱ ╲ ╱ ╲ ╱ ╲   *
*  ╳-2 ╳ 0 ╳ 2 ╳  *
*   ╲ ╱ ╲ ╱ ╲ ╱   *
*    ╳-1 ╳ 1 ╳    *
*     ╲ ╱ ╲ ╱     *
*      ╳ 0 ╳      *
*       ╲ ╱       *
*        ╳        *
* 

Rows are horizontal sections of the viewport, also half a tile wide. This time the nothern most tile on the map at height level 0 defines 0 and everything south of that has a positive number. In theory this works the same as for columns with the massive difference that due to the isometric projection the actual row where the tile is visible differs from the row where the tile would be if it were at height level 0. Strictly speaking, if you know the row of the tile at height level 0, then the row number where it is actually drawn is tile height / 2 lower than the row number of the same tile at height level 0.

Function Documentation

static Point GetBottomTileOfColumn ( Point  upper_tile,
Point  lower_right_tile 
)
static

Returns the bottom tile of the column of upper_tile shown on the viewport, given upper_tile and the lower right tile shown on the viewport.

Parameters
upper_tileSny tile inside the map.
lower_right_tileThe tile shown at the southeast edge of the viewport (ignoring height). Note that this tile may be located northeast of the upper_tile, because upper_tile is usually calculated by shifting a tile southwards until we reach the northern map border.
Returns
The lowest existing tile located in the column defined by upper_tile, which is in the same row as lower_right_tile or above that row If lower_right_tile was northeast of upper_tile, (-1,-1) is returned.

Definition at line 1403 of file viewport.cpp.

Referenced by ViewportAddLandscape().

static Point GetNorthernEndOfColumn ( Point  tile)
static

Returns the position of the tile at the northern end of the column of the given tile.

Parameters
tileAny tile.
Returns
Position of the tile at the northern end of the column as described.

Definition at line 1186 of file viewport.cpp.

Referenced by GetRowAtTile().

int GetRowAtTile ( int  viewport_y,
Point  tile,
bool  bridge_correct 
)

Given a tile coordinate assuming height zero, this returns the row actually painted at this tile coordinate if one recognizes height.

The problem concerning this calculation is that we have not enough information to calculate this in one closed formula. Which row we search rather depends on the height distribution on the map. So we have to search.

First, the searched tile may be located outside map. Then, we know that we are not too far outside map, so we can step tile by tile, starting at the given tile, until we have passed the searched tile.

If the searched tile is inside map, searching is more difficult. A linear search on some thousand tiles would be not that efficient. But, we can solve the problem by interval intersection. We know for sure, that the searched tile is south of the given tile, simply because mountains of height > 0 (and we have only such mountains) are always painted north of their tile. So we choose a tile half way between the given tile and the southern end of the map, have a look whether it is north or south of the given position, and intersect again. Until our interval has length 1, then we take the upper one.

Parameters
viewport_yThe viewport y corresponding to tile, if one assumes height zero for that tile
tileSome tile coordinate assuming height zero.
bridge_correctIf true, consider bridges south of the calculated tile, and if the bridge visually intersect the calculated tile, shift it southwards.
Returns
The row which is painted at this coordinate, according to the discussion above.

Definition at line 1287 of file viewport.cpp.

References _settings_game, GameSettings::construction, GetBridgeHeight(), GetMiddleTile(), GetNorthernBridgeEnd(), GetNorthernEndOfColumn(), GetSouthernEndOfColumn(), GetSouthernEndOfColumnWithLimit(), GetTileZ(), GetViewportY(), IsBridgeAbove(), IsValidTile(), max(), ConstructionSettings::max_bridge_height, ConstructionSettings::max_heightlevel, and TileXY().

Referenced by SmallMapWindow::GetSmallMapCoordIncludingHeight(), and ViewportAddLandscape().

static Point GetSouthernEndOfColumn ( Point  tile)
static

Returns the position of the tile at the southern end of the column of the given tile.

Parameters
tileAny tile.
Returns
Position of the tile at the soutern end of the column as described.

Definition at line 1237 of file viewport.cpp.

References GetSouthernEndOfColumnWithLimit().

Referenced by GetRowAtTile().

static Point GetSouthernEndOfColumnWithLimit ( Point  tile,
uint  limit 
)
static

Returns the position of the tile at the southern end of the column of the given tile, if it is within the given limit expressed in number of tiles.

Parameters
tileAny tile.
limitNumber of tiles to go to south at most, if the southern end is further away, stop after that number of tiles
Returns
Position of the tile at the soutern end of the column as described.

Definition at line 1210 of file viewport.cpp.

References MapMaxX(), MapMaxY(), and min().

Referenced by GetRowAtTile(), and GetSouthernEndOfColumn().

static int GetTileColumnFromTileCoord ( Point  tile_coord)
static

Given a tile coordinate as returned by TileX / TileY, this returns its column.

Parameters
tile_coordThe coordinate of the tile.
Returns
The column index.

Definition at line 1174 of file viewport.cpp.

Referenced by ViewportAddLandscape().