Exemple #1
0
        public virtual void Update(double elapsedClockSeconds)
        {
            CarId = Train?.Cars.IndexOf(Locomotive) ?? 0;

            if (firstUpdate)
            {
                firstUpdate = false;

                TrainCar previousCar = CarId > 0 ? Train.Cars[CarId - 1] : null;

                // Connect the power supply cable if the previous car is a locomotive or another passenger car
                if (previousCar != null &&
                    (previousCar.WagonType == TrainCar.WagonTypes.Engine ||
                     previousCar.WagonType == TrainCar.WagonTypes.Passenger)
                    )
                {
                    FrontElectricTrainSupplyCableConnected = true;
                }
            }

            BatterySwitch.Update(elapsedClockSeconds);
            MasterKey.Update(elapsedClockSeconds);
            ElectricTrainSupplySwitch.Update(elapsedClockSeconds);
        }
Exemple #2
0
        public virtual void Update(float elapsedClockSeconds)
        {
            CarId = Train?.Cars.IndexOf(Wagon) ?? 0;

            if (IsFirstUpdate)
            {
                IsFirstUpdate = false;

                // At this point, we can expect Train to be initialized.
                var previousCar = CarId > 0 ? Train.Cars[CarId - 1] : null;

                // Connect the power supply cable if the previous car is a locomotive or another passenger car
                if (previousCar != null &&
                    (previousCar is MSTSLocomotive locomotive && locomotive.LocomotivePowerSupply.ElectricTrainSupplyState != PowerSupplyState.Unavailable ||
                     previousCar.WagonSpecialType == TrainCar.WagonSpecialTypes.PowerVan ||
                     previousCar.WagonType == TrainCar.WagonTypes.Passenger && previousCar.PowerSupply is ScriptedPassengerCarPowerSupply)
                    )
                {
                    FrontElectricTrainSupplyCableConnected = true;
                }
            }

            ElectricTrainSupplyConnectedLocomotives = Train.Cars.OfType <MSTSLocomotive>().Where((locomotive) =>
            {
                int locomotiveId       = Train.Cars.IndexOf(locomotive);
                bool locomotiveInFront = locomotiveId < CarId;

                bool connectedToLocomotive = true;
                if (locomotiveInFront)
                {
                    for (int i = locomotiveId; i < CarId; i++)
                    {
                        if (Train.Cars[i + 1].PowerSupply == null)
                        {
                            connectedToLocomotive = false;
                            break;
                        }
                        if (!Train.Cars[i + 1].PowerSupply.FrontElectricTrainSupplyCableConnected)
                        {
                            connectedToLocomotive = false;
                            break;
                        }
                    }
                }
                else
                {
                    for (int i = locomotiveId; i > CarId; i--)
                    {
                        if (Train.Cars[i].PowerSupply == null)
                        {
                            connectedToLocomotive = false;
                            break;
                        }
                        if (!Train.Cars[i].PowerSupply.FrontElectricTrainSupplyCableConnected)
                        {
                            connectedToLocomotive = false;
                            break;
                        }
                    }
                }

                return(connectedToLocomotive);
            });

            if (ElectricTrainSupplyConnectedLocomotives.Count() > 0)
            {
                ElectricTrainSupplyState = ElectricTrainSupplyConnectedLocomotives.Select(locomotive => locomotive.LocomotivePowerSupply.ElectricTrainSupplyState).Max();
            }
            else
            {
                ElectricTrainSupplyState = PowerSupplyState.PowerOff;
            }

            BatterySwitch.Update(elapsedClockSeconds);
            Script?.Update(elapsedClockSeconds);
        }