4545using System . Text ;
4646using Event = Orts . Common . Event ;
4747using ORTS . Scripting . Api ;
48+ using Orts . Simulation . RollingStocks . SubSystems . Brakes ;
4849
4950namespace 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
0 commit comments