44 FatalError(
"Invalid map size");
73 uint32_t x =
TileX(tile) + dx;
74 uint32_t y =
TileY(tile) + dy;
99 uint x =
TileX(tile) + addx;
100 uint y =
TileY(tile) + addy;
167 return dx * dx + dy * dy;
182 return std::max(dx, dy);
198 return dx > dy ? 2 * dx + dy : 2 * dy + dx;
208 const uint xl =
TileX(tile);
209 const uint yl =
TileY(tile);
212 const uint minl = std::min(xl, yl);
213 const uint minh = std::min(xh, yh);
214 return std::min(minl, minh);
230 default: NOT_REACHED();
249 assert(proc !=
nullptr);
255 if (proc(*tile, user_data))
return true;
287 assert(proc !=
nullptr);
290 uint x =
TileX(*tile) + w + 1;
291 uint y =
TileY(*tile);
295 for (uint n = 0; n < radius; n++) {
298 for (uint j = extent[dir] + n * 2 + 1; j != 0; j--) {
302 if (proc(t, user_data)) {
333 uint max_dist = water ? 0x7F : 0x200;
343 for (uint dist = 1; dist < max_dist; dist++) {
349 static const int8_t ddx[
DIAGDIR_END] = { -1, 1, 1, -1};
350 static const int8_t ddy[
DIAGDIR_END] = { 1, 1, -1, -1};
356 for (uint a = 0; a < dist; a++) {
Functions related to the allocation of memory.
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.
static TileBase * base_tiles
Pointer to the tile-array.
static TileExtended * extended_tiles
Pointer to the extended tile-array.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
DiagDirection
Enumeration for diagonal directions.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
@ DIAGDIR_END
Used for iterations.
@ DIAGDIR_BEGIN
Used for iterations.
Error reporting related functions.
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.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
const TileIndexDiffC _tileoffs_by_axis[]
'Lookup table' for tile offsets given an Axis
uint DistanceFromEdge(TileIndex tile)
Param the minimum distance to an edge.
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
uint DistanceFromEdgeDir(TileIndex tile, DiagDirection dir)
Gets the distance to the edge of the map in given direction.
uint DistanceMaxPlusManhattan(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles plus the Manhattan distance,...
const TileIndexDiffC _tileoffs_by_dir[]
'Lookup table' for tile offsets given a Direction
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 DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
uint GetClosestWaterDistance(TileIndex tile, bool water)
Finds the distance for the closest tile with water/land given a tile.
const TileIndexDiffC _tileoffs_by_diagdir[]
'Lookup table' for tile offsets given a DiagDirection
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.
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.
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.
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
static const uint MIN_MAP_SIZE
Minimal map size = 64.
int32_t TileIndexDiff
An offset value between two tiles.
constexpr T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition of base types and functions in a cross-platform compatible way.
void free(const void *ptr)
Version of the standard free that accepts const pointers.
Functions related to low-level strings.
bool freeform_edges
allow terraforming the tiles at the map edges
ConstructionSettings construction
construction of things in-game
static TileIndex WrapToMap(TileIndex tile)
'Wraps' the given "tile" so it is within the 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 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 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 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.
Data that is stored per tile.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ MP_VOID
Invisible tiles at the SW and SE border.
Map accessors for water tiles.
bool HasTileWaterGround(Tile t)
Checks whether the tile has water at the ground.
void AllocateWaterRegions()
Allocates the appropriate amount of water regions for the current map size.
Handles dividing the water in the map into regions to assist pathfinding.