OpenTTD

road_map.cpp
Go to the documentation of this file.
1 /* $Id: road_map.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
2
3 /*
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/>.
8 */
9
12 #include "stdafx.h"
13 #include "station_map.h"
14 #include "tunnelbridge_map.h"
15
16 #include "safeguards.h"
17
18
35 RoadBits GetAnyRoadBits(TileIndex tile, RoadType rt, bool straight_tunnel_bridge_entrance)
36 {
37 if (!HasTileRoadType(tile, rt)) return ROAD_NONE;
38
39 switch (GetTileType(tile)) {
40 case MP_ROAD:
41 switch (GetRoadTileType(tile)) {
42 default:
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));
46 }
47
48 case MP_STATION:
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));
52
53 case MP_TUNNELBRIDGE:
54 if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return ROAD_NONE;
55 return straight_tunnel_bridge_entrance ?
56 AxisToRoadBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))) :
57 DiagDirToRoadBits(ReverseDiagDir(GetTunnelBridgeDirection(tile)));
58
59 default: return ROAD_NONE;
60 }
61 }
GetTileType
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:89
GetTunnelBridgeTransportType
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
Definition: tunnelbridge_map.h:41
ROAD_TILE_CROSSING
Level crossing.
Definition: road_map.h:25
station_map.h
Maps accessors for stations.
MP_ROAD
A tile with road (or tram tracks)
Definition: tile_type.h:45
ROAD_X
Full road along the x-axis (south-west + north-east)
Definition: road_type.h:61
HasTileRoadType
static bool HasTileRoadType(TileIndex t, RoadType rt)
Check if a tile has a specific road type.
Definition: road_map.h:188
GetRoadBits
static RoadBits GetRoadBits(TileIndex t, RoadType rt)
Get the present road bits for a specific road type.
Definition: road_map.h:111
DIAGDIR_NE
Northeast, upper right on your monitor.
Definition: direction_type.h:82
GetRoadDepotDirection
static DiagDirection GetRoadDepotDirection(TileIndex t)
Get the direction of the exit of a road depot.
Definition: road_map.h:534
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:22
IsDriveThroughStopTile
static bool IsDriveThroughStopTile(TileIndex t)
Is tile t a drive through road stop station?
Definition: station_map.h:234
ROAD_TILE_NORMAL
Normal road.
Definition: road_map.h:24
DiagDirToRoadBits
static RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
Definition: road_func.h:144
GetRoadStopDir
static DiagDirection GetRoadStopDir(TileIndex t)
Gets the direction the road stop entrance points towards.
Definition: station_map.h:258
ReverseDiagDir
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition: direction_func.h:120
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
safeguards.h
A number of safeguards to prevent using unsafe methods.
RoadBits
RoadBits
Enumeration for the road parts on a tile.
Definition: road_type.h:55
ROAD_NONE
No road-part is build.
Definition: road_type.h:56
GetAnyRoadBits
RoadBits GetAnyRoadBits(TileIndex tile, RoadType rt, bool straight_tunnel_bridge_entrance)
Returns the RoadBits on an arbitrary tile Special behaviour:
Definition: road_map.cpp:35
GetTunnelBridgeDirection
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
Definition: tunnelbridge_map.h:28
GetCrossingRoadBits
static RoadBits GetCrossingRoadBits(TileIndex tile)
Get the road bits of a level crossing.
Definition: road_map.h:318
DiagDirToAxis
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition: direction_func.h:216
GetRoadTileType
static RoadTileType GetRoadTileType(TileIndex t)
Get the type of the road tile.
Definition: road_map.h:35
MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:52
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
MP_STATION
A tile of a station.
Definition: tile_type.h:48
TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:30
IsRoadStopTile
static bool IsRoadStopTile(TileIndex t)
Is tile t a road stop station?
Definition: station_map.h:214
tunnelbridge_map.h
Functions that have tunnels and bridges in common.
ROAD_Y
Full road along the y-axis (north-west + south-east)
Definition: road_type.h:62
ROAD_TILE_DEPOT
Depot (one entrance)
Definition: road_map.h:26
AxisToRoadBits
static RoadBits AxisToRoadBits(Axis a)
Create the road-part which belongs to the given Axis.
Definition: road_func.h:159