예제 #1
0
        /// <summary>Fix up faction names</summary>
        public static string getPhoneticFaction(string faction, bool useICAO = false)
        {
            if (faction == null)
            {
                return(null);
            }

            // Specific fixing of names to avoid later confusion
            if (FACTION_FIXES.ContainsKey(faction))
            {
                faction = FACTION_FIXES[faction];
            }

            // Faction names can contain system names; hunt them down and change them
            foreach (var pronunciation in STAR_SYSTEM_FIXES)
            {
                if (faction.Contains(pronunciation.Key))
                {
                    return(faction.Replace(pronunciation.Key, pronunciation.Value));
                }
            }
            foreach (var pronunciation in STAR_SYSTEM_PRONUNCIATIONS)
            {
                if (faction.Contains(pronunciation.Key))
                {
                    var replacement = replaceWithPronunciation(pronunciation.Key, pronunciation.Value);
                    return(faction.Replace(pronunciation.Key, replacement));
                }
            }

            // It's possible that the name contains a constellation or catalog abbreviation, in which case translate it
            string[] pieces = faction.Split(' ');
            for (int i = 0; i < pieces.Length; i++)
            {
                if (CONSTELLATION_PRONUNCIATIONS.ContainsKey(pieces[i]))
                {
                    pieces[i] = replaceWithPronunciation(pieces[i], CONSTELLATION_PRONUNCIATIONS[pieces[i]]);
                }
                else if (ALPHA_THEN_NUMERIC.IsMatch(pieces[i]))
                {
                    pieces[i] = sayAsLettersOrNumbers(pieces[i], false, useICAO);
                }
                else if (ALPHA_DOT.IsMatch(pieces[i]))
                {
                    pieces[i] = sayAsLettersOrNumbers(pieces[i].Replace(".", ""), false, useICAO);
                }
                else if (DIGIT.IsMatch(pieces[i]))
                {
                    pieces[i] = sayAsLettersOrNumbers(pieces[i], !THREE_OR_MORE_DIGITS.IsMatch(pieces[i]), useICAO);
                }
            }
            return(string.Join(" ", pieces));
        }
예제 #2
0
        /// <summary>Fix up star system names</summary>
        public static string getPhoneticStarSystem(string starSystem, bool useICAO = false)
        {
            if (starSystem == null)
            {
                return(null);
            }

            // Specific fixing of names to avoid later confusion
            if (STAR_SYSTEM_FIXES.ContainsKey(starSystem))
            {
                return(STAR_SYSTEM_FIXES[starSystem]);
            }

            // Specific translations
            if (STAR_SYSTEM_PRONUNCIATIONS.ContainsKey(starSystem))
            {
                return(replaceWithPronunciation(starSystem, STAR_SYSTEM_PRONUNCIATIONS[starSystem]));
            }

            // Match procedurally generated star systems, breaking apart systems and bodies wherever we can
            if (PROC_GEN_SYSTEM_BODY.IsMatch(starSystem))
            {
                var match = PROC_GEN_SYSTEM_BODY.Match(starSystem);

                // Deal with the sector name first (e.g. Col 107 Sector)

                // We need to handle the pieces before and after the sector marker separately.
                // Fix common names
                string sectorNamePart1 = match.Groups["SECTOR"].Value
                                         .Replace("Col ", "Coll ")
                                         .Replace("R CrA ", @"<say-as interpret-as=""characters"">R</say-as> Corona Australis ")
                                         .Replace("Tr ", @"<say-as interpret-as=""characters"">T</say-as> <say-as interpret-as=""characters"">R</say-as> ")
                                         .Replace("Skull and Crossbones Neb. ", "Skull and Crossbones ")
                                         .Replace("(", "").Replace(")", "");

                // Various items between the sector name and 'Sector' need to be removed to allow us to find the base pronunciation
                string sectorNamePart2 = "";
                if (sectorNamePart1.EndsWith(" Dark Region B Sector"))
                {
                    sectorNamePart1 = sectorNamePart1.Replace(" Dark Region B Sector", "");
                    sectorNamePart2 = " Dark Region B Sector";
                }
                else if (sectorNamePart1.EndsWith(" Sector"))
                {
                    sectorNamePart1 = sectorNamePart1.Replace(" Sector", "");
                    sectorNamePart2 = " Sector";
                }

                // There might be a constellation name that we need to translate
                if (CONSTELLATION_PRONUNCIATIONS.ContainsKey(sectorNamePart1))
                {
                    sectorNamePart1 = replaceWithPronunciation(sectorNamePart1, CONSTELLATION_PRONUNCIATIONS[sectorNamePart1]);
                }

                // The sector name might include digits. Break up any group of three or more.
                var sectorNamePart1Words = new List <string>();
                foreach (var word in sectorNamePart1.Split(' '))
                {
                    if (THREE_OR_MORE_DIGITS.IsMatch(word))
                    {
                        sectorNamePart1Words.Add(sayAsLettersOrNumbers(word, false, useICAO));
                    }
                    else
                    {
                        sectorNamePart1Words.Add(word);
                    }
                }
                sectorNamePart1 = string.Join(" ", sectorNamePart1Words).Trim();

                // Now we spell out the procedurally generated sector coordinates (e.g. AI-H b40-6)
                var sectorCoordinates = sayAsLettersOrNumbers(match.Groups["COORDINATES"].Value, true, useICAO);

                // Name might contain a body name - handle that here.
                var body = match.Groups["BODY"]?.Value;

                return(string.IsNullOrEmpty(body)
                    ? $"{sectorNamePart1 + sectorNamePart2} {sectorCoordinates}"
                    : $"{sectorNamePart1 + sectorNamePart2} {sectorCoordinates} {getPhoneticBody(body, useICAO)}");
            }

            // Common star catalogs
            if (phoneticStarCatalogSystem(starSystem, out var result, useICAO))
            {
                return(result);
            }