ApplyAirBrakeHandle() static private method

Moves the air brake handle to the specified state
static private ApplyAirBrakeHandle ( Train Train, AirBrakeHandleState State ) : void
Train Train The train
State AirBrakeHandleState The state
return void
Exemplo n.º 1
0
        /// <summary>Jumps a train to a new station</summary>
        /// <param name="train">The train</param>
        /// <param name="stationIndex">The zero-based index of the station</param>
        internal static void JumpTrain(Train train, int stationIndex)
        {
            if (train == PlayerTrain)
            {
                for (int i = 0; i < ObjectManager.AnimatedWorldObjects.Length; i++)
                {
                    if (ObjectManager.AnimatedWorldObjects[i].FollowsTrack)
                    {
                        //Track followers should be reset if we jump between stations
                        ObjectManager.AnimatedWorldObjects[i].FrontAxleFollower.TrackPosition = ObjectManager.AnimatedWorldObjects[i].TrackPosition + ObjectManager.AnimatedWorldObjects[i].FrontAxlePosition;
                        ObjectManager.AnimatedWorldObjects[i].FrontAxleFollower.TrackPosition = ObjectManager.AnimatedWorldObjects[i].TrackPosition + ObjectManager.AnimatedWorldObjects[i].RearAxlePosition;
                        ObjectManager.AnimatedWorldObjects[i].FrontAxleFollower.UpdateWorldCoordinates(false);
                        ObjectManager.AnimatedWorldObjects[i].RearAxleFollower.UpdateWorldCoordinates(false);
                    }
                }
            }
            train.StationState = TrainStopState.Jumping;
            int stopIndex = Game.GetStopIndex(stationIndex, train.Cars.Length);

            if (stopIndex >= 0)
            {
                if (train == PlayerTrain)
                {
                    if (train.Plugin != null)
                    {
                        train.Plugin.BeginJump((OpenBveApi.Runtime.InitializationModes)Game.TrainStart);
                    }
                }
                for (int h = 0; h < train.Cars.Length; h++)
                {
                    train.Cars[h].Specs.CurrentSpeed = 0.0;
                }
                double d = Game.Stations[stationIndex].Stops[stopIndex].TrackPosition - train.Cars[0].FrontAxle.Follower.TrackPosition + train.Cars[0].FrontAxle.Position - 0.5 * train.Cars[0].Length;
                if (train == PlayerTrain)
                {
                    TrackManager.SuppressSoundEvents = true;
                }
                while (d != 0.0)
                {
                    double x;
                    if (Math.Abs(d) > 1.0)
                    {
                        x = (double)Math.Sign(d);
                    }
                    else
                    {
                        x = d;
                    }
                    for (int h = 0; h < train.Cars.Length; h++)
                    {
                        TrainManager.MoveCar(train, h, x, 0.0);
                    }
                    if (Math.Abs(d) >= 1.0)
                    {
                        d -= x;
                    }
                    else
                    {
                        break;
                    }
                }
                if (train == PlayerTrain)
                {
                    TrainManager.UnderailTrains();
                    TrackManager.SuppressSoundEvents = false;
                }
                if (train.Specs.CurrentEmergencyBrake.Driver)
                {
                    TrainManager.ApplyNotch(train, 0, false, 0, true);
                }
                else
                {
                    TrainManager.ApplyNotch(train, 0, false, train.Specs.MaximumBrakeNotch, false);
                    TrainManager.ApplyAirBrakeHandle(train, TrainManager.AirBrakeHandleState.Service);
                }
                if (Game.Sections.Length > 0)
                {
                    Game.UpdateSection(Game.Sections.Length - 1);
                }
                if (train == PlayerTrain)
                {
                    if (Game.CurrentScore.ArrivalStation <= stationIndex)
                    {
                        Game.CurrentScore.ArrivalStation = stationIndex + 1;
                    }
                }
                if (train == PlayerTrain)
                {
                    if (Game.Stations[stationIndex].ArrivalTime >= 0.0)
                    {
                        Game.SecondsSinceMidnight = Game.Stations[stationIndex].ArrivalTime;
                    }
                    else if (Game.Stations[stationIndex].DepartureTime >= 0.0)
                    {
                        Game.SecondsSinceMidnight = Game.Stations[stationIndex].DepartureTime - Game.Stations[stationIndex].StopTime;
                    }
                }
                for (int i = 0; i < train.Cars.Length; i++)
                {
                    train.Cars[i].Specs.AnticipatedLeftDoorsOpened  = Game.Stations[stationIndex].OpenLeftDoors;
                    train.Cars[i].Specs.AnticipatedRightDoorsOpened = Game.Stations[stationIndex].OpenRightDoors;
                }
                if (train == PlayerTrain)
                {
                    Game.CurrentScore.DepartureStation = stationIndex;
                    Game.CurrentInterface = Game.InterfaceType.Normal;
                    //Game.Messages = new Game.Message[] { };
                }
                ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
                TrainManager.UpdateTrainObjects(0.0, true);
                if (train == PlayerTrain)
                {
                    if (train.Plugin != null)
                    {
                        train.Plugin.EndJump();
                    }
                }
                train.StationState = TrainStopState.Pending;
            }
        }
Exemplo n.º 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;
            }