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 road_map.cpp Complex road accessors. */
|
2007-03-28 20:41:35 +00:00
|
|
|
|
2006-03-05 12:22:20 +00:00
|
|
|
#include "stdafx.h"
|
2006-03-31 19:10:54 +00:00
|
|
|
#include "station_map.h"
|
2007-12-16 15:38:51 +00:00
|
|
|
#include "tunnelbridge_map.h"
|
2006-03-05 12:22:20 +00:00
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2006-03-05 12:22:20 +00:00
|
|
|
|
2011-01-18 23:09:43 +00:00
|
|
|
/**
|
|
|
|
* Returns the RoadBits on an arbitrary tile
|
|
|
|
* Special behaviour:
|
|
|
|
* - road depots: entrance is treated as road piece
|
|
|
|
* - road tunnels: entrance is treated as road piece
|
|
|
|
* - bridge ramps: start of the ramp is treated as road piece
|
|
|
|
* - bridge middle parts: bridge itself is ignored
|
|
|
|
*
|
|
|
|
* If straight_tunnel_bridge_entrance is set a ROAD_X or ROAD_Y
|
|
|
|
* for bridge ramps and tunnel entrances is returned depending
|
|
|
|
* on the orientation of the tunnel or bridge.
|
|
|
|
* @param tile the tile to get the road bits for
|
|
|
|
* @param rt the road type to get the road bits form
|
|
|
|
* @param straight_tunnel_bridge_entrance whether to return straight road bits for tunnels/bridges.
|
|
|
|
* @return the road bits of the given tile
|
|
|
|
*/
|
2019-04-06 06:46:15 +00:00
|
|
|
RoadBits GetAnyRoadBits(TileIndex tile, RoadTramType rtt, bool straight_tunnel_bridge_entrance)
|
2006-03-05 12:22:20 +00:00
|
|
|
{
|
2019-04-06 06:46:15 +00:00
|
|
|
if (!MayHaveRoad(tile) || !HasTileRoadType(tile, rtt)) return ROAD_NONE;
|
2007-05-20 19:14:08 +00:00
|
|
|
|
2006-03-05 12:22:20 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2007-07-29 23:42:59 +00:00
|
|
|
case MP_ROAD:
|
2006-05-09 08:25:31 +00:00
|
|
|
switch (GetRoadTileType(tile)) {
|
2006-03-05 12:22:20 +00:00
|
|
|
default:
|
2019-04-06 06:46:15 +00:00
|
|
|
case ROAD_TILE_NORMAL: return GetRoadBits(tile, rtt);
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_CROSSING: return GetCrossingRoadBits(tile);
|
|
|
|
case ROAD_TILE_DEPOT: return DiagDirToRoadBits(GetRoadDepotDirection(tile));
|
2006-03-05 12:22:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case MP_STATION:
|
2022-01-25 22:02:32 +00:00
|
|
|
if (!IsAnyRoadStopTile(tile)) return ROAD_NONE;
|
2007-02-14 16:37:16 +00:00
|
|
|
if (IsDriveThroughStopTile(tile)) return (GetRoadStopDir(tile) == DIAGDIR_NE) ? ROAD_X : ROAD_Y;
|
2006-03-31 19:10:54 +00:00
|
|
|
return DiagDirToRoadBits(GetRoadStopDir(tile));
|
2006-03-05 12:22:20 +00:00
|
|
|
|
|
|
|
case MP_TUNNELBRIDGE:
|
2007-12-16 19:30:42 +00:00
|
|
|
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return ROAD_NONE;
|
2019-07-11 18:45:56 +00:00
|
|
|
if (IsRoadCustomBridgeHeadTile(tile)) return GetCustomBridgeHeadRoadBits(tile, rtt);
|
2008-03-22 10:56:08 +00:00
|
|
|
return straight_tunnel_bridge_entrance ?
|
|
|
|
AxisToRoadBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))) :
|
|
|
|
DiagDirToRoadBits(ReverseDiagDir(GetTunnelBridgeDirection(tile)));
|
2006-03-05 12:22:20 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
default: return ROAD_NONE;
|
2006-03-05 12:22:20 +00:00
|
|
|
}
|
|
|
|
}
|