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: celestar@3279: /** Converts the heights of 4 corners into a tileh, and returns the minimum height of the tile celestar@3279: * @param n,w,e,s the four corners celestar@3279: * @param h uint pointer to write the height to celestar@3279: * @return the tileh celestar@3279: */ celestar@3279: uint GetTileh(uint n, uint w, uint e, uint s, uint *h) celestar@3279: { celestar@3279: uint min = n; celestar@3279: uint r; celestar@3279: celestar@3279: if (min >= w) min = w; celestar@3279: if (min >= e) min = e; celestar@3279: if (min >= s) min = s; celestar@3279: celestar@3279: r = 0; celestar@3279: if ((n -= min) != 0) r += (--n << 4) + 8; celestar@3279: if ((e -= min) != 0) r += (--e << 4) + 4; celestar@3279: if ((s -= min) != 0) r += (--s << 4) + 2; celestar@3279: if ((w -= min) != 0) r += (--w << 4) + 1; celestar@3279: celestar@3279: if (h != NULL) *h = min * 8; celestar@3279: celestar@3279: return r; celestar@3279: } 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: 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: celestar@3279: a = TileHeight(tile); tron@1981: b = TileHeight(tile + TileDiffXY(1, 0)); tron@1981: c = TileHeight(tile + TileDiffXY(0, 1)); tron@1981: d = TileHeight(tile + TileDiffXY(1, 1)); tron@1335: celestar@3279: return GetTileh(a, b, c, d, h); 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: }