OpenBve.TrainManager.ApplyHoldBrake C# (CSharp) Method

ApplyHoldBrake() static private method

Applies or releases the hold brake
static private ApplyHoldBrake ( Train Train, bool Value ) : void
Train Train The train
Value bool Whether to apply (TRUE) or release (FALSE)
return void
		internal static void ApplyHoldBrake(Train Train, bool Value)
		{
			Train.Specs.CurrentHoldBrake.Driver = Value;
			if (Train.Plugin == null) return;
			Train.Plugin.UpdatePower();
			Train.Plugin.UpdateBrake();
		}
	}

Usage Example

示例#1
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;
            }