--- a/npf.c Wed Mar 22 11:26:08 2006 +0000
+++ b/npf.c Wed Mar 22 20:33:30 2006 +0000
@@ -501,7 +501,7 @@
TileIndex src_tile = current->path.node.tile;
DiagDirection src_exitdir = TrackdirToExitdir(src_trackdir);
FindLengthOfTunnelResult flotr;
- TileIndex dst_tile;
+ TileIndex dst_tile = INVALID_TILE;
int i;
TrackdirBits trackdirbits, ts;
TransportType type = aystar->user_data[NPF_TYPE];
@@ -517,40 +517,46 @@
* so we should skip it's body */
flotr = FindLengthOfTunnel(src_tile, src_exitdir);
dst_tile = flotr.tile;
- } else {
- if (type != TRANSPORT_WATER && (IsRoadStationTile(src_tile) || IsTileDepotType(src_tile, type))){
- /* This is a road station or a train or road depot. We can enter and exit
- * those from one side only. Trackdirs don't support that (yet), so we'll
- * do this here. */
-
- DiagDirection exitdir;
- /* Find out the exit direction first */
- if (IsRoadStationTile(src_tile))
- exitdir = GetRoadStationDir(src_tile);
- else /* Train or road depot. Direction is stored the same for both, in map5 */
- exitdir = GetDepotDirection(src_tile, type);
+ } else if (type != TRANSPORT_WATER && (IsRoadStationTile(src_tile) || IsTileDepotType(src_tile, type))) {
+ /* This is a road station or a train or road depot. We can enter and exit
+ * those from one side only. Trackdirs don't support that (yet), so we'll
+ * do this here. */
- /* Let's see if were headed the right way into the depot, and reverse
- * otherwise (only for trains, since only with trains you can
- * (sometimes) reach tiles after reversing that you couldn't reach
- * without reversing. */
- if (src_trackdir == DiagdirToDiagTrackdir(ReverseDiagdir(exitdir)) && type == TRANSPORT_RAIL)
- /* We are headed inwards. We can only reverse here, so we'll not
- * consider this direction, but jump ahead to the reverse direction.
- * It would be nicer to return one neighbour here (the reverse
- * trackdir of the one we are considering now) and then considering
- * that one to return the tracks outside of the depot. But, because
- * the code layout is cleaner this way, we will just pretend we are
- * reversed already */
+ DiagDirection exitdir;
+ /* Find out the exit direction first */
+ if (IsRoadStationTile(src_tile)) {
+ exitdir = GetRoadStationDir(src_tile);
+ } else { /* Train or road depot. Direction is stored the same for both, in map5 */
+ exitdir = GetDepotDirection(src_tile, type);
+ }
+
+ /* Let's see if were headed the right way into the depot */
+ if (src_trackdir == DiagdirToDiagTrackdir(ReverseDiagdir(exitdir))) {
+ /* We are headed inwards. We cannot go through the back of the depot.
+ * For rail, we can now reverse. Reversing for road vehicles is never
+ * useful, since you cannot take paths you couldn't take before
+ * reversing (as with rail). */
+ if (type == TRANSPORT_RAIL) {
+ /* We can only reverse here, so we'll not consider this direction, but
+ * jump ahead to the reverse direction. It would be nicer to return
+ * one neighbour here (the reverse trackdir of the one we are
+ * considering now) and then considering that one to return the tracks
+ * outside of the depot. But, because the code layout is cleaner this
+ * way, we will just pretend we are reversed already */
src_trackdir = ReverseTrackdir(src_trackdir);
+ dst_tile = AddTileIndexDiffCWrap(src_tile, TileIndexDiffCByDir(exitdir));
+ } else {
+ dst_tile = INVALID_TILE; /* Road vehicle heading inwards: dead end */
+ }
}
+ } else {
/* This a normal tile, a bridge, a tunnel exit, etc. */
dst_tile = AddTileIndexDiffCWrap(src_tile, TileIndexDiffCByDir(TrackdirToExitdir(src_trackdir)));
- if (dst_tile == INVALID_TILE) {
- /* We reached the border of the map */
- /* TODO Nicer control flow for this */
- return;
- }
+ }
+ if (dst_tile == INVALID_TILE) {
+ /* We reached the border of the map */
+ /* TODO Nicer control flow for this */
+ return;
}
/* I can't enter a tunnel entry/exit tile from a tile above the tunnel. Note