Codechange: Use cached town, station, industry names for list window sorting
[openttd-github.git] / src / road_map.cpp
blob9954e4299370e612e1d453473aafdd94f6be6d96
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file road_map.cpp Complex road accessors. */
10 #include "stdafx.h"
11 #include "station_map.h"
12 #include "tunnelbridge_map.h"
14 #include "safeguards.h"
17 /**
18 * Returns the RoadBits on an arbitrary tile
19 * Special behaviour:
20 * - road depots: entrance is treated as road piece
21 * - road tunnels: entrance is treated as road piece
22 * - bridge ramps: start of the ramp is treated as road piece
23 * - bridge middle parts: bridge itself is ignored
25 * If straight_tunnel_bridge_entrance is set a ROAD_X or ROAD_Y
26 * for bridge ramps and tunnel entrances is returned depending
27 * on the orientation of the tunnel or bridge.
28 * @param tile the tile to get the road bits for
29 * @param rt the road type to get the road bits form
30 * @param straight_tunnel_bridge_entrance whether to return straight road bits for tunnels/bridges.
31 * @return the road bits of the given tile
33 RoadBits GetAnyRoadBits(TileIndex tile, RoadTramType rtt, bool straight_tunnel_bridge_entrance)
35 if (!MayHaveRoad(tile) || !HasTileRoadType(tile, rtt)) return ROAD_NONE;
37 switch (GetTileType(tile)) {
38 case MP_ROAD:
39 switch (GetRoadTileType(tile)) {
40 default:
41 case ROAD_TILE_NORMAL: return GetRoadBits(tile, rtt);
42 case ROAD_TILE_CROSSING: return GetCrossingRoadBits(tile);
43 case ROAD_TILE_DEPOT: return DiagDirToRoadBits(GetRoadDepotDirection(tile));
46 case MP_STATION:
47 if (!IsRoadStopTile(tile)) return ROAD_NONE;
48 if (IsDriveThroughStopTile(tile)) return (GetRoadStopDir(tile) == DIAGDIR_NE) ? ROAD_X : ROAD_Y;
49 return DiagDirToRoadBits(GetRoadStopDir(tile));
51 case MP_TUNNELBRIDGE:
52 if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return ROAD_NONE;
53 return straight_tunnel_bridge_entrance ?
54 AxisToRoadBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))) :
55 DiagDirToRoadBits(ReverseDiagDir(GetTunnelBridgeDirection(tile)));
57 default: return ROAD_NONE;