@@ -75,6 +75,7 @@ public class AITrain : Train
75
75
public float doorOpenDelay = - 1f ;
76
76
public float doorCloseAdvance = - 1f ;
77
77
public AILevelCrossingHornPattern LevelCrossingHornPattern { get ; set ; }
78
+ public bool ApproachTriggerSet = false ; // station approach trigger for AI trains has been set
78
79
79
80
public float PathLength ;
80
81
@@ -246,6 +247,7 @@ public AITrain(Simulator simulator, BinaryReader inf, AI airef)
246
247
UncondAttach = inf . ReadBoolean ( ) ;
247
248
doorCloseAdvance = inf . ReadSingle ( ) ;
248
249
doorOpenDelay = inf . ReadSingle ( ) ;
250
+ ApproachTriggerSet = inf . ReadBoolean ( ) ;
249
251
if ( ! Simulator . TimetableMode && doorOpenDelay <= 0 && doorCloseAdvance > 0 && Simulator . OpenDoorsInAITrains &&
250
252
MovementState == AI_MOVEMENT_STATE . STATION_STOP && StationStops . Count > 0 )
251
253
{
@@ -339,6 +341,7 @@ public override void Save(BinaryWriter outf)
339
341
outf . Write ( UncondAttach ) ;
340
342
outf . Write ( doorCloseAdvance ) ;
341
343
outf . Write ( doorOpenDelay ) ;
344
+ outf . Write ( ApproachTriggerSet ) ;
342
345
if ( LevelCrossingHornPattern != null )
343
346
{
344
347
outf . Write ( 0 ) ;
@@ -1300,6 +1303,7 @@ public virtual void SetNextStationAction(bool fromAutopilotSwitch = false)
1300
1303
AIActionItem newAction = new AIActionItem ( null , AIActionItem . AI_ACTION_TYPE . STATION_STOP ) ;
1301
1304
newAction . SetParam ( distancesM [ 1 ] , 0.0f , distancesM [ 0 ] , DistanceTravelledM ) ;
1302
1305
requiredActions . InsertAction ( newAction ) ;
1306
+ ApproachTriggerSet = false ;
1303
1307
1304
1308
#if DEBUG_REPORTS
1305
1309
if ( StationStops [ 0 ] . ActualStopType == StationStop . STOPTYPE . STATION_STOP )
@@ -2060,6 +2064,7 @@ public virtual void UpdateStationState(float elapsedClockSeconds, int presentTim
2060
2064
2061
2065
Delay = TimeSpan . FromSeconds ( ( presentTime - thisStation . DepartTime ) % ( 24 * 3600 ) ) ;
2062
2066
}
2067
+ if ( Cars [ 0 ] is MSTSLocomotive ) Cars [ 0 ] . SignalEvent ( Event . AITrainLeavingStation ) ;
2063
2068
2064
2069
#if DEBUG_REPORTS
2065
2070
DateTime baseDTd = new DateTime ( ) ;
@@ -2621,6 +2626,13 @@ public virtual void UpdateBrakingState(float elapsedClockSeconds, int presentTim
2621
2626
}
2622
2627
}
2623
2628
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
+
2624
2636
if ( nextActionInfo != null && nextActionInfo . NextAction == AIActionItem . AI_ACTION_TYPE . STATION_STOP )
2625
2637
creepDistanceM = 0.0f ;
2626
2638
if ( nextActionInfo == null && requiredSpeedMpS == 0 )
@@ -4367,6 +4379,7 @@ public void CoupleAI(Train attachTrain, bool thisTrainFront, bool attachTrainFro
4367
4379
Simulator . OnPlayerLocomotiveChanged ( ) ;
4368
4380
AI . AITrains . Add ( this ) ;
4369
4381
}
4382
+ else if ( attachTrain is AITrain ) RedefineAITriggers ( attachTrain as AITrain ) ;
4370
4383
if ( ! UncondAttach )
4371
4384
{
4372
4385
RemoveTrain ( ) ;
@@ -4475,6 +4488,7 @@ public void CoupleAIToStatic(Train attachTrain, bool thisTrainFront, bool attach
4475
4488
AddTrackSections ( ) ;
4476
4489
ResetActions ( true ) ;
4477
4490
physicsUpdate ( 0 ) ;
4491
+ RedefineAITriggers ( this ) ;
4478
4492
}
4479
4493
4480
4494
//================================================================================================//
@@ -4716,7 +4730,8 @@ public void TerminateCoupling(Train attachTrain, bool thisTrainFront, bool attac
4716
4730
// Move WP, if any, just under the loco;
4717
4731
AuxActionsContain . MoveAuxActionAfterReversal ( this ) ;
4718
4732
ResetActions ( true ) ;
4719
-
4733
+ RedefineAITriggers ( this ) ;
4734
+ if ( attachTrain is AITrain ) RedefineAITriggers ( attachTrain as AITrain ) ;
4720
4735
physicsUpdate ( 0 ) ; // Stop the wheels from moving etc
4721
4736
4722
4737
}
@@ -6578,6 +6593,27 @@ public void RestartWaitingTrain(RestartWaitingTrain restartWaitingTrain)
6578
6593
}
6579
6594
}
6580
6595
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
+
6581
6617
}
6582
6618
6583
6619
0 commit comments