@@ -49,7 +49,12 @@ namespace Orts.Simulation.RollingStocks
49
49
public class MSTSControlTrailerCar : MSTSLocomotive
50
50
{
51
51
52
- public int ControlGearBoxNumberOfGears = 1 ;
52
+ public int ControllerNumberOfGears = 1 ;
53
+ bool HasGearController = false ;
54
+ bool ControlGearUp = false ;
55
+ bool ControlGearDown = false ;
56
+ int ControlGearIndex ;
57
+ int ControlGearIndication ;
53
58
54
59
55
60
public MSTSControlTrailerCar ( Simulator simulator , string wagFile )
@@ -63,18 +68,25 @@ public MSTSControlTrailerCar(Simulator simulator, string wagFile)
63
68
public override void LoadFromWagFile ( string wagFilePath )
64
69
{
65
70
base . LoadFromWagFile ( wagFilePath ) ;
66
-
67
- Trace . TraceInformation ( "Control Trailer" ) ;
68
-
69
71
}
70
72
71
73
72
74
public override void Initialize ( )
73
75
{
74
-
75
- base . Initialize ( ) ;
76
76
77
-
77
+
78
+ // Initialise gearbox controller
79
+ if ( ControllerNumberOfGears > 0 )
80
+ {
81
+ GearBoxController = new MSTSNotchController ( ControllerNumberOfGears + 1 ) ;
82
+ if ( Simulator . Settings . VerboseConfigurationMessages )
83
+ HasGearController = true ;
84
+ Trace . TraceInformation ( "Control Car Gear Controller created" ) ;
85
+ ControlGearIndex = 0 ;
86
+ Train . HasControlCarWithGear = true ;
87
+ }
88
+
89
+ base . Initialize ( ) ;
78
90
}
79
91
80
92
@@ -101,7 +113,7 @@ public override void Parse(string lowercasetoken, STFReader stf)
101
113
break ;
102
114
103
115
// to setup gearbox controller
104
- case "engine(gearboxnumberofgears " : ControlGearBoxNumberOfGears = stf . ReadIntBlock ( 1 ) ; break ;
116
+ case "engine(gearboxcontrollernumberofgears " : ControllerNumberOfGears = stf . ReadIntBlock ( null ) ; break ;
105
117
106
118
107
119
default :
@@ -123,7 +135,7 @@ public override void Copy(MSTSWagon copy)
123
135
124
136
MSTSControlTrailerCar locoCopy = ( MSTSControlTrailerCar ) copy ;
125
137
126
- ControlGearBoxNumberOfGears = locoCopy . ControlGearBoxNumberOfGears ;
138
+ ControllerNumberOfGears = locoCopy . ControllerNumberOfGears ;
127
139
128
140
129
141
}
@@ -135,6 +147,8 @@ public override void Copy(MSTSWagon copy)
135
147
public override void Save ( BinaryWriter outf )
136
148
{
137
149
ControllerFactory . Save ( GearBoxController , outf ) ;
150
+ outf . Write ( ControlGearIndication ) ;
151
+ outf . Write ( ControlGearIndex ) ;
138
152
}
139
153
140
154
/// <summary>
@@ -145,7 +159,8 @@ public override void Restore(BinaryReader inf)
145
159
{
146
160
base . Restore ( inf ) ;
147
161
ControllerFactory . Restore ( GearBoxController , inf ) ;
148
-
162
+ ControlGearIndication = inf . ReadInt32 ( ) ;
163
+ ControlGearIndex = inf . ReadInt32 ( ) ;
149
164
}
150
165
151
166
@@ -159,14 +174,6 @@ public override void InitializeMoving()
159
174
WheelSpeedMpS = SpeedMpS ;
160
175
161
176
ThrottleController . SetValue ( Train . MUThrottlePercent / 100 ) ;
162
-
163
- // Initialise gearbox controller
164
- if ( ControlGearBoxNumberOfGears > 0 )
165
- {
166
- GearBoxController = new MSTSNotchController ( ControlGearBoxNumberOfGears + 1 ) ;
167
- }
168
-
169
-
170
177
}
171
178
172
179
/// <summary>
@@ -177,6 +184,61 @@ public override void Update(float elapsedClockSeconds)
177
184
base . Update ( elapsedClockSeconds ) ;
178
185
WheelSpeedMpS = SpeedMpS ; // Set wheel speed for control car, required to make wheels go around.
179
186
187
+
188
+ if ( ControllerNumberOfGears > 0 && IsLeadLocomotive ( ) )
189
+ {
190
+ // pass gearbox command key to other locomotives in train, don't treat the player locomotive in this fashion.
191
+ foreach ( TrainCar car in Train . Cars )
192
+ {
193
+
194
+
195
+ var locog = car as MSTSDieselLocomotive ;
196
+
197
+ if ( locog != null && car != this && ! locog . IsLeadLocomotive ( ) && GearBoxController != null )
198
+ {
199
+
200
+ if ( ControlGearUp )
201
+ {
202
+
203
+ locog . GearBoxController . CurrentNotch = GearBoxController . CurrentNotch ;
204
+ locog . GearBoxController . SetValue ( ( float ) locog . GearBoxController . CurrentNotch ) ;
205
+
206
+ locog . ChangeGearUp ( ) ;
207
+
208
+ ControlGearUp = false ;
209
+ }
210
+
211
+
212
+ if ( ControlGearDown )
213
+ {
214
+
215
+ locog . GearBoxController . CurrentNotch = GearBoxController . CurrentNotch ;
216
+ locog . GearBoxController . SetValue ( ( float ) locog . GearBoxController . CurrentNotch ) ;
217
+
218
+ locog . ChangeGearDown ( ) ;
219
+
220
+ ControlGearDown = false ;
221
+ }
222
+
223
+ // Read values for the HuD
224
+ ControlGearIndex = locog . DieselEngines [ 0 ] . GearBox . CurrentGearIndex ;
225
+ ControlGearIndication = locog . DieselEngines [ 0 ] . GearBox . GearIndication ;
226
+ }
227
+
228
+ }
229
+ }
230
+
231
+ }
232
+
233
+ public override string GetStatus ( )
234
+ {
235
+ var status = new StringBuilder ( ) ;
236
+ if ( HasGearController )
237
+ status . AppendFormat ( "{0} = {1}\n " , Simulator . Catalog . GetString ( "Gear" ) ,
238
+ ControlGearIndex < 0 ? Simulator . Catalog . GetParticularString ( "Gear" , "N" ) : ( ControlGearIndication ) . ToString ( ) ) ;
239
+ status . AppendLine ( ) ;
240
+
241
+ return status . ToString ( ) ;
180
242
}
181
243
182
244
/// <summary>
@@ -202,7 +264,42 @@ protected override void UpdateSoundVariables(float elapsedClockSeconds)
202
264
}
203
265
204
266
267
+ public override void ChangeGearUp ( )
268
+ {
269
+
270
+ GearBoxController . CurrentNotch += 1 ;
205
271
272
+ if ( GearBoxController . CurrentNotch > ControllerNumberOfGears )
273
+ {
274
+ GearBoxController . CurrentNotch = ControllerNumberOfGears ;
275
+ }
276
+ else if ( GearBoxController . CurrentNotch < 0 )
277
+ {
278
+ GearBoxController . CurrentNotch = 0 ;
279
+ }
280
+
281
+ ControlGearUp = true ;
282
+ ControlGearDown = false ;
283
+
284
+ }
285
+
286
+ public override void ChangeGearDown ( )
287
+ {
288
+ GearBoxController . CurrentNotch -= 1 ;
289
+
290
+ if ( GearBoxController . CurrentNotch > ControllerNumberOfGears )
291
+ {
292
+ GearBoxController . CurrentNotch = ControllerNumberOfGears ;
293
+ }
294
+ else if ( GearBoxController . CurrentNotch < 0 )
295
+ {
296
+ GearBoxController . CurrentNotch = 0 ;
297
+ }
298
+
299
+ ControlGearUp = false ;
300
+ ControlGearDown = true ;
301
+
302
+ }
206
303
207
304
208
305
0 commit comments