Skip to content

Commit

Permalink
Add option to set custom unit scaling to cabview controls, also fix a…
Browse files Browse the repository at this point in the history
… bug preventing dynamic brakes from displaying on locos with cruise control
  • Loading branch information
SteelFill committed May 1, 2024
1 parent b80dd8d commit 6c8095a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Source/Documentation/Manual/cabs.rst
Expand Up @@ -785,6 +785,26 @@ can be customized with following line, to be added within the control block in t
.cvf file::

ORTSLabel ( "string" )

Custom Display Units
--------------------

Due to the wide variety of railroad equipment across the world, Open Rails may not
provide the units of measure needed for a cabview control. In this case, the tokens
`ORTSUnitsScaleFactor` and `ORTSUnitsOffset` can be added to the control block in
the .cvf file to create the units of measure required for the cab view.

- ORTSUnitsScaleFactor ( x ): Multiplies the value shown by the cab view control
by a factor of x, allowing for arbitrary conversion of units of measure. For
example, a cab view control displaying MILES_PER_HOUR with ORTSUnitsScaleFactor ( 1.467 )
would instead display a value equivalent to feet per second.
- ORTSUnitsOffset ( x ): After applying the scale factor, adds x to the value shown
by the cab view control. To subtract from the shown value, set x to a negative number.
For example, a cab view control with units of BAR and ORTSUnitsOffset ( 0.987 ) would show
pressure as absolute pressure, rather than gauge pressure.

Note that while these tokens can be used to convert between many units, it is recommended
to use built in Open Rails units wherever suitable.

Multiple screen pages on displays
---------------------------------
Expand Down
17 changes: 17 additions & 0 deletions Source/Orts.Formats.Msts/CabViewFile.cs
Expand Up @@ -470,6 +470,9 @@ public class CabViewControl
public CABViewControlStyles ControlStyle = CABViewControlStyles.NONE;
public CABViewControlUnits Units = CABViewControlUnits.NONE;

public float UnitsScale = 1.0f;
public float UnitsOffset;

public bool DisabledIfLowVoltagePowerSupplyOff { get; private set; } = false;
public bool DisabledIfCabPowerSupplyOff { get; private set; } = false;
public bool HideIfDisabled { get; private set; } = true;
Expand Down Expand Up @@ -687,6 +690,8 @@ public CVCDial(STFReader stf, string basepath)
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
});
}
}
Expand Down Expand Up @@ -783,6 +788,8 @@ public CVCGauge(STFReader stf, string basepath)
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
});
}
}
Expand Down Expand Up @@ -925,6 +932,8 @@ public CVCDigital(STFReader stf, string basepath)
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
});
}

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

// If no ACE, just don't need any fixup
Expand Down Expand Up @@ -1427,6 +1438,8 @@ public CVCMultiStateDisplay(STFReader stf, string basepath)
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
});
}
protected int ParseNumStyle(STFReader stf)
Expand Down Expand Up @@ -1477,6 +1490,8 @@ public CVCAnimatedDisplay(STFReader stf, string basepath)
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
});
}
protected int ParseNumStyle(STFReader stf)
Expand Down Expand Up @@ -1518,6 +1533,8 @@ public CVCScreen(STFReader stf, string basepath)
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
});
}
protected void ParseCustomParameters(STFReader stf)
Expand Down
Expand Up @@ -6133,6 +6133,9 @@ public virtual float GetDataOf(CabViewControl cvc)
data = Train.EOT.GetDataOf(cvc);
break;
}

data = cvc.UnitsOffset + (data * cvc.UnitsScale);

return data;
}

Expand Down
Expand Up @@ -2147,7 +2147,7 @@ public virtual int GetDrawIndex()
{
if (Locomotive.CruiseControl != null)
{
if ((Locomotive.CruiseControl.SpeedRegMode == Simulation.RollingStocks.SubSystems.CruiseControl.SpeedRegulatorMode.Auto && !Locomotive.CruiseControl.DynamicBrakePriority) || Locomotive.DynamicBrakeIntervention > 0)
if (Locomotive.CruiseControl.SpeedRegMode == Simulation.RollingStocks.SubSystems.CruiseControl.SpeedRegulatorMode.Auto && !Locomotive.CruiseControl.DynamicBrakePriority)
{
index = 0;
}
Expand Down

0 comments on commit 6c8095a

Please sign in to comment.