Пример #1
0
        public ISystem PosAlongRoute(double percentage)             // go along route and give me a co-ord along it..
        {
            double dist = CumulativeDistance();

            //System.Diagnostics.Debug.WriteLine("Total trip distance " + dist);
            dist *= percentage / 100.0;

            ISystem last = null;

            for (int i = 0; i < Systems.Count; i++)
            {
                ISystem s = SystemCache.FindSystem(Systems[i]);
                if (s != null)
                {
                    if (last != null)
                    {
                        double d = s.Distance(last);

                        if (dist < d)
                        {
                            d = dist / d;
                            //System.Diagnostics.Debug.WriteLine(percentage + " " + d + " last:" + last.X + " " + last.Y + " " + last.Z + " s:" + s.X + " " + s.Y + " " + s.Z);
                            return(new SystemClass("WP" + (i).ToString() + "-" + "WP" + (i + 1).ToString() + "-" + d.ToString("#.00"), last.X + (s.X - last.X) * d, last.Y + (s.Y - last.Y) * d, last.Z + (s.Z - last.Z) * d));
                        }

                        dist -= d;
                    }

                    last = s;
                }
            }

            return(last);
        }
Пример #2
0
        private void StarsFound(List <Tuple <ISystem, double> > systems)       // systems may be null
        {
            System.Diagnostics.Debug.Assert(Application.MessageLoop);

            dataGridView.Rows.Clear();

            if (systems != null)
            {
                DataGridViewColumn sortcol   = dataGridView.SortedColumn != null ? dataGridView.SortedColumn : dataGridView.Columns[1];
                SortOrder          sortorder = dataGridView.SortedColumn != null ? dataGridView.SortOrder : SortOrder.Ascending;

                ISystem cursystem  = discoveryform.history.CurrentSystem;       // could be null
                bool    centresort = false;

                foreach (Tuple <ISystem, double> ret in systems)
                {
                    ISystem  sys    = ret.Item1;
                    string   sep    = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator + " ";
                    object[] rowobj = { sys.Name,
                                        (ret.Item2 >= 0 ? ret.Item2.ToString("0.#") : ""),
                                        (cursystem != null ? cursystem.Distance(sys).ToString("0.#") : ""),
                                        sys.X.ToString("0.#") + sep + sys.Y.ToString("0.#") + sep + sys.Z.ToString("0.#") };

                    dataGridView.Rows.Add(rowobj);
                    dataGridView.Rows[dataGridView.Rows.Count - 1].Tag = sys;
                    centresort |= ret.Item2 >= 0;
                }

                dataGridView.Sort(sortcol, (sortorder == SortOrder.Descending) ? ListSortDirection.Descending : ListSortDirection.Ascending);
                dataGridView.Columns[sortcol.Index].HeaderCell.SortGlyphDirection = sortorder;
            }
        }
Пример #3
0
        public double CumulativeDistance(string start = null)   // optional first system to measure from
        {
            ISystem last     = null;
            double  distance = 0;

            int i = 0;

            if (start != null)
            {
                i = Systems.FindIndex(x => x.Equals(start, StringComparison.InvariantCultureIgnoreCase));
                if (i == -1)
                {
                    return(-1);
                }
            }

            for (; i < Systems.Count; i++)
            {
                ISystem s = SystemCache.FindSystem(Systems[i]);
                if (s != null)
                {
                    if (last != null)
                    {
                        //System.Diagnostics.Debug.WriteLine("Cum dist " + s.Name + " " + last.Name + " " + distance + " " + s.Distance(last));
                        distance += s.Distance(last);
                    }

                    last = s;
                }
            }

            return(distance);
        }
Пример #4
0
        private void UpdateTotalDistances()
        {
            double distance = 0;

            txtCmlDistance.Text = distance.ToString("0.00") + "LY";
            txtP2PDIstance.Text = distance.ToString("0.00") + "LY";
            if (dataGridViewRouteSystems.Rows.Count > 1)
            {
                ISystem firstSC = null;
                ISystem lastSC  = null;
                for (int i = 0; i < dataGridViewRouteSystems.Rows.Count; i++)
                {
                    if (firstSC == null && dataGridViewRouteSystems[0, i].Tag != null)
                    {
                        firstSC = (ISystem)dataGridViewRouteSystems[0, i].Tag;
                    }
                    if (dataGridViewRouteSystems[0, i].Tag != null)
                    {
                        lastSC = (ISystem)dataGridViewRouteSystems[0, i].Tag;
                    }
                    String value = dataGridViewRouteSystems[1, i].Value as string;
                    if (!String.IsNullOrWhiteSpace(value))
                    {
                        distance += Double.Parse(value);
                    }
                }
                txtCmlDistance.Text = distance.ToString("0.00") + "LY";
                distance            = 0;
                if (firstSC != null && lastSC != null)
                {
                    distance            = firstSC.Distance(lastSC);
                    txtP2PDIstance.Text = distance.ToString("0.00") + "LY";
                }
            }
        }
Пример #5
0
        }                                                       // current system

        public double DistanceCurrentTo(string system)          // from current, if we have one, to system, if its found.
        {
            ISystem cursys = CurrentSystem;
            ISystem other  = SystemCache.FindSystem(system);

            return(cursys != null?cursys.Distance(other) : -1);   // current can be null, shipsystem can be null, cursys can not have co-ord, -1 if failed.
        }
Пример #6
0
        }                                                       // current system

        public double DistanceCurrentTo(string system)          // from current, if we have one, to system, if its found.
        {
            ISystem cursys = CurrentSystem();
            ISystem other  = FindSystem(system, null, false);   // does not use EDSM for this, just DB and history

            return(cursys != null?cursys.Distance(other) : -1); // current can be null, shipsystem can be null, cursys can not have co-ord, -1 if failed.
        }
        private void StarsFound(List <Tuple <ISystem, double> > systems)       // systems may be null
        {
            System.Diagnostics.Debug.Assert(Application.MessageLoop);

            dataGridViewEDSM.Rows.Clear();

            if (systems != null)
            {
                ISystem cursystem  = discoveryform.history.CurrentSystem;       // could be null
                bool    centresort = false;

                foreach (Tuple <ISystem, double> ret in systems)
                {
                    ISystem  sys    = ret.Item1;
                    string   sep    = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator + " ";
                    object[] rowobj = { sys.Name,
                                        (ret.Item2 >= 0 ? ret.Item2.ToStringInvariant("0.#") : ""),
                                        (cursystem != null ? cursystem.Distance(sys).ToString("0.#") : ""),
                                        sys.X.ToString("0.#") + sep + sys.Y.ToString("0.#") + sep + sys.Z.ToString("0.#"),
                                        sys.EDSMID.ToStringInvariant() };

                    dataGridViewEDSM.Rows.Add(rowobj);
                    dataGridViewEDSM.Rows[dataGridViewEDSM.Rows.Count - 1].Tag = sys;
                    centresort |= ret.Item2 >= 0;
                }

                dataGridViewEDSM.Sort(centresort ? ColumnCentreDistance : ColumnCurrentDistance, ListSortDirection.Ascending);
            }
        }
Пример #8
0
        public ISystem PosAlongRoute(double percentage)             // go along route and give me a co-ord along it..
        {
            double dist = CumulativeDistance() * percentage / 100.0;

            ISystem last = null;

            for (int i = 0; i < Systems.Count; i++)
            {
                ISystem s = SystemClassDB.GetSystem(Systems[i]);
                if (s != null)
                {
                    if (last != null)
                    {
                        double d = s.Distance(last);

                        if (dist < d)
                        {
                            d = dist / d;

                            return(new SystemClass("WP" + (i).ToString() + "-" + "WP" + (i + 1).ToString() + "-" + d.ToString("#.00"), last.X + (s.X - last.X) * d, last.Y + (s.Y - last.Y) * d, last.Z + (s.Z - last.Z) * d));
                        }

                        dist -= d;
                    }

                    last = s;
                }
            }

            return(last);
        }
