2006-03-06 21:55:24 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 22:21:05 +02: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 17:11:33 +02:00
|
|
|
/** @file tunnel_map.cpp Map accessors for tunnels. */
|
2007-04-04 05:21:14 +02:00
|
|
|
|
2006-03-06 21:55:24 +01:00
|
|
|
#include "stdafx.h"
|
2007-12-16 16:38:51 +01:00
|
|
|
#include "tunnelbridge_map.h"
|
|
|
|
|
2006-03-06 21:55:24 +01:00
|
|
|
|
2007-04-18 20:20:31 +02: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 21:55:24 +01:00
|
|
|
TileIndex GetOtherTunnelEnd(TileIndex tile)
|
|
|
|
{
|
2007-12-16 16:38:51 +01:00
|
|
|
DiagDirection dir = GetTunnelBridgeDirection(tile);
|
2006-09-06 01:21:41 +02:00
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(dir);
|
2011-11-04 12:30:37 +01:00
|
|
|
int z = GetTileZ(tile);
|
2006-03-06 21:55:24 +01:00
|
|
|
|
|
|
|
dir = ReverseDiagDir(dir);
|
|
|
|
do {
|
|
|
|
tile += delta;
|
|
|
|
} while (
|
2006-03-12 16:04:03 +01:00
|
|
|
!IsTunnelTile(tile) ||
|
2007-12-16 16:38:51 +01:00
|
|
|
GetTunnelBridgeDirection(tile) != dir ||
|
2011-11-04 11:28:31 +01:00
|
|
|
GetTileZ(tile) != z
|
2006-03-06 21:55:24 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return tile;
|
|
|
|
}
|
2006-03-07 08:51:05 +01:00
|
|
|
|
|
|
|
|
2007-04-18 20:20:31 +02: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.
|
|
|
|
*/
|
2011-11-08 20:44:41 +01:00
|
|
|
bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir)
|
2006-03-07 08:51:05 +01:00
|
|
|
{
|
2006-09-06 01:21:41 +02:00
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(dir);
|
2011-11-08 20:44:41 +01:00
|
|
|
int height;
|
2006-03-07 08:51:05 +01:00
|
|
|
|
|
|
|
do {
|
|
|
|
tile -= delta;
|
2009-01-21 03:31:55 +01:00
|
|
|
if (!IsValidTile(tile)) return false;
|
2011-11-04 11:28:31 +01:00
|
|
|
height = GetTileZ(tile);
|
2006-03-07 08:51:05 +01:00
|
|
|
} while (z < height);
|
|
|
|
|
2010-11-20 16:44:24 +01:00
|
|
|
return z == height && IsTunnelTile(tile) && GetTunnelBridgeDirection(tile) == dir;
|
2006-03-07 08:51:05 +01:00
|
|
|
}
|
|
|
|
|
2007-04-18 20:20:31 +02: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.
|
|
|
|
*/
|
2011-11-08 20:44:41 +01:00
|
|
|
bool IsTunnelInWay(TileIndex tile, int z)
|
2006-03-07 08:51:05 +01:00
|
|
|
{
|
2010-11-20 16:44:24 +01:00
|
|
|
return 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 08:51:05 +01:00
|
|
|
}
|