Skip to content

Commit 7ecca2d

Browse files
committed
Distributed Power: add DPU Info window, by mbm_OR
1 parent 4e4df5e commit 7ecca2d

File tree

8 files changed

+890
-9
lines changed

8 files changed

+890
-9
lines changed

Source/ORTS.Common/Input/UserCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public enum UserCommand
4343
[GetString("Display Station Labels")] DisplayStationLabels,
4444
[GetString("Display Switch Window")] DisplaySwitchWindow,
4545
[GetString("Display Train Operations Window")] DisplayTrainOperationsWindow,
46+
[GetString("Display Train Dpu Window")] DisplayTrainDpuWindow,
4647
[GetString("Display Next Station Window")] DisplayNextStationWindow,
4748
[GetString("Display Compass Window")] DisplayCompassWindow,
4849
[GetString("Display Train List Window")] DisplayTrainListWindow,

Source/ORTS.Settings/InputSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ static void InitializeCommands(UserCommandInput[] Commands)
483483
Commands[(int)UserCommand.DisplaySwitchWindow] = new UserCommandKeyInput(0x42);
484484
Commands[(int)UserCommand.DisplayTrackMonitorWindow] = new UserCommandModifiableKeyInput(0x3E, Commands[(int)UserCommand.DisplayNextWindowTab]);
485485
Commands[(int)UserCommand.DisplayTrainOperationsWindow] = new UserCommandKeyInput(0x43);
486+
Commands[(int)UserCommand.DisplayTrainDpuWindow] = new UserCommandKeyInput(0x43, KeyModifiers.Shift);
486487

487488
Commands[(int)UserCommand.GameAutopilotMode] = new UserCommandKeyInput(0x1E, KeyModifiers.Alt);
488489
Commands[(int)UserCommand.GameChangeCab] = new UserCommandKeyInput(0x12, KeyModifiers.Control);

Source/ORTS.Settings/UserSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ public enum DirectXFeature
425425
[Default(new[] { 50, 50 })]
426426
public int[] WindowPosition_TrainOperations { get; set; }
427427
[Default(new[] { 50, 50 })]
428+
public int[] WindowPosition_TrainDpu { get; set; }
429+
[Default(new[] { 50, 50 })]
428430
public int[] WindowPosition_CarOperations { get; set; }
429431
[Default(new[] { 50, 50 })]
430432
public int[] WindowPosition_ComposeMessage { get; set; }

Source/Orts.Simulation/Simulation/RollingStocks/MSTSDieselLocomotive.cs

Lines changed: 134 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
using System.Text;
4646
using Event = Orts.Common.Event;
4747
using ORTS.Scripting.Api;
48+
using Orts.Simulation.RollingStocks.SubSystems.Brakes;
4849

4950
namespace Orts.Simulation.RollingStocks
5051
{
@@ -878,8 +879,6 @@ public override string GetDebugStatus()
878879
Simulator.Catalog.GetString("NetHt"),
879880
Train.LastCar.CarNetHeatFlowRateW);
880881
}
881-
882-
883882
return status.ToString();
884883
}
885884

