OpenTTD

tunnelbridge_map.h
Go to the documentation of this file.
1 /* $Id: tunnelbridge_map.h 24900 2013-01-08 22:46:42Z planetmaker $ */
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 #ifndef TUNNELBRIDGE_MAP_H
13 #define TUNNELBRIDGE_MAP_H
14
15 #include "bridge_map.h"
16 #include "tunnel_map.h"
17
18
28 static inline DiagDirection GetTunnelBridgeDirection(TileIndex t)
29 {
30 assert(IsTileType(t, MP_TUNNELBRIDGE));
31 return (DiagDirection)GB(_m[t].m5, 0, 2);
32 }
33
41 static inline TransportType GetTunnelBridgeTransportType(TileIndex t)
42 {
43 assert(IsTileType(t, MP_TUNNELBRIDGE));
44 return (TransportType)GB(_m[t].m5, 2, 2);
45 }
46
54 static inline bool HasTunnelBridgeSnowOrDesert(TileIndex t)
55 {
56 assert(IsTileType(t, MP_TUNNELBRIDGE));
57 return HasBit(_me[t].m7, 5);
58 }
59
68 static inline void SetTunnelBridgeSnowOrDesert(TileIndex t, bool snow_or_desert)
69 {
70 assert(IsTileType(t, MP_TUNNELBRIDGE));
71 SB(_me[t].m7, 5, 1, snow_or_desert);
72 }
73
80 static inline TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
81 {
82 assert(IsTileType(t, MP_TUNNELBRIDGE));
83 return IsTunnel(t) ? GetOtherTunnelEnd(t) : GetOtherBridgeEnd(t);
84 }
85
86
93 static inline bool HasTunnelBridgeReservation(TileIndex t)
94 {
95 assert(IsTileType(t, MP_TUNNELBRIDGE));
96 assert(GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL);
97 return HasBit(_m[t].m5, 4);
98 }
99
106 static inline void SetTunnelBridgeReservation(TileIndex t, bool b)
107 {
108 assert(IsTileType(t, MP_TUNNELBRIDGE));
109 assert(GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL);
110 SB(_m[t].m5, 4, 1, b ? 1 : 0);
111 }
112
119 static inline TrackBits GetTunnelBridgeReservationTrackBits(TileIndex t)
120 {
121 return HasTunnelBridgeReservation(t) ? DiagDirToDiagTrackBits(GetTunnelBridgeDirection(t)) : TRACK_BIT_NONE;
122 }
123
124 #endif /* TUNNELBRIDGE_MAP_H */
GetOtherBridgeEnd
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
Definition: bridge_map.cpp:61
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
SetTunnelBridgeReservation
static void SetTunnelBridgeReservation(TileIndex t, bool b)
Set the reservation state of the rail tunnel/bridge.
Definition: tunnelbridge_map.h:106
_m
Tile * _m
Tiles of the map.
Definition: map.cpp:32
SetTunnelBridgeSnowOrDesert
static void SetTunnelBridgeSnowOrDesert(TileIndex t, bool snow_or_desert)
Tunnel: Places this tunnel entrance in a snowy or desert area, or takes it out of there...
Definition: tunnelbridge_map.h:68
DiagDirToDiagTrackBits
static TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir. ...
Definition: track_func.h:512
SB
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
Definition: bitmath_func.hpp:60
TrackBits
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:41
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
_me
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:33
bridge_map.h
Map accessor functions for bridges.
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:80
GetTunnelBridgeDirection
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
Definition: tunnelbridge_map.h:28
GetOtherTunnelBridgeEnd
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
Definition: tunnelbridge_map.h:80
TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:29
HasTunnelBridgeSnowOrDesert
static bool HasTunnelBridgeSnowOrDesert(TileIndex t)
Tunnel: Is this tunnel entrance in a snowy or desert area? Bridge: Does the bridge ramp lie in a snow...
Definition: tunnelbridge_map.h:54
MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:52
HasTunnelBridgeReservation
static bool HasTunnelBridgeReservation(TileIndex t)
Get the reservation state of the rail tunnel/bridge.
Definition: tunnelbridge_map.h:93
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:21
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:34
GetOtherTunnelEnd
TileIndex GetOtherTunnelEnd(TileIndex tile)
Gets the other end of the tunnel.
Definition: tunnel_map.cpp:24
GetTunnelBridgeReservationTrackBits
static TrackBits GetTunnelBridgeReservationTrackBits(TileIndex t)
Get the reserved track bits for a rail tunnel/bridge.
Definition: tunnelbridge_map.h:119
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:105
tunnel_map.h
Map accessors for tunnels.
IsTunnel
static bool IsTunnel(TileIndex t)
Is this a tunnel (entrance)?
Definition: tunnel_map.h:24
TRACK_BIT_NONE
No track.
Definition: track_type.h:42