Skip to content

Commit 202962f

Browse files
authored
Merge pull request #675 from Csantucci/AIContainers-official
Bug fix for https://bugs.launchpad.net/or/+bug/1983511 When an AI train disappears at end of run, containers remain visible
2 parents 1ea0b22 + 4d79756 commit 202962f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Source/Orts.Simulation/Simulation/AIs/AI.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,9 @@ private void RemoveTrains()
13281328
{
13291329
car.Train = null; // WorldPosition.XNAMatrix.M42 -= 1000;
13301330
car.IsPartOfActiveTrain = false; // to stop sounds
1331+
// remove continers if any
1332+
if (car.FreightAnimations?.Animations != null)
1333+
car.FreightAnimations?.RemoveLoads();
13311334
}
13321335
}
13331336
}

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/FreightAnimations.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,22 @@ public bool CheckForMerge(int i)
863863
}
864864
return false;
865865
}
866+
867+
/// <summary>
868+
/// Removes loads (e.g. containers) when AI train is deleted
869+
/// </summary>
870+
871+
public void RemoveLoads()
872+
{
873+
foreach (var animation in Animations)
874+
{
875+
if (animation is FreightAnimationDiscrete discreteAnimation && discreteAnimation.Container != null)
876+
{
877+
Wagon.Simulator.ContainerManager.Containers.Remove(discreteAnimation.Container);
878+
}
879+
}
880+
881+
}
866882
}
867883

868884

0 commit comments

Comments
 (0)