1919using System ;
2020using System . Collections . Generic ;
2121using System . Diagnostics ;
22+ using System . IO ;
2223using System . Linq ;
24+ using System . Runtime . CompilerServices ;
2325using System . Text ;
2426
2527namespace ORTS . ContentManager . Models
@@ -31,8 +33,8 @@ public class Consist
3133 public readonly string NumCars ;
3234 public readonly float MaxSpeedMps ;
3335 public readonly float LengthM = 0F ;
34- public readonly float WeightKG = 0F ;
35- public readonly float PowerW = 0F ;
36+ public readonly float MassKG = 0F ;
37+ public readonly float MaxPowerW = 0F ;
3638 public readonly float MaxTractiveForceN = 0F ;
3739 public readonly float MaxBrakeForce = 0F ;
3840 public readonly int NumOperativeBrakes = 0 ;
@@ -52,23 +54,47 @@ public Consist(Content content)
5254 var WagCount = 0 ;
5355 var Separator = "" ; // when set, indicates that subsequent engines are in a separate block
5456
57+ var basePath = System . IO . Path . Combine ( System . IO . Path . Combine ( content . Parent . PathName , "Trains" ) , "Trainset" ) ;
58+
5559 var CarList = new List < Car > ( ) ;
5660 foreach ( Wagon wag in file . Train . TrainCfg . WagonList )
5761 {
5862 CarList . Add ( new Car ( wag ) ) ;
5963
60- if ( wag . IsEngine )
61- {
62- EngCount ++ ;
63- } else
64+ try
6465 {
65- if ( EngCount > 0 )
66+ var fileType = wag . IsEngine ? ".eng" : ".wag" ;
67+ var filePath = System . IO . Path . Combine ( System . IO . Path . Combine ( basePath , wag . Folder ) , wag . Name + fileType ) ;
68+ var wagonFile = new WagonFile ( filePath ) ;
69+ var engFile = wag . IsEngine ? new EngineFile ( filePath ) : null ;
70+
71+ LengthM += wagonFile . LengthM ;
72+ MassKG += wagonFile . MassKG ;
73+ MaxBrakeForce += wagonFile . MaxBrakeForceN ;
74+ if ( wagonFile . MaxBrakeForceN > 0 ) NumOperativeBrakes ++ ;
75+
76+ if ( wag . IsEngine && engFile . MaxForceN > 25000 ) // exclude legacy driving trailers / cab-cars
77+ {
78+ EngCount ++ ;
79+
80+ MaxPowerW += engFile . MaxPowerW ;
81+ MaxTractiveForceN += engFile . MaxForceN ;
82+ }
83+ else if ( ! wag . IsEOT && wagonFile . LengthM > 1.1 ) // exclude legacy EOT
6684 {
67- NumEngines = NumEngines + Separator + EngCount . ToString ( ) ;
68- EngCount = 0 ; Separator = "+" ;
85+ WagCount ++ ;
6986 }
70- WagCount ++ ;
87+ } catch ( IOException e ) // continue without details when eng/wag file does not exist
88+ {
89+ if ( wag . IsEngine ) EngCount ++ ; else WagCount ++ ;
90+ }
91+
92+ if ( ! wag . IsEngine && EngCount > 0 )
93+ {
94+ NumEngines = NumEngines + Separator + EngCount . ToString ( ) ;
95+ EngCount = 0 ; Separator = "+" ;
7196 }
97+
7298 }
7399 if ( EngCount > 0 ) { NumEngines = NumEngines + Separator + EngCount . ToString ( ) ; }
74100 if ( NumEngines == null ) { NumEngines = "0" ; }
0 commit comments