From fb564d612bcdc916ef758967f025797d33c63560 Mon Sep 17 00:00:00 2001 From: Daniel Scharrer Date: Fri, 10 Apr 2020 23:04:54 +0200 Subject: [PATCH] Fix wrong path waypoint event When a frame hit the target time of a path waypoint exactly we incorrectly reported the next waypoint index as reached. Additonally, when loading old saves this could mean that we send the 'on pathend' script event again for paths that were already completed: Even though the path time was past the end before saving, the millisecond resolution in the save file could result in it being rounded down to match the end exactly after loading. Fixes: bug #1293 --- src/ai/Paths.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/ai/Paths.cpp b/src/ai/Paths.cpp index 26995fc11f..7a9a457818 100644 --- a/src/ai/Paths.cpp +++ b/src/ai/Paths.cpp @@ -399,14 +399,7 @@ long ARX_PATHS_Interpolate(ARX_USE_PATH * aup, Vec3f * pos) { } // While we have time left, iterate - while(tim > 0) { - - // Path Ended - if(targetwaypoint >= ap->pathways.size()) { - *pos = ap->pos + ap->pathways[ap->pathways.size() - 1].rpos; - aup->aupflags |= ARX_USEPATH_FLAG_FINISHED; - return -2; - } + while(targetwaypoint < ap->pathways.size()) { bool bezier = (ap->pathways[targetwaypoint - 1].flag == PATHWAY_BEZIER && targetwaypoint + 1 < ap->pathways.size()); @@ -417,7 +410,6 @@ long ARX_PATHS_Interpolate(ARX_USE_PATH * aup, Vec3f * pos) { GameDuration delta = tim - ap->pathways[targetwaypoint]._time; if(delta >= 0) { tim = delta; - *pos = ap->pathways[targetwaypoint].rpos; targetwaypoint++; continue; } @@ -433,7 +425,7 @@ long ARX_PATHS_Interpolate(ARX_USE_PATH * aup, Vec3f * pos) { return targetwaypoint - 1; } - *pos += ap->pos; - - return targetwaypoint; + *pos = ap->pos + ap->pathways[ap->pathways.size() - 1].rpos; + aup->aupflags |= ARX_USEPATH_FLAG_FINISHED; + return -2; }