28 #define TILE_MASK(x) ((x) & _map_tile_mask) 198 return (y >> 4 <<
MapLogX()) + (x >> 4);
246 #define TILE_ADD(x, y) ((x) + (y)) 249 const char *exp,
const char *file,
int line);
250 #define TILE_ADD(x, y) (TileAdd((x), (y), #x " + " #y, __FILE__, __LINE__)) 260 #define TILE_ADDXY(tile, x, y) TILE_ADD(tile, TileDiffXY(x, y)) 275 return _tileoffs_by_diagdir[dir];
289 return _tileoffs_by_dir[dir];
304 int x =
TileX(tile) + diff.
x;
305 int y =
TileY(tile) + diff.
y;
386 int dx = (int)
TileX(tile_to) - (int)
TileX(tile_from);
387 int dy = (int)
TileY(tile_to) - (int)
TileY(tile_from);
425 #define RandomTile() RandomTileSeed(Random()) uint _map_size
The number of tiles on the map.
static uint MapSizeX()
Get the size of the map along the X.
Tile * _m
Pointer to the tile-array.
uint _map_size_x
Size of the map along the X.
static bool IsValidDirection(Direction d)
Checks if an integer value is a valid Direction.
static uint MapSizeY()
Get the size of the map along the Y.
TileExtended * _me
Pointer to the extended tile-array.
static TileIndexDiffC TileIndexDiffCByDir(Direction dir)
Returns the TileIndexDiffC offset from a Direction.
Flag for an invalid DiagDirection.
int32 TileIndexDiff
An offset value between to tiles.
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.
static uint MapLogX()
Logarithm of the map size along the X side.
static uint ScaleByMapSize(uint n)
Scales the given value by the map size, where the given value is for a 256 by 256 map...
static uint TileX(TileIndex tile)
Get the X component of a tile.
static TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Northeast, upper right on your monitor.
static uint MapLogY()
Logarithm of the map size along the y side.
uint DistanceManhattan(TileIndex, TileIndex)
also known as L1-Norm. Is the shortest distance one could go over diagonal tracks (or roads) ...
Direction
Defines the 8 directions on the map.
const TileIndexDiffC _tileoffs_by_dir[]
'Lookup table' for tile offsets given a Direction
int16 y
The y value of the coordinate.
static DiagDirection DiagdirBetweenTiles(TileIndex tile_from, TileIndex tile_to)
Determines the DiagDirection to get from one tile to another.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
uint _map_size_y
Size of the map along the Y.
uint DistanceMaxPlusManhattan(TileIndex, TileIndex)
Max + Manhattan.
static TileIndexDiffC TileIndexDiffCByDiagDir(DiagDirection dir)
Returns the TileIndexDiffC offset from a DiagDirection.
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. ...
int16 x
The x value of the coordinate.
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
static bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
void AllocateMap(uint size_x, uint size_y)
(Re)allocates a map with the given dimension
Data that is stored per tile.
const TileIndexDiffC _tileoffs_by_diagdir[]
'Lookup table' for tile offsets given a DiagDirection
DiagDirection
Enumeration for diagonal directions.
Data that is stored per tile.
uint GetClosestWaterDistance(TileIndex tile, bool water)
Finds the distance for the closest tile with water/land given a tile.
static uint ScaleByMapSize1D(uint n)
Scales the given value by the maps circumference, where the given value is for a 256 by 256 map...
A pair-construct of a TileIndexDiff.
uint DistanceFromEdge(TileIndex)
shortest distance from any edge of the map
uint DistanceSquare(TileIndex, TileIndex)
euclidian- or L2-Norm squared
static TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between to tiles from a TileIndexDiffC struct.
uint DistanceFromEdgeDir(TileIndex, DiagDirection)
distance from the map edge in given direction
static TileIndex RandomTileSeed(uint32 r)
Get a random tile out of a given seed.
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
static uint MapSize()
Get the size of the map.
uint DistanceMax(TileIndex, TileIndex)
also known as L-Infinity-Norm
uint32 TileIndex
The index/ID of a Tile.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
static TileIndexDiff TileOffsByDir(Direction dir)
Convert a Direction to a TileIndexDiff.
bool TestTileOnSearchProc(TileIndex tile, void *user_data)
A callback function type for searching tiles.
uint _map_log_x
2^_map_log_x == _map_size_x
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
uint _map_tile_mask
_map_size - 1 (to mask the mapsize)
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Different functions related to conversions between directions.
static TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff)
Add a TileIndexDiffC to a TileIndex and returns the new one.
#define TILE_ADD(x, y)
Adds to tiles together.
#define TILE_MASK(x)
'Wraps' the given tile to it is within the map.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
static TileIndexDiffC TileIndexToTileIndexDiffC(TileIndex tile_a, TileIndex tile_b)
Returns the diff between two tiles.
uint _map_log_y
2^_map_log_y == _map_size_y