2006-03-06 20:55:24 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file tunnel_map.cpp Map accessors for tunnels. */
|
2007-04-04 03:21:14 +00:00
|
|
|
|
2006-03-06 20:55:24 +00:00
|
|
|
#include "stdafx.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;
|
2009-01-21 02:31:55 +00:00
|
|
|
if (!IsValidTile(tile)) return false;
|
2006-03-07 07:51:05 +00:00
|
|
|
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
|
|
|
}
|