Skip to content

Commit 6c8095a

Browse files
committed
Add option to set custom unit scaling to cabview controls, also fix a bug preventing dynamic brakes from displaying on locos with cruise control
1 parent b80dd8d commit 6c8095a

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

Source/Documentation/Manual/cabs.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,26 @@ can be customized with following line, to be added within the control block in t
785785
.cvf file::
786786

787787
ORTSLabel ( "string" )
788+
789+
Custom Display Units
790+
--------------------
791+
792+
Due to the wide variety of railroad equipment across the world, Open Rails may not
793+
provide the units of measure needed for a cabview control. In this case, the tokens
794+
`ORTSUnitsScaleFactor` and `ORTSUnitsOffset` can be added to the control block in
795+
the .cvf file to create the units of measure required for the cab view.
796+
797+
- ORTSUnitsScaleFactor ( x ): Multiplies the value shown by the cab view control
798+
by a factor of x, allowing for arbitrary conversion of units of measure. For
799+
example, a cab view control displaying MILES_PER_HOUR with ORTSUnitsScaleFactor ( 1.467 )
800+
would instead display a value equivalent to feet per second.
801+
- ORTSUnitsOffset ( x ): After applying the scale factor, adds x to the value shown
802+
by the cab view control. To subtract from the shown value, set x to a negative number.
803+
For example, a cab view control with units of BAR and ORTSUnitsOffset ( 0.987 ) would show
804+
pressure as absolute pressure, rather than gauge pressure.
805+
806+
Note that while these tokens can be used to convert between many units, it is recommended
807+
to use built in Open Rails units wherever suitable.
788808

789809
Multiple screen pages on displays
790810
---------------------------------

Source/Orts.Formats.Msts/CabViewFile.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,9 @@ public class CabViewControl
470470
public CABViewControlStyles ControlStyle = CABViewControlStyles.NONE;
471471
public CABViewControlUnits Units = CABViewControlUnits.NONE;
472472

473+
public float UnitsScale = 1.0f;
474+
public float UnitsOffset;
475+
473476
public bool DisabledIfLowVoltagePowerSupplyOff { get; private set; } = false;
474477
public bool DisabledIfCabPowerSupplyOff { get; private set; } = false;
475478
public bool HideIfDisabled { get; private set; } = true;
@@ -687,6 +690,8 @@ public CVCDial(STFReader stf, string basepath)
687690
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
688691
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
689692
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
693+
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
694+
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
690695
});
691696
}
692697
}
@@ -783,6 +788,8 @@ public CVCGauge(STFReader stf, string basepath)
783788
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
784789
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
785790
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
791+
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
792+
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
786793
});
787794
}
788795
}
@@ -925,6 +932,8 @@ public CVCDigital(STFReader stf, string basepath)
925932
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
926933
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
927934
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
935+
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
936+
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
928937
});
929938
}
930939

@@ -1181,6 +1190,8 @@ public CVCDiscrete(STFReader stf, string basepath, DiscreteStates discreteState)
11811190
new STFReader.TokenProcessor("ortsnewscreenpage", () => {ParseNewScreen(stf); }),
11821191
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
11831192
new STFReader.TokenProcessor("ortsparameter1", ()=>{ Parameter1 = stf.ReadFloatBlock(STFReader.UNITS.Any, 0); }),
1193+
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
1194+
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
11841195
});
11851196

11861197
// If no ACE, just don't need any fixup
@@ -1427,6 +1438,8 @@ public CVCMultiStateDisplay(STFReader stf, string basepath)
14271438
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
14281439
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
14291440
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
1441+
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
1442+
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
14301443
});
14311444
}
14321445
protected int ParseNumStyle(STFReader stf)
@@ -1477,6 +1490,8 @@ public CVCAnimatedDisplay(STFReader stf, string basepath)
14771490
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
14781491
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
14791492
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
1493+
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
1494+
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
14801495
});
14811496
}
14821497
protected int ParseNumStyle(STFReader stf)
@@ -1518,6 +1533,8 @@ public CVCScreen(STFReader stf, string basepath)
15181533
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
15191534
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
15201535
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
1536+
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
1537+
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
15211538
});
15221539
}
15231540
protected void ParseCustomParameters(STFReader stf)

Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6133,6 +6133,9 @@ public virtual float GetDataOf(CabViewControl cvc)
61336133
data = Train.EOT.GetDataOf(cvc);
61346134
break;
61356135
}
6136+
6137+
data = cvc.UnitsOffset + (data * cvc.UnitsScale);
6138+
61366139
return data;
61376140
}
61386141

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,7 @@ public virtual int GetDrawIndex()
21472147
{
21482148
if (Locomotive.CruiseControl != null)
21492149
{
2150-
if ((Locomotive.CruiseControl.SpeedRegMode == Simulation.RollingStocks.SubSystems.CruiseControl.SpeedRegulatorMode.Auto && !Locomotive.CruiseControl.DynamicBrakePriority) || Locomotive.DynamicBrakeIntervention > 0)
2150+
if (Locomotive.CruiseControl.SpeedRegMode == Simulation.RollingStocks.SubSystems.CruiseControl.SpeedRegulatorMode.Auto && !Locomotive.CruiseControl.DynamicBrakePriority)
21512151
{
21522152
index = 0;
21532153
}

0 commit comments

Comments
 (0)