diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 25b47143ca..2ae899105f 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -1010,7 +1010,7 @@ static void SetupFarmFieldFence(TileIndex tile, int size, byte type, DiagDirecti TileIndexDiff diff = (DiagDirToAxis(side) == AXIS_Y ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); do { - tile = TILE_MASK(tile); + tile = Map::WrapToMap(tile); if (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_FIELDS)) { byte or_ = type; diff --git a/src/map.cpp b/src/map.cpp index 98bf6eb614..9eda67005c 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -92,7 +92,7 @@ TileIndex TileAdd(TileIndex tile, TileIndexDiff add, #endif } - assert(TileXY(x, y) == TILE_MASK(tile + add)); + assert(TileXY(x, y) == Map::WrapToMap(tile + add)); return TileXY(x, y); } diff --git a/src/map_func.h b/src/map_func.h index c5f5f8680a..daefdb54eb 100644 --- a/src/map_func.h +++ b/src/map_func.h @@ -15,16 +15,6 @@ #include "map_type.h" #include "direction_func.h" -extern uint _map_tile_mask; - -/** - * 'Wraps' the given tile to it is within the map. It does - * this by masking the 'high' bits of. - * @param x the tile to 'wrap' - */ - -#define TILE_MASK(x) ((x) & _map_tile_mask) - /** * Pointer to the tile-array. * @@ -117,6 +107,18 @@ struct Map { return Map::SizeY() - 1; } + + /** + * 'Wraps' the given "tile" so it is within the map. + * It does this by masking the 'high' bits of. + * @param tile the tile to 'wrap' + */ + static inline TileIndex WrapToMap(uint tile) + { + extern uint _map_tile_mask; + return tile & _map_tile_mask; + } + /** * Scales the given value by the map size, where the given value is * for a 256 by 256 map. @@ -429,7 +431,7 @@ bool CircularTileSearch(TileIndex *tile, uint radius, uint w, uint h, TestTileOn */ static inline TileIndex RandomTileSeed(uint32 r) { - return TILE_MASK(r); + return Map::WrapToMap(r); } /** diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp index 2af9d888cf..4fa37000a7 100644 --- a/src/newgrf_commons.cpp +++ b/src/newgrf_commons.cpp @@ -433,7 +433,7 @@ TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axi if (axis == AXIS_Y) Swap(x, y); /* Make sure we never roam outside of the map, better wrap in that case */ - return TILE_MASK(tile + TileDiffXY(x, y)); + return Map::WrapToMap(tile + TileDiffXY(x, y)); } /** diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index 6a7d191f72..21a4413fa2 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -346,7 +346,7 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI /* Extract tile offset. */ int8 x_offs = GB(GetRegister(0x100), 0, 8); int8 y_offs = GB(GetRegister(0x100), 8, 8); - TileIndex testtile = TILE_MASK(this->tile + TileDiffXY(x_offs, y_offs)); + TileIndex testtile = Map::WrapToMap(this->tile + TileDiffXY(x_offs, y_offs)); StationFinder stations(TileArea(testtile, 1, 1)); const StationList *sl = stations.GetStations();