Ejemplo n.º 1
0
        // Compute the distance to each rare good location from the player's current system
        private void ComputeRareGoodsDistances(object sender, EventArgs e)
        {
            if (!ValidateComboBox(CurrentSystem))
            {
                return;
            }

            RareResults.Items.Clear();

            List <Destination> sorted;

            galaxy.SortRaresByDistance(CurrentSystem.Text, availableRares.Values.ToList(), out sorted);
            foreach (Destination dest in sorted)
            {
                RareGood     rare    = dest.Rare;
                ListViewItem newItem = new ListViewItem();
                newItem.Text = rare.LocationName;
                newItem.SubItems.Add(rare.Station);
                newItem.SubItems.Add(rare.Name);
                newItem.SubItems.Add(dest.Distance.ToString("0.00"));
                newItem.SubItems.Add(rare.StationDistance);
                newItem.SubItems.Add(rare.LastKnownCost.ToString());
                newItem.SubItems.Add(rare.Allegiance);
                RareResults.Items.Add(newItem);
            }
        }
Ejemplo n.º 2
0
        private void OnRouteUpdated()
        {
            RouteResults.Items.Clear();
            for (int i = 0; i < currentRoute.Count; i++)
            {
                RouteNode r = currentRoute[i];
                string    distanceToPrev = (i > 0) ? currentRoute[i - 1].Rare.Distance(r.Rare).ToString("0.00") : "N/A";

                ListViewItem newItem = new ListViewItem();
                newItem.Text = r.Rare.LocationName;
                newItem.SubItems.Add(i.ToString());
                newItem.SubItems.Add(r.Rare.Station);
                newItem.SubItems.Add(r.Rare.StationDistance);
                newItem.SubItems.Add(r.Rare.Name);
                newItem.SubItems.Add(distanceToPrev);
                if (currentRoute[i].SellHere.Count == 0)
                {
                    newItem.SubItems.Add("N/A");
                    newItem.SubItems.Add("N/A");
                }
                for (int j = 0; j < currentRoute[i].SellHere.Count; j++)
                {
                    RareGood s = currentRoute[i].SellHere[j];
                    newItem.SubItems.Add(s.Name);
                    newItem.SubItems.Add(s.Distance(r.Rare).ToString("0.00"));
                    if (j < currentRoute[i].SellHere.Count - 1)
                    {
                        RouteResults.Items.Add(newItem);
                        newItem      = new ListViewItem();
                        newItem.Text = "";
                        newItem.SubItems.Add("");
                        newItem.SubItems.Add("");
                        newItem.SubItems.Add("");
                        newItem.SubItems.Add("");
                        newItem.SubItems.Add("");
                    }
                }
                RouteResults.Items.Add(newItem);
            }
        }
Ejemplo n.º 3
0
    public List <RouteNode> FindRoute(StarSystem currentSystem, float idealDistance, int jumpsPerLeg, int maxJumps)
    {
        RareGood closest = rares.OrderBy(r => currentSystem.Distance(r.Location)).FirstOrDefault();

        List <RouteNode> route = new List <RouteNode>();

        route.Add(new RouteNode(closest));
        List <RareGood> currentRares = new List <RareGood>();

        //float idealCutoff = 3.0f * idealDistance / 4.0f;
        while (route.Count < maxJumps)
        {
            RareGood current = route[route.Count - 1].Rare;
            currentRares.Add(current);
            RareGood next = rares.Where(delegate(RareGood r) {
                // Check to see if we've already visited this location in this leg
                if (currentRares.Contains(r))
                {
                    return(false);
                }

                // Check to see if this step is inefficient in the scope of the leg
                float distance = current.Distance(r);
                //if (distance > idealCutoff) { return false; }
                r.Fitness = distance;

                // Check to see if we have to sell here
                float sellOffsets = 0.0f;
                bool canSell      = false;
                foreach (RareGood s in currentRares)
                {
                    float toSeller = s.Distance(r);
                    if (toSeller >= idealDistance)
                    {
                        canSell = true;
                    }
                    sellOffsets -= (toSeller - idealDistance);
                }
                if (currentRares.Count == jumpsPerLeg && !canSell)
                {
                    return(false);
                }
                r.Fitness += sellOffsets / 10.0f;

                // This rare is valid
                return(true);
            }).OrderBy(r => r.Fitness).FirstOrDefault();
            if (next == null)
            {
                break;
            }
            List <RareGood> sellable = new List <RareGood>();
            foreach (RareGood r in currentRares)
            {
                if (next.Distance(r) >= idealDistance)
                {
                    sellable.Add(r);
                }
            }
            foreach (RareGood r in sellable)
            {
                currentRares.Remove(r);
            }
            route.Add(new RouteNode(next, sellable));
        }

        return(route);
    }
Ejemplo n.º 4
0
 public RouteNode(RareGood r, List <RareGood> sell)
 {
     Rare     = r;
     SellHere = new List <RareGood>(sell);
 }
Ejemplo n.º 5
0
 public RouteNode(RareGood r)
 {
     Rare     = r;
     SellHere = new List <RareGood>();
 }
Ejemplo n.º 6
0
 public RouteNode()
 {
     Rare     = null;
     SellHere = null;
 }
Ejemplo n.º 7
0
 public float Distance(RareGood other)
 {
     return(Location.Position.Distance(other.Location.Position));
 }