Go to the documentation of this file.
20 extern "C" _CRTIMP
void __cdecl _assert(
void *,
void *,
unsigned);
45 (size_x & (size_x - 1)) != 0 ||
46 (size_y & (size_y - 1)) != 0) {
47 error(
"Invalid map size");
50 DEBUG(map, 1,
"Allocating map of size %dx%d", size_x, size_y);
69 const char *exp,
const char *file,
int line)
86 seprintf(buf,
lastof(buf),
"TILE_ADD(%s) when adding 0x%.4X and 0x%.4X failed",
88 #if !defined(_MSC_VER)
89 fprintf(stderr,
"%s:%d %s\n", file, line, buf);
91 _assert(buf, (
char*)file, line);
116 uint x =
TileX(tile) + addx;
117 uint y =
TileY(tile) + addy;
178 return dx * dx + dy * dy;
193 return std::max(dx, dy);
209 return dx > dy ? 2 * dx + dy : 2 * dy + dx;
219 const uint xl =
TileX(tile);
220 const uint yl =
TileY(tile);
221 const uint xh =
MapSizeX() - 1 - xl;
222 const uint yh =
MapSizeY() - 1 - yl;
223 const uint minl = std::min(xl, yl);
224 const uint minh = std::min(xh, yh);
225 return std::min(minl, minh);
241 default: NOT_REACHED();
260 assert(proc !=
nullptr);
266 if (proc(*tile, user_data))
return true;
298 assert(proc !=
nullptr);
301 uint x =
TileX(*tile) + w + 1;
302 uint y =
TileY(*tile);
306 for (uint n = 0; n < radius; n++) {
309 for (uint j = extent[dir] + n * 2 + 1; j != 0; j--) {
313 if (proc(t, user_data)) {
344 uint max_dist = water ? 0x7F : 0x200;
354 for (uint dist = 1; dist < max_dist; dist++) {
360 static const int8 ddx[
DIAGDIR_END] = { -1, 1, 1, -1};
361 static const int8 ddy[
DIAGDIR_END] = { 1, 1, -1, -1};
367 for (uint a = 0; a < dist; a++) {
uint _map_log_y
2^_map_log_y == _map_size_y
uint32 TileIndex
The index/ID of a Tile.
const TileIndexDiffC _tileoffs_by_dir[]
'Lookup table' for tile offsets given a Direction
static const uint MIN_MAP_SIZE
Minimal map size = 64.
bool TestTileOnSearchProc(TileIndex tile, void *user_data)
A callback function type for searching tiles.
uint _map_size
The number of tiles on the map.
uint GetClosestWaterDistance(TileIndex tile, bool water)
Finds the distance for the closest tile with water/land given a tile.
static TileIndex TileAddByDir(TileIndex tile, Direction dir)
Adds a Direction to a tile.
@ DIAGDIR_END
Used for iterations.
TileExtended * _me
Extended Tiles of the map.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
#define TILE_MASK(x)
'Wraps' the given tile to it is within the map.
const TileIndexDiffC _tileoffs_by_diagdir[]
'Lookup table' for tile offsets given a DiagDirection
static uint TileX(TileIndex tile)
Get the X component of a tile.
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
static uint MapSizeX()
Get the size of the map along the X.
uint _map_size_x
Size of the map along the X.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
int16 y
The y value of the coordinate.
static uint MapSize()
Get the size 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.
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
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.
int32 TileIndexDiff
An offset value between to tiles.
#define DEBUG(name, level,...)
Output a line of debugging information.
uint DistanceFromEdge(TileIndex tile)
Param the minimum distance to an edge.
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
DiagDirection
Enumeration for diagonal directions.
static uint MapSizeY()
Get the size of the map along the Y.
uint _map_log_x
2^_map_log_x == _map_size_x
Data that is stored per tile.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
A pair-construct of a TileIndexDiff.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
@ MP_VOID
Invisible tiles at the SW and SE border.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Data that is stored per tile.
@ DIAGDIR_BEGIN
Used for iterations.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
uint _map_tile_mask
_map_size - 1 (to mask the mapsize)
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
ConstructionSettings construction
construction of things in-game
uint DistanceMaxPlusManhattan(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles plus the Manhattan distance,...
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
uint _map_size_y
Size of the map along the Y.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
#define lastof(x)
Get the last element of an fixed size array.
void AllocateMap(uint size_x, uint size_y)
(Re)allocates a map with the given dimension
Tile * _m
Tiles of the map.
uint8 FindFirstBit(uint32 x)
Search the first set bit in a 32 bit variable.
static T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
int16 x
The x value of the coordinate.