tile.c
author Darkvater
Wed, 25 Jan 2006 19:14:50 +0000
changeset 2882 54af2e527411
parent 2549 f1d3b383d557
child 3017 915fae59d5e0
child 9942 56446313309e
permissions -rw-r--r--
(svn r3430) - You can of course not join when there are more companies than the maximum set, not the other way around.
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
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     6
void SetMapExtraBits(TileIndex tile, byte bits)
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     7
{
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     8
	assert(tile < MapSize());
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
     9
	SB(_m[tile].extra, 0, 2, bits & 3);
1211
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
    10
}
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
uint GetMapExtraBits(TileIndex tile)
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
    13
{
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
    14
	assert(tile < MapSize());
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
    15
	return GB(_m[tile].extra, 0, 2);
1211
6f2f723e5c36 (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
    16
}
1335
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    17
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 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
    20
{
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    21
	uint a;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    22
	uint b;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    23
	uint c;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    24
	uint d;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    25
	uint min;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    26
	uint r;
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
	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
    29
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    30
	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
    31
		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
    32
		return 0;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    33
	}
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    34
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    35
	min = a = TileHeight(tile);
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    36
	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
    37
	if (min >= b) min = b;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    38
	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
    39
	if (min >= c) min = c;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    40
	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
    41
	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
    42
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    43
	r = 0;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
    44
	if ((a -= min) != 0) r += (--a << 4) + 8;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
    45
	if ((c -= min) != 0) r += (--c << 4) + 4;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
    46
	if ((d -= min) != 0) r += (--d << 4) + 2;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
    47
	if ((b -= min) != 0) r += (--b << 4) + 1;
1335
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    48
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    49
	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
    50
		*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
    51
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    52
	return r;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    53
}
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 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
    56
{
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    57
	uint h;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    58
	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
    59
	return h;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    60
}