diff --git a/src/pathfinder/yapf/yapf_costrail.hpp b/src/pathfinder/yapf/yapf_costrail.hpp index 67fdd07ebb..196403aa97 100644 --- a/src/pathfinder/yapf/yapf_costrail.hpp +++ b/src/pathfinder/yapf/yapf_costrail.hpp @@ -607,6 +607,15 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th uint platform_length = GetPlatformLength(n.GetLastTile(), ReverseDiagDir(TrackdirToExitdir(n.GetLastTrackdir()))); /* Reduce the extra cost caused by passing-platform penalty (each platform receives it in the segment cost). */ extra_cost -= Yapf().PfGetSettings().rail_station_penalty * platform_length; + if (tf->m_is_extended_depot) { + DepotReservation depot_reservation = GetDepotReservation(n.GetLastTile()); + if (depot_reservation == DEPOT_RESERVATION_FULL_STOPPED_VEH) { + extra_cost += YAPF_INFINITE_PENALTY; + } else { + extra_cost += (HasDepotReservation(n.GetLastTile()) ? 2 : 1) * platform_length * Yapf().PfGetSettings().rail_station_penalty; + } + } + /* Add penalty for the inappropriate platform length. */ extra_cost += PlatformLengthPenalty(platform_length); } diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 232be134a8..b1022810bf 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2390,6 +2390,7 @@ bool HandleTrainEnterDepot(Train *v) for (Train *u = t; u != nullptr; u = u->Next()) u->track |= TRACK_BIT_DEPOT; t->force_proceed = TFP_NONE; ClrBit(t->flags, VRF_TOGGLE_REVERSE); + UpdateExtendedDepotReservation(t, true); v->UpdateViewport(true, true); SetWindowClassesDirty(WC_TRAINS_LIST); SetWindowDirty(WC_VEHICLE_VIEW, v->index); @@ -2481,6 +2482,7 @@ static bool CheckTrainStayInDepot(Train *v) v->UpdateAcceleration(); ProcessOrders(v); if (CheckReverseTrain(v)) ReverseTrainDirection(v); + UpdateExtendedDepotReservation(v, false); InvalidateWindowData(WC_VEHICLE_DEPOT, depot_id); /* Check whether it is safe to exit the depot. */ @@ -3315,6 +3317,7 @@ uint Train::Crash(bool flooded) for (Train *v = this; v != nullptr; v = v->Next()) { v->track &= ~TRACK_BIT_DEPOT; } + UpdateExtendedDepotReservation(this, false); InvalidateWindowData(WC_VEHICLE_DEPOT, GetDepotIndex(this->tile)); } /* Remove reserved tracks of platform ahead. */ diff --git a/src/train_placement.cpp b/src/train_placement.cpp index 5b5be9f9d7..0f05da5ebc 100644 --- a/src/train_placement.cpp +++ b/src/train_placement.cpp @@ -185,6 +185,7 @@ void TrainPlacement::LiftTrain(Train *train, DoCommandFlag flags) if ((flags & DC_EXEC) == 0) return; SetPlatformReservation(train->tile, false); + UpdateExtendedDepotReservation(train, false); UpdateSignalsOnSegment(train->tile, INVALID_DIAGDIR, train->owner); } @@ -307,6 +308,7 @@ void TrainPlacement::PlaceTrain(Train *train, DoCommandFlag flags) } SetPlatformReservation(train->tile, true); + UpdateExtendedDepotReservation(train, true); UpdateSignalsOnSegment(train->tile, INVALID_DIAGDIR, train->owner); }