Represents the handles of the cab.
Example #1
0
			// --- constructors ---
			/// <summary>Creates a new instance of this class.</summary>
			/// <param name="handles">The handles</param>
			internal ReadOnlyHandles(Handles handles) {
				this.MyReverser = handles.Reverser;
				this.MyPowerNotch = handles.PowerNotch;
				this.MyBrakeNotch = handles.BrakeNotch;
				this.MyConstSpeed = handles.ConstSpeed;
			}
Example #2
0
			/// <summary>Sets the driver handles or the virtual handles.</summary>
			/// <param name="handles">The handles.</param>
			/// <param name="virtualHandles">Whether to set the virtual handles.</param>
			private void SetHandles(Handles handles, bool virtualHandles) {
				/*
				 * Process the handles.
				 */
				if (this.Train.Specs.SingleHandle & handles.BrakeNotch != 0) {
					handles.PowerNotch = 0;
				}
				/*
				 * Process the reverser.
				 */
				if (handles.Reverser >= -1 & handles.Reverser <= 1) {
					if (virtualHandles) {
						this.Train.Specs.CurrentReverser.Actual = handles.Reverser;
					} else {
						TrainManager.ApplyReverser(this.Train, handles.Reverser, false);
					}
				} else {
					if (virtualHandles) {
						this.Train.Specs.CurrentReverser.Actual = this.Train.Specs.CurrentReverser.Driver;
					}
					this.PluginValid = false;
				}
				/*
				 * Process the power.
				 * */
				if (handles.PowerNotch >= 0 & handles.PowerNotch <= this.Train.Specs.MaximumPowerNotch) {
					if (virtualHandles) {
						this.Train.Specs.CurrentPowerNotch.Safety = handles.PowerNotch;
					} else {
						TrainManager.ApplyNotch(this.Train, handles.PowerNotch, false, 0, true);
					}
				} else {
					if (virtualHandles) {
						this.Train.Specs.CurrentPowerNotch.Safety = this.Train.Specs.CurrentPowerNotch.Driver;
					}
					this.PluginValid = false;
				}
//				if (handles.BrakeNotch != 0) {
//					if (virtualHandles) {
//						this.Train.Specs.CurrentPowerNotch.Safety = 0;
//					}
//				}
				/*
				 * Process the brakes.
				 * */
				if (virtualHandles) {
					this.Train.Specs.CurrentEmergencyBrake.Safety = false;
					this.Train.Specs.CurrentHoldBrake.Actual = false;
				}
				if (this.Train.Cars[this.Train.DriverCar].Specs.BrakeType == TrainManager.CarBrakeType.AutomaticAirBrake) {
					if (handles.BrakeNotch == 0) {
						if (virtualHandles) {
							this.Train.Specs.AirBrake.Handle.Safety = TrainManager.AirBrakeHandleState.Release;
						} else {
							TrainManager.UnapplyEmergencyBrake(this.Train);
							TrainManager.ApplyAirBrakeHandle(this.Train, TrainManager.AirBrakeHandleState.Release);
						}
					} else if (handles.BrakeNotch == 1) {
						if (virtualHandles) {
							this.Train.Specs.AirBrake.Handle.Safety = TrainManager.AirBrakeHandleState.Lap;
						} else {
							TrainManager.UnapplyEmergencyBrake(this.Train);
							TrainManager.ApplyAirBrakeHandle(this.Train, TrainManager.AirBrakeHandleState.Lap);
						}
					} else if (handles.BrakeNotch == 2) {
						if (virtualHandles) {
							this.Train.Specs.AirBrake.Handle.Safety = TrainManager.AirBrakeHandleState.Service;
						} else {
							TrainManager.UnapplyEmergencyBrake(this.Train);
							TrainManager.ApplyAirBrakeHandle(this.Train, TrainManager.AirBrakeHandleState.Release);
						}
					} else if (handles.BrakeNotch == 3) {
						if (virtualHandles) {
							this.Train.Specs.AirBrake.Handle.Safety = TrainManager.AirBrakeHandleState.Service;
							this.Train.Specs.CurrentEmergencyBrake.Safety = true;
						} else {
							TrainManager.ApplyAirBrakeHandle(this.Train, TrainManager.AirBrakeHandleState.Service);
							TrainManager.ApplyEmergencyBrake(this.Train);
						}
					} else {
						this.PluginValid = false;
					}
				} else {
					if (this.Train.Specs.HasHoldBrake) {
						if (handles.BrakeNotch == this.Train.Specs.MaximumBrakeNotch + 2) {
							if (virtualHandles) {
								this.Train.Specs.CurrentEmergencyBrake.Safety = true;
								this.Train.Specs.CurrentBrakeNotch.Safety = this.Train.Specs.MaximumBrakeNotch;
							} else {
								TrainManager.ApplyHoldBrake(this.Train, false);
								TrainManager.ApplyNotch(this.Train, 0, true, this.Train.Specs.MaximumBrakeNotch, false);
								TrainManager.ApplyEmergencyBrake(this.Train);
							}
						} else if (handles.BrakeNotch >= 2 & handles.BrakeNotch <= this.Train.Specs.MaximumBrakeNotch + 1) {
							if (virtualHandles) {
								this.Train.Specs.CurrentBrakeNotch.Safety = handles.BrakeNotch - 1;
							} else {
								TrainManager.UnapplyEmergencyBrake(this.Train);
								TrainManager.ApplyHoldBrake(this.Train, false);
								TrainManager.ApplyNotch(this.Train, 0, true, handles.BrakeNotch - 1, false);
							}
						} else if (handles.BrakeNotch == 1) {
							if (virtualHandles) {
								this.Train.Specs.CurrentBrakeNotch.Safety = 0;
								this.Train.Specs.CurrentHoldBrake.Actual = true;
							} else {
								TrainManager.UnapplyEmergencyBrake(this.Train);
								TrainManager.ApplyNotch(this.Train, 0, true, 0, false);
								TrainManager.ApplyHoldBrake(this.Train, true);
							}
						} else if (handles.BrakeNotch == 0) {
							if (virtualHandles) {
								this.Train.Specs.CurrentBrakeNotch.Safety = 0;
							} else {
								TrainManager.UnapplyEmergencyBrake(this.Train);
								TrainManager.ApplyNotch(this.Train, 0, true, 0, false);
								TrainManager.ApplyHoldBrake(this.Train, false);
							}
						} else {
							if (virtualHandles) {
								this.Train.Specs.CurrentBrakeNotch.Safety = this.Train.Specs.CurrentBrakeNotch.Driver;
							}
							this.PluginValid = false;
						}
					} else {
						if (handles.BrakeNotch == this.Train.Specs.MaximumBrakeNotch + 1) {
							if (virtualHandles) {
								this.Train.Specs.CurrentEmergencyBrake.Safety = true;
								this.Train.Specs.CurrentBrakeNotch.Safety = this.Train.Specs.MaximumBrakeNotch;
							} else {
								TrainManager.ApplyHoldBrake(this.Train, false);
								TrainManager.ApplyEmergencyBrake(this.Train);
							}
						} else if (handles.BrakeNotch >= 0 & handles.BrakeNotch <= this.Train.Specs.MaximumBrakeNotch | this.Train.Specs.CurrentBrakeNotch.DelayedChanges.Length == 0) {
							if (virtualHandles) {
								this.Train.Specs.CurrentBrakeNotch.Safety = handles.BrakeNotch;
							} else {
								TrainManager.UnapplyEmergencyBrake(this.Train);
								TrainManager.ApplyNotch(this.Train, 0, true, handles.BrakeNotch, false);
							}
						} else {
							if (virtualHandles) {
								this.Train.Specs.CurrentBrakeNotch.Safety = this.Train.Specs.CurrentBrakeNotch.Driver;
							}
							this.PluginValid = false;
						}
					}
				}
				/*
				 * Process the const speed system.
				 * */
				this.Train.Specs.CurrentConstSpeed = handles.ConstSpeed & this.Train.Specs.HasConstSpeed;
			}
