internal static void UpdateTrain(Train Train, double TimeElapsed)
{
if (Train.State == TrainState.Pending)
{
// pending train
bool forceIntroduction = Train == PlayerTrain && !Game.MinimalisticSimulation;
double time = 0.0;
if (!forceIntroduction)
{
for (int i = 0; i < Game.Stations.Length; i++)
{
if (Game.Stations[i].StopMode == Game.StationStopMode.AllStop | Game.Stations[i].StopMode == Game.StationStopMode.PlayerPass)
{
if (Game.Stations[i].ArrivalTime >= 0.0)
{
time = Game.Stations[i].ArrivalTime;
}
else if (Game.Stations[i].DepartureTime >= 0.0)
{
time = Game.Stations[i].DepartureTime - Game.Stations[i].StopTime;
}
break;
}
}
time -= Train.TimetableDelta;
}
if (Game.SecondsSinceMidnight >= time | forceIntroduction)
{
bool introduce = true;
if (!forceIntroduction)
{
if (Train.CurrentSectionIndex >= 0)
{
if (!Game.Sections[Train.CurrentSectionIndex].IsFree())
{
introduce = false;
}
}
}
if (introduce)
{
// train is introduced
Train.State = TrainState.Available;
for (int j = 0; j < Train.Cars.Length; j++)
{
if (Train.Cars[j].CarSections.Length != 0)
{
TrainManager.ChangeCarSection(Train, j, j <= Train.DriverCar | Train != PlayerTrain ? 0 : -1);
TrainManager.ChangeFrontBogieSection(Train, j, Train != PlayerTrain ? 0 : -1);
TrainManager.ChangeRearBogieSection(Train, j, Train != PlayerTrain ? 0 : -1);
}
if (Train.Cars[j].Specs.IsMotorCar)
{
if (Train.Cars[j].Sounds.Loop.Buffer != null)
{
OpenBveApi.Math.Vector3 pos = Train.Cars[j].Sounds.Loop.Position;
Train.Cars[j].Sounds.Loop.Source = Sounds.PlaySound(Train.Cars[j].Sounds.Loop.Buffer, 1.0, 1.0, pos, Train, j, true);
}
}
}
}
}
}
else if (Train.State == TrainState.Available)
{
// available train
UpdateTrainPhysicsAndControls(Train, TimeElapsed);
if (Interface.CurrentOptions.GameMode == Interface.GameMode.Arcade)
{
if (Train.Specs.CurrentAverageSpeed > Train.CurrentRouteLimit)
{
Game.AddMessage(Interface.GetInterfaceString("message_route_overspeed"), Game.MessageDependency.RouteLimit, Interface.GameMode.Arcade, MessageColor.Orange, double.PositiveInfinity);
}
if (Train.CurrentSectionLimit == 0.0)
{
Game.AddMessage(Interface.GetInterfaceString("message_signal_stop"), Game.MessageDependency.SectionLimit, Interface.GameMode.Normal, MessageColor.Red, double.PositiveInfinity);
}
else if (Train.Specs.CurrentAverageSpeed > Train.CurrentSectionLimit)
{
Game.AddMessage(Interface.GetInterfaceString("message_signal_overspeed"), Game.MessageDependency.SectionLimit, Interface.GameMode.Normal, MessageColor.Orange, double.PositiveInfinity);
}
}
if (Train.AI != null)
{
Train.AI.Trigger(Train, TimeElapsed);
}
}
else if (Train.State == TrainState.Bogus)
{
// bogus train
if (Train.AI != null)
{
Train.AI.Trigger(Train, TimeElapsed);
}
}
}