File tree Expand file tree Collapse file tree 2 files changed +63
-4
lines changed
Source/Orts.Simulation/Simulation/RollingStocks Expand file tree Collapse file tree 2 files changed +63
-4
lines changed Original file line number Diff line number Diff line change @@ -2850,7 +2850,7 @@ public override bool GetSanderOn()
28502850 {
28512851 return Sander ;
28522852 }
2853-
2853+
28542854 #region Reverser
28552855 public void SetDirection ( Direction direction )
28562856 {
@@ -4455,9 +4455,27 @@ public virtual float GetDataOf(CabViewControl cvc)
44554455 }
44564456 case CABViewControlTypes . RPM :
44574457 {
4458- var mstsDieselLocomotive = this as MSTSDieselLocomotive ;
4459- if ( mstsDieselLocomotive . DieselEngines [ 0 ] != null )
4460- data = mstsDieselLocomotive . DieselEngines [ 0 ] . RealRPM ;
4458+ if ( EngineType == EngineTypes . Control )
4459+ {
4460+ FindControlActiveLocomotive ( ) ;
4461+ if ( ControlActiveLocomotive != null )
4462+ {
4463+ var activeloco = ControlActiveLocomotive as MSTSDieselLocomotive ;
4464+ if ( activeloco . DieselEngines [ 0 ] != null )
4465+ data = activeloco . DieselEngines [ 0 ] . RealRPM ;
4466+ // Trace.TraceInformation("Data#1 CarID {0} RPM {1}", CarID, data);
4467+
4468+ }
4469+
4470+ }
4471+ else
4472+ {
4473+ var mstsDieselLocomotive = this as MSTSDieselLocomotive ;
4474+ if ( mstsDieselLocomotive . DieselEngines [ 0 ] != null )
4475+ data = mstsDieselLocomotive . DieselEngines [ 0 ] . RealRPM ;
4476+
4477+ // Trace.TraceInformation("Data#2 CarID {0} RPM {1}", CarID, data);
4478+ }
44614479 break ;
44624480 }
44634481 case CABViewControlTypes . ORTS_DIESEL_TEMPERATURE :
Original file line number Diff line number Diff line change @@ -246,6 +246,11 @@ public class MSTSWagon : TrainCar
246246 /// </summary>
247247 public bool AuxiliaryReservoirPresent ;
248248
249+ /// <summary>
250+ /// Active locomotive for a control trailer
251+ /// </summary>
252+ public MSTSLocomotive ControlActiveLocomotive { get ; private set ; }
253+
249254 /// <summary>
250255 /// Attached steam locomotive in case this wagon is a tender
251256 /// </summary>
@@ -3271,6 +3276,42 @@ public void ToggleMirrors()
32713276 if ( Simulator . PlayerLocomotive == this ) Simulator . Confirmer . Confirm ( CabControl . Mirror , MirrorOpen ? CabSetting . On : CabSetting . Off ) ;
32723277 }
32733278
3279+ public void FindControlActiveLocomotive ( )
3280+ {
3281+ // Find the active locomotive associated with a control car
3282+ if ( Train == null || Train . Cars == null || Train . Cars . Count == 1 )
3283+ {
3284+ ControlActiveLocomotive = null ;
3285+ return ;
3286+ }
3287+
3288+ var controlIndex = 0 ;
3289+ var activeIndex = 0 ;
3290+ bool controlCar = false ;
3291+ bool activeLocomotive = false ;
3292+
3293+ // Check to see if this car is an active locomotive, if so then set linkage to relevant control car.
3294+ for ( var i = 0 ; i < Train . Cars . Count ; i ++ )
3295+ {
3296+ if ( Train . Cars [ i ] == this && activeIndex == 0 && Train . Cars [ i ] . EngineType == TrainCar . EngineTypes . Diesel )
3297+ {
3298+ activeIndex = i ;
3299+ activeLocomotive = true ;
3300+ }
3301+
3302+ if ( Train . Cars [ i ] == this && controlIndex == 0 && Train . Cars [ i ] . EngineType == TrainCar . EngineTypes . Control )
3303+ {
3304+ controlIndex = i ;
3305+ controlCar = true ;
3306+ }
3307+
3308+ if ( activeLocomotive && controlCar )
3309+ {
3310+ ControlActiveLocomotive = Train . Cars [ activeIndex ] as MSTSDieselLocomotive ;
3311+ return ;
3312+ }
3313+ }
3314+ }
32743315
32753316 public void FindTendersSteamLocomotive ( )
32763317 {
You can’t perform that action at this time.
0 commit comments