Skip to content

Commit 4520170

Browse files
committed
Include Passing Time
1 parent 6cfcfe9 commit 4520170

File tree

4 files changed

+179
-36
lines changed

4 files changed

+179
-36
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20773,6 +20773,9 @@ public enum STOPTYPE
2077320773
public Dictionary<int, int> ConnectionsAwaited = new Dictionary<int, int>(); // List of awaited trains : key = trainno., value = arr time
2077420774
public Dictionary<int, WaitInfo> ConnectionDetails = new Dictionary<int, WaitInfo>(); // Details of connection : key = trainno., value = wait info
2077520775
public RequestStop ReqStopDetails = null; // Request stop details
20776+
public int PassTime; // Passing time (int)
20777+
public DateTime passDT; // Passing time (DateTime)
20778+
public bool PassingOnly;
2077620779

2077720780
//================================================================================================//
2077820781
//
@@ -20833,6 +20836,7 @@ public StationStop(int platformReference, PlatformDetails platformItem, int subr
2083320836
AllowDepartEarly = allowdepartearly;
2083420837

2083520838
CallOnAllowed = false;
20839+
PassingOnly = false;
2083620840
}
2083720841

2083820842
//================================================================================================//
@@ -20951,6 +20955,10 @@ public StationStop(BinaryReader inf, Signals signalRef)
2095120955
{
2095220956
ReqStopDetails = new RequestStop(inf, signalRef);
2095320957
}
20958+
20959+
PassTime = inf.ReadInt32();
20960+
passDT = new DateTime(inf.ReadInt64());
20961+
PassingOnly = inf.ReadBoolean();
2095420962
}
2095520963

2095620964
//================================================================================================//
@@ -21085,6 +21093,10 @@ public void Save(BinaryWriter outf)
2108521093
{
2108621094
outf.Write(false);
2108721095
}
21096+
21097+
outf.Write(PassTime);
21098+
outf.Write((Int64)passDT.Ticks);
21099+
outf.Write(PassingOnly);
2108821100
}
2108921101

