Skip to content

Commit 64f4876

Browse files
committed
Improvements to loco brakes, compressor synchronization, train brake release, and train brake sounds to improve compatibility with DPU
1 parent 722037c commit 64f4876

File tree

4 files changed

+144
-78
lines changed

4 files changed

+144
-78
lines changed

Source/Orts.Simulation/Simulation/Physics/Train.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4312,10 +4312,10 @@ public List<TrainCar> DetermineLocomotiveGroup(TrainCar loco)
43124312
// If locomotive is a steam locomotive, check for tenders only
43134313
if (first >= 0 && loco is MSTSSteamLocomotive)
43144314
{
4315-
if (first > 0 && Cars[first - 1].WagonType == TrainCar.WagonTypes.Tender)
4316-
first--;
4317-
if (last < Cars.Count - 1 && Cars[last + 1].WagonType == TrainCar.WagonTypes.Tender)
4315+
if (last < Cars.Count - 1 && !loco.Flipped && Cars[last + 1].WagonType == TrainCar.WagonTypes.Tender)
43184316
last++;
4317+
else if (first > 0 && loco.Flipped && Cars[first - 1].WagonType == TrainCar.WagonTypes.Tender)
4318+
first--;
43194319
}
43204320
else // Other locomotive types
43214321
{
@@ -4351,9 +4351,8 @@ public TrainCar DetermineDPLeadLocomotive(TrainCar locoCar)
43514351
{
43524352
if (Cars.Contains(locoCar) && locoCar is MSTSLocomotive loco)
43534353
foreach (TrainCar dpLead in DPLeadUnits)
4354-
if (dpLead is MSTSLocomotive dpLeadLoco)
4355-
if (dpLeadLoco.DPUnitID == loco.DPUnitID)
4356-
return dpLead;
4354+
if (dpLead is MSTSLocomotive dpLeadLoco && dpLeadLoco.DPUnitID == loco.DPUnitID)
4355+
return dpLead;
43574356

43584357
return null;
43594358
}

Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,8 @@ public override void Initialize()
16441644
// for airtwinpipe system, make sure that a value is set for it
16451645
if (MaximumMainReservoirPipePressurePSI == 0)
16461646
{
1647-
MaximumMainReservoirPipePressurePSI = MaxMainResPressurePSI;
1647+
// Add 5 psi to account for main res overcharging that might happen
1648+
MaximumMainReservoirPipePressurePSI = MaxMainResPressurePSI + 5.0f;
16481649
if (Simulator.Settings.VerboseConfigurationMessages)
16491650
{
16501651
Trace.TraceInformation("AirBrakeMaxMainResPipePressure not set in ENG file, set to default pressure of {0}.", FormatStrings.FormatPressure(MaximumMainReservoirPipePressurePSI, PressureUnit.PSI, MainPressureUnit, true));
@@ -2694,31 +2695,37 @@ protected virtual void UpdateCompressor(float elapsedClockSeconds)
26942695
}
26952696
}
26962697

2697-
// Turn compressor on and off
2698-
if (MainResPressurePSI < CompressorRestartPressurePSI && LocomotivePowerSupply.AuxiliaryPowerSupplyState == PowerSupplyState.PowerOn && !CompressorIsOn)
2698+
// Determine compressor synchronization
2699+
bool syncCompressor = false;
2700+
2701+
// Compressor synchronization is ignored if 5 psi above the high setpoint
2702+
if (MainResPressurePSI < MaxMainResPressurePSI + 5.0f && LocomotivePowerSupply.AuxiliaryPowerSupplyState == PowerSupplyState.PowerOn)
26992703
{
2700-
SignalEvent(Event.CompressorOn);
27012704
foreach (List<TrainCar> locoGroup in Train.LocoGroups)
27022705
{
2703-
// Synchronize compressor between coupled locomotives
2704-
if (locoGroup.Contains(this as TrainCar))
2706+
// Only synchronize in a group of locomotives directly connected
2707+
// or synchronize between any two locomotives with MU controlled mode
2708+
foreach (TrainCar locoCar in locoGroup)
27052709
{
2706-
foreach (TrainCar locoCar in locoGroup)
2707-
if (locoCar is MSTSLocomotive loco && loco.LocomotivePowerSupply.AuxiliaryPowerSupplyOn && !loco.CompressorIsOn)
2708-
loco.SignalEvent(Event.CompressorOn);
2709-
}
2710-
else if (CompressorIsMUControlled) // Synchronize compressor between remote groups if configured to do so
2711-
{
2712-
foreach (TrainCar remoteLocoCar in locoGroup)
2713-
if (remoteLocoCar is MSTSLocomotive remoteLoco && remoteLoco.LocomotivePowerSupply.AuxiliaryPowerSupplyOn && !remoteLoco.CompressorIsOn && remoteLoco.CompressorIsMUControlled)
2714-
remoteLoco.SignalEvent(Event.CompressorOn);
2710+
if (locoCar is MSTSLocomotive loco)
2711+
syncCompressor |= (locoGroup.Contains(this as TrainCar) || CompressorIsMUControlled && loco.CompressorIsMUControlled)
2712+
&& loco.CompressorIsOn && loco.MainResPressurePSI < loco.MaxMainResPressurePSI;
2713+
2714+
// No need to check repeatedly if we already know to sync compressors
2715+
if (syncCompressor)
2716+
break;
27152717
}
2718+
if (syncCompressor)
2719+
break;
27162720
}
27172721
}
2718-
else if ((MainResPressurePSI >= MaxMainResPressurePSI || LocomotivePowerSupply.AuxiliaryPowerSupplyState != PowerSupplyState.PowerOn) && CompressorIsOn)
2719-
{
2722+
2723+
if ((MainResPressurePSI < CompressorRestartPressurePSI || (syncCompressor && MainResPressurePSI < MaxMainResPressurePSI))
2724+
&& LocomotivePowerSupply.AuxiliaryPowerSupplyState == PowerSupplyState.PowerOn && !CompressorIsOn)
2725+
SignalEvent(Event.CompressorOn);
2726+
else if (((MainResPressurePSI >= MaxMainResPressurePSI && !syncCompressor)
2727+
|| LocomotivePowerSupply.AuxiliaryPowerSupplyState != PowerSupplyState.PowerOn) && CompressorIsOn)
27202728
SignalEvent(Event.CompressorOff);
2721-
}
27222729

27232730
if (CompressorIsOn)
27242731
MainResPressurePSI += elapsedClockSeconds * reservoirChargingRate;

Source/Orts.Simulation/Simulation/RollingStocks/MSTSWagon.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ public enum BrakeValveType
291291
/// </summary>
292292
public MSTSSteamLocomotive AuxTendersSteamLocomotive { get; private set; }
293293

294+
/// <summary>
295+
/// Tender attached to this steam locomotive
296+
/// </summary>
297+
public TrainCar AttachedTender { get; private set; }
298+
294299
/// <summary>
295300
/// Steam locomotive has a tender coupled to it
296301
/// </summary>
@@ -3651,6 +3656,7 @@ public void ConfirmSteamLocomotiveTender()
36513656
{
36523657
SteamLocomotiveTender = Train.Cars[0] as MSTSSteamLocomotive;
36533658
SteamLocomotiveTender.HasTenderCoupled = false;
3659+
SteamLocomotiveTender.AttachedTender = null;
36543660
}
36553661

36563662
var tenderIndex = 0;
@@ -3664,18 +3670,21 @@ public void ConfirmSteamLocomotiveTender()
36643670
{
36653671
SteamLocomotiveTender = Train.Cars[tenderIndex] as MSTSSteamLocomotive;
36663672
SteamLocomotiveTender.HasTenderCoupled = true;
3673+
SteamLocomotiveTender.AttachedTender = Train.Cars[tenderIndex + 1];
36673674
}
36683675

36693676
else if (tenderIndex > 0 && Train.Cars[tenderIndex - 1].WagonType == WagonTypes.Tender) // Assuming the tender is "in front" of the locomotive, ie it is running in reverse
36703677
{
36713678
// TO BE CHECKED - What happens if multiple locomotives are coupled together in reverse?
36723679
SteamLocomotiveTender = Train.Cars[tenderIndex] as MSTSSteamLocomotive;
36733680
SteamLocomotiveTender.HasTenderCoupled = true;
3681+
SteamLocomotiveTender.AttachedTender = Train.Cars[tenderIndex - 1];
36743682
}
36753683
else // Assuming that locomotive is a tank locomotive, and no tender is coupled
36763684
{
36773685
SteamLocomotiveTender = Train.Cars[tenderIndex] as MSTSSteamLocomotive;
36783686
SteamLocomotiveTender.HasTenderCoupled = false;
3687+
SteamLocomotiveTender.AttachedTender = null;
36793688
}
36803689
}
36813690
}

0 commit comments

Comments
 (0)