private void ComputeAvailableRares() { availableRares = new Dictionary <string, RareGood>(); foreach (RareGood rare in RareData.GetRares()) { if (!galaxy.Systems.ContainsKey(rare.LocationName)) { MessageBox.Show(String.Format("Failed to get data for system {0} associated with rare good {1}, rare data may be out-of-date, or we may have failed to get data from EDStarCoordinator.", rare.LocationName, rare.Name), "F**k!", MessageBoxButtons.OK); continue; } rare.Location = galaxy.Systems[rare.LocationName]; rareData[rare.Name] = rare; if (blacklist.Contains(rare.Name)) { continue; } float stationDistance = rare.StationDistanceInLightSeconds(); if (MaxDistanceCheckBox.Checked && ((float)MaxDistanceUpDown.Value) < stationDistance) { continue; // Station is too far from primary star. } if (stationDistance < 0 && IgnoreUnknownStationDistanceCheckBox.Checked) { continue; } availableRares[rare.Name] = rare; } }
private void ReadNextSystem(StarSystem currentSystem) { if (currentPath == null || currentSystem == null) { return; } bool readNext = false; foreach (PathNode node in currentPath) { if (readNext) { var whole = Math.Floor(node.TraversalCost); var part = Math.Floor((node.TraversalCost - whole) * 10); Speak(string.Format( "Next, jump {0} point {1} light years to; {2}", whole, part, node.Local.PhoenicName())); return; } if (node.Local.Name.Equals(currentSystem.Name)) { readNext = true; } } if (readNext) { // We've arrived at the target system. If this system sells any rares, // read the dock name. var message = "You have arrived; "; foreach (RareGood rare in RareData.GetRares()) { if (rare.LocationName.Equals(currentSystem.Name)) { message += "Dock at " + rare.Station; break; } } Speak(message); } else { // This system isn't on the route. Should we say something? int x = new Random().Next(100); if (x > 85) { Speak("Do you know where we're going?"); } else if (x > 95) { Speak("Can't we just stop and ask for directions?"); } } }
private async void UpdateSystems() { // Get galaxy data from the web / hard drive SetLoadingStatus(true); await galaxy.GetData(); SetLoadingStatus(false); // Populate the combo boxen string[] systemNames = galaxy.Systems.Values.Select(s => s.Name).ToArray(); CurrentSystem.Items.Clear(); CurrentSystem.Items.AddRange(systemNames); DestinationSystem.Items.Clear(); DestinationSystem.Items.AddRange(systemNames); // Fill in data in rare good fields List <RareGood> rares = RareData.GetRares(); string[] rareNames = rares.Select(r => r.Name).OrderBy(r => r).ToArray(); RareGoodSelector.Items.Clear(); RareGoodSelector.Items.AddRange(rareNames); rareData = new Dictionary <string, RareGood>(); ComputeAvailableRares(); }
private void MainForm_Load(object sender, EventArgs e) { // Setup bindings ComputeButton.Click += ComputeRareGoodsDistances; PathButton.Click += ComputePath; RouteButton.Click += ComputeRoute; // Rare tab RareResults.ItemSelectionChanged += SetNewDestination; RareResults.Columns.Add("System", 100); RareResults.Columns.Add("Station", 150); RareResults.Columns.Add("Commodity", 200); RareResults.Columns.Add("Dist.", 60); RareResults.Columns.Add("Station Dist.", 60); RareResults.Columns.Add("Last Known Price", 50); RareResults.Columns.Add("Station Allegiance", 90); RareResults.ColumnClick += SortRareGoodsResults; // Path tab PathResults.ItemSelectionChanged += SetCurrentLocation; PathResults.Columns.Add("System", 150); PathResults.Columns.Add("#", 30); PathResults.Columns.Add("Jump Dist.", 60); PathResults.Columns.Add("Travelled", 60); PathResults.Columns.Add("Dist. To Target", 60); // Route tab RouteResults.ItemSelectionChanged += SetCurrentRouteStop; RouteResults.Columns.Add("System", 100); RouteResults.Columns.Add("#", 30); RouteResults.Columns.Add("Station", 150); RouteResults.Columns.Add("Station Dist.", 60); RouteResults.Columns.Add("Commodity", 150); RouteResults.Columns.Add("Dist. To Prev", 60); RouteResults.Columns.Add("Good to Sell", 150); RouteResults.Columns.Add("Dist. To Sellee", 60); this.FormClosing += OnExit; // Load previous settings Settings settings; if (!LocalData <Settings> .LoadLocalData("Settings.xml", out settings)) { settings = new Settings(); } MaxJumpDistance.Text = settings.JumpDistance; CurrentSystem.Text = settings.CurrentSystem; DestinationSystem.Text = settings.DestinationSystem; JumpsPerLeg.Text = settings.JumpsPerLeg; MaxJumps.Text = settings.MaxJumps; IdealSellDistance.Text = settings.IdealSellDistance; SaveButton.Click += FullSaveRoute; LoadButton.Click += FullLoadRoute; RareGoodSelector.DrawItem += DrawRaresComboBox; BlacklistButton.Click += Blacklist; UnblacklistButton.Click += Unblacklist; LogDirectoryTextBox.Text = settings.LogDirectory; ReadDirectionsCheckBox.Checked = settings.ReadDirections; MaxDistanceUpDown.Value = settings.MaxStationDistanceValue; MaxDistanceCheckBox.Checked = settings.MaxStationDistanceEnabled; IgnoreUnknownStationDistanceCheckBox.Checked = settings.IgnoreUnknownStationDistance; blacklist = settings.Blacklist; speechSynthesizer = new SpeechSynthesizer(); speechSynthesizer.SetOutputToDefaultAudioDevice(); speechSynthesizer.Rate = -2; // Load spaaaace galaxy = new Galaxy(); UpdateSystems(); // Start tracking the player. logWatcher = new LogWatcher(settings.LogDirectory); logWatcher.OnSystemChanged += StarSystemChanged; // Load the rare cache, and notify the user if we're using hardcoded data. RareData.GetRares(); if (RareData.UsingHardcoded()) { MessageBox.Show("Using hard-coded rare data, which is incomplete. Use an updated " + "Rares.xml to get better routes and avoid this.", "Bummer.", MessageBoxButtons.OK); } currentRoute = null; }