From 5777dd9292b4fb13955bf9ee81a1213f2dfea186 Mon Sep 17 00:00:00 2001 From: rt Date: Tue, 10 Oct 2017 16:49:39 +0200 Subject: [PATCH] fix #5803 --- rts/Sim/Path/Default/IPathFinder.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/rts/Sim/Path/Default/IPathFinder.cpp b/rts/Sim/Path/Default/IPathFinder.cpp index e180f4ad758..8add5cd4e99 100644 --- a/rts/Sim/Path/Default/IPathFinder.cpp +++ b/rts/Sim/Path/Default/IPathFinder.cpp @@ -184,10 +184,17 @@ IPath::SearchResult IPathFinder::InitSearch(const MoveDef& moveDef, const CPathF const bool isStartGoal = pfDef.IsGoal(square.x, square.y); const bool startInGoal = pfDef.startInGoalRadius; + const bool allowRawPath = pfDef.allowRawPath; + const bool allowDefPath = pfDef.allowDefPath; + + assert(allowRawPath || allowDefPath); + + IPath::SearchResult results[] = {IPath::CantGetCloser, IPath::Ok, IPath::CantGetCloser}; + // although our starting square may be inside the goal radius, the starting coordinate may be outside. // in this case we do not want to return CantGetCloser, but instead a path to our starting square. if (isStartGoal && startInGoal) - return IPath::CantGetCloser; + return results[allowRawPath]; // no, clean the system from last search ResetSearch(); @@ -215,18 +222,23 @@ IPath::SearchResult IPathFinder::InitSearch(const MoveDef& moveDef, const CPathF mGoalBlockIdx = mStartBlockIdx; mGoalHeuristic = pfDef.Heuristic(square.x, square.y, BLOCK_SIZE); + enum { + RAW = 0, + IPF = 1, + }; + // perform the search - const IPath::SearchResult rawResult = (pfDef.allowRawPath )? DoRawSearch(moveDef, pfDef, owner): IPath::Error; - const IPath::SearchResult ipfResult = (pfDef.allowDefPath && rawResult == IPath::Error)? DoSearch(moveDef, pfDef, owner): rawResult; + results[RAW] = (allowRawPath )? DoRawSearch(moveDef, pfDef, owner): IPath::Error; + results[IPF] = (allowDefPath && results[RAW] == IPath::Error)? DoSearch(moveDef, pfDef, owner): results[RAW]; - if (ipfResult == IPath::Ok) - return ipfResult; + if (results[IPF] == IPath::Ok) + return IPath::Ok; if (mGoalBlockIdx != mStartBlockIdx) - return ipfResult; + return results[IPF]; // if start and goal are within the same block, but distinct squares // or considered a single point for search purposes, then we probably - // can not get closer - return (!isStartGoal || startInGoal)? IPath::CantGetCloser: ipfResult; + // can not get closer and should return that *unless* searching raw + return results[IPF + (!allowRawPath && (!isStartGoal || startInGoal))]; }