Skip to content

Commit

Permalink
Fix OpenTTD#7592: Do not cache road vehicle path within 8 tiles of de…
Browse files Browse the repository at this point in the history
…stination with multiple entrances

Ported from jgrpp commit 79d5be7
  • Loading branch information
JGRennison authored and nielsmh committed Feb 6, 2020
1 parent 492d270 commit f0d1e15
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/pathfinder/yapf/yapf_road.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ class CYapfDestinationTileRoadT
}
}

const Station *GetDestinationStation() const
{
return m_dest_station != INVALID_STATION ? Station::GetIfValid(m_dest_station) : nullptr;
}

protected:
/** to access inherited path finder */
Tpf& Yapf()
Expand Down Expand Up @@ -402,6 +407,22 @@ class CYapfFollowRoadT
path_cache.td.pop_back();
path_cache.tile.pop_back();
}

/* Check if target is a station, and cached path ends within 8 tiles of the dest tile */
const Station *st = Yapf().GetDestinationStation();
if (st) {
const RoadStop *stop = st->GetPrimaryRoadStop(v);
if (stop != nullptr && (IsDriveThroughStopTile(stop->xy) || stop->GetNextRoadStop(v) != nullptr)) {
/* Destination station has at least 2 usable road stops, or first is a drive-through stop,
* trim end of path cache within 8 tiles of road stop tile area */
TileArea non_cached_area = v->IsBus() ? st->bus_station : st->truck_station;
non_cached_area.Expand(8);
while (!path_cache.empty() && non_cached_area.Contains(path_cache.tile.back())) {
path_cache.td.pop_back();
path_cache.tile.pop_back();
}
}
}
}
return next_trackdir;
}
Expand Down

0 comments on commit f0d1e15

Please sign in to comment.