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/>.
10 /** @file tunnelbridge_map.h Functions that have tunnels and bridges in common */
12 #ifndef TUNNELBRIDGE_MAP_H
13 #define TUNNELBRIDGE_MAP_H
15 #include "bridge_map.h"
16 #include "tunnel_map.h"
20 * Get the direction pointing to the other end.
22 * Tunnel: Get the direction facing into the tunnel
23 * Bridge: Get the direction pointing onto the bridge
24 * @param t The tile to analyze
25 * @pre IsTileType(t, MP_TUNNELBRIDGE)
26 * @return the above mentioned direction
28 static inline DiagDirection
GetTunnelBridgeDirection(TileIndex t
)
30 assert(IsTileType(t
, MP_TUNNELBRIDGE
));
31 return (DiagDirection
)GB(_m
[t
].m5
, 0, 2);
35 * Tunnel: Get the transport type of the tunnel (road or rail)
36 * Bridge: Get the transport type of the bridge's ramp
37 * @param t The tile to analyze
38 * @pre IsTileType(t, MP_TUNNELBRIDGE)
39 * @return the transport type in the tunnel/bridge
41 static inline TransportType
GetTunnelBridgeTransportType(TileIndex t
)
43 assert(IsTileType(t
, MP_TUNNELBRIDGE
));
44 return (TransportType
)GB(_m
[t
].m5
, 2, 2);
48 * Tunnel: Is this tunnel entrance in a snowy or desert area?
49 * Bridge: Does the bridge ramp lie in a snow or desert area?
50 * @param t The tile to analyze
51 * @pre IsTileType(t, MP_TUNNELBRIDGE)
52 * @return true if and only if the tile is in a snowy/desert area
54 static inline bool HasTunnelBridgeSnowOrDesert(TileIndex t
)
56 assert(IsTileType(t
, MP_TUNNELBRIDGE
));
57 return HasBit(_me
[t
].m7
, 5);
61 * Tunnel: Places this tunnel entrance in a snowy or desert area, or takes it out of there.
62 * Bridge: Sets whether the bridge ramp lies in a snow or desert area.
63 * @param t the tunnel entrance / bridge ramp tile
64 * @param snow_or_desert is the entrance/ramp in snow or desert (true), when
65 * not in snow and not in desert false
66 * @pre IsTileType(t, MP_TUNNELBRIDGE)
68 static inline void SetTunnelBridgeSnowOrDesert(TileIndex t
, bool snow_or_desert
)
70 assert(IsTileType(t
, MP_TUNNELBRIDGE
));
71 SB(_me
[t
].m7
, 5, 1, snow_or_desert
);
75 * Determines type of the wormhole and returns its other end
77 * @pre IsTileType(t, MP_TUNNELBRIDGE)
80 static inline TileIndex
GetOtherTunnelBridgeEnd(TileIndex t
)
82 assert(IsTileType(t
, MP_TUNNELBRIDGE
));
83 return IsTunnel(t
) ? GetOtherTunnelEnd(t
) : GetOtherBridgeEnd(t
);
88 * Get the reservation state of the rail tunnel/bridge
89 * @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
91 * @return reservation state
93 static inline bool HasTunnelBridgeReservation(TileIndex t
)
95 assert(IsTileType(t
, MP_TUNNELBRIDGE
));
96 assert(GetTunnelBridgeTransportType(t
) == TRANSPORT_RAIL
);
97 return HasBit(_m
[t
].m5
, 4);
101 * Set the reservation state of the rail tunnel/bridge
102 * @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
104 * @param b the reservation state
106 static inline void SetTunnelBridgeReservation(TileIndex t
, bool b
)
108 assert(IsTileType(t
, MP_TUNNELBRIDGE
));
109 assert(GetTunnelBridgeTransportType(t
) == TRANSPORT_RAIL
);
110 SB(_m
[t
].m5
, 4, 1, b
? 1 : 0);
114 * Get the reserved track bits for a rail tunnel/bridge
115 * @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
117 * @return reserved track bits
119 static inline TrackBits
GetTunnelBridgeReservationTrackBits(TileIndex t
)
121 return HasTunnelBridgeReservation(t
) ? DiagDirToDiagTrackBits(GetTunnelBridgeDirection(t
)) : TRACK_BIT_NONE
;
124 #endif /* TUNNELBRIDGE_MAP_H */