예제 #1
0
        public void updateDisplay()
        {
            lblStationName.Text = destination.station;
            lblSystemName.Text  = destination.system;

            listView1.Items.Clear();
            overallProfit = 0;

            Destination nextDestination = mainScreen.getNextDestination(index);
            StationData stationData     = mainScreen.data.GetStation(destination.system, destination.station);
            StationData nextStationData = null;

            if (nextDestination != null)
            {
                nextStationData = mainScreen.data.GetStation(nextDestination.system, nextDestination.station);
            }

            foreach (Transaction transaction in destination.transactions)
            {
                CommodityPrice ourPrice   = null;
                CommodityPrice theirPrice = null;
                if (stationData != null)
                {
                    ourPrice = stationData.GetPrice(transaction.commodity);
                    if (nextStationData != null)
                    {
                        theirPrice = nextStationData.GetPrice(transaction.commodity);
                    }
                }
                ComparedCommodity compared = new ComparedCommodity(transaction.commodity, transaction.GetAmount(mainScreen.pilotData.maxCargo), ourPrice, theirPrice);

                overallProfit += compared.profit;
                ListViewItem li = new ListViewItem(new string[] {
                    transaction.commodity,
                    transaction.amount == 0 ? String.Format("MAX ({0:0})", mainScreen.pilotData.maxCargo) : transaction.amount.ToString("N0"),
                    compared.ProfitPer,
                    compared.Profit
                });

                if (compared.profitPer == 0)
                {
                    li.BackColor = Color.Yellow;
                    li.ForeColor = Color.OrangeRed;
                }
                else if (compared.profitPer < 0)
                {
                    li.BackColor = Color.Red;
                    li.ForeColor = Color.Yellow;
                }
                else
                {
                    li.BackColor = Color.Green;
                    li.ForeColor = Color.LightGreen;
                }
                listView1.Items.Add(li);
            }
        }
예제 #2
0
		public void UpdateDisplay()
		{
			listView1.Items.Clear();
			listView1.Groups.Clear();
			foreach (KeyValuePair<string, string[]> commodityGroup in mainScreen.data.commodities)
			{
				ListViewGroup group = listView1.Groups.Add(commodityGroup.Key, commodityGroup.Key);

				foreach (string commodity in commodityGroup.Value)
				{
					CommodityPrice ourPrice = null;
					CommodityPrice theirPrice = null;
					if (stationData != null)
					{
						ourPrice = stationData.GetPrice(commodity);
						if (nextStationData != null)
						{
							theirPrice = nextStationData.GetPrice(commodity);
						}
					}
					int amount = selectedAmount == 0 ? mainScreen.pilotData.maxCargo : selectedAmount;
					ComparedCommodity compared = new ComparedCommodity(commodity, amount, ourPrice, theirPrice);

					ListViewItem li = new ListViewItem(new string[] {
						compared.Commodity,
						compared.Demand,
						compared.PriceSell,
						compared.PriceBuy,
						compared.ProfitPer,
						compared.Profit
					}, group);
					li.Tag = compared;
					if (compared.profitPer == 0)
					{
						//li.BackColor = Color.Yellow;
						//li.ForeColor = Color.OrangeRed;
					}
					else if (compared.profitPer < 0)
					{
						li.BackColor = Color.Red;
						li.ForeColor = Color.Yellow;
					}
					else
					{
						li.BackColor = Color.Green;
						li.ForeColor = Color.LightGreen;
					}

					listView1.Items.Add(li);
				}
			}
		}
예제 #3
0
        public int Compare(ListViewItem x, ListViewItem y)
        {
            if (criteria == CommoditySorterCriteria.Group)
            {
                int returnVal = 0;
                returnVal = string.Compare(x.Group.Header, y.Group.Header);
                if (sortOrder == SortOrder.Descending)
                {
                    returnVal *= -1;
                }
                return(returnVal);
            }

            ComparedCommodity cx = (ComparedCommodity)x.Tag;
            ComparedCommodity cy = (ComparedCommodity)y.Tag;

            return(Compare(cx, cy));
        }
예제 #4
0
        public int Compare(ComparedCommodity cx, ComparedCommodity cy)
        {
            int returnVal = 0;

            switch (criteria)
            {
            default:
            case CommoditySorterCriteria.Group:
                // Cannot compare what we don't have
                returnVal = 0;
                break;

            case CommoditySorterCriteria.Commodity:
                returnVal = string.Compare(cx.Commodity, cy.Commodity);
                break;

            case CommoditySorterCriteria.Demand:
                returnVal = (int)cx.demand - (int)cy.demand;
                break;

            case CommoditySorterCriteria.PriceSell:
                returnVal = cx.priceSell - cy.priceSell;
                break;

            case CommoditySorterCriteria.PriceBuy:
                returnVal = cx.priceBuy - cy.priceBuy;
                break;

            case CommoditySorterCriteria.Profit:
                returnVal = cx.profitPer - cy.profitPer;
                break;
            }
            if (sortOrder == SortOrder.Descending)
            {
                returnVal *= -1;
            }
            return(returnVal);
        }
예제 #5
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();
            }
        }