From 3b540a01d9ac441f0dddcfb6197201efd778a1eb Mon Sep 17 00:00:00 2001 From: Nicolas Chappe <74881848+nchappe@users.noreply.github.com> Date: Tue, 26 Jul 2022 18:23:14 +0200 Subject: [PATCH] Add: [YAPF] Rail depot penalty based on the number of trains waiting in it --- src/pathfinder/yapf/yapf_costrail.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/pathfinder/yapf/yapf_costrail.hpp b/src/pathfinder/yapf/yapf_costrail.hpp index 908814c8cd..4cfc91d5fd 100644 --- a/src/pathfinder/yapf/yapf_costrail.hpp +++ b/src/pathfinder/yapf/yapf_costrail.hpp @@ -13,6 +13,7 @@ #include #include "../../pbs.h" +#include "../../vehiclelist.h" template class CYapfCostRailT : public CYapfCostBase { @@ -396,6 +397,18 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th } else if (IsRailDepotTile(cur.tile)) { /* We will end in this pass (depot is possible target) */ end_segment_reason |= ESRB_DEPOT; + /* Add a penalty for each non-stopped train in the depot. + * The penalty is capped at 8 trains. */ + VehicleList vl; + BuildDepotVehicleList(VEH_TRAIN, cur.tile, &vl, nullptr, false); + int count = 0; + for (auto v : vl) { + if (!(v->vehstatus & VS_STOPPED)) { + count++; + if (count == 8) break; + } + } + segment_cost += Yapf().PfGetSettings().rail_pbs_cross_penalty * count; } else if (cur.tile_type == MP_STATION && IsRailWaypoint(cur.tile)) { if (v->current_order.IsType(OT_GOTO_WAYPOINT) &&