/// <summary>
        /// This form displays the profits one can make between two stations.
        /// </summary>
        /// <param name="localStation">The local station.</param>
        /// <param name="entityHandler">The entity handler to use.</param>
        /// <param name="hideSwitchButton">True if the switch button shall be hidden. This can be useful when this dialog is part of a
        /// longer planning process.</param>
        /// <param name="maximumCommodityPrice">The maximum price a commodity may cost. Set to 0 to disable (default).</param>
        public SpaceStationCommodityDialog(
            Entity.SpaceStation localStation, Core.IEntityHandler entityHandler, bool hideSwitchButton = false, UInt64 maximumCommodityPrice = 0
            )
        {
            _localStation          = localStation;
            _entityHandler         = entityHandler;
            _maximumCommodityPrice = maximumCommodityPrice;

            InitializeComponent();
            if (hideSwitchButton)
            {
                this.SwitchButton.Hide();
                this.ProfitView.Height += this.SwitchButton.Height;
            }

            _remoteSpaceStationComboBox.Initialize(entityHandler);
            // Fill the space station manually - OnInitialObjectsLoaded won't be called since the application is fully initialized already
            _remoteSpaceStationComboBox.OnInitialObjectsLoaded(entityHandler.GetEntityManager <Entity.SpaceStation>().GetAll());
            // Remove the local station from the list.
            _remoteSpaceStationComboBox.OnDataSetRemoved(localStation);
            _remoteSpaceStationComboBox.SelectedIndexChanged += RemoteSpaceStationComboBox_SelectedIndexChanged;

            ComboBoxPanel.Controls.Add(_remoteSpaceStationComboBox);

            MostRecentlySelectedEntry = null;
            this.ProfitView.ProfitListView.DoubleClick += ProfitListView_DoubleClick;

            // Simulate a selection
            RemoteSpaceStationComboBox_SelectedIndexChanged(_remoteSpaceStationComboBox, null);
        }
예제 #2
0
        public static List <ProfitEntry> CreateProfitListForTradesFromStation(Entity.SpaceStation localStation)
        {
            var profitList = new List <ProfitEntry>();

            // Retrieve all Commodity Types which are sold at the curren station
            // Sort them first by Commodity Group, then by Commodity Type
            var marketEntriesForSale = localStation.MarketEntries.Where(entry => entry.BuyFromStationPrice.HasValue && entry.BuyFromStationPrice != 0)
                                       .OrderBy(entry => entry.CommodityType.CommodityGroup.Name)
                                       .ThenBy(entry => entry.CommodityType.Name);

            foreach (var marketEntry in marketEntriesForSale)
            {
                var bestBuyPriceEntry = FindBestMarketEntry(marketEntry.CommodityType, findSeller: false);

                // Skip if no best buyer could be retrieved or if the retrieved price was invalid or lower than the local station's sell price
                if (bestBuyPriceEntry == null)
                {
                    continue;
                }
                if (!bestBuyPriceEntry.SellToStationPrice.HasValue || bestBuyPriceEntry.SellToStationPrice.Value == 0)
                {
                    continue;
                }
                if (bestBuyPriceEntry.SellToStationPrice.Value <= marketEntry.BuyFromStationPrice)
                {
                    continue;
                }

                profitList.Add(CreateProfitEntry(marketEntry.CommodityType, marketEntry, bestBuyPriceEntry));
            }
            return(profitList);
        }
        private String GetPriceLine(int?price, DateTime lastUpdate, Entity.SpaceStation spaceStation)
        {
            var spaceStationNameAndLocation = String.Format(
                "{0} ({1})", spaceStation.Name, spaceStation.SolarSystem.Name
                );

            return(String.Format(
                       "\n - {0}: {1} ({2})",
                       price.Value.ToString(),
                       spaceStationNameAndLocation,
                       lastUpdate.ToString("yyyy-MM-dd hh:mm:ss")
                       ));
        }
