public AirlinerClassMVVM(AirlinerClass type, int seating, int regularSeating, int maxseats, Boolean changeableSeats = false) { this.Type = type.Type; this.Seating = seating; this.RegularSeatingCapacity = regularSeating; this.ChangeableSeats = changeableSeats; this.MaxSeats = maxseats; this.MaxSeatsCapacity = maxseats; this.ChangedFacility = false; this.Facilities = new ObservableCollection <AirlinerFacilityMVVM>(); foreach (AirlinerFacility.FacilityType facType in Enum.GetValues(typeof(AirlinerFacility.FacilityType))) { AirlinerFacilityMVVM facility = new AirlinerFacilityMVVM(facType, this); foreach (AirlinerFacility fac in AirlinerFacilities.GetFacilities(facType)) { facility.Facilities.Add(fac); } AirlinerFacility selectedFacility = type.getFacility(facType) == null?AirlinerFacilities.GetBasicFacility(facType) : type.getFacility(facType); facility.SelectedFacility = selectedFacility; this.Facilities.Add(facility); } }
private void tcMenu_SelectionChanged(object sender, SelectionChangedEventArgs e) { foreach (AirlinerClassMVVM aClass in this.Classes) { foreach (AirlinerFacility.FacilityType facType in Enum.GetValues(typeof(AirlinerFacility.FacilityType))) { AirlinerFacility facility = aClass.Facilities.Where(f => f.Type == facType).First().SelectedFacility; if (facility == null) { facility = AirlinerFacilities.GetBasicFacility(facType); } aClass.Facilities.Where(f => f.Type == facType).First().SelectedFacility = facility; } } }
public AirlinerClassMVVM(AirlinerClass.ClassType type, int seating, Boolean canDelete) { this.CanDelete = canDelete; this.Type = type; this.Seating = seating; this.RegularSeating = seating; this.Facilities = new ObservableCollection <AirlinerClassFacilityMVVM>(); foreach (AirlinerFacility.FacilityType facType in Enum.GetValues(typeof(AirlinerFacility.FacilityType))) { AirlinerClassFacilityMVVM facility = new AirlinerClassFacilityMVVM(facType); foreach (AirlinerFacility fac in AirlinerFacilities.GetFacilities(facType)) { facility.Facilities.Add(fac); } this.Facilities.Add(facility); } }
public PopUpAirlinerFacility(AirlinerClass airlinerClass, AirlinerFacility.FacilityType type) { InitializeComponent(); this.AirlinerClass = airlinerClass; this.Type = type; this.Title = "Select " + type.ToString().ToLower(); this.Width = 400; this.Height = 120; this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; StackPanel mainPanel = new StackPanel(); mainPanel.Margin = new Thickness(10, 10, 10, 10); cbFacility = new ComboBox(); cbFacility.ItemTemplate = this.Resources["AirlinerFacilityItem"] as DataTemplate; cbFacility.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); foreach (AirlinerFacility facility in AirlinerFacilities.GetFacilities(this.Type, GameObject.GetInstance().GameTime.Year)) { cbFacility.Items.Add(facility); } cbFacility.SelectedItem = this.AirlinerClass.getFacility(this.Type); mainPanel.Children.Add(cbFacility); mainPanel.Children.Add(createButtonsPanel()); this.Content = mainPanel; // int serviceLevel, double percentOfSeats, double pricePerSeat }
private void btnLoadConfiguration_Click(object sender, RoutedEventArgs e) { ComboBox cbConfigurations = new ComboBox(); cbConfigurations.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbConfigurations.SelectedValuePath = "Name"; cbConfigurations.DisplayMemberPath = "Name"; cbConfigurations.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; cbConfigurations.Width = 200; foreach (AirlinerConfiguration confItem in Configurations.GetConfigurations(Configuration.ConfigurationType.Airliner).Where(a => ((AirlinerConfiguration)a).MinimumSeats <= this.Airliner.Airliner.getTotalSeatCapacity() && ((AirlinerConfiguration)a).Classes.Count <= ((AirlinerPassengerType)this.Airliner.Airliner.Type).MaxAirlinerClasses)) { cbConfigurations.Items.Add(confItem); } cbConfigurations.SelectedIndex = 0; if (TheAirline.GraphicsModel.UserControlModel.PopUpWindowsModel.PopUpSingleElement.ShowPopUp(Translator.GetInstance().GetString("PageAirlineWages", "1013"), cbConfigurations) == TheAirline.GraphicsModel.UserControlModel.PopUpWindowsModel.PopUpSingleElement.ButtonSelected.OK && cbConfigurations.SelectedItem != null) { this.Classes.Clear(); AirlinerConfiguration configuration = (AirlinerConfiguration)cbConfigurations.SelectedItem; foreach (AirlinerClassConfiguration aClass in configuration.Classes) { AirlinerClass nClass = new AirlinerClass(aClass.Type, aClass.SeatingCapacity); AirlinerClassMVVM tClass = new AirlinerClassMVVM(nClass, aClass.SeatingCapacity, aClass.RegularSeatingCapacity, aClass.RegularSeatingCapacity); foreach (AirlinerFacility facility in aClass.getFacilities()) { tClass.Facilities.First(f => f.Type == facility.Type).SelectedFacility = facility; } foreach (AirlinerFacility.FacilityType fType in Enum.GetValues(typeof(AirlinerFacility.FacilityType))) { if (!aClass.Facilities.Exists(f => f.Type == fType)) { tClass.Facilities.First(f => f.Type == fType).SelectedFacility = AirlinerFacilities.GetBasicFacility(fType); } } this.Classes.Add(tClass); } int seatingDiff = ((AirlinerPassengerType)this.Airliner.Airliner.Type).MaxSeatingCapacity - configuration.MinimumSeats; AirlinerClassMVVM economyClass = this.Classes.First(c => c.Type == AirlinerClass.ClassType.Economy_Class); economyClass.RegularSeatingCapacity += seatingDiff; AirlinerFacility seatingFacility = economyClass.Facilities.First(f => f.Type == AirlinerFacility.FacilityType.Seat).SelectedFacility; int extraSeats = (int)(seatingDiff / seatingFacility.SeatUses); economyClass.Seating += extraSeats; } }
//returns the airliner classes for an airliner public static List <AirlinerClass> GetAirlinerClasses(AirlinerType type) { List <AirlinerClass> classes = new List <AirlinerClass>(); if (type is AirlinerPassengerType) { Configuration airlinerTypeConfiguration = Configurations.GetConfigurations(Configuration.ConfigurationType.AirlinerType).Find(c => ((AirlinerTypeConfiguration)c).Airliner == type && ((AirlinerTypeConfiguration)c).Period.From <= GameObject.GetInstance().GameTime&& ((AirlinerTypeConfiguration)c).Period.To > GameObject.GetInstance().GameTime); if (airlinerTypeConfiguration == null) { AirlinerConfiguration configuration = null; int numOfClasses = rnd.Next(0, ((AirlinerPassengerType)type).MaxAirlinerClasses) + 1; if (GameObject.GetInstance().GameTime.Year >= (int)AirlinerClass.ClassType.Business_Class) { if (numOfClasses == 1) { configuration = (AirlinerConfiguration)Configurations.GetStandardConfiguration("200"); } if (numOfClasses == 2) { configuration = (AirlinerConfiguration)Configurations.GetStandardConfiguration("202"); } if (numOfClasses == 3) { configuration = (AirlinerConfiguration)Configurations.GetStandardConfiguration("203"); } } else { if (numOfClasses == 1) { configuration = (AirlinerConfiguration)Configurations.GetStandardConfiguration("200"); } if (numOfClasses == 2) { configuration = (AirlinerConfiguration)Configurations.GetStandardConfiguration("201"); } if (numOfClasses == 3) { configuration = (AirlinerConfiguration)Configurations.GetStandardConfiguration("201"); } } foreach (AirlinerClassConfiguration aClass in configuration.Classes) { AirlinerClass airlinerClass = new AirlinerClass(aClass.Type, aClass.SeatingCapacity); airlinerClass.RegularSeatingCapacity = aClass.RegularSeatingCapacity; foreach (AirlinerFacility facility in aClass.getFacilities()) { airlinerClass.setFacility(null, facility); } foreach (AirlinerFacility.FacilityType fType in Enum.GetValues(typeof(AirlinerFacility.FacilityType))) { if (!aClass.Facilities.Exists(f => f.Type == fType)) { airlinerClass.setFacility(null, AirlinerFacilities.GetBasicFacility(fType)); } } airlinerClass.SeatingCapacity = Convert.ToInt16(Convert.ToDouble(airlinerClass.RegularSeatingCapacity) / airlinerClass.getFacility(AirlinerFacility.FacilityType.Seat).SeatUses); classes.Add(airlinerClass); } int seatingDiff = ((AirlinerPassengerType)type).MaxSeatingCapacity - configuration.MinimumSeats; AirlinerClass economyClass = classes.Find(c => c.Type == AirlinerClass.ClassType.Economy_Class); economyClass.RegularSeatingCapacity += seatingDiff; AirlinerFacility seatingFacility = economyClass.getFacility(AirlinerFacility.FacilityType.Seat); int extraSeats = (int)(seatingDiff / seatingFacility.SeatUses); economyClass.SeatingCapacity += extraSeats; } else { foreach (AirlinerClassConfiguration aClass in ((AirlinerTypeConfiguration)airlinerTypeConfiguration).Classes) { AirlinerClass airlinerClass = new AirlinerClass(aClass.Type, aClass.SeatingCapacity); airlinerClass.RegularSeatingCapacity = aClass.RegularSeatingCapacity; foreach (AirlinerFacility facility in aClass.getFacilities()) { airlinerClass.setFacility(null, facility); } airlinerClass.SeatingCapacity = Convert.ToInt16(Convert.ToDouble(airlinerClass.RegularSeatingCapacity) / airlinerClass.getFacility(AirlinerFacility.FacilityType.Seat).SeatUses); classes.Add(airlinerClass); } } } else if (type is AirlinerCargoType) { AirlinerClass cargoClass = new AirlinerClass(AirlinerClass.ClassType.Economy_Class, 0); classes.Add(cargoClass); } return(classes); }
private void btnAddClass_Click(object sender, RoutedEventArgs e) { ComboBox cbClasses = new ComboBox(); cbClasses.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbClasses.ItemTemplate = this.Resources["AirlinerClassItem"] as DataTemplate; cbClasses.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; cbClasses.Width = 200; foreach (AirlinerClass.ClassType type in Enum.GetValues(typeof(AirlinerClass.ClassType))) { Boolean hasClass = this.Airliner.Classes.ToList().Exists(c => c.Type == type); if ((int)type <= GameObject.GetInstance().GameTime.Year&& !hasClass) { cbClasses.Items.Add(type); } } cbClasses.SelectedIndex = 0; AirlinerClassMVVM tClass = this.Airliner.Classes[0]; if (PopUpSingleElement.ShowPopUp(Translator.GetInstance().GetString("PageFleetAirlinerInformation", "1011"), cbClasses) == PopUpSingleElement.ButtonSelected.OK && cbClasses.SelectedItem != null) { int maxseats; int maxCapacity; if (this.Airliner.Airliner.Airliner.Type.TypeAirliner == AirlinerType.TypeOfAirliner.Passenger) { maxCapacity = ((AirlinerPassengerType)this.Airliner.Airliner.Airliner.Type).MaxSeatingCapacity; } else { maxCapacity = tClass.RegularSeatingCapacity; } if (this.Airliner.Classes.Count == 2) { maxseats = maxCapacity - 1 - this.Airliner.Classes[1].RegularSeatingCapacity; } else { maxseats = maxCapacity - 1; } AirlinerClassMVVM aClass = new AirlinerClassMVVM(new AirlinerClass((AirlinerClass.ClassType)cbClasses.SelectedItem, 0), 1, 1, maxseats, true); foreach (AirlinerFacilityMVVM aFacility in aClass.Facilities) { var facility = AirlinerFacilities.GetBasicFacility(aFacility.Type); aFacility.SelectedFacility = facility; } this.Airliner.Classes.Add(aClass); tClass.RegularSeatingCapacity -= aClass.RegularSeatingCapacity; tClass.Seating = Convert.ToInt16(Convert.ToDouble(tClass.RegularSeatingCapacity) / tClass.Facilities.Where(f => f.Type == AirlinerFacility.FacilityType.Seat).First().SelectedFacility.SeatUses); } }
//saves a game public static void SaveGame(string name) { Stopwatch sw = new Stopwatch(); sw.Start(); SaveObject so = new SaveObject(); Parallel.Invoke(() => { so.airportsList = new List <Airport>(); so.airportsfromstringList = new List <string>(); var airportsInUse = Airports.GetAllAirports().Where(a => Airlines.GetAllAirlines().Exists(al => al.Airports.Contains(a)) || a.hasAirlineFacility()); so.airportsList.AddRange(airportsInUse); foreach (Airport airport in Airports.GetAirports(a => !airportsInUse.Contains(a))) { so.airportsfromstringList.Add(airport.Profile.IATACode); } }, () => { so.airlinesList = new List <Airline>(); so.airlinesList.AddRange(Airlines.GetAllAirlines()); }, () => { so.airlinersList = new List <Airliner>(); so.airlinersList.AddRange(Airliners.GetAllAirliners().Where(a => a.Airline != null)); }, () => { 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.feeTypeslist = new List <FeeType>(); so.feeTypeslist.AddRange(FeeTypes.GetTypes()); }, () => { so.advertisementTypeslist = new List <AdvertisementType>(); so.advertisementTypeslist.AddRange(AdvertisementTypes.GetTypes()); }, () => { so.airlinerfacilitieslist = new List <AirlinerFacility>(); so.airlinerfacilitieslist.AddRange(AirlinerFacilities.GetAllFacilities()); }, () => { so.routefacilitieslist = new List <RouteFacility>(); so.routefacilitieslist.AddRange(RouteFacilities.GetAllFacilities()); }, () => { so.instance = GameObject.GetInstance(); so.settings = Settings.GetInstance(); }, () => { so.airlinefacilitieslist = new List <AirlineFacility>(); so.airlinefacilitieslist.AddRange(AirlineFacilities.GetFacilities()); }); string fileName = AppSettings.getCommonApplicationDataPath() + "\\saves\\" + name + ".sav"; FileSerializer.Serialize(fileName, so); sw.Stop(); Console.WriteLine("Saving: {0} ms", sw.ElapsedMilliseconds); //Clearing stats because there is no need for saving those. if (name != "autosave") { Airports.GetAllAirports().ForEach(a => a.clearDestinationPassengerStatistics()); Airports.GetAllAirports().ForEach(a => a.clearDestinationCargoStatistics()); AirlineHelpers.ClearRoutesStatistics(); AirlineHelpers.ClearAirlinesStatistics(); AirportHelpers.ClearAirportStatistics(); } /* * 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.feeTypeslist = new List<FeeType>(); * so.feeTypeslist.AddRange(FeeTypes.GetTypes()); * }, () => * { * so.advertisementTypeslist = new List<AdvertisementType>(); * so.advertisementTypeslist.AddRange(AdvertisementTypes.GetTypes()); * }, () => * { * so.airlinerfacilitieslist = new List<AirlinerFacility>(); * so.airlinerfacilitieslist.AddRange(AirlinerFacilities.GetAllFacilities()); * }, () => * { * so.routefacilitieslist = new List<RouteFacility>(); * so.routefacilitieslist.AddRange(RouteFacilities.GetAllFacilities()); * }, () => * { * so.instance = GameObject.GetInstance(); * so.settings = Settings.GetInstance(); * so.savetype = "039"; * so.saveversionnumber = 1; * }); */ /* * 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, CompressionLevel.Fastest)) * { * serializer.WriteObject(compress, so); * } * } */ }
//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); }