Пример #9
0
        private void StarsFound(List <Tuple <HistoryEntry, string, double> > systems)       // systems may be null
        {
            System.Diagnostics.Debug.Assert(Application.MessageLoop);

            dataGridView.Rows.Clear();

            if (systems != null)
            {
                DataGridViewColumn sortcol   = dataGridView.SortedColumn != null ? dataGridView.SortedColumn : dataGridView.Columns[0];
                SortOrder          sortorder = dataGridView.SortedColumn != null ? dataGridView.SortOrder : SortOrder.Descending;

                ISystem cursystem = discoveryform.history.CurrentSystem;        // could be null

                foreach (var ret in systems)
                {
                    ISystem  sys    = ret.Item1.System;
                    string   sep    = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator + " ";
                    object[] rowobj = { (EDDConfig.Instance.DisplayUTC ? ret.Item1.EventTimeUTC : ret.Item1.EventTimeLocal).ToString(),
                                        sys.Name,
                                        ret.Item2,
                                        (cursystem != null ? cursystem.Distance(sys).ToString("0.#") : ""),
                                        sys.X.ToString("0.#") + sep + sys.Y.ToString("0.#") + sep + sys.Z.ToString("0.#") };

                    dataGridView.Rows.Add(rowobj);
                    dataGridView.Rows[dataGridView.Rows.Count - 1].Tag = ret.Item1;
                }

                dataGridView.Sort(sortcol, (sortorder == SortOrder.Descending) ? ListSortDirection.Descending : ListSortDirection.Ascending);
                dataGridView.Columns[sortcol.Index].HeaderCell.SortGlyphDirection = sortorder;
            }
        }
Пример #10
0
        // Async task to find results given cond in helist, using only vars specified.

        private System.Threading.Tasks.Task <List <Tuple <ISystem, object[]> > > Find(List <HistoryEntry> helist, BaseUtils.ConditionLists cond, HashSet <string> varsusedincondition, ISystem cursystem)
        {
            return(System.Threading.Tasks.Task.Run(() =>
            {
                List <Tuple <ISystem, object[]> > rows = new List <Tuple <ISystem, object[]> >();
                foreach (var he in helist)
                {
                    BaseUtils.Variables scandata = new BaseUtils.Variables();
                    scandata.AddPropertiesFieldsOfClass(he.journalEntry, "",
                                                        new Type[] { typeof(System.Drawing.Icon), typeof(System.Drawing.Image), typeof(System.Drawing.Bitmap), typeof(QuickJSON.JObject) }, 5,
                                                        varsusedincondition);

                    bool?res = cond.CheckAll(scandata, out string errlist, out BaseUtils.ConditionLists.ErrorClass errclass);   // need function handler..

                    if (res.HasValue && res.Value == true)
                    {
                        ISystem sys = he.System;
                        string sep = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator + " ";

                        JournalScan js = he.journalEntry as JournalScan;
                        JournalFSSBodySignals jb = he.journalEntry as JournalFSSBodySignals;
                        JournalSAASignalsFound jbs = he.journalEntry as JournalSAASignalsFound;

                        string name, info;
                        if (js != null)
                        {
                            name = js.BodyName;
                            info = js.DisplayString(0);
                        }
                        else if (jb != null)
                        {
                            name = jb.BodyName;
                            jb.FillInformation(he.System, "", out info, out string d);
                        }
                        else
                        {
                            name = jbs.BodyName;
                            jbs.FillInformation(he.System, "", out info, out string d);
                        }

                        object[] rowobj = { EDDConfig.Instance.ConvertTimeToSelectedFromUTC(he.EventTimeUTC).ToString(),
                                            name,
                                            info,
                                            (cursystem != null ? cursystem.Distance(sys).ToString("0.#") : ""),
                                            sys.X.ToString("0.#") + sep + sys.Y.ToString("0.#") + sep + sys.Z.ToString("0.#") };
                        rows.Add(new Tuple <ISystem, object[]>(sys, rowobj));
                    }
                }

                return rows;
            }));
        }
