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, int *h)
00022 {
00023 assert(tile < MapSize());
00024
00025 if (!IsInnerTile(tile)) {
00026 if (h != NULL) *h = TileHeight(tile);
00027 return SLOPE_FLAT;
00028 }
00029
00030 int a = TileHeight(tile);
00031 int min = a;
00032 int b = TileHeight(tile + TileDiffXY(1, 0));
00033 if (min > b) min = b;
00034 int c = TileHeight(tile + TileDiffXY(0, 1));
00035 if (min > c) min = c;
00036 int d = TileHeight(tile + TileDiffXY(1, 1));
00037 if (min > d) min = d;
00038
00039
00040
00041
00042
00043
00044
00045 uint r = SLOPE_FLAT;
00046
00047
00048
00049
00050
00051 if ((a -= min) != 0) r += (--a << 4) + SLOPE_N;
00052 if ((c -= min) != 0) r += (--c << 4) + SLOPE_E;
00053 if ((d -= min) != 0) r += (--d << 4) + SLOPE_S;
00054 if ((b -= min) != 0) r += (--b << 4) + SLOPE_W;
00055
00056 if (h != NULL) *h = min;
00057
00058 return (Slope)r;
00059 }
00060
00067 bool IsTileFlat(TileIndex tile, int *h)
00068 {
00069 assert(tile < MapSize());
00070
00071 if (!IsInnerTile(tile)) {
00072 if (h != NULL) *h = TileHeight(tile);
00073 return true;
00074 }
00075
00076 uint z = TileHeight(tile);
00077 if (TileHeight(tile + TileDiffXY(1, 0)) != z) return false;
00078 if (TileHeight(tile + TileDiffXY(0, 1)) != z) return false;
00079 if (TileHeight(tile + TileDiffXY(1, 1)) != z) return false;
00080
00081 if (h != NULL) *h = z;
00082 return true;
00083 }
00084
00090 int GetTileZ(TileIndex tile)
00091 {
00092 if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return 0;
00093
00094 int h = TileHeight(tile);
00095 h = min(h, TileHeight(tile + TileDiffXY(1, 0)));
00096 h = min(h, TileHeight(tile + TileDiffXY(0, 1)));
00097 h = min(h, TileHeight(tile + TileDiffXY(1, 1)));
00098
00099 return h;
00100 }
00101
00107 int GetTileMaxZ(TileIndex t)
00108 {
00109 if (TileX(t) == MapMaxX() || TileY(t) == MapMaxY()) return 0;
00110
00111 int h = TileHeight(t);
00112 h = max<int>(h, TileHeight(t + TileDiffXY(1, 0)));
00113 h = max<int>(h, TileHeight(t + TileDiffXY(0, 1)));
00114 h = max<int>(h, TileHeight(t + TileDiffXY(1, 1)));
00115
00116 return h;
00117 }