@@ -60,7 +60,7 @@ internal static void ParseTrainData(string FileName, System.Text.Encoding Encodi
60
60
}
61
61
}
62
62
TrainDatFormats currentFormat = TrainDatFormats . openBVE ;
63
- const int currentVersion = 15311 ;
63
+ const int currentVersion = 18000 ;
64
64
int myVersion = - 1 ;
65
65
for ( int i = 0 ; i < Lines . Length ; i ++ ) {
66
66
if ( Lines [ i ] . Length > 0 ) {
@@ -152,6 +152,8 @@ internal static void ParseTrainData(string FileName, System.Text.Encoding Encodi
152
152
Train . Handles . EmergencyBrake = new TrainManager . EmergencyHandle ( ) ;
153
153
Train . Handles . HasLocoBrake = false ;
154
154
double [ ] powerDelayUp = { } , powerDelayDown = { } , brakeDelayUp = { } , brakeDelayDown = { } , locoBrakeDelayUp = { } , locoBrakeDelayDown = { } ;
155
+ int numberOfPantographs = 1 ;
156
+ double pantographLocation = - 1 ;
155
157
int powerNotches = 0 , brakeNotches = 0 , locoBrakeNotches = 0 , powerReduceSteps = - 1 , locoBrakeType = 0 , driverPowerNotches = 0 , driverBrakeNotches = 0 ;
156
158
TrainManager . MotorSoundTable [ ] Tables = new TrainManager . MotorSoundTable [ 4 ] ;
157
159
for ( int i = 0 ; i < 4 ; i ++ ) {
@@ -675,6 +677,20 @@ internal static void ParseTrainData(string FileName, System.Text.Encoding Encodi
675
677
} else {
676
678
CarUnexposedFrontalArea = a ;
677
679
} break ;
680
+ case 11 :
681
+ if ( a <= 0.0 )
682
+ {
683
+ Interface . AddMessage ( MessageType . Error , false , "NumberOfPantographs is expected to be positive at line " + ( i + 1 ) . ToString ( Culture ) + " in " + FileName ) ;
684
+ }
685
+ else
686
+ {
687
+ numberOfPantographs = ( int ) a ;
688
+ }
689
+ break ;
690
+ case 12 :
691
+ //Do no validation here, as we don't necessarily yet know the length of a car
692
+ pantographLocation = a ;
693
+ break ;
678
694
}
679
695
} i ++ ; n ++ ;
680
696
} i -- ; break ;
@@ -961,6 +977,19 @@ internal static void ParseTrainData(string FileName, System.Text.Encoding Encodi
961
977
MaximumAcceleration = AccelerationCurves [ i ] . StageOneAcceleration ;
962
978
}
963
979
}
980
+
981
+ if ( pantographLocation < 0 || pantographLocation > CarLength )
982
+ {
983
+ //Pantograph location is relative from the front of the car
984
+ //Somone will probably want to add one outside the physical model, so just warn...
985
+ Interface . AddMessage ( MessageType . Warning , false , "A PantographLocation of " + pantographLocation . ToString ( Culture ) + " places it outside the bounds of the car in file " + FileName ) ;
986
+ }
987
+
988
+ if ( numberOfPantographs > Cars )
989
+ {
990
+ Interface . AddMessage ( MessageType . Error , false , "A total of " + numberOfPantographs . ToString ( Culture ) + " were defined, when the train has " + Cars . ToString ( Culture ) + " cars in file " + FileName ) ;
991
+ numberOfPantographs = Cars ;
992
+ }
964
993
// assign motor cars
965
994
if ( MotorCars == 1 ) {
966
995
if ( FrontCarIsMotorCar | TrailerCars == 0 ) {
@@ -1010,6 +1039,84 @@ internal static void ParseTrainData(string FileName, System.Text.Encoding Encodi
1010
1039
}
1011
1040
}
1012
1041
}
1042
+ // assign pantograph cars
1043
+ if ( numberOfPantographs == Cars )
1044
+ {
1045
+ //One pantograph per car
1046
+ for ( int i = 0 ; i < Train . Cars . Length ; i ++ )
1047
+ {
1048
+ Train . Cars [ i ] . Pantograph = new TrackFollower ( Program . CurrentHost , Train ) ;
1049
+ }
1050
+ }
1051
+ else if ( numberOfPantographs == MotorCars )
1052
+ {
1053
+ //Assign pantograph to all motor cars
1054
+ for ( int i = 0 ; i < Train . Cars . Length ; i ++ )
1055
+ {
1056
+ if ( Train . Cars [ i ] . Specs . IsMotorCar )
1057
+ {
1058
+ Train . Cars [ i ] . Pantograph = new TrackFollower ( Program . CurrentHost , Train ) ;
1059
+ }
1060
+ }
1061
+ }
1062
+ else if ( numberOfPantographs == 1 )
1063
+ {
1064
+ // With single pantograph, assign to the first motor car
1065
+ for ( int i = 0 ; i < Train . Cars . Length ; i ++ )
1066
+ {
1067
+ if ( Train . Cars [ i ] . Specs . IsMotorCar )
1068
+ {
1069
+ Train . Cars [ i ] . Pantograph = new TrackFollower ( Program . CurrentHost , Train ) ;
1070
+ break ;
1071
+ }
1072
+ }
1073
+ }
1074
+ else if ( numberOfPantographs == 2 )
1075
+ {
1076
+ if ( MotorCars >= 2 )
1077
+ {
1078
+ // Assign pantographs to the first and last motor cars
1079
+ for ( int i = 0 ; i < Train . Cars . Length ; i ++ )
1080
+ {
1081
+ if ( Train . Cars [ i ] . Specs . IsMotorCar )
1082
+ {
1083
+ Train . Cars [ i ] . Pantograph = new TrackFollower ( Program . CurrentHost , Train ) ;
1084
+ break ;
1085
+ }
1086
+ }
1087
+ for ( int i = Train . Cars . Length - 1 ; i > 0 ; i -- )
1088
+ {
1089
+ if ( Train . Cars [ i ] . Specs . IsMotorCar )
1090
+ {
1091
+ Train . Cars [ i ] . Pantograph = new TrackFollower ( Program . CurrentHost , Train ) ;
1092
+ break ;
1093
+ }
1094
+ }
1095
+ }
1096
+ else
1097
+ {
1098
+ //Assign evenly
1099
+ int i = ( int ) Math . Ceiling ( 0.25 * ( double ) ( Cars - 1 ) ) ;
1100
+ int j = ( int ) Math . Floor ( 0.75 * ( double ) ( Cars - 1 ) ) ;
1101
+ Train . Cars [ i ] . Pantograph = new TrackFollower ( Program . CurrentHost , Train ) ;
1102
+ Train . Cars [ j ] . Pantograph = new TrackFollower ( Program . CurrentHost , Train ) ;
1103
+ }
1104
+ }
1105
+ else
1106
+ {
1107
+ //Assign using motor cars algo
1108
+ double t = 1.0 + numberOfPantographs ;
1109
+ double r = 0.0 ;
1110
+ double x = 1.0 ;
1111
+ while ( true ) {
1112
+ double y = x + t - r ;
1113
+ x = Math . Ceiling ( y ) ;
1114
+ r = x - y ;
1115
+ int i = ( int ) x ;
1116
+ if ( i >= Cars ) break ;
1117
+ Train . Cars [ i ] . Pantograph = new TrackFollower ( Program . CurrentHost , Train ) ;
1118
+ }
1119
+ }
1013
1120
double MotorDeceleration = Math . Sqrt ( MaximumAcceleration * BrakeDeceleration ) ;
1014
1121
// apply brake-specific attributes for all cars
1015
1122
for ( int i = 0 ; i < Cars ; i ++ ) {
@@ -1184,15 +1291,10 @@ internal static void ParseTrainData(string FileName, System.Text.Encoding Encodi
1184
1291
{
1185
1292
Train . Cars [ i ] . Coupler = new TrainManager . Coupler ( 0.9 * DistanceBetweenTheCars , 1.1 * DistanceBetweenTheCars , Train . Cars [ i / 2 ] , null , Train ) ;
1186
1293
}
1187
-
1188
- Train . Cars [ i ] . CurrentCarSection = - 1 ;
1189
- Train . Cars [ i ] . ChangeCarSection ( CarSectionType . NotVisible ) ;
1190
- Train . Cars [ i ] . FrontBogie . ChangeSection ( - 1 ) ;
1191
- Train . Cars [ i ] . RearBogie . ChangeSection ( - 1 ) ;
1192
- Train . Cars [ i ] . Coupler . ChangeSection ( - 1 ) ;
1294
+
1295
+ Train . Cars [ i ] . PantographPosition = pantographLocation ;
1193
1296
Train . Cars [ i ] . FrontAxle . Follower . TriggerType = i == 0 ? EventTriggerType . FrontCarFrontAxle : EventTriggerType . OtherCarFrontAxle ;
1194
1297
Train . Cars [ i ] . RearAxle . Follower . TriggerType = i == Cars - 1 ? EventTriggerType . RearCarRearAxle : EventTriggerType . OtherCarRearAxle ;
1195
- Train . Cars [ i ] . BeaconReceiver . TriggerType = i == 0 ? EventTriggerType . TrainFront : EventTriggerType . None ;
1196
1298
Train . Cars [ i ] . BeaconReceiverPosition = 0.5 * CarLength ;
1197
1299
Train . Cars [ i ] . FrontAxle . Follower . Car = Train . Cars [ i ] ;
1198
1300
Train . Cars [ i ] . RearAxle . Follower . Car = Train . Cars [ i ] ;
0 commit comments