mirror of https://github.com/OpenTTD/OpenTTD
Add: Set reservation and penalties to improve pathfinding in extended depots.
parent
e26d14c5ef
commit
328f0ab20e
|
@ -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())));
|
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). */
|
/* 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;
|
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. */
|
/* Add penalty for the inappropriate platform length. */
|
||||||
extra_cost += PlatformLengthPenalty(platform_length);
|
extra_cost += PlatformLengthPenalty(platform_length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2390,6 +2390,7 @@ bool HandleTrainEnterDepot(Train *v)
|
||||||
for (Train *u = t; u != nullptr; u = u->Next()) u->track |= TRACK_BIT_DEPOT;
|
for (Train *u = t; u != nullptr; u = u->Next()) u->track |= TRACK_BIT_DEPOT;
|
||||||
t->force_proceed = TFP_NONE;
|
t->force_proceed = TFP_NONE;
|
||||||
ClrBit(t->flags, VRF_TOGGLE_REVERSE);
|
ClrBit(t->flags, VRF_TOGGLE_REVERSE);
|
||||||
|
UpdateExtendedDepotReservation(t, true);
|
||||||
v->UpdateViewport(true, true);
|
v->UpdateViewport(true, true);
|
||||||
SetWindowClassesDirty(WC_TRAINS_LIST);
|
SetWindowClassesDirty(WC_TRAINS_LIST);
|
||||||
SetWindowDirty(WC_VEHICLE_VIEW, v->index);
|
SetWindowDirty(WC_VEHICLE_VIEW, v->index);
|
||||||
|
@ -2481,6 +2482,7 @@ static bool CheckTrainStayInDepot(Train *v)
|
||||||
v->UpdateAcceleration();
|
v->UpdateAcceleration();
|
||||||
ProcessOrders(v);
|
ProcessOrders(v);
|
||||||
if (CheckReverseTrain(v)) ReverseTrainDirection(v);
|
if (CheckReverseTrain(v)) ReverseTrainDirection(v);
|
||||||
|
UpdateExtendedDepotReservation(v, false);
|
||||||
InvalidateWindowData(WC_VEHICLE_DEPOT, depot_id);
|
InvalidateWindowData(WC_VEHICLE_DEPOT, depot_id);
|
||||||
|
|
||||||
/* Check whether it is safe to exit the depot. */
|
/* 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()) {
|
for (Train *v = this; v != nullptr; v = v->Next()) {
|
||||||
v->track &= ~TRACK_BIT_DEPOT;
|
v->track &= ~TRACK_BIT_DEPOT;
|
||||||
}
|
}
|
||||||
|
UpdateExtendedDepotReservation(this, false);
|
||||||
InvalidateWindowData(WC_VEHICLE_DEPOT, GetDepotIndex(this->tile));
|
InvalidateWindowData(WC_VEHICLE_DEPOT, GetDepotIndex(this->tile));
|
||||||
}
|
}
|
||||||
/* Remove reserved tracks of platform ahead. */
|
/* Remove reserved tracks of platform ahead. */
|
||||||
|
|
|
@ -185,6 +185,7 @@ void TrainPlacement::LiftTrain(Train *train, DoCommandFlag flags)
|
||||||
if ((flags & DC_EXEC) == 0) return;
|
if ((flags & DC_EXEC) == 0) return;
|
||||||
|
|
||||||
SetPlatformReservation(train->tile, false);
|
SetPlatformReservation(train->tile, false);
|
||||||
|
UpdateExtendedDepotReservation(train, false);
|
||||||
|
|
||||||
UpdateSignalsOnSegment(train->tile, INVALID_DIAGDIR, train->owner);
|
UpdateSignalsOnSegment(train->tile, INVALID_DIAGDIR, train->owner);
|
||||||
}
|
}
|
||||||
|
@ -307,6 +308,7 @@ void TrainPlacement::PlaceTrain(Train *train, DoCommandFlag flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
SetPlatformReservation(train->tile, true);
|
SetPlatformReservation(train->tile, true);
|
||||||
|
UpdateExtendedDepotReservation(train, true);
|
||||||
|
|
||||||
UpdateSignalsOnSegment(train->tile, INVALID_DIAGDIR, train->owner);
|
UpdateSignalsOnSegment(train->tile, INVALID_DIAGDIR, train->owner);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue