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 #include "core/math_func.hpp"
00015
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
00066 uint GetTileZ(TileIndex tile)
00067 {
00068 if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return 0;
00069
00070 uint h = TileHeight(tile);
00071 h = min(h, TileHeight(tile + TileDiffXY(1, 0)));
00072 h = min(h, TileHeight(tile + TileDiffXY(0, 1)));
00073 h = min(h, TileHeight(tile + TileDiffXY(1, 1)));
00074
00075 return h * TILE_HEIGHT;
00076 }
00077
00082 uint GetTileMaxZ(TileIndex t)
00083 {
00084 if (TileX(t) == MapMaxX() || TileY(t) == MapMaxY()) return 0;
00085
00086 uint h = TileHeight(t);
00087 h = max(h, TileHeight(t + TileDiffXY(1, 0)));
00088 h = max(h, TileHeight(t + TileDiffXY(0, 1)));
00089 h = max(h, TileHeight(t + TileDiffXY(1, 1)));
00090
00091 return h * TILE_HEIGHT;
00092 }