@@ -287,7 +287,7 @@ bool UpdateState()
287287 // Should prevent some unneeded computation, but is a little messy. May revise in the future
288288
289289 // 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 ;
291291 // Unit
292292 bool locomotiveFlipped = leadLocomotiveCar != null && leadLocomotiveCar . Flipped ;
293293 bool locomotiveReverseCab = leadLocomotive != null && leadLocomotive . UsingRearCab ;
@@ -320,11 +320,11 @@ bool UpdateState()
320320 // Friction brakes, activation force is arbitrary
321321 bool newBrakeOn = ! Car . Lights . IgnoredConditions [ 9 ] && Car . BrakeForceN > 250.0f ;
322322 // 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 :
324324 Car . Train . MUDirection == Direction . Forward ? 1 : - 1 ) * ( Car . Flipped ? - 1 : 1 ) : 0 ;
325325 // 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 ;
328328 // Horn and bell (for flashing ditch lights)
329329 bool newHornOn = ! Car . Lights . IgnoredConditions [ 12 ] && leadLocomotive != null && leadLocomotive . HornRecent ;
330330 bool newBellOn = ! Car . Lights . IgnoredConditions [ 13 ] && leadLocomotive != null && leadLocomotive . BellRecent ;
0 commit comments