(svn r21509) -Codechange: rename the rail pathfinders "path_not_found" parameter to "path_found" and remove the ! where the variables are set / read

pull/155/head
rubidium 14 years ago
parent a4289a4e23
commit 3390b98958

@ -1240,7 +1240,7 @@ bool NPFTrainCheckReverse(const Train *v)
return ftd.best_bird_dist != 0 && NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE);
}
Track NPFTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, struct PBSTileInfo *target)
Track NPFTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, struct PBSTileInfo *target)
{
NPFFindStationOrTileData fstd;
NPFFillWithOrderData(&fstd, v, reserve_track);
@ -1260,7 +1260,7 @@ Track NPFTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir
/* We are already at our target. Just do something
* @todo maybe display error?
* @todo: go straight ahead if possible? */
if (path_not_found) *path_not_found = false;
path_found = true;
return FindFirstTrack(tracks);
}
@ -1268,7 +1268,7 @@ Track NPFTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir
* 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. */
if (path_not_found != NULL) *path_not_found = (ftd.best_bird_dist != 0);
path_found = (ftd.best_bird_dist == 0);
/* Discard enterdir information, making it a normal track */
return TrackdirToTrack(ftd.best_trackdir);
}

@ -81,11 +81,11 @@ bool NPFTrainCheckReverse(const Train *v);
* @param tile the tile to find the path from (should be next tile the train is about to enter)
* @param enterdir diagonal direction which the RV will enter this new tile from
* @param tracks available trackdirs on the new tile (to choose from)
* @param path_not_found [out] true is returned if no path can be found (returned Trackdir is only a 'guess')
* @param path_found [out] Whether a path has been found (true) or has been guessed (false)
* @param reserve_track indicates whether YAPF should try to reserve the found path
* @param target [out] the target tile of the reservation, free is set to true if path was reserved
* @return the best track for next turn
*/
Track NPFTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, struct PBSTileInfo *target);
Track NPFTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, struct PBSTileInfo *target);
#endif /* NPF_FUNC_H */

@ -43,12 +43,12 @@ Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDi
* @param tile the tile to find the path from (should be next tile the train is about to enter)
* @param enterdir diagonal direction which the RV will enter this new tile from
* @param tracks available trackdirs on the new tile (to choose from)
* @param path_not_found [out] true is returned if no path can be found (returned Trackdir is only a 'guess')
* @param path_found [out] Whether a path has been found (true) or has been guessed (false)
* @param reserve_track indicates whether YAPF should try to reserve the found path
* @param target [out] the target tile of the reservation, free is set to true if path was reserved
* @return the best track for next turn
*/
Track YapfTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, struct PBSTileInfo *target);
Track YapfTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, struct PBSTileInfo *target);
/**
* Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using YAPF.

@ -399,18 +399,18 @@ public:
return 't';
}
static Trackdir stChooseRailTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, PBSTileInfo *target)
static Trackdir stChooseRailTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, PBSTileInfo *target)
{
/* create pathfinder instance */
Tpf pf1;
#if !DEBUG_YAPF_CACHE
Trackdir result1 = pf1.ChooseRailTrack(v, tile, enterdir, tracks, path_not_found, reserve_track, target);
Trackdir result1 = pf1.ChooseRailTrack(v, tile, enterdir, tracks, path_found, reserve_track, target);
#else
Trackdir result1 = pf1.ChooseRailTrack(v, tile, enterdir, tracks, path_not_found, false, NULL);
Trackdir result1 = pf1.ChooseRailTrack(v, tile, enterdir, tracks, path_found, false, NULL);
Tpf pf2;
pf2.DisableCache(true);
Trackdir result2 = pf2.ChooseRailTrack(v, tile, enterdir, tracks, path_not_found, reserve_track, target);
Trackdir result2 = pf2.ChooseRailTrack(v, tile, enterdir, tracks, path_found, reserve_track, target);
if (result1 != result2) {
DEBUG(yapf, 0, "CACHE ERROR: ChooseRailTrack() = [%d, %d]", result1, result2);
DumpState(pf1, pf2);
@ -420,7 +420,7 @@ public:
return result1;
}
FORCEINLINE Trackdir ChooseRailTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, PBSTileInfo *target)
FORCEINLINE Trackdir ChooseRailTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, PBSTileInfo *target)
{
if (target != NULL) target->tile = INVALID_TILE;
@ -430,12 +430,7 @@ public:
Yapf().SetDestination(v);
/* find the best path */
bool path_found = Yapf().FindPath(v);
if (path_not_found != NULL) {
/* tell controller that the path was only 'guessed'
* treat the path as found if stopped on the first two way signal(s) */
*path_not_found = !(path_found || Yapf().m_stopped_on_first_two_way_signal);
}
path_found = Yapf().FindPath(v);
/* if path not found - return INVALID_TRACKDIR */
Trackdir next_trackdir = INVALID_TRACKDIR;
@ -459,6 +454,9 @@ public:
if (reserve_track && path_found) this->TryReservePath(target);
}
/* Treat the path as found if stopped on the first two way signal(s). */
path_found |= Yapf().m_stopped_on_first_two_way_signal;
return next_trackdir;
}
@ -533,10 +531,10 @@ struct CYapfAnySafeTileRail1 : CYapfT<CYapfRail_TypesT<CYapfAnySafeTileRail1, CF
struct CYapfAnySafeTileRail2 : CYapfT<CYapfRail_TypesT<CYapfAnySafeTileRail2, CFollowTrackFreeRailNo90, CRailNodeListTrackDir, CYapfDestinationAnySafeTileRailT , CYapfFollowAnySafeTileRailT> > {};
Track YapfTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, PBSTileInfo *target)
Track YapfTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, PBSTileInfo *target)
{
/* default is YAPF type 2 */
typedef Trackdir (*PfnChooseRailTrack)(const Train*, TileIndex, DiagDirection, TrackBits, bool*, bool, PBSTileInfo*);
typedef Trackdir (*PfnChooseRailTrack)(const Train*, TileIndex, DiagDirection, TrackBits, bool&, bool, PBSTileInfo*);
PfnChooseRailTrack pfnChooseRailTrack = &CYapfRail1::stChooseRailTrack;
/* check if non-default YAPF type needed */
@ -544,7 +542,7 @@ Track YapfTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdi
pfnChooseRailTrack = &CYapfRail2::stChooseRailTrack; // Trackdir, forbid 90-deg
}
Trackdir td_ret = pfnChooseRailTrack(v, tile, enterdir, tracks, path_not_found, reserve_track, target);
Trackdir td_ret = pfnChooseRailTrack(v, tile, enterdir, tracks, path_found, reserve_track, target);
return (td_ret != INVALID_TRACKDIR) ? TrackdirToTrack(td_ret) : FindFirstTrack(tracks);
}

