//returns all unassigned pilots public static List <Pilot> GetUnassignedPilots() { var unassigned = pilots.FindAll(p => p.Airline == null); if (unassigned.Count < 5) { GeneralHelpers.CreatePilots(10); return(GetUnassignedPilots()); } return(unassigned); }
//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 hlAirliner_Click(object sender, RoutedEventArgs e) { FleetAirlinerMVVM airliner = (FleetAirlinerMVVM)((Hyperlink)sender).Tag; TabControl tab_main = UIHelpers.FindChild <TabControl>(this.Tag as Page, "tabMenu"); Frame frmContent = UIHelpers.FindChild <Frame>(this.Tag as Page, "frmContent"); if (airliner.Airliner.NumberOfPilots == airliner.Airliner.Airliner.Type.CockpitCrew) { if (tab_main != null) { var matchingItem = tab_main.Items.Cast <TabItem>() .Where(item => item.Tag.ToString() == "Airliner") .FirstOrDefault(); //matchingItem.IsSelected = true; matchingItem.Header = airliner.Airliner.Name; matchingItem.Visibility = System.Windows.Visibility.Visible; tab_main.SelectedItem = matchingItem; } if (frmContent != null) { frmContent.Navigate(new PageRoutePlanner(airliner.Airliner) { Tag = this.Tag }); } } else { int missingPilots = airliner.Airliner.Airliner.Type.CockpitCrew - airliner.Airliner.NumberOfPilots; if (GameObject.GetInstance().HumanAirline.Pilots.FindAll(p => p.Airliner == null).Count >= missingPilots) { WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2505"), string.Format(Translator.GetInstance().GetString("MessageBox", "2505", "message")), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { var unassignedPilots = GameObject.GetInstance().HumanAirline.Pilots.FindAll(p => p.Airliner == null).ToList(); for (int i = 0; i < missingPilots; i++) { unassignedPilots[i].Airliner = airliner.Airliner; airliner.Airliner.addPilot(unassignedPilots[i]); } if (tab_main != null) { var matchingItem = tab_main.Items.Cast <TabItem>() .Where(item => item.Tag.ToString() == "Airliner") .FirstOrDefault(); //matchingItem.IsSelected = true; matchingItem.Header = airliner.Airliner.Name; matchingItem.Visibility = System.Windows.Visibility.Visible; tab_main.SelectedItem = matchingItem; } if (frmContent != null) { frmContent.Navigate(new PageRoutePlanner(airliner.Airliner) { Tag = this.Tag }); } } } else { Random rnd = new Random(); WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2506"), string.Format(Translator.GetInstance().GetString("MessageBox", "2506", "message"), missingPilots), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { while (airliner.Airliner.Airliner.Type.CockpitCrew > airliner.Airliner.NumberOfPilots) { var pilots = Pilots.GetUnassignedPilots(p => p.Profile.Town.Country == airliner.Airliner.Airliner.Airline.Profile.Country && p.Aircrafts.Contains(airliner.Airliner.Airliner.Type.AirlinerFamily)); if (pilots.Count == 0) { pilots = Pilots.GetUnassignedPilots(p => p.Profile.Town.Country.Region == airliner.Airliner.Airliner.Airline.Profile.Country.Region && p.Aircrafts.Contains(airliner.Airliner.Airliner.Type.AirlinerFamily)); } if (pilots.Count == 0) { GeneralHelpers.CreatePilots(4, airliner.Airliner.Airliner.Type.AirlinerFamily); pilots = Pilots.GetUnassignedPilots(p => p.Aircrafts.Contains(airliner.Airliner.Airliner.Type.AirlinerFamily)); } if (pilots.Count < 5) { GeneralHelpers.CreatePilots(50); } Pilot pilot = pilots.First(); airliner.Airliner.Airliner.Airline.addPilot(pilot); pilot.Airliner = airliner.Airliner; airliner.Airliner.addPilot(pilot); } if (tab_main != null) { var matchingItem = tab_main.Items.Cast <TabItem>() .Where(item => item.Tag.ToString() == "Airliner") .FirstOrDefault(); //matchingItem.IsSelected = true; matchingItem.Header = airliner.Airliner.Name; matchingItem.Visibility = System.Windows.Visibility.Visible; tab_main.SelectedItem = matchingItem; } if (frmContent != null) { frmContent.Navigate(new PageRoutePlanner(airliner.Airliner) { Tag = this.Tag }); } } } } }
//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); }