OpenTTD Source: src/tunnelbridge_map.h Source File

OpenTTD Source 15.3

tunnelbridge_map.h
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#ifndef TUNNELBRIDGE_MAP_H
11#define TUNNELBRIDGE_MAP_H
12
13#include "bridge_map.h"
14#include "tunnel_map.h"
15
16
26 inline DiagDirection GetTunnelBridgeDirection(Tile t)
27{
28 assert(IsTileType(t, MP_TUNNELBRIDGE));
29 return (DiagDirection)GB(t.m5(), 0, 2);
30}
31
39 inline TransportType GetTunnelBridgeTransportType(Tile t)
40{
41 assert(IsTileType(t, MP_TUNNELBRIDGE));
42 return (TransportType)GB(t.m5(), 2, 2);
43}
44
52 inline bool HasTunnelBridgeSnowOrDesert(Tile t)
53{
54 assert(IsTileType(t, MP_TUNNELBRIDGE));
55 return HasBit(t.m7(), 5);
56}
57
66 inline void SetTunnelBridgeSnowOrDesert(Tile t, bool snow_or_desert)
67{
68 assert(IsTileType(t, MP_TUNNELBRIDGE));
69 SB(t.m7(), 5, 1, snow_or_desert);
70}
71
78 inline TileIndex GetOtherTunnelBridgeEnd(Tile t)
79{
80 assert(IsTileType(t, MP_TUNNELBRIDGE));
81 return IsTunnel(t) ? GetOtherTunnelEnd(t) : GetOtherBridgeEnd(t);
82}
83
84
91 inline bool HasTunnelBridgeReservation(Tile t)
92{
93 assert(IsTileType(t, MP_TUNNELBRIDGE));
94 assert(GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL);
95 return HasBit(t.m5(), 4);
96}
97
104 inline void SetTunnelBridgeReservation(Tile t, bool b)
105{
106 assert(IsTileType(t, MP_TUNNELBRIDGE));
107 assert(GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL);
108 AssignBit(t.m5(), 4, b);
109}
110
117 inline TrackBits GetTunnelBridgeReservationTrackBits(Tile t)
118{
119 return HasTunnelBridgeReservation(t) ? DiagDirToDiagTrackBits(GetTunnelBridgeDirection(t)) : TRACK_BIT_NONE;
120}
121
122#endif /* TUNNELBRIDGE_MAP_H */
AssignBit
constexpr T AssignBit(T &x, const uint8_t y, bool value)
Assigns a bit in a variable.
Definition bitmath_func.hpp:176
SB
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
Definition bitmath_func.hpp:58
GB
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition bitmath_func.hpp:32
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
GetOtherBridgeEnd
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
Definition bridge_map.cpp:59
bridge_map.h
Map accessor functions for bridges.
Tile
Wrapper class to abstract away the way the tiles are stored.
Definition map_func.h:25
Tile::m5
uint8_t & m5()
General purpose.
Definition map_func.h:161
Tile::m7
uint8_t & m7()
Primarily used for newgrf support.
Definition map_func.h:185
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
IsTileType
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition tile_type.h:57
DiagDirToDiagTrackBits
TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir.
Definition track_func.h:524
TrackBits
TrackBits
Allow incrementing of Track variables.
Definition track_type.h:35
TRACK_BIT_NONE
@ TRACK_BIT_NONE
No track.
Definition track_type.h:36
TransportType
TransportType
Available types of transport.
Definition transport_type.h:17
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition transport_type.h:25
GetOtherTunnelEnd
TileIndex GetOtherTunnelEnd(TileIndex tile)
Gets the other end of the tunnel.
Definition tunnel_map.cpp:22
tunnel_map.h
Map accessors for tunnels.
IsTunnel
bool IsTunnel(Tile t)
Is this a tunnel (entrance)?
Definition tunnel_map.h:23
SetTunnelBridgeSnowOrDesert
void SetTunnelBridgeSnowOrDesert(Tile 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:66
GetTunnelBridgeDirection
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
Definition tunnelbridge_map.h:26
HasTunnelBridgeSnowOrDesert
bool HasTunnelBridgeSnowOrDesert(Tile 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:52
HasTunnelBridgeReservation
bool HasTunnelBridgeReservation(Tile t)
Get the reservation state of the rail tunnel/bridge.
Definition tunnelbridge_map.h:91
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
GetTunnelBridgeReservationTrackBits
TrackBits GetTunnelBridgeReservationTrackBits(Tile t)
Get the reserved track bits for a rail tunnel/bridge.
Definition tunnelbridge_map.h:117
GetOtherTunnelBridgeEnd
TileIndex GetOtherTunnelBridgeEnd(Tile t)
Determines type of the wormhole and returns its other end.
Definition tunnelbridge_map.h:78
SetTunnelBridgeReservation
void SetTunnelBridgeReservation(Tile t, bool b)
Set the reservation state of the rail tunnel/bridge.
Definition tunnelbridge_map.h:104