44 FatalError(
"Invalid map size");
70 uint32_t x =
TileX(tile) + dx;
71 uint32_t y =
TileY(tile) + dy;
96 uint x =
TileX(tile) + addx;
97 uint y =
TileY(tile) + addy;
164 return dx * dx + dy * dy;
179 return std::max(dx, dy);
195 return dx > dy ? 2 * dx + dy : 2 * dy + dx;
205 const uint xl =
TileX(tile);
206 const uint yl =
TileY(tile);
209 const uint minl = std::min(xl, yl);
210 const uint minh = std::min(xh, yh);
211 return std::min(minl, minh);
227 default: NOT_REACHED();
246 assert(proc !=
nullptr);
252 if (proc(*tile, user_data))
return true;
284 assert(proc !=
nullptr);
287 uint x =
TileX(*tile) + w + 1;
288 uint y =
TileY(*tile);
292 for (uint n = 0; n < radius; n++) {
295 for (uint j = extent[dir] + n * 2 + 1; j != 0; j--) {
299 if (proc(t, user_data)) {
330 uint max_dist = water ? 0x7F : 0x200;
340 for (uint dist = 1; dist < max_dist; dist++) {
346 static const int8_t ddx[
DIAGDIR_END] = { -1, 1, 1, -1};
347 static const int8_t ddy[
DIAGDIR_END] = { 1, 1, -1, -1};
353 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 std::unique_ptr< TileExtended[]> extended_tiles
Pointer to the extended tile-array.
static std::unique_ptr< TileBase[]> base_tiles
Pointer to the 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 bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
constexpr T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
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.
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.
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.