using Nonemm.Core; using Nonemm.Core.Country; namespace Nonemm.Contests.Rules; /// The Mexico RTTY contest. A Mexican station sends its state, everyone else a /// serial number. A contact with Mexico is worth 4 points, one inside your own /// country 2, and anything else 3. The multipliers are the countries and the /// Mexican states, each once per band. public sealed class MexicoRtty : Contest { public string Name => "XERTTY"; public string DisplayName => "Mexico RTTY Contest"; public string CabrilloName => "XE-RTTY"; public IReadOnlyList ExchangeFieldsFor(StationInfo me) => IsMexican(me.CountryPrefix) ? [ new ExchangeField("Snt", ExchangeSlot.SentReport, ExchangeFieldKind.Report, IsRequired: false), new ExchangeField("Rcv", ExchangeSlot.ReceivedReport, ExchangeFieldKind.Report), new ExchangeField("Exch", ExchangeSlot.Exchange1, ExchangeFieldKind.Text) { Width = 3 }, ] : [ new ExchangeField("Snt", ExchangeSlot.SentReport, ExchangeFieldKind.Report, IsRequired: false), new ExchangeField("Rcv", ExchangeSlot.ReceivedReport, ExchangeFieldKind.Report), new ExchangeField("SentNR", ExchangeSlot.SentNumber, ExchangeFieldKind.Number, IsRequired: false), new ExchangeField("Exch", ExchangeSlot.Exchange1, ExchangeFieldKind.Text) { Width = 3 }, ]; /// A Mexican station sends a state, which goes in the section column; the /// serial everyone else sends stays in the exchange column. public Qso FromExchange1(Qso qso, string typed) => qso with { Section = IsMexican(qso.CountryPrefix) ? typed.Trim().ToUpperInvariant() : "", }; public IReadOnlyList MultiplierNames => ["Countries", "States"]; public DupeScope DupeScope => DupeScope.PerBand; public bool HasSerialNumbers => true; public IReadOnlyList Modes => [ModeCategory.Digital]; public string SentExchangeFor(StationInfo me) => IsMexican(me.CountryPrefix) ? me.State : "001"; public int PointsFor(QsoContext qso) => IsMexican(qso.CountryPrefix) ? 4 : qso.IsSameCountry ? 2 : 3; public IReadOnlyList MultipliersFor(QsoContext qso) { string band = qso.Band?.Name ?? ""; List found = []; if (qso.CountryPrefix.Length > 0) { found.Add(new Multiplier(1, qso.CountryPrefix, band)); } string state = qso.Qso.Section.Trim().ToUpperInvariant(); if (IsMexican(qso.CountryPrefix) && state.Length > 0) { found.Add(new Multiplier(2, state, band)); } return found; } public int TotalScore(ScoreTally tally, ContestEntry entry) => tally.Points * tally.TotalMultipliers; public CabrilloExchange CabrilloExchange(Qso qso, StationInfo me, ContestEntry entry) => new( [ new CabrilloField(me.Callsign, 13), new CabrilloField(qso.SentReport, 3), new CabrilloField(IsMexican(me.CountryPrefix) ? me.State : $"{qso.SentNumber:000}", 6), ], [ new CabrilloField(qso.Call.Text, 13), new CabrilloField(qso.ReceivedReport, 3), new CabrilloField(qso.Section.Length > 0 ? qso.Section : qso.Exchange1, 6), ]); private static bool IsMexican(string countryPrefix) => countryPrefix == "XE"; }