Add signal methods to RailPathPos
[openttd/fttd.git] / src / signal_map.h
blob5911a74760399a0ebf0913f4cba8426992e2f48f
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 signal_map.h Slightly cooked access to signals on the map */
12 #ifndef SIGNAL_MAP_H
13 #define SIGNAL_MAP_H
15 #include "stdafx.h"
16 #include "signal_type.h"
17 #include "map/rail.h"
18 #include "pathfinder/railpos.h"
20 /**
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);
27 } else {
28 maptile_set_tunnel_signal_state(tile, TrackdirToExitdir(trackdir) == GetTunnelBridgeDirection(tile), state);
33 /**
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));
45 /**
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);
54 /**
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));
64 /**
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));
77 } else {
78 return false;
82 /**
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 */