mirror of https://github.com/OpenTTD/OpenTTD
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
parent
174030a15f
commit
4eeac3ea75
|
@ -1090,12 +1090,16 @@ static int RoadFindPathToDest(Vehicle *v, uint tile, int enterdir)
|
||||||
//debug("Finding path. Enterdir: %d, Trackdir: %d", enterdir, trackdir);
|
//debug("Finding path. Enterdir: %d, Trackdir: %d", enterdir, trackdir);
|
||||||
|
|
||||||
ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_ROAD, v->owner);
|
ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_ROAD, v->owner);
|
||||||
if (ftd.best_bird_dist != 0 || ftd.best_trackdir == 0xff) {
|
if (ftd.best_trackdir == 0xff) {
|
||||||
/* Not found, just do something, or we are already there */
|
/* We are already at our target. Just do something */
|
||||||
//TODO: maybe display error?
|
//TODO: maybe display error?
|
||||||
//TODO: go straight ahead if possible?
|
//TODO: go straight ahead if possible?
|
||||||
return_track(FindFirstBit2x64(bitmask));
|
return_track(FindFirstBit2x64(bitmask));
|
||||||
} else {
|
} else {
|
||||||
|
/* If ftd.best_bird_dist is 0, we found our target and ftd.best_trackdir contains
|
||||||
|
the direction we need to take to get there, if ftd.best_bird_dist is not 0,
|
||||||
|
we did not find our target, but ftd.best_trackdir contains the direction leading
|
||||||
|
to the tile closest to our target. */
|
||||||
return_track(ftd.best_trackdir);
|
return_track(ftd.best_trackdir);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
10
ship_cmd.c
10
ship_cmd.c
|
@ -576,12 +576,14 @@ static int ChooseShipTrack(Vehicle *v, uint tile, int enterdir, uint tracks)
|
||||||
|
|
||||||
ftd = NPFRouteToStationOrTile(src_tile, _track_direction_to_trackdir[track][v->direction], &fstd, TRANSPORT_WATER, v->owner);
|
ftd = NPFRouteToStationOrTile(src_tile, _track_direction_to_trackdir[track][v->direction], &fstd, TRANSPORT_WATER, v->owner);
|
||||||
|
|
||||||
if (ftd.best_bird_dist == 0 && ftd.best_trackdir != 0xff)
|
if (ftd.best_trackdir != 0xff)
|
||||||
/* Found the target, and it is not our current tile */
|
/* If ftd.best_bird_dist is 0, we found our target and ftd.best_trackdir contains
|
||||||
|
the direction we need to take to get there, if ftd.best_bird_dist is not 0,
|
||||||
|
we did not find our target, but ftd.best_trackdir contains the direction leading
|
||||||
|
to the tile closest to our target. */
|
||||||
return ftd.best_trackdir & 7; /* TODO: Wrapper function? */
|
return ftd.best_trackdir & 7; /* TODO: Wrapper function? */
|
||||||
else
|
else
|
||||||
return -1; /* Couldn't find target, reverse */
|
return -1; /* Already at target, reverse? */
|
||||||
/* TODO: When the target is unreachable, the ship will keep reversing */
|
|
||||||
} else {
|
} else {
|
||||||
uint b;
|
uint b;
|
||||||
uint tot_dist, dist;
|
uint tot_dist, dist;
|
||||||
|
|
|
@ -1672,12 +1672,17 @@ static byte ChooseTrainTrack(Vehicle *v, uint tile, int enterdir, byte trackbits
|
||||||
assert(trackdir != 0xff);
|
assert(trackdir != 0xff);
|
||||||
|
|
||||||
ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_RAIL, v->owner);
|
ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_RAIL, v->owner);
|
||||||
if (ftd.best_bird_dist != 0 || ftd.best_trackdir == 0xff) {
|
|
||||||
/* Not found, or we are already there. Just do something */
|
if (ftd.best_trackdir == 0xff) {
|
||||||
|
/* We are already at our target. Just do something */
|
||||||
//TODO: maybe display error?
|
//TODO: maybe display error?
|
||||||
//TODO: go straight ahead if possible?
|
//TODO: go straight ahead if possible?
|
||||||
best_track = FIND_FIRST_BIT(bits);
|
best_track = FIND_FIRST_BIT(bits);
|
||||||
} else {
|
} else {
|
||||||
|
/* If ftd.best_bird_dist is 0, we found our target and ftd.best_trackdir contains
|
||||||
|
the direction we need to take to get there, if ftd.best_bird_dist is not 0,
|
||||||
|
we did not find our target, but ftd.best_trackdir contains the direction leading
|
||||||
|
to the tile closest to our target. */
|
||||||
/* Discard enterdir information, making it a normal track */
|
/* Discard enterdir information, making it a normal track */
|
||||||
best_track = ftd.best_trackdir & 7; /* TODO: Wrapper function? */
|
best_track = ftd.best_trackdir & 7; /* TODO: Wrapper function? */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue