// --- constructors --- /// <summary>Creates a new train without any devices installed.</summary> /// <param name="panel">The array of panel variables.</param> /// <param name="playSound">The delegate to play sounds.</param> internal Train(int[] panel, PlaySoundDelegate playSound) { this.PluginInitializing = false; this.Specs = new VehicleSpecs(0, BrakeTypes.ElectromagneticStraightAirBrake, 0, false, 0); this.State = new VehicleState(0.0, new Speed(0.0), 0.0, 0.0, 0.0, 0.0, 0.0); this.Handles = new ReadOnlyHandles(new Handles(0, 0, 0, false)); this.Doors = DoorStates.None; this.Panel = panel; this.Sounds = new Sounds(playSound); this.AI = new AI(this); }
/// <summary>Called every frame to update the plugin.</summary> internal void UpdatePlugin() { /* * Prepare the vehicle state. * */ double location = this.Train.Cars[0].FrontAxle.Follower.TrackPosition - this.Train.Cars[0].FrontAxlePosition + 0.5 * this.Train.Cars[0].Length; double speed = this.Train.Cars[this.Train.DriverCar].Specs.CurrentPerceivedSpeed; double bcPressure = this.Train.Cars[this.Train.DriverCar].Specs.AirBrake.BrakeCylinderCurrentPressure; double mrPressure = this.Train.Cars[this.Train.DriverCar].Specs.AirBrake.MainReservoirCurrentPressure; double erPressure = this.Train.Cars[this.Train.DriverCar].Specs.AirBrake.EqualizingReservoirCurrentPressure; double bpPressure = this.Train.Cars[this.Train.DriverCar].Specs.AirBrake.BrakePipeCurrentPressure; double sapPressure = this.Train.Cars[this.Train.DriverCar].Specs.AirBrake.StraightAirPipeCurrentPressure; VehicleState vehicle = new VehicleState(location, new Speed(speed), bcPressure, mrPressure, erPressure, bpPressure, sapPressure); /* * Prepare the preceding vehicle state. * */ double bestLocation = double.MaxValue; double bestSpeed = 0.0; for (int i = 0; i < TrainManager.Trains.Length; i++) { if (TrainManager.Trains[i] != this.Train & TrainManager.Trains[i].State == TrainManager.TrainState.Available) { int c = TrainManager.Trains[i].Cars.Length - 1; double z = TrainManager.Trains[i].Cars[c].RearAxle.Follower.TrackPosition - TrainManager.Trains[i].Cars[c].RearAxlePosition - 0.5 * TrainManager.Trains[i].Cars[c].Length; if (z >= location & z < bestLocation) { bestLocation = z; bestSpeed = TrainManager.Trains[i].Specs.CurrentAverageSpeed; } } } PrecedingVehicleState precedingVehicle; if (bestLocation != double.MaxValue) { precedingVehicle = new PrecedingVehicleState(bestLocation, bestLocation - location, new Speed(bestSpeed)); } else { precedingVehicle = null; } /* * Get the driver handles. * */ Handles handles = GetHandles(); /* * Update the plugin. * */ double totalTime = Game.SecondsSinceMidnight; double elapsedTime = Game.SecondsSinceMidnight - LastTime; ElapseData data = new ElapseData(vehicle, precedingVehicle, handles, new Time(totalTime), new Time(elapsedTime)); LastTime = Game.SecondsSinceMidnight; Elapse(data); this.PluginMessage = data.DebugMessage; /* * Set the virtual handles. * */ this.PluginValid = true; SetHandles(data.Handles, true); }
/// <summary>Called every frame to update the plugin.</summary> internal void UpdatePlugin() { /* * Prepare the vehicle state. * */ double location = this.Train.Cars[0].FrontAxle.Follower.TrackPosition - this.Train.Cars[0].FrontAxlePosition + 0.5 * this.Train.Cars[0].Length; //Curve Radius, Cant and Pitch Added double CurrentRadius = this.Train.Cars[0].FrontAxle.Follower.CurveRadius; double CurrentCant = this.Train.Cars[0].FrontAxle.Follower.CurveCant; double CurrentPitch = this.Train.Cars[0].FrontAxle.Follower.Pitch; //If the list of stations has not been loaded, do so if (!StationsLoaded) { currentRouteStations = new List<Station>(); foreach (Game.Station selectedStation in Game.Stations) { Station i = new Station { Name = selectedStation.Name, ArrivalTime = selectedStation.ArrivalTime, DepartureTime = selectedStation.DepartureTime, StopTime = selectedStation.StopTime, OpenLeftDoors = selectedStation.OpenLeftDoors, OpenRightDoors = selectedStation.OpenRightDoors, ForceStopSignal = selectedStation.ForceStopSignal, DefaultTrackPosition = selectedStation.DefaultTrackPosition }; currentRouteStations.Add(i); } StationsLoaded = true; } //End of additions double speed = this.Train.Cars[this.Train.DriverCar].Specs.CurrentPerceivedSpeed; double bcPressure = this.Train.Cars[this.Train.DriverCar].Specs.AirBrake.BrakeCylinderCurrentPressure; double mrPressure = this.Train.Cars[this.Train.DriverCar].Specs.AirBrake.MainReservoirCurrentPressure; double erPressure = this.Train.Cars[this.Train.DriverCar].Specs.AirBrake.EqualizingReservoirCurrentPressure; double bpPressure = this.Train.Cars[this.Train.DriverCar].Specs.AirBrake.BrakePipeCurrentPressure; double sapPressure = this.Train.Cars[this.Train.DriverCar].Specs.AirBrake.StraightAirPipeCurrentPressure; VehicleState vehicle = new VehicleState(location, new Speed(speed), bcPressure, mrPressure, erPressure, bpPressure, sapPressure, CurrentRadius, CurrentCant, CurrentPitch); /* * Prepare the preceding vehicle state. * */ double bestLocation = double.MaxValue; double bestSpeed = 0.0; for (int i = 0; i < TrainManager.Trains.Length; i++) { if (TrainManager.Trains[i] != this.Train & TrainManager.Trains[i].State == TrainManager.TrainState.Available) { int c = TrainManager.Trains[i].Cars.Length - 1; double z = TrainManager.Trains[i].Cars[c].RearAxle.Follower.TrackPosition - TrainManager.Trains[i].Cars[c].RearAxlePosition - 0.5 * TrainManager.Trains[i].Cars[c].Length; if (z >= location & z < bestLocation) { bestLocation = z; bestSpeed = TrainManager.Trains[i].Specs.CurrentAverageSpeed; } } } var precedingVehicle = bestLocation != double.MaxValue ? new PrecedingVehicleState(bestLocation, bestLocation - location, new Speed(bestSpeed)) : null; /* * Get the driver handles. * */ Handles handles = GetHandles(); /* * Update the plugin. * */ double totalTime = Game.SecondsSinceMidnight; double elapsedTime = Game.SecondsSinceMidnight - LastTime; /* * Set the current camera view mode * Could probably do away with the CurrentCameraViewMode and use a direct cast?? * */ CurrentCameraViewMode = (OpenBveApi.Runtime.CameraViewMode)World.CameraMode; ElapseData data = new ElapseData(vehicle, precedingVehicle, handles, new Time(totalTime), new Time(elapsedTime), currentRouteStations, CurrentCameraViewMode, Interface.CurrentLanguageCode); LastTime = Game.SecondsSinceMidnight; Elapse(data); this.PluginMessage = data.DebugMessage; DisableTimeAcceleration = data.DisableTimeAcceleration; /* * Set the virtual handles. * */ this.PluginValid = true; SetHandles(data.Handles, true); }
/// <summary>Is called when a key is pressed.</summary> /// <param name="key">The key.</param> internal void KeyDown(VirtualKeys key) { if (key == VirtualKeys.D) { // --- enable safety systems --- if (this.AtsSx != null) { if (this.AtsSx.State == AtsSx.States.Disabled) { this.AtsSx.State = AtsSx.States.Suppressed; } } if (this.AtsP != null) { if (this.AtsP.State == AtsP.States.Disabled) { this.AtsP.State = AtsP.States.Suppressed; } } if (this.Atc != null) { if (this.Atc.State == Atc.States.Disabled) { this.Atc.State = Atc.States.Suppressed; } } } else if (key == VirtualKeys.E) { // --- disable safety systems --- if (this.AtsSx != null) { if (this.AtsSx.State != AtsSx.States.Disabled) { this.AtsSx.State = AtsSx.States.Disabled; } } if (this.AtsP != null) { if (this.AtsP.State != AtsP.States.Disabled) { this.AtsP.State = AtsP.States.Disabled; } } if (this.Atc != null) { if (this.Atc.State != Atc.States.Disabled) { this.Atc.State = Atc.States.Disabled; } } } else { // --- other functions --- foreach (Device device in this.Devices) { device.KeyDown(key); } } }
/// <summary>Is called every frame.</summary> /// <param name="data">The data.</param> internal void Elapse(ElapseData data) { this.PluginInitializing = false; if (data.ElapsedTime.Seconds > 0.0 & data.ElapsedTime.Seconds < 1.0) { // --- panel --- for (int i = 0; i < this.Panel.Length; i++) { this.Panel[i] = 0; } // --- devices --- this.State = data.Vehicle; this.Handles = new ReadOnlyHandles(data.Handles); bool blocking = false; foreach (Device device in this.Devices) { device.Elapse(data, ref blocking); } // --- panel --- int seconds = (int)Math.Floor(data.TotalTime.Seconds); this.Panel[10] = (seconds / 3600) % 24; this.Panel[11] = (seconds / 60) % 60; this.Panel[12] = seconds % 60; this.Panel[269] = data.Handles.ConstSpeed ? 1 : 0; if (data.Handles.Reverser != 0 & (this.Handles.PowerNotch > 0 & this.Handles.BrakeNotch == 0 | this.Handles.PowerNotch == 0 & this.Handles.BrakeNotch == 1 & this.Specs.HasHoldBrake)) { this.Panel[100] = 1; } if (data.Handles.BrakeNotch >= this.Specs.AtsNotch & data.Handles.BrakeNotch <= this.Specs.BrakeNotches | data.Handles.Reverser != 0 & data.Handles.BrakeNotch == 1 & this.Specs.HasHoldBrake) { this.Panel[101] = 1; } // --- sound --- this.Sounds.Elapse(data); } }
// --- constructors --- /// <summary>Creates a new instance of this class.</summary> /// <param name="vehicle">The state of the train.</param> /// <param name="precedingVehicle">The state of the preceding train, or a null reference if there is no preceding train.</param> /// <param name="handles">The virtual handles.</param> /// <param name="totalTime">The current absolute time.</param> /// <param name="elapsedTime">The elapsed time since the last call to Elapse.</param> public ElapseData(VehicleState vehicle, PrecedingVehicleState precedingVehicle, Handles handles, Time totalTime, Time elapsedTime) { this.MyVehicle = vehicle; this.MyPrecedingVehicle = precedingVehicle; this.MyHandles = handles; this.MyTotalTime = totalTime; this.MyElapsedTime = elapsedTime; this.MyDebugMessage = null; }
// --- constructors --- /// <summary>Creates a new instance of this class.</summary> /// <param name="vehicle">The state of the train.</param> /// <param name="precedingVehicle">The state of the preceding train, or a null reference if there is no preceding train.</param> /// <param name="handles">The virtual handles.</param> /// <param name="totalTime">The current absolute time.</param> /// <param name="elapsedTime">The elapsed time since the last call to Elapse.</param> /// <param name="stations">The current route's list of stations.</param> /// <param name="cameraView">The current camera view mode</param> /// <param name="languageCode">The current language code</param> public ElapseData(VehicleState vehicle, PrecedingVehicleState precedingVehicle, Handles handles, Time totalTime, Time elapsedTime, List<Station> stations, CameraViewMode cameraView, string languageCode) { this.MyVehicle = vehicle; this.MyPrecedingVehicle = precedingVehicle; this.MyHandles = handles; this.MyTotalTime = totalTime; this.MyElapsedTime = elapsedTime; this.MyDebugMessage = null; this.MyStations = stations; this.MyCameraViewMode = cameraView; this.MyLanguageCode = languageCode; }