Example #1
0
        private string GetCustomName(JournalScan sc, ISystem sys)
        {
            string rest       = sc.IsStarNameRelatedReturnRest(sys.Name);
            string customname = null;

            if (sc.BodyName.StartsWith(sys.Name, StringComparison.InvariantCultureIgnoreCase))
            {
                customname = sc.BodyName.Substring(sys.Name.Length).TrimStart(' ', '-');

                if (customname == "" && !sc.IsStar)
                {
                    customname = sc.BodyName;
                }
                else if (customname == "" || customname == rest)
                {
                    customname = null;
                }
            }
            else if (rest == null || !sc.BodyName.EndsWith(rest))
            {
                customname = sc.BodyName;
            }

            return(customname);
        }
Example #2
0
        // find a better name for the body

        private string GetCustomNameJournalScan(JournalScan sc, ISystem sys)
        {
            string rest       = sc.IsStarNameRelatedReturnRest(sys.Name, sys.SystemAddress); // this can be null
            string customname = null;

            if (sc.BodyName.StartsWith(sys.Name, StringComparison.InvariantCultureIgnoreCase)) // if body starts with system name
            {
                customname = sc.BodyName.Substring(sys.Name.Length).TrimStart(' ', '-');       // cut out system name

                if (customname == "" && !sc.IsStar)                                            // if empty, and not star, customname is just the body name
                {
                    customname = sc.BodyName;
                }
                else if (customname == "" || customname == rest)                            // if empty, or its the same as the star name related, its not got a customname
                {
                    customname = null;
                }
            }
            else if (rest == null || !sc.BodyName.EndsWith(rest))                           // not related to star, or not related to bodyname, set back to body name
            {
                customname = sc.BodyName;
            }

            return(customname);
        }
Example #3
0
        private List <string> ExtractElements(JournalScan sc, ISystem sys, out bool isbeltcluster, out ScanNodeType starscannodetype)
        {
            starscannodetype = ScanNodeType.star;
            isbeltcluster    = false;
            List <string> elements;
            string        rest = sc.IsStarNameRelatedReturnRest(sys.Name);

            if (rest != null)                                   // if we have a relationship..
            {
                if (sc.IsStar && !sc.IsEDSMBody && sc.DistanceFromArrivalLS == 0 && rest.Length >= 2)
                {
                    elements = new List <string> {
                        rest
                    };
                    starscannodetype = ScanNodeType.star;
                }
                else if (rest.Length > 0)
                {
                    elements = rest.Split(' ').ToList();

                    if (elements.Count == 4 && elements[0].Length == 1 && char.IsLetter(elements[0][0]) &&
                        elements[1].Equals("belt", StringComparison.InvariantCultureIgnoreCase) &&
                        elements[2].Equals("cluster", StringComparison.InvariantCultureIgnoreCase))
                    {
                        elements = new List <string> {
                            "Main Star", elements[0] + " " + elements[1], elements[2] + " " + elements[3]
                        };
                        isbeltcluster = true;
                    }
                    else if (elements.Count == 5 && elements[0].Length == 1 &&
                             elements[1].Length == 1 && char.IsLetter(elements[1][0]) &&
                             elements[2].Equals("belt", StringComparison.InvariantCultureIgnoreCase) &&
                             elements[3].Equals("cluster", StringComparison.InvariantCultureIgnoreCase))
                    {
                        elements = new List <string> {
                            elements[0], elements[1] + " " + elements[2], elements[3] + " " + elements[4]
                        };
                        isbeltcluster = true;
                    }

                    if (char.IsDigit(elements[0][0]))       // if digits, planet number, no star designator
                    {
                        elements.Insert(0, "Main Star");    // no star designator, main star, add MAIN
                    }
                    else if (elements[0].Length > 1)        // designator, is it multiple chars..
                    {
                        starscannodetype = ScanNodeType.barycentre;
                    }
                }
                else
                {
                    elements = new List <string>();         // only 1 item, the star, which is the same as the system name..
                    elements.Add("Main Star");              // Sol / SN:Sol should come thru here
                }
            }
            else if (sc.IsStar && !sc.IsEDSMBody && sc.DistanceFromArrivalLS == 0)
            {
                elements = new List <string> {
                    sc.BodyName
                };
                starscannodetype = ScanNodeType.star;
            }
            else
            {                                               // so not part of starname
                elements = sc.BodyName.Split(' ').ToList(); // not related in any way (earth) so assume all bodyparts, and
                elements.Insert(0, "Main Star");            // insert the MAIN designator as the star designator
            }

            return(elements);
        }
