Exemplo n.º 1
0
 public ReferenceSystem(StarSystem refsys, StarSystem EstimatedPosition)
 {
     _refSys = refsys;
     Azimuth = Math.Atan2(_refSys.Y - EstimatedPosition.Y, _refSys.X - EstimatedPosition.X);
     Distance = CalculationsService.CalculateDistance(_refSys, EstimatedPosition);
     Altitude = Math.Acos((_refSys.Z - EstimatedPosition.Z) / Distance);
 }
        public SuggestedReferences(double x, double y, double z)
        {
            EstimatedPosition = new StarSystem();

            EstimatedPosition.X = x;
            EstimatedPosition.Y = y;
            EstimatedPosition.Z = z;
            EstimatedPosition.Name = "Estimated position";

            Stopwatch sw = new Stopwatch();
            sw.Start();

            CreateSectors();
            AddSystemsToSectors();
            sw.Stop();
            System.Diagnostics.Trace.WriteLine("FindCandidates time " + sw.Elapsed.TotalSeconds.ToString("0.000s"));

            for (int i = 0; i < sections; i++)
            {
                for (int j = 0; j < sections/2; j++)
                {
                    System.Diagnostics.Trace.WriteLine(i.ToString() + ":" + j.ToString() + "  " + sectors[i, j].Name + "  " + sectors[i, j].CandidatesCount.ToString());
                }
            }
        }
        public static double CalculateDistance(StarSystem s1, StarSystem s2)
        {
            if (s1 == null || s2 == null)
                return -1;

            //return Math.Sqrt(Math.Pow(s1.X - s2.X, 2) + Math.Pow(s1.y - s2.y, 2) + Math.Pow(s1.z - s2.z, 2));
            return Math.Sqrt((s1.X - s2.X) * (s1.X - s2.X) + (s1.Y - s2.Y) * (s1.Y - s2.Y) + (s1.Z - s2.Z) * (s1.Z - s2.Z));
        }
 public static StarSystem InsertStarSystem(StarSystem system)
 {
     if (null == system) throw new ArgumentNullException("expedition");
     using (var db = new EelContext()) {
         db.StarSystems.Add(system);
         db.SaveChanges();
     }
     return system;
 }
        public void AddReferenceStar(StarSystem sys)
        {
            ReferenceSystem refSys = new ReferenceSystem(sys, EstimatedPosition);

            if (NrOfRefenreceSystems== 0 || refSys.Distance > 0.0) // Exlude own position
            {
                int aznr = (int)Math.Floor((refSys.Azimuth * 180 / Math.PI + 180) / (360.0 / sections));
                int altnr = (int)Math.Floor((refSys.Altitude * 180 / Math.PI) / (360.0 / sections));

                sectors[aznr % sections, altnr % (sections / 2)].AddReference(refSys);
            }
        }
 public static StarSystem UpdateStarSystem(StarSystem system)
 {
     if (null == system) throw new ArgumentNullException("expedition");
     using (var db = new EelContext()) {
         system.UpdatedAt = DateTime.Now;
         db.StarSystems.Attach(system);
         db.Entry(system).State = Microsoft.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
     return system;
 }
Exemplo n.º 7
0
        public StarSystem RetrieveNextStarSystem(FileInfo fileInfo)
        {
            if (fileInfo == null) throw new ArgumentNullException("fileInfo");
            var starSystem = new StarSystem();
            int count = 0, nrsystems = VisitedSystems.Count;
            _foundSystems = new List<StarSystem>();

            using (Stream fs = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
                using (StreamReader sr = new StreamReader(fs)) {
                    DateTime gammastart = new DateTime(2014, 11, 22, 13, 00, 00);
                    string FirstLine = sr.ReadLine();
                    string line, str;
                    NetLogFileInfo nfi = null;
                    str = "20" + FirstLine.Substring(0, 8) + " " + FirstLine.Substring(9, 5);

                    DateTime filetime = DateTime.Parse(str);
                    if (_netlogfiles.ContainsKey(fileInfo.FullName)) {
                        nfi = _netlogfiles[fileInfo.FullName];
                        sr.BaseStream.Position = nfi.filePos;
                        sr.DiscardBufferedData();
                    }

                    while ((line = sr.ReadLine()) != null) {
                        if (line.Contains(" System:")) {
                            SystemPosition ps = SystemPosition.Parse(filetime, line);
                            if (ps != null) {
                                if (ps.Name.Equals("Training"))
                                    continue;
                                if (ps.Name.Equals("Destination"))
                                    continue;

                                filetime = ps.Time;

                                if (VisitedSystems.Count > 0)
                                    if (VisitedSystems[VisitedSystems.Count - 1].Name.Equals(ps.Name))
                                        continue;

                                if (ps.Time.Subtract(gammastart).TotalMinutes > 0) { // Ta bara med efter gamma.
                                    AddNewSystem(ps);
                                    count++;
                                }
                            }
                        }
                    }

                    if (nfi == null)
                        nfi = new NetLogFileInfo();

                    nfi.FileName = fileInfo.FullName;
                    nfi.lastchanged = File.GetLastWriteTimeUtc(nfi.FileName);
                    nfi.filePos = sr.BaseStream.Position;
                    nfi.fileSize = fileInfo.Length;

                    _netlogfiles[nfi.FileName] = nfi;
                    _lastnfi = nfi;
                }
            }
            if (_foundSystems.Count > 0) {
                starSystem = _foundSystems[_foundSystems.Count - 1];
                return starSystem;
            } else {
                return null;
            }
        }
Exemplo n.º 8
0
 private void VisitedSystemsGrid_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
 {
     if (e.StateChanged != DataGridViewElementStates.Selected) return;
     var row = (SystemGridRow)e.Row.DataBoundItem;
     _currentStarSystem = StarSystemServices.GetByStarSystemId(row.Id);
     RefreshStarSystemControls();
 }
Exemplo n.º 9
0
 private void Refuel_Click(object sender, EventArgs e)
 {
     _currentStarSystem.Refuel = Refuel.Checked;
        // _currentStarSystem.Expedition = _currentExpedition;
     _currentStarSystem = StarSystemServices.UpdateStarSystem(_currentStarSystem);
 }
Exemplo n.º 10
0
 private void Discovered_Click(object sender, EventArgs e)
 {
     _currentStarSystem.Discovered = Discovered.Checked;
     _currentStarSystem = StarSystemServices.UpdateStarSystem(_currentStarSystem);
 }
Exemplo n.º 11
0
 private void Bookmark_Click(object sender, EventArgs e)
 {
     _currentStarSystem.IsBookMarked = Bookmark.Checked;
     _currentStarSystem = StarSystemServices.UpdateStarSystem(_currentStarSystem);
 }
Exemplo n.º 12
0
 private void AddNewSystem(SystemPosition ps)
 {
     if (ps == null) throw new ArgumentNullException("ps");
     var starSystem = new StarSystem { CreatedAt = DateTime.Now, Name = ps.Name };
     NetLogWatcherEventArgs args = new NetLogWatcherEventArgs();
     args.CurrentSystem = starSystem;
     OnNewPosition(this, args);
 }