tron@2186: /* $Id$ */ tron@2186: darkvater@1213: #include "stdafx.h" tron@1211: #include "tile.h" tron@1211: tron@1211: void SetMapExtraBits(TileIndex tile, byte bits) tron@1211: { tron@1211: assert(tile < MapSize()); tron@2049: SB(_m[tile].extra, 0, 2, bits & 3); tron@1211: } tron@1211: tron@1211: uint GetMapExtraBits(TileIndex tile) tron@1211: { tron@1211: assert(tile < MapSize()); tron@2049: return GB(_m[tile].extra, 0, 2); tron@1211: } tron@1335: tron@1335: tron@1335: uint GetTileSlope(TileIndex tile, uint *h) tron@1335: { tron@1335: uint a; tron@1335: uint b; tron@1335: uint c; tron@1335: uint d; tron@1335: uint min; tron@1335: uint r; tron@1335: tron@1335: assert(tile < MapSize()); tron@1335: tron@1335: if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) { tron@1335: if (h != NULL) *h = 0; tron@1335: return 0; tron@1335: } tron@1335: tron@1335: min = a = TileHeight(tile); tron@1981: b = TileHeight(tile + TileDiffXY(1, 0)); tron@1335: if (min >= b) min = b; tron@1981: c = TileHeight(tile + TileDiffXY(0, 1)); tron@1335: if (min >= c) min = c; tron@1981: d = TileHeight(tile + TileDiffXY(1, 1)); tron@1335: if (min >= d) min = d; tron@1335: tron@1335: r = 0; tron@2549: if ((a -= min) != 0) r += (--a << 4) + 8; tron@2549: if ((c -= min) != 0) r += (--c << 4) + 4; tron@2549: if ((d -= min) != 0) r += (--d << 4) + 2; tron@2549: if ((b -= min) != 0) r += (--b << 4) + 1; tron@1335: tron@1335: if (h != NULL) tron@1335: *h = min * 8; tron@1335: tron@1335: return r; tron@1335: } tron@1335: tron@1335: uint GetTileZ(TileIndex tile) tron@1335: { tron@1335: uint h; tron@1335: GetTileSlope(tile, &h); tron@1335: return h; tron@1335: }