(svn r4023) - Fix: [ 1453646 NPF ] Road vehicles planning through the back of depots and stations.

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
matthijs 19 years ago
parent 0b102f0e00
commit 8ea31d293a

66
npf.c

@ -518,7 +518,7 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
Trackdir src_trackdir = (Trackdir)current->path.node.direction; Trackdir src_trackdir = (Trackdir)current->path.node.direction;
TileIndex src_tile = current->path.node.tile; TileIndex src_tile = current->path.node.tile;
DiagDirection src_exitdir = TrackdirToExitdir(src_trackdir); DiagDirection src_exitdir = TrackdirToExitdir(src_trackdir);
TileIndex dst_tile; TileIndex dst_tile = INVALID_TILE;
int i; int i;
TrackdirBits trackdirbits, ts; TrackdirBits trackdirbits, ts;
TransportType type = aystar->user_data[NPF_TYPE]; TransportType type = aystar->user_data[NPF_TYPE];
@ -532,42 +532,46 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
* otherwise we wouldn't have got here. It is also facing us, * otherwise we wouldn't have got here. It is also facing us,
* so we should skip it's body */ * so we should skip it's body */
dst_tile = GetOtherTunnelEnd(src_tile); dst_tile = GetOtherTunnelEnd(src_tile);
} else { } else if (type != TRANSPORT_WATER && (IsRoadStationTile(src_tile) || IsTileDepotType(src_tile, type))) {
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
/* 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
* those from one side only. Trackdirs don't support that (yet), so we'll * do this here. */
* do this here. */
DiagDirection exitdir;
DiagDirection exitdir; /* Find out the exit direction first */
/* Find out the exit direction first */ if (IsRoadStationTile(src_tile)) {
if (IsRoadStationTile(src_tile)) { exitdir = GetRoadStationDir(src_tile);
exitdir = GetRoadStationDir(src_tile); } else { /* Train or road depot. Direction is stored the same for both, in map5 */
} else { /* Train or road depot. Direction is stored the same for both, in map5 */ exitdir = GetDepotDirection(src_tile, type);
exitdir = GetDepotDirection(src_tile, type); }
}
/* Let's see if were headed the right way into the depot, and reverse /* Let's see if were headed the right way into the depot */
* otherwise (only for trains, since only with trains you can if (src_trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(exitdir))) {
* (sometimes) reach tiles after reversing that you couldn't reach /* We are headed inwards. We cannot go through the back of the depot.
* without reversing. */ * For rail, we can now reverse. Reversing for road vehicles is never
if (src_trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(exitdir)) && type == TRANSPORT_RAIL) { * useful, since you cannot take paths you couldn't take before
/* We are headed inwards. We can only reverse here, so we'll not * reversing (as with rail). */
* consider this direction, but jump ahead to the reverse direction. if (type == TRANSPORT_RAIL) {
* It would be nicer to return one neighbour here (the reverse /* We can only reverse here, so we'll not consider this direction, but
* trackdir of the one we are considering now) and then considering * jump ahead to the reverse direction. It would be nicer to return
* that one to return the tracks outside of the depot. But, because * one neighbour here (the reverse trackdir of the one we are
* the code layout is cleaner this way, we will just pretend we are * considering now) and then considering that one to return the tracks
* reversed already */ * 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); 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. */ /* This a normal tile, a bridge, a tunnel exit, etc. */
dst_tile = AddTileIndexDiffCWrap(src_tile, TileIndexDiffCByDir(TrackdirToExitdir(src_trackdir))); dst_tile = AddTileIndexDiffCWrap(src_tile, TileIndexDiffCByDir(TrackdirToExitdir(src_trackdir)));
if (dst_tile == INVALID_TILE) { }
/* We reached the border of the map */ if (dst_tile == INVALID_TILE) {
/* TODO Nicer control flow for this */ /* We reached the border of the map */
return; /* TODO Nicer control flow for this */
} return;
} }
/* I can't enter a tunnel entry/exit tile from a tile above the tunnel. Note /* I can't enter a tunnel entry/exit tile from a tile above the tunnel. Note

Loading…
Cancel
Save