//checks the list of warnings
        private void checkWarnings()
        {
            var warnings = Warnings.GetWarnings();

            GameObjectWorker.GetInstance().pause();

            foreach (KeyValuePair <string, string> warning in warnings)
            {
                WPFMessageBox.Show(warning.Key, warning.Value, WPFMessageBoxButtons.Ok);
            }

            GameObjectWorker.GetInstance().restart();

            Warnings.Clear();
        }
        private void btnSaveGame_Click(object sender, RoutedEventArgs e)
        {
            Boolean gameworkerPaused = GameObjectWorker.GetInstance().isPaused();

            GameObjectWorker.GetInstance().cancel();

            string name = txtName.Text.Trim();

            Boolean doSave = true;


            if (SerializedLoadSaveHelpers.SaveGameExists(name))
            {
                WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "1007"), Translator.GetInstance().GetString("MessageBox", "1007", "message"), WPFMessageBoxButtons.YesNo);

                doSave = result == WPFMessageBoxResult.Yes;

                if (doSave)
                {
                    SerializedLoadSaveHelpers.DeleteSavedGame(name);
                }
            }

            if (doSave)
            {
                SplashControl scSaving = UIHelpers.FindChild <SplashControl>(this, "scSaving");

                scSaving.Visibility = System.Windows.Visibility.Visible;

                BackgroundWorker bgWorker = new BackgroundWorker();
                bgWorker.DoWork += (s, x) =>
                {
                    GameObject.GetInstance().Name = name;

                    SerializedLoadSaveHelpers.SaveGame(name);
                };
                bgWorker.RunWorkerCompleted += (s, x) =>
                {
                    if (!gameworkerPaused)
                    {
                        GameObjectWorker.GetInstance().start();
                    }

                    scSaving.Visibility = System.Windows.Visibility.Collapsed;
                };
                bgWorker.RunWorkerAsync();
            }
        }
        private void PageBottomMenu_OnTimeChanged()
        {
            if (this.IsLoaded)
            {
                if (GameObject.GetInstance().DayRoundEnabled)
                {
                    txtTime.Text = GameObject.GetInstance().GameTime.ToLongDateString() + " " + GameObject.GetInstance().TimeZone.ShortDisplayName;
                }
                else
                {
                    txtTime.Text = GameObject.GetInstance().GameTime.ToLongDateString() + " " + GameObject.GetInstance().GameTime.ToShortTimeString() + " " + GameObject.GetInstance().TimeZone.ShortDisplayName;//GameObject.GetInstance().GameTime.ToString("dddd MMMM dd, yyyy HH:mm", CultureInfo.CreateSpecificCulture("en-US")) + " " + GameObject.GetInstance().TimeZone.ShortDisplayName;
                }
                // txtMoney.Text = string.Format("{0:c}", GameObject.GetInstance().HumanAirline.Money);
                txtMoney.Text       = new ValueCurrencyConverter().Convert(GameObject.GetInstance().HumanAirline.Money).ToString();
                txtMoney.Foreground = new Converters.ValueIsMinusConverter().Convert(GameObject.GetInstance().HumanAirline.Money, null, null, null) as Brush;

                if (GameObject.GetInstance().Scenario != null && (GameObject.GetInstance().Scenario.ScenarioFailed != null || GameObject.GetInstance().Scenario.IsSuccess))
                {
                    GameObjectWorker.GetInstance().cancel();

                    WPFMessageBoxResult result;
                    if (GameObject.GetInstance().Scenario.ScenarioFailed != null)
                    {
                        result = WPFMessageBox.Show(Translator.GetInstance().GetString("PageBottomMenu", "1001"), GameObject.GetInstance().Scenario.ScenarioFailed.FailureText, WPFMessageBoxButtons.ContinueExit);
                    }
                    else
                    {
                        result = WPFMessageBox.Show(Translator.GetInstance().GetString("PageBottomMenu", "1002"), Translator.GetInstance().GetString("PageBottomMenu", "1003"), WPFMessageBoxButtons.ContinueExit);
                    }

                    if (result == WPFMessageBoxResult.Continue)
                    {
                        GameObjectWorker.GetInstance().start();

                        GameObject.GetInstance().Scenario = null;
                    }
                    else
                    {
                        Setup.SetupGame();
                        PageNavigator.NavigateTo(new PageNewGame());
                        GameObject.RestartInstance();
                    }
                }
            }
        }
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "1003"), Translator.GetInstance().GetString("MessageBox", "1003", "message"), WPFMessageBoxButtons.YesNo);

                if (result == WPFMessageBoxResult.Yes)
                {
                    this.Close();
                }
            }
            if (e.Key == Key.F8)
            {
                string text = string.Format("Gameobjectworker paused: {0}\n", GameObjectWorker.GetInstance().isPaused());
                text += string.Format("Gameobjectworker finished: {0}\n", GameObjectWorker.GetInstance().IsFinish);
                text += string.Format("Gameobjectworker errored: {0}\n", GameObjectWorker.GetInstance().IsError);

                Console.WriteLine(text);

                WPFMessageBox.Show("Threads states", text, WPFMessageBoxButtons.Ok);
            }
            if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.F12)
            {
                System.IO.StreamWriter file = new System.IO.StreamWriter(AppSettings.getCommonApplicationDataPath() + "\\theairline.log");

                if (Airports.Count() >= 5)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        Airport airport = Airports.GetAllAirports()[i];

                        file.WriteLine("Airport demand for {0} of size {1}", airport.Profile.Name, airport.Profile.Size);

                        foreach (Airport demand in airport.getDestinationDemands())
                        {
                            file.WriteLine("    Demand to {0} ({2}) is {1}", demand.Profile.Name, airport.getDestinationPassengersRate(demand, AirlinerClass.ClassType.Economy_Class), demand.Profile.Size);
                        }
                    }
                }

                WPFMessageBox.Show("Demand has been dumped", "The demand has been dumped to the log file", WPFMessageBoxButtons.Ok);

                file.Close();
            }
        }
