Skip to content

Commit dc54f37

Browse files
committed
Show more data for cars and locomotives.
1 parent 63ab5b1 commit dc54f37

File tree

5 files changed

+82
-10
lines changed

5 files changed

+82
-10
lines changed

Source/Contrib/ContentManager/ContentInfo.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@
2727
using System.Runtime.Serialization.Formatters.Binary;
2828
using System.Text;
2929
using Path = ORTS.ContentManager.Models.Path;
30+
using FormatStrings = ORTS.Common.FormatStrings;
3031

3132
namespace ORTS.ContentManager
3233
{
3334
public static class ContentInfo
3435
{
36+
// fixed for now; need to read from user settings (see Wagon.cs)
37+
public static bool IsMetric = false;
38+
public static bool IsUk = false;
39+
public static bool isImperialBHP = false;
40+
public static bool isImperialBTUpS = false;
41+
3542
public static string GetText(Content content)
3643
{
3744
var details = new StringBuilder();
@@ -181,6 +188,8 @@ public static string GetText(Content content)
181188
details.AppendFormat("Name:\t{1}{0}", Environment.NewLine, data.Name);
182189
details.AppendFormat("NumEngines:\t{1}{0}", Environment.NewLine, data.NumEngines);
183190
details.AppendFormat("NumCars:\t{1}{0}", Environment.NewLine, data.NumCars);
191+
details.AppendFormat("MaxSpeed:\t{1}{0}", Environment.NewLine, FormatStrings.FormatSpeedLimit(data.MaxSpeedMps, IsMetric));
192+
details.AppendLine();
184193
details.AppendFormat("Car ID:\tDirection:\tName:\t{0}", Environment.NewLine);
185194
foreach (var car in data.Cars)
186195
details.AppendFormat("{1}\t{2}\t\u0001{3}\u0002Car\u0001{0}", Environment.NewLine, car.ID, car.Direction, car.Name);
@@ -191,6 +200,16 @@ public static string GetText(Content content)
191200
var data = new Car(content);
192201
details.AppendFormat("Type:\t{1}{0}", Environment.NewLine, data.Type);
193202
details.AppendFormat("Name:\t{1}{0}", Environment.NewLine, data.Name);
203+
details.AppendFormat("Weight:\t{1} ({2}){0}", Environment.NewLine, FormatStrings.FormatMass(data.MassKG, IsMetric), FormatStrings.FormatLargeMass(data.MassKG, IsMetric, IsUk));
204+
details.AppendFormat("Length:\t{1}{0}", Environment.NewLine, FormatStrings.FormatShortDistanceDisplay(data.LengthM, IsMetric));
205+
if (data.Type == CarType.Engine)
206+
{
207+
details.AppendFormat("MaxPowerW:\t{1}{0}", Environment.NewLine, FormatStrings.FormatPower(data.MaxPowerW, IsMetric, isImperialBHP, isImperialBTUpS));
208+
details.AppendFormat("MaxForce:\t{1}{0}", Environment.NewLine, FormatStrings.FormatForce(data.MaxForceN, IsMetric));
209+
details.AppendFormat("MaxSpeed:\t{1}{0}", Environment.NewLine, FormatStrings.FormatSpeedLimit(data.MaxSpeedMps, IsMetric));
210+
}
211+
details.AppendFormat("MaxBrakeF:\t{1}{0}", Environment.NewLine, FormatStrings.FormatForce(data.MaxBarkeForceN, IsMetric));
212+
details.AppendLine();
194213
details.AppendFormat("Description:\t{0}{0}{1}{0}{0}", Environment.NewLine, data.Description);
195214
}
196215
else if (content is ContentMSTSCab)

Source/Contrib/ContentManager/Models/Car.cs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,34 @@ public class Car
3535
public readonly CarType Type;
3636
public readonly string Name;
3737
public readonly string Description;
38+
public readonly float MassKG;
39+
public readonly float LengthM;
40+
public readonly float MaxBarkeForceN;
41+
public readonly float MaxPowerW;
42+
public readonly float MaxForceN;
43+
public readonly float MaxSpeedMps;
3844

3945
public Car(Content content)
4046
{
4147
Debug.Assert(content.Type == ContentType.Car);
48+
49+
// .eng files also have a wagon block
50+
var wagFile = new WagonFile(content.PathName);
51+
Type = CarType.Wagon;
52+
Name = wagFile.Name;
53+
MassKG = wagFile.MassKG;
54+
LengthM = wagFile.LengthM;
55+
MaxBarkeForceN = wagFile.MaxBrakeForceN;
56+
4257
if (System.IO.Path.GetExtension(content.PathName).Equals(".eng", StringComparison.OrdinalIgnoreCase))
4358
{
44-
var file = new EngineFile(content.PathName);
59+
var engFile = new EngineFile(content.PathName);
4560
Type = CarType.Engine;
46-
Name = file.Name;
47-
Description = file.Description;
48-
}
49-
else if (System.IO.Path.GetExtension(content.PathName).Equals(".wag", StringComparison.OrdinalIgnoreCase))
50-
{
51-
var file = new WagonFile(content.PathName);
52-
Type = CarType.Wagon;
53-
Name = file.Name;
54-
Description = "";
61+
Name = engFile.Name;
62+
MaxPowerW = engFile.MaxPowerW;
63+
MaxForceN = engFile.MaxForceN;
64+
MaxSpeedMps = engFile.MaxSpeedMps;
65+
Description = engFile.Description;
5566
}
5667
}
5768
}

Source/Contrib/ContentManager/Models/Consist.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ public class Consist
2929
public readonly string Name;
3030
public readonly string NumEngines; // using "+" between DPU sets
3131
public readonly string NumCars;
32+
public readonly float MaxSpeedMps;
33+
public readonly float LengthM = 0F;
34+
public readonly float WeightKG = 0F;
35+
public readonly float PowerW = 0F;
36+
public readonly float MaxTractiveForceN = 0F;
37+
public readonly float MaxBrakeForce = 0F;
38+
public readonly int NumOperativeBrakes = 0;
3239

3340
public readonly IEnumerable<Car> Cars;
3441

@@ -39,6 +46,7 @@ public Consist(Content content)
3946
{
4047
var file = new ConsistFile(content.PathName);
4148
Name = file.Name;
49+
MaxSpeedMps = file.Train.TrainCfg.MaxVelocity.A;
4250

4351
var EngCount = 0;
4452
var WagCount = 0;
@@ -48,6 +56,7 @@ public Consist(Content content)
4856
foreach (Wagon wag in file.Train.TrainCfg.WagonList)
4957
{
5058
CarList.Add(new Car(wag));
59+
5160
if (wag.IsEngine)
5261
{
5362
EngCount++;

Source/Orts.Formats.Msts/EngineFile.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ namespace Orts.Formats.Msts
2828
public class EngineFile
2929
{
3030
public string Name;
31+
public float MaxPowerW;
32+
public float MaxForceN;
33+
public float MaxSpeedMps;
3134
public string Description;
3235
public string CabViewFile;
3336

@@ -40,6 +43,9 @@ public EngineFile(string filePath)
4043
stf.ReadString();
4144
stf.ParseBlock(new STFReader.TokenProcessor[] {
4245
new STFReader.TokenProcessor("name", ()=>{ Name = stf.ReadStringBlock(null); }),
46+
new STFReader.TokenProcessor("maxpower", ()=>{ MaxPowerW = stf.ReadFloatBlock( STFReader.UNITS.Power, null); }),
47+
new STFReader.TokenProcessor("maxforce", ()=>{ MaxForceN = stf.ReadFloatBlock( STFReader.UNITS.Force, null); }),
48+
new STFReader.TokenProcessor("maxvelocity", ()=>{ MaxSpeedMps = stf.ReadFloatBlock( STFReader.UNITS.Speed, null); }),
4349
new STFReader.TokenProcessor("description", ()=>{ Description = stf.ReadStringBlock(null); }),
4450
new STFReader.TokenProcessor("cabview", ()=>{ CabViewFile = stf.ReadStringBlock(null); }),
4551
});

Source/Orts.Formats.Msts/WagonFile.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,31 @@ namespace Orts.Formats.Msts
2727
/// </summary>
2828
public class WagonFile
2929
{
30+
public class CarSize
31+
{
32+
public float CarWidth;
33+
public float CarHeight;
34+
public float CarLength;
35+
36+
public CarSize(STFReader stf)
37+
{
38+
stf.MustMatch("(");
39+
CarWidth = stf.ReadFloat(STFReader.UNITS.Distance, null);
40+
CarHeight = stf.ReadFloat(STFReader.UNITS.Distance, null);
41+
CarLength = stf.ReadFloat(STFReader.UNITS.Distance, null);
42+
stf.SkipRestOfBlock(); // or should this be stf.MustMatch(")")
43+
}
44+
45+
public override string ToString()
46+
{
47+
return CarWidth.ToString() + "x" + CarHeight.ToString() + "x" + CarLength.ToString();
48+
}
49+
}
50+
3051
public string Name;
52+
public float MassKG;
53+
public float LengthM;
54+
public float MaxBrakeForceN;
3155

3256
public WagonFile(string filePath)
3357
{
@@ -38,6 +62,9 @@ public WagonFile(string filePath)
3862
stf.ReadString();
3963
stf.ParseBlock(new STFReader.TokenProcessor[] {
4064
new STFReader.TokenProcessor("name", ()=>{ Name = stf.ReadStringBlock(null); }),
65+
new STFReader.TokenProcessor("mass", ()=>{ MassKG = stf.ReadFloatBlock(STFReader.UNITS.Mass, null); }),
66+
new STFReader.TokenProcessor("size", ()=>{ LengthM = new CarSize( stf).CarLength; }),
67+
new STFReader.TokenProcessor("maxbrakeforce", ()=>{ MaxBrakeForceN = stf.ReadFloatBlock(STFReader.UNITS.Force, null); }),
4168
});
4269
}),
4370
});

0 commit comments

Comments
 (0)