From fe3d5a77187a64f8d7de86796271fcea26d01c63 Mon Sep 17 00:00:00 2001 From: Michael Bernardi Date: Wed, 10 May 2023 17:25:32 +0200 Subject: [PATCH] Fix #10467: [YAPF] Trains do not use all available tracks --- src/pathfinder/yapf/yapf_costrail.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pathfinder/yapf/yapf_costrail.hpp b/src/pathfinder/yapf/yapf_costrail.hpp index 042ccf9275..4755389839 100644 --- a/src/pathfinder/yapf/yapf_costrail.hpp +++ b/src/pathfinder/yapf/yapf_costrail.hpp @@ -156,12 +156,18 @@ public: if (n.m_num_signals_passed >= m_sig_look_ahead_costs.size() / 2) return 0; if (!IsPbsSignal(n.m_last_signal_type)) return 0; + const Train *v = Yapf().GetVehicle(); + assert(v != nullptr); + assert(v->type == VEH_TRAIN); + /* the longer a train waits, the more it will consider longer routes around blocking trains */ + int impatience = std::max(0, v->wait_counter - DAY_TICKS / 2); + if (IsRailStationTile(tile) && IsAnyStationTileReserved(tile, trackdir, skipped)) { - return Yapf().PfGetSettings().rail_pbs_station_penalty * (skipped + 1); + return Yapf().PfGetSettings().rail_pbs_station_penalty * (skipped + 1) + impatience; } else if (TrackOverlapsTracks(GetReservedTrackbits(tile), TrackdirToTrack(trackdir))) { int cost = Yapf().PfGetSettings().rail_pbs_cross_penalty; if (!IsDiagonalTrackdir(trackdir)) cost = (cost * YAPF_TILE_CORNER_LENGTH) / YAPF_TILE_LENGTH; - return cost * (skipped + 1); + return cost * (skipped + 1) + impatience; } return 0; }