tile.c
author tron
Sat, 25 Jun 2005 16:44:57 +0000
changeset 1981 de031d2aed47
parent 1854 8e246ac3d172
child 2049 ad0d49c916d4
permissions -rw-r--r--
(svn r2487) Replace TILE_XY by TileXY/TileDiffXY
1213
bb9906f67932 (svn r1717) -Fix: some compilation problems for braindead VS6 and added missing files to project (thx bociusz)
darkvater
parents: 1211
diff changeset
     1
#include "stdafx.h"
1211
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     2
#include "tile.h"
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     3
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     4
void SetMapExtraBits(TileIndex tile, byte bits)
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     5
{
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     6
	assert(tile < MapSize());
1854
8e246ac3d172 (svn r2360) Use GB and SB in [GS]etMapExtraBits
tron
parents: 1335
diff changeset
     7
	SB(_map_extra_bits[tile >> 2], (tile & 3) * 2, 2, bits & 3);
1211
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     8
}
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     9
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
    10
uint GetMapExtraBits(TileIndex tile)
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
    11
{
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
    12
	assert(tile < MapSize());
1854
8e246ac3d172 (svn r2360) Use GB and SB in [GS]etMapExtraBits
tron
parents: 1335
diff changeset
    13
	return GB(_map_extra_bits[tile >> 2], (tile & 3) * 2, 2);
1211
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
    14
}
1335
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    15
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
uint GetTileSlope(TileIndex tile, uint *h)
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    18
{
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    19
	uint a;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    20
	uint b;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    21
	uint c;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    22
	uint d;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    23
	uint min;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    24
	uint r;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    25
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    26
	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
    27
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    28
	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
    29
		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
    30
		return 0;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    31
	}
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    32
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    33
	min = a = TileHeight(tile);
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    34
	b = TileHeight(tile + TileDiffXY(1, 0));
1335
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    35
	if (min >= b) min = b;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    36
	c = TileHeight(tile + TileDiffXY(0, 1));
1335
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    37
	if (min >= c) min = c;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    38
	d = TileHeight(tile + TileDiffXY(1, 1));
1335
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    39
	if (min >= d) min = d;
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
	r = 0;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    42
	if ((a -= min) != 0) { r += (--a << 4) + 8; }
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    43
	if ((c -= min) != 0) { r += (--c << 4) + 4; }
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    44
	if ((d -= min) != 0) { r += (--d << 4) + 2; }
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    45
	if ((b -= min) != 0) { r += (--b << 4) + 1; }
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    46
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    47
	if (h != NULL)
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    48
		*h = min * 8;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    49
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    50
	return r;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    51
}
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    52
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    53
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
    54
{
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    55
	uint h;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    56
	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
    57
	return h;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    58
}