Example #4
0
        public bool Process(JournalScan sc, EliteDangerous.ISystem sys)           // FALSE if you can't process it
        {
            Tuple <string, long> withedsm = new Tuple <string, long>(sys.name, sys.id_edsm);

            SystemNode sn = null;

            if (scandata.ContainsKey(withedsm))         // if with edsm (if id_edsm=0, then thats okay)
            {
                sn = scandata[withedsm];
            }
            else if (scandataByName.ContainsKey(sys.name))  // if we now have an edsm id, see if we have one without it
            {
                foreach (SystemNode _sn in scandataByName[sys.name])
                {
                    if (_sn.system.Equals(sys))
                    {
                        if (sys.id_edsm != 0)             // yep, replace
                        {
                            scandata.Add(new Tuple <string, long>(sys.name, sys.id_edsm), _sn);
                        }
                        sn = _sn;
                        break;
                    }
                }
            }

            if (sn == null)
            {
                sn = new SystemNode()
                {
                    system = sys, starnodes = new SortedList <string, ScanNode>(new DuplicateKeyComparer <string>())
                };

                if (!scandataByName.ContainsKey(sys.name))
                {
                    scandataByName[sys.name] = new List <SystemNode>();
                }

                scandataByName[sys.name].Add(sn);

                if (sys.id_edsm != 0)
                {
                    scandata.Add(new Tuple <string, long>(sys.name, sys.id_edsm), sn);
                }
            }

            // handle Earth, starname = Sol
            // handle Eol Prou LW-L c8-306 A 4 a and Eol Prou LW-L c8-306
            // handle Colonia 4 , starname = Colonia, planet 4
            // handle Aurioum B A BELT
            // Kyloasly OY-Q d5-906 13 1

            List <string> elements;

            ScanNodeType starscannodetype = ScanNodeType.star;          // presuming..

            string rest = sc.IsStarNameRelatedReturnRest(sys.name);

            if (rest != null)                                   // if we have a relationship..
            {
                if (rest.Length > 0)
                {
                    elements = rest.Split(' ').ToList();

                    if (char.IsDigit(elements[0][0]))       // if digits, planet number, no star designator
                    {
                        elements.Insert(0, "Main Star");    // no star designator, main star, add MAIN
                    }
                    else if (elements[0].Length > 1)        // designator, is it multiple chars..
                    {
                        starscannodetype = ScanNodeType.barycentre;
                    }
                }
                else
                {
                    elements = new List <string>();         // only 1 item, the star, which is the same as the system name..
                    elements.Add("Main Star");              // Sol / SN:Sol should come thru here
                }
            }
            else
            {                                               // so not part of starname
                elements = sc.BodyName.Split(' ').ToList(); // not related in any way (earth) so assume all bodyparts, and
                elements.Insert(0, "Main Star");            // insert the MAIN designator as the star designator
            }

            string customname = null;

            if (sc.BodyName.StartsWith(sys.name, StringComparison.InvariantCultureIgnoreCase))
            {
                customname = sc.BodyName.Substring(sys.name.Length).TrimStart(' ', '-');

                if (customname == "" && !sc.IsStar)
                {
                    customname = sc.BodyName;
                }
                else if (customname == "" || customname == rest)
                {
                    customname = null;
                }
            }
            else if (rest == null || !sc.BodyName.EndsWith(rest))
            {
                customname = sc.BodyName;
            }

            if (elements.Count >= 1)                          // okay, we have an element.. first is the star..
            {
                ScanNode sublv0;

                if (!sn.starnodes.TryGetValue(elements[0], out sublv0))     // not found this node, add..
                {
                    sublv0 = new ScanNode()
                    {
                        ownname  = elements[0],
                        fullname = sys.name + (elements[0].Contains("Main") ? "" : (" " + elements[0])),
                        ScanData = null,
                        children = null,
                        type     = starscannodetype
                    };

                    sn.starnodes.Add(elements[0], sublv0);
                    //System.Diagnostics.Debug.WriteLine("Added star " + star.fullname + " '" + star.ownname + "'" + " under '" + designator + "' type " + ty);
                }

                if (elements.Count >= 2)                        // we have a sub designator..
                {
                    ScanNode sublv1;

                    if (sublv0.children == null || !sublv0.children.TryGetValue(elements[1], out sublv1))
                    {
                        if (sublv0.children == null)
                        {
                            sublv0.children = new SortedList <string, ScanNode>(new DuplicateKeyComparer <string>());
                        }

                        sublv1 = new ScanNode()
                        {
                            ownname = elements[1], fullname = sublv0.fullname + " " + elements[1], ScanData = null, children = null, type = ScanNodeType.body
                        };
                        sublv0.children.Add(elements[1], sublv1);
                    }

                    if (elements.Count >= 3)
                    {
                        ScanNode sublv2;

                        if (sublv1.children == null || !sublv1.children.TryGetValue(elements[2], out sublv2))
                        {
                            if (sublv1.children == null)
                            {
                                sublv1.children = new SortedList <string, ScanNode>(new DuplicateKeyComparer <string>());
                            }

                            sublv2 = new ScanNode()
                            {
                                ownname = elements[2], fullname = sublv0.fullname + " " + elements[1] + " " + elements[2], ScanData = null, children = null, type = ScanNodeType.body
                            };
                            sublv1.children.Add(elements[2], sublv2);
                        }

                        if (elements.Count >= 4)
                        {
                            ScanNode sublv3;

                            if (sublv2.children == null || !sublv2.children.TryGetValue(elements[3], out sublv3))
                            {
                                if (sublv2.children == null)
                                {
                                    sublv2.children = new SortedList <string, ScanNode>(new DuplicateKeyComparer <string>());
                                }

                                sublv3 = new ScanNode()
                                {
                                    ownname = elements[3], fullname = sublv0.fullname + " " + elements[1] + " " + elements[2] + " " + elements[3], ScanData = null, children = null, type = ScanNodeType.body
                                };
                                sublv2.children.Add(elements[3], sublv3);
                            }

                            if (elements.Count == 4)            // okay, need only 4 elements now.. if not, we have not coped..
                            {
                                sublv3.customname = customname;
                                sublv3.ScanData   = sc;
                            }
                            else
                            {
                                System.Diagnostics.Debug.WriteLine("Failed to add system " + sc.BodyName + " too long");
                                return(false);
                            }
                        }
                        else
                        {
                            sublv2.customname = customname;
                            sublv2.ScanData   = sc;
                        }
                    }
                    else
                    {
                        sublv1.customname = customname;
                        sublv1.ScanData   = sc;
                    }
                }
                else
                {
                    sublv0.customname = customname;
                    sublv0.ScanData   = sc;
                }

                return(true);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Failed to add system " + sc.BodyName + " not enough elements");
                return(false);
            }
        }
