42 static_assert(
sizeof(
TileBase) == 8);
80 debug_inline constexpr
operator uint()
const {
return tile.base(); }
89 debug_inline uint8_t &
type()
113 debug_inline uint8_t &
m1()
125 debug_inline uint16_t &
m2()
137 debug_inline uint8_t &
m3()
149 debug_inline uint8_t &
m4()
161 debug_inline uint8_t &
m5()
173 debug_inline uint8_t &
m6()
185 debug_inline uint8_t &
m7()
197 debug_inline uint16_t &
m8()
215 typedef size_t difference_type;
216 typedef std::forward_iterator_tag iterator_category;
219 bool operator==(
const Iterator &other)
const {
return this->index == other.index; }
220 bool operator!=(
const Iterator &other)
const {
return !(*
this == other); }
221 Tile operator*()
const {
return this->index; }
222 Iterator & operator++() { this->index++;
return *
this; }
233 bool empty() {
return false; }
251 debug_inline
static uint
LogX()
288 debug_inline
static uint
Size()
297 debug_inline
static uint
MaxX()
406 return (y >> 4 <<
Map::LogX()) + (x >> 4);
514 int x =
TileX(tile) + diff.
x;
515 int y =
TileY(tile) + diff.
y;
622 int dx = (int)
TileX(tile_to) - (int)
TileX(tile_from);
623 int dy = (int)
TileY(tile_to) - (int)
TileY(tile_from);
661 #define RandomTile() RandomTileSeed(Random())
Wrapper class to abstract away the way the tiles are stored.
static TileBase * base_tiles
Pointer to the tile-array.
debug_inline uint16_t & m8()
General purpose.
debug_inline uint8_t & m7()
Primarily used for newgrf support.
debug_inline Tile(TileIndex tile)
Create the tile wrapper for the given tile.
debug_inline uint8_t & type()
The type (bits 4..7), bridges (2..3), rainforest/desert (0..1)
debug_inline uint8_t & m5()
General purpose.
debug_inline uint8_t & m1()
Primarily used for ownership information.
debug_inline uint8_t & m4()
General purpose.
debug_inline uint8_t & height()
The height of the northern corner.
debug_inline uint16_t & m2()
Primarily used for indices to towns, industries and stations.
Tile(uint tile)
Create the tile wrapper for the given tile.
static TileExtended * extended_tiles
Pointer to the extended tile-array.
debug_inline uint8_t & m6()
General purpose.
debug_inline uint8_t & m3()
General purpose.
TileIndex tile
The tile to access the map data for.
Different functions related to conversions between directions.
bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
bool IsValidDirection(Direction d)
Checks if an integer value is a valid Direction.
Direction
Defines the 8 directions on the map.
@ DIR_END
Used to iterate.
Axis
Allow incrementing of DiagDirDiff variables.
DiagDirection
Enumeration for diagonal directions.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
@ DIAGDIR_END
Used for iterations.
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
const TileIndexDiffC _tileoffs_by_axis[]
'Lookup table' for tile offsets given an Axis
const TileIndexDiffC _tileoffs_by_dir[]
'Lookup table' for tile offsets given a Direction
const TileIndexDiffC _tileoffs_by_diagdir[]
'Lookup table' for tile offsets given a DiagDirection
bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data)
Function performing a search around a center tile and going outward, thus in circle.
DiagDirection DiagdirBetweenTiles(TileIndex tile_from, TileIndex tile_to)
Determines the DiagDirection to get from one tile to another.
TileIndex TileAddXY(TileIndex tile, int x, int y)
Adds a given offset to a tile.
uint DistanceMaxPlusManhattan(TileIndex, TileIndex)
Max + Manhattan.
TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff)
Add a TileIndexDiffC to a TileIndex and returns the new one.
TileIndex TileAddByDir(TileIndex tile, Direction dir)
Adds a Direction to a tile.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between two tiles from a TileIndexDiffC struct.
TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
uint DistanceMax(TileIndex, TileIndex)
also known as L-Infinity-Norm
TileIndex RandomTileSeed(uint32_t r)
Get a random tile out of a given seed.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
TileIndexDiff TileOffsByAxis(Axis axis)
Convert an Axis to a TileIndexDiff.
uint DistanceFromEdgeDir(TileIndex, DiagDirection)
distance from the map edge in given direction
uint DistanceFromEdge(TileIndex)
shortest distance from any edge of the map
TileIndex TileAddWrap(TileIndex tile, int addx, int addy)
This function checks if we add addx/addy to tile, if we do wrap around the edges.
uint DistanceSquare(TileIndex, TileIndex)
euclidian- or L2-Norm squared
TileIndexDiffC TileIndexDiffCByDiagDir(DiagDirection dir)
Returns the TileIndexDiffC offset from a DiagDirection.
uint GetClosestWaterDistance(TileIndex tile, bool water)
Finds the distance for the closest tile with water/land given a tile.
uint DistanceManhattan(TileIndex, TileIndex)
also known as L1-Norm. Is the shortest distance one could go over diagonal tracks (or roads)
constexpr TileIndex TileAdd(TileIndex tile, TileIndexDiff offset)
Adds a given offset to a tile.
bool TestTileOnSearchProc(TileIndex tile, void *user_data)
A callback function type for searching tiles.
TileIndexDiffC TileIndexDiffCByDir(Direction dir)
Returns the TileIndexDiffC offset from a Direction.
TileIndexDiff TileOffsByDir(Direction dir)
Convert a Direction to a TileIndexDiff.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
TileIndexDiffC TileIndexToTileIndexDiffC(TileIndex tile_a, TileIndex tile_b)
Returns the diff between two tiles.
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
int32_t TileIndexDiff
An offset value between two tiles.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Iterator to iterate all Tiles.
Size related data of the map.
static TileIndex WrapToMap(TileIndex tile)
'Wraps' the given "tile" so it is within the map.
static uint ScaleBySize(uint n)
Scales the given value by the map size, where the given value is for a 256 by 256 map.
static uint SizeY()
Get the size of the map along the Y.
static IterateWrapper Iterate()
Returns an iterable ensemble of all Tiles.
static uint size
The number of tiles on the map.
static debug_inline uint SizeX()
Get the size of the map along the X.
static debug_inline uint LogX()
Logarithm of the map size along the X side.
static uint size_x
Size of the map along the X.
static uint tile_mask
_map_size - 1 (to mask the mapsize)
static uint size_y
Size of the map along the Y.
static uint ScaleBySize1D(uint n)
Scales the given value by the maps circumference, where the given value is for a 256 by 256 map.
static uint LogY()
Logarithm of the map size along the y side.
static bool IsInitialized()
Check whether the map has been initialized, as to not try to save the map during crashlog when the ma...
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
static uint log_y
2^_map_log_y == _map_size_y
static uint log_x
2^_map_log_x == _map_size_x
static void Allocate(uint size_x, uint size_y)
(Re)allocates a map with the given dimension
static debug_inline uint Size()
Get the size of the map.
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
A pair-construct of a TileIndexDiff.
int16_t x
The x value of the coordinate.
int16_t y
The y value of the coordinate.
Data that is stored per tile.
uint8_t m3
General purpose.
uint8_t m4
General purpose.
uint8_t type
The type (bits 4..7), bridges (2..3), rainforest/desert (0..1)
uint8_t m5
General purpose.
uint8_t height
The height of the northern corner.
uint8_t m1
Primarily used for ownership information.
uint16_t m2
Primarily used for indices to towns, industries and stations.
Data that is stored per tile.
uint8_t m6
General purpose.
uint8_t m7
Primarily used for newgrf support.
uint16_t m8
General purpose.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.