summaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-01-09 17:55:11 +0000
committertron <tron@openttd.org>2005-01-09 17:55:11 +0000
commit7ee55362c53905a98d7fb99209a1a4adf234f012 (patch)
tree0fc0024c473c2a61c0b6b9be4b9fcaae7e056ddd /map.c
parentd9ea82a8866a2376936c5eeb21a1ba9552825741 (diff)
downloadopenttd-7ee55362c53905a98d7fb99209a1a4adf234f012.tar.xz
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
Diffstat (limited to 'map.c')
-rw-r--r--map.c36
1 files changed, 36 insertions, 0 deletions
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},