public static HistoryEntry FromJournalEntry(JournalEntry je, HistoryEntry prev)
        {
            ISystem isys = prev == null ? new SystemClass("Unknown") : prev.System;

            if (je.EventTypeID == JournalTypeEnum.Location || je.EventTypeID == JournalTypeEnum.FSDJump || je.EventTypeID == JournalTypeEnum.CarrierJump)
            {
                JournalLocOrJump jl = je as JournalLocOrJump;

                ISystem newsys;

                if (jl != null && jl.HasCoordinate)       // LAZY LOAD IF it has a co-ord.. the front end will when it needs it
                {
                    newsys = new SystemClass(jl.StarSystem, jl.StarPos.X, jl.StarPos.Y, jl.StarPos.Z)
                    {
                        EDSMID         = 0, // not an EDSM entry
                        SystemAddress  = jl.SystemAddress,
                        Population     = jl.Population ?? 0,
                        Faction        = jl.Faction,
                        Government     = jl.EDGovernment,
                        Allegiance     = jl.EDAllegiance,
                        State          = jl.EDState,
                        Security       = jl.EDSecurity,
                        PrimaryEconomy = jl.EDEconomy,
                        Power          = jl.PowerList,
                        PowerState     = jl.PowerplayState,
                        Source         = jl.StarPosFromEDSM ? SystemSource.FromEDSM : SystemSource.FromJournal,
                    };

                    SystemCache.FindCachedJournalSystem(newsys);        // this puts it in the cache

                    // If it was a new system, pass the coords back to the StartJump
                    if (prev != null && prev.journalEntry is JournalStartJump)
                    {
                        prev.System = newsys;       // give the previous startjump our system..
                    }
                }
                else
                {
                    // NOTE Rob: 09-JAN-2018 I've removed the Jumpstart looking up a system by name since they were using up lots of lookup time during history reading.
                    // This is used for pre 2.2 systems without co-ords, which now should be limited.
                    // JumpStart still gets the system when the FSD loc is processed, see above.
                    // Jumpstart was also screwing about with the EDSM ID fill in which was broken.  This is now working again.

                    newsys = new SystemClass(jl.StarSystem);         // this will be a synthesised one
                }

                isys = newsys;
            }

            HistoryEntry he = new HistoryEntry
            {
                journalEntry = je,
                System       = isys,
                EntryStatus  = HistoryEntryStatus.Update(prev?.EntryStatus, je, isys.Name)
            };

            he.TravelStatus = HistoryTravelStatus.Update(prev?.TravelStatus, prev, he);     // need a real he so can't do that as part of the constructor.

            return(he);
        }
Esempio n. 2
0
        public static HistoryEntry FromJournalEntry(JournalEntry je, HistoryEntry prev, out bool journalupdate, SQLiteConnectionSystem conn = null)
        {
            ISystem isys    = prev == null ? new SystemClass("Unknown") : prev.System;
            int     indexno = prev == null ? 1 : prev.Indexno + 1;

            journalupdate = false;

            if (je.EventTypeID == JournalTypeEnum.Location || je.EventTypeID == JournalTypeEnum.FSDJump)
            {
                JournalLocOrJump jl = je as JournalLocOrJump;

                ISystem newsys;

                if (jl != null && jl.HasCoordinate)       // LAZY LOAD IF it has a co-ord.. the front end will when it needs it
                {
                    newsys = new SystemClass(jl.StarSystem, jl.StarPos.X, jl.StarPos.Y, jl.StarPos.Z)
                    {
                        EDSMID         = jl.EdsmID < 0 ? 0 : jl.EdsmID, // pass across the EDSMID for the lazy load process.
                        SystemAddress  = jl.SystemAddress,
                        Population     = jl.Population ?? 0,
                        Faction        = jl.Faction,
                        Government     = jl.EDGovernment,
                        Allegiance     = jl.EDAllegiance,
                        State          = jl.EDState,
                        Security       = jl.EDSecurity,
                        PrimaryEconomy = jl.EDEconomy,
                        Power          = jl.PowerList,
                        PowerState     = jl.PowerplayState,
                        status         = SystemStatusEnum.EDDiscovery,
                    };

                    // If it was a new system, pass the coords back to the StartJump
                    if (prev != null && prev.journalEntry is JournalStartJump)
                    {
                        prev.System = newsys;       // give the previous startjump our system..
                    }
                }
                else
                {
                    // NOTE Rob: 09-JAN-2018 I've removed the Jumpstart looking up a system by name since they were using up lots of lookup time during history reading.
                    // This is used for pre 2.2 systems without co-ords, which now should be limited.
                    // JumpStart still gets the system when the FSD loc is processed, see above.
                    // Jumpstart was also screwing about with the EDSM ID fill in which was broken.  This is now working again.

                    // Default one
                    newsys        = new SystemClass(jl.StarSystem);
                    newsys.EDSMID = je.EdsmID;

                    ISystem s = SystemCache.FindSystem(newsys, conn); // has no co-ord, did we find it?

                    if (s != null)                                    // found a system..
                    {
                        if (jl != null && jl.HasCoordinate)           // if journal Loc, and journal has a star position, use that instead of EDSM..
                        {
                            s.X = Math.Round(jl.StarPos.X * 32.0) / 32.0;
                            s.Y = Math.Round(jl.StarPos.Y * 32.0) / 32.0;
                            s.Z = Math.Round(jl.StarPos.Z * 32.0) / 32.0;
                        }

                        //Debug.WriteLine("HistoryList found system {0} {1}", s.id_edsm, s.name);
                        newsys = s;

                        if (jl != null && je.EdsmID <= 0 && newsys.EDSMID > 0) // only update on a JL..
                        {
                            journalupdate = true;
                            Debug.WriteLine("HE EDSM ID update requested {0} {1}", newsys.EDSMID, newsys.Name);
                        }
                    }
                    else
                    {
                        newsys.EDSMID = -1;        // mark as checked but not found
                    }
                }

                JournalFSDJump jfsd = je as JournalFSDJump;

                if (jfsd != null)
                {
                    if (jfsd.JumpDist <= 0 && isys.HasCoordinate && newsys.HasCoordinate) // if no JDist, its a really old entry, and if previous has a co-ord
                    {
                        jfsd.JumpDist = isys.Distance(newsys);                            // fill it out here

                        if (jfsd.JumpDist > 0)
                        {
                            journalupdate = true;
                            Debug.WriteLine("Je Jump distance update(3) requested {0} {1} {2}", newsys.EDSMID, newsys.Name, jfsd.JumpDist);
                        }
                    }
                }

                isys = newsys;
            }

            HistoryEntry he = new HistoryEntry
            {
                Indexno      = indexno,
                journalEntry = je,
                System       = isys,
                EntryStatus  = HistoryEntryStatus.Update(prev?.EntryStatus, je, isys.Name)
            };

            he.TravelStatus = HistoryTravelStatus.Update(prev?.TravelStatus, prev, he);     // need a real he so can't do that as part of the constructor.

            return(he);
        }