Skip to content

Commit db2d1c8

Browse files
committed
Changes as suggested in the PR.
1 parent 3c49af0 commit db2d1c8

File tree

6 files changed

+58
-65
lines changed

6 files changed

+58
-65
lines changed

Source/Contrib/ContentManager/ContentInfo.cs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ public static string GetText(Content content)
193193
details.AppendFormat("Length:\t{1}{0}", Environment.NewLine, FormatStrings.FormatShortDistanceDisplay(data.LengthM, IsMetric));
194194
details.AppendFormat("Power:\t{1}{0}", Environment.NewLine, FormatStrings.FormatPower(data.MaxPowerW, IsMetric, IsImperialBHP, IsImperialBTUpS));
195195
details.AppendFormat("MaxTE:\t{1}{0}", Environment.NewLine, FormatStrings.FormatForce(data.MaxTractiveForceN, IsMetric));
196-
if (!IsMetric && !IsUK) details.AppendFormat("HPT:\t{1}{0}", Environment.NewLine, FormatStrings.FormatHPT(data.MaxPowerW, data.MassKG));
197-
if (!IsMetric && !IsUK) details.AppendFormat("TPOB:\t{1}{0}", Environment.NewLine, FormatStrings.FormatTPOB(data.MassKG, data.NumOperativeBrakes));
196+
if (!IsMetric && !IsUK) details.AppendFormat("HPT:\t{1}{0}", Environment.NewLine, FormatHPT(data.MaxPowerW, data.MassKG));
197+
if (!IsMetric && !IsUK) details.AppendFormat("TPOB:\t{1}{0}", Environment.NewLine, FormatTPOB(data.MassKG, data.NumOperativeBrakes));
198198
details.AppendLine();
199199
details.AppendFormat("Car ID:\tDirection:\tWeight:\tName:\t{0}", Environment.NewLine);
200200
foreach (var car in data.Cars)
201-
details.AppendFormat("{1}\t{2}\t{3}\t\u0001{4}\u0002Car\u0001{0}", Environment.NewLine, car.ID, car.Direction, car.IsEngine ? "Engine" : FormatStrings.FormatMassBar(car.MassKG), car.Name);
201+
details.AppendFormat("{1}\t{2}\t{3}\t\u0001{4}\u0002Car\u0001{0}", Environment.NewLine, car.ID, car.Direction, car.IsEngine ? "Engine" : FormatMassBar(car.MassKG), car.Name);
202202
details.AppendFormat("{0}", Environment.NewLine);
203203
}
204204
else if (content.Type == ContentType.Car)
@@ -243,5 +243,46 @@ static string FormatDateTime(DateTime dateTime)
243243
{
244244
return String.Format("{0} {1}", dateTime.Day - 1, dateTime.ToLongTimeString());
245245
}
246+
247+
/// <summary>
248+
/// Create a simple bar graph (string of asterisk) for the car mass.
249+
/// </summary>
250+
/// <param name="massKg"></param>
251+
/// <returns>String of asterisk representing the mass.</returns>
252+
static string FormatMassBar(float massKg)
253+
{
254+
string massBar;
255+
var range = (int)Math.Ceiling(massKg / 20000);
256+
if (massKg < 1.0) { massBar = "?"; }
257+
else if (range > 8) { massBar = new string('*', 8) + '>'; }
258+
else { massBar = new string('*', range); }
259+
return massBar;
260+
}
261+
262+
/// <summary>
263+
/// Calculate and format horsepower per ton for consist, rounded to one decimal.
264+
/// </summary>
265+
/// <param name="consistPowerW"></param>
266+
/// <param name="consistMassKG"></param>
267+
/// <returns>horsepower-per-ton formated to one decimal.</returns>
268+
//TODO: implement UK and metric version
269+
static string FormatHPT(float consistPowerW, float consistMassKG)
270+
{
271+
var hpt = consistMassKG > 0 ? W.ToHp(consistPowerW) / Kg.ToTUS(consistMassKG) : 0;
272+
return string.Format("{0:0.0}", hpt);
273+
}
274+
275+
/// <summary>
276+
/// Calculate and format tons per operative brake for consist, rounded to an integer.
277+
/// </summary>
278+
/// <param name="consistMassKG"></param>
279+
/// <param name="consistNumOpBrakes"></param>
280+
/// <returns>tons-per-operative-brake formated to an integer.</returns>
281+
//TODO: implement UK and metric version
282+
static string FormatTPOB(float consistMassKG, float consistNumOpBrakes)
283+
{
284+
var tpob = consistNumOpBrakes > 0 ? Kg.ToTUS(consistMassKG) / consistNumOpBrakes : 0;
285+
return string.Format("{0:0}", tpob);
286+
}
246287
}
247288
}

