|
OpenTTD Source
14.0-beta1
|
Go to the documentation of this file.
22 extern "C" _CRTIMP
void __cdecl _assert(
void *,
void *,
unsigned);
49 FatalError(
"Invalid map size");
73 const char *exp,
const char *file,
int line)
88 std::string message = fmt::format(
"TILE_ADD({}) when adding 0x{:04X} and 0x{:04X} failed",
90 #if !defined(_MSC_VER)
91 fmt::print(stderr,
"{}:{} {}\n", file, line, message);
93 _assert(message.data(), (
char*)file, line);
118 uint x =
TileX(tile) + addx;
119 uint y =
TileY(tile) + addy;
180 return dx * dx + dy * dy;
195 return std::max(dx, dy);
211 return dx > dy ? 2 * dx + dy : 2 * dy + dx;
221 const uint xl =
TileX(tile);
222 const uint yl =
TileY(tile);
225 const uint minl = std::min(xl, yl);
226 const uint minh = std::min(xh, yh);
227 return std::min(minl, minh);
243 default: NOT_REACHED();
262 assert(proc !=
nullptr);
268 if (proc(*tile, user_data))
return true;
300 assert(proc !=
nullptr);
303 uint x =
TileX(*tile) + w + 1;
304 uint y =
TileY(*tile);
308 for (uint n = 0; n < radius; n++) {
311 for (uint j = extent[dir] + n * 2 + 1; j != 0; j--) {
315 if (proc(t, user_data)) {
346 uint max_dist = water ? 0x7F : 0x200;
356 for (uint dist = 1; dist < max_dist; dist++) {
362 static const int8_t ddx[
DIAGDIR_END] = { -1, 1, 1, -1};
363 static const int8_t ddy[
DIAGDIR_END] = { 1, 1, -1, -1};
369 for (uint a = 0; a < dist; a++) {
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Data that is stored per tile.
static uint size_y
Size of the map along the Y.
const TileIndexDiffC _tileoffs_by_dir[]
'Lookup table' for tile offsets given a Direction
static const uint MIN_MAP_SIZE
Minimal map size = 64.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
bool TestTileOnSearchProc(TileIndex tile, void *user_data)
A callback function type for searching tiles.
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
static uint size_x
Size of the map along the X.
uint GetClosestWaterDistance(TileIndex tile, bool water)
Finds the distance for the closest tile with water/land given a tile.
@ DIAGDIR_END
Used for iterations.
static void Allocate(uint size_x, uint size_y)
(Re)allocates a map with the given dimension
static TileIndex WrapToMap(TileIndex tile)
'Wraps' the given "tile" so it is within the map.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
const TileIndexDiffC _tileoffs_by_diagdir[]
'Lookup table' for tile offsets given a DiagDirection
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
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.
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.
void free(const void *ptr)
Version of the standard free that accepts const pointers.
uint DistanceFromEdge(TileIndex tile)
Param the minimum distance to an edge.
static TileExtended * extended_tiles
Pointer to the extended tile-array.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
uint DistanceFromEdgeDir(TileIndex tile, DiagDirection dir)
Gets the distance to the edge of the map in given direction.
bool freeform_edges
allow terraforming the tiles at the map edges
int32_t TileIndexDiff
An offset value between two tiles.
DiagDirection
Enumeration for diagonal directions.
TileIndex TileAddByDir(TileIndex tile, Direction dir)
Adds a Direction to a tile.
static uint log_x
2^_map_log_x == _map_size_x
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
static uint log_y
2^_map_log_y == _map_size_y
A pair-construct of a TileIndexDiff.
static debug_inline uint SizeX()
Get the size of the map along the X.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
@ MP_VOID
Invisible tiles at the SW and SE border.
static debug_inline uint Size()
Get the size of the map.
@ DIAGDIR_BEGIN
Used for iterations.
static uint tile_mask
_map_size - 1 (to mask the mapsize)
void AllocateWaterRegions()
Allocates the appropriate amount of water regions for the current map size.
int16_t y
The y value of the coordinate.
constexpr T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
static TileBase * base_tiles
Pointer to the tile-array.
ConstructionSettings construction
construction of things in-game
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
uint DistanceMaxPlusManhattan(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles plus the Manhattan distance,...
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Data that is stored per tile.
bool HasTileWaterGround(Tile t)
Checks whether the tile has water at the ground.
int16_t x
The x value of the coordinate.
static uint size
The number of tiles on the map.
static uint SizeY()
Get the size of the map along the Y.
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.