1 using OpenBveApi.Trains; 2 using SoundManager; 3 4 namespace TrainManager.Power 5 { 6 /// <summary>Represents a basic circuit breaker for the electric engine</summary> 7 public class Breaker 8 { 9 /// <summary>Played once when power application is resumed</summary> 10 /// <remarks>May be triggered either by driver actions (power, reverser, brake) or similar from a safety system</remarks> 11 public CarSound Resume; 12 /// <summary>Played once when power application is resumed or interrrupted</summary> 13 /// <remarks>May be triggered either by driver actions (power, reverser, brake) or similar from a safety system</remarks> 14 public CarSound ResumeOrInterrupt; 15 /// <summary>Whether the last action of the breaker was to resume power</summary> 16 private bool Resumed; 17 /// <summary>Holds a reference to the car for sounds playback</summary> 18 private readonly AbstractCar Car; 19 20 /// <summary>Creates a new breaker</summary> 21 /// <param name="car">The car</param> Breaker(AbstractCar car)22 public Breaker(AbstractCar car) 23 { 24 Resumed = false; 25 Car = car; 26 Resume = new CarSound(); 27 ResumeOrInterrupt = new CarSound(); 28 } 29 30 /// <summary> Updates the breaker</summary> 31 /// <param name="BreakerActive">Whether the breaker is currently active</param> Update(bool BreakerActive)32 public void Update(bool BreakerActive) 33 { 34 if (BreakerActive & !Resumed) 35 { 36 // resume 37 Resume.Play(Car, false); 38 ResumeOrInterrupt.Play(Car, false); 39 Resumed = true; 40 } 41 else if (!BreakerActive & Resumed) 42 { 43 // interrupt 44 ResumeOrInterrupt.Play(Car, false); 45 Resumed = false; 46 } 47 } 48 } 49 } 50