From aa63517c92e34facde14b0dc97850499a3ad42d3 Mon Sep 17 00:00:00 2001 From: J0an Josep Date: Mon, 14 Jan 2019 23:14:44 +0100 Subject: Fix #7060: [NPF] Do not check whether ignored first tiles are end nodes. --- src/pathfinder/npf/aystar.cpp | 2 +- src/pathfinder/npf/aystar.h | 2 ++ src/pathfinder/npf/npf.cpp | 15 +++++++++------ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/pathfinder/npf/aystar.cpp b/src/pathfinder/npf/aystar.cpp index 8bd63beb7..beac06291 100644 --- a/src/pathfinder/npf/aystar.cpp +++ b/src/pathfinder/npf/aystar.cpp @@ -170,7 +170,7 @@ int AyStar::Loop() if (current == NULL) return AYSTAR_EMPTY_OPENLIST; /* Check for end node and if found, return that code */ - if (this->EndNodeCheck(this, current) == AYSTAR_FOUND_END_NODE) { + if (this->EndNodeCheck(this, current) == AYSTAR_FOUND_END_NODE && !CheckIgnoreFirstTile(¤t->path)) { if (this->FoundEndNode != NULL) { this->FoundEndNode(this, current); } diff --git a/src/pathfinder/npf/aystar.h b/src/pathfinder/npf/aystar.h index 052feb6e8..890b023e8 100644 --- a/src/pathfinder/npf/aystar.h +++ b/src/pathfinder/npf/aystar.h @@ -59,6 +59,8 @@ struct OpenListNode { PathNode path; }; +bool CheckIgnoreFirstTile(const PathNode *node); + struct AyStar; /** diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp index 93c5f947a..c9a22f5f0 100644 --- a/src/pathfinder/npf/npf.cpp +++ b/src/pathfinder/npf/npf.cpp @@ -101,6 +101,11 @@ static inline void NPFSetFlag(AyStarNode *node, NPFNodeFlag flag, bool value) SB(node->user_data[NPF_NODE_FLAGS], flag, 1, value); } +bool CheckIgnoreFirstTile(const PathNode *node) +{ + return (node->parent == NULL && HasBit(node->node.user_data[NPF_NODE_FLAGS], NPF_FLAG_IGNORE_START_TILE)); +} + /** * Calculates the minimum distance travelled to get from t0 to t1 when only * using tracks (ie, only making 45 degree turns). Returns the distance in the @@ -853,11 +858,6 @@ static void NPFFollowTrack(AyStar *aystar, OpenListNode *current) TileIndex src_tile = current->path.node.tile; DiagDirection src_exitdir = TrackdirToExitdir(src_trackdir); - /* Is src_tile valid, and can be used? - * When choosing track on a junction src_tile is the tile neighboured to the junction wrt. exitdir. - * But we must not check the validity of this move, as src_tile is totally unrelated to the move, if a roadvehicle reversed on a junction. */ - bool ignore_src_tile = (current->path.parent == NULL && NPFGetFlag(¤t->path.node, NPF_FLAG_IGNORE_START_TILE)); - /* Information about the vehicle: TransportType (road/rail/water) and SubType (compatible rail/road types) */ TransportType type = user->type; uint subtype = user->roadtypes; @@ -871,7 +871,10 @@ static void NPFFollowTrack(AyStar *aystar, OpenListNode *current) TrackdirBits trackdirbits; /* Find dest tile */ - if (ignore_src_tile) { + /* Is src_tile valid, and can be used? + * When choosing track on a junction src_tile is the tile neighboured to the junction wrt. exitdir. + * But we must not check the validity of this move, as src_tile is totally unrelated to the move, if a roadvehicle reversed on a junction. */ + if (CheckIgnoreFirstTile(¤t->path)) { /* Do not perform any checks that involve src_tile */ dst_tile = src_tile + TileOffsByDiagDir(src_exitdir); trackdirbits = GetDriveableTrackdirBits(dst_tile, src_trackdir, type, subtype); -- cgit v1.2.3-54-g00ecf