Example #3
0
        /// <summary>Called every frame to update the plugin.</summary>
        public void UpdatePlugin()
        {
            if (Train.Cars == null || Train.Cars.Length == 0)
            {
                return;
            }

            /*
             * Prepare the vehicle state.
             * */
            double location = this.Train.Cars[0].FrontAxle.Follower.TrackPosition - this.Train.Cars[0].FrontAxle.Position + 0.5 * this.Train.Cars[0].Length;

            //If the list of stations has not been loaded, do so
            if (!StationsLoaded)
            {
                currentRouteStations = new List <Station>();
                int s = 0;
                foreach (RouteStation selectedStation in TrainManagerBase.CurrentRoute.Stations)
                {
                    double stopPosition = -1;
                    int    stopIdx      = TrainManagerBase.CurrentRoute.Stations[s].GetStopIndex(Train.NumberOfCars);
                    if (selectedStation.Stops.Length != 0)
                    {
                        stopPosition = selectedStation.Stops[stopIdx].TrackPosition;
                    }

                    Station i = new Station(selectedStation, stopPosition);
                    currentRouteStations.Add(i);
                    s++;
                }

                StationsLoaded = true;
            }

            //End of additions
            double       speed       = this.Train.Cars[this.Train.DriverCar].Specs.PerceivedSpeed;
            double       bcPressure  = this.Train.Cars[this.Train.DriverCar].CarBrake.brakeCylinder.CurrentPressure;
            double       mrPressure  = this.Train.Cars[this.Train.DriverCar].CarBrake.mainReservoir.CurrentPressure;
            double       erPressure  = this.Train.Cars[this.Train.DriverCar].CarBrake.equalizingReservoir.CurrentPressure;
            double       bpPressure  = this.Train.Cars[this.Train.DriverCar].CarBrake.brakePipe.CurrentPressure;
            double       sapPressure = this.Train.Cars[this.Train.DriverCar].CarBrake.straightAirPipe.CurrentPressure;
            VehicleState vehicle     = new VehicleState(location, new Speed(speed), bcPressure, mrPressure, erPressure, bpPressure, sapPressure, this.Train.Cars[0].FrontAxle.Follower);

            /*
             * Prepare the preceding vehicle state.
             * */


            PrecedingVehicleState precedingVehicle;

            try
            {
                AbstractTrain closestTrain = TrainManagerBase.currentHost.ClosestTrain(this.Train);
                precedingVehicle = closestTrain != null ? new PrecedingVehicleState(closestTrain.RearCarTrackPosition(), closestTrain.RearCarTrackPosition() - location, new Speed(closestTrain.CurrentSpeed)) : new PrecedingVehicleState(Double.MaxValue, Double.MaxValue - location, new Speed(0.0));
            }
            catch
            {
                precedingVehicle = null;
            }

            /*
             * Get the driver handles.
             * */
            OpenBveApi.Runtime.Handles handles = GetHandles();

            /*
             * Update the plugin.
             * */
            double totalTime   = TrainManagerBase.currentHost.InGameTime;
            double elapsedTime = TrainManagerBase.currentHost.InGameTime - LastTime;

            ElapseData data = new ElapseData(vehicle, precedingVehicle, handles, this.Train.SafetySystems.DoorInterlockState, new Time(totalTime), new Time(elapsedTime), currentRouteStations, TrainManagerBase.Renderer.Camera.CurrentMode, Translations.CurrentLanguageCode, this.Train.Destination);
            ElapseData inputDevicePluginData = data;

            LastTime = TrainManagerBase.currentHost.InGameTime;
            Elapse(ref data);
            this.PluginMessage = data.DebugMessage;
            this.Train.SafetySystems.DoorInterlockState = data.DoorInterlockState;
            DisableTimeAcceleration = data.DisableTimeAcceleration;
            for (int i = 0; i < InputDevicePlugin.AvailablePluginInfos.Count; i++)
            {
                if (InputDevicePlugin.AvailablePluginInfos[i].Status == InputDevicePlugin.PluginInfo.PluginStatus.Enable)
                {
                    InputDevicePlugin.AvailablePlugins[i].SetElapseData(inputDevicePluginData);
                }
            }

            /*
             * Set the virtual handles.
             * */
            this.PluginValid = true;
            SetHandles(data.Handles, true);
            this.Train.Destination = data.Destination;
        }
