tile.c
author tron
Fri, 07 Apr 2006 07:08:20 +0000
changeset 3460 0965a51903db
parent 3422 a6eba3443452
child 3636 a36cc46e754d
permissions -rw-r--r--
(svn r4304) The chat box' parent window (the main toolbar, wtf?) doesn't care for the WE_ON_EDIT_TEXT_CANCEL event, so don't send one. This code looks like it was mindlessly copy&pasted from the query box
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
*/
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    11
uint GetTileh(uint n, uint w, uint e, uint s, uint *h)
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;
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    14
	uint r;
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
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    20
	r = 0;
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    21
	if ((n -= min) != 0) r += (--n << 4) + 8;
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    22
	if ((e -= min) != 0) r += (--e << 4) + 4;
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    23
	if ((s -= min) != 0) r += (--s << 4) + 2;
3f3b6ce1f427 (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 3017
diff changeset
    24
	if ((w -= min) != 0) r += (--w << 4) + 1;
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
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1213
diff changeset
    31
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
    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
}