22 extern "C" _CRTIMP
void __cdecl _assert(
void *,
void *,
unsigned);
47 (size_x & (size_x - 1)) != 0 ||
48 (size_y & (size_y - 1)) != 0) {
49 error(
"Invalid map size");
52 DEBUG(map, 1,
"Allocating map of size %dx%d", size_x, size_y);
71 const char *exp,
const char *file,
int line)
88 seprintf(buf,
lastof(buf),
"TILE_ADD(%s) when adding 0x%.4X and 0x%.4X failed",
90 #if !defined(_MSC_VER) || defined(WINCE) 91 fprintf(stderr,
"%s:%d %s\n", file, line, buf);
93 _assert(buf, (
char*)file, line);
118 uint x =
TileX(tile) + addx;
119 uint y =
TileY(tile) + addy;
180 return dx * dx + dy * dy;
211 return dx > dy ? 2 * dx + dy : 2 * dy + dx;
221 const uint xl =
TileX(tile);
222 const uint yl =
TileY(tile);
223 const uint xh =
MapSizeX() - 1 - xl;
224 const uint yh =
MapSizeY() - 1 - yl;
225 const uint minl =
min(xl, yl);
226 const uint minh =
min(xh, yh);
227 return min(minl, minh);
243 default: NOT_REACHED();
262 assert(proc != NULL);
268 if (proc(*tile, user_data))
return true;
300 assert(proc != NULL);
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)) {
323 x += _tileoffs_by_diagdir[dir].
x;
324 y += _tileoffs_by_diagdir[dir].
y;
328 x += _tileoffs_by_dir[
DIR_W].
x;
329 y += _tileoffs_by_dir[
DIR_W].
y;
346 uint max_dist = water ? 0x7F : 0x200;
356 for (uint dist = 1; dist < max_dist; dist++) {
362 static const int8 ddx[
DIAGDIR_END] = { -1, 1, 1, -1};
363 static const int8 ddy[
DIAGDIR_END] = { 1, 1, -1, -1};
369 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.
static bool IsInsideMM(const T x, const uint min, const uint max)
Checks if a value is in an interval.
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.
Northeast, upper right on your monitor.
#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.
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 give 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
DiagDirection
Enumeration for diagonal directions.
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.
static TileIndexDiff TileOffsByDir(Direction dir)
Convert a Direction to a TileIndexDiff.
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 void free(const void *ptr)
Version of the standard free that accepts const pointers.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
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.
#define TILE_ADD(x, y)
Adds to tiles together.
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