Example #4
0
        /// <summary>Sets the driver handles or the virtual handles.</summary>
        /// <param name="handles">The handles.</param>
        /// <param name="virtualHandles">Whether to set the virtual handles.</param>
        private void SetHandles(OpenBveApi.Runtime.Handles handles, bool virtualHandles)
        {
            /*
             * Process the handles.
             */
            if (this.Train.Handles.HandleType == HandleType.SingleHandle & handles.BrakeNotch != 0)
            {
                handles.PowerNotch = 0;
            }

            /*
             * Process the reverser.
             */
            if (handles.Reverser >= -1 & handles.Reverser <= 1)
            {
                if (virtualHandles)
                {
                    this.Train.Handles.Reverser.Actual = (ReverserPosition)handles.Reverser;
                }
                else
                {
                    this.Train.Handles.Reverser.ApplyState((ReverserPosition)handles.Reverser);
                }
            }
            else
            {
                if (virtualHandles)
                {
                    this.Train.Handles.Reverser.Actual = this.Train.Handles.Reverser.Driver;
                }

                this.PluginValid = false;
            }

            /*
             * Process the power.
             * */
            if (handles.PowerNotch >= 0 & handles.PowerNotch <= this.Train.Handles.Power.MaximumNotch)
            {
                if (virtualHandles)
                {
                    this.Train.Handles.Power.Safety = handles.PowerNotch;
                }
                else
                {
                    Train.Handles.Power.ApplyState(handles.PowerNotch, false, true);
                }
            }
            else
            {
                if (virtualHandles)
                {
                    this.Train.Handles.Power.Safety = this.Train.Handles.Power.Driver;
                }

                this.PluginValid = false;
            }

            /*
             * Process the brakes.
             * */
            if (virtualHandles)
            {
                this.Train.Handles.EmergencyBrake.Safety = false;
                this.Train.Handles.HoldBrake.Actual      = false;
            }

            if (this.Train.Handles.Brake is AirBrakeHandle)
            {
                if (handles.BrakeNotch == 0)
                {
                    if (virtualHandles)
                    {
                        this.Train.Handles.Brake.Safety = (int)AirBrakeHandleState.Release;
                    }
                    else
                    {
                        this.Train.Handles.EmergencyBrake.Release();
                        Train.Handles.Brake.ApplyState(AirBrakeHandleState.Release);
                    }
                }
                else if (handles.BrakeNotch == 1)
                {
                    if (virtualHandles)
                    {
                        this.Train.Handles.Brake.Safety = (int)AirBrakeHandleState.Lap;
                    }
                    else
                    {
                        this.Train.Handles.EmergencyBrake.Release();
                        Train.Handles.Brake.ApplyState(AirBrakeHandleState.Lap);
                    }
                }
                else if (handles.BrakeNotch == 2)
                {
                    if (virtualHandles)
                    {
                        this.Train.Handles.Brake.Safety = (int)AirBrakeHandleState.Service;
                    }
                    else
                    {
                        this.Train.Handles.EmergencyBrake.Release();
                        Train.Handles.Brake.ApplyState(AirBrakeHandleState.Release);
                    }
                }
                else if (handles.BrakeNotch == 3)
                {
                    if (virtualHandles)
                    {
                        this.Train.Handles.Brake.Safety          = (int)AirBrakeHandleState.Service;
                        this.Train.Handles.EmergencyBrake.Safety = true;
                    }
                    else
                    {
                        Train.Handles.Brake.ApplyState(AirBrakeHandleState.Service);
                        this.Train.Handles.EmergencyBrake.Apply();
                    }
                }
                else
                {
                    this.PluginValid = false;
                }
            }
            else
            {
                if (this.Train.Handles.HasHoldBrake)
                {
                    if (handles.BrakeNotch == this.Train.Handles.Brake.MaximumNotch + 2)
                    {
                        if (virtualHandles)
                        {
                            this.Train.Handles.EmergencyBrake.Safety = true;
                            this.Train.Handles.Brake.Safety          = this.Train.Handles.Brake.MaximumNotch;
                        }
                        else
                        {
                            this.Train.Handles.HoldBrake.ApplyState(false);
                            this.Train.Handles.Brake.ApplyState(this.Train.Handles.Brake.MaximumNotch, false, true);
                            this.Train.Handles.EmergencyBrake.Apply();
                        }
                    }
                    else if (handles.BrakeNotch >= 2 & handles.BrakeNotch <= this.Train.Handles.Brake.MaximumNotch + 1)
                    {
                        if (virtualHandles)
                        {
                            this.Train.Handles.Brake.Safety = handles.BrakeNotch - 1;
                        }
                        else
                        {
                            this.Train.Handles.EmergencyBrake.Release();
                            this.Train.Handles.HoldBrake.ApplyState(false);
                            this.Train.Handles.Brake.ApplyState(handles.BrakeNotch - 1, false, true);
                        }
                    }
                    else if (handles.BrakeNotch == 1)
                    {
                        if (virtualHandles)
                        {
                            this.Train.Handles.Brake.Safety     = 0;
                            this.Train.Handles.HoldBrake.Actual = true;
                        }
                        else
                        {
                            this.Train.Handles.EmergencyBrake.Release();
                            this.Train.Handles.Brake.ApplyState(0, false, true);
                            this.Train.Handles.HoldBrake.ApplyState(true);
                        }
                    }
                    else if (handles.BrakeNotch == 0)
                    {
                        if (virtualHandles)
                        {
                            this.Train.Handles.Brake.Safety = 0;
                        }
                        else
                        {
                            this.Train.Handles.EmergencyBrake.Release();
                            this.Train.Handles.Brake.ApplyState(0, false, true);
                            this.Train.Handles.HoldBrake.ApplyState(false);
                        }
                    }
                    else
                    {
                        if (virtualHandles)
                        {
                            this.Train.Handles.Brake.Safety = this.Train.Handles.Brake.Driver;
                        }

                        this.PluginValid = false;
                    }
                }
                else
                {
                    if (handles.BrakeNotch == this.Train.Handles.Brake.MaximumNotch + 1)
                    {
                        if (virtualHandles)
                        {
                            this.Train.Handles.EmergencyBrake.Safety = true;
                            this.Train.Handles.Brake.Safety          = this.Train.Handles.Brake.MaximumNotch;
                        }
                        else
                        {
                            this.Train.Handles.HoldBrake.ApplyState(false);
                            this.Train.Handles.EmergencyBrake.Apply();
                        }
                    }
                    else if (handles.BrakeNotch >= 0 & handles.BrakeNotch <= this.Train.Handles.Brake.MaximumNotch | this.Train.Handles.Brake.DelayedChanges.Length == 0)
                    {
                        if (virtualHandles)
                        {
                            this.Train.Handles.Brake.Safety = handles.BrakeNotch;
                        }
                        else
                        {
                            this.Train.Handles.EmergencyBrake.Release();
                            this.Train.Handles.Brake.ApplyState(handles.BrakeNotch, false, true);
                        }
                    }
                    else
                    {
                        if (virtualHandles)
                        {
                            this.Train.Handles.Brake.Safety = this.Train.Handles.Brake.Driver;
                        }

                        this.PluginValid = false;
                    }
                }
            }

            /*
             * Process the const speed system.
             * */
            this.Train.Specs.CurrentConstSpeed  = handles.ConstSpeed & this.Train.Specs.HasConstSpeed;
            this.Train.Handles.HoldBrake.Actual = handles.HoldBrake & this.Train.Handles.HasHoldBrake;
        }
