@@ -360,7 +360,7 @@ public bool LargeEjectorSoundOn
360360
361361 protected float OdometerResetPositionM = 0 ;
362362 protected bool OdometerCountingUp = true ;
363- protected bool OdometerCountingForwards = true ;
363+ protected bool OdometerDirectionForward = true ; // direction of the train when odometer was reset
364364 public bool OdometerResetButtonPressed = false ;
365365
366366 public bool OdometerVisible { get ; private set ; }
@@ -371,7 +371,11 @@ public float OdometerM
371371 if ( Train == null )
372372 return 0 ;
373373
374- return OdometerCountingForwards ? Train . DistanceTravelledM - OdometerResetPositionM : OdometerResetPositionM - Train . DistanceTravelledM ;
374+ float odo ;
375+
376+ if ( OdometerDirectionForward ^ OdometerCountingUp ) { odo = OdometerResetPositionM - Train . DistanceTravelledM ; }
377+ else { odo = Train . DistanceTravelledM - OdometerResetPositionM ; }
378+ return odo ;
375379 }
376380 }
377381
@@ -1364,7 +1368,7 @@ public override void Save(BinaryWriter outf)
13641368 outf . Write ( Wiper ) ;
13651369 outf . Write ( OdometerResetPositionM ) ;
13661370 outf . Write ( OdometerCountingUp ) ;
1367- outf . Write ( OdometerCountingForwards ) ;
1371+ outf . Write ( OdometerDirectionForward ) ;
13681372 outf . Write ( OdometerVisible ) ;
13691373 outf . Write ( MainResPressurePSI ) ;
13701374 outf . Write ( CompressorIsOn ) ;
@@ -1418,7 +1422,7 @@ public override void Restore(BinaryReader inf)
14181422 if ( inf . ReadBoolean ( ) ) SignalEvent ( Event . WiperOn ) ;
14191423 OdometerResetPositionM = inf . ReadSingle ( ) ;
14201424 OdometerCountingUp = inf . ReadBoolean ( ) ;
1421- OdometerCountingForwards = inf . ReadBoolean ( ) ;
1425+ OdometerDirectionForward = inf . ReadBoolean ( ) ;
14221426 OdometerVisible = inf . ReadBoolean ( ) ;
14231427 MainResPressurePSI = inf . ReadSingle ( ) ;
14241428 CompressorIsOn = inf . ReadBoolean ( ) ;
@@ -5049,57 +5053,48 @@ public virtual void Refuel()
50495053 // Electric locos do nothing. Diesel and steam override this.
50505054 }
50515055
5056+ /// <summary>
5057+ /// Show / hide the odometer.
5058+ /// </summary>
50525059 public void OdometerToggle ( )
50535060 {
50545061 OdometerVisible = ! OdometerVisible ;
50555062 }
50565063
50575064 /// <summary>
5058- /// Set odometer reference distance to actual travelled distance,
5059- /// and set measuring direction to the actual direction
5065+ /// Reset the odometer. Sets a new reset position, adjusted by +/- the train length when counting down.
5066+ /// The odometer calculation is in OdometerM.get().
50605067 /// </summary>
50615068 public void OdometerReset ( bool toState )
50625069 {
50635070 if ( Train == null )
50645071 return ;
5072+
50655073 if ( toState )
50665074 {
5067- if ( OdometerCountingForwards != OdometerCountingUp ^ ( Direction == Direction . Reverse ) )
5068- {
5069- OdometerCountingForwards = ! OdometerCountingForwards ;
5070- }
5075+ OdometerDirectionForward = ( Direction == Direction . Reverse ) ? false : true ;
50715076
5072- if ( Direction == Direction . Reverse )
5073- {
5074- if ( OdometerCountingForwards )
5075- OdometerResetPositionM = Train . DistanceTravelledM - Train . Length ;
5076- else
5077- OdometerResetPositionM = Train . DistanceTravelledM ;
5078- }
5079- else
5080- {
5081- if ( OdometerCountingForwards )
5082- OdometerResetPositionM = Train . DistanceTravelledM ;
5083- else
5084- OdometerResetPositionM = Train . DistanceTravelledM + Train . Length ;
5085- }
5077+ if ( OdometerCountingUp ) { OdometerResetPositionM = Train . DistanceTravelledM ; }
5078+ else if ( Direction == Direction . Reverse ) { OdometerResetPositionM = Train . DistanceTravelledM - Train . Length ; }
5079+ else { OdometerResetPositionM = Train . DistanceTravelledM + Train . Length ; }
50865080
50875081 Simulator . Confirmer . Confirm ( CabControl . Odometer , CabSetting . On ) ;
50885082 }
50895083 OdometerResetButtonPressed = toState ;
50905084 }
50915085
5086+ /// <summary>
5087+ /// Change the odometer counting direction. Adjusts the reset position +/- the train length.
5088+ /// The odometer calculation is in OdometerM.get().
5089+ /// </summary>
50925090 public void OdometerToggleDirection ( )
50935091 {
50945092 if ( Train == null )
50955093 return ;
50965094
5097- // change the up/down flag for the reset logic (above)
5098- // change the forward/reverse flag for OdometerM calculation (see OdometerM get() function)
5099- // change the reference point to match the up/down flag
51005095 OdometerCountingUp = ! OdometerCountingUp ;
5101- OdometerCountingForwards = ! OdometerCountingForwards ;
5102- OdometerResetPositionM = OdometerCountingUp ? OdometerResetPositionM - Train . Length : OdometerResetPositionM + Train . Length ;
5096+ if ( OdometerDirectionForward ^ OdometerCountingUp ) { OdometerResetPositionM += Train . Length ; }
5097+ else { OdometerResetPositionM -= Train . Length ; }
51035098
51045099 Simulator . Confirmer . Confirm ( CabControl . Odometer , OdometerCountingUp ? CabSetting . Increase : CabSetting . Decrease ) ;
51055100 }
0 commit comments