tile.c
author celestar
Mon, 01 Jan 2007 16:07:21 +0000
branchcustombridgeheads
changeset 5621 6ce400c0a2f4
parent 4067 ab047dec0733
permissions -rw-r--r--
(svn r7719) [cbh] - Codechange: KUDr and I have decided that our developemnt efforts went in the wrong direction, so revert all changes from 7686 onwards
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2049
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2049
diff changeset
     2
1213
bb9906f67932 (svn r1717) -Fix: some compilation problems for braindead VS6 and added missing files to project (thx bociusz)
darkvater
parents: 1211
diff changeset
     3
#include "stdafx.h"
1211
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     4
#include "tile.h"
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     5
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3422
diff changeset
     6
Slope GetTileSlope(TileIndex tile, uint *h)
1335
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
     7
{
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
     8
	uint a;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
     9
	uint b;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    10
	uint c;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    11
	uint d;
4067
ab047dec0733 (svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents: 3773
diff changeset
    12
	uint min;
ab047dec0733 (svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents: 3773
diff changeset
    13
	uint r;
1335
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    14
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    15
	assert(tile < MapSize());
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    16
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    17
	if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) {
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    18
		if (h != NULL) *h = 0;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    19
		return 0;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    20
	}
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    21
4067
ab047dec0733 (svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents: 3773
diff changeset
    22
	min = a = TileHeight(tile);
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    23
	b = TileHeight(tile + TileDiffXY(1, 0));
4067
ab047dec0733 (svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents: 3773
diff changeset
    24
	if (min >= b) min = b;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    25
	c = TileHeight(tile + TileDiffXY(0, 1));
4067
ab047dec0733 (svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents: 3773
diff changeset
    26
	if (min >= c) min = c;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    27
	d = TileHeight(tile + TileDiffXY(1, 1));
4067
ab047dec0733 (svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents: 3773
diff changeset
    28
	if (min >= d) min = d;
1335
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    29
4067
ab047dec0733 (svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents: 3773
diff changeset
    30
	r = SLOPE_FLAT;
ab047dec0733 (svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents: 3773
diff changeset
    31
	if ((a -= min) != 0) r += (--a << 4) + SLOPE_N;
ab047dec0733 (svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents: 3773
diff changeset
    32
	if ((c -= min) != 0) r += (--c << 4) + SLOPE_E;
ab047dec0733 (svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents: 3773
diff changeset
    33
	if ((d -= min) != 0) r += (--d << 4) + SLOPE_S;
ab047dec0733 (svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents: 3773
diff changeset
    34
	if ((b -= min) != 0) r += (--b << 4) + SLOPE_W;
ab047dec0733 (svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents: 3773
diff changeset
    35
ab047dec0733 (svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents: 3773
diff changeset
    36
	if (h != NULL) *h = min * TILE_HEIGHT;
ab047dec0733 (svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents: 3773
diff changeset
    37
ab047dec0733 (svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents: 3773
diff changeset
    38
	return r;
1335
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    39
}
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    40
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    41
uint GetTileZ(TileIndex tile)
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    42
{
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    43
	uint h;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    44
	GetTileSlope(tile, &h);
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    45
	return h;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    46
}
3773
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    47
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    48
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    49
uint GetTileMaxZ(TileIndex t)
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    50
{
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    51
	uint max;
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    52
	uint h;
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    53
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    54
	h = TileHeight(t);
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    55
	max = h;
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    56
	h = TileHeight(t + TileDiffXY(1, 0));
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    57
	if (h > max) max = h;
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    58
	h = TileHeight(t + TileDiffXY(0, 1));
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    59
	if (h > max) max = h;
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    60
	h = TileHeight(t + TileDiffXY(1, 1));
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    61
	if (h > max) max = h;
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    62
	return max * 8;
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3636
diff changeset
    63
}