예제 #1
0
        public virtual void Parse(string lowercasetoken, STFReader stf)
        {
            switch (lowercasetoken)
            {
            case "wagon(ortspowersupply":
                ScriptName = stf.ReadStringBlock(null);
                break;

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

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

            case "wagon(ortspowersupplycontinuouspower":
                ContinuousPowerW = stf.ReadFloatBlock(STFReader.UNITS.Power, 0f);
                break;

            case "wagon(ortspowersupplyheatingpower":
                HeatingPowerW = stf.ReadFloatBlock(STFReader.UNITS.Power, 0f);
                break;

            case "wagon(ortspowersupplyairconditioningpower":
                AirConditioningPowerW = stf.ReadFloatBlock(STFReader.UNITS.Power, 0f);
                break;

            case "wagon(ortspowersupplyairconditioningyield":
                AirConditioningYield = stf.ReadFloatBlock(STFReader.UNITS.Power, 0.9f);
                break;
            }
        }
예제 #2
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;
            }
        }
예제 #3
0
        /// <summary>
        /// Initialization when simulation starts with moving train
        /// <\summary>
        public virtual void InitializeMoving()
        {
            BatterySwitch.InitializeMoving();

            ElectricTrainSupplyState = PowerSupplyState.PowerOn;
            BatteryState             = PowerSupplyState.PowerOn;

            Script?.InitializeMoving();
        }
예제 #4
0
        public virtual void Save(BinaryWriter outf)
        {
            BatterySwitch.Save(outf);

            outf.Write(FrontElectricTrainSupplyCableConnected);

            outf.Write(ElectricTrainSupplyState.ToString());
            outf.Write(LowVoltagePowerSupplyState.ToString());
            outf.Write(BatteryState.ToString());
        }
예제 #5
0
        public virtual void Restore(BinaryReader inf)
        {
            BatterySwitch.Restore(inf);

            FrontElectricTrainSupplyCableConnected = inf.ReadBoolean();

            ElectricTrainSupplyState = (PowerSupplyState)Enum.Parse(typeof(PowerSupplyState), inf.ReadString());
            BatteryState             = (PowerSupplyState)Enum.Parse(typeof(PowerSupplyState), inf.ReadString());

            IsFirstUpdate = false;
        }
예제 #6
0
        public void Copy(ScriptedPassengerCarPowerSupply other)
        {
            BatterySwitch.Copy(other.BatterySwitch);

            ScriptName = other.ScriptName;

            PowerOnDelayS         = other.PowerOnDelayS;
            ContinuousPowerW      = other.ContinuousPowerW;
            HeatingPowerW         = other.HeatingPowerW;
            AirConditioningPowerW = other.AirConditioningPowerW;
            AirConditioningYield  = other.AirConditioningYield;
        }
예제 #7
0
        protected virtual void AssignScriptFunctions()
        {
            // AbstractScriptClass
            Script.ClockTime          = () => (float)Simulator.ClockTime;
            Script.GameTime           = () => (float)Simulator.GameTime;
            Script.PreUpdate          = () => Simulator.PreUpdate;
            Script.DistanceM          = () => Wagon.DistanceM;
            Script.SpeedMpS           = () => Math.Abs(Wagon.SpeedMpS);
            Script.Confirm            = Simulator.Confirmer.Confirm;
            Script.Message            = Simulator.Confirmer.Message;
            Script.SignalEvent        = Wagon.SignalEvent;
            Script.SignalEventToTrain = (evt) => Train?.SignalEvent(evt);

            // AbstractPowerSupply getters
            Script.CurrentElectricTrainSupplyState   = () => ElectricTrainSupplyState;
            Script.CurrentLowVoltagePowerSupplyState = () => LowVoltagePowerSupplyState;
            Script.CurrentBatteryState = () => BatteryState;
            Script.BatterySwitchOn     = () => BatterySwitch.On;

            // PassengerCarPowerSupply getters
            Script.CurrentVentilationState          = () => VentilationState;
            Script.CurrentHeatingState              = () => HeatingState;
            Script.CurrentAirConditioningState      = () => AirConditioningState;
            Script.CurrentElectricTrainSupplyPowerW = () => ElectricTrainSupplyPowerW;
            Script.CurrentHeatFlowRateW             = () => HeatFlowRateW;
            Script.ContinuousPowerW      = () => ContinuousPowerW;
            Script.HeatingPowerW         = () => HeatingPowerW;
            Script.AirConditioningPowerW = () => AirConditioningPowerW;
            Script.AirConditioningYield  = () => AirConditioningYield;
            Script.PowerOnDelayS         = () => PowerOnDelayS;
            Script.DesiredTemperatureC   = () => Wagon.DesiredCompartmentTempSetpointC;
            Script.InsideTemperatureC    = () => Wagon.CarInsideTempC;
            Script.OutsideTemperatureC   = () => Wagon.CarOutsideTempC;

            // AbstractPowerSupply setters
            Script.SetCurrentLowVoltagePowerSupplyState = (value) => LowVoltagePowerSupplyState = value;
            Script.SetCurrentBatteryState     = (value) => BatteryState = value;
            Script.SignalEventToBatterySwitch = (evt) => BatterySwitch.HandleEvent(evt);
            Script.SignalEventToPantographs   = (evt) => Wagon.Pantographs.HandleEvent(evt);
            Script.SignalEventToPantograph    = (evt, id) => Wagon.Pantographs.HandleEvent(evt, id);

            // PassengerCarPowerSupply setters
            Script.SetCurrentVentilationState          = (value) => VentilationState = value;
            Script.SetCurrentHeatingState              = (value) => HeatingState = value;
            Script.SetCurrentAirConditioningState      = (value) => AirConditioningState = value;
            Script.SetCurrentElectricTrainSupplyPowerW = (value) => {
                if (value >= 0f)
                {
                    ElectricTrainSupplyPowerW = value;
                }
            };
            Script.SetCurrentHeatFlowRateW = (value) => HeatFlowRateW = value;
        }
