internal override void SetBeacon(BeaconData beacon) { if (this.State != AtsSx.States.Disabled & this.State != AtsSx.States.Initializing) { int type = beacon.Type; if (type > 9) { if (type == 12) { if (this.CompatibilityDistanceAccumulator == 0) { this.CompatibilityDistanceAccumulator = 4.94065645841247E-324; return; } if (beacon.Signal.Aspect == 0 | beacon.Signal.Aspect >= 10 && this.State == AtsSx.States.Chime | this.State == AtsSx.States.Normal | this.State == AtsSx.States.Alarm && Math.Abs(this.Train.State.Speed.KilometersPerHour) > (double)beacon.Optional) { this.State = AtsSx.States.Emergency; } this.CompatibilityDistanceAccumulator = 0; return; } if (type != 50) { switch (type) { case 55: { if (!(this.State == AtsSx.States.Chime | this.State == AtsSx.States.Normal | this.State == AtsSx.States.Alarm) || Math.Abs(this.Train.State.Speed.KilometersPerHour) <= (double)beacon.Optional) { return; } this.State = AtsSx.States.Emergency; return; } case 56: { if (!(this.State == AtsSx.States.Chime | this.State == AtsSx.States.Normal) || Math.Abs(this.Train.State.Speed.KilometersPerHour) <= (double)beacon.Optional) { return; } this.AlarmCountdown = this.DurationOfAlarm; this.State = AtsSx.States.Alarm; return; } case 60: { this.CompatibilityAccidentalDepartureCounter = 0; return; } case 61: { if (!(beacon.Signal.Aspect == 0 | beacon.Signal.Aspect >= 10) || this.CompatibilityAccidentalDepartureCounter <= 0.001 * (double)beacon.Optional || !(this.State == AtsSx.States.Chime | this.State == AtsSx.States.Normal | this.State == AtsSx.States.Alarm)) { return; } this.State = AtsSx.States.Emergency; return; } } } else if (beacon.Signal.Aspect == 0 | beacon.Signal.Aspect >= 10 && this.State == AtsSx.States.Chime | this.State == AtsSx.States.Normal | this.State == AtsSx.States.Alarm && Math.Abs(this.Train.State.Speed.KilometersPerHour) > 45) { this.State = AtsSx.States.Emergency; return; } else { return; } } else { switch (type) { case 0: { if (!(beacon.Signal.Aspect == 0 | beacon.Signal.Aspect >= 10) || !(this.State == AtsSx.States.Chime | this.State == AtsSx.States.Normal)) { return; } this.AlarmCountdown = this.DurationOfAlarm; this.State = AtsSx.States.Alarm; this.UpdateRedSignalLocation(beacon); return; } case 1: { if (!(beacon.Signal.Aspect == 0 | beacon.Signal.Aspect >= 10) || !(this.State == AtsSx.States.Chime | this.State == AtsSx.States.Normal | this.State == AtsSx.States.Alarm)) { return; } this.State = AtsSx.States.Emergency; return; } case 2: { if (!((beacon.Signal.Aspect == 0 | beacon.Signal.Aspect >= 10) & (beacon.Optional == 0 | beacon.Optional >= this.Train.Specs.Cars)) || !(this.State == AtsSx.States.Chime | this.State == AtsSx.States.Normal | this.State == AtsSx.States.Alarm)) { return; } this.State = AtsSx.States.Emergency; return; } default: { if (type == 9) { int optional = beacon.Optional / 1000; int num = beacon.Optional % 1000; if (optional != 0 || !(this.State == AtsSx.States.Chime | this.State == AtsSx.States.Normal | this.State == AtsSx.States.Alarm) || Math.Abs(this.Train.State.Speed.KilometersPerHour) <= (double)num) { return; } this.State = AtsSx.States.Emergency; return; } else { break; } } } } int frequencyFromBeacon = Train.GetFrequencyFromBeacon(beacon); if (frequencyFromBeacon == 108) { if (this.State == AtsSx.States.Chime | this.State == AtsSx.States.Normal | this.State == AtsSx.States.Alarm) { if (this.SpeedCheckCountdown <= 0) { this.SpeedCheckCountdown = this.DurationOfSpeedCheck; return; } this.SpeedCheckCountdown = 0; this.State = AtsSx.States.Emergency; return; } } else if (frequencyFromBeacon != 123) { switch (frequencyFromBeacon) { case 129: case 130: { if (!(this.State == AtsSx.States.Chime | this.State == AtsSx.States.Normal)) { break; } this.AlarmCountdown = this.DurationOfAlarm; this.State = AtsSx.States.Alarm; this.UpdateRedSignalLocation(beacon); break; } default: { return; } } } else if (this.State == AtsSx.States.Chime | this.State == AtsSx.States.Normal | this.State == AtsSx.States.Alarm) { this.State = AtsSx.States.Emergency; return; } } }
/// <summary>Is called when a beacon is passed.</summary> /// <param name="beacon">The beacon data.</param> internal override void SetBeacon(BeaconData beacon) { if (this.State != States.Disabled & this.State != States.Initializing) { switch (beacon.Type) { case 0: // --- Sx long --- if (beacon.Signal.Aspect == 0 | beacon.Signal.Aspect >= 10) { if (this.State == States.Chime | this.State == States.Normal) { this.AlarmCountdown = DurationOfAlarm; this.State = States.Alarm; UpdateRedSignalLocation(beacon); } } break; case 1: // --- Sx immediate stop --- if (beacon.Signal.Aspect == 0 | beacon.Signal.Aspect >= 10) { if (this.State == States.Chime | this.State == States.Normal | this.State == States.Alarm) { this.State = States.Emergency; } } break; case 2: // --- accidental departure --- if ((beacon.Signal.Aspect == 0 | beacon.Signal.Aspect >= 10) & (beacon.Optional == 0 | beacon.Optional >= this.Train.Specs.Cars)) { if (this.State == States.Chime | this.State == States.Normal | this.State == States.Alarm) { this.State = States.Emergency; } } break; case 9: // --- P upcoming curve limit / Sx speed check --- int distance = beacon.Optional / 1000; int speed = beacon.Optional % 1000; if (distance == 0) { // --- Sx speed check --- if (this.State == States.Chime | this.State == States.Normal | this.State == States.Alarm) { if (Math.Abs(this.Train.State.Speed.KilometersPerHour) > speed) { this.State = States.Emergency; } } } break; case 12: // --- Ps second pattern / Sx speed check --- if (this.CompatibilityDistanceAccumulator == 0.0) { this.CompatibilityDistanceAccumulator = double.Epsilon; } else { if (beacon.Signal.Aspect == 0 | beacon.Signal.Aspect >= 10) { if (this.State == States.Chime | this.State == States.Normal | this.State == States.Alarm) { if (Math.Abs(this.Train.State.Speed.KilometersPerHour) > beacon.Optional) { this.State = States.Emergency; } } } this.CompatibilityDistanceAccumulator = 0.0; } break; case 50: // --- Sx speed check, immediate stop type, 45 km/h if signal is red --- if (beacon.Signal.Aspect == 0 | beacon.Signal.Aspect >= 10) { if (this.State == States.Chime | this.State == States.Normal | this.State == States.Alarm) { if (Math.Abs(this.Train.State.Speed.KilometersPerHour) > 45.0) { this.State = States.Emergency; } } } break; case 55: // --- Sx speed check, immediate stop type --- if (this.State == States.Chime | this.State == States.Normal | this.State == States.Alarm) { if (Math.Abs(this.Train.State.Speed.KilometersPerHour) > beacon.Optional) { this.State = States.Emergency; } } break; case 56: // --- Sx speed check, alarm --- if (this.State == States.Chime | this.State == States.Normal) { if (Math.Abs(this.Train.State.Speed.KilometersPerHour) > beacon.Optional) { this.AlarmCountdown = DurationOfAlarm; this.State = States.Alarm; } } break; case 60: // --- accidental departure counter reset --- this.CompatibilityAccidentalDepartureCounter = 0.0; break; case 61: // --- accidental departure trigger --- if (beacon.Signal.Aspect == 0 | beacon.Signal.Aspect >= 10) { if (this.CompatibilityAccidentalDepartureCounter > 0.001 * (double)beacon.Optional) { if (this.State == States.Chime | this.State == States.Normal | this.State == States.Alarm) { this.State = States.Emergency; } } } break; default: // --- frequency-based beacons --- int frequency = Train.GetFrequencyFromBeacon(beacon); switch (frequency) { case 108: // --- Sx speed check (108.5 KHz) --- if (this.State == States.Chime | this.State == States.Normal | this.State == States.Alarm) { if (this.SpeedCheckCountdown <= 0.0) { this.SpeedCheckCountdown = DurationOfSpeedCheck; } else { this.SpeedCheckCountdown = 0.0; this.State = States.Emergency; } } break; case 123: // --- SN immediate stop (123 KHz) --- if (this.State == States.Chime | this.State == States.Normal | this.State == States.Alarm) { this.State = States.Emergency; } break; case 129: case 130: // --- S long (129.3 KHz / 130 KHz) --- if (this.State == States.Chime | this.State == States.Normal) { this.AlarmCountdown = DurationOfAlarm; this.State = States.Alarm; UpdateRedSignalLocation(beacon); } break; } break; } } }