1 /* $Id: road_map.cpp 21846 2011-01-18 23:09:43Z rubidium $ */
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file road_map.cpp Complex road accessors. */
13 #include "station_map.h"
14 #include "tunnelbridge_map.h"
16 #include "safeguards.h"
20 * Returns the RoadBits on an arbitrary tile
22 * - road depots: entrance is treated as road piece
23 * - road tunnels: entrance is treated as road piece
24 * - bridge ramps: start of the ramp is treated as road piece
25 * - bridge middle parts: bridge itself is ignored
27 * If straight_tunnel_bridge_entrance is set a ROAD_X or ROAD_Y
28 * for bridge ramps and tunnel entrances is returned depending
29 * on the orientation of the tunnel or bridge.
30 * @param tile the tile to get the road bits for
31 * @param rt the road type to get the road bits form
32 * @param straight_tunnel_bridge_entrance whether to return straight road bits for tunnels/bridges.
33 * @return the road bits of the given tile
35 RoadBits
GetAnyRoadBits(TileIndex tile
, RoadType rt
, bool straight_tunnel_bridge_entrance
)
37 if (!HasTileRoadType(tile
, rt
)) return ROAD_NONE
;
39 switch (GetTileType(tile
)) {
41 switch (GetRoadTileType(tile
)) {
43 case ROAD_TILE_NORMAL
: return GetRoadBits(tile
, rt
);
44 case ROAD_TILE_CROSSING
: return GetCrossingRoadBits(tile
);
45 case ROAD_TILE_DEPOT
: return DiagDirToRoadBits(GetRoadDepotDirection(tile
));
49 if (!IsRoadStopTile(tile
)) return ROAD_NONE
;
50 if (IsDriveThroughStopTile(tile
)) return (GetRoadStopDir(tile
) == DIAGDIR_NE
) ? ROAD_X
: ROAD_Y
;
51 return DiagDirToRoadBits(GetRoadStopDir(tile
));
54 if (GetTunnelBridgeTransportType(tile
) != TRANSPORT_ROAD
) return ROAD_NONE
;
55 if (IsRoadCustomBridgeHeadTile(tile
)) return GetCustomBridgeHeadRoadBits(tile
, rt
);
56 return straight_tunnel_bridge_entrance
?
57 AxisToRoadBits(DiagDirToAxis(GetTunnelBridgeDirection(tile
))) :
58 DiagDirToRoadBits(ReverseDiagDir(GetTunnelBridgeDirection(tile
)));
60 default: return ROAD_NONE
;