tile_map.cpp
Go to the documentation of this file.00001
00002
00005 #include "stdafx.h"
00006 #include "tile_map.h"
00007 #include "core/math_func.hpp"
00008 #include "settings_type.h"
00009
00015 Slope GetTileSlope(TileIndex tile, uint *h)
00016 {
00017 assert(tile < MapSize());
00018
00019 if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY() ||
00020 (_settings_game.construction.freeform_edges && (TileX(tile) == 0 || TileY(tile) == 0))) {
00021 if (h != NULL) *h = TileHeight(tile) * TILE_HEIGHT;
00022 return SLOPE_FLAT;
00023 }
00024
00025 uint a = TileHeight(tile);
00026 uint min = a;
00027 uint b = TileHeight(tile + TileDiffXY(1, 0));
00028 if (min > b) min = b;
00029 uint c = TileHeight(tile + TileDiffXY(0, 1));
00030 if (min > c) min = c;
00031 uint d = TileHeight(tile + TileDiffXY(1, 1));
00032 if (min > d) min = d;
00033
00034
00035
00036
00037
00038
00039
00040 uint r = SLOPE_FLAT;
00041
00042
00043
00044
00045
00046 if ((a -= min) != 0) r += (--a << 4) + SLOPE_N;
00047 if ((c -= min) != 0) r += (--c << 4) + SLOPE_E;
00048 if ((d -= min) != 0) r += (--d << 4) + SLOPE_S;
00049 if ((b -= min) != 0) r += (--b << 4) + SLOPE_W;
00050
00051 if (h != NULL) *h = min * TILE_HEIGHT;
00052
00053 return (Slope)r;
00054 }
00055
00060 uint GetTileZ(TileIndex tile)
00061 {
00062 if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return 0;
00063
00064 uint h = TileHeight(tile);
00065 h = min(h, TileHeight(tile + TileDiffXY(1, 0)));
00066 h = min(h, TileHeight(tile + TileDiffXY(0, 1)));
00067 h = min(h, TileHeight(tile + TileDiffXY(1, 1)));
00068
00069 return h * TILE_HEIGHT;
00070 }
00071
00076 uint GetTileMaxZ(TileIndex t)
00077 {
00078 if (TileX(t) == MapMaxX() || TileY(t) == MapMaxY()) return 0;
00079
00080 uint h = TileHeight(t);
00081 h = max(h, TileHeight(t + TileDiffXY(1, 0)));
00082 h = max(h, TileHeight(t + TileDiffXY(0, 1)));
00083 h = max(h, TileHeight(t + TileDiffXY(1, 1)));
00084
00085 return h * TILE_HEIGHT;
00086 }