private void Discoveryform_OnNewEntry(EliteDangerousCore.HistoryEntry he, EliteDangerousCore.HistoryList hel) { if (current != null) { bool tryadd = true; // normally go for it.. if (current.Type == FilterEntry.EntryType.Time) // time is limited { tryadd = he.EventTimeUTC <= current.EndTime; } else if (current.Type == FilterEntry.EntryType.Mission) // mission is limited, lookup mission and check end time { MissionState ml = current.MissionKey != null && he.MissionList.Missions.ContainsKey(current.MissionKey) ? he.MissionList.Missions[current.MissionKey] : null; tryadd = ml != null ? (he.EventTimeUTC <= ml.MissionEndTime) : false; } if (tryadd) { if (AddToGrid(he, true)) // if did add.. { SetLabels(); } } } if (he.EntryType == JournalTypeEnum.MissionAccepted) // mission accepted means another entry.. { FillCampaignCombo(); // could only add entries, so no need to check it its disappeared } }
public JToken NewJRec(HistoryList hl, string type, int startindex, int length) { JObject response = new JObject(); response["responsetype"] = type; response["firstrow"] = startindex; JArray jarray = new JArray(); for (int i = startindex; i > Math.Max(-1, startindex - length); i--) { EliteDangerousCore.HistoryEntry he = hl.EntryOrder()[i]; JArray jent = new JArray(); jent.Add(he.journalEntry.GetIconPackPath); jent.Add(he.journalEntry.EventTimeUTC); he.FillInformation(out string info, out string detailed); string note = (he.snc != null) ? he.snc.Note : ""; jent.Add(he.EventSummary); jent.Add(info); jent.Add(note); jarray.Add(jent); } response["rows"] = jarray; return(response); }
private void Discoveryform_OnNewEntry(EliteDangerousCore.HistoryEntry he, EliteDangerousCore.HistoryList hel) { if (current != null) { bool tryadd = true; // normally go for it.. if (current.Type == FilterEntry.EntryType.Time) // time is limited { tryadd = he.EventTimeUTC <= current.EndTimeUTC; } else if (current.Type == FilterEntry.EntryType.Mission) // mission is limited, lookup mission and check end time { MissionState ms = hel.MissionListAccumulator.GetMission(current.MissionKey ?? "-"); tryadd = ms != null ? (he.EventTimeUTC <= ms.MissionEndTime) : false; } if (tryadd) { if (insertToGrid(he)) // if did add.. { SetLabels(); } } if (he.EntryType == JournalTypeEnum.Undocked && current.Type == FilterEntry.EntryType.Lastdock) // on undock, and we are in last docked mode, refresh { Display(); } } if (he.EntryType == JournalTypeEnum.MissionAccepted) // mission accepted means another entry.. { FillCampaignCombo(); // could only add entries, so no need to check it its disappeared } SetTarget(he); }
// used by historylist directly for a single update during play, in foreground.. Also used by above.. so can be either in fore/back public bool AddScanToBestSystem(JournalScan je, int startindex, List <HistoryEntry> hl, out HistoryEntry he, out JournalLocOrJump jl) { for (int j = startindex; j >= 0; j--) { he = hl[j]; if (he.IsLocOrJump) { jl = (JournalLocOrJump)he.journalEntry; string designation = GetBodyDesignation(je, he.System.Name); if (je.IsStarNameRelated(he.System.Name, designation)) // if its part of the name, use it { je.BodyDesignation = designation; return(Process(je, he.System, true)); } else if (jl != null && je.IsStarNameRelated(jl.StarSystem, designation)) { // Ignore scans where the system name has changed return(false); } } } jl = null; he = null; je.BodyDesignation = GetBodyDesignation(je, hl[startindex].System.Name); return(Process(je, hl[startindex].System, true)); // no relationship, add.. }
// used by historylist directly for a single update during play, in foreground.. Also used by above.. so can be either in fore/back public bool AddBodyToBestSystem(IBodyNameAndID je, int startindex, List <HistoryEntry> hl, out HistoryEntry he, out JournalLocOrJump jl) { if (je.Body == null || je.BodyType == "Station" || je.BodyType == "PlanetaryRing" || je.BodyType == "SmallBody") { he = null; jl = null; return(false); } for (int j = startindex; j >= 0; j--) { he = hl[j]; if (he.IsLocOrJump && he.System.Name == je.StarSystem && (he.System.SystemAddress == null || je.SystemAddress == null || he.System.SystemAddress == je.SystemAddress)) { jl = (JournalLocOrJump)he.journalEntry; string designation = GetBodyDesignation(je); if (IsStarNameRelated(he.System.Name, je.Body, designation)) // if its part of the name, use it { je.BodyDesignation = designation; return(Process(je, he.System, true)); } else if (jl != null && IsStarNameRelated(jl.StarSystem, je.Body, designation)) { // Ignore scans where the system name has changed return(false); } } } jl = null; he = null; je.BodyDesignation = GetBodyDesignation(je); return(Process(je, hl[startindex].System, true)); // no relationship, add.. }
public static HistoryEntry FromJournalEntry(JournalEntry je, HistoryEntry prev, out bool journalupdate, SQLiteConnectionSystem conn = null, EDCommander cmdr = null) { ISystem isys = prev == null ? new SystemClass("Unknown") : prev.System; int indexno = prev == null ? 1 : prev.Indexno + 1; int mapcolour = 0; journalupdate = false; bool starposfromedsm = false; bool firstdiscover = 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. Faction = jl.Faction, Government = jl.EDGovernment, PrimaryEconomy = jl.EDEconomy, Security = jl.EDSecurity, Population = jl.Population ?? 0, State = jl.EDState, Allegiance = jl.EDAllegiance, UpdateDate = jl.EventTimeUTC, status = SystemStatusEnum.EDDiscovery, SystemAddress = jl.SystemAddress, }; // 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); } } mapcolour = jfsd.MapColor; } isys = newsys; starposfromedsm = (jl != null && jl.HasCoordinate) ? jl.StarPosFromEDSM : newsys.HasCoordinate; firstdiscover = jl == null ? false : jl.EDSMFirstDiscover; } string summary, info, detailed; je.FillInformation(out summary, out info, out detailed); HistoryEntry he = new HistoryEntry { Indexno = indexno, EntryType = je.EventTypeID, Journalid = je.Id, journalEntry = je, System = isys, EventTimeUTC = je.EventTimeUTC, MapColour = mapcolour, EdsmSync = je.SyncedEDSM, EDDNSync = je.SyncedEDDN, EGOSync = je.SyncedEGO, StartMarker = je.StartMarker, StopMarker = je.StopMarker, EventSummary = summary, EventDescription = info, EventDetailedInfo = detailed, IsStarPosFromEDSM = starposfromedsm, IsEDSMFirstDiscover = firstdiscover, Commander = cmdr ?? EDCommander.GetCommander(je.CommanderId) }; // WORK out docked/landed state if (prev != null) { if (prev.docked.HasValue) // copy docked.. { he.docked = prev.docked; } if (prev.landed.HasValue) { he.landed = prev.landed; } if (prev.hyperspace.HasValue) { he.hyperspace = prev.hyperspace; } if (prev.marketId != null) { he.marketId = prev.marketId; } if (prev.wanted.HasValue) { he.wanted = prev.wanted; } he.stationName = prev.stationName; he.shiptype = prev.shiptype; he.shipid = prev.shipid; he.whereami = prev.whereami; he.onCrewWithCaptain = prev.onCrewWithCaptain; he.gamemode = prev.gamemode; he.group = prev.group; } if (je.EventTypeID == JournalTypeEnum.Location) { JournalLocation jl = je as JournalLocation; he.docked = jl.Docked; he.landed = jl.Latitude.HasValue; he.whereami = jl.Docked ? jl.StationName : jl.Body; he.hyperspace = false; he.wanted = jl.Wanted; } else if (je.EventTypeID == JournalTypeEnum.Docked) { JournalDocked jl = je as JournalDocked; he.docked = true; he.whereami = jl.StationName; he.stationName = jl.StationName; he.marketId = jl.MarketID; } else if (je.EventTypeID == JournalTypeEnum.Undocked) { he.docked = false; he.stationName = null; he.marketId = null; } else if (je.EventTypeID == JournalTypeEnum.Touchdown) { he.landed = true; } else if (je.EventTypeID == JournalTypeEnum.Liftoff) { he.landed = !(je as JournalLiftoff).PlayerControlled; } else if (je.EventTypeID == JournalTypeEnum.SupercruiseEntry) { he.whereami = (je as JournalSupercruiseEntry).StarSystem; he.hyperspace = true; } else if (je.EventTypeID == JournalTypeEnum.SupercruiseExit) { he.whereami = (je as JournalSupercruiseExit).Body; he.hyperspace = false; } else if (je.EventTypeID == JournalTypeEnum.FSDJump) { JournalFSDJump ju = (je as JournalFSDJump); he.whereami = ju.StarSystem; he.hyperspace = true; he.wanted = ju.Wanted; } else if (je.EventTypeID == JournalTypeEnum.StartJump) { he.hyperspace = true; // some of these are just to make sure, as FSDJump will also set it } else if (je.EventTypeID == JournalTypeEnum.LoadGame) { JournalLoadGame jl = je as JournalLoadGame; he.onCrewWithCaptain = null; // can't be in a crew at this point he.gamemode = jl.GameMode; // set game mode he.group = jl.Group; // and group, may be empty he.landed = jl.StartLanded; he.hyperspace = false; if (jl.Ship.IndexOf("buggy", StringComparison.InvariantCultureIgnoreCase) == -1) // load game with buggy, can't tell what ship we get back into, so ignore { he.shiptype = (je as JournalLoadGame).Ship; he.shipid = (je as JournalLoadGame).ShipId; } } else if (je.EventTypeID == JournalTypeEnum.ShipyardBuy) // BUY does not have ship id, but the new entry will that is written later - journals 8.34 { he.shiptype = (je as JournalShipyardBuy).ShipType; } else if (je.EventTypeID == JournalTypeEnum.ShipyardNew) { he.shiptype = (je as JournalShipyardNew).ShipType; he.shipid = (je as JournalShipyardNew).ShipId; } else if (je.EventTypeID == JournalTypeEnum.ShipyardSwap) { he.shiptype = (je as JournalShipyardSwap).ShipType; he.shipid = (je as JournalShipyardSwap).ShipId; } else if (je.EventTypeID == JournalTypeEnum.JoinACrew) { he.onCrewWithCaptain = (je as JournalJoinACrew).Captain; } else if (je.EventTypeID == JournalTypeEnum.QuitACrew) { he.onCrewWithCaptain = null; } if (prev != null && prev.travelling) // if we are travelling.. { he.travelled_distance = prev.travelled_distance; he.travelled_missingjump = prev.travelled_missingjump; he.travelled_jumps = prev.travelled_jumps; if (he.IsFSDJump && !he.MultiPlayer) // if jump, and not multiplayer.. { double dist = ((JournalFSDJump)je).JumpDist; if (dist <= 0) { he.travelled_missingjump++; } else { he.travelled_distance += dist; he.travelled_jumps++; } } he.travelled_seconds = prev.travelled_seconds; TimeSpan diff = he.EventTimeUTC.Subtract(prev.EventTimeUTC); if (he.EntryType != JournalTypeEnum.LoadGame && diff < new TimeSpan(2, 0, 0)) // time between last entry and load game is not real time { he.travelled_seconds += diff; } if (he.StopMarker || he.StartMarker) { //Debug.WriteLine("Travelling stop at " + he.Indexno); he.travelling = false; he.EventDetailedInfo += ((he.EventDetailedInfo.Length > 0) ? Environment.NewLine : "") + "Travelled " + he.travelled_distance.ToStringInvariant("0.0") + " LY" + ", " + he.travelled_jumps + " jumps" + ((he.travelled_missingjump > 0) ? ", " + he.travelled_missingjump + " unknown distance jumps" : "") + ", time " + he.travelled_seconds; he.travelled_distance = 0; he.travelled_seconds = new TimeSpan(0); } else { he.travelling = true; if (he.IsFSDJump) { he.EventDetailedInfo += ((he.EventDetailedInfo.Length > 0) ? Environment.NewLine : "") + "Travelling" + " distance " + he.travelled_distance.ToString("0.0") + " LY" + ", " + he.travelled_jumps + " jumps" + ((he.travelled_missingjump > 0) ? ", " + he.travelled_missingjump + " unknown distance jumps" : "") + ", time " + he.travelled_seconds; } } } if (he.StartMarker) { //Debug.WriteLine("Travelling start at " + he.Indexno); he.travelling = true; } return(he); }
public void ProcessWithUserDb(JournalEntry je, HistoryEntry prev, HistoryList hl, SQLiteConnectionUser conn) // called after above with a USER connection { materialscommodities = MaterialCommoditiesList.Process(je, prev?.materialscommodities, conn, EliteConfigInstance.InstanceConfig.ClearMaterials, EliteConfigInstance.InstanceConfig.ClearCommodities); snc = SystemNoteClass.GetSystemNote(Journalid, IsFSDJump, System); // may be null }
public void ProcessWithUserDb(JournalEntry je, HistoryEntry prev, HistoryList hl) // called after above with a USER connection { MaterialCommodity = MaterialCommoditiesList.Process(je, prev?.MaterialCommodity); snc = SystemNoteClass.GetSystemNote(Journalid, IsFSDJump, System); // may be null }
// 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.IsFSDJump) // 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) { 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, source = jl.StarPosFromEDSM ? SystemSource.FromEDSM : SystemSource.FromJournal, }; SystemCache.FindCachedJournalSystem(newsys); // 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); // this will be a synthesised one, unless we find an EDSM to replace it newsys.EDSMID = je.EdsmID; ISystem s = SystemCache.FindSystem(newsys); // 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); }
public static HistoryEntry FromJournalEntry(JournalEntry je, HistoryEntry prev, bool checkedsm, out bool journalupdate, SQLiteConnectionSystem conn = null, EDCommander cmdr = null) { ISystem isys = prev == null ? new SystemClassDB("Unknown") : prev.System; int indexno = prev == null ? 1 : prev.Indexno + 1; int mapcolour = 0; journalupdate = false; bool starposfromedsm = false; bool firstdiscover = false; if (je.EventTypeID == JournalTypeEnum.Location || je.EventTypeID == JournalTypeEnum.FSDJump) { JournalLocOrJump jl = je as JournalLocOrJump; JournalFSDJump jfsd = je as JournalFSDJump; ISystem newsys; if (jl.HasCoordinate) // LAZY LOAD IF it has a co-ord.. the front end will when it needs it { newsys = new SystemClassDB(jl.StarSystem, jl.StarPos.X, jl.StarPos.Y, jl.StarPos.Z); newsys.id_edsm = jl.EdsmID < 0 ? 0 : jl.EdsmID; // pass across the EDSMID for the lazy load process. if (jfsd != null && jfsd.JumpDist <= 0 && isys.HasCoordinate) // if we don't have a jump distance (pre 2.2) but the last sys does have pos, we can compute distance and update entry { jfsd.JumpDist = SystemClassDB.Distance(isys, newsys); // fill it out here journalupdate = true; } } else { // Default one newsys = new SystemClassDB(jl.StarSystem); newsys.id_edsm = jl.EdsmID; if (checkedsm) // see if we can find the right system { SystemClassDB s = SystemClassDB.FindEDSM(newsys, conn); // has no co-ord, did we find it? if (s != null) // yes, use, and update the journal with the esdmid, and also the position if we have a co-ord { // so next time we don't have to do this again.. if (jl.HasCoordinate) { 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; } newsys = s; if (jfsd != null && jfsd.JumpDist <= 0 && newsys.HasCoordinate && isys.HasCoordinate) // if we don't have a jump distance (pre 2.2) but the last sys does, we can compute { jfsd.JumpDist = SystemClassDB.Distance(isys, newsys); // fill it out here. EDSM systems always have co-ords, but we should check anyway journalupdate = true; } if (jl.EdsmID <= 0 && newsys.id_edsm > 0) { journalupdate = true; } } } } 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 = SystemClassDB.Distance(isys, newsys); // fill it out here journalupdate = true; } mapcolour = jfsd.MapColor; } isys = newsys; starposfromedsm = jl.HasCoordinate ? jl.StarPosFromEDSM : newsys.HasCoordinate; firstdiscover = jl.EDSMFirstDiscover; } string summary, info, detailed; je.FillInformation(out summary, out info, out detailed); HistoryEntry he = new HistoryEntry { Indexno = indexno, EntryType = je.EventTypeID, Journalid = je.Id, journalEntry = je, System = isys, EventTimeUTC = je.EventTimeUTC, MapColour = mapcolour, EdsmSync = je.SyncedEDSM, EDDNSync = je.SyncedEDDN, EGOSync = je.SyncedEGO, StartMarker = je.StartMarker, StopMarker = je.StopMarker, EventSummary = summary, EventDescription = info, EventDetailedInfo = detailed, IsStarPosFromEDSM = starposfromedsm, IsEDSMFirstDiscover = firstdiscover, Commander = cmdr ?? EDCommander.GetCommander(je.CommanderId) }; // WORK out docked/landed state if (prev != null) { if (prev.docked.HasValue) // copy docked.. { he.docked = prev.docked; } if (prev.landed.HasValue) { he.landed = prev.landed; } he.shiptype = prev.shiptype; he.shipid = prev.shipid; he.whereami = prev.whereami; he.onCrewWithCaptain = prev.onCrewWithCaptain; he.gamemode = prev.gamemode; he.group = prev.group; } if (je.EventTypeID == JournalTypeEnum.Location) { JournalLocation jl = je as JournalLocation; he.docked = jl.Docked; he.whereami = jl.Docked ? jl.StationName : jl.Body; } else if (je.EventTypeID == JournalTypeEnum.Docked) { JournalDocked jl = je as JournalDocked; he.docked = true; he.whereami = jl.StationName; } else if (je.EventTypeID == JournalTypeEnum.Undocked) { he.docked = false; } else if (je.EventTypeID == JournalTypeEnum.Touchdown) { he.landed = true; } else if (je.EventTypeID == JournalTypeEnum.Liftoff) { he.landed = false; } else if (je.EventTypeID == JournalTypeEnum.SupercruiseEntry) { he.whereami = (je as JournalSupercruiseEntry).StarSystem; } else if (je.EventTypeID == JournalTypeEnum.SupercruiseExit) { he.whereami = (je as JournalSupercruiseExit).Body; } else if (je.EventTypeID == JournalTypeEnum.FSDJump) { he.whereami = (je as JournalFSDJump).StarSystem; } else if (je.EventTypeID == JournalTypeEnum.LoadGame) { JournalLoadGame jl = je as JournalLoadGame; he.onCrewWithCaptain = null; // can't be in a crew at this point he.gamemode = jl.GameMode; // set game mode he.group = jl.Group; // and group, may be empty he.landed = jl.StartLanded; if (jl.Ship.IndexOf("buggy", StringComparison.InvariantCultureIgnoreCase) == -1) // load game with buggy, can't tell what ship we get back into, so ignore { he.shiptype = (je as JournalLoadGame).Ship; he.shipid = (je as JournalLoadGame).ShipId; } } else if (je.EventTypeID == JournalTypeEnum.ShipyardBuy) // BUY does not have ship id, but the new entry will that is written later - journals 8.34 { he.shiptype = (je as JournalShipyardBuy).ShipType; } else if (je.EventTypeID == JournalTypeEnum.ShipyardNew) { he.shiptype = (je as JournalShipyardNew).ShipType; he.shipid = (je as JournalShipyardNew).ShipId; } else if (je.EventTypeID == JournalTypeEnum.ShipyardSwap) { he.shiptype = (je as JournalShipyardSwap).ShipType; he.shipid = (je as JournalShipyardSwap).ShipId; } else if (je.EventTypeID == JournalTypeEnum.JoinACrew) { he.onCrewWithCaptain = (je as JournalJoinACrew).Captain; } else if (je.EventTypeID == JournalTypeEnum.QuitACrew) { he.onCrewWithCaptain = null; } if (prev != null && prev.travelling) // if we are travelling.. { he.travelled_distance = prev.travelled_distance; he.travelled_missingjump = prev.travelled_missingjump; he.travelled_jumps = prev.travelled_jumps; if (he.IsFSDJump && !he.MultiPlayer) // if jump, and not multiplayer.. { double dist = ((JournalFSDJump)je).JumpDist; if (dist <= 0) { he.travelled_missingjump++; } else { he.travelled_distance += dist; he.travelled_jumps++; } } he.travelled_seconds = prev.travelled_seconds; TimeSpan diff = he.EventTimeUTC.Subtract(prev.EventTimeUTC); if (he.EntryType != JournalTypeEnum.LoadGame && diff < new TimeSpan(2, 0, 0)) // time between last entry and load game is not real time { he.travelled_seconds += diff; } if (he.StopMarker || he.StartMarker) { //Debug.WriteLine("Travelling stop at " + he.Indexno); he.travelling = false; he.EventDetailedInfo += ((he.EventDetailedInfo.Length > 0) ? Environment.NewLine : "") + "Travelled " + he.travelled_distance.ToStringInvariant("0.0") + " LY" + ", " + he.travelled_jumps + " jumps" + ((he.travelled_missingjump > 0) ? ", " + he.travelled_missingjump + " unknown distance jumps" : "") + ", time " + he.travelled_seconds; he.travelled_distance = 0; he.travelled_seconds = new TimeSpan(0); } else { he.travelling = true; if (he.IsFSDJump) { he.EventDetailedInfo += ((he.EventDetailedInfo.Length > 0) ? Environment.NewLine : "") + "Travelling" + " distance " + he.travelled_distance.ToString("0.0") + " LY" + ", " + he.travelled_jumps + " jumps" + ((he.travelled_missingjump > 0) ? ", " + he.travelled_missingjump + " unknown distance jumps" : "") + ", time " + he.travelled_seconds; } } } if (he.StartMarker) { //Debug.WriteLine("Travelling start at " + he.Indexno); he.travelling = true; } return(he); }
public static void AddToVisitsScan(HistoryList hist, HistoryEntry he, Action <string> logerror) { if ((hist.LastSystem == null || he.System.Name != hist.LastSystem) && he.System.Name != "Unknown") // if system is not last, we moved somehow (FSD, location, carrier jump), add { if (hist.Visited.TryGetValue(he.System.Name, out var value)) { he.Visits = value.Visits + 1; // visits is 1 more than previous entry hist.Visited[he.System.Name] = he; // reset to point to latest he } else { he.Visits = 1; // first visit hist.Visited[he.System.Name] = he; // point to he } hist.LastSystem = he.System.Name; } if (he.EntryType == JournalTypeEnum.Scan) { if (logerror != null) { BaseUtils.AppTicks.TickCountLapDelta("Scan", true); } JournalScan js = he.journalEntry as JournalScan; if (!hist.StarScan.AddScanToBestSystem(js, hist.historylist.Count - 1, hist.historylist, out HistoryEntry jlhe, out JournalLocOrJump jl)) { if (logerror != null) { // Ignore scans where the system name has been changed // Also ignore belt clusters var bodyname = js.BodyDesignation ?? js.BodyName; if (bodyname == null) { logerror("Body name not set in scan entry"); } else if (jl == null || (jl.StarSystem.Equals(jlhe.System.Name, StringComparison.InvariantCultureIgnoreCase) && !bodyname.ToLowerInvariant().Contains(" belt cluster "))) { logerror("Cannot add scan to system - alert the EDDiscovery developers using either discord or Github (see help)" + Environment.NewLine + "Scan object " + js.BodyName + " in " + he.System.Name); } } else { System.Diagnostics.Debug.WriteLine("******** Cannot add scan to system " + (he.journalEntry as JournalScan).BodyName + " in " + he.System.Name); } } if (logerror != null) { System.Diagnostics.Debug.WriteLine(BaseUtils.AppTicks.TickCountLap("Scan") + " Scan End"); } } else if (he.EntryType == JournalTypeEnum.SAAScanComplete) { hist.StarScan.AddSAAScanToBestSystem((JournalSAAScanComplete)he.journalEntry, hist.historylist.Count - 1, hist.historylist); } else if (he.EntryType == JournalTypeEnum.SAASignalsFound) { hist.StarScan.AddSAASignalsFoundToBestSystem((JournalSAASignalsFound)he.journalEntry, hist.historylist.Count - 1, hist.historylist); } else if (he.EntryType == JournalTypeEnum.FSSDiscoveryScan && he.System != null) { hist.StarScan.SetFSSDiscoveryScan((JournalFSSDiscoveryScan)he.journalEntry, he.System); } else if (he.journalEntry is IBodyNameAndID) { hist.StarScan.AddBodyToBestSystem((IBodyNameAndID)he.journalEntry, hist.historylist.Count - 1, hist.historylist); } }
public static HistoryList LoadHistory(EDJournalUIScanner journalmonitor, Func <bool> cancelRequested, Action <int, string> reportProgress, string NetLogPath = null, bool ForceNetLogReload = false, bool ForceJournalReload = false, int CurrentCommander = Int32.MinValue, int fullhistoryloaddaylimit = 0, string essentialitems = "" ) { HistoryList hist = new HistoryList(); if (CurrentCommander >= 0) { journalmonitor.SetupWatchers(); // Parse files stop monitor.. int forcereloadoflastn = ForceJournalReload ? int.MaxValue / 2 : 0; // if forcing a reload, we indicate that by setting the reload count to a very high value, but not enough to cause int wrap journalmonitor.ParseJournalFilesOnWatchers((p, s) => reportProgress(p, s), forcereloadoflastn); if (NetLogPath != null) { string errstr = null; NetLogClass.ParseFiles(NetLogPath, out errstr, EDCommander.Current.MapColour, () => cancelRequested(), (p, s) => reportProgress(p, s), ForceNetLogReload, currentcmdrid: CurrentCommander); } } Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Files read "); reportProgress(-1, "Reading Database"); List <JournalEntry> jlist; // returned in date ascending, oldest first order. System.Diagnostics.Debug.WriteLine(BaseUtils.AppTicks.TickCountLapDelta("HLL", true) + "History Load"); if (fullhistoryloaddaylimit > 0) { var list = (essentialitems == nameof(JournalEssentialEvents.JumpScanEssentialEvents)) ? JournalEssentialEvents.JumpScanEssentialEvents : (essentialitems == nameof(JournalEssentialEvents.JumpEssentialEvents)) ? JournalEssentialEvents.JumpEssentialEvents : (essentialitems == nameof(JournalEssentialEvents.NoEssentialEvents)) ? JournalEssentialEvents.NoEssentialEvents : (essentialitems == nameof(JournalEssentialEvents.FullStatsEssentialEvents)) ? JournalEssentialEvents.FullStatsEssentialEvents : JournalEssentialEvents.EssentialEvents; jlist = JournalEntry.GetAll(CurrentCommander, ids: list, allidsafterutc: DateTime.UtcNow.Subtract(new TimeSpan(fullhistoryloaddaylimit, 0, 0, 0)) ); } else { jlist = JournalEntry.GetAll(CurrentCommander); } System.Diagnostics.Debug.WriteLine(BaseUtils.AppTicks.TickCountLapDelta("HLL") + "History Load END"); Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Database read " + jlist.Count); HistoryEntry hprev = null; JournalEntry jprev = null; reportProgress(-1, "Creating History"); Stopwatch sw = new Stopwatch(); sw.Start(); foreach (JournalEntry je in jlist) { if (MergeEntries(jprev, je)) // if we merge, don't store into HE { continue; } // Clean up "UnKnown" systems from EDSM log if (je is JournalFSDJump && ((JournalFSDJump)je).StarSystem == "UnKnown") { JournalEntry.Delete(je.Id); continue; } if (je is EliteDangerousCore.JournalEvents.JournalMusic) // remove music.. not shown.. now UI event. remove it for backwards compatibility { //System.Diagnostics.Debug.WriteLine("**** Filter out " + je.EventTypeStr + " on " + je.EventTimeLocal.ToString()); continue; } long timetoload = sw.ElapsedMilliseconds; HistoryEntry he = HistoryEntry.FromJournalEntry(je, hprev); // **** REMEMBER NEW Journal entry needs this too ***************** he.UpdateMaterialsCommodities(je, hprev?.MaterialCommodity); // update material commodities Debug.Assert(he.MaterialCommodity != null); if (CheckForRemoval(he, hprev)) // check here to see if we want to remove the entry.. can move this lower later, but at first point where we have the data { continue; } he.UpdateStats(je, hprev?.Stats, he.StationFaction); he.UpdateSystemNote(); hist.CashLedger.Process(je); // update the ledger he.Credits = hist.CashLedger.CashTotal; hist.Shipyards.Process(je); hist.Outfitting.Process(je); Tuple <ShipInformation, ModulesInStore> ret = hist.ShipInformationList.Process(je, he.WhereAmI, he.System); // the ships he.UpdateShipInformation(ret.Item1); he.UpdateShipStoredModules(ret.Item2); he.UpdateMissionList(hist.missionlistaccumulator.Process(je, he.System, he.WhereAmI)); hist.historylist.Add(he); // now add it to the history AddToVisitsScan(hist, he, null); // add to scan but don't complain if can't add. Do this AFTER add, as it uses the history list hprev = he; jprev = je; } //for (int i = hist.Count - 10; i < hist.Count; i++) System.Diagnostics.Debug.WriteLine("Hist {0} {1} {2}", hist[i].EventTimeUTC, hist[i].Indexno , hist[i].EventSummary); // now database has been updated due to initial fill, now fill in stuff which needs the user database hist.CommanderId = CurrentCommander; EDCommander.Current.FID = hist.GetCommanderFID(); // ensure FID is set.. the other place it gets changed is a read of LoadGame. if (NetLogPath != null) { reportProgress(-1, "Netlog Updating System Positions"); hist.FillInPositionsFSDJumps(); // if netlog reading, try and resolve systems.. } reportProgress(-1, "Done"); return(hist); }
public static HistoryEntry FromJournalEntry(JournalEntry je, HistoryEntry prev) { ISystem isys = prev == null ? new SystemClass("Unknown") : prev.System; int entryno = prev == null ? 1 : prev.EntryNumber + 1; 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 { EntryNumber = entryno, 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); }