1 using SoundManager; 2 using TrainManager.Handles; 3 using TrainManager.Power; 4 5 namespace TrainManager.BrakeSystems 6 { 7 public abstract class CarBrake 8 { 9 internal const double Tolerance = 5000.0; 10 11 /// <summary>Contains a reference to the EB handle of the controlling train</summary> 12 internal EmergencyHandle emergencyHandle; 13 14 /// <summary>Contains a reference to the reverser handle of the controlling train</summary> 15 internal ReverserHandle reverserHandle; 16 17 /// <summary>Whether this is a main or auxiliary brake system</summary> 18 public BrakeType brakeType; 19 20 public EqualizingReservoir equalizingReservoir; 21 22 public MainReservoir mainReservoir; 23 24 public AuxiliaryReservoir auxiliaryReservoir; 25 26 public BrakePipe brakePipe; 27 28 public BrakeCylinder brakeCylinder; 29 30 public Compressor airCompressor; 31 32 internal EletropneumaticBrakeType electropneumaticBrakeType; 33 34 public StraightAirPipe straightAirPipe; 35 36 /// <summary>Stores whether the car is a motor car</summary> 37 internal bool isMotorCar; 38 39 /// <summary>The speed at which the brake control system activates in m/s</summary> 40 public double brakeControlSpeed; 41 42 /// <summary>The current deceleration provided by the electric motor</summary> 43 public double motorDeceleration; 44 45 /// <summary>The air sound currently playing</summary> 46 public CarSound airSound = new CarSound(); 47 /// <summary>Played when the pressure in the brake cylinder is decreased from a non-high to a non-zero value</summary> 48 public CarSound Air = new CarSound(); 49 /// <summary>Played when the pressure in the brake cylinder is decreased from a high value</summary> 50 public CarSound AirHigh = new CarSound(); 51 /// <summary>Played when the pressure in the brake cylinder is decreased to zero</summary> 52 public CarSound AirZero = new CarSound(); 53 /// <summary>Played when the brake shoe rubs against the wheels</summary> 54 public CarSound Rub = new CarSound(); 55 /// <summary>The sound played when the brakes are released</summary> 56 public CarSound Release = new CarSound(); 57 58 internal AccelerationCurve[] decelerationCurves; 59 /// <summary>A non-negative floating point number representing the jerk in m/s when the deceleration produced by the electric brake is increased.</summary> 60 public double JerkUp; 61 /// <summary>A non-negative floating point number representing the jerk in m/s when the deceleration produced by the electric brake is decreased.</summary> 62 public double JerkDown; 63 64 /// <summary>Updates the brake system</summary> 65 /// <param name="TimeElapsed">The frame time elapsed</param> 66 /// <param name="currentSpeed">The current speed of the train</param> 67 /// <param name="brakeHandle">The controlling brake handle (NOTE: May either be the loco brake if fitted or the train brake)</param> 68 /// <param name="Deceleration">The deceleration output provided</param> Update(double TimeElapsed, double currentSpeed, AbstractHandle brakeHandle, out double Deceleration)69 public abstract void Update(double TimeElapsed, double currentSpeed, AbstractHandle brakeHandle, out double Deceleration); 70 GetRate(double Ratio, double Factor)71 internal double GetRate(double Ratio, double Factor) 72 { 73 Ratio = Ratio < 0.0 ? 0.0 : Ratio > 1.0 ? 1.0 : Ratio; 74 Ratio = 1.0 - Ratio; 75 return 1.5 * Factor * (1.01 - Ratio * Ratio); 76 } 77 78 /// <summary>Calculates the max possible deceleration given a brake notch and speed</summary> 79 /// <param name="Notch">The brake notch</param> 80 /// <param name="currentSpeed">The speed</param> 81 /// <returns>The deceleration in m/s</returns> DecelerationAtServiceMaximumPressure(int Notch, double currentSpeed)82 public double DecelerationAtServiceMaximumPressure(int Notch, double currentSpeed) 83 { 84 if (Notch == 0) 85 { 86 return this.decelerationCurves[0].GetAccelerationOutput(currentSpeed, 1.0); 87 } 88 if (this.decelerationCurves.Length >= Notch) 89 { 90 return this.decelerationCurves[Notch - 1].GetAccelerationOutput(currentSpeed, 1.0); 91 } 92 return this.decelerationCurves[this.decelerationCurves.Length - 1].GetAccelerationOutput(currentSpeed, 1.0); 93 } 94 } 95 } 96