Skip to content

Commit

Permalink
Fix: Coupler distances could be incorrect if train reversed
Browse files Browse the repository at this point in the history
  • Loading branch information
leezer3 committed Nov 21, 2022
1 parent 06d5ab1 commit 41f7018
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions source/TrainManager/Train/TrainBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,14 @@ public override void Reverse()
for (int i = 0; i < Cars.Length; i++)
{
Cars[i].Reverse();
// Re-create the coupler with appropriate distances between the cars
double minDistance = 0, maxDistance = 0;
if (i < Cars.Length - 1)
{
minDistance = Cars[i + 1].Coupler.MinimumDistanceBetweenCars;
maxDistance = Cars[i + 1].Coupler.MaximumDistanceBetweenCars;
}
Cars[i].Coupler = new Coupler(minDistance, maxDistance, Cars[i], i < Cars.Length - 1 ? Cars[i + 1] : null, this);
}
PlaceCars(trackPosition);
DriverCar = Cars.Length - 1 - DriverCar;
Expand Down

0 comments on commit 41f7018

Please sign in to comment.