//undos the settings private void undoSettings() { lbWages.Items.Clear(); foreach (FeeType type in FeeTypes.GetTypes(FeeType.eFeeType.Wage)) { this.FeeValues[type] = this.Airline.Fees.getValue(type); lbWages.Items.Add(new QuickInfoValue(type.Name, createWageSlider(type))); } lbFees.Items.Clear(); foreach (FeeType type in FeeTypes.GetTypes(FeeType.eFeeType.Fee).FindAll(f => GameObject.GetInstance().GameTime.Year >= f.FromYear)) { this.FeeValues[type] = this.Airline.Fees.getValue(type); lbFees.Items.Add(new QuickInfoValue(type.Name, createWageSlider(type))); } lbFoodDrinks.Items.Clear(); foreach (FeeType type in FeeTypes.GetTypes(FeeType.eFeeType.FoodDrinks)) { this.FeeValues[type] = this.Airline.Fees.getValue(type); lbFoodDrinks.Items.Add(new QuickInfoValue(type.Name, createWageSlider(type))); } lbDiscounts.Items.Clear(); foreach (FeeType type in FeeTypes.GetTypes(FeeType.eFeeType.Discount)) { this.FeeValues[type] = this.Airline.Fees.getValue(type); lbDiscounts.Items.Add(new QuickInfoValue(type.Name, createDiscountSlider(type))); } }
//resets the fees public void resetFees() { this.Wages.Clear(); this.Chargers.Clear(); this.Fees.Clear(); this.Discounts.Clear(); FeeTypes.GetTypes(FeeType.eFeeType.Wage).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Wages.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f)))); FeeTypes.GetTypes(FeeType.eFeeType.Discount).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Discounts.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f)))); FeeTypes.GetTypes(FeeType.eFeeType.Fee).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Fees.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f)))); FeeTypes.GetTypes(FeeType.eFeeType.FoodDrinks).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Chargers.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f)))); }
//creates the wage panel private StackPanel createWagesPanel() { StackPanel panelWagesFee = new StackPanel(); TextBlock txtHeaderFoods = new TextBlock(); txtHeaderFoods.Uid = "1002"; //txtHeaderFoods.Margin = new Thickness(0, 5, 0, 0); txtHeaderFoods.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; txtHeaderFoods.SetResourceReference(TextBlock.BackgroundProperty, "HeaderBackgroundBrush2"); txtHeaderFoods.FontWeight = FontWeights.Bold; txtHeaderFoods.Text = Translator.GetInstance().GetString("PageAirlineWages", txtHeaderFoods.Uid); panelWagesFee.Children.Add(txtHeaderFoods); lbFoodDrinks = new ListBox(); lbFoodDrinks.ItemContainerStyleSelector = new ListBoxItemStyleSelector(); lbFoodDrinks.SetResourceReference(ListBox.ItemTemplateProperty, "QuickInfoItem"); foreach (FeeType type in FeeTypes.GetTypes(FeeType.eFeeType.FoodDrinks)) { lbFoodDrinks.Items.Add(new QuickInfoValue(type.Name, createWageSlider(type))); } panelWagesFee.Children.Add(lbFoodDrinks); TextBlock txtHeaderFees = new TextBlock(); txtHeaderFees.Uid = "1003"; txtHeaderFees.Margin = new Thickness(0, 5, 0, 0); txtHeaderFees.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; txtHeaderFees.SetResourceReference(TextBlock.BackgroundProperty, "HeaderBackgroundBrush2"); txtHeaderFees.FontWeight = FontWeights.Bold; txtHeaderFees.Text = Translator.GetInstance().GetString("PageAirlineWages", txtHeaderFees.Uid); panelWagesFee.Children.Add(txtHeaderFees); lbFees = new ListBox(); lbFees.ItemContainerStyleSelector = new ListBoxItemStyleSelector(); lbFees.SetResourceReference(ListBox.ItemTemplateProperty, "QuickInfoItem"); foreach (FeeType type in FeeTypes.GetTypes(FeeType.eFeeType.Fee).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year)) { lbFees.Items.Add(new QuickInfoValue(type.Name, createWageSlider(type))); } panelWagesFee.Children.Add(lbFees); TextBlock txtHeaderDiscounts = new TextBlock(); txtHeaderDiscounts.Uid = "1015"; txtHeaderDiscounts.Margin = new Thickness(0, 5, 0, 0); txtHeaderDiscounts.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; txtHeaderDiscounts.SetResourceReference(TextBlock.BackgroundProperty, "HeaderBackgroundBrush2"); txtHeaderDiscounts.FontWeight = FontWeights.Bold; txtHeaderDiscounts.Text = Translator.GetInstance().GetString("PageAirlineWages", txtHeaderDiscounts.Uid); panelWagesFee.Children.Add(txtHeaderDiscounts); lbDiscounts = new ListBox(); lbDiscounts.ItemContainerStyleSelector = new ListBoxItemStyleSelector(); lbDiscounts.SetResourceReference(ListBox.ItemTemplateProperty, "QuickInfoItem"); foreach (FeeType type in FeeTypes.GetTypes(FeeType.eFeeType.Discount).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year)) { lbDiscounts.Items.Add(new QuickInfoValue(type.Name, createDiscountSlider(type))); } panelWagesFee.Children.Add(lbDiscounts); panelWagesFee.Children.Add(createButtonsPanel()); return(panelWagesFee); }
public PageAirlineWages(Airline airline) { InitializeComponent(); this.Airline = airline; this.FeeValues = new Dictionary <FeeType, double>(); FeeTypes.GetTypes().ForEach(f => this.FeeValues.Add(f, this.Airline.Fees.getValue(f))); StackPanel panelWagesAndEmployees = new StackPanel(); WrapPanel panelMenuButtons = new WrapPanel(); panelWagesAndEmployees.Children.Add(panelMenuButtons); ucSelectButton sbWages = new ucSelectButton(); sbWages.Uid = "1004"; sbWages.Content = Translator.GetInstance().GetString("PageAirlineWages", sbWages.Uid); sbWages.IsSelected = true; sbWages.Click += new RoutedEventHandler(sbWages_Click); panelMenuButtons.Children.Add(sbWages); ucSelectButton sbEmployees = new ucSelectButton(); sbEmployees.Uid = "1005"; sbEmployees.Content = Translator.GetInstance().GetString("PageAirlineWages", sbEmployees.Uid); sbEmployees.Click += new RoutedEventHandler(sbEmployees_Click); panelMenuButtons.Children.Add(sbEmployees); ucSelectButton sbService = new ucSelectButton(); sbService.Uid = "1006"; sbService.Content = Translator.GetInstance().GetString("PageAirlineWages", sbService.Uid); sbService.Click += new RoutedEventHandler(sbService_Click); panelMenuButtons.Children.Add(sbService); ucSelectButton sbAirlineService = new ucSelectButton(); sbAirlineService.Uid = "1007"; sbAirlineService.Content = Translator.GetInstance().GetString("PageAirlineWages", sbAirlineService.Uid); sbAirlineService.Click += new RoutedEventHandler(sbAirlineService_Click); panelMenuButtons.Children.Add(sbAirlineService); ucSelectButton sbAdvertisement = new ucSelectButton(); sbAdvertisement.Uid = "1008"; sbAdvertisement.Content = Translator.GetInstance().GetString("PageAirlineWages", sbAdvertisement.Uid); sbAdvertisement.Click += new RoutedEventHandler(sbAdvertisement_Click); panelMenuButtons.Children.Add(sbAdvertisement); ucSelectButton sbPolicies = new ucSelectButton(); sbPolicies.Uid = "1016"; sbPolicies.Content = Translator.GetInstance().GetString("PageAirlineWages", sbPolicies.Uid); sbPolicies.Click += new RoutedEventHandler(sbPolicies_Click); panelMenuButtons.Children.Add(sbPolicies); panelWages = createWagesPanel(); panelWagesAndEmployees.Children.Add(panelWages); panelEmployees = createEmployeesPanel(); panelEmployees.Visibility = System.Windows.Visibility.Collapsed; panelWagesAndEmployees.Children.Add(panelEmployees); panelInflightServices = createInflightServicesPanel(); panelInflightServices.Visibility = System.Windows.Visibility.Collapsed; panelWagesAndEmployees.Children.Add(panelInflightServices); panelAirlineServices = createAirlineServicesPanel(); panelAirlineServices.Visibility = System.Windows.Visibility.Collapsed; panelWagesAndEmployees.Children.Add(panelAirlineServices); panelAdvertisement = createAdvertisementPanel(); panelAdvertisement.Visibility = System.Windows.Visibility.Collapsed; panelWagesAndEmployees.Children.Add(panelAdvertisement); panelAirlinePolicies = createPoliciesPanel(); panelAirlinePolicies.Visibility = System.Windows.Visibility.Collapsed; panelWagesAndEmployees.Children.Add(panelAirlinePolicies); this.Content = panelWagesAndEmployees; }
//creates the employees panel private StackPanel createEmployeesPanel() { StackPanel panelEmployees = new StackPanel(); TextBlock txtHeaderWages = new TextBlock(); txtHeaderWages.Uid = "1001"; txtHeaderWages.Margin = new Thickness(0, 0, 0, 0); txtHeaderWages.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; txtHeaderWages.SetResourceReference(TextBlock.BackgroundProperty, "HeaderBackgroundBrush2"); txtHeaderWages.FontWeight = FontWeights.Bold; txtHeaderWages.Text = Translator.GetInstance().GetString("PageAirlineWages", txtHeaderWages.Uid); panelEmployees.Children.Add(txtHeaderWages); lbWages = new ListBox(); lbWages.ItemContainerStyleSelector = new ListBoxItemStyleSelector(); lbWages.SetResourceReference(ListBox.ItemTemplateProperty, "QuickInfoItem"); foreach (FeeType type in FeeTypes.GetTypes(FeeType.eFeeType.Wage)) { lbWages.Items.Add(new QuickInfoValue(type.Name, createWageSlider(type))); } panelEmployees.Children.Add(lbWages); TextBlock txtEmployeesHeader = new TextBlock(); txtEmployeesHeader.Uid = "1005"; txtEmployeesHeader.Margin = new Thickness(0, 5, 0, 0); txtEmployeesHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; txtEmployeesHeader.SetResourceReference(TextBlock.BackgroundProperty, "HeaderBackgroundBrush2"); txtEmployeesHeader.FontWeight = FontWeights.Bold; txtEmployeesHeader.Text = Translator.GetInstance().GetString("PageAirlineWages", txtEmployeesHeader.Uid); panelEmployees.Children.Add(txtEmployeesHeader); ListBox lbEmployees = new ListBox(); lbEmployees.ItemContainerStyleSelector = new ListBoxItemStyleSelector(); lbEmployees.ItemTemplate = this.Resources["EmployeeItem"] as DataTemplate; int cockpitCrew = this.Airline.Pilots.Count;//this.Airline.Fleet.Sum(f => f.Airliner.Type.CockpitCrew); //var list = (from r in this.Airline.Fleet.SelectMany(f => f.Routes) select r); int cabinCrew = this.Airline.Routes.Where(r => r.Type == Route.RouteType.Passenger).Sum(r => ((PassengerRoute)r).getTotalCabinCrew()); int serviceCrew = this.Airline.Airports.SelectMany(a => a.getCurrentAirportFacilities(this.Airline)).Where(a => a.EmployeeType == AirportFacility.EmployeeTypes.Support).Sum(a => a.NumberOfEmployees); int maintenanceCrew = this.Airline.Airports.SelectMany(a => a.getCurrentAirportFacilities(this.Airline)).Where(a => a.EmployeeType == AirportFacility.EmployeeTypes.Maintenance).Sum(a => a.NumberOfEmployees); lbEmployees.Items.Add(new KeyValuePair <string, int>(Translator.GetInstance().GetString("PageAirlineWages", "1009"), cockpitCrew)); lbEmployees.Items.Add(new KeyValuePair <string, int>(Translator.GetInstance().GetString("PageAirlineWages", "1010"), cabinCrew)); lbEmployees.Items.Add(new KeyValuePair <string, int>(Translator.GetInstance().GetString("PageAirlineWages", "1011"), serviceCrew)); lbEmployees.Items.Add(new KeyValuePair <string, int>(Translator.GetInstance().GetString("PageAirlineWages", "1012"), maintenanceCrew)); panelEmployees.Children.Add(lbEmployees); panelEmployees.Children.Add(createButtonsPanel()); return(panelEmployees); }
//simulates the landing of a flight private static void SimulateLanding(FleetAirliner airliner) { DateTime landingTime = airliner.CurrentFlight.FlightTime.Add(MathHelpers.GetFlightTime(airliner.CurrentFlight.Entry.DepartureAirport.Profile.Coordinates.convertToGeoCoordinate(), airliner.CurrentFlight.Entry.Destination.Airport.Profile.Coordinates.convertToGeoCoordinate(), airliner.Airliner.Type)); double fdistance = MathHelpers.GetDistance(airliner.CurrentFlight.getDepartureAirport(), airliner.CurrentFlight.Entry.Destination.Airport); TimeSpan flighttime = landingTime.Subtract(airliner.CurrentFlight.FlightTime); double groundTaxPerPassenger = 5; double tax = 0; if (airliner.CurrentFlight.Entry.Destination.Airport.Profile.Country != airliner.CurrentFlight.getDepartureAirport().Profile.Country) { tax = 2 * tax; } double ticketsIncome = 0; double feesIncome = 0; double mealExpenses = 0; double fuelExpenses = 0; if (airliner.CurrentFlight.isPassengerFlight()) { tax = groundTaxPerPassenger * airliner.CurrentFlight.getTotalPassengers(); fuelExpenses = FleetAirlinerHelpers.GetFuelExpenses(airliner, fdistance); foreach (FlightAirlinerClass fac in airliner.CurrentFlight.Classes) { ticketsIncome += fac.Passengers * ((PassengerRoute)airliner.CurrentFlight.Entry.TimeTable.Route).getRouteAirlinerClass(fac.AirlinerClass.Type).FarePrice; } FeeType employeeDiscountType = FeeTypes.GetType("Employee Discount"); double employeesDiscount = airliner.Airliner.Airline.Fees.getValue(employeeDiscountType); double totalDiscount = ticketsIncome * (employeeDiscountType.Percentage / 100.0) * (employeesDiscount / 100.0); ticketsIncome = ticketsIncome - totalDiscount; foreach (FeeType feeType in FeeTypes.GetTypes(FeeType.eFeeType.Fee)) { if (GameObject.GetInstance().GameTime.Year >= feeType.FromYear) { foreach (FlightAirlinerClass fac in airliner.CurrentFlight.Classes) { double percent = 0.10; double maxValue = Convert.ToDouble(feeType.Percentage) * (1 + percent); double minValue = Convert.ToDouble(feeType.Percentage) * (1 - percent); double value = Convert.ToDouble(rnd.Next((int)minValue, (int)maxValue)) / 100; feesIncome += fac.Passengers * value * airliner.Airliner.Airline.Fees.getValue(feeType); } } } foreach (FlightAirlinerClass fac in airliner.CurrentFlight.Classes) { foreach (RouteFacility facility in ((PassengerRoute)airliner.CurrentFlight.Entry.TimeTable.Route).getRouteAirlinerClass(fac.AirlinerClass.Type).getFacilities()) { if (facility.EType == RouteFacility.ExpenseType.Fixed) { mealExpenses += fac.Passengers * facility.ExpensePerPassenger; } else { FeeType feeType = facility.FeeType; double percent = 0.10; double maxValue = Convert.ToDouble(feeType.Percentage) * (1 + percent); double minValue = Convert.ToDouble(feeType.Percentage) * (1 - percent); double value = Convert.ToDouble(rnd.Next((int)minValue, (int)maxValue)) / 100; mealExpenses -= fac.Passengers * value * airliner.Airliner.Airline.Fees.getValue(feeType); } } } } if (airliner.CurrentFlight.isCargoFlight()) { tax = groundTaxPerPassenger * airliner.CurrentFlight.Cargo; fuelExpenses = FleetAirlinerHelpers.GetFuelExpenses(airliner, fdistance); ticketsIncome = airliner.CurrentFlight.Cargo * airliner.CurrentFlight.getCargoPrice(); } Airport dest = airliner.CurrentFlight.Entry.Destination.Airport; Airport dept = airliner.CurrentFlight.Entry.DepartureAirport; double dist = MathHelpers.GetDistance(dest.Profile.Coordinates.convertToGeoCoordinate(), dept.Profile.Coordinates.convertToGeoCoordinate()); double expenses = fuelExpenses + dest.getLandingFee() + tax; if (double.IsNaN(expenses)) { expenses = 0; } if (double.IsNaN(ticketsIncome) || ticketsIncome < 0) { ticketsIncome = 0; } FleetAirlinerHelpers.SetFlightStats(airliner); long airportIncome = Convert.ToInt64(dest.getLandingFee()); dest.Income += airportIncome; Airline airline = airliner.Airliner.Airline; var agreements = airline.Codeshares.Where(c => c.Airline1 == airline || c.Type == CodeshareAgreement.CodeshareType.Both_Ways); foreach (CodeshareAgreement agreement in agreements) { var tAirline = agreement.Airline1 == airline ? agreement.Airline2 : agreement.Airline1; double agreementIncome = ticketsIncome * (CodeshareAgreement.TicketSalePercent / 100); AirlineHelpers.AddAirlineInvoice(tAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Tickets, agreementIncome); } AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Flight_Expenses, -expenses); AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Tickets, ticketsIncome); AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.OnFlight_Income, -mealExpenses); AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Fees, feesIncome); airliner.CurrentFlight.Entry.TimeTable.Route.addRouteInvoice(new Invoice(GameObject.GetInstance().GameTime, Invoice.InvoiceType.Flight_Expenses, -expenses)); airliner.CurrentFlight.Entry.TimeTable.Route.addRouteInvoice(new Invoice(GameObject.GetInstance().GameTime, Invoice.InvoiceType.Tickets, ticketsIncome)); airliner.CurrentFlight.Entry.TimeTable.Route.addRouteInvoice(new Invoice(GameObject.GetInstance().GameTime, Invoice.InvoiceType.OnFlight_Income, -mealExpenses)); airliner.CurrentFlight.Entry.TimeTable.Route.addRouteInvoice(new Invoice(GameObject.GetInstance().GameTime, Invoice.InvoiceType.Fees, feesIncome)); double wages = 0; if (airliner.CurrentFlight.isPassengerFlight()) { int cabinCrew = ((AirlinerPassengerType)airliner.Airliner.Type).CabinCrew; wages = cabinCrew * flighttime.TotalHours * airliner.Airliner.Airline.Fees.getValue(FeeTypes.GetType("Cabin Wage"));// +(airliner.CurrentFlight.Entry.TimeTable.Route.getTotalCabinCrew() * airliner.Airliner.Airline.Fees.getValue(FeeTypes.GetType("Cabin kilometer rate")) * fdistance) + (airliner.Airliner.Type.CockpitCrew * airliner.Airliner.Airline.Fees.getValue(FeeTypes.GetType("Cockpit kilometer rate")) * fdistance); //wages AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Wages, -wages); HolidayYearEvent holiday = HolidayYear.GetHoliday(airline.Profile.Country, GameObject.GetInstance().GameTime); if (holiday != null && (holiday.Holiday.Travel == Holiday.TravelType.Both || holiday.Holiday.Travel == Holiday.TravelType.Normal)) { wages = wages * 1.50; } airliner.CurrentFlight.Entry.TimeTable.Route.addRouteInvoice(new Invoice(GameObject.GetInstance().GameTime, Invoice.InvoiceType.Wages, -wages)); CreatePassengersHappiness(airliner); } airliner.Statistics.addStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Airliner_Income"), ticketsIncome - expenses - mealExpenses + feesIncome - wages); airliner.Airliner.Flown += fdistance; if (airliner.CurrentFlight.isPassengerFlight()) { foreach (Cooperation cooperation in airliner.CurrentFlight.Entry.Destination.Airport.Cooperations.Where(c => c.Airline == airline)) { double incomePerPax = MathHelpers.GetRandomDoubleNumber(cooperation.Type.IncomePerPax * 0.9, cooperation.Type.IncomePerPax * 1.1); double incomeFromCooperation = Convert.ToDouble(airliner.CurrentFlight.getTotalPassengers()) * incomePerPax; AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.OnFlight_Income, incomeFromCooperation); } } if (airliner.Airliner.Airline.IsHuman && Settings.GetInstance().MailsOnLandings) { GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Flight_News, GameObject.GetInstance().GameTime, string.Format("{0} landed", airliner.Name), string.Format("Your airliner [LI airliner={0}] has landed in [LI airport={1}], {2} with {3} passengers.\nThe airliner flow from [LI airport={4}], {5}", new object[] { airliner.Airliner.TailNumber, dest.Profile.IATACode, dest.Profile.Country.Name, airliner.CurrentFlight.getTotalPassengers(), dept.Profile.IATACode, dept.Profile.Country.Name }))); } if (airliner.CurrentFlight is StopoverFlight && !((StopoverFlight)airliner.CurrentFlight).IsLastTrip) { SimulateFlight(airliner.CurrentFlight.Entry); } else { airliner.CurrentFlight = null; } }
//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); * } * } */ }
public AirlineMVVM(Airline airline) { this.Airline = airline; this.Alliance = this.Airline.Alliances.Count == 0 ? null : this.Airline.Alliances[0]; this.DeliveredFleet = new ObservableCollection <FleetAirliner>(); foreach (FleetAirliner airliner in this.Airline.Fleet.FindAll(a => a.Airliner.BuiltDate <= GameObject.GetInstance().GameTime)) { this.DeliveredFleet.Add(airliner); } this.OrderedFleet = this.Airline.Fleet.FindAll(a => a.Airliner.BuiltDate > GameObject.GetInstance().GameTime); this.Finances = new ObservableCollection <AirlineFinanceMVVM>(); this.LoanRate = GeneralHelpers.GetAirlineLoanRate(this.Airline); this.Loans = new ObservableCollection <LoanMVVM>(); this.Pilots = new ObservableCollection <PilotMVVM>(); this.Wages = new ObservableCollection <AirlineFeeMVVM>(); this.Discounts = new ObservableCollection <AirlineFeeMVVM>(); this.Facilities = new ObservableCollection <AirlineFacilityMVVM>(); this.TrainingFacilities = new ObservableCollection <AirlineFacilityMVVM>(); this.Fees = new ObservableCollection <AirlineFeeMVVM>(); this.Chargers = new ObservableCollection <AirlineFeeMVVM>(); this.Subsidiaries = new ObservableCollection <SubsidiaryAirline>(); this.Insurances = new ObservableCollection <AirlineInsurance>(); this.Advertisements = new ObservableCollection <AirlineAdvertisementMVVM>(); this.Destinations = new ObservableCollection <AirlineDestinationMVVM>(); this.AirlineAirlines = new ObservableCollection <Airline>(); this.FundsAirlines = new ObservableCollection <Airline>(); this.Routes = new List <AirlineRouteMVVM>(); this.Codeshares = new ObservableCollection <Airline>(); this.Cooperations = new List <CooperationMVVM>(); this.Airline.Routes.ForEach(r => this.Routes.Add(new AirlineRouteMVVM(r))); this.Airline.Loans.FindAll(l => l.IsActive).ForEach(l => this.Loans.Add(new LoanMVVM(l, this.Airline))); this.Airline.Pilots.ForEach(p => this.Pilots.Add(new PilotMVVM(p))); this.UnassignedPilots = this.Pilots.Count(p => p.Pilot.Airliner == null); this.PilotsToRetire = this.Pilots.Count(p => p.Pilot.Profile.Age == Pilot.RetirementAge - 1); FeeTypes.GetTypes(FeeType.eFeeType.Wage).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Wages.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f)))); FeeTypes.GetTypes(FeeType.eFeeType.Discount).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Discounts.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f)))); FeeTypes.GetTypes(FeeType.eFeeType.FoodDrinks).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Chargers.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f)))); FeeTypes.GetTypes(FeeType.eFeeType.Fee).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Fees.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f)))); this.Airline.Subsidiaries.ForEach(s => this.Subsidiaries.Add(s)); this.Airline.InsurancePolicies.ForEach(i => this.Insurances.Add(i)); this.Airline.Codeshares.ForEach(c => this.Codeshares.Add(c.Airline1 == this.Airline ? c.Airline2 : c.Airline1)); foreach (Airport airport in this.Airline.Airports) { foreach (Cooperation cooperation in airport.Cooperations.Where(c => c.Airline == this.Airline)) { this.Cooperations.Add(new CooperationMVVM(airport, cooperation)); } } setValues(); this.Colors = new List <PropertyInfo>(); foreach (PropertyInfo c in typeof(Colors).GetProperties()) { this.Colors.Add(c); } foreach (Airport airport in this.Airline.Airports.OrderByDescending(a => this.Airline.Airports[0] == a).ThenBy(a => a.Profile.Name)) { this.Destinations.Add(new AirlineDestinationMVVM(airport, airport.hasHub(this.Airline))); } double buyingPrice = this.Airline.getValue() * 1000000 * 1.10; this.IsBuyable = !this.Airline.IsHuman && GameObject.GetInstance().HumanAirline.Money > buyingPrice; this.ActiveQuantity = new List <AirlinerQuantityMVVM>(); this.OrderedQuantity = new List <AirlinerQuantityMVVM>(); var fleet = new List <FleetAirliner>(this.Airline.Fleet); foreach (FleetAirliner airliner in fleet) { if (airliner.Airliner.BuiltDate > GameObject.GetInstance().GameTime) { if (this.OrderedQuantity.Any(o => o.Type == airliner.Airliner.Type)) { this.OrderedQuantity.First(o => o.Type == airliner.Airliner.Type).Quantity++; } else { this.OrderedQuantity.Add(new AirlinerQuantityMVVM(airliner.Airliner.Type, 1)); } } else { if (this.ActiveQuantity.Any(o => o.Type == airliner.Airliner.Type)) { this.ActiveQuantity.First(o => o.Type == airliner.Airliner.Type).Quantity++; } else { this.ActiveQuantity.Add(new AirlinerQuantityMVVM(airliner.Airliner.Type, 1)); } } } this.HasAlliance = this.Alliance != null || this.Codeshares.Count > 0; }
public AirlineMVVM(Airline airline) { this.Airline = airline; this.Alliance = this.Airline.Alliances.Count == 0 ? null : this.Airline.Alliances[0]; this.DeliveredFleet = new ObservableCollection <FleetAirliner>(); foreach (FleetAirliner airliner in this.Airline.Fleet.FindAll(a => a.Airliner.BuiltDate <= GameObject.GetInstance().GameTime)) { this.DeliveredFleet.Add(airliner); } this.OrderedFleet = this.Airline.Fleet.FindAll(a => a.Airliner.BuiltDate > GameObject.GetInstance().GameTime); this.Finances = new ObservableCollection <AirlineFinanceMVVM>(); this.LoanRate = GeneralHelpers.GetAirlineLoanRate(this.Airline); this.Loans = new ObservableCollection <LoanMVVM>(); this.Pilots = new ObservableCollection <Pilot>(); this.Wages = new ObservableCollection <AirlineFeeMVVM>(); this.Discounts = new ObservableCollection <AirlineFeeMVVM>(); this.Facilities = new ObservableCollection <AirlineFacilityMVVM>(); this.Fees = new ObservableCollection <AirlineFeeMVVM>(); this.Chargers = new ObservableCollection <AirlineFeeMVVM>(); this.Subsidiaries = new ObservableCollection <SubsidiaryAirline>(); this.Insurances = new ObservableCollection <AirlineInsurance>(); this.Advertisements = new ObservableCollection <AirlineAdvertisementMVVM>(); this.Destinations = new ObservableCollection <AirlineDestinationMVVM>(); this.AirlineAirlines = new ObservableCollection <Airline>(); this.Airline.Loans.FindAll(l => l.IsActive).ForEach(l => this.Loans.Add(new LoanMVVM(l))); this.Airline.Pilots.ForEach(p => this.Pilots.Add(p)); FeeTypes.GetTypes(FeeType.eFeeType.Wage).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Wages.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f)))); FeeTypes.GetTypes(FeeType.eFeeType.Discount).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Discounts.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f)))); FeeTypes.GetTypes(FeeType.eFeeType.FoodDrinks).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Chargers.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f)))); FeeTypes.GetTypes(FeeType.eFeeType.Fee).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Fees.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f)))); this.Airline.Subsidiaries.ForEach(s => this.Subsidiaries.Add(s)); this.Airline.InsurancePolicies.ForEach(i => this.Insurances.Add(i)); setValues(); this.Colors = new List <PropertyInfo>(); foreach (PropertyInfo c in typeof(Colors).GetProperties()) { this.Colors.Add(c); } foreach (Airport airport in this.Airline.Airports.OrderByDescending(a => this.Airline.Airports[0] == a).ThenBy(a => a.Profile.Name)) { this.Destinations.Add(new AirlineDestinationMVVM(airport, airport.hasHub(this.Airline))); } double buyingPrice = this.Airline.getValue() * 1000000 * 1.10; this.IsBuyable = !this.Airline.IsHuman && GameObject.GetInstance().HumanAirline.Money > buyingPrice; }