1 using OpenBveApi;
2 using OpenBveApi.Colors;
3 using OpenBveApi.Runtime;
4 using OpenBveApi.Trains;
5 using RouteManager2.MessageManager;
6 
7 namespace TrainManager.Trains
8 {
9 	public partial class TrainBase
10 	{
11 		/// <inheritdoc/>
RequestStop(RequestStop stopRequest)12 		public override void RequestStop(RequestStop stopRequest)
13 		{
14 			if (stopRequest.MaxCars != 0 && NumberOfCars > stopRequest.MaxCars)
15 			{
16 				//Check whether our train length is valid for this before doing anything else
17 				Cars[DriverCar].Sounds.RequestStop[2].Play(Cars[DriverCar], false);
18 				return;
19 			}
20 
21 			if (TrainManagerBase.RandomNumberGenerator.Next(0, 100) <= stopRequest.Probability)
22 			{
23 				//We have hit our probability roll
24 				if (TrainManagerBase.CurrentRoute.Stations[stopRequest.StationIndex].StopMode == StationStopMode.AllRequestStop || (IsPlayerTrain && TrainManagerBase.CurrentRoute.Stations[stopRequest.StationIndex].StopMode == StationStopMode.PlayerRequestStop))
25 				{
26 
27 					//If our train can stop at this station, set it's index accordingly
28 					Station = stopRequest.StationIndex;
29 					NextStopSkipped = StopSkipMode.None;
30 					//Play sound
31 					Cars[DriverCar].Sounds.RequestStop[0].Play(Cars[DriverCar], false);
32 				}
33 				else
34 				{
35 					//We don't meet the conditions for this request stop
36 					if (stopRequest.FullSpeed)
37 					{
38 						//Pass at linespeed, rather than braking as if for stop
39 						NextStopSkipped = StopSkipMode.Linespeed;
40 					}
41 					else
42 					{
43 						NextStopSkipped = StopSkipMode.Decelerate;
44 					}
45 
46 					//Play sound
47 					Cars[DriverCar].Sounds.RequestStop[1].Play(Cars[DriverCar], false);
48 					//If message is not empty, add it
49 					if (!string.IsNullOrEmpty(stopRequest.PassMessage) && IsPlayerTrain)
50 					{
51 						TrainManagerBase.currentHost.AddMessage(stopRequest.PassMessage, MessageDependency.None, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 10.0, null);
52 					}
53 
54 					return;
55 				}
56 
57 				//Play sound
58 				Cars[DriverCar].Sounds.RequestStop[0].Play(Cars[DriverCar], false);
59 				//If message is not empty, add it
60 				if (!string.IsNullOrEmpty(stopRequest.StopMessage) && IsPlayerTrain)
61 				{
62 					TrainManagerBase.currentHost.AddMessage(stopRequest.StopMessage, MessageDependency.None, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 10.0, null);
63 				}
64 			}
65 			else
66 			{
67 				Cars[DriverCar].Sounds.RequestStop[1].Play(Cars[DriverCar], false);
68 				if (stopRequest.FullSpeed)
69 				{
70 					//Pass at linespeed, rather than braking as if for stop
71 					NextStopSkipped = StopSkipMode.Linespeed;
72 				}
73 				else
74 				{
75 					NextStopSkipped = StopSkipMode.Decelerate;
76 				}
77 
78 				//Play sound
79 				Cars[DriverCar].Sounds.RequestStop[1].Play(Cars[DriverCar], false);
80 				//If message is not empty, add it
81 				if (!string.IsNullOrEmpty(stopRequest.PassMessage) && IsPlayerTrain)
82 				{
83 					TrainManagerBase.currentHost.AddMessage(stopRequest.PassMessage, MessageDependency.None, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 10.0, null);
84 				}
85 			}
86 		}
87 	}
88 }
89