OpenTTD Source: src/road_map.cpp Source File

OpenTTD Source 15.0-RC2

road_map.cpp
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "stdafx.h"
11#include "station_map.h"
12#include "tunnelbridge_map.h"
13
14#include "safeguards.h"
15
21 bool MayHaveRoad(Tile t)
22{
23 switch (GetTileType(t)) {
24 case MP_ROAD:
25 return true;
26
27 case MP_STATION:
28 return IsAnyRoadStop(t);
29
30 case MP_TUNNELBRIDGE:
31 return GetTunnelBridgeTransportType(t) == TRANSPORT_ROAD;
32
33 default:
34 return false;
35 }
36}
37
54 RoadBits GetAnyRoadBits(Tile tile, RoadTramType rtt, bool straight_tunnel_bridge_entrance)
55{
56 if (!MayHaveRoad(tile) || !HasTileRoadType(tile, rtt)) return ROAD_NONE;
57
58 switch (GetTileType(tile)) {
59 case MP_ROAD:
60 switch (GetRoadTileType(tile)) {
61 default:
62 case RoadTileType::Normal: return GetRoadBits(tile, rtt);
63 case RoadTileType::Crossing: return GetCrossingRoadBits(tile);
64 case RoadTileType::Depot: return DiagDirToRoadBits(GetRoadDepotDirection(tile));
65 }
66
67 case MP_STATION:
68 assert(IsAnyRoadStopTile(tile)); // ensured by MayHaveRoad
69 if (IsDriveThroughStopTile(tile)) return AxisToRoadBits(GetDriveThroughStopAxis(tile));
70 return DiagDirToRoadBits(GetBayRoadStopDir(tile));
71
72 case MP_TUNNELBRIDGE:
73 assert(GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD); // ensured by MayHaveRoad
74 return straight_tunnel_bridge_entrance ?
75 AxisToRoadBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))) :
76 DiagDirToRoadBits(ReverseDiagDir(GetTunnelBridgeDirection(tile)));
77
78 default: return ROAD_NONE;
79 }
80}
Tile
Wrapper class to abstract away the way the tiles are stored.
Definition map_func.h:25
ReverseDiagDir
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition direction_func.h:118
DiagDirToAxis
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition direction_func.h:214
AxisToRoadBits
RoadBits AxisToRoadBits(Axis a)
Create the road-part which belongs to the given Axis.
Definition road_func.h:111
DiagDirToRoadBits
RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
Definition road_func.h:96
MayHaveRoad
bool MayHaveRoad(Tile t)
Test whether a tile can have road/tram types.
Definition road_map.cpp:21
GetAnyRoadBits
RoadBits GetAnyRoadBits(Tile tile, RoadTramType rtt, bool straight_tunnel_bridge_entrance)
Returns the RoadBits on an arbitrary tile Special behaviour:
Definition road_map.cpp:54
GetRoadTileType
static RoadTileType GetRoadTileType(Tile t)
Get the type of the road tile.
Definition road_map.h:36
GetRoadBits
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition road_map.h:112
HasTileRoadType
bool HasTileRoadType(Tile t, RoadTramType rtt)
Check if a tile has a road or a tram road type.
Definition road_map.h:195
GetRoadDepotDirection
DiagDirection GetRoadDepotDirection(Tile t)
Get the direction of the exit of a road depot.
Definition road_map.h:550
RoadTileType::Normal
@ Normal
Normal road.
RoadTileType::Depot
@ Depot
Depot (one entrance)
RoadTileType::Crossing
@ Crossing
Level crossing.
GetCrossingRoadBits
RoadBits GetCrossingRoadBits(Tile tile)
Get the road bits of a level crossing.
Definition road_map.h:332
RoadBits
RoadBits
Enumeration for the road parts on a tile.
Definition road_type.h:56
ROAD_NONE
@ ROAD_NONE
No road-part is build.
Definition road_type.h:57
RoadTramType
RoadTramType
The different types of road type.
Definition road_type.h:37
safeguards.h
A number of safeguards to prevent using unsafe methods.
station_map.h
Maps accessors for stations.
IsDriveThroughStopTile
bool IsDriveThroughStopTile(Tile t)
Is tile t a drive through road stop station or waypoint?
Definition station_map.h:276
IsAnyRoadStop
bool IsAnyRoadStop(Tile t)
Is the station at t a road station?
Definition station_map.h:245
GetDriveThroughStopAxis
Axis GetDriveThroughStopAxis(Tile t)
Gets the axis of the drive through stop.
Definition station_map.h:356
GetBayRoadStopDir
DiagDirection GetBayRoadStopDir(Tile t)
Gets the direction the bay road stop entrance points towards.
Definition station_map.h:344
IsAnyRoadStopTile
bool IsAnyRoadStopTile(Tile t)
Is tile t a road stop station?
Definition station_map.h:256
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
GetTileType
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition tile_type.h:50
MP_STATION
@ MP_STATION
A tile of a station.
Definition tile_type.h:53
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition tile_type.h:57
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition transport_type.h:26
tunnelbridge_map.h
Functions that have tunnels and bridges in common.
GetTunnelBridgeDirection
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
Definition tunnelbridge_map.h:26
GetTunnelBridgeTransportType
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
Definition tunnelbridge_map.h:39