Skip to content

Commit 4861181

Browse files
committed
Provides functionality for unpowered control car
1 parent 920a433 commit 4861181

File tree

7 files changed

+199
-51
lines changed

7 files changed

+199
-51
lines changed

Source/Orts.Simulation/Orts.Simulation.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
<Compile Include="Simulation\LevelCrossing.cs" />
9999
<Compile Include="Simulation\Physics\Train.cs" />
100100
<Compile Include="Simulation\RollingStocks\LocomotiveAttributes.cs" />
101+
<Compile Include="Simulation\RollingStocks\MSTSControlTrailerCar.cs" />
101102
<Compile Include="Simulation\RollingStocks\MSTSDieselLocomotive.cs" />
102103
<Compile Include="Simulation\RollingStocks\MSTSElectricLocomotive.cs" />
103104
<Compile Include="Simulation\RollingStocks\MSTSLocomotive.cs" />
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
// COPYRIGHT 2009, 2010, 2011, 2012, 2013 by the Open Rails project.
2+
//
3+
// This file is part of Open Rails.
4+
//
5+
// Open Rails is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Open Rails is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
17+
18+
/* DIESEL LOCOMOTIVE CLASSES
19+
*
20+
* The Locomotive is represented by two classes:
21+
* MSTSDieselLocomotiveSimulator - defines the behaviour, ie physics, motion, power generated etc
22+
* MSTSDieselLocomotiveViewer - defines the appearance in a 3D viewer. The viewer doesn't
23+
* get attached to the car until it comes into viewing range.
24+
*
25+
* Both these classes derive from corresponding classes for a basic locomotive
26+
* LocomotiveSimulator - provides for movement, basic controls etc
27+
* LocomotiveViewer - provides basic animation for running gear, wipers, etc
28+
*
29+
*/
30+
31+
using Microsoft.Xna.Framework;
32+
using Orts.Formats.Msts;
33+
using Orts.Parsers.Msts;
34+
using Orts.Simulation.Physics;
35+
using Orts.Simulation.RollingStocks.SubSystems.Controllers;
36+
using Orts.Simulation.RollingStocks.SubSystems.PowerSupplies;
37+
using Orts.Simulation.RollingStocks.SubSystems.PowerTransmissions;
38+
using ORTS.Common;
39+
using System.Diagnostics;
40+
using System;
41+
using System.IO;
42+
using System.Text;
43+
using Event = Orts.Common.Event;
44+
using ORTS.Scripting.Api;
45+
46+
namespace Orts.Simulation.RollingStocks
47+
{
48+
class MSTSControlTrailerCar : MSTSLocomotive
49+
{
50+
51+
public MSTSControlTrailerCar(Simulator simulator, string wagFile)
52+
: base(simulator, wagFile)
53+
{
54+
55+
// PowerSupply = new ScriptedDieselPowerSupply(this);
56+
57+
}
58+
59+
public override void LoadFromWagFile(string wagFilePath)
60+
{
61+
base.LoadFromWagFile(wagFilePath);
62+
63+
Trace.TraceInformation("Control Trailer");
64+
65+
}
66+
67+
68+
public override void Initialize()
69+
{
70+
71+
base.Initialize();
72+
73+
74+
}
75+
76+
77+
/// <summary>
78+
/// Set starting conditions when initial speed > 0
79+
///
80+
81+
public override void InitializeMoving()
82+
{
83+
base.InitializeMoving();
84+
WheelSpeedMpS = SpeedMpS;
85+
86+
ThrottleController.SetValue(Train.MUThrottlePercent / 100);
87+
}
88+
89+
/// <summary>
90+
/// This function updates periodically the states and physical variables of the locomotive's subsystems.
91+
/// </summary>
92+
public override void Update(float elapsedClockSeconds)
93+
{
94+
base.Update(elapsedClockSeconds);
95+
96+
}
97+
98+
/// <summary>
99+
/// This function updates periodically the locomotive's motive force.
100+
/// </summary>
101+
protected override void UpdateTractiveForce(float elapsedClockSeconds, float t, float AbsSpeedMpS, float AbsWheelSpeedMpS)
102+
{
103+
104+
105+
106+
107+
}
108+
109+
110+
/// <summary>
111+
/// This function updates periodically the locomotive's sound variables.
112+
/// </summary>
113+
protected override void UpdateSoundVariables(float elapsedClockSeconds)
114+
{
115+
116+
117+
118+
}
119+
120+
121+
122+
123+
124+
125+
126+
}
127+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,7 @@ public override void Update(float elapsedClockSeconds)
17621762
}
17631763

17641764
}
1765-
else
1765+
else if (EngineType != EngineTypes.Control) // TODO - Control trailers would not have compressors, but if they do then need to be linked to power supply requirements
17661766
{
17671767
UpdateCompressor(elapsedClockSeconds);
17681768
}

Source/Orts.Simulation/Simulation/RollingStocks/RollingStock.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public static TrainCar Load(Simulator simulator, string wagFilePath, bool initia
6868
case "electric": car = new MSTSElectricLocomotive(simulator, wagFilePath); break;
6969
case "steam": car = new MSTSSteamLocomotive(simulator, wagFilePath); break;
7070
case "diesel": car = new MSTSDieselLocomotive(simulator, wagFilePath); break;
71+
case "control": car = new MSTSControlTrailerCar(simulator, wagFilePath); break;
7172
default: throw new InvalidDataException(wagFilePath + "\r\n\r\nUnknown engine type: " + wagFile.Engine.Type);
7273
}
7374
}

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Brakes/MSTS/AirSinglePipe.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -465,19 +465,23 @@ public override void Update(float elapsedClockSeconds)
465465
BrakeLine2PressurePSI -= dp * AuxBrakeLineVolumeRatio;
466466
}
467467

