private static void UpdateBrakeSystem(Train Train, double TimeElapsed, out double[] DecelerationDueToBrake, out double[] DecelerationDueToMotor)
{
// individual brake systems
DecelerationDueToBrake = new double[Train.Cars.Length];
DecelerationDueToMotor = new double[Train.Cars.Length];
for (int i = 0; i < Train.Cars.Length; i++)
{
UpdateBrakeSystem(Train, i, TimeElapsed, out DecelerationDueToBrake[i], out DecelerationDueToMotor[i]);
}
// brake pipe pressure distribution dummy (just averages)
double TotalPressure = 0.0;
for (int i = 0; i < Train.Cars.Length; i++)
{
if (i > 0)
{
if (Train.Cars[i - 1].Derailed | Train.Cars[i].Derailed)
{
Train.Cars[i].Specs.AirBrake.BrakePipeCurrentPressure -= Game.BrakePipeLeakRate * TimeElapsed;
if (Train.Cars[i].Specs.AirBrake.BrakePipeCurrentPressure < 0.0) Train.Cars[i].Specs.AirBrake.BrakePipeCurrentPressure = 0.0;
}
}
if (i < Train.Cars.Length - 1)
{
if (Train.Cars[i].Derailed | Train.Cars[i + 1].Derailed)
{
Train.Cars[i].Specs.AirBrake.BrakePipeCurrentPressure -= Game.BrakePipeLeakRate * TimeElapsed;
if (Train.Cars[i].Specs.AirBrake.BrakePipeCurrentPressure < 0.0) Train.Cars[i].Specs.AirBrake.BrakePipeCurrentPressure = 0.0;
}
}
TotalPressure += Train.Cars[i].Specs.AirBrake.BrakePipeCurrentPressure;
}
double AveragePressure = TotalPressure / (double)Train.Cars.Length;
for (int i = 0; i < Train.Cars.Length; i++)
{
Train.Cars[i].Specs.AirBrake.BrakePipeCurrentPressure = AveragePressure;
}
}