Пример #11
0
        private void buttonFind_Click(object sender, EventArgs e)
        {
            BaseUtils.ConditionLists cond = Valid();
            if (cond != null)
            {
                this.Cursor = Cursors.WaitCursor;
                dataGridView.Rows.Clear();

                DataGridViewColumn sortcol   = dataGridView.SortedColumn != null ? dataGridView.SortedColumn : dataGridView.Columns[0];
                SortOrder          sortorder = dataGridView.SortedColumn != null ? dataGridView.SortOrder : SortOrder.Descending;

                ISystem cursystem = discoveryform.history.CurrentSystem();        // could be null

                foreach (var he in discoveryform.history.FilterByScan())
                {
                    JournalScan js = he.journalEntry as JournalScan;

                    BaseUtils.Variables scandata = new BaseUtils.Variables();
                    scandata.AddPropertiesFieldsOfClass(js, "", new Type[] { typeof(System.Drawing.Icon), typeof(System.Drawing.Image), typeof(System.Drawing.Bitmap), typeof(BaseUtils.JSON.JObject) }, 5);

                    bool?res = cond.CheckAll(scandata, out string errlist, out BaseUtils.ConditionLists.ErrorClass errclass);    // need function handler..

                    if (res.HasValue && res.Value == true)
                    {
                        ISystem  sys    = he.System;
                        string   sep    = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator + " ";
                        object[] rowobj =
                        {
                            EDDConfig.Instance.ConvertTimeToSelectedFromUTC(he.EventTimeUTC).ToString(),
                            js.BodyName,
                            js.DisplayString(0),
                            (cursystem != null ? cursystem.Distance(sys).ToString("0.#") : ""),
                            sys.X.ToString("0.#") + sep + sys.Y.ToString("0.#") + sep + sys.Z.ToString("0.#")
                        };

                        dataGridView.Rows.Add(rowobj);
                        dataGridView.Rows[dataGridView.Rows.Count - 1].Tag = sys;
                    }

                    if (errclass == BaseUtils.ConditionLists.ErrorClass.LeftSideVarUndefined || errclass == BaseUtils.ConditionLists.ErrorClass.RightSideBadFormat)
                    {
                        ExtendedControls.MessageBoxTheme.Show(errlist, "Warning".T(EDTx.Warning), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        break;
                    }
                }

                dataGridView.Sort(sortcol, (sortorder == SortOrder.Descending) ? ListSortDirection.Descending : ListSortDirection.Ascending);
                dataGridView.Columns[sortcol.Index].HeaderCell.SortGlyphDirection = sortorder;
                this.Cursor = Cursors.Default;
            }
        }
Пример #12
0
        private void buttonFind_Click(object sender, EventArgs e)
        {
            BaseUtils.ConditionLists cond = Valid();
            if (cond != null)
            {
                this.Cursor = Cursors.WaitCursor;
                dataGridView.Rows.Clear();

                DataGridViewColumn sortcol   = dataGridView.SortedColumn != null ? dataGridView.SortedColumn : dataGridView.Columns[0];
                SortOrder          sortorder = dataGridView.SortedColumn != null ? dataGridView.SortOrder : SortOrder.Descending;

                ISystem cursystem = discoveryform.history.CurrentSystem;        // could be null

                foreach (var he in discoveryform.history.FilterByScan)
                {
                    JournalScan js = he.journalEntry as JournalScan;

                    BaseUtils.Variables scandata = new BaseUtils.Variables();
                    scandata.AddPropertiesFieldsOfClass(js, "", new Type[] { typeof(System.Drawing.Icon), typeof(System.Drawing.Image), typeof(System.Drawing.Bitmap), typeof(Newtonsoft.Json.Linq.JObject) }, 5);

                    bool?res = cond.CheckAll(scandata, out string errlist);   // need function handler..

                    if (res.HasValue && res.Value == true)
                    {
                        ISystem  sys    = he.System;
                        string   sep    = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator + " ";
                        object[] rowobj =
                        {
                            (EDDConfig.Instance.DisplayUTC ? he.EventTimeUTC : he.EventTimeLocal).ToString(),
                            js.BodyName,
                            js.DisplayString(0,                                                              true),
                            (cursystem != null ? cursystem.Distance(sys).ToString("0.#") : ""),
                            sys.X.ToString("0.#") + sep + sys.Y.ToString("0.#") + sep + sys.Z.ToString("0.#")
                        };

                        dataGridView.Rows.Add(rowobj);
                        dataGridView.Rows[dataGridView.Rows.Count - 1].Tag = sys;
                    }
                }

                dataGridView.Sort(sortcol, (sortorder == SortOrder.Descending) ? ListSortDirection.Descending : ListSortDirection.Ascending);
                dataGridView.Columns[sortcol.Index].HeaderCell.SortGlyphDirection = sortorder;
                this.Cursor = Cursors.Default;
            }
        }
Пример #13
0
        public double CumulativeDistance()
        {
            ISystem last     = null;
            double  distance = 0;

            for (int i = 0; i < Systems.Count; i++)
            {
                ISystem s = SystemClassDB.GetSystem(Systems[i]);
                if (s != null)
                {
                    if (last != null)
                    {
                        distance += s.Distance(last);
                    }

                    last = s;
                }
            }

            return(distance);
        }
Пример #14
0
        void Search(MaterialCommodityData cm, Dictionary <string, Tuple <HistoryEntry, string, double> > foundlist,
                    string prefix = "")
        {
            ISystem cursystem = discoveryform.history.CurrentSystem; // could be null

            foreach (var he in discoveryform.history)                // oldest first..
            {
                Tuple <HistoryEntry, string> found = null;
                bool checkstation = false;

                if (he.EntryType == JournalTypeEnum.Scan)
                {
                    var je = he.journalEntry as JournalScan;
                    if (je.HasMaterial(cm.FDName))
                    {
                        found = new Tuple <HistoryEntry, string>(he, prefix + je.BodyName);
                    }
                }
                else if (he.EntryType == JournalTypeEnum.Market)
                {
                    var je = he.journalEntry as JournalMarket;
                    if (je.HasCommodityToBuy(cm.FDName))
                    {
                        found        = new Tuple <HistoryEntry, string>(he, prefix + je.Station);
                        checkstation = true;
                    }
                }
                else if (he.EntryType == JournalTypeEnum.EDDCommodityPrices)
                {
                    var je = he.journalEntry as JournalEDDCommodityPrices;
                    if (je.HasCommodityToBuy(cm.FDName))
                    {
                        found        = new Tuple <HistoryEntry, string>(he, prefix + je.Station);
                        checkstation = true;
                    }
                }
                else if (he.EntryType == JournalTypeEnum.MaterialDiscovered)
                {
                    var je = he.journalEntry as JournalMaterialDiscovered;
                    if (je.Name.Equals(cm.FDName))
                    {
                        found = new Tuple <HistoryEntry, string>(he, prefix + "Discovered at ".Tx(this, "DIS") + he.WhereAmI);
                    }
                }
                else if (he.EntryType == JournalTypeEnum.MaterialCollected)
                {
                    var je = he.journalEntry as JournalMaterialCollected;
                    if (je.Name.Equals(cm.FDName))
                    {
                        found = new Tuple <HistoryEntry, string>(he, prefix + "Collected at ".Tx(this, "DIS") + he.WhereAmI);
                    }
                }

                if (found != null)
                {
                    string keyname = he.System.Name + (checkstation ? ":" + he.WhereAmI : "");
                    double dist    = cursystem.Distance(he.System);

                    if (foundlist.ContainsKey(keyname))
                    {
                        if (!foundlist[keyname].Item2.Contains(found.Item2))     // don't double repeat
                        {
                            foundlist[keyname] = new Tuple <HistoryEntry, string, double>(he, foundlist[keyname].Item2.AppendPrePad(found.Item2, Environment.NewLine), dist);
                        }
                    }
                    else
                    {
                        foundlist[keyname] = new Tuple <HistoryEntry, string, double>(he, found.Item2, dist);
                    }
                }
            }
        }
Пример #15
0
        // double percent = 0; Timer t = new Timer();// play thru harness

        private void Display(ISystem cursys)
        {
            if (currentRoute == null)
            {
                DisplayText("Please set a route, by right clicking", "");
                return;
            }

            if (currentRoute.Systems.Count == 0)
            {
                DisplayText(currentRoute.Name, "Route contains no waypoints");
                return;
            }

            string topline = "";

            ISystem finalSystem = SystemClassDB.GetSystem(currentRoute.Systems[currentRoute.Systems.Count - 1]);

            if (finalSystem != null && cursys.HasCoordinate)
            {
                string mesg  = "remain";
                double distX = cursys.Distance(finalSystem);
                //Small hack to pull the jump range from TripPanel1
                var jumpRange = SQLiteDBClass.GetSettingDouble("TripPanel1" + "JumpRange", -1.0);       //TBD Not a good idea.
                if (jumpRange > 0)
                {
                    int jumps = (int)Math.Ceiling(distX / jumpRange);
                    if (jumps > 0)
                    {
                        mesg = "@ " + jumps.ToString() + ((jumps == 1) ? " jump" : " jumps");
                    }
                }
                topline = String.Format("{0} {1} WPs, {2:N2}ly {3}", currentRoute.Name, currentRoute.Systems.Count, distX, mesg);
            }
            else
            {
                topline = String.Format("{0} {1} WPs remain", currentRoute.Name, currentRoute.Systems.Count);
            }

            string bottomline = "";

            Tuple <ISystem, int> closest = cursys.HasCoordinate ? currentRoute.ClosestTo(cursys) : null;

            if (closest != null)
            {
                if (closest.Item2 >= currentRoute.Systems.Count) // if past end..
                {
                    bottomline = String.Format("Past Last WP{0} {1}", closest.Item2, currentRoute.LastSystem);
                }
                else
                {
                    string name = null;

                    if (closest.Item1 != null)          // if have a closest system
                    {
                        double distance = cursys.Distance(closest.Item1);

                        bottomline = String.Format("{0:N2}ly to WP{1} {2} @ {3},{4},{5}", distance, closest.Item2 + 1, closest.Item1.Name,
                                                   closest.Item1.X.ToString("0.#"), closest.Item1.Y.ToString("0.#"), closest.Item1.Z.ToString("0.#"));

                        name = closest.Item1.Name;
                    }
                    else
                    {           // just know waypoint..
                        bottomline = String.Format("To WP{0} {1}", closest.Item2 + 1, currentRoute.Systems[closest.Item2]);

                        name = currentRoute.Systems[closest.Item2];
                    }

                    if (lastsystem == null || name.CompareTo(lastsystem) != 0)
                    {
                        if (autoCopyWPToolStripMenuItem.Checked)
                        {
                            Clipboard.SetText(name);
                        }

                        if (autoSetTargetToolStripMenuItem.Checked)
                        {
                            string targetName;
                            double x, y, z;
                            TargetClass.GetTargetPosition(out targetName, out x, out y, out z);
                            if (name.CompareTo(targetName) != 0)
                            {
                                TargetHelpers.setTargetSystem(this, discoveryform, name, false);
                            }
                        }

                        lastsystem = name;
                    }
                }
            }
            else
            {
                bottomline = "No current position/no systems found in database";
            }

            DisplayText(topline, bottomline);
        }
Пример #16
0
        private void UpdateSystemRow(int rowindex)
        {
            const int idxVisits = 5;
            const int idxScans  = 6;
            const int idxBodies = 7;
            const int idxstars  = 8;
            const int idxInfo   = 9;
            const int idxNote   = 10;

            ISystem currentSystem = discoveryform.history.CurrentSystem; // may be null

            if (rowindex < dataGridViewExplore.Rows.Count && dataGridViewExplore[0, rowindex].Value != null)
            {
                string  sysname = dataGridViewExplore[0, rowindex].Value.ToString();
                ISystem sys     = (ISystem)dataGridViewExplore[0, rowindex].Tag;

                if (sys == null)
                {
                    sys = discoveryform.history.FindSystem(sysname);
                }

                if (sys != null && currentSystem != null)
                {
                    double dist    = sys.Distance(currentSystem);
                    string strdist = dist >= 0 ? ((double)dist).ToString("0.00") : "";
                    dataGridViewExplore[1, rowindex].Value = strdist;
                }

                dataGridViewExplore[0, rowindex].Tag = sys;
                dataGridViewExplore.Rows[rowindex].DefaultCellStyle.ForeColor = (sys != null && sys.HasCoordinate) ? discoveryform.theme.VisitedSystemColor : discoveryform.theme.NonVisitedSystemColor;

                if (sys != null)
                {
                    if (sys.HasCoordinate)
                    {
                        dataGridViewExplore[2, rowindex].Value = sys.X.ToString("0.00");
                        dataGridViewExplore[3, rowindex].Value = sys.Y.ToString("0.00");
                        dataGridViewExplore[4, rowindex].Value = sys.Z.ToString("0.00");
                    }

                    dataGridViewExplore[idxVisits, rowindex].Value = discoveryform.history.GetVisitsCount(sysname).ToString();

                    StarScan.SystemNode sysnode = discoveryform.history.starscan.FindSystemSynchronous(sys, false);

                    if (sysnode != null)
                    {
                        dataGridViewExplore[idxScans, rowindex].Value = sysnode.StarPlanetsScanned().ToString();
                        if (sysnode.FSSTotalBodies.HasValue)
                        {
                            dataGridViewExplore[idxBodies, rowindex].Value = sysnode.FSSTotalBodies.Value.ToString();
                        }

                        dataGridViewExplore[idxstars, rowindex].Value = sysnode.StarTypesFound(false);

                        string info = "";
                        foreach (var scan in sysnode.Bodies)
                        {
                            JournalScan sd = scan.ScanData;
                            if (sd != null)
                            {
                                if (sd.IsStar)
                                {
                                    if (sd.StarTypeID == EDStar.AeBe)
                                    {
                                        info = info + " " + "AeBe";
                                    }
                                    if (sd.StarTypeID == EDStar.N)
                                    {
                                        info = info + " " + "NS";
                                    }
                                    if (sd.StarTypeID == EDStar.H)
                                    {
                                        info = info + " " + "BH";
                                    }
                                }
                                else
                                {
                                    if (sd.PlanetTypeID == EDPlanet.Earthlike_body)
                                    {
                                        info = info + " " + (sd.Terraformable ? "T-ELW" : "ELW");
                                    }
                                    else if (sd.PlanetTypeID == EDPlanet.Water_world)
                                    {
                                        info = info + " " + (sd.Terraformable ? "T-WW" : "WW");
                                    }
                                    else if (sd.PlanetTypeID == EDPlanet.High_metal_content_body && sd.Terraformable)
                                    {
                                        info = info + " " + "T-HMC";
                                    }
                                }
                            }
                        }

                        dataGridViewExplore[idxInfo, rowindex].Value = info.Trim();
                    }

                    string          note = "";
                    SystemNoteClass sn   = SystemNoteClass.GetNoteOnSystem(sys.Name, sys.EDSMID);
                    if (sn != null && !string.IsNullOrWhiteSpace(sn.Note))
                    {
                        note = sn.Note;
                    }
                    else
                    {
                        BookmarkClass bkmark = GlobalBookMarkList.Instance.FindBookmarkOnSystem(sys.Name);
                        if (bkmark != null && !string.IsNullOrWhiteSpace(bkmark.Note))
                        {
                            note = bkmark.Note;
                        }
                        else
                        {
                            var gmo = discoveryform.galacticMapping.Find(sys.Name);
                            if (gmo != null && !string.IsNullOrWhiteSpace(gmo.description))
                            {
                                note = gmo.description;
                            }
                        }
                    }
                    dataGridViewExplore[idxNote, rowindex].Value = note.WordWrap(60);
                }

                if (sys == null && sysname != "")
                {
                    dataGridViewExplore.Rows[rowindex].ErrorText = "System not known".T(EDTx.Systemnotknown);
                }
                else
                {
                    dataGridViewExplore.Rows[rowindex].ErrorText = "";
                }
            }
        }
Пример #17
0
        private void UpdateTo(object sender, string optupdateto = null)
        {
            changesilence = true;

            if (optupdateto != null)
            {
                textBox_To.Text = optupdateto;
            }

            if (sender == textBox_To)
            {
                ISystem ds1 = SystemCache.FindSystem(SystemNameOnly(textBox_To.Text), discoveryform.galacticMapping, true);
                if (ds1 != null)
                {
                    textBox_ToName.Text = ds1.Name;
                    textBox_ToX.Text    = ds1.X.ToString("0.00");
                    textBox_ToY.Text    = ds1.Y.ToString("0.00");
                    textBox_ToZ.Text    = ds1.Z.ToString("0.00");
                }
                else
                {
                    textBox_ToX.Text = textBox_ToY.Text = textBox_ToZ.Text = "";
                }
            }
            else
            {
                string res = "", resname = "";

                if (GetCoordsTo(out Point3D curpos))
                {
                    ISystem           nearest    = SystemCache.FindNearestSystemTo(curpos.X, curpos.Y, curpos.Z, 100);
                    GalacticMapObject nearestgmo = discoveryform.galacticMapping.FindNearest(curpos.X, curpos.Y, curpos.Z);

                    if (nearest != null)
                    {
                        if (nearestgmo != null && nearest.Distance(curpos.X, curpos.Y, curpos.Z) > nearestgmo.GetSystem().Distance(curpos.X, curpos.Y, curpos.Z))
                        {
                            nearest = nearestgmo.GetSystem();
                        }
                    }
                    else
                    {
                        nearest = nearestgmo?.GetSystem();
                    }

                    if (nearest != null)
                    {
                        res = resname = nearest.Name;

                        double distance = Point3D.DistanceBetween(curpos, new Point3D(nearest.X, nearest.Y, nearest.Z));
                        if (distance > 0.1)
                        {
                            resname = nearest.Name + " @ " + distance.ToString("0.00") + "ly";
                        }
                    }
                }

                textBox_To.Text     = res;
                textBox_ToName.Text = resname;
            }

            UpdateDistance();
            button_Route.Enabled = IsValid();
            changesilence        = false;
        }
Пример #18
0
        private void FillInSystemFromDBInt(HistoryEntry syspos, ISystem edsmsys, SQLiteConnectionUser uconn, DbTransaction utn)        // call to fill in ESDM data for entry, and also fills in all others pointing to the system object
        {
            List <HistoryEntry> alsomatching = new List <HistoryEntry>();

            foreach (HistoryEntry he in historylist)       // list of systems in historylist using the same system object
            {
                if (Object.ReferenceEquals(he.System, syspos.System))
                {
                    alsomatching.Add(he);
                }
            }

            if (edsmsys != null)
            {
                ISystem oldsys = syspos.System;

                bool updateedsmid = oldsys.EDSMID <= 0 && edsmsys.EDSMID > 0;
                bool updatesyspos = !oldsys.HasCoordinate && edsmsys.HasCoordinate;
                bool updatename   = oldsys.HasCoordinate && edsmsys.HasCoordinate &&
                                    oldsys.Distance(edsmsys) < 0.1 &&
                                    !String.Equals(edsmsys.Name, oldsys.Name, StringComparison.InvariantCultureIgnoreCase) &&
                                    edsmsys.UpdateDate > syspos.EventTimeUTC;

                ISystem newsys = new SystemClass
                {
                    Name            = updatename ? edsmsys.Name : oldsys.Name,
                    X               = updatesyspos ? edsmsys.X : oldsys.X,
                    Y               = updatesyspos ? edsmsys.Y : oldsys.Y,
                    Z               = updatesyspos ? edsmsys.Z : oldsys.Z,
                    EDSMID          = updateedsmid ? edsmsys.EDSMID : oldsys.EDSMID,
                    SystemAddress   = oldsys.SystemAddress ?? edsmsys.SystemAddress,
                    Allegiance      = oldsys.Allegiance == EDAllegiance.Unknown ? edsmsys.Allegiance : oldsys.Allegiance,
                    Government      = oldsys.Government == EDGovernment.Unknown ? edsmsys.Government : oldsys.Government,
                    Population      = oldsys.Government == EDGovernment.Unknown ? edsmsys.Population : oldsys.Population,
                    PrimaryEconomy  = oldsys.PrimaryEconomy == EDEconomy.Unknown ? edsmsys.PrimaryEconomy : oldsys.PrimaryEconomy,
                    Security        = oldsys.Security == EDSecurity.Unknown ? edsmsys.Security : oldsys.Security,
                    State           = oldsys.State == EDState.Unknown ? edsmsys.State : oldsys.State,
                    Faction         = oldsys.Faction ?? edsmsys.Faction,
                    CommanderCreate = edsmsys.CommanderCreate,
                    CommanderUpdate = edsmsys.CommanderUpdate,
                    CreateDate      = edsmsys.CreateDate,
                    EDDBID          = edsmsys.EDDBID,
                    EDDBUpdatedAt   = edsmsys.EDDBUpdatedAt,
                    GridID          = edsmsys.GridID,
                    NeedsPermit     = edsmsys.NeedsPermit,
                    RandomID        = edsmsys.RandomID,
                    UpdateDate      = edsmsys.UpdateDate,
                    SystemNote      = edsmsys.SystemNote,
                    status          = SystemStatusEnum.EDSM
                };

                foreach (HistoryEntry he in alsomatching)       // list of systems in historylist using the same system object
                {
                    bool updatepos = (he.EntryType == JournalTypeEnum.FSDJump || he.EntryType == JournalTypeEnum.Location) && updatesyspos;

                    if (updatepos || updateedsmid)
                    {
                        JournalEntry.UpdateEDSMIDPosJump(he.Journalid, edsmsys, updatepos, -1, uconn, utn);   // update pos and edsmid, jdist not updated
                    }
                    he.System = newsys;
                }
            }
            else
            {
                foreach (HistoryEntry he in alsomatching)      // list of systems in historylist using the same system object
                {
                    he.System.EDSMID = -1;                     // can't do it
                }
            }
        }
Пример #19
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.
                        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);
                        }
                    }
                }

                isys = newsys;
            }

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

            if (prev != null)
            {
                if (prev.StopMarker)                  // if we had a stop marker previously, means the next one needs to clear the counters
                {
                    he.travelling            = false; // still travelling if its a start marker
                    he.travelled_distance    = 0;
                    he.travelled_seconds     = new TimeSpan(0);
                    he.travelled_missingjump = 0;
                    he.travelled_jumps       = 0;
                }
                else
                {
                    he.travelling            = prev.travelling;
                    he.travelled_distance    = prev.travelled_distance;
                    he.travelled_seconds     = prev.travelled_seconds;
                    he.travelled_missingjump = prev.travelled_missingjump;
                    he.travelled_jumps       = prev.travelled_jumps;
                }
            }

            if (he.StartMarker)           // start marker, start travelling
            {
                he.travelling = true;
            }

            if (he.travelling)
            {
                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++;
                    }
                }

                if (prev != null)
                {
                    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;
                    }
                }
            }

            return(he);
        }
