private void SwitchToSx() { if (this.Train.AtsSx != null) { AtsP.Pattern[] patterns = this.Patterns; for (int i = 0; i < (int)patterns.Length; i++) { patterns[i].Clear(); } this.State = AtsP.States.Standby; if (!this.Blocked) { if (!SoundManager.IsPlaying(CommonSounds.ATSPBell)) { SoundManager.Play(CommonSounds.ATSPBell, 1.0, 1.0, false); } } this.Train.AtsSx.State = AtsSx.States.Chime; } else if (this.State != AtsP.States.Emergency) { this.State = AtsP.States.Emergency; if (this.State != AtsP.States.Brake & this.State != AtsP.States.Service && !this.Blocked) { if (!SoundManager.IsPlaying(CommonSounds.ATSPBell)) { SoundManager.Play(CommonSounds.ATSPBell, 1.0, 1.0, false); } } } this.SwitchToAtsSxPosition = double.MaxValue; this.DAtsPActive = false; }
private void SwitchToP(AtsP.States state) { if (this.State == AtsP.States.Standby) { if (this.Train.AtsSx == null || this.Train.AtsSx.State != AtsSx.States.Emergency) { this.State = state; if (!this.Blocked) { if (!SoundManager.IsPlaying(CommonSounds.ATSPBell)) { SoundManager.Play(CommonSounds.ATSPBell, 1.0, 1.0, false); } return; } } } else if (state == AtsP.States.Service | state == AtsP.States.Emergency) { if (this.State != AtsP.States.Brake & this.State != AtsP.States.Service & this.State != AtsP.States.Emergency && !this.Blocked) { if (!SoundManager.IsPlaying(CommonSounds.ATSPBell)) { SoundManager.Play(CommonSounds.ATSPBell, 1.0, 1.0, false); } } this.State = state; } }
internal AtsP(Train train) { this.Train = train; this.State = AtsP.States.Disabled; this.AtsSxPMode = false; this.InitializationCountdown = 0; this.SwitchToAtsSxPosition = double.MaxValue; this.CompatibilityLimits = new List <AtsP.CompatibilityLimit>(); this.CompatibilityLimitPointer = 0; this.DAtsPSupported = false; this.DAtsPActive = false; this.DAtsPContinuous = false; this.SignalPatterns = new AtsP.Pattern[10]; for (int i = 0; i < (int)this.SignalPatterns.Length; i++) { this.SignalPatterns[i] = new AtsP.Pattern(this); } this.DivergencePattern = new AtsP.Pattern(this); this.DownslopePattern = new AtsP.Pattern(this); this.CurvePattern = new AtsP.Pattern(this); this.TemporaryPattern = new AtsP.Pattern(this); this.RoutePermanentPattern = new AtsP.Pattern(this); this.TrainPermanentPattern = new AtsP.Pattern(this); this.CompatibilityTemporaryPattern = new AtsP.Pattern(this); this.CompatibilityPermanentPattern = new AtsP.Pattern(this); this.DAtsPZerothSignalPattern = new AtsP.Pattern(this); this.DAtsPFirstSignalPattern = new AtsP.Pattern(this); this.DAtsPSecondSignalPattern = new AtsP.Pattern(this); List <AtsP.Pattern> patterns = new List <AtsP.Pattern>(); patterns.AddRange(this.SignalPatterns); patterns.Add(this.DivergencePattern); patterns.Add(this.DownslopePattern); patterns.Add(this.CurvePattern); patterns.Add(this.TemporaryPattern); patterns.Add(this.RoutePermanentPattern); patterns.Add(this.TrainPermanentPattern); patterns.Add(this.CompatibilityTemporaryPattern); patterns.Add(this.CompatibilityPermanentPattern); patterns.Add(this.DAtsPZerothSignalPattern); patterns.Add(this.DAtsPFirstSignalPattern); patterns.Add(this.DAtsPSecondSignalPattern); this.Patterns = patterns.ToArray(); }
internal override void Initialize(InitializationModes mode) { if (mode != InitializationModes.OffEmergency) { this.State = AtsP.States.Standby; } else { this.State = AtsP.States.Suppressed; } AtsP.Pattern[] patterns = this.Patterns; for (int i = 0; i < (int)patterns.Length; i++) { AtsP.Pattern pattern = patterns[i]; if (Math.Abs(this.Train.State.Speed.MetersPerSecond) >= pattern.WarningPattern) { pattern.Clear(); } } }
internal override void KeyDown(VirtualKeys key) { VirtualKeys virtualKey = key; switch (virtualKey) { case VirtualKeys.B1: { if (!((this.State == AtsP.States.Brake | this.State == AtsP.States.Service | this.State == AtsP.States.Emergency) & this.Train.Handles.Reverser == 0 & this.Train.Handles.PowerNotch == 0 & this.Train.Handles.BrakeNotch >= this.Train.Specs.BrakeNotches)) { break; } AtsP.Pattern[] patterns = this.Patterns; for (int i = 0; i < (int)patterns.Length; i++) { AtsP.Pattern pattern = patterns[i]; if (Math.Abs(this.Train.State.Speed.MetersPerSecond) >= pattern.WarningPattern) { pattern.Clear(); } } this.State = AtsP.States.Normal; Train.TractionManager.ResetBrakeApplication(); if (!SoundManager.IsPlaying(CommonSounds.ATSPBell)) { SoundManager.Play(CommonSounds.ATSPBell, 1.0, 1.0, false); } return; } case VirtualKeys.B2: { if (!((this.State == AtsP.States.Normal | this.State == AtsP.States.Pattern) & !this.BrakeRelease & this.DurationOfBrakeRelease > 0)) { break; } this.BrakeRelease = true; this.BrakeReleaseCountdown = this.DurationOfBrakeRelease; if (!SoundManager.IsPlaying(CommonSounds.ATSPBell)) { SoundManager.Play(CommonSounds.ATSPBell, 1.0, 1.0, false); } return; } default: { if (virtualKey != VirtualKeys.E) { return; } if (this.State == AtsP.States.Disabled) { this.State = AtsP.States.Suppressed; return; } this.State = AtsP.States.Disabled; break; } } }
internal override void Elapse(ElapseData data, ref bool blocking) { this.Blocked = blocking; if (this.State == AtsP.States.Suppressed && this.Train.TractionManager.CurrentInterventionBrakeNotch <= this.Train.Specs.BrakeNotches) { this.InitializationCountdown = this.DurationOfInitialization; this.State = AtsP.States.Initializing; } if (this.State == AtsP.States.Initializing) { AtsP initializationCountdown = this; initializationCountdown.InitializationCountdown = initializationCountdown.InitializationCountdown - data.ElapsedTime.Seconds; if (this.InitializationCountdown <= 0) { this.State = AtsP.States.Standby; this.BrakeRelease = false; this.SwitchToAtsSxPosition = double.MaxValue; AtsP.Pattern[] patterns = this.Patterns; for (int i = 0; i < (int)patterns.Length; i++) { AtsP.Pattern pattern = patterns[i]; if (Math.Abs(data.Vehicle.Speed.MetersPerSecond) >= pattern.WarningPattern) { pattern.Clear(); } } if (!SoundManager.IsPlaying(CommonSounds.ATSPBell)) { SoundManager.Play(CommonSounds.ATSPBell, 1.0, 1.0, false); } } } if (this.BrakeRelease) { AtsP brakeReleaseCountdown = this; brakeReleaseCountdown.BrakeReleaseCountdown = brakeReleaseCountdown.BrakeReleaseCountdown - data.ElapsedTime.Seconds; if (this.BrakeReleaseCountdown <= 0) { this.BrakeRelease = false; if (!SoundManager.IsPlaying(CommonSounds.ATSPBell)) { SoundManager.Play(CommonSounds.ATSPBell, 1.0, 1.0, false); } } } if (this.State != AtsP.States.Disabled & this.State != AtsP.States.Initializing) { AtsP position = this; position.Position = position.Position + data.Vehicle.Speed.MetersPerSecond * data.ElapsedTime.Seconds; } if (!blocking) { if (this.DAtsPSupported && this.DAtsPFirstSignalPattern.Position - this.Train.State.Location < 0) { this.DAtsPZerothSignalPattern.Position = this.DAtsPFirstSignalPattern.Position; this.DAtsPZerothSignalPattern.TargetSpeed = this.DAtsPFirstSignalPattern.TargetSpeed; this.DAtsPFirstSignalPattern.Position = this.DAtsPSecondSignalPattern.Position; this.DAtsPFirstSignalPattern.TargetSpeed = this.DAtsPSecondSignalPattern.TargetSpeed; this.DAtsPSecondSignalPattern.Position = double.MaxValue; this.DAtsPSecondSignalPattern.TargetSpeed = double.MaxValue; } if (this.DAtsPActive & this.DAtsPContinuous) { switch (this.DAtsPAspect) { case 1: { this.DAtsPFirstSignalPattern.TargetSpeed = 6.94444444444444; break; } case 2: { this.DAtsPFirstSignalPattern.TargetSpeed = 12.5; break; } case 3: { this.DAtsPFirstSignalPattern.TargetSpeed = 20.8333333333333; break; } case 4: case 5: case 6: { this.DAtsPFirstSignalPattern.TargetSpeed = double.MaxValue; break; } default: { this.DAtsPFirstSignalPattern.TargetSpeed = 0; break; } } if (this.DAtsPZerothSignalPattern.TargetSpeed < this.DAtsPFirstSignalPattern.TargetSpeed) { this.DAtsPZerothSignalPattern.TargetSpeed = this.DAtsPFirstSignalPattern.TargetSpeed; } } if (this.State == AtsP.States.Normal | this.State == AtsP.States.Pattern | this.State == AtsP.States.Brake) { bool flag = false; bool flag1 = false; bool flag2 = true; if (this.DivergencePattern.Position > double.MinValue & this.DivergencePattern.Position < double.MaxValue && Math.Abs(data.Vehicle.Speed.MetersPerSecond) < this.DivergencePattern.BrakePattern && this.DivergencePattern.Position - this.Position < -50) { this.DivergencePattern.Clear(); } this.UpdateCompatibilityTemporarySpeedPattern(); AtsP.Pattern[] patternArray = this.Patterns; for (int j = 0; j < (int)patternArray.Length; j++) { AtsP.Pattern pattern1 = patternArray[j]; pattern1.Perform(this, data); if (Math.Abs(data.Vehicle.Speed.MetersPerSecond) >= pattern1.WarningPattern - 0.277777777777778) { flag2 = false; } if (Math.Abs(data.Vehicle.Speed.MetersPerSecond) >= pattern1.WarningPattern) { flag1 = true; } if (Math.Abs(data.Vehicle.Speed.MetersPerSecond) >= pattern1.BrakePattern) { flag = true; } } if (this.BrakeRelease) { flag = false; } if (flag & this.State != AtsP.States.Brake) { this.State = AtsP.States.Brake; if (!SoundManager.IsPlaying(CommonSounds.ATSPBell)) { SoundManager.Play(CommonSounds.ATSPBell, 1.0, 1.0, false); } } else if (flag1 & this.State == AtsP.States.Normal) { this.State = AtsP.States.Pattern; if (!SoundManager.IsPlaying(CommonSounds.ATSPBell)) { SoundManager.Play(CommonSounds.ATSPBell, 1.0, 1.0, false); } } else if (!flag & !flag1 & flag2 & (this.State == AtsP.States.Pattern | this.State == AtsP.States.Brake)) { this.State = AtsP.States.Normal; if (!SoundManager.IsPlaying(CommonSounds.ATSPBell)) { SoundManager.Play(CommonSounds.ATSPBell, 1.0, 1.0, false); } } if (this.State == AtsP.States.Brake) { Train.TractionManager.DemandBrakeApplication(this.Train.Specs.BrakeNotches, "Brake application demanded by ATS-P"); } if (this.Position > this.SwitchToAtsSxPosition & this.State != AtsP.States.Brake & this.State != AtsP.States.Service & this.State != AtsP.States.Emergency) { this.SwitchToSx(); } } else if (this.State == AtsP.States.Service) { Train.TractionManager.DemandBrakeApplication(this.Train.Specs.BrakeNotches, "Brake application demanded by ATS-P"); } else if (this.State == AtsP.States.Emergency) { Train.TractionManager.DemandBrakeApplication(this.Train.Specs.BrakeNotches + 1, "Brake application demanded by ATS-P"); } if (!this.AtsSxPMode & (this.State == AtsP.States.Normal | this.State == AtsP.States.Pattern | this.State == AtsP.States.Brake | this.State == AtsP.States.Service | this.State == AtsP.States.Emergency)) { blocking = true; } } else if (this.State != AtsP.States.Disabled & this.State != AtsP.States.Suppressed) { this.State = AtsP.States.Standby; } if (this.State != AtsP.States.Disabled & this.State != AtsP.States.Suppressed) { this.Train.Panel[2] = 1; this.Train.Panel[259] = 1; } if (this.State == AtsP.States.Pattern | this.State == AtsP.States.Brake | this.State == AtsP.States.Service | this.State == AtsP.States.Emergency) { this.Train.Panel[3] = 1; this.Train.Panel[260] = 1; } if (this.State == AtsP.States.Brake | this.State == AtsP.States.Service | this.State == AtsP.States.Emergency) { this.Train.Panel[5] = 1; this.Train.Panel[262] = 1; } if (this.State != AtsP.States.Disabled & this.State != AtsP.States.Suppressed & this.State != AtsP.States.Standby) { this.Train.Panel[6] = 1; this.Train.Panel[263] = 1; } if (this.State == AtsP.States.Initializing) { this.Train.Panel[7] = 1; this.Train.Panel[264] = 1; } if (this.State == AtsP.States.Disabled) { this.Train.Panel[50] = 1; } if (this.State != AtsP.States.Disabled & this.State != AtsP.States.Suppressed & this.State != AtsP.States.Standby & this.BrakeRelease) { this.Train.Panel[4] = 1; this.Train.Panel[261] = 1; } if (this.State == AtsP.States.Normal | this.State == AtsP.States.Pattern | this.State == AtsP.States.Brake | this.State == AtsP.States.Service | this.State == AtsP.States.Emergency) { StringBuilder stringBuilder = new StringBuilder(); for (int k = 0; k < (int)this.SignalPatterns.Length; k++) { this.SignalPatterns[k].AddToStringBuilder(string.Concat(k.ToString(), ":"), stringBuilder); } this.DivergencePattern.AddToStringBuilder("分岐/D:", stringBuilder); this.TemporaryPattern.AddToStringBuilder("臨時/T:", stringBuilder); this.CurvePattern.AddToStringBuilder("曲線/C:", stringBuilder); this.DownslopePattern.AddToStringBuilder("勾配/S:", stringBuilder); this.RoutePermanentPattern.AddToStringBuilder("P:", stringBuilder); this.TrainPermanentPattern.AddToStringBuilder("M:", stringBuilder); if (this.SwitchToAtsSxPosition != double.MaxValue) { if (stringBuilder.Length != 0) { stringBuilder.Append(", "); } double switchToAtsSxPosition = this.SwitchToAtsSxPosition - this.Position; stringBuilder.Append(string.Concat("Sx@", switchToAtsSxPosition.ToString("0"))); } if (stringBuilder.Length == 0) { data.DebugMessage = this.State.ToString(); return; } data.DebugMessage = string.Concat(this.State.ToString(), " - ", stringBuilder.ToString()); } }