2006-03-06 20:55:24 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/** @file tunnel_map.cpp */
|
|
|
|
|
2006-03-06 20:55:24 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "openttd.h"
|
|
|
|
#include "tunnel_map.h"
|
2007-12-16 15:38:51 +00:00
|
|
|
#include "tunnelbridge_map.h"
|
|
|
|
|
2006-03-06 20:55:24 +00:00
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Gets the other end of the tunnel. Where a vehicle would reappear when it
|
|
|
|
* enters at the given tile.
|
|
|
|
* @param tile the tile to search from.
|
|
|
|
* @return the tile of the other end of the tunnel.
|
|
|
|
*/
|
2006-03-06 20:55:24 +00:00
|
|
|
TileIndex GetOtherTunnelEnd(TileIndex tile)
|
|
|
|
{
|
2007-12-16 15:38:51 +00:00
|
|
|
DiagDirection dir = GetTunnelBridgeDirection(tile);
|
2006-09-05 23:21:41 +00:00
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(dir);
|
2006-03-06 20:55:24 +00:00
|
|
|
uint z = GetTileZ(tile);
|
|
|
|
|
|
|
|
dir = ReverseDiagDir(dir);
|
|
|
|
do {
|
|
|
|
tile += delta;
|
|
|
|
} while (
|
2006-03-12 15:04:03 +00:00
|
|
|
!IsTunnelTile(tile) ||
|
2007-12-16 15:38:51 +00:00
|
|
|
GetTunnelBridgeDirection(tile) != dir ||
|
2006-03-06 20:55:24 +00:00
|
|
|
GetTileZ(tile) != z
|
|
|
|
);
|
|
|
|
|
|
|
|
return tile;
|
|
|
|
}
|
2006-03-07 07:51:05 +00:00
|
|
|
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Is there a tunnel in the way in the given direction?
|
|
|
|
* @param tile the tile to search from.
|
|
|
|
* @param z the 'z' to search on.
|
|
|
|
* @param dir the direction to start searching to.
|
|
|
|
* @return true if and only if there is a tunnel.
|
|
|
|
*/
|
2007-06-21 17:25:17 +00:00
|
|
|
bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir)
|
2006-03-07 07:51:05 +00:00
|
|
|
{
|
2006-09-05 23:21:41 +00:00
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(dir);
|
2006-03-07 07:51:05 +00:00
|
|
|
uint height;
|
|
|
|
|
|
|
|
do {
|
|
|
|
tile -= delta;
|
|
|
|
height = GetTileZ(tile);
|
|
|
|
} while (z < height);
|
|
|
|
|
|
|
|
return
|
|
|
|
z == height &&
|
2006-03-12 15:04:03 +00:00
|
|
|
IsTunnelTile(tile) &&
|
2007-12-16 15:38:51 +00:00
|
|
|
GetTunnelBridgeDirection(tile) == dir;
|
2006-03-07 07:51:05 +00:00
|
|
|
}
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Is there a tunnel in the way in any direction?
|
|
|
|
* @param tile the tile to search from.
|
|
|
|
* @param z the 'z' to search on.
|
|
|
|
* @return true if and only if there is a tunnel.
|
|
|
|
*/
|
2006-03-07 07:51:05 +00:00
|
|
|
bool IsTunnelInWay(TileIndex tile, uint z)
|
|
|
|
{
|
|
|
|
return
|
2007-07-25 15:45:46 +00:00
|
|
|
IsTunnelInWayDir(tile, z, (TileX(tile) > (MapMaxX() / 2)) ? DIAGDIR_NE : DIAGDIR_SW) ||
|
|
|
|
IsTunnelInWayDir(tile, z, (TileY(tile) > (MapMaxY() / 2)) ? DIAGDIR_NW : DIAGDIR_SE);
|
2006-03-07 07:51:05 +00:00
|
|
|
}
|