Пример #20
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);
        }
Пример #21
0
        private void UpdateSystemRows()
        {
            for (int rowindex = 0; rowindex < dataGridView.Rows.Count; rowindex++)
            {
                dataGridView[1, rowindex].ReadOnly = true;
                dataGridView[2, rowindex].ReadOnly = true;
                dataGridView[3, rowindex].ReadOnly = true;
                dataGridView[4, rowindex].ReadOnly = true;
                dataGridView[5, rowindex].ReadOnly = true;

                string sysname = dataGridView[0, rowindex].Value.ToString();

                if (sysname.HasChars())
                {
                    var sys = discoveryform.history.FindSystem(sysname);

                    dataGridView[1, rowindex].Value = "";

                    if (rowindex > 0 && dataGridView[0, rowindex - 1].Value != null && dataGridView[0, rowindex].Value != null)
                    {
                        string prevsysname = dataGridView[0, rowindex - 1].Value.ToString();
                        var    prevsys     = discoveryform.history.FindSystem(prevsysname);

                        if ((sys?.HasCoordinate ?? false) && (prevsys?.HasCoordinate ?? false))
                        {
                            double dist    = sys.Distance(prevsys);
                            string strdist = dist >= 0 ? ((double)dist).ToString("0.00") : "";
                            dataGridView[1, rowindex].Value = strdist;
                        }
                    }

                    dataGridView[0, rowindex].Tag = sys;
                    dataGridView.Rows[rowindex].Cells[0].Style.ForeColor = (sys != null && sys.HasCoordinate) ? Color.Empty : discoveryform.theme.UnknownSystemColor;

                    string          note = "";
                    SystemNoteClass sn   = SystemNoteClass.GetNoteOnSystem(sysname);
                    if (sn != null && !string.IsNullOrWhiteSpace(sn.Note))
                    {
                        note = sn.Note;
                    }

                    BookmarkClass bkmark = GlobalBookMarkList.Instance.FindBookmarkOnSystem(sysname);
                    if (bkmark != null && !string.IsNullOrWhiteSpace(bkmark.Note))
                    {
                        note = note.AppendPrePad(bkmark.Note, "; ");
                    }

                    var gmo = discoveryform.galacticMapping.Find(sysname);
                    if (gmo != null && !string.IsNullOrWhiteSpace(gmo.description))
                    {
                        note = note.AppendPrePad(gmo.description, "; ");
                    }

                    dataGridView[2, rowindex].Value = note;

                    if (sys != null && sys.HasCoordinate)
                    {
                        dataGridView[3, rowindex].Value       = sys.X.ToString("0.0.#");
                        dataGridView[4, rowindex].Value       = sys.Y.ToString("0.0.#");
                        dataGridView[5, rowindex].Value       = sys.Z.ToString("0.0.#");
                        dataGridView.Rows[rowindex].ErrorText = "";
                    }
                    else
                    {
                        dataGridView.Rows[rowindex].ErrorText = "System not known location".T(EDTx.UserControlExpedition_EDSMUnk);
                    }
                }
            }

            txtCmlDistance.Text = txtP2PDIstance.Text = "";

            if (dataGridView.Rows.Count > 1)
            {
                double  distance = 0;
                ISystem firstSC  = null;
                ISystem lastSC   = null;
                for (int i = 0; i < dataGridView.Rows.Count; i++)
                {
                    if (firstSC == null && dataGridView[0, i].Tag != null)
                    {
                        firstSC = (ISystem)dataGridView[0, i].Tag;
                    }
                    if (dataGridView[0, i].Tag != null)
                    {
                        lastSC = (ISystem)dataGridView[0, i].Tag;
                    }
                    String value = dataGridView[1, i].Value as string;
                    if (!String.IsNullOrWhiteSpace(value))
                    {
                        distance += Double.Parse(value);
                    }
                }

                txtCmlDistance.Text = distance.ToString("0.00") + "LY";

                if (firstSC != null && lastSC != null)
                {
                    distance            = firstSC.Distance(lastSC);
                    txtP2PDIstance.Text = distance.ToString("0.00") + "LY";
                }
            }
        }