예제 #4
0
        /// <summary>
        /// Retrieves the best profit which can be made when buying at supplierStation and selling at demanderStation, respecting a maximumCostPerUnit.
        /// </summary>
        /// <param name="supplierStation">The name of the station which sells stuff.</param>
        /// <param name="demanderStation">The name of the station which buys stuff.</param>
        /// <param name="maximumCostPerUnit">The maximum cost per unit.</param>
        /// <returns>The best profit entry, or null if no such entry exists.</returns>
        public static ProfitEntry FindBestProfitEntry(Entity.SpaceStation supplierStation, Entity.SpaceStation demanderStation, int maximumCostPerUnit)
        {
            var profits = CreateProfitList(supplierStation, demanderStation)
                          .Where(entry => entry.BuyFromMarketPrice.Value <= maximumCostPerUnit && entry.Profit.Value > 0)
                          .OrderByDescending(entry => entry.Profit)
                          .ThenByDescending(entry => entry.ProfitPerInvestment);

            if (profits.Count() == 0)
            {
                return(null);
            }

            return(profits.First());
        }
예제 #5
0
 public static List <ProfitEntry> CreateProfitList(Entity.SpaceStation localStation, Entity.SpaceStation remoteStation)
 {
     if (remoteStation == null)
     {
         return(CreateProfitListForTradesFromStation(localStation));
     }
     if (localStation == null)
     {
         return(CreateProfitListForTradesToStation(remoteStation));
     }
     else
     {
         return(CreateProfitList(BuildLookupHash(localStation), BuildLookupHash(remoteStation)));
     }
 }
예제 #6
0
        public JumpConnectionAdditionDialog(Entity.SpaceStation spaceStation1)
        {
            InitializeComponent();

            SpaceStation2  = null;
            JumpRange      = null;
            _spaceStation1 = spaceStation1;
            this.SpaceStation1TextBox.Text = spaceStation1.Name;

            this.TableLayout.Controls.Add(SpaceStation2ComboBox, 1, 1);

            this.SpaceStation2ComboBox.SelectedIndexChanged += SpaceStation2ComboBox_SelectedIndexChanged;
            this.JumpRangeTextBox.TextChanged += JumpRangeTextBox_TextChanged;

            ValidateInput();
        }
 private void UpdateLabelText(Entity.SpaceStation localStation, Entity.SpaceStation remoteStation)
 {
     if (remoteStation == null)
     {
         this.ListViewCaption.Text = String.Format(
             "The following profits can be made when buying from the {0} station:", _localStation.Name
             );
     }
     else
     {
         this.ListViewCaption.Text = String.Format(
             "The following profits can be made when buying from the {0} station and selling at the {1} station",
             localStation.Name, remoteStation.Name
             );
     }
 }
예제 #8
0
        public void UpdateHighestBuyer(Entity.CommodityType commodityType, Entity.SpaceStation currentStation = null)
        {
            IEnumerable <Entity.MarketEntry> marketEntries = commodityType.MarketEntries;

            if (currentStation != null)
            {
                // Do not inspect current station
                marketEntries = marketEntries.Where(x => x.SpaceStation != currentStation);
            }

            var maximumBuyPrice = marketEntries.Max(x => x.SellToStationPrice);

            if (!maximumBuyPrice.HasValue)
            {
                HighestBuyerLabel.Text = String.Empty;
            }
            else
            {
                var highestEntry = marketEntries.Where(x => x.SellToStationPrice == maximumBuyPrice);
                HighestBuyerLabel.Text = highestEntry.First().SellToStationPrice.ToString() + ": " +
                                         highestEntry.First().SpaceStation.Name + " (" + highestEntry.First().SpaceStation.SolarSystem.Name + ")";
            }
        }
예제 #9
0
 public World(int width, int height)
 {
     spaceStation = new Entity.SpaceStation(301);
     dynamicCellSpacePartition = new Systems.CellSpacePartition(spaceStation.Diameter, spaceStation.Diameter, 4);
 }
예제 #10
0
        private static Dictionary <Entity.CommodityType, Entity.MarketEntry> BuildLookupHash(Entity.SpaceStation spaceStation)
        {
            var lookupHash = new Dictionary <Entity.CommodityType, Entity.MarketEntry>();

            if (spaceStation != null)
            {
                foreach (var marketEntry in spaceStation.MarketEntries)
                {
                    lookupHash.Add(marketEntry.CommodityType, marketEntry);
                }
            }

            return(lookupHash);
        }