public static void UpdateSys(List <VisitedSystemsClass> visitedSystems, bool usedistancedb, bool matchsystems) // oldest system is lowest index { if (matchsystems) { SystemClass.FillVisitedSystems(visitedSystems); // first try and populate with SystemClass info } foreach (VisitedSystemsClass vsc in visitedSystems) { if (vsc.curSystem == null) // if no systemclass info, make a dummy { vsc.curSystem = new SystemClass(vsc.Name); if (vsc.HasTravelCoordinates) { vsc.curSystem.x = vsc.X; vsc.curSystem.y = vsc.Y; vsc.curSystem.z = vsc.Z; } } if (vsc.strDistance == null) { vsc.strDistance = ""; // set empty, must have a string in there. } } DistanceClass.FillVisitedSystems(visitedSystems, usedistancedb); // finally fill in the distances, indicating if can use db or not }
private void buttonUpdate_Click(object sender, EventArgs e) { var dist = DistanceAsDouble(textBoxDistance.Text.Trim()); if (!dist.HasValue) { MessageBox.Show("Distance in wrong format!"); } else { DistanceClass distance = new DistanceClass(); distance.Dist = dist.Value; distance.CreateTime = DateTime.UtcNow; distance.CommanderCreate = EDDiscoveryForm.EDDConfig.CurrentCommander.Name.Trim(); distance.NameA = textBoxSystem.Text; distance.NameB = textBoxPrevSystem.Text; distance.Status = DistancsEnum.EDDiscovery; distance.Store(); SQLiteDBClass.AddDistanceToCache(distance); if (dataGridViewTravel.SelectedCells.Count > 0) // if we have selected (we should!) { dataGridViewTravel.Rows[dataGridViewTravel.SelectedCells[0].OwningRow.Index].Cells[2].Value = textBoxDistance.Text.Trim(); } } }
private void buttonUpdate_Click(object sender, EventArgs e) { var dist = DistanceAsDouble(textBoxDistance.Text.Trim()); if (!dist.HasValue) { MessageBox.Show("Distance in wrong format!"); } else { DistanceClass distance = new DistanceClass(); distance.Dist = dist.Value; distance.CreateTime = DateTime.UtcNow; distance.CommanderCreate = textBoxCmdrName.Text.Trim(); distance.NameA = textBoxSystem.Text; distance.NameB = textBoxPrevSystem.Text; distance.Status = DistancsEnum.EDDiscovery; distance.Store(); SQLiteDBClass.AddDistanceToCache(distance); dataGridView1.Rows[lastRowIndex].Cells[2].Value = textBoxDistance.Text.Trim(); } }
private void LoadData() { try { using (var db = new MarathonDBEntities1()) { var speed = db.Speed.AsNoTracking().ToList(); foreach (var sp in speed) { string way = Assembly.GetExecutingAssembly().Location.Replace("Marathon.exe", "how long is marathon/"); SpeedClass newSpeed = new SpeedClass { Id = sp.SpeedId, Name = sp.Name, ImgSource = new BitmapImage(new Uri(way + sp.Image)), Speed = sp.TopSpeed }; speedList.Add(newSpeed); } ListVSpeed.ItemsSource = speedList; ListVSpeed.SelectedValuePath = "Id"; var distances = db.Distance.AsNoTracking().ToList(); foreach (var sp in distances) { string way = Assembly.GetExecutingAssembly().Location.Replace("Marathon.exe", "how long is marathon/"); DistanceClass newDist = new DistanceClass { Id = sp.DistanceId, Name = sp.Name, ImgSource = new BitmapImage(new Uri(way + sp.Image)), Distance = sp.Length }; distanceList.Add(newDist); } ListVDistance.ItemsSource = distanceList; ListVDistance.SelectedValuePath = "Id"; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public List <DistanceClass> GetDistances(string systemname) { List <DistanceClass> listDistances = new List <DistanceClass>(); try { string json; string query; query = "?sysname=" + WebUtility.HtmlEncode(systemname) + "&coords=1&distances=1&submitted=1"; json = RequestGet("sysinfo.php" + query); //http://the-temple.de/public/sysinfo.php?sysname=Col+359+Sector+CP-Y+c1-18&coords=1&include_hidden=1&distances=1&submitted=1 if (json.Length > 1) { JObject ditancesresp = (JObject)JObject.Parse(json); JArray distances = (JArray)ditancesresp["distances"]; if (distances != null) { foreach (JObject jo in distances) { DistanceClass dc = new DistanceClass(); dc.NameA = systemname; dc.NameB = jo["name"].Value <string>(); dc.Dist = jo["dist"].Value <float>(); // dc.CommanderCreate = jo[] listDistances.Add(dc); } } } } catch { } return(listDistances); }
public List <DistanceClass> GetDistances(string systemname) { List <DistanceClass> listDistances = new List <DistanceClass>(); try { string query; query = "?sysname=" + HttpUtility.UrlEncode(systemname) + "&coords=1&distances=1&submitted=1"; var response = RequestGet("api-v1/system" + query); var json = response.Body; //http://www.edsm.net/api-v1/system?sysname=Col+359+Sector+CP-Y+c1-18&coords=1&include_hidden=1&distances=1&submitted=1 if (json.Length > 1) { JObject ditancesresp = (JObject)JObject.Parse(json); JArray distances = (JArray)ditancesresp["distances"]; if (distances != null) { foreach (JObject jo in distances) { DistanceClass dc = new DistanceClass(); dc.NameA = systemname; dc.NameB = jo["name"].Value <string>(); dc.Dist = jo["dist"].Value <float>(); // dc.CommanderCreate = jo[] listDistances.Add(dc); } } } } catch { } return(listDistances); }
internal void NewPosition(object source) { try { string name = netlog.visitedSystems.Last().Name; Invoke((MethodInvoker) delegate { LogText("Arrived to system: "); SystemClass sys1 = SystemData.GetSystem(name); if (sys1 == null || sys1.HasCoordinate == false) { LogTextHighlight(name); } else { LogText(name); } int count = GetVisitsCount(name); LogText(" : Vist nr " + count.ToString() + Environment.NewLine); System.Diagnostics.Trace.WriteLine("Arrived to system: " + name + " " + count.ToString() + ":th visit."); var result = visitedSystems.OrderByDescending(a => a.time).ToList <SystemPosition>(); //if (TrilaterationControl.Visible) //{ // CloseTrilateration(); // MessageBox.Show("You have arrived to another system while trilaterating." // + " As a pre-caution to prevent any mistakes with submitting wrong systems or distances" // + ", your trilateration was aborted."); //} SystemPosition item = result[0]; SystemPosition item2; if (result.Count > 1) { item2 = result[1]; } else { item2 = null; } // grab distance to next (this) system textBoxDistanceToNextSystem.Enabled = false; if (textBoxDistanceToNextSystem.Text.Length > 0 && item2 != null) { SystemClass currentSystem = null, previousSystem = null; SystemData.SystemList.ForEach(s => { if (s.name == item.Name) { currentSystem = s; } if (s.name == item2.Name) { previousSystem = s; } }); if (currentSystem == null || previousSystem == null || !currentSystem.HasCoordinate || !previousSystem.HasCoordinate) { var presetDistance = DistanceAsDouble(textBoxDistanceToNextSystem.Text.Trim(), 45); if (presetDistance.HasValue) { var distance = new DistanceClass { Dist = presetDistance.Value, CreateTime = DateTime.UtcNow, CommanderCreate = EDDiscoveryForm.EDDConfig.CurrentCommander.Name, NameA = item.Name, NameB = item2.Name, Status = DistancsEnum.EDDiscovery }; Console.Write("Pre-set distance " + distance.NameA + " -> " + distance.NameB + " = " + distance.Dist); distance.Store(); SQLiteDBClass.AddDistanceToCache(distance); } } } textBoxDistanceToNextSystem.Clear(); textBoxDistanceToNextSystem.Enabled = true; AddHistoryRow(true, item, item2); StoreSystemNote(); }); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("Exception NewPosition: " + ex.Message); System.Diagnostics.Trace.WriteLine("Trace: " + ex.StackTrace); } }
private void AddHistoryRow(bool insert, SystemPosition item, SystemPosition item2) { SystemClass sys1 = null, sys2; double dist; sys1 = SystemData.GetSystem(item.Name); if (sys1 == null) { sys1 = new SystemClass(item.Name); if (SQLiteDBClass.globalSystemNotes.ContainsKey(sys1.SearchName)) { sys1.Note = SQLiteDBClass.globalSystemNotes[sys1.SearchName].Note; } } if (item2 != null) { sys2 = SystemData.GetSystem(item2.Name); if (sys2 == null) { sys2 = new SystemClass(item2.Name); } } else { sys2 = null; } item.curSystem = sys1; item.prevSystem = sys2; if (!insert) { if (item.vs == null) { SystemPosition known = visitedSystems.First(x => x.Name == item.Name); if (known != null) { item.vs = known.vs; } } } string diststr = ""; dist = 0; if (sys2 != null) { if (sys1.HasCoordinate && sys2.HasCoordinate) { dist = SystemData.Distance(sys1, sys2); } else { dist = DistanceClass.Distance(sys1, sys2); } if (dist > 0) { diststr = dist.ToString("0.00"); } } item.strDistance = diststr; //richTextBox_History.AppendText(item.time + " " + item.Name + Environment.NewLine); object[] rowobj = { item.time, item.Name, diststr, item.curSystem.Note, "█" }; int rownr; if (insert) { dataGridViewTravel.Rows.Insert(0, rowobj); rownr = 0; } else { dataGridViewTravel.Rows.Add(rowobj); rownr = dataGridViewTravel.Rows.Count - 1; } var cell = dataGridViewTravel.Rows[rownr].Cells[1]; cell.Tag = item; dataGridViewTravel.Rows[rownr].DefaultCellStyle.ForeColor = (sys1.HasCoordinate) ? _discoveryForm.theme.VisitedSystemColor : _discoveryForm.theme.NonVisitedSystemColor; cell = dataGridViewTravel.Rows[rownr].Cells[4]; cell.Style.ForeColor = (item.vs == null) ? Color.FromArgb(defaultMapColour) : Color.FromArgb(item.vs.MapColour); }
// Update is called once per frame void Update() { camPos = Vector3.Lerp(camPos, transform.position + camOffset, camDelay); shipCam.transform.position = camPos; shipCam.transform.LookAt(transform); if (shipAlive) { // Handle User Input MoveShip(); if ((Input.GetAxis("Horizontal") != 0) || (Input.GetAxis("Vertical") != 0)) { //rigidBody.angularVelocity = -30 * Input.GetAxis("Horizontal"); float x_input = Input.GetAxis("Horizontal"); float y_input = Input.GetAxis("Vertical"); int heading = (int)(Mathf.Atan2(y_input, x_input) * 180 / Mathf.PI) - 90; rotAngle += x_input * sensitivity; this.transform.eulerAngles = new Vector3(0, rotAngle, 0); } else { rigidBody.angularVelocity = Vector3.zero; } } else { rigidBody.velocity = Vector3.zero; rigidBody.angularVelocity = Vector3.zero; } // Wrap Ship Around if ((this.transform.position.x * this.transform.position.x + this.transform.position.z * this.transform.position.z) > worldRadius * worldRadius) { this.transform.position = new Vector3(this.transform.position.x * -0.99f, this.transform.position.y, this.transform.position.z * -0.99f); } // Mine Sounds GameObject[] Mines = GameObject.FindGameObjectsWithTag("Mine"); DistanceClass CurrentClass = DistanceClass.Safe; GameObject closestMine = null; if (Mines.Length > 0) { float mindist = Vector3.Distance(this.transform.position, Mines[0].transform.position); closestMine = Mines[0]; for (int i = 0; i < Mines.Length; i++) { if (Vector3.Distance(this.transform.position, Mines[i].transform.position) < mindist) { closestMine = Mines[i]; mindist = Vector3.Distance(this.transform.position, Mines[i].transform.position); } } if (mindist <= SuperDangerThreshold) { CurrentClass = DistanceClass.SuperDanger; } else if (mindist <= DangerThreshold) { CurrentClass = DistanceClass.Danger; } else if (mindist <= WarningThreshold) { CurrentClass = DistanceClass.Warning; } else if (mindist <= SlightWarningThreshold) { CurrentClass = DistanceClass.SlightWarning; } } if (CurrentClass == DistanceClass.Safe) { // stop playing everything if (superDangerSource != null) { SoundManager.instance.StopSFX(superDangerSource); } if (dangerSource != null) { SoundManager.instance.StopSFX(dangerSource); } if (warningSource != null) { SoundManager.instance.StopSFX(warningSource); } if (slightWarningSource != null) { SoundManager.instance.StopSFX(slightWarningSource); } } else { if (PreviousClass > CurrentClass) { switch (CurrentClass) { case DistanceClass.SuperDanger: superDangerSource = SoundManager.instance.PlaySFX(SoundEffect.Warning4, true, 0, null, 0, 0, closestMine); break; case DistanceClass.Danger: dangerSource = SoundManager.instance.PlaySFX(SoundEffect.Warning3, true, 0, null, 0, 0, closestMine); break; case DistanceClass.Warning: warningSource = SoundManager.instance.PlaySFX(SoundEffect.Warning2, true, 0, null, 0, 0, closestMine); break; case DistanceClass.SlightWarning: slightWarningSource = SoundManager.instance.PlaySFX(SoundEffect.Warning1, true, 0, null, 0, 0, closestMine); break; } } else if (CurrentClass > PreviousClass) { switch (CurrentClass) { case DistanceClass.Danger: if (superDangerSource != null) { SoundManager.instance.StopSFX(superDangerSource); } break; case DistanceClass.Warning: if (dangerSource != null) { SoundManager.instance.StopSFX(dangerSource); } break; case DistanceClass.SlightWarning: if (warningSource != null) { SoundManager.instance.StopSFX(warningSource); } break; } } } PreviousClass = CurrentClass; }
private void AddHistoryRow(bool insert, SystemPosition item, SystemPosition item2) { SystemClass sys1 = null, sys2; double dist; sys1 = SystemData.GetSystem(item.Name); if (sys1 == null) { sys1 = new SystemClass(item.Name); if (SQLiteDBClass.globalSystemNotes.ContainsKey(sys1.SearchName)) { sys1.Note = SQLiteDBClass.globalSystemNotes[sys1.SearchName].Note; } } if (item2 != null) { sys2 = SystemData.GetSystem(item2.Name); if (sys2 == null) { sys2 = new SystemClass(item2.Name); } } else { sys2 = null; } item.curSystem = sys1; item.prevSystem = sys2; string diststr = ""; dist = 0; if (sys2 != null) { if (sys1.HasCoordinate && sys2.HasCoordinate) { dist = SystemData.Distance(sys1, sys2); } else { dist = DistanceClass.Distance(sys1, sys2); } if (dist > 0) { diststr = dist.ToString("0.00"); } } item.strDistance = diststr; //richTextBox_History.AppendText(item.time + " " + item.Name + Environment.NewLine); object[] rowobj = { item.time, item.Name, diststr, item.curSystem.Note }; int rownr; if (insert) { dataGridView1.Rows.Insert(0, rowobj); rownr = 0; } else { dataGridView1.Rows.Add(rowobj); rownr = dataGridView1.Rows.Count - 1; } var cell = dataGridView1.Rows[rownr].Cells[1]; cell.Tag = item; if (!sys1.HasCoordinate) // Mark all systems without coordinates { cell.Style.ForeColor = Color.Blue; } }
private void GetEDSCDistances() { try { SQLiteDBClass db = new SQLiteDBClass(); //EDSCClass edsc = new EDSCClass(); EDSMClass edsm = new EDSMClass(); string lstdist = db.GetSettingString("EDSCLastDist", "2010-01-01 00:00:00"); string json; // Get distances string rwdisttime = db.GetSettingString("RWLastDist", "2000-01-01 00:00:00"); // Latest time from RW file. string rwdistfiletime = ""; lstdist = db.GetSettingString("EDSCLastDist", "2010-01-01 00:00:00"); List <DistanceClass> dists = new List <DistanceClass>(); json = LoadJsonArray(fileTgcDistances); dists = DistanceClass.ParseEDSC(json, ref rwdistfiletime); if (!rwdisttime.Equals(rwdistfiletime)) // New distance file from Redwizzard { DistanceClass.Delete(DistancsEnum.EDSC); // Remove all EDSC distances. lstdist = "2010-01-01 00:00:00"; db.PutSettingString("RWLastDist", rwdistfiletime); } if (lstdist.Equals("2010-01-01 00:00:00")) { LogText("Adding data from tgcdistances.json " + Environment.NewLine); lstdist = rwdistfiletime; if (json == null) { LogText("Couldn't read file." + Environment.NewLine); } else { LogText("Found " + dists.Count.ToString() + " new distances." + Environment.NewLine); DistanceClass.Store(dists); db.PutSettingString("EDSCLastDist", lstdist); } } LogText("Checking for new distances from EDSM. "); Application.DoEvents(); json = edsm.RequestDistances(lstdist); dists = new List <DistanceClass>(); dists = DistanceClass.ParseEDSM(json, ref lstdist); if (json == null) { LogText("No response from server." + Environment.NewLine); } else { LogText("Found " + dists.Count.ToString() + " new distances." + Environment.NewLine); } Application.DoEvents(); DistanceClass.Store(dists); db.PutSettingString("EDSCLastDist", lstdist); db.GetAllDistances(); OnDistancesLoaded(); // Check for a new installer CheckForNewInstaller(); } catch (Exception ex) { LogText("GetEDSCDistances exception:" + ex.Message + Environment.NewLine); } }
private void GetEDSMDistances() { try { if (EDDConfig.UseDistances) { EDSMClass edsm = new EDSMClass(); EDDBClass eddb = new EDDBClass(); string lstdist = _db.GetSettingString("EDSCLastDist", "2010-01-01 00:00:00"); string json; // Get distances lstdist = _db.GetSettingString("EDSCLastDist", "2010-01-01 00:00:00"); List <DistanceClass> dists = new List <DistanceClass>(); if (lstdist.Equals("2010-01-01 00:00:00")) { LogText("Downloading mirrored EDSM distance data. (Might take some time)" + Environment.NewLine); eddb.GetEDSMDistances(); json = LoadJsonFile(_fileEDSMDistances); if (json != null) { LogText("Adding mirrored EDSM distance data." + Environment.NewLine); dists = new List <DistanceClass>(); dists = DistanceClass.ParseEDSM(json, ref lstdist); LogText("Found " + dists.Count.ToString() + " distances." + Environment.NewLine); Application.DoEvents(); DistanceClass.Store(dists); _db.PutSettingString("EDSCLastDist", lstdist); } } LogText("Checking for new distances from EDSM. "); Application.DoEvents(); json = edsm.RequestDistances(lstdist); dists = new List <DistanceClass>(); dists = DistanceClass.ParseEDSM(json, ref lstdist); if (json == null) { LogText("No response from server." + Environment.NewLine); } else { LogText("Found " + dists.Count.ToString() + " new distances." + Environment.NewLine); } Application.DoEvents(); DistanceClass.Store(dists); _db.PutSettingString("EDSCLastDist", lstdist); } _db.GetAllDistances(EDDConfig.UseDistances); // Load user added distances updateMapData(); OnDistancesLoaded(); GC.Collect(); } catch (Exception ex) { LogText("GetEDSMDistances exception:" + ex.Message + Environment.NewLine); LogText(ex.StackTrace + Environment.NewLine); } }