예제 #8
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;
        }
예제 #9
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;
            }
        }
예제 #10
0
        public virtual void Save(BinaryWriter outf)
        {
            BatterySwitch.Save(outf);

            outf.Write(FrontElectricTrainSupplyCableConnected);

            outf.Write(ElectricTrainSupplyState.ToString());
            outf.Write(LowVoltagePowerSupplyState.ToString());
            outf.Write(BatteryState.ToString());
            outf.Write(VentilationState.ToString());
            outf.Write(HeatingState.ToString());
            outf.Write(AirConditioningState.ToString());

            outf.Write(HeatFlowRateW);
        }
예제 #11
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;
        }
예제 #12
0
        public virtual void Restore(BinaryReader inf)
        {
            BatterySwitch.Restore(inf);

            FrontElectricTrainSupplyCableConnected = inf.ReadBoolean();

            ElectricTrainSupplyState   = (PowerSupplyState)Enum.Parse(typeof(PowerSupplyState), inf.ReadString());
            LowVoltagePowerSupplyState = (PowerSupplyState)Enum.Parse(typeof(PowerSupplyState), inf.ReadString());
            BatteryState         = (PowerSupplyState)Enum.Parse(typeof(PowerSupplyState), inf.ReadString());
            VentilationState     = (PowerSupplyState)Enum.Parse(typeof(PowerSupplyState), inf.ReadString());
            HeatingState         = (PowerSupplyState)Enum.Parse(typeof(PowerSupplyState), inf.ReadString());
            AirConditioningState = (PowerSupplyState)Enum.Parse(typeof(PowerSupplyState), inf.ReadString());

            HeatFlowRateW = inf.ReadSingle();

            IsFirstUpdate = false;
        }
예제 #13
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();
        }
예제 #14
0
        public virtual void Initialize()
        {
            if (!Activated)
            {
                if (ScriptName != null && ScriptName != "Default")
                {
                    Script = Simulator.ScriptManager.Load(Path.Combine(Path.GetDirectoryName(Wagon.WagFilePath), "Script"), ScriptName) as PassengerCarPowerSupply;
                }
                if (Script == null)
                {
                    Script = new DefaultPassengerCarPowerSupply();
                }

                AssignScriptFunctions();

                Script.Initialize();
                Activated = true;
            }

            BatterySwitch.Initialize();
        }
예제 #15
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);
        }
예제 #16
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);
        }
예제 #17
0
 public virtual void Initialize()
 {
     BatterySwitch.Initialize();
     MasterKey.Initialize();
     ElectricTrainSupplySwitch.Initialize();
 }
예제 #18
0
        public ScriptedPassengerCarPowerSupply(MSTSWagon wagon)
        {
            Wagon = wagon;

            BatterySwitch = new BatterySwitch(Wagon);
        }
예제 #19
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);
                }
            };
        }