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); }
public HistoryTravelStatus(HistoryTravelStatus prevstatus) { TravelledDistance = prevstatus.TravelledDistance; TravelledSeconds = prevstatus.TravelledSeconds; TravelledMissingjump = prevstatus.TravelledMissingjump; Travelledjumps = prevstatus.Travelledjumps; IsShutDown = false; // can't be shutdown if copied.. IsTravelling = true; // must be travelling }
// previous and heprev can be null, hecur is always set public static HistoryTravelStatus Update(HistoryTravelStatus previous, HistoryEntry heprev, HistoryEntry hecur) { if (previous == null || (heprev?.StopMarker ?? false)) // if prev is null (start of list) OR previous ordered a stop, new list { previous = new HistoryTravelStatus(); } if (previous.IsTravelling == false && hecur.StartMarker == false) // if not travelling, and not ordered a start, we are in inert, return previous { return(previous); } if (previous.IsShutDown) { if (hecur.EntryType != JournalTypeEnum.LoadGame) // in shutdown, and not loadgame, no counting, return previous { return(previous); } } TimeSpan diff = hecur.EventTimeUTC.Subtract(heprev?.EventTimeUTC ?? hecur.EventTimeUTC); // heprev can be null, cope. if (hecur.EntryType == JournalTypeEnum.Fileheader && diff >= new TimeSpan(0, 30, 0)) // if we have a load game, and previous one was > X, its a game gap { return(previous); // older logs did not have the shutdown event. } HistoryTravelStatus cur = new HistoryTravelStatus(previous); // fresh entry, not shutdown, travelling if (!hecur.MultiPlayer) // multiplayer bits don't count, but we need a fresh entry because we are now monitoring for shutdown. { if (hecur.journalEntry is JournalFSDJump) // if jump, and not multiplayer.. { double dist = ((JournalFSDJump)hecur.journalEntry).JumpDist; if (dist <= 0) { cur.TravelledMissingjump++; } else { cur.TravelledDistance += dist; cur.Travelledjumps++; } } cur.TravelledSeconds += diff; } if (hecur.EntryType == JournalTypeEnum.Shutdown) // if into a shutdown, note { cur.IsShutDown = true; } return(cur); }
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); }