Source/Contrib/ContentManager/Models/Car.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public Car(Content content)
5353
SubType = wagFile.WagonType;
5454
Name = wagFile.Name;
5555
MassKG = wagFile.MassKG;
56-
LengthM = wagFile.LengthM;
56+
LengthM = wagFile.WagonSize.LengthM;
5757
MaxBarkeForceN = wagFile.MaxBrakeForceN;
5858

5959
if (System.IO.Path.GetExtension(content.PathName).Equals(".eng", StringComparison.OrdinalIgnoreCase))

Source/Contrib/ContentManager/Models/Consist.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public Consist(Content content)
6767
var wagonFile = new WagonFile(filePath);
6868
var engFile = wag.IsEngine ? new EngineFile(filePath) : null;
6969

70-
LengthM += wagonFile.LengthM;
70+
LengthM += wagonFile.WagonSize.LengthM;
7171
MassKG += wagonFile.MassKG;
7272
wagonMassKG = wagonFile.MassKG;
7373
MaxBrakeForce += wagonFile.MaxBrakeForceN;
@@ -80,7 +80,7 @@ public Consist(Content content)
8080
MaxPowerW += engFile.MaxPowerW;
8181
MaxTractiveForceN += engFile.MaxForceN;
8282
}
83-
else if (!wag.IsEOT && wagonFile.LengthM > 1.1) // exclude legacy EOT
83+
else if (!wag.IsEOT && wagonFile.WagonSize.LengthM > 1.1) // exclude legacy EOT
8484
{
8585
WagCount++;
8686
}

Source/ORTS.Common/Conversions.cs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -720,25 +720,6 @@ public static string FormatLargeMass(float massKg, bool isMetric, bool isUK)
720720
return FormatMass(massKg, isMetric);
721721
}
722722

723-
public static string FormatMassBar( float massKg)
724-
{
725-
string massBar;
726-
var range = (int) Math.Ceiling(massKg / 20000);
727-
switch (range)
728-
{
729-
case 1: massBar = "*"; break;
730-
case 2: massBar = "**"; break;
731-
case 3: massBar = "***"; break;
732-
case 4: massBar = "****"; break;
733-
case 5: massBar = "*****"; break;
734-
case 6: massBar = "******"; break;
735-
case 7: massBar = "*******"; break;
736-
case 8: massBar = "********"; break;
737-
default: massBar = massKg < 1.0 ? "?" : "********>"; break;
738-
}
739-
return massBar;
740-
}
741-
742723
public static string FormatArea(float areaM2, bool isMetric)
743724
{
744725
var area = isMetric ? areaM2 : Me2.ToFt2(areaM2);
@@ -932,33 +913,5 @@ public static string FormatApproximateTime(double clockTimeSeconds)
932913

933914
return string.Format("{0:D2}:{1:D2}", hour, minute);
934915
}
935-
936-
937-
/// <summary>
938-
/// Calculate and format horsepower per ton for consist, rounded to one decimal.
939-
/// </summary>
940-
/// <param name="consistPowerW"></param>
941-
/// <param name="consistMassKG"></param>
942-
/// <returns>horsepower-per-ton formated to one decimal.</returns>
943-
//TODO: implement UK and metric version
944-
public static string FormatHPT(float consistPowerW, float consistMassKG)
945-
{
946-
var hpt = consistMassKG > 0 ? W.ToHp(consistPowerW) / Kg.ToTUS(consistMassKG) : 0;
947-
return string.Format("{0:0.0}", hpt);
948-
}
949-
950-
951-
/// <summary>
952-
/// Calculate and format tons per operative brake for consist, rounded to an integer.
953-
/// </summary>
954-
/// <param name="consistMassKG"></param>
955-
/// <param name="consistNumOpBrakes"></param>
956-
/// <returns>tons-per-operative-brake formated to an integer.</returns>
957-
//TODO: implement UK and metric version
958-
public static string FormatTPOB(float consistMassKG, float consistNumOpBrakes)
959-
{
960-
var tpob = consistNumOpBrakes > 0 ? Kg.ToTUS(consistMassKG) / consistNumOpBrakes : 0;
961-
return string.Format("{0:0}", tpob);
962-
}
963916
}
964917
}