@ -2134,16 +2134,16 @@ static const byte _initial_tile_subcoord[6][4][3] = {
* @param tile The tile the train is about to enter
* @param enterdir Diagonal direction the train is coming from
* @param tracks Usable tracks on the new tile
* @param path_not_found [out] Set to false if the pathfinder couldn't find a way to the destination
* @param path_found [out] Whether a path has been found or not.
* @param do_track_reservation Path reservation is requested
* @param dest [out] State and destination of the requested path
* @return The best track the train should follow
*/
static Track DoTrainPathfind(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool do_track_reservation, PBSTileInfo *dest)
static Track DoTrainPathfind(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool do_track_reservation, PBSTileInfo *dest)
{
switch (_settings_game.pf.pathfinder_for_trains) {
case VPF_NPF: return NPFTrainChooseTrack(v, tile, enterdir, tracks, path_not_found, do_track_reservation, dest);
case VPF_YAPF: return YapfTrainChooseTrack(v, tile, enterdir, tracks, path_not_found, do_track_reservation, dest);
case VPF_NPF: return NPFTrainChooseTrack(v, tile, enterdir, tracks, path_found, do_track_reservation, dest);
case VPF_YAPF: return YapfTrainChooseTrack(v, tile, enterdir, tracks, path_found, do_track_reservation, dest);
default: NOT_REACHED();
}
@ -2403,12 +2403,12 @@ static Track ChooseTrainTrack(Train *v, TileIndex tile, DiagDirection enterdir,
if (res_dest.tile != INVALID_TILE && !res_dest.okay) {
/* Pathfinders are able to tell that route was only 'guessed'. */
bool path_not_found = false;
bool path_found = true;
TileIndex new_tile = res_dest.tile;
Track next_track = DoTrainPathfind(v, new_tile, dest_enterdir, tracks, &path_not_found, do_track_reservation, &res_dest);
Track next_track = DoTrainPathfind(v, new_tile, dest_enterdir, tracks, path_found, do_track_reservation, &res_dest);
if (new_tile == tile) best_track = next_track;
v->HandlePathfindingResult(!path_not_found);
v->HandlePathfindingResult(path_found);
}
/* No track reservation requested -> finished. */
@ -2453,7 +2453,8 @@ static Track ChooseTrainTrack(Train *v, TileIndex tile, DiagDirection enterdir,
/* Get next order with destination. */
if (orders.SwitchToNextOrder(true)) {
PBSTileInfo cur_dest;
DoTrainPathfind(v, next_tile, exitdir, reachable, NULL, true, &cur_dest);
bool path_found;
DoTrainPathfind(v, next_tile, exitdir, reachable, path_found, true, &cur_dest);
if (cur_dest.tile != INVALID_TILE) {
res_dest = cur_dest;
if (res_dest.okay) continue;

Loading…
Cancel
Save