Fix ICU iterators on leading/trailing whitespace
[openttd/fttd.git] / src / signal_map.h
blob134ab17200cca150a8b752476e1dbb3b73a0cbfa
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));
46 /**
47 * Is a one-way signal blocking the trackdir? A one-way signal on the
48 * trackdir against will block, but signals on both trackdirs won't.
49 * @param tile the tile to check
50 * @param td the trackdir to check
52 static inline bool HasOnewaySignalBlockingTrackdir(TileIndex tile, Trackdir td)
54 if (IsRailwayTile(tile)) {
55 return HasSignalOnTrackdir(tile, ReverseTrackdir(td)) &&
56 !HasSignalOnTrackdir(tile, td) && IsOnewaySignal(GetSignalType(tile, TrackdirToTrack(td)));
57 } else if (maptile_is_rail_tunnel(tile)) {
58 return maptile_has_tunnel_signal(tile, TrackdirToExitdir(td) != GetTunnelBridgeDirection(tile));
59 } else {
60 return false;
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 pos the position to check
69 static inline bool HasOnewaySignalBlockingPos(const RailPathPos &pos)
71 return !pos.in_wormhole() && HasOnewaySignalBlockingTrackdir(pos.tile, pos.td);
74 #endif /* SIGNAL_MAP_H */