tile.c
author peter1138
Wed, 17 May 2006 21:26:12 +0000
changeset 3865 b80b50f14fcd
parent 3773 0019b5f70ea9
child 4067 5ef297943eff
permissions -rw-r--r--
(svn r4901) - Codechange: change 'SpriteGroup *' to 'struct SpriteGroup *' within StationSpec and GRFFile struct declarations. Now only code which actually references those pointers needs to know about the SpriteGroup struct. Remove some unnecessary lingering header dependencies.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2049
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2049
diff changeset
     2
1213
fc87a2ee4161 (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
43ae74415fdd (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     4
#include "tile.h"
43ae74415fdd (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     5
3279
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
     6
/** Converts the heights of 4 corners into a tileh, and returns the minimum height of the tile
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
     7
  * @param n,w,e,s the four corners
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
     8
  * @param h uint pointer to write the height to
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
     9
  * @return the tileh
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    10
*/
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3422
diff changeset
    11
Slope GetTileh(uint n, uint w, uint e, uint s, uint *h)
3279
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    12
{
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    13
	uint min = n;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3422
diff changeset
    14
	Slope r;
3279
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    15
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    16
	if (min >= w) min = w;
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    17
	if (min >= e) min = e;
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    18
	if (min >= s) min = s;
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    19
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3422
diff changeset
    20
	r = SLOPE_FLAT;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3422
diff changeset
    21
	if ((n -= min) != 0) r += (--n << 4) + SLOPE_N;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3422
diff changeset
    22
	if ((e -= min) != 0) r += (--e << 4) + SLOPE_E;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3422
diff changeset
    23
	if ((s -= min) != 0) r += (--s << 4) + SLOPE_S;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3422
diff changeset
    24
	if ((w -= min) != 0) r += (--w << 4) + SLOPE_W;
3279
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    25
3422
a6eba3443452 (svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents: 3379
diff changeset
    26
	if (h != NULL) *h = min * TILE_HEIGHT;
3279
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    27
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    28
	return r;
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    29
}
1335
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    30
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3422
diff changeset
    31
Slope GetTileSlope(TileIndex tile, uint *h)
1335
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    32
{
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    33
	uint a;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    34
	uint b;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    35
	uint c;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    36
	uint d;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    37
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    38
	assert(tile < MapSize());
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    39
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    40
	if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) {
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    41
		if (h != NULL) *h = 0;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    42
		return 0;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    43
	}
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    44
3279
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    45
	a = TileHeight(tile);
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    46
	b = TileHeight(tile + TileDiffXY(1, 0));
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    47
	c = TileHeight(tile + TileDiffXY(0, 1));
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    48
	d = TileHeight(tile + TileDiffXY(1, 1));
1335
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    49
3279
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    50
	return GetTileh(a, b, c, d, h);
1335
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    51
}
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    52
a5f223b9f549 (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)
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    54
{
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    55
	uint h;
a5f223b9f549 (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);
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    57
	return h;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    58
}
3773
0019b5f70ea9 (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
0019b5f70ea9 (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
0019b5f70ea9 (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
uint GetTileMaxZ(TileIndex t)
0019b5f70ea9 (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
{
0019b5f70ea9 (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
	uint max;
0019b5f70ea9 (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
    64
	uint h;
0019b5f70ea9 (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
    65
0019b5f70ea9 (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
    66
	h = TileHeight(t);
0019b5f70ea9 (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
    67
	max = h;
0019b5f70ea9 (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
    68
	h = TileHeight(t + TileDiffXY(1, 0));
0019b5f70ea9 (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
    69
	if (h > max) max = h;
0019b5f70ea9 (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
    70
	h = TileHeight(t + TileDiffXY(0, 1));
0019b5f70ea9 (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
    71
	if (h > max) max = h;
0019b5f70ea9 (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
    72
	h = TileHeight(t + TileDiffXY(1, 1));
0019b5f70ea9 (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
    73
	if (h > max) max = h;
0019b5f70ea9 (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
    74
	return max * 8;
0019b5f70ea9 (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
    75
}