forked from mirror/OpenTTD
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
This commit is contained in:
36
map.c
36
map.c
@@ -18,6 +18,42 @@ byte _map_owner [MAP_SIZE];
|
||||
uint16 _map2 [MAP_SIZE];
|
||||
byte _map_extra_bits [MAP_SIZE / 4];
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
|
||||
const char *exp, const char *file, int line)
|
||||
{
|
||||
int dx;
|
||||
int dy;
|
||||
uint x;
|
||||
uint y;
|
||||
|
||||
dx = add & MapMaxX();
|
||||
if (dx >= MapSizeX() / 2) dx -= MapSizeX();
|
||||
dy = (add - dx) / (int)MapSizeX();
|
||||
|
||||
x = TileX(tile) + dx;
|
||||
y = TileY(tile) + dy;
|
||||
|
||||
if (x >= MapSizeX() || y >= MapSizeY()) {
|
||||
char buf[512];
|
||||
|
||||
sprintf(buf, "TILE_ADD(%s) when adding 0x%.4X and 0x%.4X failed",
|
||||
exp, tile, add);
|
||||
#if !defined(_MSC_VER)
|
||||
fprintf(stderr, "%s:%d %s\n", file, line, buf);
|
||||
#else
|
||||
_assert(buf, (char*)file, line);
|
||||
#endif
|
||||
}
|
||||
|
||||
assert(TILE_XY(x,y) == TILE_MASK(tile + add));
|
||||
|
||||
return TILE_XY(x,y);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
const TileIndexDiffC _tileoffs_by_dir[] = {
|
||||
{-1, 0},
|
||||
{ 0, 1},
|
||||
|
Reference in New Issue
Block a user