public PageSelectOpponents(StartDataObject sdo)
        {
            this.StartData = sdo;

            this.SelectedAirlines = new ObservableCollection<Airline>();
            this.Opponents = new ObservableCollection<Airline>();

            foreach (Airline airline in Airlines.GetAirlines(a => a.Profile.Founded <= this.StartData.Year && a.Profile.Folded > this.StartData.Year && a != this.StartData.Airline && (a.Profile.Country.Region == this.StartData.Region || (this.StartData.Continent != null && (this.StartData.Continent.Uid == "100" || this.StartData.Continent.hasRegion(a.Profile.Country.Region))))))
                this.Opponents.Add(airline);

            InitializeComponent();
        }
        public PageAirlineData(StartDataObject startData)
        {
            this.AllTimeZones = TimeZones.GetTimeZones();
            this.AllAirports = new ObservableCollection<Airport>();
            this.StartData = startData;

            InitializeComponent();

            var airlines = Airlines.GetAirlines(airline => (airline.Profile.Country.Region == this.StartData.Region || (this.StartData.Region.Uid == "100" && this.StartData.Continent.Uid == "100") || (this.StartData.Region.Uid == "100" && this.StartData.Continent.hasRegion(airline.Profile.Country.Region))) && airline.Profile.Founded <= this.StartData.Year && airline.Profile.Folded > this.StartData.Year).OrderBy(a=>a.Profile.Name).ToList();

            cbAirline.ItemsSource = airlines;
        }
        public PageSelectAirports(StartDataObject startdata)
        {
            StartData = startdata;
            SelectedCountries = new List<Country>();

            List<Country> countries =
            Airports.GetAllAirports()
                .Select(a => new CountryCurrentCountryConverter().Convert(a.Profile.Country) as Country)
                .Distinct()
                .ToList();

            AllCountries = countries.OrderBy(c=>c.Region.Name).ThenBy(c => c.Name).ToList();

            setNumberOfAirports();

            InitializeComponent();
        }
        //creates a new game
        public static void CreateGame(StartDataObject startData)
        {
            if (startData.RealData)
            {
                var notRealAirlines = Airlines.GetAirlines(a => !a.Profile.IsReal && a != startData.Airline);
                var notRealManufacturers = Manufacturers.GetManufacturers(m => !m.IsReal);
                var notRealAirliners = AirlinerTypes.GetTypes(a => notRealManufacturers.Contains(a.Manufacturer));

                foreach (Airline notRealAirliner in notRealAirlines)
                    Airlines.RemoveAirline(notRealAirliner);

                foreach (AirlinerType airliner in notRealAirliners)
                    AirlinerTypes.RemoveType(airliner);

            }

            int startYear = startData.Year;
            int opponents = startData.NumberOfOpponents;
            Airline airline = startData.Airline;
            Continent continent = startData.Continent;
            Region region = startData.Region;

            GameTimeZone gtz = startData.TimeZone;
            GameObject.GetInstance().DayRoundEnabled = startData.UseDayTurns;
            GameObject.GetInstance().TimeZone = gtz;
            GameObject.GetInstance().Difficulty = startData.Difficulty;
            GameObject.GetInstance().GameTime = new DateTime(startYear, 1, 1);
            GameObject.GetInstance().StartDate = GameObject.GetInstance().GameTime;
            //sets the fuel price
            GameObject.GetInstance().FuelPrice = Inflations.GetInflation(GameObject.GetInstance().GameTime.Year).FuelPrice;

            airline.Profile.Country = startData.HomeCountry;
            airline.Profile.CEO = startData.CEO;

            GameObject.GetInstance().setHumanAirline(airline);
            GameObject.GetInstance().MainAirline = GameObject.GetInstance().HumanAirline;

            if (startData.LocalCurrency)
                GameObject.GetInstance().CurrencyCountry = airline.Profile.Country;
            // AppSettings.GetInstance().resetCurrencyFormat();

            Airport airport = startData.Airport;

            AirportHelpers.RentGates(airport, airline, AirportContract.ContractType.Full, 2);

            AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1);
            AirportFacility facility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.Service).Find((delegate(AirportFacility f) { return f.TypeLevel == 1; }));

            airport.addAirportFacility(GameObject.GetInstance().HumanAirline, facility, GameObject.GetInstance().GameTime);
            airport.addAirportFacility(GameObject.GetInstance().HumanAirline, checkinFacility, GameObject.GetInstance().GameTime);

            if (continent.Uid != "100" || region.Uid != "100")
            {
                var airlines = Airlines.GetAirlines(a => a.Profile.Country.Region == region || (region.Uid == "100" && continent.hasRegion(a.Profile.Country.Region)) && a.Profile.Founded <= startYear && a.Profile.Folded > startYear);
                var airports = Airports.GetAirports(a => a.Profile.Country.Region == region || (region.Uid == "100" && continent.hasRegion(a.Profile.Country.Region)) && a.Profile.Period.From.Year <= startYear && a.Profile.Period.To.Year > startYear);

                Airports.Clear();
                foreach (Airport a in airports)
                    Airports.AddAirport(a);

                Airlines.Clear();
                foreach (Airline a in airlines)
                    Airlines.AddAirline(a);
            }

            PassengerHelpers.CreateAirlineDestinationDemand();

            AirlinerHelpers.CreateStartUpAirliners();

            if (startData.RandomOpponents || startData.Opponents == null)
                Setup.SetupMainGame(opponents, startData.SameRegion);
            else
                Setup.SetupMainGame(startData.Opponents, startData.NumberOfOpponents);

            if (startData.MajorAirports)
            {
                var majorAirports = Airports.GetAllAirports(a => a.Profile.Size == GeneralHelpers.Size.Largest || a.Profile.Size == GeneralHelpers.Size.Large || a.Profile.Size == GeneralHelpers.Size.Very_large || a.Profile.Size == GeneralHelpers.Size.Medium);
                var usedAirports = Airlines.GetAllAirlines().SelectMany(a => a.Airports);

                int minAirportsPerRegion = 5;
                foreach (Region airportRegion in Regions.GetRegions())
                {
                    int countRegionAirports = majorAirports.Count(a => a.Profile.Country.Region == airportRegion);
                    if (countRegionAirports < minAirportsPerRegion)
                    {
                        var regionAirports = Airports.GetAirports(airportRegion).Where(a => !majorAirports.Contains(a)).OrderByDescending(a => a.Profile.Size).Take(minAirportsPerRegion - countRegionAirports);

                        majorAirports.AddRange(regionAirports);
                    }
                }

                majorAirports.AddRange(usedAirports);

                Airports.Clear();

                foreach (Airport majorAirport in majorAirports.Distinct())
                    Airports.AddAirport(majorAirport);

            }

            airline.MarketFocus = startData.Focus;

            GeneralHelpers.CreateHolidays(GameObject.GetInstance().GameTime.Year);

            if (startData.IsPaused)
                GameObjectWorker.GetInstance().startPaused();
            else
                GameObjectWorker.GetInstance().start();

            GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Standard_News, GameObject.GetInstance().GameTime, Translator.GetInstance().GetString("News", "1001"), string.Format(Translator.GetInstance().GetString("News", "1001", "message"), GameObject.GetInstance().HumanAirline.Profile.CEO, GameObject.GetInstance().HumanAirline.Profile.IATACode)));

            Action action = () =>
            {
                Stopwatch swPax = new Stopwatch();
                swPax.Start();

                PassengerHelpers.CreateDestinationDemand();

                Console.WriteLine("Demand have been created in {0} ms.", swPax.ElapsedMilliseconds);
                swPax.Stop();
            };

            Task.Factory.StartNew(action);
            //Task.Run(action);
            //Task t2 = Task.Factory.StartNew(action, "passengers");
        }
        public static void CreateGame(StartDataObject startData)
        {
            if (startData.RealData)
            {
                List<Airline> notRealAirlines = Airlines.GetAirlines(a => !a.Profile.IsReal && a != startData.Airline);
                List<Manufacturer> notRealManufacturers = Manufacturers.GetManufacturers(m => !m.IsReal);
                List<AirlinerType> notRealAirliners =
                    AirlinerTypes.GetTypes(a => notRealManufacturers.Contains(a.Manufacturer));

                foreach (Airline notRealAirliner in notRealAirlines)
                {
                    Airlines.RemoveAirline(notRealAirliner);
                }

                foreach (AirlinerType airliner in notRealAirliners)
                {
                    AirlinerTypes.RemoveType(airliner);
                }
            }

            int startYear = startData.Year;
            int opponents = startData.NumberOfOpponents;
            Airline airline = startData.Airline;
            Continent continent = startData.Continent;
            Region region = startData.Region;

            GameTimeZone gtz = startData.TimeZone;
            GameObject.GetInstance().DayRoundEnabled = startData.UseDayTurns;
            GameObject.GetInstance().TimeZone = gtz;
            GameObject.GetInstance().Difficulty = startData.Difficulty;
            GameObject.GetInstance().GameTime = new DateTime(startYear, 1, 1);
            GameObject.GetInstance().StartDate = GameObject.GetInstance().GameTime;
            //sets the fuel price
            GameObject.GetInstance().FuelPrice =
                Inflations.GetInflation(GameObject.GetInstance().GameTime.Year).FuelPrice;

            airline.Profile.Country = startData.HomeCountry;
            airline.Profile.CEO = startData.CEO;

            GameObject.GetInstance().SetHumanAirline(airline);
            GameObject.GetInstance().MainAirline = GameObject.GetInstance().HumanAirline;

            if (startData.LocalCurrency)
            {
                GameObject.GetInstance().CurrencyCountry = airline.Profile.Country;
            }
            // AppSettings.GetInstance().resetCurrencyFormat();

            Airport airport = startData.Airport;

            AirportHelpers.RentGates(airport, airline, AirportContract.ContractType.Full,
                                     airline.AirlineRouteFocus == Route.RouteType.Cargo ? Terminal.TerminalType.Cargo : Terminal.TerminalType.Passenger, 2);

            AirportFacility checkinFacility =
                AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1);
            AirportFacility facility =
                AirportFacilities.GetFacilities(AirportFacility.FacilityType.Service)
                                 .Find((f => f.TypeLevel == 1));

            airport.AddAirportFacility(
                GameObject.GetInstance().HumanAirline,
                facility,
                GameObject.GetInstance().GameTime);
            airport.AddAirportFacility(
                GameObject.GetInstance().HumanAirline,
                checkinFacility,
                GameObject.GetInstance().GameTime);

            if (continent.Uid != "100" || region.Uid != "100")
            {
                List<Airline> airlines =
                    Airlines.GetAirlines(
                        a =>
                        a.Profile.Country.Region == region
                        || (region.Uid == "100" && continent.HasRegion(a.Profile.Country.Region))
                        && a.Profile.Founded <= startYear && a.Profile.Folded > startYear);
                List<Airport> airports =
                    Airports.GetAirports(
                        a =>
                        a.Profile.Country.Region == region
                        || (region.Uid == "100" && continent.HasRegion(a.Profile.Country.Region))
                        && a.Profile.Period.From.Year <= startYear && a.Profile.Period.To.Year > startYear);

                Airports.Clear();
                foreach (Airport a in airports)
                {
                    Airports.AddAirport(a);
                }

                Airlines.Clear();
                foreach (Airline a in airlines)
                {
                    Airlines.AddAirline(a);
                }
            }

            PassengerHelpers.CreateAirlineDestinationDemand();

            AirlinerHelpers.CreateStartUpAirliners();

            if (startData.RandomOpponents || startData.Opponents == null)
            {
                Setup.SetupMainGame(opponents, startData.SameRegion);
            }
            else
            {
                Setup.SetupMainGame(startData.Opponents, startData.NumberOfOpponents);
            }
            List<Airport> heliports = Airports.GetAirports(a => a.Runways.Exists(r => r.Type == Runway.RunwayType.Helipad));

            if (startData.InternationalAirports)
            {
                List<Airport> intlAirports = Airports.GetAllAirports(a => a.Profile.Type == AirportProfile.AirportType.LongHaulInternational
                                                                          || a.Profile.Type == AirportProfile.AirportType.ShortHaulInternational);

                const int minAirportsPerRegion = 5;
                foreach (Region airportRegion in Regions.GetRegions())
                {
                    IEnumerable<Airport> usedAirports = Airlines.GetAllAirlines().SelectMany(a => a.Airports);

                    int countRegionAirports = intlAirports.Count(a => a.Profile.Country.Region == airportRegion);
                    if (countRegionAirports < minAirportsPerRegion)
                    {
                        IEnumerable<Airport> regionAirports =
                            Airports.GetAirports(airportRegion)
                                    .Where(a => !intlAirports.Contains(a))
                                    .OrderByDescending(a => a.Profile.Size)
                                    .Take(minAirportsPerRegion - countRegionAirports);

                        intlAirports.AddRange(regionAirports);
                    }

                    if (startData.SelectedCountries != null)
                    {
                        foreach (Country country in startData.SelectedCountries)
                        {
                            Country country1 = country;
                            List<Airport> countryAirports =
                                Airports.GetAllAirports(
                                    a => (new CountryCurrentCountryConverter().Convert(a.Profile.Country) as Country) == country1 &&
                                         (a.Profile.Type == AirportProfile.AirportType.Regional || a.Profile.Type == AirportProfile.AirportType.Domestic));

                            foreach (Airport cairport in countryAirports)
                                if (!intlAirports.Contains(cairport))
                                    intlAirports.Add(cairport);
                        }
                    }

                    intlAirports.AddRange(usedAirports);
                    intlAirports.AddRange(heliports);

                    Airports.Clear();

                    foreach (Airport majorAirport in intlAirports.Distinct())
                    {
                        Airports.AddAirport(majorAirport);
                    }
                }
            }
            if (startData.MajorAirports)
            {
                List<Airport> majorAirports =
                    Airports.GetAllAirports(
                        a =>
                        a.Profile.Size == GeneralHelpers.Size.Largest || a.Profile.Size == GeneralHelpers.Size.Large
                        || a.Profile.Size == GeneralHelpers.Size.VeryLarge
                        || a.Profile.Size == GeneralHelpers.Size.Medium);
                IEnumerable<Airport> usedAirports = Airlines.GetAllAirlines().SelectMany(a => a.Airports);

                const int minAirportsPerRegion = 5;
                foreach (Region airportRegion in Regions.GetRegions())
                {
                    int countRegionAirports = majorAirports.Count(a => a.Profile.Country.Region == airportRegion);
                    if (countRegionAirports < minAirportsPerRegion)
                    {
                        IEnumerable<Airport> regionAirports =
                            Airports.GetAirports(airportRegion)
                                    .Where(a => !majorAirports.Contains(a))
                                    .OrderByDescending(a => a.Profile.Size)
                                    .Take(minAirportsPerRegion - countRegionAirports);

                        majorAirports.AddRange(regionAirports);
                    }
                }

                if (startData.SelectedCountries != null)
                {
                    foreach (Country country in startData.SelectedCountries)
                    {
                        Country country1 = country;
                        List<Airport> countryAirports =
                            Airports.GetAllAirports(
                                a => (new CountryCurrentCountryConverter().Convert(a.Profile.Country) as Country) == country1 &&
                                     (a.Profile.Size == GeneralHelpers.Size.Smallest || a.Profile.Size == GeneralHelpers.Size.VerySmall
                                      || a.Profile.Size == GeneralHelpers.Size.Smallest));

                        foreach (Airport cairport in countryAirports)
                            if (!majorAirports.Contains(cairport))
                                majorAirports.Add(cairport);
                    }
                }

                majorAirports.AddRange(usedAirports);
                majorAirports.AddRange(heliports);

                Airports.Clear();

                foreach (Airport majorAirport in majorAirports.Distinct())
                {
                    Airports.AddAirport(majorAirport);
                }
            }

            airline.MarketFocus = startData.Focus;

            GeneralHelpers.CreateHolidays(GameObject.GetInstance().GameTime.Year);

            if (startData.IsPaused)
            {
                GameObjectWorker.GetInstance().StartPaused();
            }
            else
            {
                GameObjectWorker.GetInstance().Start();
            }

            GameObject.GetInstance()
                      .NewsBox.AddNews(
                          new News(
                              News.NewsType.StandardNews,
                              GameObject.GetInstance().GameTime,
                              Translator.GetInstance().GetString("News", "1001"),
                              string.Format(
                                  Translator.GetInstance().GetString("News", "1001", "message"),
                                  GameObject.GetInstance().HumanAirline.Profile.CEO,
                                  GameObject.GetInstance().HumanAirline.Profile.IATACode)));

            Action action = () =>
                {
                    var swPax = new Stopwatch();
                    swPax.Start();

                    PassengerHelpers.CreateDestinationDemand();

                    Console.WriteLine(@"Demand have been created in {0} ms.", swPax.ElapsedMilliseconds);
                    swPax.Stop();
                };

            Task.Factory.StartNew(action);
            //Task.Run(action);
            //Task t2 = Task.Factory.StartNew(action, "passengers");
        }
        //creates a new game
        public static void CreateGame(StartDataObject startData)
        {
            int startYear = startData.Year;
            int opponents = startData.NumberOfOpponents;
            Airline airline = startData.Airline;
            Continent continent = startData.Continent;
            Region region = startData.Region;

            GameTimeZone gtz = startData.TimeZone;
            GameObject.GetInstance().DayRoundEnabled = startData.UseDayTurns;
            GameObject.GetInstance().TimeZone = gtz;
            GameObject.GetInstance().Difficulty = startData.Difficulty;
            GameObject.GetInstance().GameTime = new DateTime(startYear, 1, 1);
            GameObject.GetInstance().StartDate = GameObject.GetInstance().GameTime;
            //sets the fuel price
            GameObject.GetInstance().FuelPrice = Inflations.GetInflation(GameObject.GetInstance().GameTime.Year).FuelPrice;

            airline.Profile.Country = startData.HomeCountry;
            airline.Profile.CEO = startData.CEO;

            GameObject.GetInstance().HumanAirline = airline;
            GameObject.GetInstance().MainAirline = GameObject.GetInstance().HumanAirline;

            if (startData.LocalCurrency)
                GameObject.GetInstance().CurrencyCountry = airline.Profile.Country;
            // AppSettings.GetInstance().resetCurrencyFormat();

            Airport airport = startData.Airport;

            AirportHelpers.RentGates(airport, airline, 2);

            AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1);
            AirportFacility facility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.Service).Find((delegate(AirportFacility f) { return f.TypeLevel == 1; }));

            airport.addAirportFacility(GameObject.GetInstance().HumanAirline, facility, GameObject.GetInstance().GameTime);
            airport.addAirportFacility(GameObject.GetInstance().HumanAirline, checkinFacility, GameObject.GetInstance().GameTime);

            if (continent.Uid != "100" || region.Uid != "100")
            {
                var airlines = Airlines.GetAirlines(a => a.Profile.Country.Region == region || (region.Uid == "100" && continent.hasRegion(a.Profile.Country.Region)) && a.Profile.Founded <= startYear && a.Profile.Folded > startYear);
                var airports = Airports.GetAirports(a => a.Profile.Country.Region == region || (region.Uid == "100" && continent.hasRegion(a.Profile.Country.Region)) && a.Profile.Period.From.Year <= startYear && a.Profile.Period.To.Year > startYear);

                //Airports.RemoveAirports(a => (a.Profile.Country.Region != region && !continent.hasRegion(a.Profile.Country.Region)) || (a.Profile.Town.State != null && a.Profile.Town.State.IsOverseas));
                Airports.Clear();
                foreach (Airport a in airports)
                    Airports.AddAirport(a);

                Airlines.Clear();
                foreach (Airline a in airlines)
                    Airlines.AddAirline(a);
            }

            PassengerHelpers.CreateAirlineDestinationDemand();

            AirlinerHelpers.CreateStartUpAirliners();

            if (startData.RandomOpponents || startData.Opponents == null)
                Setup.SetupMainGame(opponents, startData.SameRegion);
            else
                Setup.SetupMainGame(startData.Opponents);

            airline.MarketFocus = startData.Focus;

            GeneralHelpers.CreateHolidays(GameObject.GetInstance().GameTime.Year);

            if (startData.IsPaused)
                GameObjectWorker.GetInstance().startPaused();
            else
                GameObjectWorker.GetInstance().start();

            GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Standard_News, GameObject.GetInstance().GameTime, Translator.GetInstance().GetString("News", "1001"), string.Format(Translator.GetInstance().GetString("News", "1001", "message"), GameObject.GetInstance().HumanAirline.Profile.CEO, GameObject.GetInstance().HumanAirline.Profile.IATACode)));

            Action action = () =>
            {
                Stopwatch swPax = new Stopwatch();
                swPax.Start();

                PassengerHelpers.CreateDestinationDemand();

                Console.WriteLine("Demand have been created in {0} ms.", swPax.ElapsedMilliseconds);
                swPax.Stop();
            };

            Task.Factory.StartNew(action);
            //Task.Run(action);
            //Task t2 = Task.Factory.StartNew(action, "passengers");
        }