@@ -684,7 +684,7 @@ public void AIUpdate(float elapsedClockSeconds, double clockTime, bool preUpdate
684684
685685 if ( MovementState == AI_MOVEMENT_STATE . AI_STATIC )
686686 {
687- physicsUpdate ( 0 ) ; //required to make train visible ; set elapsed time to zero to avoid actual movement
687+ CalculatePositionOfCars ( 0 , 0 ) ; //required to make train visible ; set elapsed time to zero to avoid actual movement
688688 }
689689 else
690690 {
@@ -4027,6 +4027,7 @@ public void BuildWaitingPointList(float clearingDistanceM)
40274027 RandomizedWPDelay ( ref randomizedDelay ) ;
40284028 }
40294029 action . SetDelay ( randomizedDelay ) ;
4030+ action . OriginalDelay = action . Delay ;
40304031 AuxActionsContain . Add ( action ) ;
40314032 if ( insertSigDelegate && ( waitingPoint [ 2 ] != 60002 ) && signalIndex [ iWait ] > - 1 )
40324033 {
@@ -5100,6 +5101,32 @@ public void CreateTrainAction(float presentSpeedMpS, float reqSpeedMpS, float di
51005101 // correct trigger for approach distance but not backward beyond present position
51015102 triggerDistanceM = Math . Max ( PresentPosition [ 0 ] . DistanceTravelledM , triggerDistanceM - ( 3.0f * signalApproachDistanceM ) ) ;
51025103
5104+ // for signal stop item : check if action allready in list, if so, remove (can be result of restore action)
5105+ LinkedListNode < DistanceTravelledItem > thisItemLink = requiredActions . First ;
5106+ bool itemFound = false ;
5107+
5108+ while ( thisItemLink != null && ! itemFound )
5109+ {
5110+ DistanceTravelledItem thisDTItem = thisItemLink . Value ;
5111+ if ( thisDTItem is AIActionItem )
5112+ {
5113+ AIActionItem thisActionItem = thisDTItem as AIActionItem ;
5114+ if ( thisActionItem . ActiveItem != null && thisActionItem . NextAction == thisAction )
5115+ {
5116+ if ( thisActionItem . ActiveItem . ObjectDetails . thisRef == thisItem . ObjectDetails . thisRef )
5117+ {
5118+ // equal item, so remove it
5119+ requiredActions . Remove ( thisDTItem ) ;
5120+ itemFound = true ;
5121+ }
5122+ }
5123+ }
5124+ if ( ! itemFound )
5125+ {
5126+ thisItemLink = thisItemLink . Next ;
5127+ }
5128+ }
5129+
51035130 // create and insert action
51045131
51055132 AIActionItem newAction = new AIActionItem ( thisItem , thisAction ) ;
@@ -5298,7 +5325,7 @@ public override void PerformActions(List<DistanceTravelledItem> nowActions)
52985325 }
52995326 else if ( thisAction is ClearMovingTableAction )
53005327 {
5301- ClearMovingTable ( ) ;
5328+ ClearMovingTable ( thisAction ) ;
53025329 }
53035330 else if ( thisAction is AIActionItem && ! ( thisAction is AuxActionItem ) )
53045331 {
@@ -5345,7 +5372,7 @@ public void SetAIPendingSpeedLimit(ActivateSpeedLimit speedInfo)
53455372 else
53465373 AllowedMaxSpeedMpS = Math . Min ( speedInfo . MaxSpeedMpSLimit , Math . Min ( allowedMaxSpeedSignalMpS , allowedMaxTempSpeedLimitMpS ) ) ;
53475374 }
5348- if ( speedInfo . MaxTempSpeedMpSLimit > 0 && ! Simulator . TimetableMode )
5375+ if ( speedInfo . MaxTempSpeedMpSLimit > 0 )
53495376 {
53505377 allowedMaxTempSpeedLimitMpS = allowedAbsoluteMaxTempSpeedLimitMpS ;
53515378 AllowedMaxSpeedMpS = Math . Min ( speedInfo . MaxTempSpeedMpSLimit , Math . Min ( allowedMaxSpeedSignalMpS , allowedMaxSpeedLimitMpS ) ) ;
@@ -5453,22 +5480,41 @@ public void ProcessActionItem(AIActionItem thisItem)
54535480 if ( thisItem . ActiveItem . signal_state == MstsSignalAspect . STOP &&
54545481 thisItem . ActiveItem . ObjectDetails . holdState == HoldState . StationStop )
54555482 {
5456- actionValid = false ;
5483+ // check if train is approaching or standing at station and has not yet departed
5484+ if ( StationStops != null && StationStops . Count >= 1 && AtStation && StationStops [ 0 ] . ExitSignal == thisItem . ActiveItem . ObjectDetails . thisRef )
5485+ {
5486+ actionValid = false ;
54575487
54585488#if DEBUG_REPORTS
54595489 File . AppendAllText ( @"C:\temp\printproc.txt" , "Train " +
54605490 Number . ToString ( ) + " : signal " +
54615491 thisItem . ActiveItem . ObjectDetails . thisRef . ToString ( ) + " at " +
54625492 thisItem . ActivateDistanceM . ToString ( ) + " is held for station stop\n " ) ;
54635493#endif
5464- if ( CheckTrain )
5494+ if ( CheckTrain )
5495+ {
5496+ File . AppendAllText ( @"C:\temp\checktrain.txt" , "Train " +
5497+ Number . ToString ( ) + " : signal " +
5498+ thisItem . ActiveItem . ObjectDetails . thisRef . ToString ( ) + " at " +
5499+ thisItem . ActivateDistanceM . ToString ( ) + " is held for station stop\n " ) ;
5500+ }
5501+ }
5502+ else
54655503 {
5466- File . AppendAllText ( @"C:\temp\checktrain.txt" , "Train " +
5467- Number . ToString ( ) + " : signal " +
5468- thisItem . ActiveItem . ObjectDetails . thisRef . ToString ( ) + " at " +
5469- thisItem . ActivateDistanceM . ToString ( ) + " is held for station stop\n " ) ;
5504+ #if DEBUG_REPORTS
5505+ File . AppendAllText ( @"C:\temp\printproc.txt" , "Train " +
5506+ Number . ToString ( ) + " : signal " +
5507+ thisItem . ActiveItem . ObjectDetails . thisRef . ToString ( ) + " at " +
5508+ thisItem . ActivateDistanceM . ToString ( ) + " is held for station stop but train is no longer stopped in station\n " ) ;
5509+ #endif
5510+ if ( CheckTrain )
5511+ {
5512+ File . AppendAllText ( @"C:\temp\checktrain.txt" , "Train " +
5513+ Number . ToString ( ) + " : signal " +
5514+ thisItem . ActiveItem . ObjectDetails . thisRef . ToString ( ) + " at " +
5515+ thisItem . ActivateDistanceM . ToString ( ) + " is held for station stop but train is no longer stopped in station\n " ) ;
5516+ }
54705517 }
5471-
54725518 }
54735519
54745520 // check if cleared
@@ -6640,7 +6686,7 @@ public void RestartWaitingTrain(RestartWaitingTrain restartWaitingTrain)
66406686 var matchingWPDelay = restartWaitingTrain . MatchingWPDelay ;
66416687 int presentTime = Convert . ToInt32 ( Math . Floor ( Simulator . ClockTime ) ) ;
66426688 var roughActualDepart = presentTime + delayToRestart ;
6643- if ( MovementState == AITrain . AI_MOVEMENT_STATE . HANDLE_ACTION && ( ( ( nextActionInfo as AuxActionWPItem ) . ActionRef as AIActionWPRef ) . Delay == matchingWPDelay ||
6689+ if ( MovementState == AITrain . AI_MOVEMENT_STATE . HANDLE_ACTION && ( ( ( nextActionInfo as AuxActionWPItem ) . ActionRef as AIActionWPRef ) . OriginalDelay == matchingWPDelay ||
66446690 ( AuxActionsContain . specRequiredActions . Count > 0 && ( ( AuxActSigDelegate ) ( AuxActionsContain . specRequiredActions ) . First . Value ) . currentMvmtState == AITrain . AI_MOVEMENT_STATE . HANDLE_ACTION &&
66456691 ( ( ( AuxActSigDelegate ) ( AuxActionsContain . specRequiredActions ) . First . Value ) . ActionRef as AIActSigDelegateRef ) . Delay == matchingWPDelay ) ) )
66466692 {
0 commit comments