public override void Initialize() { PowerOnTimer = new Timer(this); PowerOnTimer.Setup(PowerOnDelayS()); AuxPowerOnTimer = new Timer(this); AuxPowerOnTimer.Setup(AuxPowerOnDelayS()); PreviousFirstEngineState = CurrentDieselEngineState(0); PreviousSecondEngineState = CurrentDieselEngineState(1); }
protected void UpdateSounds() { // First engine if ((PreviousFirstEngineState == DieselEngineState.Stopped || PreviousFirstEngineState == DieselEngineState.Stopping) && (CurrentDieselEngineState(0) == DieselEngineState.Starting || CurrentDieselEngineState(0) == DieselEngineState.Running)) { SignalEvent(TrainEvent.EnginePowerOn); } else if ((PreviousFirstEngineState == DieselEngineState.Starting || PreviousFirstEngineState == DieselEngineState.Running) && (CurrentDieselEngineState(0) == DieselEngineState.Stopping || CurrentDieselEngineState(0) == DieselEngineState.Stopped)) { SignalEvent(TrainEvent.EnginePowerOff); } PreviousFirstEngineState = CurrentDieselEngineState(0); // Second engine if ((PreviousSecondEngineState == DieselEngineState.Stopped || PreviousSecondEngineState == DieselEngineState.Stopping) && (CurrentDieselEngineState(1) == DieselEngineState.Starting || CurrentDieselEngineState(1) == DieselEngineState.Running)) { SignalEvent(TrainEvent.SecondEnginePowerOn); } else if ((PreviousSecondEngineState == DieselEngineState.Starting || PreviousSecondEngineState == DieselEngineState.Running) && (CurrentDieselEngineState(1) == DieselEngineState.Stopping || CurrentDieselEngineState(1) == DieselEngineState.Stopped)) { SignalEvent(TrainEvent.SecondEnginePowerOff); } PreviousSecondEngineState = CurrentDieselEngineState(1); }
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); } }; }