src/tile.cpp
branchcustombridgeheads
changeset 5649 55c8267c933f
parent 5643 3778051e8095
child 5650 aefc131bf5ce
equal deleted inserted replaced
5648:1608018c5ff2 5649:55c8267c933f
       
     1 /* $Id$ */
       
     2 
       
     3 #include "stdafx.h"
       
     4 #include "tile.h"
       
     5 
       
     6 Slope GetTileSlope(TileIndex tile, uint *h)
       
     7 {
       
     8 	uint a;
       
     9 	uint b;
       
    10 	uint c;
       
    11 	uint d;
       
    12 	uint min;
       
    13 	uint r;
       
    14 
       
    15 	assert(tile < MapSize());
       
    16 
       
    17 	if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) {
       
    18 		if (h != NULL) *h = 0;
       
    19 		return 0;
       
    20 	}
       
    21 
       
    22 	min = a = TileHeight(tile);
       
    23 	b = TileHeight(tile + TileDiffXY(1, 0));
       
    24 	if (min >= b) min = b;
       
    25 	c = TileHeight(tile + TileDiffXY(0, 1));
       
    26 	if (min >= c) min = c;
       
    27 	d = TileHeight(tile + TileDiffXY(1, 1));
       
    28 	if (min >= d) min = d;
       
    29 
       
    30 	r = SLOPE_FLAT;
       
    31 	if ((a -= min) != 0) r += (--a << 4) + SLOPE_N;
       
    32 	if ((c -= min) != 0) r += (--c << 4) + SLOPE_E;
       
    33 	if ((d -= min) != 0) r += (--d << 4) + SLOPE_S;
       
    34 	if ((b -= min) != 0) r += (--b << 4) + SLOPE_W;
       
    35 
       
    36 	if (h != NULL) *h = min * TILE_HEIGHT;
       
    37 
       
    38 	return r;
       
    39 }
       
    40 
       
    41 uint GetTileZ(TileIndex tile)
       
    42 {
       
    43 	uint h;
       
    44 	GetTileSlope(tile, &h);
       
    45 	return h;
       
    46 }
       
    47 
       
    48 
       
    49 uint GetTileMaxZ(TileIndex t)
       
    50 {
       
    51 	uint max;
       
    52 	uint h;
       
    53 
       
    54 	h = TileHeight(t);
       
    55 	max = h;
       
    56 	h = TileHeight(t + TileDiffXY(1, 0));
       
    57 	if (h > max) max = h;
       
    58 	h = TileHeight(t + TileDiffXY(0, 1));
       
    59 	if (h > max) max = h;
       
    60 	h = TileHeight(t + TileDiffXY(1, 1));
       
    61 	if (h > max) max = h;
       
    62 	return max * 8;
       
    63 }