MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / TileAddWrap

Function TileAddWrap

src/map.cpp:120–132  ·  view source on GitHub ↗

* This function checks if we add addx/addy to tile, if we * do wrap around the edges. For example, tile = (10,2) and * addx = +3 and addy = -4. This function will now return * INVALID_TILE, because the y is wrapped. This is needed in * for example, farmland. When the tile is not wrapped, * the result will be tile + TileDiffXY(addx, addy) * * @param tile the 'starting' point of the adding *

Source from the content-addressed store, hash-verified

118 * @return translated tile, or INVALID_TILE when it would've wrapped.
119 */
120TileIndex TileAddWrap(TileIndex tile, int addx, int addy)
121{
122 uint x = TileX(tile) + addx;
123 uint y = TileY(tile) + addy;
124
125 /* Disallow void tiles at the north border. */
126 if ((x == 0 || y == 0) && _settings_game.construction.freeform_edges) return INVALID_TILE;
127
128 /* Are we about to wrap? */
129 if (x >= Map::MaxX() || y >= Map::MaxY()) return INVALID_TILE;
130
131 return TileXY(x, y);
132}
133
134/** 'Lookup table' for tile offsets given an Axis */
135extern const TileIndexDiffC _tileoffs_by_axis[] = {

Callers 13

PlantRandomFarmFieldFunction · 0.85
FindSpringFunction · 0.85
CountMapSquareAroundFunction · 0.85
CmdBuildRailStationFunction · 0.85
CmdBuildRoadStopFunction · 0.85
CmdRemoveRoadStopFunction · 0.85
PlaceTreeGroupsFunction · 0.85
PlaceTreeAtSameHeightFunction · 0.85
PlaceTreeGroupAroundTileFunction · 0.85

Calls 3

TileXFunction · 0.85
TileYFunction · 0.85
TileXYFunction · 0.85

Tested by

no test coverage detected