Delete pointless project file remnants.
[openttd-joker.git] / src / tunnelbridge_map.h
blob068fc325611df884447ac8d95ff391d7ef8f6498
1 /* $Id$ */
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 */
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_base.h"
17 #include "cmd_helper.h"
18 #include "signal_type.h"
21 /**
22 * Get the direction pointing to the other end.
24 * Tunnel: Get the direction facing into the tunnel
25 * Bridge: Get the direction pointing onto the bridge
26 * @param t The tile to analyze
27 * @pre IsTileType(t, MP_TUNNELBRIDGE)
28 * @return the above mentioned direction
30 static inline DiagDirection GetTunnelBridgeDirection(TileIndex t)
32 assert(IsTileType(t, MP_TUNNELBRIDGE));
33 return (DiagDirection)GB(_m[t].m5, 0, 2);
36 /**
37 * Tunnel: Get the transport type of the tunnel (road or rail)
38 * Bridge: Get the transport type of the bridge's ramp
39 * @param t The tile to analyze
40 * @pre IsTileType(t, MP_TUNNELBRIDGE)
41 * @return the transport type in the tunnel/bridge
43 static inline TransportType GetTunnelBridgeTransportType(TileIndex t)
45 assert(IsTileType(t, MP_TUNNELBRIDGE));
46 return (TransportType)GB(_m[t].m5, 2, 2);
49 /**
50 * Tunnel: Is this tunnel entrance in a snowy or desert area?
51 * Bridge: Does the bridge ramp lie in a snow or desert area?
52 * @param t The tile to analyze
53 * @pre IsTileType(t, MP_TUNNELBRIDGE)
54 * @return true if and only if the tile is in a snowy/desert area
56 static inline bool HasTunnelBridgeSnowOrDesert(TileIndex t)
58 assert(IsTileType(t, MP_TUNNELBRIDGE));
59 return HasBit(_me[t].m7, 5);
63 /**
64 * Is this a rail bridge or tunnel?
65 * @param t the tile that might be a rail bridge or tunnel
66 * @return true if and only if this tile is a rail bridge or tunnel
68 static inline bool IsRailTunnelBridgeTile(TileIndex t)
70 TransportType tt = Extract<TransportType, 2, 2>(_m[t].m5);
72 return IsTileType(t, MP_TUNNELBRIDGE) && (tt == TRANSPORT_RAIL);
75 /**
76 * Tunnel: Places this tunnel entrance in a snowy or desert area, or takes it out of there.
77 * Bridge: Sets whether the bridge ramp lies in a snow or desert area.
78 * @param t the tunnel entrance / bridge ramp tile
79 * @param snow_or_desert is the entrance/ramp in snow or desert (true), when
80 * not in snow and not in desert false
81 * @pre IsTileType(t, MP_TUNNELBRIDGE)
83 static inline void SetTunnelBridgeSnowOrDesert(TileIndex t, bool snow_or_desert)
85 assert(IsTileType(t, MP_TUNNELBRIDGE));
86 SB(_me[t].m7, 5, 1, snow_or_desert);
89 /**
90 * Determines type of the wormhole and returns its other end
91 * @param t one end
92 * @pre IsTileType(t, MP_TUNNELBRIDGE)
93 * @return other end
95 static inline TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
97 assert(IsTileType(t, MP_TUNNELBRIDGE));
98 return IsTunnel(t) ? GetOtherTunnelEnd(t) : GetOtherBridgeEnd(t);
103 * Get the reservation state of the rail tunnel/bridge
104 * @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
105 * @param t the tile
106 * @return reservation state
108 static inline bool HasTunnelBridgeReservation(TileIndex t)
110 assert(IsTileType(t, MP_TUNNELBRIDGE));
111 assert(GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL);
112 return HasBit(_m[t].m5, 4);
116 * Set the reservation state of the rail tunnel/bridge
117 * @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
118 * @param t the tile
119 * @param b the reservation state
121 static inline void SetTunnelBridgeReservation(TileIndex t, bool b)
123 assert(IsTileType(t, MP_TUNNELBRIDGE));
124 assert(GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL);
125 SB(_m[t].m5, 4, 1, b ? 1 : 0);
129 * Get the reserved track bits for a rail tunnel/bridge
130 * @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
131 * @param t the tile
132 * @return reserved track bits
134 static inline TrackBits GetTunnelBridgeReservationTrackBits(TileIndex t)
136 return HasTunnelBridgeReservation(t) ? DiagDirToDiagTrackBits(GetTunnelBridgeDirection(t)) : TRACK_BIT_NONE;
140 * Declare tunnel/bridge entrance with signal simulation.
141 * @param t the tunnel/bridge tile.
143 static inline void SetTunnelBridgeSignalSimulationEntrance(TileIndex t)
145 assert(IsTileType(t, MP_TUNNELBRIDGE));
146 SetBit(_m[t].m5, 5);
150 * Remove tunnel/bridge entrance with signal simulation.
151 * @param t the tunnel/bridge tile.
153 static inline void ClrTunnelBridgeSignalSimulationEntrance(TileIndex t)
155 assert(IsTileType(t, MP_TUNNELBRIDGE));
156 ClrBit(_m[t].m5, 5);
160 * Declare tunnel/bridge exit with signal simulation.
161 * @param t the tunnel/bridge tile.
163 static inline void SetTunnelBridgeSignalSimulationExit(TileIndex t)
165 assert(IsTileType(t, MP_TUNNELBRIDGE));
166 SetBit(_m[t].m5, 6);
170 * Remove tunnel/bridge exit with signal simulation.
171 * @param t the tunnel/bridge tile.
173 static inline void ClrTunnelBridgeSignalSimulationExit(TileIndex t)
175 assert(IsTileType(t, MP_TUNNELBRIDGE));
176 ClrBit(_m[t].m5, 6);
180 * Is this a tunnel/bridge pair with signal simulation?
181 * On tunnel/bridge pair minimal one of the two bits is set.
182 * @param t the tile that might be a tunnel/bridge.
183 * @return true if and only if this tile is a tunnel/bridge with signal simulation.
185 static inline bool IsTunnelBridgeWithSignalSimulation(TileIndex t)
187 return IsTileType(t, MP_TUNNELBRIDGE) && (HasBit(_m[t].m5, 5) || HasBit(_m[t].m5, 6));
191 * Is this a tunnel/bridge entrance tile with signal?
192 * Tunnel bridge signal simulation has allways bit 5 on at entrance.
193 * @param t the tile that might be a tunnel/bridge.
194 * @pre IsTileType(t, MP_TUNNELBRIDGE)
195 * @return true if and only if this tile is a tunnel/bridge entrance.
197 static inline bool IsTunnelBridgeSignalSimulationEntrance(TileIndex t)
199 assert(IsTileType(t, MP_TUNNELBRIDGE));
200 return HasBit(_m[t].m5, 5) && !HasBit(_m[t].m5, 6);
204 * Is this a tunnel/bridge exit?
205 * @param t the tile that might be a tunnel/bridge.
206 * @pre IsTileType(t, MP_TUNNELBRIDGE)
207 * @return true if and only if this tile is a tunnel/bridge exit.
209 static inline bool IsTunnelBridgeSignalSimulationExit(TileIndex t)
211 assert(IsTileType(t, MP_TUNNELBRIDGE));
212 return !HasBit(_m[t].m5, 5) && HasBit(_m[t].m5, 6);
216 * Get the signal state for a tunnel/bridge entrance or exit with signal simulation
217 * @param t the tunnel/bridge entrance or exit tile with signal simulation
218 * @pre IsTunnelBridgeWithSignalSimulation(t)
219 * @return signal state
221 static inline SignalState GetTunnelBridgeSignalState(TileIndex t)
223 assert(IsTunnelBridgeWithSignalSimulation(t));
224 return HasBit(_me[t].m6, 0) ? SIGNAL_STATE_GREEN : SIGNAL_STATE_RED;
228 * Set the signal state for a tunnel/bridge entrance or exit with signal simulation
229 * @param t the tunnel/bridge entrance or exit tile with signal simulation
230 * @pre IsTunnelBridgeWithSignalSimulation(t)
231 * @param state signal state
233 static inline void SetTunnelBridgeSignalState(TileIndex t, SignalState state)
235 assert(IsTunnelBridgeWithSignalSimulation(t));
236 SB(_me[t].m6, 0, 1, (state == SIGNAL_STATE_GREEN) ? 1 : 0);
239 static inline bool IsTunnelBridgeSemaphore(TileIndex t)
241 assert(IsTunnelBridgeWithSignalSimulation(t));
242 return HasBit(_me[t].m6, 1);
245 static inline void SetTunnelBridgeSemaphore(TileIndex t, bool is_semaphore)
247 assert(IsTunnelBridgeWithSignalSimulation(t));
248 SB(_me[t].m6, 1, 1, is_semaphore ? 1 : 0);
251 static inline bool IsTunnelBridgePBS(TileIndex t)
253 assert(IsTunnelBridgeWithSignalSimulation(t));
254 return HasBit(_me[t].m6, 6);
257 static inline void SetTunnelBridgePBS(TileIndex t, bool is_pbs)
259 assert(IsTunnelBridgeWithSignalSimulation(t));
260 SB(_me[t].m6, 6, 1, is_pbs ? 1 : 0);
263 void AddRoadTunnelBridgeInfrastructure(TileIndex begin, TileIndex end);
264 void SubtractRoadTunnelBridgeInfrastructure(TileIndex begin, TileIndex end);
266 #endif /* TUNNELBRIDGE_MAP_H */