Exemple #5
0
        private void btnLoadGame_Click(object sender, RoutedEventArgs e)
        {
            GameObjectWorker.GetInstance().cancel();

            while (GameObjectWorker.GetInstance().isBusy())
            {
            }

            string file = (string)lbSaves.SelectedItem;

            WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "1002"), Translator.GetInstance().GetString("MessageBox", "1002", "message"), WPFMessageBoxButtons.YesNo);

            if (result == WPFMessageBoxResult.Yes)
            {
                if (file != null)
                {
                    SplashControl scLoading = UIHelpers.FindChild <SplashControl>(this, "scLoading");

                    scLoading.Visibility = System.Windows.Visibility.Visible;

                    BackgroundWorker bgWorker = new BackgroundWorker();
                    bgWorker.DoWork += (s, x) =>
                    {
                        SerializedLoadSaveHelpers.LoadGame(file);
                    };
                    bgWorker.RunWorkerCompleted += (s, x) =>
                    {
                        scLoading.Visibility = System.Windows.Visibility.Collapsed;

                        HolidayYear.Clear();

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

                        Setup.SetupMergers();

                        GameObjectWorker.GetInstance().pause();

                        PageNavigator.NavigateTo(new PageAirline(GameObject.GetInstance().HumanAirline));
                    };
                    bgWorker.RunWorkerAsync();
                }
            }
        }
Exemple #6
0
        private void btnNewGame_Click(object sender, RoutedEventArgs e)
        {
            GameObjectWorker.GetInstance().cancel();

            WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "1001"), Translator.GetInstance().GetString("MessageBox", "1001", "message"), WPFMessageBoxButtons.YesNo);

            if (result == WPFMessageBoxResult.Yes)
            {
                GameObjectWorker.GetInstance().cancel();

                while (GameObjectWorker.GetInstance().isBusy())
                {
                }
                PageNavigator.NavigateTo(new PageNewGame());
                GameObject.RestartInstance();

                Setup.SetupGame();
            }
        }
        private void lnkLoadGame_Click(object sender, RoutedEventArgs e)
        {
            Popup popUpSplash = new Popup();

            popUpSplash.Child           = createSplashWindow("Loading.....");
            popUpSplash.Placement       = PlacementMode.Center;
            popUpSplash.PlacementTarget = PageNavigator.MainWindow;
            popUpSplash.IsOpen          = false;

            GameObjectWorker.GetInstance().cancel();

            while (GameObjectWorker.GetInstance().isBusy())
            {
            }


            WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "1002"), Translator.GetInstance().GetString("MessageBox", "1002", "message"), WPFMessageBoxButtons.YesNo);

            if (result == WPFMessageBoxResult.Yes)
            {
                String file = (String)PopUpLoad.ShowPopUp();

                if (file != null)
                {
                    popUpSplash.IsOpen = true;
                    DoEvents();

                    LoadSaveHelpers.LoadGame(file);

                    PageNavigator.NavigateTo(new PageAirline(GameObject.GetInstance().HumanAirline));

                    HolidayYear.Clear();

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

                    Setup.SetupMergers();

                    popUpSplash.IsOpen = false;
                }
            }

            GameObjectWorker.GetInstance().start();
        }