Source/Orts.Formats.Msts/ActivityFile.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,6 @@ public class Wagon {
13201320
public string Folder;
13211321
public string Name;
13221322
public int UiD;
1323-
public bool IsWagon;
13241323
public bool IsEngine;
13251324
public bool IsEOT;
13261325
public bool Flip;
@@ -1332,7 +1331,7 @@ public Wagon(STFReader stf) {
13321331
new STFReader.TokenProcessor("uid", ()=>{ UiD = stf.ReadIntBlock(null); }),
13331332
new STFReader.TokenProcessor("flip", ()=>{ stf.MustMatch("("); stf.MustMatch(")"); Flip = true; }),
13341333
new STFReader.TokenProcessor("enginedata", ()=>{ stf.MustMatch("("); Name = stf.ReadString(); Folder = stf.ReadString(); stf.MustMatch(")"); IsEngine = true; }),
1335-
new STFReader.TokenProcessor("wagondata", ()=>{ stf.MustMatch("("); Name = stf.ReadString(); Folder = stf.ReadString(); stf.MustMatch(")"); IsWagon = true; }),
1334+
new STFReader.TokenProcessor("wagondata", ()=>{ stf.MustMatch("("); Name = stf.ReadString(); Folder = stf.ReadString(); stf.MustMatch(")"); }),
13361335
new STFReader.TokenProcessor("eotdata", ()=>{ stf.MustMatch("("); Name = stf.ReadString(); Folder = stf.ReadString(); stf.MustMatch(")"); IsEOT = true; }),
13371336
new STFReader.TokenProcessor("loaddata", ()=>
13381337
{

Source/Orts.Formats.Msts/WagonFile.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,29 @@ public class WagonFile
2929
{
3030
public class CarSize
3131
{
32-
public float CarWidth;
33-
public float CarHeight;
34-
public float CarLength;
32+
public float WidthM;
33+
public float HeightM;
34+
public float LengthM;
3535

3636
public CarSize(STFReader stf)
3737
{
3838
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(")")
39+
WidthM = stf.ReadFloat(STFReader.UNITS.Distance, null);
40+
HeightM = stf.ReadFloat(STFReader.UNITS.Distance, null);
41+
LengthM = stf.ReadFloat(STFReader.UNITS.Distance, null);
42+
stf.MustMatch(")");
4343
}
4444

4545
public override string ToString()
4646
{
47-
return CarWidth.ToString() + "x" + CarHeight.ToString() + "x" + CarLength.ToString();
47+
return WidthM.ToString() + "x" + HeightM.ToString() + "x" + LengthM.ToString();
4848
}
4949
}
5050

5151
public string Name;
5252
public string WagonType;
5353
public float MassKG;
54-
public float LengthM;
54+
public CarSize WagonSize;
5555
public float MaxBrakeForceN;
5656

5757
public WagonFile(string filePath)
@@ -65,7 +65,7 @@ public WagonFile(string filePath)
6565
new STFReader.TokenProcessor("name", ()=>{ Name = stf.ReadStringBlock(null); }),
6666
new STFReader.TokenProcessor("type", ()=>{ WagonType = stf.ReadStringBlock(null); }),
6767
new STFReader.TokenProcessor("mass", ()=>{ MassKG = stf.ReadFloatBlock(STFReader.UNITS.Mass, null); }),
68-
new STFReader.TokenProcessor("size", ()=>{ LengthM = new CarSize( stf).CarLength; }),
68+
new STFReader.TokenProcessor("size", ()=>{ WagonSize = new CarSize( stf); }),
6969
new STFReader.TokenProcessor("maxbrakeforce", ()=>{ MaxBrakeForceN = stf.ReadFloatBlock(STFReader.UNITS.Force, null); }),
7070
});
7171
}),

0 commit comments

Comments
 (0)