@@ -300,7 +300,7 @@ bool UpdateState()
300
300
Debug . Assert ( Viewer . PlayerTrain . LeadLocomotive == Viewer . PlayerLocomotive || Viewer . PlayerTrain . TrainType == Train . TRAINTYPE . AI_PLAYERHOSTING || Viewer . PlayerTrain . Autopilot ||
301
301
Viewer . PlayerTrain . TrainType == Train . TRAINTYPE . REMOTE || Viewer . PlayerTrain . TrainType == Train . TRAINTYPE . STATIC , "PlayerTrain.LeadLocomotive must be PlayerLocomotive." ) ;
302
302
var leadLocomotiveCar = Car . Train ? . LeadLocomotive ; // Note: Will return null for AI trains, this is intended behavior
303
- var leadLocomotive = leadLocomotiveCar as MSTSLocomotive ;
303
+ var leadLocomotive = leadLocomotiveCar as MSTSLocomotive ;
304
304
305
305
// There are a lot of conditions now! IgnoredConditions[] stores which conditions are ignored, allowing shortcutting of many of these calculations
306
306
// Should prevent some unneeded computation, but is a little messy. May revise in the future
@@ -318,7 +318,7 @@ bool UpdateState()
318
318
&& leadLocomotive != null && leadLocomotive . TrainBrakeController . EmergencyBraking ;
319
319
// Control
320
320
bool newCarIsPlayer = ! Car . Lights . IgnoredConditions [ 3 ] && Car . Train != null && ( Car . Train == Viewer . PlayerTrain || Car . Train . TrainType == Train . TRAINTYPE . REMOTE ) ;
321
- // Service - if a player or AI train, then will considered to be in servie , loose consists will not be considered to be in service.
321
+ // Service - if a player or AI train, then will considered to be in service , loose consists will not be considered to be in service.
322
322
bool newCarInService = ! Car . Lights . IgnoredConditions [ 4 ] && Car . Train != null
323
323
&& ( Car . Train == Viewer . PlayerTrain || Car . Train . TrainType == Train . TRAINTYPE . REMOTE || Car . Train . TrainType == Train . TRAINTYPE . AI ) ;
324
324
// Time of day
@@ -346,6 +346,15 @@ bool UpdateState()
346
346
// Passenger doors
347
347
bool newLeftDoorOpen = ! Car . Lights . IgnoredConditions [ 11 ] && Car . Train ? . DoorState ( DoorSide . Left ) != DoorState . Closed ;
348
348
bool newRightDoorOpen = ! Car . Lights . IgnoredConditions [ 11 ] && Car . Train ? . DoorState ( DoorSide . Right ) != DoorState . Closed ;
349
+ // AI trains don't have a lead locomotive, but the upcoming lighting calculations want a lead locomotive, try to determine a lead locomotive to use
350
+ if ( leadLocomotive == null )
351
+ {
352
+ // If first car is flipped, the 'lead' vehicle is actually at the rear
353
+ if ( Car . Train . FirstCar . Flipped && Car . Train . LastCar is MSTSLocomotive )
354
+ leadLocomotive = Car . Train . LastCar as MSTSLocomotive ;
355
+ else if ( Car . Train . FirstCar is MSTSLocomotive )
356
+ leadLocomotive = Car . Train . FirstCar as MSTSLocomotive ;
357
+ }
349
358
// Horn and bell (for flashing ditch lights)
350
359
bool newHornOn = ! Car . Lights . IgnoredConditions [ 12 ] && leadLocomotive != null && leadLocomotive . HornRecent ;
351
360
bool newBellOn = ! Car . Lights . IgnoredConditions [ 13 ] && leadLocomotive != null && leadLocomotive . BellRecent ;
0 commit comments