2727// #define DEBUG_EXTRAINFO
2828// #define DEBUG_TRACEINFO
2929// #define DEBUG_TTANALYSIS
30+ // #define DEBUG_DELAYS
3031// DEBUG flag for debug prints
3132
3233using System;
@@ -70,6 +71,8 @@ public class TTTrain : AITrain
7071 // required direction on leaving pool (if applicable)
7172 public string ForcedConsistName = String.Empty; // forced consist name for extraction from pool
7273
74+ public string ttanalysisreport = String.Empty; // string holding last analysis report, to avoid continouos output of same string
75+
7376 // Timetable Commands info
7477 public List<WaitInfo> WaitList = null; //used when in timetable mode for wait instructions
7578 public Dictionary<int, List<WaitInfo>> WaitAnyList = null; //used when in timetable mode for waitany instructions
@@ -1239,7 +1242,7 @@ public bool PostInit(bool activateTrain)
12391242
12401243 File.AppendAllText(@"C:\temp\checktrain.txt", "--------\n");
12411244 File.AppendAllText(@"C:\temp\checktrain.txt", "PostInit at " + actTime.ToString("HH:mm:ss") + "\n");
1242- File.AppendAllText(@"C:\temp\checktrain.txt", "Train : " + Number.ToString() + "\n");
1245+ File.AppendAllText(@"C:\temp\checktrain.txt", "Train : " + Number.ToString() + " ( AI : " + OrgAINumber.ToString() + " ) \n");
12431246 File.AppendAllText(@"C:\temp\checktrain.txt", "Name : " + Name + "\n");
12441247 File.AppendAllText(@"C:\temp\checktrain.txt", "Frght : " + IsFreight.ToString() + "\n");
12451248 File.AppendAllText(@"C:\temp\checktrain.txt", "Length: " + Length.ToString() + "\n");
@@ -4037,6 +4040,11 @@ public override void UpdateStationState(float elapsedClockSeconds, int presentTi
40374040 }
40384041#endif
40394042
4043+ #if DEBUG_DELAYS
4044+ if (Delay.HasValue && Delay.Value.TotalMinutes > 5)
4045+ Trace.TraceInformation("{0} at {1} : + {2}", Name, thisStation.PlatformItem.Name, Delay.Value.ToString());
4046+ #endif
4047+
40404048 if (CheckTrain)
40414049 {
40424050 DateTime baseDTdCT = new DateTime();
@@ -8156,6 +8164,13 @@ public void FinalizeTimetableCommands()
81568164#if DEBUG_TRACEINFO
81578165 Trace.TraceInformation("Train : " + Name);
81588166 Trace.TraceInformation("WAIT : Search for : {0} - found {1}", reqWait.referencedTrainName, otherTrain == null ? -1 : otherTrain.Number);
8167+ #endif
8168+ #if DEBUG_DELAYS
8169+ if (otherTrain == null)
8170+ {
8171+ Trace.TraceInformation("Train : " + Name);
8172+ Trace.TraceInformation("WAIT : Search for : {0} - not found", reqWait.referencedTrainName);
8173+ }
81598174#endif
81608175 if (otherTrain != null)
81618176 {
@@ -8170,6 +8185,13 @@ public void FinalizeTimetableCommands()
81708185#if DEBUG_TRACEINFO
81718186 Trace.TraceInformation("Train : " + Name);
81728187 Trace.TraceInformation("FOLLOW : Search for : {0} - found {1}", reqWait.referencedTrainName, otherTrain == null ? -1 : otherTrain.Number);
8188+ #endif
8189+ #if DEBUG_DELAYS
8190+ if (otherTrain == null)
8191+ {
8192+ Trace.TraceInformation("Train : " + Name);
8193+ Trace.TraceInformation("FOLLOW : Search for : {0} - not found", reqWait.referencedTrainName);
8194+ }
81738195#endif
81748196 if (otherTrain != null)
81758197 {
@@ -8185,6 +8207,14 @@ public void FinalizeTimetableCommands()
81858207 Trace.TraceInformation("Train : " + Name);
81868208 Trace.TraceInformation("CONNECT : Search for : {0} - found {1}", reqWait.referencedTrainName, otherTrain == null ? -1 : otherTrain.Number);
81878209#endif
8210+ #if DEBUG_DELAYS
8211+ if (otherTrain == null)
8212+ {
8213+ Trace.TraceInformation("Train : " + Name);
8214+ Trace.TraceInformation("CONNECT : Search for : {0} - not found", reqWait.referencedTrainName);
8215+ }
8216+ #endif
8217+
81888218 if (otherTrain != null)
81898219 {
81908220 ProcessConnectRequest(reqWait, otherTrain, ref newWaitItems);
@@ -9593,6 +9623,7 @@ public bool CheckEndOfRoutePositionTT()
95939623 MovementState = AI_MOVEMENT_STATE.TURNTABLE;
95949624 if (CheckTrain)
95959625 {
9626+ File.AppendAllText(@"C:\temp\checktrain.txt", "TURNTABLE : Pool : " + thisTurntablePool.PoolName + " : Table state set to " + ActiveTurntable.MovingTableState.ToString() + "\n");
95969627 File.AppendAllText(@"C:\temp\checktrain.txt", "Moving table access ; Movement State : " + MovementState + "\n");
95979628 }
95989629 return (endOfRoute);
@@ -11508,6 +11539,11 @@ public int GetUnitsToDetach(DetachInfo.DetachUnitsInfo detachUnits, int numberOf
1150811539
1150911540 default:
1151011541 iunits = numberOfUnits;
11542+ if (iunits > Cars.Count - 1)
11543+ {
11544+ Trace.TraceInformation("Train {0} : no. of units to detach ({1}) : value too large, only {2} units on train\n", Name, iunits, Cars.Count);
11545+ iunits = Cars.Count - 1;
11546+ }
1151111547 frontpos = detachUnits == DetachInfo.DetachUnitsInfo.unitsAtFront;
1151211548 break;
1151311549 }
@@ -12659,12 +12695,13 @@ public void TTAnalysisUpdateStationState1(int presentTime, StationStop thisStati
1265912695 {
1266012696
1266112697 DateTime baseDTA = new DateTime();
12698+ DateTime presentDTA = baseDTA.AddSeconds(AI.clockTime);
1266212699 DateTime arrTimeA = baseDTA.AddSeconds(presentTime);
1266312700 DateTime depTimeA = baseDTA.AddSeconds(thisStation.ActualDepart);
1266412701
1266512702 var sob = new StringBuilder();
1266612703 sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}",
12667- Number, AI.clockTime , Name, Delay, thisStation.PlatformItem.Name, thisStation.arrivalDT.ToString("HH:mm:ss"), thisStation.departureDT.ToString("HH:mm:ss"),
12704+ Number, presentDTA.ToString("HH:mm:ss") , Name, Delay, thisStation.PlatformItem.Name, thisStation.arrivalDT.ToString("HH:mm:ss"), thisStation.departureDT.ToString("HH:mm:ss"),
1266812705 arrTimeA.ToString("HH:mm:ss"), depTimeA.ToString("HH:mm:ss"), "", "", "", "");
1266912706 File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
1267012707 }
@@ -12721,9 +12758,16 @@ public void TTAnalysisUpdateStationState2()
1272112758 DateTime baseDT = new DateTime();
1272212759 DateTime stopTime = baseDT.AddSeconds(AI.clockTime);
1272312760
12724- var sob = new StringBuilder();
12725- sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}", Number, AI.clockTime, Name, Delay, "", "", "", "", "", "", stopTime.ToString("HH:mm:ss"), signalstring.ToString(), waitforstring.ToString());
12726- File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
12761+ // output string only if different from last output
12762+
12763+ if (waitforstring.ToString() != ttanalysisreport)
12764+ {
12765+ ttanalysisreport = waitforstring.ToString();
12766+
12767+ var sob = new StringBuilder();
12768+ sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}", Number, stopTime.ToString("HH:mm:ss"), Name, Delay, "", "", "", "", "", "", stopTime.ToString("HH:mm:ss"), signalstring.ToString(), waitforstring.ToString());
12769+ File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
12770+ }
1272712771 }
1272812772
1272912773 public void TTAnalysisUpdateBrakingState1()
@@ -12780,9 +12824,14 @@ public void TTAnalysisUpdateBrakingState1()
1278012824 DateTime baseDT = new DateTime();
1278112825 DateTime stopTime = baseDT.AddSeconds(AI.clockTime);
1278212826
12783- var sob = new StringBuilder();
12784- sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}", Number, AI.clockTime, Name, Delay, "", "", "", "", "", "", stopTime.ToString("HH:mm:ss"), signalstring.ToString(), waitforstring.ToString());
12785- File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
12827+ if (waitforstring.ToString() != ttanalysisreport)
12828+ {
12829+ ttanalysisreport = waitforstring.ToString();
12830+
12831+ var sob = new StringBuilder();
12832+ sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}", Number, stopTime.ToString("HH:mm:ss"), Name, Delay, "", "", "", "", "", "", stopTime.ToString("HH:mm:ss"), signalstring.ToString(), waitforstring.ToString());
12833+ File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
12834+ }
1278612835 }
1278712836 }
1278812837
@@ -12846,9 +12895,14 @@ public void TTAnalysisUpdateBrakingState2()
1284612895 DateTime baseDT = new DateTime();
1284712896 DateTime stopTime = baseDT.AddSeconds(AI.clockTime);
1284812897
12849- var sob = new StringBuilder();
12850- sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}", Number, AI.clockTime, Name, Delay, "", "", "", "", "", "", stopTime.ToString("HH:mm:ss"), signalstring.ToString(), waitforstring.ToString());
12851- File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
12898+ if (waitforstring.ToString() != ttanalysisreport)
12899+ {
12900+ ttanalysisreport = waitforstring.ToString();
12901+
12902+ var sob = new StringBuilder();
12903+ sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}", Number, stopTime.ToString("HH:mm:ss"), Name, Delay, "", "", "", "", "", "", stopTime.ToString("HH:mm:ss"), signalstring.ToString(), waitforstring.ToString());
12904+ File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
12905+ }
1285212906 }
1285312907
1285412908 public void TTAnalysisStartMoving(String info)
@@ -12858,8 +12912,9 @@ public void TTAnalysisStartMoving(String info)
1285812912
1285912913 var sob = new StringBuilder();
1286012914 sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}",
12861- Number, AI.clockTime , Name, Delay, "", "", "", "", "", moveTimeA.ToString("HH:mm:ss"), "", "", info);
12915+ Number, moveTimeA.ToString("HH:mm:ss") , Name, Delay, "", "", "", "", "", moveTimeA.ToString("HH:mm:ss"), "", "", info);
1286212916 File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
12917+ ttanalysisreport = String.Empty;
1286312918 }
1286412919 }
1286512920
@@ -13310,6 +13365,13 @@ public DetachInfo(TTTrain thisTrain, TTTrainCommands commandInfo, bool atActivat
1331013365 bool portionDefined = false;
1331113366 bool formedTrainDefined = false;
1331213367
13368+ if (commandInfo.CommandQualifiers == null || commandInfo.CommandQualifiers.Count < 1)
13369+ {
13370+ Trace.TraceInformation("Train {0} : missing detach command qualifiers", thisTrain.Name);
13371+ Valid = false;
13372+ return;
13373+ }
13374+
1331313375 foreach (TTTrainCommands.TTTrainComQualifiers Qualifier in commandInfo.CommandQualifiers)
1331413376 {
1331513377 switch (Qualifier.QualifierName.Trim().ToLower())
0 commit comments