Exemple #8
0
        private void btnLoadGame_Click(object sender, RoutedEventArgs e)
        {
            String file = (String)PopUpLoad.ShowPopUp();

            if (file != null)
            {
                Setup.SetupGame();

                //LoadSaveHelpers.LoadGame(file);
                SerializedLoadSaveHelpers.LoadGame(file);

                HolidayYear.Clear();

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


                GameObjectWorker.GetInstance().start();

                PageNavigator.NavigateTo(new PageAirline(GameObject.GetInstance().HumanAirline));

                Action action = () =>
                {
                    PassengerHelpers.CreateDestinationDemand();

                    var airports = Airports.GetAllAirports();
                    int count    = airports.Count;

                    //var airports = Airports.GetAirports(a => a != airport && a.Profile.Town != airport.Profile.Town && MathHelpers.GetDistance(a.Profile.Coordinates, airport.Profile.Coordinates) > 50);

                    Parallel.For(0, count - 1, i =>
                    {
                        Parallel.For(i + 1, count, j =>
                        {
                            airports[j].Statics.addDistance(airports[i], MathHelpers.GetDistance(airports[j], airports[i]));
                        });
                    });
                };

                Task.Factory.StartNew(action);
            }
        }
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "1003"), Translator.GetInstance().GetString("MessageBox", "1003", "message"), WPFMessageBoxButtons.YesNo);

                if (result == WPFMessageBoxResult.Yes)
                {
                    this.Close();
                }
            }
            if (e.Key == Key.F8)
            {
                string text = string.Format("Gameobjectworker paused: {0}\n", GameObjectWorker.GetInstance().isPaused());
                text += string.Format("Gameobjectworker finished: {0}\n", GameObjectWorker.GetInstance().IsFinish);
                text += string.Format("Gameobjectworker errored: {0}\n", GameObjectWorker.GetInstance().IsError);

                Console.WriteLine(text);

                WPFMessageBox.Show("Threads states", text, WPFMessageBoxButtons.Ok);
            }
        }