Пример #22
0
        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);
        }
Пример #23
0
        private async void Display(HistoryList hl)
        {
            pictureBox.ClearImageList();

            current_historylist = hl;

            if (hl != null && hl.Count > 0)                                                                   // just for safety
            {
                List <HistoryEntry> result = current_historylist.LatestFirst();                               // Standard filtering

                int ftotal;                                                                                   // event filter
                result = HistoryList.FilterByJournalEvent(result, GetSetting(dbFilter, "All"), out ftotal);
                result = FilterHelpers.FilterHistory(result, fieldfilter, discoveryform.Globals, out ftotal); // and the field filter..

                RevertToNormalSize();                                                                         // ensure size is back to normal..
                scanpostextoffset = new Point(0, 0);                                                          // left/ top used by scan display

                Color textcolour = IsTransparent ? discoveryform.theme.SPanelColor : discoveryform.theme.LabelColor;
                Color backcolour = IsTransparent ? (Config(Configuration.showBlackBoxAroundText) ? Color.Black : Color.Transparent) : this.BackColor;

                bool drawnnootherstuff = DrawScanText(true, textcolour, backcolour); // go 1 for some of the scan positions

                if (!drawnnootherstuff)                                              // and it may indicate its overwriting all stuff, which is fine
                {
                    int rowpos    = scanpostextoffset.Y;
                    int rowmargin = displayfont.ScalePixels(4);

                    // Check if need to hide the UI
                    var ts = hl.CurrentTravelState();

                    if (Config(Configuration.showNothingWhenDocked) && (ts == HistoryEntryStatus.TravelStateType.Docked))
                    {
                        if (!Config(Configuration.showNoTitleWhenHidden))
                        {
                            AddColText(0, 0, rowpos, "<>", textcolour, backcolour, null);                                   // just show a marker
                        }
                    }
                    else if (uistate != EliteDangerousCore.UIEvents.UIGUIFocus.Focus.NoFocus && Config(Configuration.showNothingWhenPanel))
                    {
                        if (!Config(Configuration.showNoTitleWhenHidden))
                        {
                            AddColText(0, 0, rowpos, uistate.ToString().SplitCapsWord(),
                                       textcolour, backcolour, null);
                        }
                    }
                    else
                    {
                        string  name;
                        Point3D tpos;
                        bool    targetpresent = TargetClass.GetTargetPosition(out name, out tpos);

                        ISystem currentsystem = hl.CurrentSystem(); // may be null

                        HistoryEntry last = hl.GetLast;

                        // last = hl.FindByName("Myeia Thaa QY-H c23-0");

                        if (Config(Configuration.showSystemInformation) && last != null)
                        {
                            string allegiance, economy, gov, faction, factionstate, security;
                            hl.ReturnSystemInfo(last, out allegiance, out economy, out gov, out faction, out factionstate, out security);

                            string str = last.System.Name + " : " + BaseUtils.FieldBuilder.Build(
                                "", faction,
                                "", factionstate,
                                "", security,
                                "", allegiance,
                                "", economy,
                                "", gov
                                );


                            HistoryEntry lastfsd        = hl.GetLastHistoryEntry(x => x.journalEntry is EliteDangerousCore.JournalEvents.JournalFSDJump, last);
                            bool         firstdiscovery = (lastfsd != null && (lastfsd.journalEntry as EliteDangerousCore.JournalEvents.JournalFSDJump).EDSMFirstDiscover);

                            rowpos = rowmargin + AddColText(0, 0, rowpos, str, textcolour, backcolour, null, firstdiscovery ? EDDiscovery.Icons.Controls.firstdiscover : null, "Shows if EDSM indicates your it's first discoverer").Location.Bottom;
                        }

                        if (Config(Configuration.showHabInformation) && last != null)
                        {
                            StarScan scan = hl.StarScan;

                            StarScan.SystemNode sn = await scan.FindSystemAsync(last.System, true);    // EDSM look up here..

                            StringBuilder res = new StringBuilder();

                            if (sn != null && sn.StarNodes.Count > 0 && sn.StarNodes.Values[0].ScanData != null)
                            {
                                JournalScan js = sn.StarNodes.Values[0].ScanData;

                                if (showCircumstellarZonesToolStripMenuItem.Checked)
                                {
                                    string hz = js.CircumstellarZonesString(false, JournalScan.CZPrint.CZHab);
                                    res.AppendFormat(hz + Environment.NewLine);
                                }

                                if (showMetalRichPlanetsToolStripMenuItem.Checked)
                                {
                                    string hz = js.CircumstellarZonesString(false, JournalScan.CZPrint.CZMR);
                                    res.AppendFormat(hz + Environment.NewLine);
                                }

                                if (showWaterWorldsToolStripMenuItem.Checked)
                                {
                                    string hz = js.CircumstellarZonesString(false, JournalScan.CZPrint.CZWW);
                                    res.AppendFormat(hz + Environment.NewLine);
                                }

                                if (showEarthLikeToolStripMenuItem.Checked)
                                {
                                    string hz = js.CircumstellarZonesString(false, JournalScan.CZPrint.CZEL);
                                    res.AppendFormat(hz + Environment.NewLine);
                                }

                                if (showAmmoniaWorldsToolStripMenuItem.Checked)
                                {
                                    string hz = js.CircumstellarZonesString(false, JournalScan.CZPrint.CZAW);
                                    res.AppendFormat(hz + Environment.NewLine);
                                }

                                if (showIcyPlanetsToolStripMenuItem.Checked)
                                {
                                    string hz = js.CircumstellarZonesString(false, JournalScan.CZPrint.CZIP);
                                    res.AppendFormat(hz + Environment.NewLine);
                                }
                            }

                            if (res.ToString().HasChars())
                            {
                                rowpos = rowmargin + AddColText(0, 0, rowpos, res.ToString(), textcolour, backcolour, null).Location.Bottom;
                            }
                        }

                        if (targetpresent && Config(Configuration.showTargetLine) && currentsystem != null)
                        {
                            string dist = (currentsystem.HasCoordinate) ? currentsystem.Distance(tpos.X, tpos.Y, tpos.Z).ToString("0.00") : "Unknown".T(EDTx.Unknown);
                            rowpos = rowmargin + AddColText(0, 0, rowpos, "Target".T(EDTx.UserControlSpanel_Target) + ": " + name + " @ " + dist + " ly", textcolour, backcolour, null).Location.Bottom;
                        }

                        foreach (HistoryEntry rhe in result)
                        {
                            rowpos = rowmargin + DrawHistoryEntry(rhe, rowpos, tpos, textcolour, backcolour);

                            if (rowpos > ClientRectangle.Height)                // stop when off of screen
                            {
                                break;
                            }
                        }
                    }
                }

                DrawScanText(false, textcolour, backcolour);     // go 2
            }

            pictureBox.Render();
        }
