@@ -287,13 +287,13 @@ bool UpdateState()
287
287
// Should prevent some unneeded computation, but is a little messy. May revise in the future
288
288
289
289
// Headlight
290
- int newTrainHeadlight = ! Car . Lights . IgnoredConditions [ 0 ] ? ( Car . Train != null ? Car . Train . TrainType != Train . TRAINTYPE . STATIC ? leadLocomotiveCar . Headlight : 0 : 0 ) : 0 ;
290
+ int newTrainHeadlight = ! Car . Lights . IgnoredConditions [ 0 ] ? ( Car . Train ? . TrainType != Train . TRAINTYPE . STATIC ? ( leadLocomotiveCar != null ? leadLocomotiveCar . Headlight : 2 ) : 0 ) : 0 ;
291
291
// Unit
292
292
bool locomotiveFlipped = leadLocomotiveCar != null && leadLocomotiveCar . Flipped ;
293
293
bool locomotiveReverseCab = leadLocomotive != null && leadLocomotive . UsingRearCab ;
294
294
bool newCarIsReversed = Car . Flipped ^ locomotiveFlipped ^ locomotiveReverseCab ;
295
- bool newCarIsFirst = ! Car . Lights . IgnoredConditions [ 1 ] && Car . Train == null || ( locomotiveFlipped ^ locomotiveReverseCab ? Car . Train . LastCar : Car . Train . FirstCar ) == Car ;
296
- bool newCarIsLast = ! Car . Lights . IgnoredConditions [ 1 ] && Car . Train == null || ( locomotiveFlipped ^ locomotiveReverseCab ? Car . Train . FirstCar : Car . Train . LastCar ) == Car ;
295
+ bool newCarIsFirst = ! Car . Lights . IgnoredConditions [ 1 ] && ( locomotiveFlipped ^ locomotiveReverseCab ? Car . Train ? . LastCar : Car . Train ? . FirstCar ) == Car ;
296
+ bool newCarIsLast = ! Car . Lights . IgnoredConditions [ 1 ] && ( locomotiveFlipped ^ locomotiveReverseCab ? Car . Train ? . FirstCar : Car . Train ? . LastCar ) == Car ;
297
297
// Penalty
298
298
bool newPenalty = ! Car . Lights . IgnoredConditions [ 2 ] && leadLocomotive != null && leadLocomotive . TrainBrakeController . EmergencyBraking ;
299
299
// Control
@@ -320,11 +320,11 @@ bool UpdateState()
320
320
// Friction brakes, activation force is arbitrary
321
321
bool newBrakeOn = ! Car . Lights . IgnoredConditions [ 9 ] && Car . BrakeForceN > 250.0f ;
322
322
// Reverser: -1: reverse, 0: within 10% of neutral, 1: forwards. Automatically swaps if this car is reversed
323
- int newReverserState = ! Car . Lights . IgnoredConditions [ 10 ] ? ( ( Car . Train . MUDirection == Direction . N || Math . Abs ( Car . Train . MUReverserPercent ) < 10.0f ) ? 0 :
323
+ int newReverserState = ( ! Car . Lights . IgnoredConditions [ 10 ] && Car . Train != null ) ? ( ( Car . Train . MUDirection == Direction . N || Math . Abs ( Car . Train . MUReverserPercent ) < 10.0f ) ? 0 :
324
324
Car . Train . MUDirection == Direction . Forward ? 1 : - 1 ) * ( Car . Flipped ? - 1 : 1 ) : 0 ;
325
325
// Passenger doors
326
- bool newLeftDoorOpen = ! Car . Lights . IgnoredConditions [ 11 ] && Car . Train . DoorState ( DoorSide . Left ) != DoorState . Closed ;
327
- bool newRightDoorOpen = ! Car . Lights . IgnoredConditions [ 11 ] && Car . Train . DoorState ( DoorSide . Right ) != DoorState . Closed ;
326
+ bool newLeftDoorOpen = ! Car . Lights . IgnoredConditions [ 11 ] && Car . Train ? . DoorState ( DoorSide . Left ) != DoorState . Closed ;
327
+ bool newRightDoorOpen = ! Car . Lights . IgnoredConditions [ 11 ] && Car . Train ? . DoorState ( DoorSide . Right ) != DoorState . Closed ;
328
328
// Horn and bell (for flashing ditch lights)
329
329
bool newHornOn = ! Car . Lights . IgnoredConditions [ 12 ] && leadLocomotive != null && leadLocomotive . HornRecent ;
330
330
bool newBellOn = ! Car . Lights . IgnoredConditions [ 13 ] && leadLocomotive != null && leadLocomotive . BellRecent ;
0 commit comments