public Route(Route copy)
        {
            manifests = new List<Manifest>();

            foreach (Manifest copyManifest in copy.Manifests)
                manifests.Add(new Manifest(copyManifest));
        }
        public RouteEditorDialog(Route route, EditorMode mode = EditorMode.View)
        {
            InitializeComponent();
            this.Icon = new Icon("Graphics\\EliteDangerousIcon.ico");

            this.route = route;
            this.mode = mode;

            if (mode == EditorMode.View)
                SetUpViewer();
        }
        private static void CalculateOptimalRoutes(GameData gameData)
        {
            gameData.OptimalRoutes.Clear();

            foreach (StarSystem startSystem in gameData.StarSystems)
                foreach (Station startStation in startSystem.Stations)
                {
                    Route candidateRoute = null;

                    //Find best first out and return pair.
                    foreach (StarSystem endSystem in gameData.StarSystems)
                        foreach (Station endStation in endSystem.Stations)
                        {
                            if (startSystem.Equals(endSystem) || startStation.Equals(endStation))
                                continue;

                            Manifest outManifest = FindManifest(gameData, startSystem, startStation, endSystem, endStation);
                            Manifest returnManifest = FindManifest(gameData, endSystem, endStation, startSystem, startStation);

                            if (outManifest == null || returnManifest == null)
                                continue;
                            else
                            {
                                if (candidateRoute == null || candidateRoute.AverageProfitPerTrip < (outManifest.Profit + returnManifest.Profit) / 2.0M)
                                {
                                    candidateRoute = new Route();
                                    candidateRoute.Manifests.Add(outManifest);
                                    candidateRoute.Manifests.Add(returnManifest);
                                }
                            }
                        }

                    if (candidateRoute != null)
                    {
                        //Find a new out and return pair. Compare to the candidate to see if the route gets better.
                        bool foundNewPair;

                        do
                        {
                            foundNewPair = false;

                            Route compareTo = new Route(candidateRoute);
                            compareTo.Manifests.RemoveAt(compareTo.Manifests.Count - 1);
                            Manifest lastCompareManifest = compareTo.Manifests[compareTo.Manifests.Count - 1];

                            Manifest candidateStart = null;
                            Manifest candidateReturn = null;

                            foreach (StarSystem newSystem in gameData.StarSystems)
                                foreach (Station newStation in newSystem.Stations)
                                {
                                    bool isUsed = false;

                                    foreach (Manifest usedManifest in compareTo.Manifests)
                                        if (usedManifest.StartSystemName == newSystem.Name && usedManifest.StartStationName == newStation.Name)
                                            isUsed = true;

                                    if (isUsed)
                                        continue;

                                    Manifest newStart = FindManifest(gameData, lastCompareManifest.EndSystem, lastCompareManifest.EndStation, newSystem, newStation);
                                    Manifest newReturn = FindManifest(gameData, newSystem, newStation, compareTo.CenterSystem, compareTo.CenterStation);

                                    if (newStart == null || newReturn == null)
                                        continue;
                                    else
                                    {
                                        if ((candidateStart == null && candidateReturn == null) ||
                                            candidateStart.Profit + candidateReturn.Profit < newStart.Profit + newReturn.Profit)
                                        {
                                            candidateStart = newStart;
                                            candidateReturn = newReturn;
                                        }
                                    }
                                }

                            if (candidateStart != null && candidateReturn != null)
                            {
                                compareTo.Manifests.Add(candidateStart);
                                compareTo.Manifests.Add(candidateReturn);

                                if (compareTo.AverageProfitPerTrip > candidateRoute.AverageProfitPerTrip)
                                {
                                    candidateRoute = compareTo;
                                    foundNewPair = true;
                                }
                            }
                        }
                        while (foundNewPair);

                        if (candidateRoute != null)
                            gameData.OptimalRoutes.Add(candidateRoute);
                    }
                }
        }
        public bool Equals(Route compareTo)
        {
            if (Trips != compareTo.Trips || Profit != compareTo.Profit || AverageProfitPerTrip != compareTo.AverageProfitPerTrip)
                return false;

            return true;
        }
        private static void CalculateOptimalRoutes(GameData gameData)
        {
            gameData.OptimalRoutes.Clear();

            foreach (StarSystem startSystem in gameData.StarSystems)
            {
                foreach (Station startStation in startSystem.Stations)
                {
                    Route candidateRoute = null;

                    //Find best first out and return pair.
                    foreach (StarSystem endSystem in gameData.StarSystems)
                    {
                        foreach (Station endStation in endSystem.Stations)
                        {
                            if (startSystem.Equals(endSystem) || startStation.Equals(endStation))
                            {
                                continue;
                            }

                            Manifest outManifest    = FindManifest(gameData, startSystem, startStation, endSystem, endStation);
                            Manifest returnManifest = FindManifest(gameData, endSystem, endStation, startSystem, startStation);

                            if (outManifest == null || returnManifest == null)
                            {
                                continue;
                            }
                            else
                            {
                                if (candidateRoute == null || candidateRoute.AverageProfitPerTrip < (outManifest.Profit + returnManifest.Profit) / 2.0M)
                                {
                                    candidateRoute = new Route();
                                    candidateRoute.Manifests.Add(outManifest);
                                    candidateRoute.Manifests.Add(returnManifest);
                                }
                            }
                        }
                    }

                    if (candidateRoute != null)
                    {
                        //Find a new out and return pair. Compare to the candidate to see if the route gets better.
                        bool foundNewPair;

                        do
                        {
                            foundNewPair = false;

                            Route compareTo = new Route(candidateRoute);
                            compareTo.Manifests.RemoveAt(compareTo.Manifests.Count - 1);
                            Manifest lastCompareManifest = compareTo.Manifests[compareTo.Manifests.Count - 1];

                            Manifest candidateStart  = null;
                            Manifest candidateReturn = null;

                            foreach (StarSystem newSystem in gameData.StarSystems)
                            {
                                foreach (Station newStation in newSystem.Stations)
                                {
                                    bool isUsed = false;

                                    foreach (Manifest usedManifest in compareTo.Manifests)
                                    {
                                        if (usedManifest.StartSystemName == newSystem.Name && usedManifest.StartStationName == newStation.Name)
                                        {
                                            isUsed = true;
                                        }
                                    }

                                    if (isUsed)
                                    {
                                        continue;
                                    }

                                    Manifest newStart  = FindManifest(gameData, lastCompareManifest.EndSystem, lastCompareManifest.EndStation, newSystem, newStation);
                                    Manifest newReturn = FindManifest(gameData, newSystem, newStation, compareTo.CenterSystem, compareTo.CenterStation);

                                    if (newStart == null || newReturn == null)
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        if ((candidateStart == null && candidateReturn == null) ||
                                            candidateStart.Profit + candidateReturn.Profit < newStart.Profit + newReturn.Profit)
                                        {
                                            candidateStart  = newStart;
                                            candidateReturn = newReturn;
                                        }
                                    }
                                }
                            }

                            if (candidateStart != null && candidateReturn != null)
                            {
                                compareTo.Manifests.Add(candidateStart);
                                compareTo.Manifests.Add(candidateReturn);

                                if (compareTo.AverageProfitPerTrip > candidateRoute.AverageProfitPerTrip)
                                {
                                    candidateRoute = compareTo;
                                    foundNewPair   = true;
                                }
                            }
                        }while (foundNewPair);

                        if (candidateRoute != null)
                        {
                            gameData.OptimalRoutes.Add(candidateRoute);
                        }
                    }
                }
            }
        }