@@ -360,7 +360,7 @@ public bool LargeEjectorSoundOn
360
360
361
361
protected float OdometerResetPositionM = 0 ;
362
362
protected bool OdometerCountingUp = true ;
363
- protected bool OdometerCountingForwards = true ;
363
+ protected bool OdometerDirectionForward = true ; // direction of the train when odometer was reset
364
364
public bool OdometerResetButtonPressed = false ;
365
365
366
366
public bool OdometerVisible { get ; private set ; }
@@ -371,7 +371,11 @@ public float OdometerM
371
371
if ( Train == null )
372
372
return 0 ;
373
373
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 ;
375
379
}
376
380
}
377
381
@@ -1364,7 +1368,7 @@ public override void Save(BinaryWriter outf)
1364
1368
outf . Write ( Wiper ) ;
1365
1369
outf . Write ( OdometerResetPositionM ) ;
1366
1370
outf . Write ( OdometerCountingUp ) ;
1367
- outf . Write ( OdometerCountingForwards ) ;
1371
+ outf . Write ( OdometerDirectionForward ) ;
1368
1372
outf . Write ( OdometerVisible ) ;
1369
1373
outf . Write ( MainResPressurePSI ) ;
1370
1374
outf . Write ( CompressorIsOn ) ;
@@ -1418,7 +1422,7 @@ public override void Restore(BinaryReader inf)
1418
1422
if ( inf . ReadBoolean ( ) ) SignalEvent ( Event . WiperOn ) ;
1419
1423
OdometerResetPositionM = inf . ReadSingle ( ) ;
1420
1424
OdometerCountingUp = inf . ReadBoolean ( ) ;
1421
- OdometerCountingForwards = inf . ReadBoolean ( ) ;
1425
+ OdometerDirectionForward = inf . ReadBoolean ( ) ;
1422
1426
OdometerVisible = inf . ReadBoolean ( ) ;
1423
1427
MainResPressurePSI = inf . ReadSingle ( ) ;
1424
1428
CompressorIsOn = inf . ReadBoolean ( ) ;
@@ -5049,52 +5053,48 @@ public virtual void Refuel()
5049
5053
// Electric locos do nothing. Diesel and steam override this.
5050
5054
}
5051
5055
5056
+ /// <summary>
5057
+ /// Show / hide the odometer.
5058
+ /// </summary>
5052
5059
public void OdometerToggle ( )
5053
5060
{
5054
5061
OdometerVisible = ! OdometerVisible ;
5055
5062
}
5056
5063
5057
5064
/// <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().
5060
5067
/// </summary>
5061
5068
public void OdometerReset ( bool toState )
5062
5069
{
5063
5070
if ( Train == null )
5064
5071
return ;
5072
+
5065
5073
if ( toState )
5066
5074
{
5067
- if ( OdometerCountingForwards != OdometerCountingUp ^ ( Direction == Direction . Reverse ) )
5068
- {
5069
- OdometerCountingForwards = ! OdometerCountingForwards ;
5070
- }
5075
+ OdometerDirectionForward = ( Direction == Direction . Reverse ) ? false : true ;
5071
5076
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 ; }
5086
5080
5087
5081
Simulator . Confirmer . Confirm ( CabControl . Odometer , CabSetting . On ) ;
5088
5082
}
5089
5083
OdometerResetButtonPressed = toState ;
5090
5084
}
5091
5085
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>
5092
5090
public void OdometerToggleDirection ( )
5093
5091
{
5094
5092
if ( Train == null )
5095
5093
return ;
5096
5094
5097
5095
OdometerCountingUp = ! OdometerCountingUp ;
5096
+ if ( OdometerDirectionForward ^ OdometerCountingUp ) { OdometerResetPositionM += Train . Length ; }
5097
+ else { OdometerResetPositionM -= Train . Length ; }
5098
5098
5099
5099
Simulator . Confirmer . Confirm ( CabControl . Odometer , OdometerCountingUp ? CabSetting . Increase : CabSetting . Decrease ) ;
5100
5100
}
0 commit comments