From 55e6b4f928656c23b1f8bb5cbb3763152213a0b0 Mon Sep 17 00:00:00 2001 From: tron Date: Sun, 9 Jan 2005 17:55:11 +0000 Subject: (svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic --- map.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'map.c') diff --git a/map.c b/map.c index 7c0791db4..a158dd6de 100644 --- a/map.c +++ b/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}, -- cgit v1.2.3-54-g00ecf