Example #5
0
        // extract elements of the name and form into an element array
        // element[0] is the star or barycentre
        // element[0] star/barycentre [ element[1] planet [ element[2] submoon [ element[3] subsubmoon ]]]
        // if belt cluster, we get [0] = star, [1] = belt, [2] = cluster N
        // if ring, we get [0] = star, [2] = body, ... [last-1] = ring name

        private List <string> ExtractElementsJournalScan(JournalScan sc, ISystem sys, out ScanNodeType starscannodetype, out bool isbeltcluster, out bool isring)
        {
            starscannodetype = ScanNodeType.star;
            isbeltcluster    = false;
            isring           = false;
            List <string> elements;

            string rest = sc.IsStarNameRelatedReturnRest(sys.Name, sys.SystemAddress);                // extract any relationship between the system we are in and the name, and return it if so

            if (rest != null)                                                                         // if we have a relationship between the system name and the body name
            {
                if (sc.IsStar && !sc.IsEDSMBody && sc.DistanceFromArrivalLS == 0 && rest.Length >= 2) // star, primary, with name >= 2 (AB)
                {
                    elements = new List <string> {
                        rest
                    };                                                                                     // its a star, default
                }
                else if (rest.Length > 0)                                                                  // we have characters in rest, and its related to the system name
                {
                    elements = rest.Split(' ').ToList();                                                   // split into spaced parts

                    if (elements.Count == 4 && elements[0].Length == 1 && char.IsLetter(elements[0][0]) && // A belt cluster N
                        elements[1].Equals("belt", StringComparison.InvariantCultureIgnoreCase) &&
                        elements[2].Equals("cluster", StringComparison.InvariantCultureIgnoreCase))
                    {
                        elements = new List <string> {
                            MainStar, elements[0] + " " + elements[1], elements[2] + " " + elements[3]
                        };                                                                                                              // reform into Main Star | A belt | Cluster N
                        isbeltcluster = true;
                    }
                    else if (elements.Count == 5 && elements[0].Length >= 1 &&                                      // AA A belt cluster N
                             elements[1].Length == 1 && char.IsLetter(elements[1][0]) &&
                             elements[2].Equals("belt", StringComparison.InvariantCultureIgnoreCase) &&
                             elements[3].Equals("cluster", StringComparison.InvariantCultureIgnoreCase))
                    {
                        elements = new List <string> {
                            elements[0], elements[1] + " " + elements[2], elements[3] + " " + elements[4]
                        };                                                                                                                  // reform into <star> | A belt | Cluster N
                        isbeltcluster = true;
                    }
                    else if (elements.Count >= 3 &&
                             elements[elements.Count - 1].Equals("ring", StringComparison.InvariantCultureIgnoreCase) &&        // A 2 A ring
                             elements[elements.Count - 2].Length == 1 &&
                             char.IsLetter(elements[elements.Count - 2][0]))
                    {                                                                                               // reform into A | 2 | A ring three level or A A ring
                        elements = elements.Take(elements.Count - 2).Concat(new string[] { elements[elements.Count - 2] + " " + elements[elements.Count - 1] }).ToList();
                        isring   = true;
                    }

                    if (char.IsDigit(elements[0][0]))                                   // if digits, planet number, no star designator
                    {
                        elements.Insert(0, MainStar);                                   // no star designator, main star, add MAIN
                    }
                    else if (elements[0].Length > 1 && elements[0] != MainStar)         // designator, is it multiple chars.. its a barycentre ABC
                    {
                        starscannodetype = ScanNodeType.barycentre;                     // override node type to barycentre
                    }
                }
                else
                {
                    elements = new List <string>();                                     // only 1 item, the star, which is the same as the system name..
                    elements.Add(MainStar);                                             // Sol / SN:Sol should come thru here
                }
            }
            else if (sc.IsStar && !sc.IsEDSMBody && sc.DistanceFromArrivalLS == 0)      // name has no relationship to system (Gliese..) and its a star at LS=0
            {
                elements = new List <string> {
                    sc.BodyName
                };                                                                      // its a star
            }
            else
            {                                                                           // name has no relationship to system (Earth) but its not at LS=0
                elements = sc.BodyName.Split(' ').ToList();                             // use all bodyparts, and
                elements.Insert(0, MainStar);                                           // insert the MAIN designator as the star designator
            }

            return(elements);
        }