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 uint x = TileX(tile);
00026 uint y = TileY(tile);
00027
00028 if (x == MapMaxX() || y == MapMaxY() ||
00029 ((x == 0 || y == 0) && _settings_game.construction.freeform_edges)) {
00030 if (h != NULL) *h = TileHeight(tile);
00031 return SLOPE_FLAT;
00032 }
00033
00034 int a = TileHeight(tile);
00035 int min = a;
00036 int b = TileHeight(tile + TileDiffXY(1, 0));
00037 if (min > b) min = b;
00038 int c = TileHeight(tile + TileDiffXY(0, 1));
00039 if (min > c) min = c;
00040 int d = TileHeight(tile + TileDiffXY(1, 1));
00041 if (min > d) min = d;
00042
00043
00044
00045
00046
00047
00048
00049 uint r = SLOPE_FLAT;
00050
00051
00052
00053
00054
00055 if ((a -= min) != 0) r += (--a << 4) + SLOPE_N;
00056 if ((c -= min) != 0) r += (--c << 4) + SLOPE_E;
00057 if ((d -= min) != 0) r += (--d << 4) + SLOPE_S;
00058 if ((b -= min) != 0) r += (--b << 4) + SLOPE_W;
00059
00060 if (h != NULL) *h = min;
00061
00062 return (Slope)r;
00063 }
00064
00070 int GetTileZ(TileIndex tile)
00071 {
00072 if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return 0;
00073
00074 int h = TileHeight(tile);
00075 h = min(h, TileHeight(tile + TileDiffXY(1, 0)));
00076 h = min(h, TileHeight(tile + TileDiffXY(0, 1)));
00077 h = min(h, TileHeight(tile + TileDiffXY(1, 1)));
00078
00079 return h;
00080 }
00081
00087 int GetTileMaxZ(TileIndex t)
00088 {
00089 if (TileX(t) == MapMaxX() || TileY(t) == MapMaxY()) return 0;
00090
00091 int h = TileHeight(t);
00092 h = max<int>(h, TileHeight(t + TileDiffXY(1, 0)));
00093 h = max<int>(h, TileHeight(t + TileDiffXY(0, 1)));
00094 h = max<int>(h, TileHeight(t + TileDiffXY(1, 1)));
00095
00096 return h;
00097 }