tile.c
author Darkvater
Tue, 21 Mar 2006 09:14:41 +0000
changeset 3280 524352fbb229
parent 3279 7c642c5c501c
child 3379 ea8aa9e71328
permissions -rw-r--r--
(svn r3994) - Fix: convert filenames to UTF-8-MAC instead of UTF-8 for MACOSX, because that's what it uses. This is no real fix for the current iconv hack but it should at least work properly
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
3279
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    18
/** Converts the heights of 4 corners into a tileh, and returns the minimum height of the tile
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    19
  * @param n,w,e,s the four corners
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    20
  * @param h uint pointer to write the height to
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    21
  * @return the tileh
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    22
*/
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    23
uint GetTileh(uint n, uint w, uint e, uint s, uint *h)
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    24
{
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    25
	uint min = n;
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    26
	uint r;
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    27
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    28
	if (min >= w) min = w;
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    29
	if (min >= e) min = e;
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    30
	if (min >= s) min = s;
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    31
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    32
	r = 0;
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    33
	if ((n -= min) != 0) r += (--n << 4) + 8;
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    34
	if ((e -= min) != 0) r += (--e << 4) + 4;
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    35
	if ((s -= min) != 0) r += (--s << 4) + 2;
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    36
	if ((w -= min) != 0) r += (--w << 4) + 1;
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    37
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    38
	if (h != NULL) *h = min * 8;
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    39
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    40
	return r;
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    41
}
1335
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 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
    44
{
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    45
	uint a;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    46
	uint b;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    47
	uint c;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    48
	uint d;
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
	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
    51
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    52
	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
    53
		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
    54
		return 0;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    55
	}
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    56
3279
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    57
	a = TileHeight(tile);
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    58
	b = TileHeight(tile + TileDiffXY(1, 0));
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    59
	c = TileHeight(tile + TileDiffXY(0, 1));
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    60
	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
    61
3279
7c642c5c501c (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    62
	return GetTileh(a, b, c, d, h);
1335
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    63
}
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    64
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    65
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
    66
{
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    67
	uint h;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    68
	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
    69
	return h;
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    70
}