Пример #24
0
        private void UpdateSystemRow(int rowindex)
        {
            const int idxVisits  = 5;
            const int idxScans   = 6;
            const int idxPriStar = 7;
            const int idxInfo    = 8;
            const int idxNote    = 9;

            ISystem currentSystem = discoveryform.history.CurrentSystem; // may be null

            if (rowindex < dataGridViewExplore.Rows.Count && dataGridViewExplore[0, rowindex].Value != null)
            {
                string  sysname = dataGridViewExplore[0, rowindex].Value.ToString();
                ISystem sys     = (ISystem)dataGridViewExplore[0, rowindex].Tag;

                if (sys == null)
                {
                    sys = SystemCache.FindSystem(sysname);
                }

                if (sys != null && currentSystem != null)
                {
                    double dist    = sys.Distance(currentSystem);
                    string strdist = dist >= 0 ? ((double)dist).ToString("0.00") : "";
                    dataGridViewExplore[1, rowindex].Value = strdist;
                }

                dataGridViewExplore[0, rowindex].Tag = sys;
                dataGridViewExplore.Rows[rowindex].DefaultCellStyle.ForeColor = (sys != null && sys.HasCoordinate) ? discoveryform.theme.VisitedSystemColor : discoveryform.theme.NonVisitedSystemColor;

                if (sys != null)
                {
                    if (sys.HasCoordinate)
                    {
                        dataGridViewExplore[2, rowindex].Value = sys.X.ToString("0.00");
                        dataGridViewExplore[3, rowindex].Value = sys.Y.ToString("0.00");
                        dataGridViewExplore[4, rowindex].Value = sys.Z.ToString("0.00");
                    }

                    dataGridViewExplore[idxVisits, rowindex].Value = discoveryform.history.GetVisitsCount(sysname).ToString();

                    List <JournalScan> scans = discoveryform.history.GetScans(sysname);
                    dataGridViewExplore[idxScans, rowindex].Value = scans.Count.ToString();

                    string pristar = "";
                    // Search for primary star
                    foreach (var scan in scans)
                    {
                        if (scan.IsStar && scan.DistanceFromArrivalLS == 0.0)
                        {
                            pristar = scan.StarType;
                            break;
                        }
                    }
                    dataGridViewExplore[idxPriStar, rowindex].Value = pristar;


                    string info = "";

                    foreach (var scan in scans)
                    {
                        if (scan.IsStar)
                        {
                            if (scan.StarTypeID == EDStar.AeBe)
                            {
                                info = info + " " + "AeBe";
                            }
                            if (scan.StarTypeID == EDStar.N)
                            {
                                info = info + " " + "NS";
                            }
                            if (scan.StarTypeID == EDStar.H)
                            {
                                info = info + " " + "BH";
                            }
                        }
                        else
                        {
                            if (scan.PlanetTypeID == EDPlanet.Earthlike_body)
                            {
                                info = info + " " + "ELW";
                            }
                            if (scan.PlanetTypeID == EDPlanet.Water_world)
                            {
                                info = info + " " + "WW";
                            }
                        }
                    }

                    dataGridViewExplore[idxInfo, rowindex].Value = info.Trim();


                    string          note = "";
                    SystemNoteClass sn   = SystemNoteClass.GetNoteOnSystem(sys.Name, sys.EDSMID);
                    if (sn != null && !string.IsNullOrWhiteSpace(sn.Note))
                    {
                        note = sn.Note;
                    }
                    else
                    {
                        BookmarkClass bkmark = GlobalBookMarkList.Instance.FindBookmarkOnSystem(sys.Name);
                        if (bkmark != null && !string.IsNullOrWhiteSpace(bkmark.Note))
                        {
                            note = bkmark.Note;
                        }
                        else
                        {
                            var gmo = discoveryform.galacticMapping.Find(sys.Name);
                            if (gmo != null && !string.IsNullOrWhiteSpace(gmo.description))
                            {
                                note = gmo.description;
                            }
                        }
                    }
                    dataGridViewExplore[idxNote, rowindex].Value = note.WordWrap(60);
                }

                if (sys == null && sysname != "")
                {
                    dataGridViewExplore.Rows[rowindex].ErrorText = "System not known".Tx();
                }
                else
                {
                    dataGridViewExplore.Rows[rowindex].ErrorText = "";
                }
            }
        }
