Skip to content

Commit cd5c185

Browse files
committed
Fix horn, bell, and MU light conditions on AI trains
1 parent d0c2856 commit cd5c185

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Source/RunActivity/Viewer3D/Lights.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ bool UpdateState()
300300
Debug.Assert(Viewer.PlayerTrain.LeadLocomotive == Viewer.PlayerLocomotive ||Viewer.PlayerTrain.TrainType == Train.TRAINTYPE.AI_PLAYERHOSTING || Viewer.PlayerTrain.Autopilot ||
301301
Viewer.PlayerTrain.TrainType == Train.TRAINTYPE.REMOTE || Viewer.PlayerTrain.TrainType == Train.TRAINTYPE.STATIC, "PlayerTrain.LeadLocomotive must be PlayerLocomotive.");
302302
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;
304304

305305
// There are a lot of conditions now! IgnoredConditions[] stores which conditions are ignored, allowing shortcutting of many of these calculations
306306
// Should prevent some unneeded computation, but is a little messy. May revise in the future
@@ -318,7 +318,7 @@ bool UpdateState()
318318
&& leadLocomotive != null && leadLocomotive.TrainBrakeController.EmergencyBraking;
319319
// Control
320320
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.
322322
bool newCarInService = !Car.Lights.IgnoredConditions[4] && Car.Train != null
323323
&& (Car.Train == Viewer.PlayerTrain || Car.Train.TrainType == Train.TRAINTYPE.REMOTE || Car.Train.TrainType == Train.TRAINTYPE.AI);
324324
// Time of day
@@ -346,6 +346,15 @@ bool UpdateState()
346346
// Passenger doors
347347
bool newLeftDoorOpen = !Car.Lights.IgnoredConditions[11] && Car.Train?.DoorState(DoorSide.Left) != DoorState.Closed;
348348
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+
}
349358
// Horn and bell (for flashing ditch lights)
350359
bool newHornOn = !Car.Lights.IgnoredConditions[12] && leadLocomotive != null && leadLocomotive.HornRecent;
351360
bool newBellOn = !Car.Lights.IgnoredConditions[13] && leadLocomotive != null && leadLocomotive.BellRecent;

0 commit comments

Comments
 (0)