2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 /** @file pathfinder/railpos.h Railway path position type. */
10 #ifndef PATHFINDER_RAILPOS_H
11 #define PATHFINDER_RAILPOS_H
14 #include "../rail_type.h"
15 #include "../track_func.h"
16 #include "../map/rail.h"
18 struct RailPathPos
: PathPos
<PathVTile
> {
19 typedef PathPos
<PathVTile
> Base
;
21 /** Create an empty RailPathPos */
22 RailPathPos() : Base() { }
24 /** Create a PathPos for a given tile and trackdir */
25 RailPathPos (TileIndex t
, Trackdir d
) : Base (t
, d
) { }
27 /** Create a PathPos in a wormhole */
28 RailPathPos (TileIndex t
, Trackdir d
, TileIndex w
) : Base (t
, d
, w
) { }
30 /** Get the rail type for this position. */
31 RailType
get_railtype() const
34 return !in_wormhole() ? GetRailType (tile
, TrackdirToTrack(td
)) :
35 IsRailwayTile(wormhole
) ? GetBridgeRailType(wormhole
) : GetRailType(wormhole
);
38 /** Check if there are signals at a position */
39 bool has_signals() const
43 } else if (IsRailwayTile(tile
)) {
44 return HasSignalOnTrack (tile
, TrackdirToTrack(td
));
45 } else if (maptile_is_rail_tunnel(tile
)) {
46 return maptile_has_tunnel_signals (tile
);
52 /** Get the type of signals at a position */
53 SignalType
get_signal_type() const
55 assert(has_signals());
56 return IsRailwayTile(tile
) ?
57 GetSignalType (tile
, TrackdirToTrack(td
)) :
58 maptile_get_tunnel_signal_type(tile
);
61 /** Check if there is a signal along/against a position */
62 bool has_signal_along (bool along
= true) const
66 } else if (IsRailwayTile(tile
)) {
67 return HasSignalOnTrackdir (tile
, along
? td
: ReverseTrackdir(td
));
68 } else if (maptile_is_rail_tunnel(tile
)) {
69 bool inwards
= TrackdirToExitdir(td
) == GetTunnelBridgeDirection(tile
);
70 return maptile_has_tunnel_signal (tile
, along
== inwards
);
76 /** Check if there is a signal against a position */
77 bool has_signal_against() const { return has_signal_along(false); }
79 /** Check if there is a one-way signal against a position */
80 bool has_blocking_signal() const
84 } else if (IsRailwayTile (tile
)) {
85 return HasSignalOnTrackdir (tile
, ReverseTrackdir (td
)) &&
86 !HasSignalOnTrackdir (tile
, td
) && IsOnewaySignal (GetSignalType (tile
, TrackdirToTrack (td
)));
87 } else if (maptile_is_rail_tunnel (tile
)) {
88 return maptile_has_tunnel_signal (tile
, TrackdirToExitdir (td
) != GetTunnelBridgeDirection (tile
));
94 /** Get the state of the signal along a position */
95 SignalState
get_signal_state() const
97 assert(has_signal_along());
98 return IsRailwayTile(tile
) ?
99 GetSignalStateByTrackdir (tile
, td
) :
100 maptile_get_tunnel_signal_state (tile
, TrackdirToExitdir(td
) == GetTunnelBridgeDirection(tile
));
103 /** Set the state of the signal along a position */
104 void set_signal_state (SignalState state
) const
106 assert (has_signal_along());
107 if (IsRailwayTile (tile
)) {
108 SetSignalStateByTrackdir (tile
, td
, state
);
110 maptile_set_tunnel_signal_state (tile
, TrackdirToExitdir (td
) == GetTunnelBridgeDirection (tile
), state
);
115 #endif /* PATHFINDER_RAILPOS_H */