Пример #25
0
        // given the system list, which is the next waypoint to go to.  return the system (or null if not available or past end) and the waypoint.. (0 based)

        public Tuple <ISystem, int> ClosestTo(ISystem sys)
        {
            double  dist    = Double.MaxValue;
            ISystem found   = null;
            int     closest = -1;

            List <ISystem> list = new List <ISystem>();

            for (int i = 0; i < Systems.Count; i++)
            {
                ISystem s = SystemClassDB.GetSystem(Systems[i]);

                if (s != null)
                {
                    double sd = s.Distance(sys);
                    if (sd < dist)
                    {
                        dist    = sd;
                        closest = i;
                        found   = s;
                    }
                }
                list.Add(s);
            }


            if (found != null)
            {
                //System.Diagnostics.Debug.WriteLine("Found at " + closest + " System " + found.name + " " + found.x + " " + found.y + " " + found.z + " dist " + dist);

                if (closest > 0)
                {
                    int lastentry = closest - 1;
                    while (lastentry >= 0 && list[lastentry] == null)       // go and find the last one which had a position..
                    {
                        lastentry--;
                    }

                    if (lastentry >= 0 && list[lastentry] != null)                                                                 // found it, so work out using distance if we are closest to last or past it
                    {
                        double distlasttoclosest = list[closest].Distance(list[lastentry]);                                        // last->closest vs
                        double distlasttocur     = sys.Distance(list[lastentry]);                                                  // last->cur position

                        if (distlasttocur > distlasttoclosest - 0.1)                                                               // past current because the distance last->cur > last->closest waypoint
                        {
                            return(new Tuple <ISystem, int>(closest < Systems.Count - 1 ? list[closest + 1] : null, closest + 1)); // en-route to this. may be null
                        }
                        else
                        {
                            return(new Tuple <ISystem, int>(found, closest)); // en-route to this
                        }
                    }
                }

                return(new Tuple <ISystem, int>(found, closest));
            }
            else
            {
                return(null);
            }
        }
Пример #26
0
        public ClosestInfo ClosestTo(ISystem currentsystem)
        {
            double  dist    = Double.MaxValue;
            ISystem found   = null;
            int     closest = -1;

            List <ISystem> list = new List <ISystem>();

            for (int i = 0; i < Systems.Count; i++)
            {
                ISystem s = SystemCache.FindSystem(Systems[i]);

                if (s != null && s.HasCoordinate)
                {
                    double sd = s.Distance(currentsystem);
                    if (sd < dist)
                    {
                        dist    = sd;
                        closest = i;
                        found   = s;
                    }
                }
                list.Add(s);
            }


            if (found != null)
            {
                //System.Diagnostics.Debug.WriteLine(Environment.NewLine + "Found at " + closest + " System " + found.Name + " " + found.X + " " + found.Y + " " + found.Z + " dist " + dist + " cur " + currentsystem.X + "," + currentsystem.Y + "," + currentsystem.Z);

                if (closest > 0)    // if not starting point
                {
                    int lastentry = closest - 1;
                    while (lastentry >= 0 && list[lastentry] == null)       // go and find the last one which had a position..
                    {
                        lastentry--;
                    }

                    if (lastentry >= 0 && list[lastentry] != null)                          // found it, so work out using distance if we are closest to last or past it
                    {
                        double distlasttoclosest = list[closest].Distance(list[lastentry]); // last->closest vs
                        double distlasttocurrent = currentsystem.Distance(list[lastentry]); // last->cur position

                        //System.Diagnostics.Debug.WriteLine("Dist to last " + list[lastentry].Name + "=" + distlasttocurrent + " >? Dist last to closest" + distlasttoclosest);

                        if (distlasttocurrent > distlasttoclosest - 0.1) // past closest because the distance last->cur > last->closest waypoint
                        {
                            closest++;                                   // must move to next target
                            //System.Diagnostics.Debug.WriteLine("Moved to " + closest);
                        }

                        if (closest < Systems.Count)        // is this still a valid system..
                        {
                            ISystem nextsys      = list[closest];
                            double  distanceleft = CumulativeDistance(nextsys.Name);    // -1 if can't find..
                            //System.Diagnostics.Debug.WriteLine("Cum dist " + distanceleft + " to  current system " + currentsystem.Distance(nextsys));

                            return(new ClosestInfo(nextsys, closest, distanceleft, currentsystem.Distance(nextsys))); // en-route to this. may be null
                        }
                        else
                        {
                            return(new ClosestInfo(null, closest, -1, -1)); // pass last.. end of trip
                        }
                    }
                }

                return(new ClosestInfo(found, closest, CumulativeDistance(), currentsystem.Distance(found)));
            }
            else
            {
                return(null);
            }
        }
