* 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 *
| 118 | * @return translated tile, or INVALID_TILE when it would've wrapped. |
| 119 | */ |
| 120 | TileIndex 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 */ |
| 135 | extern const TileIndexDiffC _tileoffs_by_axis[] = { |
no test coverage detected