tunnel_map.c
author peter1138
Thu, 29 Jun 2006 07:19:24 +0000
changeset 4094 a83fac319c4e
parent 3184 7405329343ce
child 4290 2d6895dc84eb
permissions -rw-r--r--
(svn r5426) - Makefile: Make the configure script work properly for setting target compilers; Set CC_TARGET / CXX_TARGET
up the same way as CC_HOST / CXX_HOST, and add or fix their options within the configure script. In the
Makefile, instead of overriding CC / CXX with the target compilers if they are set, set the target compilers
with the default compilers if none are set (bit of a mouthful), and use the target compilers explicitly.
/* $Id$ */

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

TileIndex GetOtherTunnelEnd(TileIndex tile)
{
	DiagDirection dir = GetTunnelDirection(tile);
	TileIndexDiff delta = TileOffsByDir(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 = TileOffsByDir(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);
}