468-
if (Car is MSTSLocomotive loco && loco.LocomotivePowerSupply.MainPowerSupplyOn)
468+
if (Car is MSTSLocomotive loco && loco.EngineType != TrainCar.EngineTypes.Control) // TODO - Control cars ned to be linked to power suppy requirements.
469469
{
470-
BailOffOn = false;
471-
if ((loco.Train.LeadLocomotiveIndex >= 0 && ((MSTSLocomotive)loco.Train.Cars[loco.Train.LeadLocomotiveIndex]).BailOff) || loco.DynamicBrakeAutoBailOff && loco.Train.MUDynamicBrakePercent > 0 && loco.DynamicBrakeForceCurves == null)
472-
BailOffOn = true;
473-
else if (loco.DynamicBrakeAutoBailOff && loco.Train.MUDynamicBrakePercent > 0 && loco.DynamicBrakeForceCurves != null)
470+
// if (Car is MSTSLocomotive loco && loco.LocomotivePowerSupply.MainPowerSupplyOn)
471+
if (loco.LocomotivePowerSupply.MainPowerSupplyOn)
474472
{
475-
var dynforce = loco.DynamicBrakeForceCurves.Get(1.0f, loco.AbsSpeedMpS); // max dynforce at that speed
476-
if ((loco.MaxDynamicBrakeForceN == 0 && dynforce > 0) || dynforce > loco.MaxDynamicBrakeForceN * 0.6)
473+
BailOffOn = false;
474+
if ((loco.Train.LeadLocomotiveIndex >= 0 && ((MSTSLocomotive)loco.Train.Cars[loco.Train.LeadLocomotiveIndex]).BailOff) || loco.DynamicBrakeAutoBailOff && loco.Train.MUDynamicBrakePercent > 0 && loco.DynamicBrakeForceCurves == null)
477475
BailOffOn = true;
476+
else if (loco.DynamicBrakeAutoBailOff && loco.Train.MUDynamicBrakePercent > 0 && loco.DynamicBrakeForceCurves != null)
477+
{
478+
var dynforce = loco.DynamicBrakeForceCurves.Get(1.0f, loco.AbsSpeedMpS); // max dynforce at that speed
479+
if ((loco.MaxDynamicBrakeForceN == 0 && dynforce > 0) || dynforce > loco.MaxDynamicBrakeForceN * 0.6)
480+
BailOffOn = true;
481+
}
482+
if (BailOffOn)
483+
AutoCylPressurePSI -= MaxReleaseRatePSIpS * elapsedClockSeconds;
478484
}
479-
if (BailOffOn)
480-
AutoCylPressurePSI -= MaxReleaseRatePSIpS * elapsedClockSeconds;
481485
}
482486

483487
if (AutoCylPressurePSI < 0)

Source/Orts.Simulation/Simulation/RollingStocks/TrainCar.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ public enum EngineTypes
623623
Steam,
624624
Diesel,
625625
Electric,
626+
Control,
626627
}
627628
public EngineTypes EngineType;
628629

@@ -1737,7 +1738,13 @@ public virtual void SignalEvent(PowerSupplyEvent evt, int id) { }
17371738
public virtual string GetStatus() { return null; }
17381739
public virtual string GetDebugStatus()
17391740
{
1740-
return String.Format("{0}\t{2}\t{1}\t{3}\t{4:F0}%\t{5}\t\t{6}\t{7}\t",
1741+
string locomotivetypetext = "";
1742+
if (EngineType == EngineTypes.Control)
1743+
{
1744+
locomotivetypetext = "Unpowered Control Trailer Car";
1745+
}
1746+
1747+
return String.Format("{0}\t{2}\t{1}\t{3}\t{4:F0}%\t{5}\t\t{6}\t{7}\t{8}\t",
17411748
CarID,
17421749
Flipped ? Simulator.Catalog.GetString("Yes") : Simulator.Catalog.GetString("No"),
17431750
FormatStrings.Catalog.GetParticularString("Reverser", GetStringAttribute.GetPrettyName(Direction)),
@@ -1746,7 +1753,10 @@ public virtual string GetDebugStatus()
17461753
String.Format("{0}", FormatStrings.FormatSpeedDisplay(SpeedMpS, IsMetric)),
17471754
// For Locomotive HUD display shows "forward" motive power (& force) as a positive value, braking power (& force) will be shown as negative values.
17481755
FormatStrings.FormatPower((MotiveForceN) * SpeedMpS, IsMetric, false, false),
1749-
String.Format("{0}{1}", FormatStrings.FormatForce(MotiveForceN, IsMetric), WheelSlip ? "!!!" : WheelSlipWarning ? "???" : ""));
1756+
String.Format("{0}{1}", FormatStrings.FormatForce(MotiveForceN, IsMetric), WheelSlip ? "!!!" : WheelSlipWarning ? "???" : ""),
1757+
Simulator.Catalog.GetString(locomotivetypetext)
1758+
1759+
);
17501760
}
17511761
public virtual string GetTrainBrakeStatus() { return null; }
17521762
public virtual string GetEngineBrakeStatus() { return null; }

0 commit comments

Comments
 (0)