@@ -897,14 +896,14 @@ public string GetDPDebugStatus()
897896
{
898897
if (RemoteControlGroup == 1)
899898
{
900-
throttle = Simulator.Catalog.GetParticularString("Notch", "B") + MathHelper.Clamp((Train.LeadLocomotive as MSTSLocomotive).DPDynamicBrakeController.CurrentNotch, 1, 8);
899+
throttle = Simulator.Catalog.GetParticularString("Notch", "B") + MathHelper.Clamp((Train.LeadLocomotive as MSTSLocomotive).DPDynamicBrakeController.CurrentNotch, 1, 8);
901900
}
902901
else
903902
{
904903
// The clause here below leads to possible differences of one notch near the notch value, and therefore is commented
905-
// if (DynamicBrakeController.NotchCount() > 3)
906-
// throttle = Simulator.Catalog.GetParticularString("Notch", "B") + MathHelper.Clamp((DynamicBrakeController.GetNearestNotch(DynamicBrakePercent / 100f)), 1, 8);
907-
// else
904+
// if (DynamicBrakeController.NotchCount() > 3)
905+
// throttle = Simulator.Catalog.GetParticularString("Notch", "B") + MathHelper.Clamp((DynamicBrakeController.GetNearestNotch(DynamicBrakePercent / 100f)), 1, 8);
906+
// else
908907
throttle = Simulator.Catalog.GetParticularString("Notch", "B") + MathHelper.Clamp((Train.LeadLocomotive as MSTSLocomotive).DPDynamicBrakeController.GetNotch(DynamicBrakePercent / 100f), 1, 8);
909908
}
910909
}
@@ -928,13 +927,99 @@ public string GetDPDebugStatus()
928927
return status.ToString();
929928
}
930929