2109021102
/// <summary>

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,10 +1542,6 @@ public bool BuildTrain(List<string[]> fileStrings, rowType[] RowInfo, int pathRo
15421542
{
15431543
Trace.TraceInformation("Double station reference : train " + Name + " ; station : " + stationDetails.StationName);
15441544
}
1545-
else if (fileStrings[iRow][columnIndex].StartsWith("P"))
1546-
{
1547-
// Allowed in timetable but not yet implemented
1548-
}
15491545
else
15501546
{
15511547
Stops.Add(stationDetails.StationName, ProcessStopInfo(fileStrings[iRow][columnIndex], stationDetails));
@@ -3168,18 +3164,15 @@ public enum SignalHoldType
31683164
public string StopName;
31693165
public int? arrivalTime;
31703166
public int? departureTime;
3171-
public int passTime;
3167+
public int? passTime;
31723168
public DateTime? arrivalDT;
31733169
public DateTime? departureDT;
3174-
public DateTime passDT;
3170+
public DateTime? passDT;
31753171
public bool arrdeppassvalid;
31763172
public bool allowDepartEarly;
31773173
public bool reqStop;
31783174
public SignalHoldType holdState;
31793175
public bool noWaitSignal;
3180-
// TODO
3181-
// public int passageTime; // not yet implemented
3182-
// public bool passvalid; // not yet implemented
31833176
public List<TTTrainCommands> Commands;
31843177

31853178
public TimetableInfo refTTInfo;
@@ -3197,7 +3190,7 @@ public StopInfo(string name, string arrTime, string depTime, TimetableInfo ttinf
31973190
refTTInfo = ttinfo;
31983191
arrivalTime = -1;
31993192
departureTime = -1;
3200-
passTime = -1;
3193+
passTime = null;
32013194
Commands = null;
32023195
allowDepartEarly = false;
32033196
reqStop = false;
@@ -3225,6 +3218,17 @@ public StopInfo(string name, string arrTime, string depTime, TimetableInfo ttinf
32253218
departureTime = arrivalTime = null;
32263219
}
32273220
}
3221+
else if (arrTime.StartsWith("P"))
3222+
{
3223+
string passingTime = arrTime.Substring(1);
3224+
validPassTime = TimeSpan.TryParse(passingTime, out atime);
3225+
3226+
if (validPassTime)
3227+
{
3228+
passTime = Convert.ToInt32(atime.TotalSeconds);
3229+
passDT = new DateTime(atime.Ticks);
3230+
}
3231+
}
32283232
else if (arrTime.Contains("P"))
32293233
{
32303234
string passingTime = arrTime.Replace('P', ':');
@@ -3294,7 +3298,7 @@ public bool BuildStopInfo(TTTrain actTrain, int actPlatformID, Signals signalRef
32943298
bool validStop = false;
32953299

32963300
// Valid stop and not passing
3297-
if (arrdeppassvalid && passTime < 0)
3301+
if (arrdeppassvalid && !passTime.HasValue)
32983302
{
32993303
// Check for station flags
33003304
bool terminal = false;
@@ -3561,9 +3565,10 @@ public bool BuildStopInfo(TTTrain actTrain, int actPlatformID, Signals signalRef
35613565
}
35623566

35633567
// Pass time only - valid condition but not yet processed
3564-
if (!validStop && passTime >= 0)
3568+
if (!validStop && passTime.HasValue)
35653569
{
3566-
validStop = true;
3570+
validStop = actTrain.CreateStationStop(actPlatformID, null, null, arrivalDT, departureDT, 0,
3571+
0, false, null, null, null, false, false, false, false, false, false, false, passTime, passDT);
35673572
}
35683573

35693574
return validStop;

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

Lines changed: 127 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,9 @@ public override bool PostInit()
13261326
/// <\summary>
13271327
public StationStop CalculateStationStop(int platformStartID, int? arrivalTime, int? departTime, DateTime? arrivalDT, DateTime? departureDT, float clearingDistanceM,
13281328
float minStopDistance, bool terminal, int? actMinStopTime, float? keepClearFront, float? keepClearRear, bool forcePosition, bool closeupSignal,
1329-
bool closeup, bool restrictPlatformToSignal, bool extendPlatformToSignal, bool endStop, bool allowdepartearly)
1329+
bool closeup, bool restrictPlatformToSignal, bool extendPlatformToSignal, bool endStop, bool allowdepartearly,
1330+
int? passTime = null, DateTime? passDT = null)
1331+
13301332
{
13311333
int platformIndex;
13321334
int activeSubroute = 0;
@@ -1374,24 +1376,25 @@ public StationStop CalculateStationStop(int platformStartID, int? arrivalTime, i
13741376
return null;
13751377
}
13761378

1377-
// Determine end stop position depending on direction
1378-
StationStop dummyStop = CalculateStationStopPosition(thisRoute, routeIndex, thisPlatform, activeSubroute,
1379-
keepClearFront, keepClearRear, forcePosition, closeupSignal, closeup, restrictPlatformToSignal, extendPlatformToSignal,
1380-
terminal, platformIndex);
1379+
StationStop thisStation;
1380+
1381+
// Determine pass time
1382+
// determine end stop position depending on direction
13811383

1382-
// Build and add station stop
1383-
StationStop thisStation = new StationStop(
1384+
if (passTime.HasValue)
1385+
{
1386+
thisStation = new StationStop(
13841387
platformStartID,
13851388
thisPlatform,
13861389
activeSubroute,
1387-
dummyStop.RouteIndex,
1388-
dummyStop.TCSectionIndex,
1389-
dummyStop.Direction,
1390-
dummyStop.ExitSignal,
1391-
dummyStop.HoldSignal,
1390+
routeIndex,
1391+
sectionIndex,
1392+
0,
1393+
-1,
1394+
false,
13921395
false,
13931396
false,
1394-
dummyStop.StopOffset,
1397+
0,
13951398
arrivalTime,
13961399
departTime,
13971400
terminal,
@@ -1407,10 +1410,51 @@ public StationStop CalculateStationStop(int platformStartID, int? arrivalTime, i
14071410
allowdepartearly,
14081411
StationStop.STOPTYPE.STATION_STOP);
14091412

1410-
if (arrivalDT.HasValue)
1413+
thisStation.PassTime = passTime.Value;
1414+
thisStation.passDT = passDT.Value;
1415+
thisStation.PassingOnly = true;
1416+
}
1417+
else
14111418
{
1412-
thisStation.arrivalDT = arrivalDT.Value;
1413-
thisStation.departureDT = departureDT.Value;
1419+
1420+
// Determine end stop position depending on direction
1421+
StationStop dummyStop = CalculateStationStopPosition(thisRoute, routeIndex, thisPlatform, activeSubroute,
1422+
keepClearFront, keepClearRear, forcePosition, closeupSignal, closeup, restrictPlatformToSignal, extendPlatformToSignal,
1423+
terminal, platformIndex);
1424+
1425+
// Build and add station stop
1426+
thisStation = new StationStop(
1427+
platformStartID,
1428+
thisPlatform,
1429+
activeSubroute,
1430+
dummyStop.RouteIndex,
1431+
dummyStop.TCSectionIndex,
1432+
dummyStop.Direction,
1433+
dummyStop.ExitSignal,
1434+
dummyStop.HoldSignal,
1435+
false,
1436+
false,
1437+
dummyStop.StopOffset,
1438+
arrivalTime,
1439+
departTime,
1440+
terminal,
1441+
actMinStopTime,
1442+
keepClearFront,
1443+
keepClearRear,
1444+
forcePosition,
1445+
closeupSignal,
1446+
closeup,
1447+
restrictPlatformToSignal,
1448+
extendPlatformToSignal,
1449+
endStop,
1450+
allowdepartearly,
1451+
StationStop.STOPTYPE.STATION_STOP);
1452+
1453+
if (arrivalDT.HasValue)
1454+
{
1455+
thisStation.arrivalDT = arrivalDT.Value;
1456+
thisStation.departureDT = departureDT.Value;
1457+
}
14141458
}
14151459

14161460
return thisStation;
@@ -2000,11 +2044,12 @@ public StationStop CalculateStationStopPosition(TCSubpathRoute thisRoute, int ro
20002044
/// <returns></returns>
20012045
public bool CreateStationStop(int platformStartID, int? arrivalTime, int? departTime, DateTime? arrivalDT, DateTime? departureDT, float clearingDistanceM,
20022046
float minStopDistanceM, bool terminal, int? actMinStopTime, float? keepClearFront, float? keepClearRear, bool forcePosition, bool closeupSignal,
2003-
bool closeup, bool restrictPlatformToSignal, bool extendPlatformToSignal, bool endStop, bool allowdepartearly)
2047+
bool closeup, bool restrictPlatformToSignal, bool extendPlatformToSignal, bool endStop, bool allowdepartearly,
2048+
int? passTime = null, DateTime? passDT = null)
20042049
{
20052050
StationStop thisStation = CalculateStationStop(platformStartID, arrivalTime, departTime, arrivalDT, departureDT, clearingDistanceM,
20062051
minStopDistanceM, terminal, actMinStopTime, keepClearFront, keepClearRear, forcePosition, closeupSignal, closeup,
2007-
restrictPlatformToSignal, extendPlatformToSignal, endStop, allowdepartearly);
2052+
restrictPlatformToSignal, extendPlatformToSignal, endStop, allowdepartearly, passTime, passDT);
20082053

20092054
if (thisStation != null)
20102055
{
@@ -2224,6 +2269,20 @@ public override void SetNextStationAction(bool fromAutopilotSwitch = false)
22242269
return;
22252270
}
22262271

2272+
// check if passing location only, remove for AI trains
2273+
2274+
while (thisStation.PassingOnly)
2275+
{
2276+
StationStops.RemoveAt(0);
2277+
2278+
if (StationStops.Count <= 0)
2279+
{
2280+
return;
2281+
}
2282+
2283+
thisStation = StationStops[0];
2284+
}
2285+
22272286
// Get distance to station, but not if just after switch to Autopilot and not during station stop
22282287
bool validStop = false;
22292288
while (!validStop)
@@ -4055,6 +4114,23 @@ public override void UpdateStationState(float elapsedClockSeconds, int presentTi
40554114
{
40564115
PreviousStop = StationStops[0].CreateCopy();
40574116
StationStops.RemoveAt(0);
4117+
4118+
if (StationStops.Count > 0)
4119+
{
4120+
thisStation = StationStops[0];
4121+
4122+
// check if next station is passing location only, if so remove
4123+
4124+
while (thisStation.PassingOnly)
4125+
{
4126+
StationStops.RemoveAt(0);
4127+
if (StationStops.Count <= 0)
4128+
{
4129+
break;
4130+
}
4131+
thisStation = StationStops[0];
4132+
}
4133+
}
40584134
}
40594135

40604136
ResetActions(true);
@@ -10200,14 +10276,15 @@ public void SetupStationStopHandling()
1020010276
/// </summary>
1020110277
public override void CheckStationTask()
1020210278
{
10279+
int presentTime = Convert.ToInt32(Math.Floor(Simulator.ClockTime));
10280+
1020310281
// If at station
1020410282
if (AtStation)
1020510283
{
1020610284
// Check for activation of other train
1020710285
ActivateTriggeredTrain(TriggerActivationType.StationStop, StationStops[0].PlatformReference);
1020810286

1020910287
// Get time
10210-
int presentTime = Convert.ToInt32(Math.Floor(Simulator.ClockTime));
1021110288
int eightHundredHours = 8 * 3600;
1021210289
int sixteenHundredHours = 16 * 3600;
1021310290

@@ -10598,7 +10675,6 @@ public override void CheckStationTask()
1059810675
{
1059910676
MovementState = AI_MOVEMENT_STATE.STATION_STOP;
1060010677

10601-
int presentTime = Convert.ToInt32(Math.Floor(Simulator.ClockTime));
1060210678
StationStops[0].ActualArrival = presentTime;
1060310679
StationStops[0].CalculateDepartTime(presentTime, this);
1060410680

@@ -10652,6 +10728,7 @@ public override void CheckStationTask()
1065210728

1065310729
// check if station missed : station must be at least 500m. behind us
1065410730
// also check if station was skipped as request stop
10731+
// also check if station was only passing point
1065510732
bool missedStation = false;
1065610733
int stationRouteIndex = ValidRoute[0].GetRouteIndex(StationStops[0].TCSectionIndex, 0);
1065710734

@@ -10682,6 +10759,36 @@ public override void CheckStationTask()
1068210759
}
1068310760
}
1068410761
}
10762+
else if (StationStops[0].PassingOnly)
10763+
{
10764+
bool passedstation = false;
10765+
if (StationStops[0].SubrouteIndex == TCRoute.activeSubpath)
10766+
{
10767+
if (stationRouteIndex < 0)
10768+
{
10769+
passedstation = true;
10770+
}
10771+
else if (stationRouteIndex == PresentPosition[1].RouteListIndex)
10772+
{
10773+
if ((PresentPosition[1].TCOffset - StationStops[0].StopOffset) > 50.0f)
10774+
{
10775+
passedstation = true;
10776+
}
10777+
}
10778+
else if (stationRouteIndex < PresentPosition[1].RouteListIndex)
10779+
{
10780+
passedstation = true;
10781+
}
10782+
}
10783+
10784+
if (passedstation)
10785+
{
10786+
StationStops[0].Passed = true;
10787+
StationStops[0].ActualDepart = presentTime;
10788+
PreviousStop = StationStops[0].CreateCopy();
10789+
StationStops.RemoveAt(0);
10790+
}
10791+
}
1068510792
else
1068610793
{
1068710794
if (StationStops[0].SubrouteIndex == TCRoute.activeSubpath)

0 commit comments

Comments
 (0)