Ejemplo n.º 1
0
		public CommoditySelection(MainScreen mainScreen)
		{
			this.mainScreen = mainScreen;
			InitializeComponent();
			sorter = new CommoditySorter();
			listView1.ListViewItemSorter = sorter;
		}
Ejemplo n.º 2
0
        public void UpdateDisplay()
        {
            evaluations.Clear();
            Destination     currentData    = mainScreen.currentRoute.destinations[index];
            StationData     currentStation = mainScreen.data.GetStation(currentData.system, currentData.station);
            CommoditySorter sorter         = new CommoditySorter();

            sorter.criteria  = CommoditySorterCriteria.Profit;
            sorter.sortOrder = SortOrder.Descending;
            foreach (StationData station in mainScreen.data.Stations)
            {
                if (station == currentStation)
                {
                    continue;
                }
                List <ComparedCommodity> compared = new List <ComparedCommodity>();
                int amount = mainScreen.pilotData.maxCargo;
                foreach (string commodity in mainScreen.data.allCommodities)
                {
                    compared.Add(new ComparedCommodity(commodity, amount, currentStation.GetPrice(commodity), station.GetPrice(commodity)));
                }
                compared.Sort(sorter);
                Destination destination = new Destination(currentData);
                int         profit      = 0;
                if (respectBalance)
                {
                    if (sliceTransactions)
                    {
                        //TODO: go from most to least profitable and add transactions with as much as we can afford
                    }
                    else
                    {
                        //TODO: go from most to least profitable and add a single transaction once we can afford a full load.
                    }
                    //TODO: What to do if we cannot afford anything? Fallback?
                }
                else
                {
                    ComparedCommodity comm = compared.First();
                    profit += comm.profitPer * amount;
                    destination.transactions.Add(new Transaction(comm.commodity, 0));
                }
                evaluations.Add(new Evaluation(destination, new Destination(station), profit));
            }
            evaluations.Sort(new EvaluationSorter());

            if (evaluations.Count > showResults)
            {
                evaluations.RemoveRange(evaluations.Count, evaluations.Count - showResults);
            }

            // Cut off controls we don't need anymore
            if (destinationControls.Count > evaluations.Count)
            {
                for (int i = destinationControls.Count - 1; i >= evaluations.Count; i--)
                {
                    destinationControls[i].Dispose();
                    destinationControls.RemoveAt(i);
                }
                destinationControls.TrimExcess();
            }
            // Add missing controls & update existing ones
            destinationControls.Capacity = evaluations.Count;
            for (int i = 0; i < evaluations.Count; i++)
            {
                EvaluateDestinationControl ctrl;
                if (i >= destinationControls.Count)
                {
                    ctrl = new EvaluateDestinationControl(this);
                    destinationControls.Add(ctrl);
                    ctrl.Parent = flowLayoutPanel1;
                }
                else
                {
                    ctrl = destinationControls[i];
                }
                ctrl.index           = i;
                ctrl.destination     = evaluations[i].destination;
                ctrl.nextDestination = evaluations[i].nextDestination;
                ctrl.updateDisplay();
            }
        }