コード例 #1
0
        public virtual void Parse(string lowercasetoken, STFReader stf)
        {
            switch (lowercasetoken)
            {
            case "engine(ortspowersupply":
                ScriptName = stf.ReadStringBlock(null);
                break;

            case "engine(ortspowerondelay":
                PowerOnDelayS = stf.ReadFloatBlock(STFReader.Units.Time, null);
                break;

            case "engine(ortsauxpowerondelay":
                AuxPowerOnDelayS = stf.ReadFloatBlock(STFReader.Units.Time, null);
                break;

            case "engine(ortsbattery(mode":
            case "engine(ortsbattery(delay":
                BatterySwitch.Parse(lowercasetoken, stf);
                break;

            case "engine(ortsmasterkey(mode":
            case "engine(ortsmasterkey(delayoff":
            case "engine(ortsmasterkey(headlightcontrol":
                MasterKey.Parse(lowercasetoken, stf);
                break;

            case "engine(ortselectrictrainsupply(mode":
                ElectricTrainSupplySwitch.Parse(lowercasetoken, stf);
                break;
            }
        }
コード例 #2
0
        public ScriptedLocomotivePowerSupply(MSTSLocomotive locomotive)
        {
            Locomotive = locomotive;

            BatterySwitch             = new BatterySwitch(Locomotive);
            MasterKey                 = new MasterKey(Locomotive);
            ElectricTrainSupplySwitch = new ElectricTrainSupplySwitch(Locomotive);

            MainPowerSupplyState       = PowerSupplyState.PowerOff;
            AuxiliaryPowerSupplyState  = PowerSupplyState.PowerOff;
            LowVoltagePowerSupplyState = PowerSupplyState.PowerOff;
            CabPowerSupplyState        = PowerSupplyState.PowerOff;
        }
コード例 #3
0
        public virtual void Copy(IPowerSupply other)
        {
            if (other is ScriptedLocomotivePowerSupply scriptedOther)
            {
                BatterySwitch.Copy(scriptedOther.BatterySwitch);
                MasterKey.Copy(scriptedOther.MasterKey);
                ElectricTrainSupplySwitch.Copy(scriptedOther.ElectricTrainSupplySwitch);

                ScriptName = scriptedOther.ScriptName;

                PowerOnDelayS    = scriptedOther.PowerOnDelayS;
                AuxPowerOnDelayS = scriptedOther.AuxPowerOnDelayS;
            }
        }
コード例 #4
0
        public virtual void Save(BinaryWriter outf)
        {
            BatterySwitch.Save(outf);
            MasterKey.Save(outf);
            ElectricTrainSupplySwitch.Save(outf);

            outf.Write(FrontElectricTrainSupplyCableConnected);

            outf.Write(MainPowerSupplyState.ToString());
            outf.Write(AuxiliaryPowerSupplyState.ToString());
            outf.Write(ElectricTrainSupplyState.ToString());
            outf.Write(LowVoltagePowerSupplyState.ToString());
            outf.Write(BatteryState.ToString());
            outf.Write(CabPowerSupplyState.ToString());
        }
コード例 #5
0
        public virtual void Restore(BinaryReader inf)
        {
            BatterySwitch.Restore(inf);
            MasterKey.Restore(inf);
            ElectricTrainSupplySwitch.Restore(inf);

            FrontElectricTrainSupplyCableConnected = inf.ReadBoolean();

            MainPowerSupplyState       = (PowerSupplyState)Enum.Parse(typeof(PowerSupplyState), inf.ReadString());
            AuxiliaryPowerSupplyState  = (PowerSupplyState)Enum.Parse(typeof(PowerSupplyState), inf.ReadString());
            ElectricTrainSupplyState   = (PowerSupplyState)Enum.Parse(typeof(PowerSupplyState), inf.ReadString());
            LowVoltagePowerSupplyState = (PowerSupplyState)Enum.Parse(typeof(PowerSupplyState), inf.ReadString());
            BatteryState        = (PowerSupplyState)Enum.Parse(typeof(PowerSupplyState), inf.ReadString());
            CabPowerSupplyState = (PowerSupplyState)Enum.Parse(typeof(PowerSupplyState), inf.ReadString());

            firstUpdate = false;
        }
コード例 #6
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();
        }
コード例 #7
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);
        }
コード例 #8
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);
                }
            };
        }
コード例 #9
0
 public virtual void Initialize()
 {
     BatterySwitch.Initialize();
     MasterKey.Initialize();
     ElectricTrainSupplySwitch.Initialize();
 }