OpenBve.TrainManager.ApplyNotch C# (CSharp) Method

ApplyNotch() static private method

static private ApplyNotch ( Train Train, int PowerValue, bool PowerRelative, int BrakeValue, bool BrakeRelative ) : void
Train Train
PowerValue int
PowerRelative bool
BrakeValue int
BrakeRelative bool
return void
		internal static void ApplyNotch(Train Train, int PowerValue, bool PowerRelative, int BrakeValue, bool BrakeRelative)
		{
			// determine notch
			int p = PowerRelative ? PowerValue + Train.Specs.CurrentPowerNotch.Driver : PowerValue;
			if (p < 0)
			{
				p = 0;
			}
			else if (p > Train.Specs.MaximumPowerNotch)
			{
				p = Train.Specs.MaximumPowerNotch;
			}
			int b = BrakeRelative ? BrakeValue + Train.Specs.CurrentBrakeNotch.Driver : BrakeValue;
			if (b < 0)
			{
				b = 0;
			}
			else if (b > Train.Specs.MaximumBrakeNotch)
			{
				b = Train.Specs.MaximumBrakeNotch;
			}
			// power sound
			if (p < Train.Specs.CurrentPowerNotch.Driver)
			{
				if (p > 0)
				{
					// down (not min)
					Sounds.SoundBuffer buffer = Train.Cars[Train.DriverCar].Sounds.MasterControllerDown.Buffer;
					if (buffer != null)
					{
						OpenBveApi.Math.Vector3 pos = Train.Cars[Train.DriverCar].Sounds.MasterControllerDown.Position;
						Sounds.PlaySound(buffer, 1.0, 1.0, pos, Train, Train.DriverCar, false);
					}
				}
				else
				{
					// min
					Sounds.SoundBuffer buffer = Train.Cars[Train.DriverCar].Sounds.MasterControllerMin.Buffer;
					if (buffer != null)
					{
						OpenBveApi.Math.Vector3 pos = Train.Cars[Train.DriverCar].Sounds.MasterControllerMin.Position;
						Sounds.PlaySound(buffer, 1.0, 1.0, pos, Train, Train.DriverCar, false);
					}
				}
			}
			else if (p > Train.Specs.CurrentPowerNotch.Driver)
			{
				if (p < Train.Specs.MaximumPowerNotch)
				{
					// up (not max)
					Sounds.SoundBuffer buffer = Train.Cars[Train.DriverCar].Sounds.MasterControllerUp.Buffer;
					if (buffer != null)
					{
						OpenBveApi.Math.Vector3 pos = Train.Cars[Train.DriverCar].Sounds.MasterControllerUp.Position;
						Sounds.PlaySound(buffer, 1.0, 1.0, pos, Train, Train.DriverCar, false);
					}
				}
				else
				{
					// max
					Sounds.SoundBuffer buffer = Train.Cars[Train.DriverCar].Sounds.MasterControllerMax.Buffer;
					if (buffer != null)
					{
						OpenBveApi.Math.Vector3 pos = Train.Cars[Train.DriverCar].Sounds.MasterControllerMax.Position;
						Sounds.PlaySound(buffer, 1.0, 1.0, pos, Train, Train.DriverCar, false);
					}
				}
			}
			// brake sound
			if (b < Train.Specs.CurrentBrakeNotch.Driver)
			{
				// brake release
				Sounds.SoundBuffer buffer = Train.Cars[Train.DriverCar].Sounds.Brake.Buffer;
				if (buffer != null)
				{
					OpenBveApi.Math.Vector3 pos = Train.Cars[Train.DriverCar].Sounds.Brake.Position;
					Sounds.PlaySound(buffer, 1.0, 1.0, pos, Train, Train.DriverCar, false);
				}
				if (b > 0)
				{
					// brake release (not min)
					buffer = Train.Cars[Train.DriverCar].Sounds.BrakeHandleRelease.Buffer;
					if (buffer != null)
					{
						OpenBveApi.Math.Vector3 pos = Train.Cars[Train.DriverCar].Sounds.BrakeHandleRelease.Position;
						Sounds.PlaySound(buffer, 1.0, 1.0, pos, Train, Train.DriverCar, false);
					}
				}
				else
				{
					// brake min
					buffer = Train.Cars[Train.DriverCar].Sounds.BrakeHandleMin.Buffer;
					if (buffer != null)
					{
						OpenBveApi.Math.Vector3 pos = Train.Cars[Train.DriverCar].Sounds.BrakeHandleMin.Position;
						Sounds.PlaySound(buffer, 1.0, 1.0, pos, Train, Train.DriverCar, false);
					}
				}
			}
			else if (b > Train.Specs.CurrentBrakeNotch.Driver)
			{
				// brake
				Sounds.SoundBuffer buffer = Train.Cars[Train.DriverCar].Sounds.BrakeHandleApply.Buffer;
				if (buffer != null)
				{
					OpenBveApi.Math.Vector3 pos = Train.Cars[Train.DriverCar].Sounds.BrakeHandleApply.Position;
					Sounds.PlaySound(buffer, 1.0, 1.0, pos, Train, Train.DriverCar, false);
				}
			}
			// apply notch
			if (Train.Specs.SingleHandle)
			{
				if (b != 0) p = 0;
			}
			Train.Specs.CurrentPowerNotch.Driver = p;
			Train.Specs.CurrentBrakeNotch.Driver = b;
			Game.AddBlackBoxEntry(Game.BlackBoxEventToken.None);
			// plugin
			if (Train.Plugin != null)
			{
				Train.Plugin.UpdatePower();
				Train.Plugin.UpdateBrake();
			}
		}	

Usage Example

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;
            }
        }
All Usage Examples Of OpenBve.TrainManager::ApplyNotch