tunnel_map.c
author miham
Fri, 08 Dec 2006 17:40:42 +0000
changeset 5285 b4a8aa4e55fe
parent 4559 c853d2440065
child 5513 0d3227e250eb
permissions -rw-r--r--
(svn r7434) WebTranslator2 update to 2006-12-08 18:40:00
american - 1 fixed by WhiteRabbit (1)
bulgarian - 5 fixed, 2 changed by groupsky (7)
esperanto - 314 fixed, 31 changed by LaPingvino (345)
french - 3 fixed, 5 changed by glx (8)
italian - 7 fixed, 3 changed by sidew (10)
portuguese - 3 fixed by izhirahider (3)
slovak - 7 fixed, 8 changed by lengyel (15)
ukrainian - 10 fixed by znikoz (10)
/* $Id$ */

#include "stdafx.h"
#include "openttd.h"
#include "tile.h"
#include "tunnel_map.h"

TileIndex GetOtherTunnelEnd(TileIndex tile)
{
	DiagDirection dir = GetTunnelDirection(tile);
	TileIndexDiff delta = TileOffsByDiagDir(dir);
	uint z = GetTileZ(tile);

	dir = ReverseDiagDir(dir);
	do {
		tile += delta;
	} while (
		!IsTunnelTile(tile) ||
		GetTunnelDirection(tile) != dir ||
		GetTileZ(tile) != z
	);

	return tile;
}


static bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir)
{
	TileIndexDiff delta = TileOffsByDiagDir(dir);
	uint height;

	do {
		tile -= delta;
		height = GetTileZ(tile);
	} while (z < height);

	return
		z == height &&
		IsTunnelTile(tile) &&
		GetTunnelDirection(tile) == dir;
}

bool IsTunnelInWay(TileIndex tile, uint z)
{
	return
		IsTunnelInWayDir(tile, z, DIAGDIR_NE) ||
		IsTunnelInWayDir(tile, z, DIAGDIR_SE) ||
		IsTunnelInWayDir(tile, z, DIAGDIR_SW) ||
		IsTunnelInWayDir(tile, z, DIAGDIR_NW);
}