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;
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 =
min(xl, yl);
224 const uint minh =
min(xh, yh);
225 return 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)) {
321 x += _tileoffs_by_diagdir[dir].
x;
322 y += _tileoffs_by_diagdir[dir].
y;
326 x += _tileoffs_by_dir[
DIR_W].
x;
327 y += _tileoffs_by_dir[
DIR_W].
y;
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_size
The number of tiles on the map.
static uint MapSizeX()
Get the size of the map along the X.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
uint _map_size_x
Size of the map along the X.
static uint MapSizeY()
Get the size of the map along the Y.
int32 TileIndexDiff
An offset value between to tiles.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Functions related to debugging.
Tile * _m
Tiles of the map.
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
void AllocateMap(uint size_x, uint size_y)
(Re)allocates a map with the given dimension
static uint TileX(TileIndex tile)
Get the X component of a tile.
#define lastof(x)
Get the last element of an fixed size array.
static T max(const T a, const T b)
Returns the maximum of two values.
static const uint MIN_MAP_SIZE
Minimal map size = 64.
const TileIndexDiffC _tileoffs_by_dir[]
'Lookup table' for tile offsets given a Direction
bool freeform_edges
allow terraforming the tiles at the map edges
int16 y
The y value of the coordinate.
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
Functions related to low-level strings.
uint _map_size_y
Size of the map along the Y.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
uint _map_tile_mask
_map_size - 1 (to mask the mapsize)
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
Functions related to the allocation of memory.
Map accessors for water tiles.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
int16 x
The x value of the coordinate.
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.
TileExtended * _me
Extended Tiles of the map.
Data that is stored per tile.
const TileIndexDiffC _tileoffs_by_diagdir[]
'Lookup table' for tile offsets given a DiagDirection
static T min(const T a, const T b)
Returns the minimum of two values.
uint DistanceFromEdgeDir(TileIndex tile, DiagDirection dir)
Gets the distance to the edge of the map in given direction.
uint DistanceFromEdge(TileIndex tile)
Param the minimum distance to an edge.
Data that is stored per tile.
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. ...
#define DEBUG(name, level,...)
Output a line of debugging information.
uint8 FindFirstBit(uint32 x)
Search the first set bit in a 32 bit variable.
uint GetClosestWaterDistance(TileIndex tile, bool water)
Finds the distance for the closest tile with water/land given a tile.
A pair-construct of a TileIndexDiff.
static uint MapSize()
Get the size of the map.
Invisible tiles at the SW and SE border.
uint32 TileIndex
The index/ID of a Tile.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
uint DistanceMaxPlusManhattan(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles plus the Manhattan distance...
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
bool TestTileOnSearchProc(TileIndex tile, void *user_data)
A callback function type for searching tiles.
ConstructionSettings construction
construction of things in-game
uint _map_log_x
2^_map_log_x == _map_size_x
static TileIndex TileAddByDir(TileIndex tile, Direction dir)
Adds a Direction to a tile.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
DiagDirection
Enumeration for diagonal directions.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Northeast, upper right on your monitor.
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
static T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
#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.
uint _map_log_y
2^_map_log_y == _map_size_y