930+
public string GetDpuStatus(bool dataDpu)// used by the TrainDpuInfo window
931+
{
932+
string throttle = "";
933+
if (ThrottlePercent > 0)
934+
{
935+
if (ThrottleController.NotchCount() > 3)
936+
throttle = Simulator.Catalog.GetParticularString("Notch", "N") + MathHelper.Clamp(ThrottleController.GetNearestNotch(ThrottlePercent / 100f), 1, 8);
937+
else
938+
throttle = string.Format("{0:F0}%", ThrottlePercent);
939+
}
940+
else if (DynamicBrakePercent > 0 && DynamicBrake)
941+
{
942+
if (RemoteControlGroup == 1)
943+
{
944+
throttle = Simulator.Catalog.GetParticularString("Notch", "B") + MathHelper.Clamp((Train.LeadLocomotive as MSTSLocomotive).DPDynamicBrakeController.CurrentNotch, 1, 8);
945+
}
946+
else
947+
{
948+
// The clause here below leads to possible differences of one notch near the notch value, and therefore is commented
949+
// if (DynamicBrakeController.NotchCount() > 3)
950+
// throttle = Simulator.Catalog.GetParticularString("Notch", "B") + MathHelper.Clamp((DynamicBrakeController.GetNearestNotch(DynamicBrakePercent / 100f)), 1, 8);
951+
// else
952+
throttle = Simulator.Catalog.GetParticularString("Notch", "B") + MathHelper.Clamp((Train.LeadLocomotive as MSTSLocomotive).DPDynamicBrakeController.GetNotch(DynamicBrakePercent / 100f), 1, 8);
953+
}
954+
}
955+
else if (DynamicBrakePercent == 0 && !DynamicBrake)
956+
throttle = Simulator.Catalog.GetString("Setup");
957+
else
958+
throttle = Simulator.Catalog.GetParticularString("Notch", "Idle");
959+
if (DynamicBrakePercent >= 0)
960+
throttle += "???";
961+
962+
var status = new StringBuilder();
963+
// ID
964+
status.AppendFormat("{0}({1})\t", CarID, DPUnitID);
965+
// Throttle
966+
status.AppendFormat("{0}\t", throttle);
967+
// Load
968+
foreach (var eng in DieselEngines.DEList)
969+
status.AppendFormat("{0:F1}%\t", eng.LoadPercent);
970+
// BP
971+
var brakeInfoValue = brakeValue(Simulator.Catalog.GetString("BP"), Simulator.Catalog.GetString("EOT"));
972+
status.AppendFormat("{0:F0}\t", brakeInfoValue);
973+
974+
// Flow
975+
foreach (var eng in DieselEngines.DEList)
976+
status.AppendFormat("{0}/{1}\t", FormatStrings.FormatFuelVolume(pS.TopH(eng.DieselFlowLps), Simulator.PlayerLocomotive.IsMetric, Simulator.PlayerLocomotive.IsUK), FormatStrings.h);
977+
// Remote
978+
if (dataDpu)
979+
{
980+
status.AppendFormat("{0}\t", IsLeadLocomotive() || RemoteControlGroup < 0 ? "———" : RemoteControlGroup == 0 ? Simulator.Catalog.GetString("Sync") : Simulator.Catalog.GetString("Async"));
981+
}
982+
else
983+
{
984+
status.AppendFormat("{0}", IsLeadLocomotive() || RemoteControlGroup < 0 ? "———" : RemoteControlGroup == 0 ? Simulator.Catalog.GetString("Sync") : Simulator.Catalog.GetString("Async"));
985+
}
986+
987+
if (dataDpu)
988+
{ // ER
989+
brakeInfoValue = brakeValue(Simulator.Catalog.GetString("EQ"), Simulator.Catalog.GetString("BC"));
990+
status.AppendFormat("{0:F0}\t", brakeInfoValue);
991+
992+
// BC
993+
brakeInfoValue = brakeValue(Simulator.Catalog.GetString("BC"), Simulator.Catalog.GetString("BP"));
994+
status.AppendFormat("{0:F0}\t", brakeInfoValue);
995+
996+
// MR
997+
status.AppendFormat("{0:F0}", FormatStrings.FormatPressure((Simulator.PlayerLocomotive as MSTSLocomotive).MainResPressurePSI, PressureUnit.PSI, (Simulator.PlayerLocomotive as MSTSLocomotive).BrakeSystemPressureUnits[BrakeSystemComponent.MainReservoir], true));
998+
}
999+
return status.ToString();
1000+
}
1001+
1002+
string brakeValue(string tokenIni, string tokenEnd) // used by GetDpuStatus(bool dataHud)
1003+
{
1004+
string trainBrakeStatus = Simulator.PlayerLocomotive.GetTrainBrakeStatus();
1005+
var brakeInfoValue = "-";
1006+
if (trainBrakeStatus.Contains(tokenIni) && trainBrakeStatus.Contains(tokenEnd))
1007+
{
1008+
var indexIni = trainBrakeStatus.IndexOf(tokenIni) + tokenIni.Length + 1;
1009+
var indexEnd = trainBrakeStatus.IndexOf(tokenEnd) - indexIni;
1010+
brakeInfoValue = trainBrakeStatus.Substring(indexIni, indexEnd).TrimEnd();
1011+
}
1012+
return brakeInfoValue;
1013+
}
1014+
9311015
public override string GetMultipleUnitsConfiguration()
9321016
{
9331017
if (Train == null)
9341018
return base.GetMultipleUnitsConfiguration();
9351019
var numberOfLocomotives = 0;
9361020
var group = 0;
9371021
var configuration = "";
1022+
9381023
var dpUnitId = 0;
9391024
var remoteControlGroup = 0;
9401025
for (var i = 0; i < Train.Cars.Count; i++)
@@ -960,24 +1045,51 @@ public override string GetMultipleUnitsConfiguration()
9601045

9611046
private static string[] DebugLabels;
9621047
private static int MaxNumberOfEngines;
1048+
private static string[] DpuLabels;
1049+
private static string[] DPULabels;
9631050

9641051
private static void SetDebugLabels(int numberOfEngines)
9651052
{
9661053
MaxNumberOfEngines = numberOfEngines;
9671054
var labels = new StringBuilder();
9681055
labels.AppendFormat("{0}\t", Simulator.Catalog.GetString("ID"));
1056+
labels.AppendFormat("{0}\t", Simulator.Catalog.GetString("Throttle"));
9691057
labels.AppendFormat("{0}\t", Simulator.Catalog.GetParticularString("NonSteam", "Reverser"));
9701058
labels.AppendFormat("{0}\t", Simulator.Catalog.GetString("Remote"));
971-
labels.AppendFormat("{0}\t", Simulator.Catalog.GetString("Throttle"));
9721059
labels.AppendFormat("{0}\t", Simulator.Catalog.GetString("Fuel"));
9731060
labels.AppendFormat("{0}\t", Simulator.Catalog.GetString("Tractive Effort"));
9741061
labels.Append(DieselEngines.SetDebugLabels(numberOfEngines));
9751062
DebugLabels = labels.ToString().Split('\t');
9761063
}
9771064

1065+
private static void SetDPULabels(bool dpuFull, int numberOfEngines)
1066+
{
1067+
MaxNumberOfEngines = numberOfEngines;
1068+
var labels = new StringBuilder();
1069+
labels.AppendFormat("{0}\t", Simulator.Catalog.GetString("ID"));
1070+
labels.AppendFormat("{0}\t", Simulator.Catalog.GetString("Throttle"));
1071+
labels.AppendFormat("{0}\t", Simulator.Catalog.GetString("Load"));
1072+
labels.AppendFormat("{0}\t", Simulator.Catalog.GetString("BP"));
1073+
labels.AppendFormat("{0}\t", Simulator.Catalog.GetString("Flow"));
1074+
if (!dpuFull)
1075+
{
1076+
labels.AppendFormat("{0}", Simulator.Catalog.GetString("Remote"));
1077+
DpuLabels = labels.ToString().Split('\t');
1078+
}
1079+
1080+
if (dpuFull)
1081+
{
1082+
labels.AppendFormat("{0}\t", Simulator.Catalog.GetString("Remote"));
1083+
labels.AppendFormat("{0}\t", Simulator.Catalog.GetString("ER"));
1084+
labels.AppendFormat("{0}\t", Simulator.Catalog.GetString("BC"));
1085+
labels.AppendFormat("{0}", Simulator.Catalog.GetString("MR"));
1086+
DPULabels = labels.ToString().Split('\t');
1087+
}
1088+
}
1089+
9781090
public static string GetDebugTableBase(int locomotivesInTrain, int maxNumberOfEngines)
9791091
{
980-
if (MaxNumberOfEngines != maxNumberOfEngines)
1092+
if (MaxNumberOfEngines != maxNumberOfEngines || DebugLabels == null)
9811093
SetDebugLabels(maxNumberOfEngines);
9821094
string table = "";
9831095
for (var i = 0; i < DebugLabels.Length; i++)
@@ -987,6 +1099,20 @@ public static string GetDebugTableBase(int locomotivesInTrain, int maxNumberOfEn
9871099
table += "\t\t";
9881100
table += "\n";
9891101
}
1102+
return table;
1103+
}
1104+
1105+
public static string GetDpuHeader(bool dpuVerticalFull, int locomotivesInTrain, int dpuMaxNumberOfEngines)
1106+
{
1107+
if (MaxNumberOfEngines != dpuMaxNumberOfEngines || dpuVerticalFull? DPULabels == null : DpuLabels == null)
1108+
SetDPULabels(dpuVerticalFull , dpuMaxNumberOfEngines);
1109+
string table = "";
1110+
for (var i = 0; i < (dpuVerticalFull ? DPULabels.Length : DpuLabels.Length); i++)
1111+
{
1112+
table += dpuVerticalFull ? DPULabels[i] : DpuLabels[i];
1113+
table += "\n";
1114+
}
1115+
table = table.TrimEnd('\n');
9901116
return table;
9911117
}
9921118

Source/RunActivity/RunActivity.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
<Compile Include="Viewer3D\Popups\SwitchWindow.cs" />
145145
<Compile Include="Viewer3D\Popups\TrackMonitorWindow.cs" />
146146
<Compile Include="Viewer3D\Popups\TracksDebugWindow.cs" />
147+
<Compile Include="Viewer3D\Popups\TrainDPUWindow.cs" />
147148
<Compile Include="Viewer3D\Popups\TrainDrivingWindow.cs" />
148149
<Compile Include="Viewer3D\Popups\TrainListWindow.cs" />
149150
<Compile Include="Viewer3D\Popups\TrainOperationsWindow.cs" />

0 commit comments

Comments
 (0)