OpenBve.TrainManager.JumpTrain C# (CSharp) Метод

JumpTrain() статический приватный Метод

Jumps a train to a new station
static private JumpTrain ( Train train, int stationIndex ) : void
train Train The train
stationIndex int The zero-based index of the station
Результат void
		internal static void JumpTrain(Train train, int stationIndex)
		{
			train.StationState = TrainStopState.Pending;
			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].FrontAxlePosition - 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();
					}
				}
			}
		}
	}

Usage Example

Пример #1
0
        //
        // PROCESS MENU COMMAND
        //
        /// <summary>Processes a user command for the current menu</summary>
        /// <param name="cmd">The command to apply to the current menu</param>
        /// <param name="timeElapsed">The time elapsed since previous frame</param>
        internal void ProcessCommand(Translations.Command cmd, double timeElapsed)
        {
            if (CurrMenu < 0)
            {
                return;
            }
            // MenuBack is managed independently from single menu data
            if (cmd == Translations.Command.MenuBack)
            {
                PopMenu();
                return;
            }

            SingleMenu menu = Menus[CurrMenu];

            if (menu.Selection == SelectionNone)                // if menu has no selection, do nothing
            {
                return;
            }
            switch (cmd)
            {
            case Translations.Command.MenuUp:                          // UP
                if (menu.Selection > 0 &&
                    !(menu.Items[menu.Selection - 1] is MenuCaption))
                {
                    menu.Selection--;
                    PositionMenu();
                }
                break;

            case Translations.Command.MenuDown:                        // DOWN
                if (menu.Selection < menu.Items.Length - 1)
                {
                    menu.Selection++;
                    PositionMenu();
                }
                break;

            //			case Translations.Command.MenuBack:	// ESC:	managed above
            //				break;
            case Translations.Command.MenuEnter:                       // ENTER
                if (menu.Items[menu.Selection] is MenuCommand)
                {
                    MenuCommand menuItem = (MenuCommand)menu.Items[menu.Selection];
                    switch (menuItem.Tag)
                    {
                    // menu management commands
                    case MenuTag.MenuBack:                                                  // BACK TO PREVIOUS MENU
                        Menu.instance.PopMenu();
                        break;

                    case MenuTag.MenuJumpToStation:                                         // TO STATIONS MENU
                        Menu.instance.PushMenu(MenuType.JumpToStation);
                        break;

                    case MenuTag.MenuExitToMainMenu:                                        // TO EXIT MENU
                        Menu.instance.PushMenu(MenuType.ExitToMainMenu);
                        break;

                    case MenuTag.MenuQuit:                                                  // TO QUIT MENU
                        Menu.instance.PushMenu(MenuType.Quit);
                        break;

                    case MenuTag.MenuControls:                                              // TO CONTROLS MENU
                        Menu.instance.PushMenu(MenuType.Controls);
                        break;

                    case MenuTag.BackToSim:                                                 // OUT OF MENU BACK TO SIMULATION
                        Reset();
                        Game.PreviousInterface = Game.InterfaceType.Menu;
                        Game.CurrentInterface  = Game.InterfaceType.Normal;
                        break;

                    // simulation commands
                    case MenuTag.JumpToStation:                                             // JUMP TO STATION
                        Reset();
                        TrainManager.JumpTrain(TrainManager.PlayerTrain, menuItem.Data);
                        TrainManager.JumpTFO();
                        break;

                    case MenuTag.ExitToMainMenu:                                            // BACK TO MAIN MENU
                        Reset();
                        Program.RestartArguments =
                            Interface.CurrentOptions.GameMode == GameMode.Arcade ? "/review" : "";
                        MainLoop.Quit = MainLoop.QuitMode.ExitToMenu;
                        break;

                    case MenuTag.Control:                                                   // CONTROL CUSTOMIZATION
                        PushMenu(MenuType.Control, ((MenuCommand)menu.Items[menu.Selection]).Data);
                        isCustomisingControl = true;
                        CustomControlIdx     = ((MenuCommand)menu.Items[menu.Selection]).Data;
                        break;

                    case MenuTag.Quit:                                                      // QUIT PROGRAMME
                        Reset();
                        MainLoop.Quit = MainLoop.QuitMode.QuitProgram;
                        break;
                    }
                }
                break;

            case Translations.Command.MiscFullscreen:
                // fullscreen
                Screen.ToggleFullscreen();
                break;

            case Translations.Command.MiscMute:
                // mute
                Program.Sounds.GlobalMute = !Program.Sounds.GlobalMute;
                Program.Sounds.Update(timeElapsed, Interface.CurrentOptions.SoundModel);
                break;
            }
        }