Example #5
0
 // --- constructors ---
 /// <summary>Creates a new instance of this class.</summary>
 /// <param name="vehicle">The state of the train.</param>
 /// <param name="precedingVehicle">The state of the preceding train, or a null reference if there is no preceding train.</param>
 /// <param name="handles">The virtual handles.</param>
 /// <param name="totalTime">The current absolute time.</param>
 /// <param name="elapsedTime">The elapsed time since the last call to Elapse.</param>
 public ElapseData(VehicleState vehicle, PrecedingVehicleState precedingVehicle, Handles handles, Time totalTime, Time elapsedTime)
 {
     this.MyVehicle = vehicle;
     this.MyPrecedingVehicle = precedingVehicle;
     this.MyHandles = handles;
     this.MyTotalTime = totalTime;
     this.MyElapsedTime = elapsedTime;
     this.MyDebugMessage = null;
 }
Example #6
0
 // --- constructors ---
 /// <summary>Creates a new instance of this class.</summary>
 /// <param name="handles">The driver handles.</param>
 public AIData(Handles handles)
 {
     this.MyHandles = handles;
     this.MyResponse = AIResponse.None;
 }
Example #7
0
		// --- constructors ---
		/// <summary>Creates a new instance of this class.</summary>
		/// <param name="vehicle">The state of the train.</param>
		/// <param name="precedingVehicle">The state of the preceding train, or a null reference if there is no preceding train.</param>
		/// <param name="handles">The virtual handles.</param>
		/// <param name="totalTime">The current absolute time.</param>
		/// <param name="elapsedTime">The elapsed time since the last call to Elapse.</param>
		/// <param name="stations">The current route's list of stations.</param>
		/// <param name="cameraView">The current camera view mode</param>
		/// <param name="languageCode">The current language code</param>
		public ElapseData(VehicleState vehicle, PrecedingVehicleState precedingVehicle, Handles handles, Time totalTime, Time elapsedTime, List<Station> stations, CameraViewMode cameraView, string languageCode) {
			this.MyVehicle = vehicle;
			this.MyPrecedingVehicle = precedingVehicle;
			this.MyHandles = handles;
			this.MyTotalTime = totalTime;
			this.MyElapsedTime = elapsedTime;
			this.MyDebugMessage = null;
			this.MyStations = stations;
			this.MyCameraViewMode = cameraView;
			this.MyLanguageCode = languageCode;
		}