# tile_map.cpp

Go to the documentation of this file.

    00001 /* $Id: tile_map.cpp 11914 2008-01-18 03:48:29Z glx $ */
    00002
    00005 #include "stdafx.h"
    00006 #include "openttd.h"
    00007 #include "tile_map.h"
    00008 #include "core/math_func.hpp"
    00009
    00010 Slope GetTileSlope(TileIndex tile, uint *h)
    00011 {
    00012   uint a;
    00013   uint b;
    00014   uint c;
    00015   uint d;
    00016   uint min;
    00017   uint r;
    00018
    00019   assert(tile < MapSize());
    00020
    00021   if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) {
    00022     if (h != NULL) *h = 0;
    00023     return SLOPE_FLAT;
    00024   }
    00025
    00026   min = a = TileHeight(tile);
    00027   b = TileHeight(tile + TileDiffXY(1, 0));
    00028   if (min > b) min = b;
    00029   c = TileHeight(tile + TileDiffXY(0, 1));
    00030   if (min > c) min = c;
    00031   d = TileHeight(tile + TileDiffXY(1, 1));
    00032   if (min > d) min = d;
    00033
    00034   r = SLOPE_FLAT;
    00035   if ((a -= min) != 0) r += (--a << 4) + SLOPE_N;
    00036   if ((c -= min) != 0) r += (--c << 4) + SLOPE_E;
    00037   if ((d -= min) != 0) r += (--d << 4) + SLOPE_S;
    00038   if ((b -= min) != 0) r += (--b << 4) + SLOPE_W;
    00039
    00040   if (h != NULL) *h = min * TILE_HEIGHT;
    00041
    00042   return (Slope)r;
    00043 }
    00044
    00045 uint GetTileZ(TileIndex tile)
    00046 {
    00047   if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return 0;
    00048
    00049   uint h = TileHeight(tile);
    00050   h = min(h, TileHeight(tile + TileDiffXY(1, 0)));
    00051   h = min(h, TileHeight(tile + TileDiffXY(0, 1)));
    00052   h = min(h, TileHeight(tile + TileDiffXY(1, 1)));
    00053
    00054   return h * TILE_HEIGHT;
    00055 }
    00056
    00057
    00058 uint GetTileMaxZ(TileIndex t)
    00059 {
    00060   if (TileX(t) == MapMaxX() || TileY(t) == MapMaxY()) return 0;
    00061
    00062   uint h = TileHeight(t);
    00063   h = max(h, TileHeight(t + TileDiffXY(1, 0)));
    00064   h = max(h, TileHeight(t + TileDiffXY(0, 1)));
    00065   h = max(h, TileHeight(t + TileDiffXY(1, 1)));
    00066
    00067   return h * TILE_HEIGHT;
    00068 }