tile_map.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "tile_map.h"
00014
00021 Slope GetTileSlope(TileIndex tile, uint *h)
00022 {
00023 assert(tile < MapSize());
00024
00025 if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY() ||
00026 (_settings_game.construction.freeform_edges && (TileX(tile) == 0 || TileY(tile) == 0))) {
00027 if (h != NULL) *h = TileHeight(tile) * TILE_HEIGHT;
00028 return SLOPE_FLAT;
00029 }
00030
00031 uint a = TileHeight(tile);
00032 uint min = a;
00033 uint b = TileHeight(tile + TileDiffXY(1, 0));
00034 if (min > b) min = b;
00035 uint c = TileHeight(tile + TileDiffXY(0, 1));
00036 if (min > c) min = c;
00037 uint d = TileHeight(tile + TileDiffXY(1, 1));
00038 if (min > d) min = d;
00039
00040
00041
00042
00043
00044
00045
00046 uint r = SLOPE_FLAT;
00047
00048
00049
00050
00051
00052 if ((a -= min) != 0) r += (--a << 4) + SLOPE_N;
00053 if ((c -= min) != 0) r += (--c << 4) + SLOPE_E;
00054 if ((d -= min) != 0) r += (--d << 4) + SLOPE_S;
00055 if ((b -= min) != 0) r += (--b << 4) + SLOPE_W;
00056
00057 if (h != NULL) *h = min * TILE_HEIGHT;
00058
00059 return (Slope)r;
00060 }
00061
00067 uint GetTileZ(TileIndex tile)
00068 {
00069 if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return 0;
00070
00071 uint h = TileHeight(tile);
00072 h = min(h, TileHeight(tile + TileDiffXY(1, 0)));
00073 h = min(h, TileHeight(tile + TileDiffXY(0, 1)));
00074 h = min(h, TileHeight(tile + TileDiffXY(1, 1)));
00075
00076 return h * TILE_HEIGHT;
00077 }
00078
00084 uint GetTileMaxZ(TileIndex t)
00085 {
00086 if (TileX(t) == MapMaxX() || TileY(t) == MapMaxY()) return 0;
00087
00088 uint h = TileHeight(t);
00089 h = max(h, TileHeight(t + TileDiffXY(1, 0)));
00090 h = max(h, TileHeight(t + TileDiffXY(0, 1)));
00091 h = max(h, TileHeight(t + TileDiffXY(1, 1)));
00092
00093 return h * TILE_HEIGHT;
00094 }