@@ -75,6 +75,7 @@ public class AITrain : Train
7575        public  float  doorOpenDelay  =  - 1f ; 
7676        public  float  doorCloseAdvance  =  - 1f ; 
7777        public  AILevelCrossingHornPattern  LevelCrossingHornPattern  {  get ;  set ;  } 
78+         public  bool  ApproachTriggerSet  =  false ;          // station approach trigger for AI trains has been set 
7879
7980        public  float  PathLength ; 
8081
@@ -246,6 +247,7 @@ public AITrain(Simulator simulator, BinaryReader inf, AI airef)
246247            UncondAttach  =  inf . ReadBoolean ( ) ; 
247248            doorCloseAdvance  =  inf . ReadSingle ( ) ; 
248249            doorOpenDelay  =  inf . ReadSingle ( ) ; 
250+ 			ApproachTriggerSet  =  inf . ReadBoolean ( ) ; 
249251            if  ( ! Simulator . TimetableMode  &&  doorOpenDelay  <=  0  &&  doorCloseAdvance  >  0  &&  Simulator . OpenDoorsInAITrains  && 
250252                MovementState  ==  AI_MOVEMENT_STATE . STATION_STOP  &&  StationStops . Count  >  0 ) 
251253            { 
@@ -339,6 +341,7 @@ public override void Save(BinaryWriter outf)
339341            outf . Write ( UncondAttach ) ; 
340342            outf . Write ( doorCloseAdvance ) ; 
341343            outf . Write ( doorOpenDelay ) ; 
344+             outf . Write ( ApproachTriggerSet ) ; 
342345            if  ( LevelCrossingHornPattern  !=  null ) 
343346            { 
344347                outf . Write ( 0 ) ; 
@@ -1300,6 +1303,7 @@ public virtual void SetNextStationAction(bool fromAutopilotSwitch = false)
13001303                        AIActionItem  newAction  =  new  AIActionItem ( null ,  AIActionItem . AI_ACTION_TYPE . STATION_STOP ) ; 
13011304                        newAction . SetParam ( distancesM [ 1 ] ,  0.0f ,  distancesM [ 0 ] ,  DistanceTravelledM ) ; 
13021305                        requiredActions . InsertAction ( newAction ) ; 
1306+                         ApproachTriggerSet  =  false ; 
13031307
13041308#if DEBUG_REPORTS 
13051309                if  ( StationStops [ 0 ] . ActualStopType  ==  StationStop . STOPTYPE . STATION_STOP ) 
@@ -2060,6 +2064,7 @@ public virtual void UpdateStationState(float elapsedClockSeconds, int presentTim
20602064
20612065                Delay  =  TimeSpan . FromSeconds ( ( presentTime  -  thisStation . DepartTime )  %  ( 24  *  3600 ) ) ; 
20622066            } 
2067+             if  ( Cars [ 0 ]  is  MSTSLocomotive )  Cars [ 0 ] . SignalEvent ( Event . AITrainLeavingStation ) ; 
20632068
20642069#if DEBUG_REPORTS 
20652070            DateTime  baseDTd  =  new  DateTime ( ) ; 
@@ -2621,6 +2626,13 @@ public virtual void UpdateBrakingState(float elapsedClockSeconds, int presentTim
26212626                } 
26222627            } 
26232628
2629+             if  ( nextActionInfo  !=  null  &&  nextActionInfo . NextAction  ==  AIActionItem . AI_ACTION_TYPE . STATION_STOP  && 
2630+                 distanceToGoM  <  150  +  StationStops [ 0 ] . PlatformItem . Length  &&  ! ApproachTriggerSet ) 
2631+             { 
2632+                 if  ( Cars [ 0 ]  is  MSTSLocomotive )  Cars [ 0 ] . SignalEvent ( Event . AITrainApproachingStation ) ; 
2633+                 ApproachTriggerSet  =  true ; 
2634+             } 
2635+ 
26242636            if  ( nextActionInfo  !=  null  &&  nextActionInfo . NextAction  ==  AIActionItem . AI_ACTION_TYPE . STATION_STOP ) 
26252637                creepDistanceM  =  0.0f ; 
26262638            if  ( nextActionInfo  ==  null  &&  requiredSpeedMpS  ==  0 ) 
@@ -4367,6 +4379,7 @@ public void CoupleAI(Train attachTrain, bool thisTrainFront, bool attachTrainFro
43674379                    Simulator . OnPlayerLocomotiveChanged ( ) ; 
43684380                    AI . AITrains . Add ( this ) ; 
43694381                } 
4382+                 else  if  ( attachTrain  is  AITrain )  RedefineAITriggers ( attachTrain  as  AITrain ) ; 
43704383                if  ( ! UncondAttach ) 
43714384                { 
43724385                    RemoveTrain ( ) ; 
@@ -4475,6 +4488,7 @@ public void CoupleAIToStatic(Train attachTrain, bool thisTrainFront, bool attach
44754488            AddTrackSections ( ) ; 
44764489            ResetActions ( true ) ; 
44774490            physicsUpdate ( 0 ) ; 
4491+             RedefineAITriggers ( this ) ; 
44784492        } 
44794493
44804494        //================================================================================================// 
@@ -4716,7 +4730,8 @@ public void TerminateCoupling(Train attachTrain, bool thisTrainFront, bool attac
47164730            // Move WP, if any, just under the loco; 
47174731            AuxActionsContain . MoveAuxActionAfterReversal ( this ) ; 
47184732            ResetActions ( true ) ; 
4719- 
4733+             RedefineAITriggers ( this ) ; 
4734+             if  ( attachTrain  is  AITrain )  RedefineAITriggers ( attachTrain  as  AITrain ) ; 
47204735            physicsUpdate ( 0 ) ; // Stop the wheels from moving etc 
47214736
47224737        } 
@@ -6578,6 +6593,27 @@ public void RestartWaitingTrain(RestartWaitingTrain restartWaitingTrain)
65786593            } 
65796594        } 
65806595
6596+         //================================================================================================// 
6597+         /// <summary> 
6598+         /// Redefine sound triggers for AI trains 
6599+         /// </summary> 
6600+         public  void  RedefineAITriggers ( AITrain  train ) 
6601+         { 
6602+             var  leadFound  =  false ; 
6603+             foreach  ( var  car  in  train . Cars ) 
6604+             { 
6605+                 if  ( car  is  MSTSLocomotive ) 
6606+                 { 
6607+                     if  ( ! leadFound ) 
6608+                     { 
6609+                         car . SignalEvent ( Event . AITrainLeadLoco ) ; 
6610+                         leadFound  =  true ; 
6611+                     } 
6612+                     else  car . SignalEvent ( Event . AITrainHelperLoco ) ; 
6613+                 } 
6614+             } 
6615+         } 
6616+ 
65816617    } 
65826618
65836619
0 commit comments