Fix #9521: Don't load at just removed docks that were part of a multi-dock station...
[openttd-github.git] / src / tunnelbridge_map.h
blob62d3c14b2dd6054b804e36403e263f1806c991e9
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 tunnelbridge_map.h Functions that have tunnels and bridges in common */
10 #ifndef TUNNELBRIDGE_MAP_H
11 #define TUNNELBRIDGE_MAP_H
13 #include "bridge_map.h"
14 #include "tunnel_map.h"
17 /**
18 * Get the direction pointing to the other end.
20 * Tunnel: Get the direction facing into the tunnel
21 * Bridge: Get the direction pointing onto the bridge
22 * @param t The tile to analyze
23 * @pre IsTileType(t, MP_TUNNELBRIDGE)
24 * @return the above mentioned direction
26 static inline DiagDirection GetTunnelBridgeDirection(TileIndex t)
28 assert(IsTileType(t, MP_TUNNELBRIDGE));
29 return (DiagDirection)GB(_m[t].m5, 0, 2);
32 /**
33 * Tunnel: Get the transport type of the tunnel (road or rail)
34 * Bridge: Get the transport type of the bridge's ramp
35 * @param t The tile to analyze
36 * @pre IsTileType(t, MP_TUNNELBRIDGE)
37 * @return the transport type in the tunnel/bridge
39 static inline TransportType GetTunnelBridgeTransportType(TileIndex t)
41 assert(IsTileType(t, MP_TUNNELBRIDGE));
42 return (TransportType)GB(_m[t].m5, 2, 2);
45 /**
46 * Tunnel: Is this tunnel entrance in a snowy or desert area?
47 * Bridge: Does the bridge ramp lie in a snow or desert area?
48 * @param t The tile to analyze
49 * @pre IsTileType(t, MP_TUNNELBRIDGE)
50 * @return true if and only if the tile is in a snowy/desert area
52 static inline bool HasTunnelBridgeSnowOrDesert(TileIndex t)
54 assert(IsTileType(t, MP_TUNNELBRIDGE));
55 return HasBit(_me[t].m7, 5);
58 /**
59 * Tunnel: Places this tunnel entrance in a snowy or desert area, or takes it out of there.
60 * Bridge: Sets whether the bridge ramp lies in a snow or desert area.
61 * @param t the tunnel entrance / bridge ramp tile
62 * @param snow_or_desert is the entrance/ramp in snow or desert (true), when
63 * not in snow and not in desert false
64 * @pre IsTileType(t, MP_TUNNELBRIDGE)
66 static inline void SetTunnelBridgeSnowOrDesert(TileIndex t, bool snow_or_desert)
68 assert(IsTileType(t, MP_TUNNELBRIDGE));
69 SB(_me[t].m7, 5, 1, snow_or_desert);
72 /**
73 * Determines type of the wormhole and returns its other end
74 * @param t one end
75 * @pre IsTileType(t, MP_TUNNELBRIDGE)
76 * @return other end
78 static inline TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
80 assert(IsTileType(t, MP_TUNNELBRIDGE));
81 return IsTunnel(t) ? GetOtherTunnelEnd(t) : GetOtherBridgeEnd(t);
85 /**
86 * Get the reservation state of the rail tunnel/bridge
87 * @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
88 * @param t the tile
89 * @return reservation state
91 static inline bool HasTunnelBridgeReservation(TileIndex t)
93 assert(IsTileType(t, MP_TUNNELBRIDGE));
94 assert(GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL);
95 return HasBit(_m[t].m5, 4);
98 /**
99 * Set the reservation state of the rail tunnel/bridge
100 * @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
101 * @param t the tile
102 * @param b the reservation state
104 static inline void SetTunnelBridgeReservation(TileIndex t, bool b)
106 assert(IsTileType(t, MP_TUNNELBRIDGE));
107 assert(GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL);
108 SB(_m[t].m5, 4, 1, b ? 1 : 0);
112 * Get the reserved track bits for a rail tunnel/bridge
113 * @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
114 * @param t the tile
115 * @return reserved track bits
117 static inline TrackBits GetTunnelBridgeReservationTrackBits(TileIndex t)
119 return HasTunnelBridgeReservation(t) ? DiagDirToDiagTrackBits(GetTunnelBridgeDirection(t)) : TRACK_BIT_NONE;
122 #endif /* TUNNELBRIDGE_MAP_H */