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 signal_map.h Slightly cooked access to signals on the map */
16 #include "signal_type.h"
18 #include "pathfinder/railpos.h"
21 * Sets the state of the signal along the given trackdir.
23 static inline void SetSignalState(TileIndex tile
, Trackdir trackdir
, SignalState state
)
25 if (IsRailwayTile(tile
)) {
26 SetSignalStateByTrackdir(tile
, trackdir
, state
);
28 maptile_set_tunnel_signal_state(tile
, TrackdirToExitdir(trackdir
) == GetTunnelBridgeDirection(tile
), state
);
34 * Is a pbs signal present along the trackdir?
35 * @param tile the tile to check
36 * @param td the trackdir to check
38 static inline bool HasPbsSignalOnTrackdir(TileIndex tile
, Trackdir td
)
40 return IsRailwayTile(tile
) ?
41 HasSignalOnTrackdir(tile
, td
) && IsPbsSignal(GetSignalType(tile
, TrackdirToTrack(td
))) :
42 maptile_is_rail_tunnel(tile
) && maptile_has_tunnel_signal(tile
, TrackdirToExitdir(td
) == GetTunnelBridgeDirection(tile
)) && IsPbsSignal(maptile_get_tunnel_signal_type(tile
));
46 * Is a pbs signal present along the trackdir?
47 * @param pos the position to check
49 static inline bool HasPbsSignalAlongPos(const RailPathPos
&pos
)
51 return !pos
.in_wormhole() && HasPbsSignalOnTrackdir(pos
.tile
, pos
.td
);
55 * Is a pbs signal present against the trackdir?
56 * @param pos the position to check
58 static inline bool HasPbsSignalAgainstPos(const RailPathPos
&pos
)
60 return !pos
.in_wormhole() && HasPbsSignalOnTrackdir(pos
.tile
, ReverseTrackdir(pos
.td
));
65 * Is a one-way signal blocking the trackdir? A one-way signal on the
66 * trackdir against will block, but signals on both trackdirs won't.
67 * @param tile the tile to check
68 * @param td the trackdir to check
70 static inline bool HasOnewaySignalBlockingTrackdir(TileIndex tile
, Trackdir td
)
72 if (IsRailwayTile(tile
)) {
73 return HasSignalOnTrackdir(tile
, ReverseTrackdir(td
)) &&
74 !HasSignalOnTrackdir(tile
, td
) && IsOnewaySignal(GetSignalType(tile
, TrackdirToTrack(td
)));
75 } else if (maptile_is_rail_tunnel(tile
)) {
76 return maptile_has_tunnel_signal(tile
, TrackdirToExitdir(td
) != GetTunnelBridgeDirection(tile
));
83 * Is a one-way signal blocking the trackdir? A one-way signal on the
84 * trackdir against will block, but signals on both trackdirs won't.
85 * @param pos the position to check
87 static inline bool HasOnewaySignalBlockingPos(const RailPathPos
&pos
)
89 return !pos
.in_wormhole() && HasOnewaySignalBlockingTrackdir(pos
.tile
, pos
.td
);
92 #endif /* SIGNAL_MAP_H */