Пример #27
0
        // mcllist may be null, cursystem may be null as may crafts

        public void UpdateStatus(string status, ISystem cursystem, List <MaterialCommodityMicroResource> mcllist, List <HistoryEntry> crafts)
        {
            labelEngineerStatus.Text = status;
            string dist = "";

            if (cursystem != null && EngineerInfo != null)
            {
                var d = cursystem.Distance(EngineerInfo.X, EngineerInfo.Y, EngineerInfo.Z);
                dist = d.ToString("0.#") + " ly";
            }

            labelEngineerDistance.Text = dist;

            if (mcllist != null)                                           // may be null
            {
                var totals = MaterialCommoditiesRecipe.TotalList(mcllist); // start with totals present

                dataViewScrollerPanel.Suspend();
                dataGridViewEngineering.SuspendLayout();

                var wwmode = dataGridViewEngineering.DefaultCellStyle.WrapMode;
                dataGridViewEngineering.DefaultCellStyle.WrapMode = DataGridViewTriState.False;     // seems to make it a tad faster

                foreach (DataGridViewRow row in dataGridViewEngineering.Rows)
                {
                    row.Visible = true;     // if we hide stuff, we just make it invisible, we do not remove it

                    Recipes.EngineeringRecipe r = row.Tag as Recipes.EngineeringRecipe;

                    string tooltip    = "";
                    int    craftcount = 0;

                    foreach (var c in crafts.EmptyIfNull())     // all crafts
                    {
                        var cb = c.journalEntry as EliteDangerousCore.JournalEvents.JournalEngineerCraftBase;
                        if (cb != null)     // if an craft base type, check name and level
                        {
                            if (cb.Engineering.BlueprintName.Equals(r.fdname, StringComparison.InvariantCultureIgnoreCase) && cb.Engineering.Level == r.LevelInt)
                            {
                                tooltip = tooltip.AppendPrePad(c.EventTimeUTC.ToString() + " " + (c.ShipInformation?.Name ?? "?") + " " + (cb.Engineering.ExperimentalEffect_Localised ?? ""), Environment.NewLine);
                                craftcount++;
                            }
                        }
                        else if (c.EntryType == JournalTypeEnum.TechnologyBroker)       // if tech broker, check name
                        {
                            var tb = c.journalEntry as EliteDangerousCore.JournalEvents.JournalTechnologyBroker;
                            //string unl = string.Join(",", tb.ItemsUnlocked.Select(x=>x.Name));  System.Diagnostics.Debug.WriteLine($"{unl} {r.fdname}");
                            if (tb.ItemsUnlocked != null && Array.FindIndex(tb.ItemsUnlocked, x => x.Name.Equals(r.fdname, StringComparison.InvariantCultureIgnoreCase)) >= 0)
                            {
                                tooltip = tooltip.AppendPrePad(c.EventTimeUTC.ToString() + " " + (tb.BrokerType ?? "") + " " + string.Join(",", tb.ItemsUnlocked.Select(x => x.Name_Localised)));
                                craftcount++;
                            }
                        }
                    }

                    row.Cells[CraftedCol.Index].ToolTipText = tooltip;

                    var res = MaterialCommoditiesRecipe.HowManyLeft(mcllist, totals, r, WantedPerRecipe[row.Index], reducetotals: false);    // recipes not chained not in order

                    row.Cells[MaxCol.Index].Value         = res.Item1.ToString();
                    row.Cells[CraftedCol.Index].Value     = CraftedCol.HeaderText == "-" ? "" : craftcount.ToString();
                    row.Cells[PercentageCol.Index].Value  = res.Item5.ToString("N0");
                    row.Cells[NotesCol.Index].Value       = res.Item3;
                    row.Cells[NotesCol.Index].ToolTipText = res.Item4;
                    row.Cells[RecipeCol.Index].Value      = r.IngredientsStringvsCurrent(mcllist);
                    row.DefaultCellStyle.BackColor        = (res.Item5 >= 100.0) ? ExtendedControls.Theme.Current.GridHighlightBack : ExtendedControls.Theme.Current.GridCellBack;
                }

                dataGridViewEngineering.DefaultCellStyle.WrapMode = wwmode;
                dataGridViewEngineering.ResumeLayout();
                dataViewScrollerPanel.Resume();
            }

            labelCrafts.Text = crafts != null ? (crafts.Count + " crafts") : "";
        }
Пример #28
0
        private void Display(HistoryList hl)
        {
            pictureBox.ClearImageList();

            current_historylist = hl;

            if (hl != null && hl.Count > 0)                                                                   // just for safety
            {
                List <HistoryEntry> result = current_historylist.LastFirst;                                   // Standard filtering

                int ftotal;                                                                                   // event filter
                result = HistoryList.FilterByJournalEvent(result, SQLiteDBClass.GetSettingString(DbFilterSave, "All"), out ftotal);
                result = FilterHelpers.FilterHistory(result, fieldfilter, discoveryform.Globals, out ftotal); // and the field filter..

                RevertToNormalSize();                                                                         // ensure size is back to normal..
                scanpostextoffset = new Point(0, 0);                                                          // left/ top used by scan display

                Color textcolour = IsTransparent ? discoveryform.theme.SPanelColor : discoveryform.theme.LabelColor;
                Color backcolour = IsTransparent ? (Config(Configuration.showBlackBoxAroundText) ? Color.Black : Color.Transparent) : this.BackColor;

                bool drawnnootherstuff = DrawScanText(true, textcolour, backcolour); // go 1 for some of the scan positions

                if (!drawnnootherstuff)                                              // and it may indicate its overwriting all stuff, which is fine
                {
                    int rowpos    = scanpostextoffset.Y;
                    int rowheight = Config(Configuration.showIcon) ? 26 : 20;

                    if (Config(Configuration.showNothingWhenDocked) && (hl.IsCurrentlyDocked || hl.IsCurrentlyLanded))
                    {
                        AddColText(0, 0, rowpos, rowheight, (hl.IsCurrentlyDocked) ? "Docked" : "Landed", textcolour, backcolour, null);
                    }
                    else if ((uistate == UIState.GalMap && Config(Configuration.showNothingWhenGalmap)) || (uistate == UIState.SystemMap && Config(Configuration.showNothingWhenSysmap)))
                    {
                        AddColText(0, 0, rowpos, rowheight, (uistate == UIState.GalMap) ? "Galaxy Map" : "System Map", textcolour, backcolour, null);
                    }
                    else
                    {
                        string  name;
                        Point3D tpos;
                        bool    targetpresent = TargetClass.GetTargetPosition(out name, out tpos);

                        ISystem currentsystem = hl.CurrentSystem; // may be null

                        HistoryEntry last = hl.GetLast;

                        if (Config(Configuration.showSystemInformation) && last != null)
                        {
                            string allegiance, economy, gov, faction, factionstate, security;
                            hl.ReturnSystemInfo(last, out allegiance, out economy, out gov, out faction, out factionstate, out security);

                            string str = last.System.Name + " : " + BaseUtils.FieldBuilder.Build(
                                "", faction,
                                "", factionstate,
                                "", security,
                                "", allegiance,
                                "", economy,
                                "", gov
                                );


                            HistoryEntry lastfsd        = hl.GetLastHistoryEntry(x => x.journalEntry is EliteDangerousCore.JournalEvents.JournalFSDJump, last);
                            bool         firstdiscovery = (lastfsd != null && (lastfsd.journalEntry as EliteDangerousCore.JournalEvents.JournalFSDJump).EDSMFirstDiscover);

                            AddColText(0, 0, rowpos, rowheight, str, textcolour, backcolour, null, firstdiscovery ? EDDiscovery.Icons.Controls.firstdiscover : null, "Shows if EDSM indicates your it's first discoverer");

                            rowpos += rowheight;
                        }

                        if (Config(Configuration.showHabInformation) && last != null)
                        {
                            StarScan scan = hl.starscan;

                            StarScan.SystemNode sn = scan.FindSystem(last.System, true);    // EDSM look up here..

                            string res = null;

                            if (sn != null && sn.starnodes.Count > 0 && sn.starnodes.Values[0].ScanData != null)
                            {
                                JournalScan js = sn.starnodes.Values[0].ScanData;
                                res = js.HabZoneString().Replace("\r\n", " ");
                            }

                            if (res != null)
                            {
                                AddColText(0, 0, rowpos, rowheight, res, textcolour, backcolour, null);
                                rowpos += rowheight;
                            }
                        }

                        if (targetpresent && Config(Configuration.showTargetLine) && currentsystem != null)
                        {
                            string dist = (currentsystem.HasCoordinate) ? currentsystem.Distance(tpos.X, tpos.Y, tpos.Z).ToString("0.00") : "Unknown";
                            AddColText(0, 0, rowpos, rowheight, "Target: " + name + " @ " + dist + " ly", textcolour, backcolour, null);
                            rowpos += rowheight;
                        }

                        foreach (HistoryEntry rhe in result)
                        {
                            DrawHistoryEntry(rhe, rowpos, rowheight, tpos, textcolour, backcolour);
                            rowpos += rowheight;

                            if (rowpos > ClientRectangle.Height)                // stop when off of screen
                            {
                                break;
                            }
                        }
                    }
                }

                DrawScanText(false, textcolour, backcolour);     // go 2
            }

            pictureBox.Render();
        }