Exemple #10
0
        //loads a game
        public static void LoadGame(string file)
        {
            string fileName = AppSettings.getCommonApplicationDataPath() + "\\saves\\" + file + ".sav";

            SaveObject deserializedSaveObject = FileSerializer.Deserialize <SaveObject>(fileName);

            /*
             *
             * DataContractSerializer serializer = new DataContractSerializer(typeof(SaveObject));
             * SaveObject deserializedSaveObject;
             * string loading;
             * int version;
             *
             * using (FileStream stream = new FileStream(fileName, FileMode.Open))
             * {
             * using (DeflateStream decompress = new DeflateStream(stream, CompressionMode.Decompress))
             * {
             *     deserializedSaveObject = (SaveObject)serializer.ReadObject(decompress);
             * }
             * }
             *
             * loading = deserializedSaveObject.savetype;
             * version = deserializedSaveObject.saveversionnumber;
             */
            //Parrarel for loading the game
            Parallel.Invoke(() =>
            {
                Airlines.Clear();

                foreach (Airline airline in deserializedSaveObject.airlinesList)
                {
                    Airlines.AddAirline(airline);
                }
            },
                            () =>
            {
                Setup.LoadAirports();

                var airports = Airports.GetAllAirports();

                Airports.Clear();

                foreach (Airport airport in deserializedSaveObject.airportsList)
                {
                    airport.Statics = new AirportStatics(airport);
                    Airports.AddAirport(airport);
                }

                foreach (string iata in deserializedSaveObject.airportsfromstringList)
                {
                    Airport airport = airports.FirstOrDefault(a => a.Profile.IATACode == iata);

                    if (airport != null)
                    {
                        Airports.AddAirport(airport);
                    }
                }
            },
                            () =>
            {
                Airliners.Clear();

                foreach (Airliner airliner in deserializedSaveObject.airlinersList)
                {
                    Airliners.AddAirliner(airliner);
                }
            },
                            () =>
            {
                CalendarItems.Clear();

                foreach (CalendarItem item in deserializedSaveObject.calendaritemsList)
                {
                    CalendarItems.AddCalendarItem(item);
                }
            },
                            () =>
            {
                Configurations.Clear();

                foreach (Configuration configuration in deserializedSaveObject.configurationList)
                {
                    Configurations.AddConfiguration(configuration);
                }
            },
                            () =>
            {
                RandomEvents.Clear();

                foreach (RandomEvent e in deserializedSaveObject.eventsList)
                {
                    RandomEvents.AddEvent(e);
                }
            },
                            () =>
            {
                Alliances.Clear();

                foreach (Alliance alliance in deserializedSaveObject.allianceList)
                {
                    Alliances.AddAlliance(alliance);
                }
            },
                            () =>
            {
                AirportFacilities.Clear();

                foreach (AirportFacility facility in deserializedSaveObject.Airportfacilitieslist)
                {
                    AirportFacilities.AddFacility(facility);
                }
            },
                            () =>
            {
                FeeTypes.Clear();

                foreach (FeeType type in deserializedSaveObject.feeTypeslist)
                {
                    FeeTypes.AddType(type);
                }
            },
                            () =>
            {
                AdvertisementTypes.Clear();

                foreach (AdvertisementType addtype in deserializedSaveObject.advertisementTypeslist)
                {
                    AdvertisementTypes.AddAdvertisementType(addtype);
                }
            },
                            () =>
            {
                AirlinerFacilities.Clear();

                foreach (AirlinerFacility airlinerfas in deserializedSaveObject.airlinerfacilitieslist)
                {
                    AirlinerFacilities.AddFacility(airlinerfas);
                }
            },
                            () =>
            {
                RouteFacilities.Clear();

                foreach (RouteFacility routefas in deserializedSaveObject.routefacilitieslist)
                {
                    RouteFacilities.AddFacility(routefas);
                }
            },
                            () =>
            {
                GameObject.SetInstance(deserializedSaveObject.instance);
                Settings.SetInstance(deserializedSaveObject.settings);
            },
                            () =>
            {
                if (deserializedSaveObject.airlinefacilitieslist != null)
                {
                    AirlineFacilities.Clear();

                    foreach (AirlineFacility airlinefac in deserializedSaveObject.airlinefacilitieslist)
                    {
                        AirlineFacilities.AddFacility(airlinefac);
                    }
                }
            }); //close parallel.invoke

            //for 0.3.9.2 and the issue with no saved facilities on a route classes
            var emptyRouteClassesFacilities = Configurations.GetConfigurations(Configuration.ConfigurationType.Routeclasses).SelectMany(c => ((RouteClassesConfiguration)c).Classes.Where(cl => cl.Facilities == null));

            foreach (RouteClassConfiguration rClassConfiguration in emptyRouteClassesFacilities)
            {
                rClassConfiguration.Facilities = new List <RouteFacility>();
            }

            Setup.SetupLoadedGame();
            //Maybe this helps? But i doubt this is the best way
            Action action = () =>
            {
                Stopwatch swPax = new Stopwatch();
                swPax.Start();

                PassengerHelpers.CreateDestinationDemand();

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

            //create some pilots for the game
            int pilotsPool = 100 * Airlines.GetAllAirlines().Count;

            GeneralHelpers.CreatePilots(pilotsPool);
            int instructorsPool = 75 * Airlines.GetAllAirlines().Count;

            GeneralHelpers.CreateInstructors(instructorsPool);

            //creates some airliners for the game
            AirlinerHelpers.CreateStartUpAirliners();

            //Start the game paused
            GameObjectWorker.GetInstance().startPaused();

            //Task is needed this unlocks the game agian.
            Task.Factory.StartNew(action);
        }
Exemple #11
0
 private void btnStart_Click(object sender, RoutedEventArgs e)
 {
     GameObjectWorker.GetInstance().restart();
 }
Exemple #12
0
 private void btnPause_Click(object sender, RoutedEventArgs e)
 {
     GameObjectWorker.GetInstance().pause();
 }
 private void btnPause_Click(object sender, RoutedEventArgs e)
 {
     this.btnStart.Visibility = System.Windows.Visibility.Visible;
     this.btnPause.Visibility = System.Windows.Visibility.Collapsed;
     GameObjectWorker.GetInstance().pause();
 }
        //loads a game
        public static void LoadGame(string file)
        {
            string fileName = AppSettings.getCommonApplicationDataPath() + "\\saves\\" + file + ".sav";

            DataContractSerializer serializer = new DataContractSerializer(typeof(SaveObject));
            SaveObject             deserializedSaveObject;

            using (FileStream stream = new FileStream(fileName, FileMode.Open))
            {
                using (DeflateStream decompress = new DeflateStream(stream, CompressionMode.Decompress))
                {
                    deserializedSaveObject =
                        (SaveObject)serializer.ReadObject(decompress);
                }
            }

            //Parrarel for loading the game
            Parallel.Invoke(() =>
            {
                Airlines.Clear();

                foreach (Airline airline in deserializedSaveObject.airlinesList)
                {
                    Airlines.AddAirline(airline);
                }
            },
                            () =>
            {
                Airports.Clear();

                foreach (Airport airport in deserializedSaveObject.airportsList)
                {
                    airport.Statics = new AirportStatics(airport);
                    Airports.AddAirport(airport);
                }
            },
                            () =>
            {
                Airliners.Clear();

                foreach (Airliner airliner in deserializedSaveObject.airlinersList)
                {
                    Airliners.AddAirliner(airliner);
                }
            },
                            () =>
            {
                CalendarItems.Clear();

                foreach (CalendarItem item in deserializedSaveObject.calendaritemsList)
                {
                    CalendarItems.AddCalendarItem(item);
                }

                Configurations.Clear();

                foreach (Configuration configuration in deserializedSaveObject.configurationList)
                {
                    Configurations.AddConfiguration(configuration);
                }
            },
                            () =>
            {
                RandomEvents.Clear();

                foreach (RandomEvent e in deserializedSaveObject.eventsList)
                {
                    RandomEvents.AddEvent(e);
                }
            },
                            () =>
            {
                Alliances.Clear();

                foreach (Alliance alliance in deserializedSaveObject.allianceList)
                {
                    Alliances.AddAlliance(alliance);
                }
            },
                            () =>
            {
                AirportFacilities.Clear();

                foreach (AirportFacility facility in deserializedSaveObject.Airportfacilitieslist)
                {
                    AirportFacilities.AddFacility(facility);
                }
            },
                            () =>
            {
                GameObject.SetInstance(deserializedSaveObject.instance);
            });  //close parallel.invoke

            //Maybe this helps? But i doubt this is the best way
            Action action = () =>
            {
                Stopwatch swPax = new Stopwatch();
                swPax.Start();

                PassengerHelpers.CreateDestinationDemand();

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

            //Create some pilots for the game
            int pilotsPool = 100 * Airlines.GetAllAirlines().Count;

            GeneralHelpers.CreatePilots(pilotsPool);
            int instructorsPool = 75 * Airlines.GetAllAirlines().Count;

            GeneralHelpers.CreateInstructors(instructorsPool);

            //Start the game paused
            GameObjectWorker.GetInstance().startPaused();

            //Task is needed this unlocks the game agian.
            Task.Factory.StartNew(action);
        }
Exemple #15
0
        //creates a new game
        private void createNewGame()
        {
            if (txtName.Text.Trim().Length > 2)
            {
                object    o         = null;
                int       startYear = (int)cbStartYear.SelectedItem;
                int       opponents = (int)cbOpponents.SelectedItem;
                Airline   airline   = (Airline)cbAirline.SelectedItem;
                Continent continent = (Continent)cbContinent.SelectedItem;
                Region    region    = (Region)cbRegion.SelectedItem;


                if (this.OpponentType == OpponentSelect.User)
                {
                    if (cbSameRegion.IsChecked.Value)
                    {
                        o = PopUpSelectOpponents.ShowPopUp(airline, opponents, startYear, airline.Profile.Country.Region);
                    }
                    else
                    {
                        o = PopUpSelectOpponents.ShowPopUp(airline, opponents, startYear, region, continent);
                    }
                }



                // popUpSplash.IsOpen = true;

                DoEvents();

                GameTimeZone gtz = (GameTimeZone)cbTimeZone.SelectedItem;
                GameObject.GetInstance().DayRoundEnabled = cbDayTurnEnabled.IsChecked.Value;
                GameObject.GetInstance().TimeZone        = gtz;
                GameObject.GetInstance().Difficulty      = (DifficultyLevel)cbDifficulty.SelectedItem;
                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 = (Country)cbCountry.SelectedItem;
                airline.Profile.CEO     = txtName.Text.Trim();

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

                if (cbLocalCurrency.IsChecked.Value)
                {
                    GameObject.GetInstance().CurrencyCountry = airline.Profile.Country;
                }
                // AppSettings.GetInstance().resetCurrencyFormat();

                Airport airport = (Airport)cbAirport.SelectedItem;

                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 (this.OpponentType == OpponentSelect.Random || o == null)
                {
                    Setup.SetupMainGame(opponents, cbSameRegion.IsChecked.Value);
                }
                else
                {
                    Setup.SetupMainGame((List <Airline>)o);
                }


                airline.MarketFocus = (Airline.AirlineFocus)cbFocus.SelectedItem;

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

                //PassengerHelpers.CreateDestinationPassengers();

                GameObjectWorker.GetInstance().start();
                // AIWorker.GetInstance().start();

                PageNavigator.NavigateTo(new PageAirline(GameObject.GetInstance().HumanAirline));

                PageNavigator.ClearNavigator();

                //GameObject.GetInstance().HumanAirline.Money = 10000000000000;

                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)));

                popUpSplash.IsOpen = false;



                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");
            }
            else
            {
                WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2403"), Translator.GetInstance().GetString("MessageBox", "2403"), WPFMessageBoxButtons.Ok);
            }
        }
        //saves a game
        public static void SaveGame(string name)
        {
            //Pause the game so we can save without the clock running :)
            GameObjectWorker.GetInstance().pause();

            string fileName = AppSettings.getCommonApplicationDataPath() + "\\saves\\" + name + ".sav";

            Stopwatch sw = new Stopwatch();

            sw.Start();

            SaveObject so = new SaveObject();

            Parallel.Invoke(() =>
            {
                so.airportsList = new List <Airport>();
                so.airportsList.AddRange(Airports.GetAllAirports());
            }, () =>
            {
                so.airlinesList = new List <Airline>();
                so.airlinesList.AddRange(Airlines.GetAllAirlines());
            }, () =>
            {
                so.airlinersList = new List <Airliner>();
                so.airlinersList.AddRange(Airliners.GetAllAirliners());
            }, () =>
            {
                so.calendaritemsList = new List <CalendarItem>();
                so.calendaritemsList.AddRange(CalendarItems.GetCalendarItems());
            }, () =>
            {
                so.configurationList = new List <Configuration>();
                so.configurationList.AddRange(Configurations.GetConfigurations());
            }, () =>
            {
                so.eventsList = new List <RandomEvent>();
                so.eventsList.AddRange(RandomEvents.GetEvents());
            }, () =>
            {
                so.allianceList = new List <Alliance>();
                so.allianceList.AddRange(Alliances.GetAlliances());
            }, () =>
            {
                so.Airportfacilitieslist = new List <AirportFacility>();
                so.Airportfacilitieslist.AddRange(AirportFacilities.GetFacilities());
            }, () =>
            {
                so.instance = GameObject.GetInstance();
            });


            DataContractSerializer serializer = new DataContractSerializer(typeof(SaveObject), null,
                                                                           Int32.MaxValue,
                                                                           false,
                                                                           true,
                                                                           null);

            using (Stream stream = new FileStream(fileName, FileMode.Create))
            {
                using (DeflateStream compress = new DeflateStream(stream, CompressionMode.Compress))
                {
                    serializer.WriteObject(compress, so);
                }
            }

            sw.Stop();
        }
        //sets up a scenario
        public static void SetupScenario(Scenario scenario)
        {
            Airline airline = scenario.Airline;

            GameObject.GetInstance().DayRoundEnabled = true;
            GameObject.GetInstance().TimeZone        = scenario.Homebase.Profile.TimeZone;
            GameObject.GetInstance().Difficulty      = scenario.Difficulty;
            GameObject.GetInstance().GameTime        = new DateTime(scenario.StartYear, 1, 1);
            GameObject.GetInstance().StartDate       = GameObject.GetInstance().GameTime;
            //sets the fuel price
            GameObject.GetInstance().FuelPrice = Inflations.GetInflation(GameObject.GetInstance().GameTime.Year).FuelPrice;

            GameObject.GetInstance().setHumanAirline(airline);
            GameObject.GetInstance().MainAirline = GameObject.GetInstance().HumanAirline;
            GameObject.GetInstance().HumanAirline.Money = scenario.StartCash;

            GameObject.GetInstance().Scenario = new ScenarioObject(scenario);

            Airport airport = scenario.Homebase;

            SetupScenarioAirport(airline, airport);


            // PassengerHelpers.CreateDestinationPassengers();

            AirlinerHelpers.CreateStartUpAirliners();

            int pilotsPool = 100 * Airlines.GetAllAirlines().Count;

            GeneralHelpers.CreatePilots(pilotsPool);

            int instructorsPool = 75 * Airlines.GetAllAirlines().Count;

            GeneralHelpers.CreateInstructors(instructorsPool);

            SetupScenarioAirlines(scenario);
            SetupScenario();
            Setup.SetupAlliances();

            PassengerHelpers.CreateAirlineDestinationDemand();

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

            PageNavigator.NavigateTo(new PageAirline(GameObject.GetInstance().HumanAirline));

            PageNavigator.ClearNavigator();

            // GameObject.GetInstance().HumanAirline.Money = 1000000000;

            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 <object> action = (object obj) =>
            {
                PassengerHelpers.CreateDestinationDemand();

                SetupScenarioPassengerDemand(scenario);
            };


            Task t2 = Task.Factory.StartNew(action, "passengers");
        }
        private void btnThreadState_Click(object sender, RoutedEventArgs e)
        {
            string text = string.Format("Gameobjectworker paused: {0}\n", GameObjectWorker.GetInstance().isPaused());

            WPFMessageBox.Show("Threads states", text, WPFMessageBoxButtons.Ok);
        }
        private void lnkSaveGame_Click(object sender, RoutedEventArgs e)
        {
            Boolean gameworkerPaused = GameObjectWorker.GetInstance().isPaused();

            GameObjectWorker.GetInstance().cancel();

            Popup popUpSplash = new Popup();

            popUpSplash.Child           = createSplashWindow("Saving......");
            popUpSplash.Placement       = PlacementMode.Center;
            popUpSplash.PlacementTarget = PageNavigator.MainWindow;
            popUpSplash.IsOpen          = false;


            String name = (String)PopUpSave.ShowPopUp();

            Boolean doSave = name != null;

            if (doSave)
            {
                if (SerializedLoadSaveHelpers.SaveGameExists(name))
                {
                    WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "1007"), Translator.GetInstance().GetString("MessageBox", "1007", "message"), WPFMessageBoxButtons.YesNo);

                    doSave = result == WPFMessageBoxResult.Yes;
                }
                if (doSave)
                {
                    popUpSplash.IsOpen = true;
                    DoEvents();

                    GameObject.GetInstance().Name = name;

                    /*
                     * string fileName;
                     *
                     * var saves = LoadSaveHelpers.GetSavedGames();
                     *
                     *
                     * KeyValuePair<string,string>? f = LoadSaveHelpers.GetSavedGames().Find(fs=>fs.Key == name);
                     *
                     * if (!f.HasValue || f.Value.Key == null)
                     * {
                     *  Guid file = Guid.NewGuid();
                     *
                     *  fileName = file.ToString();
                     *
                     *  LoadSaveHelpers.AppendSavedFile(name, fileName);
                     *
                     * }
                     * else
                     * {
                     *  fileName = f.Value.Value;
                     * }
                     */
                    //LoadSaveHelpers.SaveGame(fileName);
                    SerializedLoadSaveHelpers.SaveGame(name);

                    popUpSplash.IsOpen = false;
                }
            }


            if (!gameworkerPaused)
            {
                GameObjectWorker.GetInstance().start();
            }
        }