Skip to content

Commit 35493ca

Browse files
committed
2025-01-17 A
1 parent 3132cc2 commit 35493ca

File tree

5 files changed

+185
-59
lines changed

5 files changed

+185
-59
lines changed

Source/Orts.Simulation/Simulation/AIs/AITrain.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,10 @@ public virtual void UpdateStationState(float elapsedClockSeconds, int presentTim
19921992

19931993
// Depart
19941994
thisStation.Passed = true;
1995-
Delay = TimeSpan.FromSeconds((presentTime - thisStation.DepartTime) % (24 * 3600));
1995+
if (thisStation.ArrivalTime >= 0)
1996+
{
1997+
Delay = TimeSpan.FromSeconds((presentTime - thisStation.DepartTime) % (24 * 3600));
1998+
}
19961999
PreviousStop = thisStation.CreateCopy();
19972000

19982001
if (thisStation.ActualStopType == StationStop.STOPTYPE.STATION_STOP
@@ -2059,7 +2062,10 @@ public virtual void UpdateStationState(float elapsedClockSeconds, int presentTim
20592062
if (TrainType != TRAINTYPE.AI_PLAYERHOSTING) AtStation = false;
20602063
}
20612064

2062-
Delay = TimeSpan.FromSeconds((presentTime - thisStation.DepartTime) % (24 * 3600));
2065+
if (thisStation.ArrivalTime >= 0)
2066+
{
2067+
Delay = TimeSpan.FromSeconds((presentTime - thisStation.DepartTime) % (24 * 3600));
2068+
}
20632069
}
20642070

20652071
#if DEBUG_REPORTS

Source/Orts.Simulation/Simulation/Physics/Train.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20788,7 +20788,7 @@ public enum STOPTYPE
2078820788

2078920789
public StationStop(int platformReference, PlatformDetails platformItem, int subrouteIndex, int routeIndex,
2079020790
int tcSectionIndex, int direction, int exitSignal, bool holdSignal, bool noWaitSignal, bool noClaimAllowed, float stopOffset,
20791-
int arrivalTime, int departTime, bool terminal, int? actualMinStopTime, float? keepClearFront, float? keepClearRear,
20791+
int? arrivalTime, int? departTime, bool terminal, int? actualMinStopTime, float? keepClearFront, float? keepClearRear,
2079220792
bool forcePosition, bool closeupSignal, bool closeup,
2079320793
bool restrictPlatformToSignal, bool extendPlatformToSignal, bool endStop, bool allowdepartearly, STOPTYPE actualStopType)
2079420794
{
@@ -20806,14 +20806,21 @@ public StationStop(int platformReference, PlatformDetails platformItem, int subr
2080620806
StopOffset = stopOffset;
2080720807
if (actualStopType == STOPTYPE.STATION_STOP)
2080820808
{
20809-
ArrivalTime = Math.Max(0, arrivalTime);
20810-
DepartTime = Math.Max(0, departTime);
20809+
if (arrivalTime.HasValue)
20810+
{
20811+
ArrivalTime = Math.Max(0, arrivalTime.Value);
20812+
DepartTime = Math.Max(0, departTime.Value);
20813+
}
20814+
else
20815+
{
20816+
ArrivalTime = DepartTime = -1;
20817+
}
2081120818
}
2081220819
else
2081320820
// times may be <0 for waiting point
2081420821
{
20815-
ArrivalTime = arrivalTime;
20816-
DepartTime = departTime;
20822+
ArrivalTime = arrivalTime.Value;
20823+
DepartTime = departTime.Value;
2081720824
}
2081820825
ActualArrival = -1;
2081920826
ActualDepart = -1;
@@ -21110,7 +21117,8 @@ public int CalculateDepartTime(int presentTime, Train stoppedTrain)
2111021117
int stopTime = 0;
2111121118

2111221119
// allow to depart early if set (timetable mode only, so no need to check for valid schedule)
21113-
if (AllowDepartEarly)
21120+
// also allow to depart after boarding time if arrival time is not set
21121+
if (AllowDepartEarly || ArrivalTime < 0)
2111421122
{
2111521123
stoppedTrain.ComputeTrainBoardingTime(this, ref stopTime);
2111621124
ActualDepart = ActualArrival + stopTime;

Source/Orts.Simulation/Simulation/Timetables/ProcessTimetable.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,7 +2462,7 @@ public StopInfo ProcessStopInfo(string stationInfo, StationInfo stationDetails)
24622462
{
24632463
int commandseparator = stationInfo.IndexOf('$');
24642464
fullCommandString = stationInfo.Substring(commandseparator + 1);
2465-
stationInfo = stationInfo.Substring(0, commandseparator);
2465+
stationInfo = stationInfo.Substring(0, commandseparator).Trim();
24662466
}
24672467

24682468
if (!String.IsNullOrEmpty(stationInfo))
@@ -3166,11 +3166,11 @@ public enum SignalHoldType
31663166
}
31673167

31683168
public string StopName;
3169-
public int arrivalTime;
3170-
public int departureTime;
3169+
public int? arrivalTime;
3170+
public int? departureTime;
31713171
public int passTime;
3172-
public DateTime arrivalDT;
3173-
public DateTime departureDT;
3172+
public DateTime? arrivalDT;
3173+
public DateTime? departureDT;
31743174
public DateTime passDT;
31753175
public bool arrdeppassvalid;
31763176
public bool allowDepartEarly;
@@ -3208,7 +3208,24 @@ public StopInfo(string name, string arrTime, string depTime, TimetableInfo ttinf
32083208
bool validDepTime = false;
32093209
bool validPassTime = false;
32103210

3211-
if (arrTime.Contains("P"))
3211+
if (arrTime.Length == 1)
3212+
{
3213+
if (arrTime == "*")
3214+
{
3215+
allowDepartEarly = true;
3216+
validArrTime = true;
3217+
departureTime = arrivalTime = null;
3218+
departureDT = arrivalDT = null;
3219+
}
3220+
else if (arrTime == "x")
3221+
{
3222+
reqStop = true;
3223+
allowDepartEarly = true;
3224+
validArrTime = true;
3225+
departureTime = arrivalTime = null;
3226+
}
3227+
}
3228+
else if (arrTime.Contains("P"))
32123229
{
32133230
string passingTime = arrTime.Replace('P', ':');
32143231
validPassTime = TimeSpan.TryParse(passingTime, out atime);
@@ -3471,10 +3488,10 @@ public bool BuildStopInfo(TTTrain actTrain, int actPlatformID, Signals signalRef
34713488
string infoString = String.Concat("Train : ", actTrain.Name, " , at Station : ",
34723489
actTrain.StationStops[actTrain.StationStops.Count - 1].PlatformItem.Name);
34733490
actTrain.StationStops[actTrain.StationStops.Count - 1].ReqStopDetails.ProcessCommands(thisCommand.CommandQualifiers, infoString);
3474-
actTrain.StationStops[actTrain.StationStops.Count - 1].ReqStopDetails.SetStopDetails(actTrain.Name, actTrain.StationStops[actTrain.StationStops.Count - 1].PlatformItem.Name);
34753491
continue;
34763492
}
34773493
}
3494+
actTrain.StationStops[actTrain.StationStops.Count - 1].ReqStopDetails.SetStopDetails(actTrain.Name, actTrain.StationStops[actTrain.StationStops.Count - 1].PlatformItem.Name);
34783495
}
34793496

34803497
// Check holdsignal list

Source/Orts.Simulation/Simulation/Timetables/TTTrain.cs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
// #define DEBUG_TRACEINFO
2929
// #define DEBUG_TTANALYSIS
3030
// #define DEBUG_DELAYS
31+
#define DEBUG_RQS
3132
// DEBUG flag for debug prints
3233

3334
using System;
@@ -1328,7 +1329,7 @@ public override bool PostInit()
13281329
/// <summary>
13291330
/// Calculate actual station stop details
13301331
/// <\summary>
1331-
public StationStop CalculateStationStop(int platformStartID, int arrivalTime, int departTime, DateTime arrivalDT, DateTime departureDT, float clearingDistanceM,
1332+
public StationStop CalculateStationStop(int platformStartID, int? arrivalTime, int? departTime, DateTime? arrivalDT, DateTime? departureDT, float clearingDistanceM,
13321333
float minStopDistance, bool terminal, int? actMinStopTime, float? keepClearFront, float? keepClearRear, bool forcePosition, bool closeupSignal,
13331334
bool closeup, bool restrictPlatformToSignal, bool extendPlatformToSignal, bool endStop, bool allowdepartearly)
13341335
{
@@ -1409,11 +1410,13 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in
14091410
extendPlatformToSignal,
14101411
endStop,
14111412
allowdepartearly,
1412-
StationStop.STOPTYPE.STATION_STOP)
1413+
StationStop.STOPTYPE.STATION_STOP);
1414+
1415+
if (arrivalDT.HasValue)
14131416
{
1414-
arrivalDT = arrivalDT,
1415-
departureDT = departureDT
1416-
};
1417+
thisStation.arrivalDT = arrivalDT.Value;
1418+
thisStation.departureDT = departureDT.Value;
1419+
}
14171420

14181421
return thisStation;
14191422
}
@@ -2000,7 +2003,7 @@ public StationStop CalculateStationStopPosition(TCSubpathRoute thisRoute, int ro
20002003
/// <param name="forcePosition"></param>
20012004
/// <param name="endStop"></param>
20022005
/// <returns></returns>
2003-
public bool CreateStationStop(int platformStartID, int arrivalTime, int departTime, DateTime arrivalDT, DateTime departureDT, float clearingDistanceM,
2006+
public bool CreateStationStop(int platformStartID, int? arrivalTime, int? departTime, DateTime? arrivalDT, DateTime? departureDT, float clearingDistanceM,
20042007
float minStopDistanceM, bool terminal, int? actMinStopTime, float? keepClearFront, float? keepClearRear, bool forcePosition, bool closeupSignal,
20052008
bool closeup, bool restrictPlatformToSignal, bool extendPlatformToSignal, bool endStop, bool allowdepartearly)
20062009
{
@@ -2766,7 +2769,7 @@ public void UpdateMinimalDelay()
27662769

27672770
if (StationStops != null && StationStops.Count > 0 && !AtStation)
27682771
{
2769-
if (presentTime > StationStops[0].ArrivalTime)
2772+
if (StationStops[0].ArrivalTime >= 0 && presentTime > StationStops[0].ArrivalTime)
27702773
{
27712774
TimeSpan tempDelay = TimeSpan.FromSeconds((presentTime - StationStops[0].ArrivalTime) % (24 * 3600));
27722775
// Skip when delay exceeds 12 hours - that's due to passing midnight
@@ -3976,7 +3979,7 @@ public override void UpdateStationState(float elapsedClockSeconds, int presentTi
39763979
}
39773980
}
39783981

3979-
if (thisStation.ActualStopType == StationStop.STOPTYPE.STATION_STOP)
3982+
if (thisStation.ActualStopType == StationStop.STOPTYPE.STATION_STOP && thisStation.ArrivalTime >= 0)
39803983
{
39813984
Delay = TimeSpan.FromSeconds((presentTime - thisStation.DepartTime) % (24 * 3600));
39823985
}
@@ -10225,7 +10228,10 @@ public override void CheckStationTask()
1022510228
AtStation = false;
1022610229
MayDepart = false;
1022710230
DisplayMessage = "";
10228-
Delay = TimeSpan.FromSeconds((presentTime - StationStops[0].DepartTime) % (24 * 3600));
10231+
if (StationStops[0].ArrivalTime >= 0)
10232+
{
10233+
Delay = TimeSpan.FromSeconds((presentTime - StationStops[0].DepartTime) % (24 * 3600));
10234+
}
1022910235

1023010236
// Check for activation of other train
1023110237
ActivateTriggeredTrain(TriggerActivationType.StationDepart, StationStops[0].PlatformReference);
@@ -12680,10 +12686,17 @@ public void TTAnalysisUpdateStationState1(int presentTime, StationStop thisStati
1268012686
DateTime presentDTA = baseDTA.AddSeconds(AI.clockTime);
1268112687
DateTime arrTimeA = baseDTA.AddSeconds(presentTime);
1268212688
DateTime depTimeA = baseDTA.AddSeconds(thisStation.ActualDepart);
12689+
string arrstring = "--:--:--";
12690+
string depstring = "--:--:--";
12691+
if (thisStation.ArrivalTime >= 0)
12692+
{
12693+
arrstring = thisStation.arrivalDT.ToString("HH:mm:ss");
12694+
depstring = thisStation.departureDT.ToString("HH:mm:ss");
12695+
}
1268312696

1268412697
var sob = new StringBuilder();
1268512698
sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}",
12686-
Number, presentDTA.ToString("HH:mm:ss"), Name, Delay, thisStation.PlatformItem.Name, thisStation.arrivalDT.ToString("HH:mm:ss"), thisStation.departureDT.ToString("HH:mm:ss"),
12699+
Number, presentDTA.ToString("HH:mm:ss"), Name, Delay, thisStation.PlatformItem.Name, arrstring, depstring,
1268712700
arrTimeA.ToString("HH:mm:ss"), depTimeA.ToString("HH:mm:ss"), "", "", "", "");
1268812701
File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
1268912702
}
@@ -15574,20 +15587,20 @@ public void SetStopDetails(string trainName, string stationName)
1557415587
{
1557515588
probvalue = Simulator.Random.Next(100);
1557615589
pickupSet = probvalue <= probPickUp;
15577-
#if DEBUG_REPORTS
15578-
File.AppendAllText(@"C:\temp\printproc.txt", "Train " + trainName +
15590+
#if DEBUG_RQS
15591+
Trace.TraceInformation("Train " + trainName +
1557915592
" : request stop at " + stationName + " : pickup : probability : " + probPickUp + " ; number : " + probvalue +
15580-
" set : " + pickupSet + "\n");
15593+
" set : " + pickupSet);
1558115594
#endif
1558215595
}
1558315596
if (probSetDown > 0)
1558415597
{
1558515598
probvalue = Simulator.Random.Next(100);
1558615599
setdownSet = probvalue <= probSetDown;
15587-
#if DEBUG_REPORTS
15588-
File.AppendAllText(@"C:\temp\printproc.txt", "Train " + trainName +
15600+
#if DEBUG_RQS
15601+
Trace.TraceInformation("Train " + trainName +
1558915602
" : request stop at " + stationName + " : setdown : probability : " + probSetDown + " ; number : " + probvalue +
15590-
" set : " + setdownSet + "\n");
15603+
" set : " + setdownSet);
1559115604
#endif
1559215605
}
1559315606
}

0 commit comments

Comments
 (0)