Ejemplo n.º 1
0
        /// <summary>
        /// Initialization when simulation starts with moving train
        /// <\summary>
        public virtual void InitializeMoving()
        {
            BatterySwitch.InitializeMoving();
            MasterKey.InitializeMoving();
            ElectricTrainSupplySwitch.InitializeMoving();

            MainPowerSupplyState       = PowerSupplyState.PowerOn;
            AuxiliaryPowerSupplyState  = PowerSupplyState.PowerOn;
            ElectricTrainSupplyState   = PowerSupplyState.PowerOn;
            LowVoltagePowerSupplyState = PowerSupplyState.PowerOn;
            BatteryState = PowerSupplyState.PowerOn;
            if (Locomotive.IsLeadLocomotive())
            {
                CabPowerSupplyState = PowerSupplyState.PowerOn;
            }

            AbstractScript?.InitializeMoving();
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        protected virtual void AssignScriptFunctions()
        {
            // AbstractScriptClass
            AbstractScript.ClockTime          = () => (float)Simulator.ClockTime;
            AbstractScript.GameTime           = () => (float)Simulator.GameTime;
            AbstractScript.PreUpdate          = () => Simulator.PreUpdate;
            AbstractScript.DistanceM          = () => Locomotive.DistanceM;
            AbstractScript.SpeedMpS           = () => Math.Abs(Locomotive.SpeedMpS);
            AbstractScript.Confirm            = Locomotive.Simulator.Confirmer.Confirm;
            AbstractScript.Message            = Locomotive.Simulator.Confirmer.Message;
            AbstractScript.SignalEvent        = Locomotive.SignalEvent;
            AbstractScript.SignalEventToTrain = (evt) =>
            {
                if (Locomotive.Train != null)
                {
                    Locomotive.Train.SignalEvent(evt);
                }
            };

            // AbstractPowerSupply getters
            AbstractScript.CurrentMainPowerSupplyState       = () => MainPowerSupplyState;
            AbstractScript.CurrentAuxiliaryPowerSupplyState  = () => AuxiliaryPowerSupplyState;
            AbstractScript.CurrentElectricTrainSupplyState   = () => ElectricTrainSupplyState;
            AbstractScript.CurrentLowVoltagePowerSupplyState = () => LowVoltagePowerSupplyState;
            AbstractScript.CurrentBatteryState        = () => BatteryState;
            AbstractScript.CurrentCabPowerSupplyState = () => CabPowerSupplyState;
            AbstractScript.CurrentHelperEnginesState  = () =>
            {
                DieselEngineState state = DieselEngineState.Unavailable;

                foreach (MSTSDieselLocomotive locomotive in Train.Cars.OfType <MSTSDieselLocomotive>().Where((MSTSLocomotive locomotive) => { return(locomotive.AcceptMUSignals); }))
                {
                    if (locomotive == Simulator.PlayerLocomotive)
                    {
                        foreach (DieselEngine dieselEngine in locomotive.DieselEngines.DEList.Where(de => de != locomotive.DieselEngines[0]))
                        {
                            if (dieselEngine.State > state)
                            {
                                state = dieselEngine.State;
                            }
                        }
                    }
                    else
                    {
                        foreach (DieselEngine dieselEngine in locomotive.DieselEngines)
                        {
                            if (dieselEngine.State > state)
                            {
                                state = dieselEngine.State;
                            }
                        }
                    }
                }

                return(state);
            };
            AbstractScript.CurrentDynamicBrakeAvailability = () => DynamicBrakeAvailable;
            AbstractScript.ThrottlePercent             = () => Locomotive.ThrottlePercent;
            AbstractScript.PowerOnDelayS               = () => PowerOnDelayS;
            AbstractScript.AuxPowerOnDelayS            = () => AuxPowerOnDelayS;
            AbstractScript.BatterySwitchOn             = () => BatterySwitch.On;
            AbstractScript.MasterKeyOn                 = () => MasterKey.On;
            AbstractScript.ElectricTrainSupplySwitchOn = () => ElectricTrainSupplySwitch.On;
            AbstractScript.ElectricTrainSupplyUnfitted = () => ElectricTrainSupplySwitch.Mode == ElectricTrainSupplySwitch.ModeType.Unfitted;

            // AbstractPowerSupply setters
            AbstractScript.SetCurrentMainPowerSupplyState       = (value) => MainPowerSupplyState = value;
            AbstractScript.SetCurrentAuxiliaryPowerSupplyState  = (value) => AuxiliaryPowerSupplyState = value;
            AbstractScript.SetCurrentElectricTrainSupplyState   = (value) => ElectricTrainSupplyState = value;
            AbstractScript.SetCurrentLowVoltagePowerSupplyState = (value) => LowVoltagePowerSupplyState = value;
            AbstractScript.SetCurrentBatteryState                 = (value) => BatteryState = value;
            AbstractScript.SetCurrentCabPowerSupplyState          = (value) => CabPowerSupplyState = value;
            AbstractScript.SetCurrentDynamicBrakeAvailability     = (value) => DynamicBrakeAvailable = value;
            AbstractScript.SignalEventToBatterySwitch             = (evt) => BatterySwitch.HandleEvent(evt);
            AbstractScript.SignalEventToMasterKey                 = (evt) => MasterKey.HandleEvent(evt);
            AbstractScript.SignalEventToElectricTrainSupplySwitch = (evt) => ElectricTrainSupplySwitch.HandleEvent(evt);
            AbstractScript.SignalEventToPantographs               = (evt) => Locomotive.Pantographs.HandleEvent(evt);
            AbstractScript.SignalEventToPantograph                = (evt, id) => Locomotive.Pantographs.HandleEvent(evt, id);
            AbstractScript.SignalEventToTcs              = (evt) => Locomotive.TrainControlSystem.HandleEvent(evt);
            AbstractScript.SignalEventToTcsWithMessage   = (evt, message) => Locomotive.TrainControlSystem.HandleEvent(evt, message);
            AbstractScript.SignalEventToOtherLocomotives = (evt) =>
            {
                if (Locomotive == Simulator.PlayerLocomotive)
                {
                    foreach (MSTSLocomotive locomotive in Locomotive.Train.Cars.OfType <MSTSLocomotive>())
                    {
                        if (locomotive != Locomotive && locomotive != Locomotive.Train.LeadLocomotive && locomotive.AcceptMUSignals)
                        {
                            locomotive.LocomotivePowerSupply.HandleEventFromLeadLocomotive(evt);
                        }
                    }
                }
            };
            AbstractScript.SignalEventToOtherLocomotivesWithId = (evt, id) =>
            {
                if (Locomotive == Simulator.PlayerLocomotive)
                {
                    foreach (MSTSLocomotive locomotive in Locomotive.Train.Cars.OfType <MSTSLocomotive>())
                    {
                        if (locomotive != Locomotive && locomotive != Locomotive.Train.LeadLocomotive && locomotive.AcceptMUSignals)
                        {
                            locomotive.LocomotivePowerSupply.HandleEventFromLeadLocomotive(evt, id);
                        }
                    }
                }
            };
            AbstractScript.SignalEventToOtherTrainVehicles = (evt) =>
            {
                if (Locomotive == Simulator.PlayerLocomotive)
                {
                    foreach (TrainCar car in Locomotive.Train.Cars)
                    {
                        if (car != Locomotive && car != Locomotive.Train.LeadLocomotive && car.AcceptMUSignals)
                        {
                            car.PowerSupply?.HandleEventFromLeadLocomotive(evt);
                        }
                    }
                }
            };
            AbstractScript.SignalEventToOtherTrainVehiclesWithId = (evt, id) =>
            {
                if (Locomotive == Simulator.PlayerLocomotive)
                {
                    foreach (TrainCar car in Locomotive.Train.Cars)
                    {
                        if (car != Locomotive && car != Locomotive.Train.LeadLocomotive && car.AcceptMUSignals)
                        {
                            car.PowerSupply?.HandleEventFromLeadLocomotive(evt, id);
                        }
                    }
                }
            };
            AbstractScript.SignalEventToHelperEngines = (evt) =>
            {
                bool helperFound = false; //this avoids that locomotive engines toggle in opposite directions

                foreach (MSTSDieselLocomotive locomotive in Train.Cars.OfType <MSTSDieselLocomotive>().Where((MSTSLocomotive locomotive) => { return(locomotive.AcceptMUSignals); }))
                {
                    if (locomotive == Simulator.PlayerLocomotive)
                    {
                        // Engine number 1 or above are helper engines
                        for (int i = 1; i < locomotive.DieselEngines.Count; i++)
                        {
                            if (!helperFound)
                            {
                                helperFound = true;
                            }

                            locomotive.DieselEngines.HandleEvent(evt, i);
                        }
                    }
                    else
                    {
                        if (!helperFound)
                        {
                            helperFound = true;
                        }

                        locomotive.DieselEngines.HandleEvent(evt);
                    }
                }

                if (helperFound && (evt == PowerSupplyEvent.StartEngine || evt == PowerSupplyEvent.StopEngine))
                {
                    Simulator.Confirmer.Confirm(CabControl.HelperDiesel, evt == PowerSupplyEvent.StartEngine ? CabSetting.On : CabSetting.Off);
                }
            };
        }
Ejemplo n.º 4
0
 public virtual void Initialize()
 {
     BatterySwitch.Initialize();
     MasterKey.Initialize();
     ElectricTrainSupplySwitch.Initialize();
 }