tile.c
author tron
Fri, 24 Feb 2006 19:52:26 +0000
changeset 3075 fd64f71655eb
parent 3017 a75caf4efa2d
child 3279 3f3b6ce1f427
permissions -rw-r--r--
(svn r3664) Add a function to turn a tile into a void tile
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
43ae74415fdd (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     6
void SetMapExtraBits(TileIndex tile, byte bits)
43ae74415fdd (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     7
{
43ae74415fdd (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
     8
	assert(tile < MapSize());
2049
538e73c53f54 (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
43ae74415fdd (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
    10
}
43ae74415fdd (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
    11
43ae74415fdd (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
    12
uint GetMapExtraBits(TileIndex tile)
43ae74415fdd (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
    13
{
43ae74415fdd (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
    14
	assert(tile < MapSize());
2049
538e73c53f54 (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
43ae74415fdd (svn r1715) Move [GS]etMapExtraBits to tile.[ch]
tron
parents:
diff changeset
    16
}
1335
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    17
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    18
a5f223b9f549 (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)
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    20
{
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    21
	uint a;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    22
	uint b;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    23
	uint c;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    24
	uint d;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    25
	uint min;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    26
	uint r;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    27
a5f223b9f549 (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());
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    29
a5f223b9f549 (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()) {
a5f223b9f549 (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;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    32
		return 0;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    33
	}
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    34
a5f223b9f549 (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
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    36
	b = TileHeight(tile + TileDiffXY(1, 0));
1335
a5f223b9f549 (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
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    38
	c = TileHeight(tile + TileDiffXY(0, 1));
1335
a5f223b9f549 (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
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1854
diff changeset
    40
	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
    41
	if (min >= d) min = d;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    42
a5f223b9f549 (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
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
    44
	if ((a -= min) != 0) r += (--a << 4) + 8;
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
    45
	if ((c -= min) != 0) r += (--c << 4) + 4;
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
    46
	if ((d -= min) != 0) r += (--d << 4) + 2;
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
    47
	if ((b -= min) != 0) r += (--b << 4) + 1;
1335
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    48
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2549
diff changeset
    49
	if (h != NULL) *h = min * 8;
1335
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    50
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    51
	return r;
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
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    54
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
    55
{
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    56
	uint h;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    57
	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
    58
	return h;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    59
}