//creates the airline private void createAirline() { Airline tAirline = Airlines.GetAirline(txtIATA.Text.Trim().ToUpper()); if (tAirline != null) { Airlines.RemoveAirline(tAirline); } string name = txtAirlineName.Text.Trim(); string iata = txtIATA.Text.Trim().ToUpper(); Country country = (Country)cbCountry.SelectedItem; string color = ((PropertyInfo)cbColor.SelectedItem).Name; AirlineProfile profile = new AirlineProfile(name, iata, color, "Unknown", false, 1950, 2199); profile.Countries = new List <Country>() { country }; profile.Country = country; profile.addLogo(new AirlineLogo(logoPath)); Airline airline = new Airline(profile, Airline.AirlineMentality.Aggressive, Airline.AirlineFocus.Local, Airline.AirlineLicense.Domestic, airlinerType); Airlines.AddAirline(airline); PageNavigator.NavigateTo(new PageNewGame()); }
private void createAirline() { string name = txtName.Text.Trim(); string iata = txtIATA.Text.Trim().ToUpper(); string ceo = txtCEO.Text.Trim(); Airline tAirline = Airlines.GetAirline(iata); if (tAirline != null) { Airlines.RemoveAirline(tAirline); } Country country = (Country)cbCountry.SelectedItem; string color = ((PropertyInfo)cbColor.SelectedItem).Name; AirlineProfile profile = new AirlineProfile(name, iata, color, ceo, false, 1950, 2199); profile.Countries = new List <Country>() { country }; profile.Country = country; profile.addLogo(new AirlineLogo(logoPath)); profile.PreferedAirport = cbAirport.SelectedItem != null ? (Airport)cbAirport.SelectedItem : null; Route.RouteType focus = rbPassengerType.IsChecked.Value ? Route.RouteType.Passenger : Route.RouteType.Cargo; Airline airline = new Airline(profile, Airline.AirlineMentality.Aggressive, Airline.AirlineFocus.Local, Airline.AirlineLicense.Domestic, focus); Airlines.AddAirline(airline); WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2405"), Translator.GetInstance().GetString("MessageBox", "2405", "message"), WPFMessageBoxButtons.Ok); }
private void btnBuyAsSubsidiary_Click(object sender, RoutedEventArgs e) { AirlinesMVVM airline = this.SelectedAirline; double buyingPrice = airline.Airline.getValue() * 100000 * 1.10; WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2113"), string.Format(Translator.GetInstance().GetString("MessageBox", "2113", "message"), airline.Airline.Profile.Name, buyingPrice), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { List <AirlineLogo> oldLogos = airline.Airline.Profile.Logos; string oldColor = airline.Airline.Profile.Color; //creates independent airlines for each subsidiary while (airline.Airline.Subsidiaries.Count > 0) { SubsidiaryAirline subAirline = airline.Airline.Subsidiaries[0]; subAirline.Airline = null; airline.Airline.removeSubsidiaryAirline(subAirline); } if (airline.Airline.License > GameObject.GetInstance().HumanAirline.License) { GameObject.GetInstance().HumanAirline.License = airline.Airline.License; } SubsidiaryAirline sAirline = new SubsidiaryAirline(GameObject.GetInstance().HumanAirline, airline.Airline.Profile, airline.Airline.Mentality, airline.Airline.MarketFocus, airline.Airline.License, airline.Airline.AirlineRouteFocus); AirlineHelpers.SwitchAirline(airline.Airline, sAirline); GameObject.GetInstance().HumanAirline.addSubsidiaryAirline(sAirline); AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Airline_Expenses, -buyingPrice); Airlines.RemoveAirline(airline.Airline); Airlines.AddAirline(sAirline); sAirline.Profile.Logos = oldLogos; sAirline.Profile.Color = oldColor; foreach (AirlinePolicy policy in airline.Airline.Policies) { sAirline.addAirlinePolicy(policy); } sAirline.Money = airline.Airline.Money; sAirline.StartMoney = airline.Airline.Money; sAirline.Fees = new AirlineFees(); PageNavigator.NavigateTo(new PageAirline(GameObject.GetInstance().HumanAirline)); } }
private void btnLoadAirline_Click(object sender, RoutedEventArgs e) { string directory = AppSettings.getCommonApplicationDataPath() + "\\custom airlines"; Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".xml"; dlg.Filter = "Airline XMLs (.xml)|*.xml"; dlg.InitialDirectory = System.IO.Path.GetFullPath(directory); dlg.Multiselect = false; Nullable <bool> result = dlg.ShowDialog(); if (result == true) { string path = dlg.FileName; Airline airline = Setup.LoadAirline(path); string imagePath = string.Format("{0}\\{1}.png", directory, airline.Profile.IATACode); if (File.Exists(imagePath)) { airline.Profile.addLogo(new AirlineLogo(imagePath)); } else { airline.Profile.addLogo(new AirlineLogo(AppSettings.getDataPath() + "\\graphics\\airlinelogos\\default.png")); } if (Airlines.GetAirline(airline.Profile.IATACode) != null) { Airlines.RemoveAirlines(a => a.Profile.IATACode == airline.Profile.IATACode); } Airlines.AddAirline(airline); var airlines = Airlines.GetAirlines(a => (a.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(a.Profile.Country.Region))) && a.Profile.Founded <= this.StartData.Year && a.Profile.Folded > this.StartData.Year).OrderBy(a => a.Profile.Name).ToList(); cbAirline.ItemsSource = airlines; WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2409"), Translator.GetInstance().GetString("MessageBox", "2409", "message"), WPFMessageBoxButtons.Ok); if (cbAirline.Items.Contains(airline)) { cbAirline.SelectedItem = airline; } } }
//sets up the airlines for a scenario private static void SetupScenarioAirlines(Scenario scenario) { List <Airline> airlines = new List <Airline>(); airlines.Add(scenario.Airline); foreach (ScenarioAirline airline in scenario.OpponentAirlines) { airlines.Add(airline.Airline); SetupOpponentAirline(airline); } Airlines.Clear(); airlines.ForEach(a => Airlines.AddAirline(a)); SetupHumanAirline(scenario); }
//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); } }
//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); }
//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); }