Silence uninitialised variable warnings in SSE blitters
[openttd/fttd.git] / src / signal_map.h
blob322977f13348b1cc53f9edfd463e0acbd480fdac
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/pos.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 * Checks for the presence of signals along the given trackdir.
36 static inline bool HasSignalAlongPos(const RailPathPos &pos)
38 if (pos.in_wormhole()) {
39 return false;
40 } else if (IsRailwayTile(pos.tile)) {
41 return HasSignalOnTrackdir(pos.tile, pos.td);
42 } else if (maptile_is_rail_tunnel(pos.tile)) {
43 return maptile_has_tunnel_signal(pos.tile, TrackdirToExitdir(pos.td) == GetTunnelBridgeDirection(pos.tile));
44 } else {
45 return false;
49 /**
50 * Checks for the presence of signals against the given trackdir.
52 static inline bool HasSignalAgainstPos(const RailPathPos &pos)
54 if (pos.in_wormhole()) {
55 return false;
56 } else if (IsRailwayTile(pos.tile)) {
57 return HasSignalOnTrackdir(pos.tile, ReverseTrackdir(pos.td));
58 } else if (maptile_is_rail_tunnel(pos.tile)) {
59 return maptile_has_tunnel_signal(pos.tile, TrackdirToExitdir(pos.td) != GetTunnelBridgeDirection(pos.tile));
60 } else {
61 return false;
65 /**
66 * Checks for the presence of signals along or against the given trackdir.
68 static inline bool HasSignalOnPos(const RailPathPos &pos)
70 if (pos.in_wormhole()) {
71 return false;
72 } else if (IsRailwayTile(pos.tile)) {
73 return HasSignalOnTrack(pos.tile, TrackdirToTrack(pos.td));
74 } else if (maptile_is_rail_tunnel(pos.tile)) {
75 return maptile_has_tunnel_signals(pos.tile);
76 } else {
77 return false;
81 static inline SignalType GetSignalType(const RailPathPos &pos)
83 assert(HasSignalOnPos(pos));
84 return IsRailwayTile(pos.tile) ? GetSignalType(pos.tile, TrackdirToTrack(pos.td)) : maptile_get_tunnel_signal_type(pos.tile);
87 /**
88 * Gets the state of the signal along the given trackdir.
90 static inline SignalState GetSignalStateByPos(const RailPathPos &pos)
92 return IsRailwayTile(pos.tile) ? GetSignalStateByTrackdir(pos.tile, pos.td) :
93 maptile_get_tunnel_signal_state(pos.tile, TrackdirToExitdir(pos.td) == GetTunnelBridgeDirection(pos.tile));
97 /**
98 * Is a pbs signal present along the trackdir?
99 * @param tile the tile to check
100 * @param td the trackdir to check
102 static inline bool HasPbsSignalOnTrackdir(TileIndex tile, Trackdir td)
104 return IsRailwayTile(tile) ?
105 HasSignalOnTrackdir(tile, td) && IsPbsSignal(GetSignalType(tile, TrackdirToTrack(td))) :
106 maptile_is_rail_tunnel(tile) && maptile_has_tunnel_signal(tile, TrackdirToExitdir(td) == GetTunnelBridgeDirection(tile)) && IsPbsSignal(maptile_get_tunnel_signal_type(tile));
110 * Is a pbs signal present along the trackdir?
111 * @param pos the position to check
113 static inline bool HasPbsSignalAlongPos(const RailPathPos &pos)
115 return !pos.in_wormhole() && HasPbsSignalOnTrackdir(pos.tile, pos.td);
119 * Is a pbs signal present against the trackdir?
120 * @param pos the position to check
122 static inline bool HasPbsSignalAgainstPos(const RailPathPos &pos)
124 return !pos.in_wormhole() && HasPbsSignalOnTrackdir(pos.tile, ReverseTrackdir(pos.td));
129 * Is a one-way signal blocking the trackdir? A one-way signal on the
130 * trackdir against will block, but signals on both trackdirs won't.
131 * @param tile the tile to check
132 * @param td the trackdir to check
134 static inline bool HasOnewaySignalBlockingTrackdir(TileIndex tile, Trackdir td)
136 if (IsRailwayTile(tile)) {
137 return HasSignalOnTrackdir(tile, ReverseTrackdir(td)) &&
138 !HasSignalOnTrackdir(tile, td) && IsOnewaySignal(GetSignalType(tile, TrackdirToTrack(td)));
139 } else if (maptile_is_rail_tunnel(tile)) {
140 return maptile_has_tunnel_signal(tile, TrackdirToExitdir(td) != GetTunnelBridgeDirection(tile));
141 } else {
142 return false;
147 * Is a one-way signal blocking the trackdir? A one-way signal on the
148 * trackdir against will block, but signals on both trackdirs won't.
149 * @param pos the position to check
151 static inline bool HasOnewaySignalBlockingPos(const RailPathPos &pos)
153 return !pos.in_wormhole() && HasOnewaySignalBlockingTrackdir(pos.tile, pos.td);
156 #endif /* SIGNAL_MAP_H */