/*!creates an airliner from a specific year */ public static Airliner CreateAirlinerFromYear(int year) { Guid id = Guid.NewGuid(); List<AirlinerType> types = AirlinerTypes.GetTypes(t=>t.Produced.From.Year < year && t.Produced.To.Year > year); int typeNumber = rnd.Next(types.Count); AirlinerType type = types[typeNumber]; int countryNumber = rnd.Next(Countries.GetCountries().Count() - 1); Country country = Countries.GetCountries()[countryNumber]; int builtYear = year; Airliner airliner = new Airliner(id.ToString(), type, country.TailNumbers.getNextTailNumber(), new DateTime(builtYear, 1, 1)); int age = MathHelpers.CalculateAge(airliner.BuiltDate, GameObject.GetInstance().GameTime); long kmPerYear = rnd.Next(1000, 100000); long km = kmPerYear * age; airliner.Flown = km; CreateAirlinerClasses(airliner); return airliner; }
public PageUsedAirliner(Airliner airliner) { this.Airliner = airliner; this.Homebases = GameObject.GetInstance().HumanAirline.Airports.FindAll(a => a.getCurrentAirportFacility(GameObject.GetInstance().HumanAirline, AirportFacility.FacilityType.Service).TypeLevel > 0 && a.getMaxRunwayLength() >= this.Airliner.Type.MinRunwaylength); this.DataContext = this.Airliner; InitializeComponent(); }
//adds an airliner to the list public static void AddAirliner(Airliner airliner) { lock (airliners) { //if (airliners.Exists(a => a.ID == airliner.ID)) // throw new Exception("Airliner element already exists exception"); airliners.Add(airliner); } }
public static FleetAirliner BuyAirliner(Airline airline, Airliner airliner, Airport airport, double discount) { FleetAirliner fAirliner = AddAirliner(airline, airliner, airport,false); double price = airliner.getPrice() * ((100 - discount) / 100); AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -price); return fAirliner; }
//creates the airliner classes for an airliner public static void CreateAirlinerClasses(Airliner airliner) { airliner.clearAirlinerClasses(); List<AirlinerClass> classes = GetAirlinerClasses(airliner.Type); foreach (AirlinerClass aClass in classes) { airliner.addAirlinerClass(aClass); } }
public static FleetAirliner AddAirliner(Airline airline, Airliner airliner, Airport airport) { if (Countries.GetCountryFromTailNumber(airliner.TailNumber).Name != airline.Profile.Country.Name) airliner.TailNumber = airline.Profile.Country.TailNumbers.getNextTailNumber(); FleetAirliner fAirliner = new FleetAirliner(FleetAirliner.PurchasedType.Bought, GameObject.GetInstance().GameTime, airline, airliner, airport); airline.addAirliner(fAirliner); return fAirliner; }
public PageUsedAirliner(Airliner airliner) { this.Airliner = airliner; long minRunway = this.Airliner.Type.MinRunwaylength; var homebases = AirlineHelpers.GetHomebases(GameObject.GetInstance().HumanAirline, minRunway); this.Homebases = homebases; this.DataContext = this.Airliner; InitializeComponent(); }
//creates an airliner for an airline public static FleetAirliner CreateAirliner(Airline airline, AirlinerType type) { Guid id = Guid.NewGuid(); Airliner airliner = new Airliner(id.ToString(), type, airline.Profile.Country.TailNumbers.getNextTailNumber(), GameObject.GetInstance().GameTime); Airliners.AddAirliner(airliner); FleetAirliner fAirliner = new FleetAirliner(FleetAirliner.PurchasedType.Bought, GameObject.GetInstance().GameTime, airline, airliner, airline.Airports[0]); airliner.clearAirlinerClasses(); AirlinerHelpers.CreateAirlinerClasses(airliner); return fAirliner; }
public FleetAirliner(PurchasedType purchased, DateTime purchasedDate, Airline airline, Airliner airliner, Airport homebase) { this.Airliner = airliner; this.Purchased = purchased; this.PurchasedDate = purchasedDate; this.Airliner.Airline = airline; this.Homebase = homebase; this.Name = airliner.TailNumber; this.Statistics = new AirlinerStatistics(this); this.LastCMaintenance = this.Airliner.BuiltDate; this.LastAMaintenance = this.Airliner.BuiltDate; this.LastBMaintenance = this.Airliner.BuiltDate; this.LastDMaintenance = this.Airliner.BuiltDate; this.Status = AirlinerStatus.Stopped; this.MaintRoutes = new List<RouteModel.Route>(); this.CurrentPosition = this.Homebase;//new GeoCoordinate(this.Homebase.Profile.Coordinates.Latitude,this.Homebase.Profile.Coordinates.Longitude); this.Routes = new List<Route>(); this.Pilots = new List<Pilot>(); this.InsurancePolicies = new List<AirlinerInsurance>(); this.MaintenanceHistory = new Dictionary<Invoice, string>(); }
//adds an airliner to the airlines fleet public void addAirliner(FleetAirliner.PurchasedType type, Airliner airliner, Airport homeBase) { addAirliner(new FleetAirliner(type,GameObject.GetInstance().GameTime, this,airliner, homeBase)); }
private ComboBox cbAirport; // cbName; #endregion Fields #region Constructors public PanelUsedAirliner(PageAirliners parent, Airliner airliner) : base(parent) { this.Airliner = airliner; StackPanel panelAirliner = new StackPanel(); panelAirliner.Children.Add(PanelAirliner.createQuickInfoPanel(airliner.Type)); this.addObject(panelAirliner); TextBlock txtHeader = new TextBlock(); txtHeader.Uid = "1001"; txtHeader.Margin = new System.Windows.Thickness(0, 5, 0, 0); txtHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; txtHeader.SetResourceReference(TextBlock.BackgroundProperty, "HeaderBackgroundBrush2"); txtHeader.FontWeight = FontWeights.Bold; txtHeader.Text = Translator.GetInstance().GetString("PanelUsedAirliner", txtHeader.Uid); this.addObject(txtHeader); ListBox lbAirlineInfo = new ListBox(); lbAirlineInfo.ItemContainerStyleSelector = new ListBoxItemStyleSelector(); lbAirlineInfo.SetResourceReference(ListBox.ItemTemplateProperty, "QuickInfoItem"); this.addObject(lbAirlineInfo); lbAirlineInfo.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PanelUsedAirliner", "1002"), UICreator.CreateTextBlock(string.Format("{0} ({1} years old)", this.Airliner.BuiltDate.ToShortDateString(), this.Airliner.Age)))); WrapPanel panelTailNumber = new WrapPanel(); TextBlock txtTailNumber = UICreator.CreateTextBlock(this.Airliner.TailNumber); txtTailNumber.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; panelTailNumber.Children.Add(txtTailNumber); ContentControl ccFlag = new ContentControl(); ccFlag.SetResourceReference(ContentControl.ContentTemplateProperty, "CountryFlagLongItem"); ccFlag.Content = new CountryCurrentCountryConverter().Convert(Countries.GetCountryFromTailNumber(this.Airliner.TailNumber)); ccFlag.Margin = new Thickness(10, 0, 0, 0); panelTailNumber.Children.Add(ccFlag); lbAirlineInfo.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PanelUsedAirliner", "1003"), panelTailNumber)); lbAirlineInfo.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PanelUsedAirliner", "1004"), UICreator.CreateTextBlock(string.Format("{0:0.##} {1}", new NumberToUnitConverter().Convert(this.Airliner.Flown), new StringToLanguageConverter().Convert("km."))))); lbAirlineInfo.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PanelUsedAirliner", "1005"), UICreator.CreateTextBlock(string.Format("{0:0.##} {1}", new NumberToUnitConverter().Convert(this.Airliner.LastServiceCheck),new StringToLanguageConverter().Convert("km."))))); foreach (AirlinerClass aClass in this.Airliner.Classes) { TextBlock txtClass = UICreator.CreateTextBlock(new TextUnderscoreConverter().Convert(aClass.Type, null, null, null).ToString()); txtClass.FontWeight = FontWeights.Bold; lbAirlineInfo.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PanelUsedAirliner", "1006"), txtClass)); foreach (AirlinerFacility.FacilityType type in Enum.GetValues(typeof(AirlinerFacility.FacilityType))) { AirlinerFacility facility = aClass.getFacility(type); lbAirlineInfo.Items.Add(new QuickInfoValue(string.Format("{0} facilities", type), UICreator.CreateTextBlock(facility.Name))); } } TextBlock txtPriceHeader = new TextBlock(); txtPriceHeader.Uid = "1101"; txtPriceHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; txtPriceHeader.SetResourceReference(TextBlock.BackgroundProperty, "HeaderBackgroundBrush2"); txtPriceHeader.Margin = new System.Windows.Thickness(0, 5, 0, 0); txtPriceHeader.FontWeight = FontWeights.Bold; txtPriceHeader.Text = Translator.GetInstance().GetString("PanelUsedAirliner", txtPriceHeader.Uid); this.addObject(txtPriceHeader); ListBox lbPriceInfo = new ListBox(); lbPriceInfo.ItemContainerStyleSelector = new ListBoxItemStyleSelector(); lbPriceInfo.SetResourceReference(ListBox.ItemTemplateProperty, "QuickInfoItem"); this.addObject(lbPriceInfo); /* lbPriceInfo.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PanelUsedAirliner", "1102"), UICreator.CreateTextBlock(string.Format("{0:c}", this.Airliner.Price)))); lbPriceInfo.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PanelUsedAirliner", "1103"), UICreator.CreateTextBlock(string.Format("{0:c}", this.Airliner.LeasingPrice)))); lbPriceInfo.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PanelUsedAirliner", "1104"), UICreator.CreateTextBlock(string.Format("{0:c}", this.Airliner.Type.getMaintenance())))); */ lbPriceInfo.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PanelUsedAirliner", "1102"), UICreator.CreateTextBlock(new ValueCurrencyConverter().Convert(Airliner.Price).ToString()))); lbPriceInfo.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PanelUsedAirliner", "1103"), UICreator.CreateTextBlock(new ValueCurrencyConverter().Convert(this.Airliner.LeasingPrice).ToString()))); lbPriceInfo.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PanelUsedAirliner", "1104"), UICreator.CreateTextBlock(new ValueCurrencyConverter().Convert(this.Airliner.Type.getMaintenance()).ToString()))); cbAirport = new ComboBox(); cbAirport.SetResourceReference(ComboBox.ItemTemplateProperty, "AirportCountryItem"); cbAirport.Background = Brushes.Transparent; cbAirport.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbAirport.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; List<Airport> airports = GameObject.GetInstance().HumanAirline.Airports.FindAll(a=>a.getCurrentAirportFacility(GameObject.GetInstance().HumanAirline, AirportFacility.FacilityType.Service).TypeLevel > 0 && a.getMaxRunwayLength() >= this.Airliner.Type.MinRunwaylength); airports = (from a in airports orderby a.Profile.Name select a).ToList(); foreach (Airport airport in airports) cbAirport.Items.Add(airport); cbAirport.SelectedIndex = 0; lbPriceInfo.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PanelUsedAirliner", "1105"), cbAirport)); WrapPanel panelButtons = new WrapPanel(); panelButtons.Margin = new Thickness(0, 5, 0, 0); this.addObject(panelButtons); Button btnBuy = new Button(); btnBuy.Uid = "200"; btnBuy.SetResourceReference(Button.StyleProperty, "RoundedButton"); btnBuy.Height = Double.NaN; btnBuy.Width = Double.NaN; btnBuy.Content = Translator.GetInstance().GetString("PanelUsedAirliner", btnBuy.Uid); btnBuy.SetResourceReference(Button.BackgroundProperty, "ButtonBrush"); btnBuy.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; btnBuy.Click += new System.Windows.RoutedEventHandler(btnBuy_Click); panelButtons.Children.Add(btnBuy); Button btnLease = new Button(); btnLease.Uid = "201"; btnLease.SetResourceReference(Button.StyleProperty, "RoundedButton"); btnLease.Height = Double.NaN; btnLease.Width = Double.NaN; btnLease.Content = Translator.GetInstance().GetString("PanelUsedAirliner", btnLease.Uid); btnLease.SetResourceReference(Button.BackgroundProperty, "ButtonBrush"); btnLease.Margin = new Thickness(5, 0, 0, 0); btnLease.Click += new RoutedEventHandler(btnLease_Click); panelButtons.Children.Add(btnLease); }
public FleetAirliner(PurchasedType purchased, DateTime purchasedDate, Airline airline, Airliner airliner, Airport homebase) { this.Airliner = airliner; this.Purchased = purchased; this.PurchasedDate = purchasedDate; this.Airliner.Airline = airline; this.Homebase = homebase; this.Name = airliner.TailNumber; this.Statistics = new AirlinerStatistics(this); this.LastCMaintenance = this.Airliner.BuiltDate; this.LastAMaintenance = this.Airliner.BuiltDate; this.LastBMaintenance = this.Airliner.BuiltDate; this.LastDMaintenance = this.Airliner.BuiltDate; this.Status = AirlinerStatus.Stopped; this.MaintRoutes = new List <RouteModel.Route>(); this.CurrentPosition = this.Homebase;//new GeoCoordinate(this.Homebase.Profile.Coordinates.Latitude,this.Homebase.Profile.Coordinates.Longitude); this.Routes = new List <Route>(); this.Pilots = new List <Pilot>(); this.InsurancePolicies = new List <AirlinerInsurance>(); this.MaintenanceHistory = new Dictionary <Invoice, string>(); }
//buys an airliner to an airline public static FleetAirliner BuyAirliner(Airline airline, Airliner airliner, Airport airport) { return BuyAirliner(airline, airliner, airport, 0); }
//orders the airliners private void orderAirliners(double discount = 0) { DateTime deliveryDate = this.Orders.getDeliveryDate(); Guid id = Guid.NewGuid(); foreach (AirlinerOrderMVVM order in this.Orders.Orders) { for (int i = 0; i < order.Amount; i++) { Airliner airliner = new Airliner(id.ToString(), order.Type, GameObject.GetInstance().HumanAirline.Profile.Country.TailNumbers.getNextTailNumber(), deliveryDate); Model.AirlinerModel.Airliners.AddAirliner(airliner); FleetAirliner.PurchasedType pType = FleetAirliner.PurchasedType.Bought; GameObject.GetInstance().HumanAirline.addAirliner(pType, airliner, order.Homebase); airliner.clearAirlinerClasses(); foreach (AirlinerClass aClass in order.Classes) { AirlinerClass tClass = new AirlinerClass(aClass.Type, aClass.SeatingCapacity); tClass.RegularSeatingCapacity = aClass.RegularSeatingCapacity; foreach (AirlinerFacility facility in aClass.getFacilities()) tClass.setFacility(GameObject.GetInstance().HumanAirline, facility); airliner.addAirlinerClass(tClass); } } } int totalAmount = this.Orders.Orders.Sum(o => o.Amount); double price = this.Orders.Orders.Sum(o => o.Type.Price * o.Amount); double totalPrice = price * ((1 - GeneralHelpers.GetAirlinerOrderDiscount(totalAmount))) * ((100 - discount) / 100); AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -totalPrice); }
//removes an airliner from the list public static void RemoveAirliner(Airliner airliner) { airliners.Remove(airliner); }
public PopUpAirlinerConfiguration(Airliner airliner) { this.Classes = new List<AirlinerClass>(); foreach (AirlinerClass aClass in airliner.Classes) { this.Classes.Add(aClass); } this.Type = airliner.Type; createPopUp(); }
public AirlinerMVVM(Airliner airliner) { this.Airliner = airliner; this.IsSelected = false; }
private void btnOrder_Click(object sender, RoutedEventArgs e) { Boolean contractedOrder = false; Boolean tryOrder = true; Airport airport = (Airport)cbAirport.SelectedItem; if (airport == null) { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2002"), Translator.GetInstance().GetString("MessageBox", "2002", "message"), WPFMessageBoxButtons.Ok); } else { if (GameObject.GetInstance().HumanAirline.Contract != null) { if (GameObject.GetInstance().HumanAirline.Contract.Manufacturer == this.Manufacturer) contractedOrder = true; else { double terminationFee = GameObject.GetInstance().HumanAirline.Contract.getTerminationFee(); WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2010"), string.Format(Translator.GetInstance().GetString("MessageBox", "2010", "message"), GameObject.GetInstance().HumanAirline.Contract.Manufacturer.Name, terminationFee), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -terminationFee); GameObject.GetInstance().HumanAirline.Contract = null; } tryOrder = result == WPFMessageBoxResult.Yes; } } if (tryOrder) { int totalAmount = orders.Sum(o => o.Amount); double price = orders.Sum(o => o.Type.Price * o.Amount); double totalPrice = price * ((1 - GeneralHelpers.GetAirlinerOrderDiscount(totalAmount))); if (contractedOrder) totalPrice = totalPrice * ((100 - GameObject.GetInstance().HumanAirline.Contract.Discount) / 100); double downpaymentPrice = 0; downpaymentPrice = totalPrice * (GameObject.GetInstance().Difficulty.PriceLevel / 10); if (cbDownPayment.IsChecked.Value) { if (downpaymentPrice > GameObject.GetInstance().HumanAirline.Money) { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2001"), Translator.GetInstance().GetString("MessageBox", "2001", "message"), WPFMessageBoxButtons.Ok); } else { WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2009"), string.Format(Translator.GetInstance().GetString("MessageBox", "2009", "message"), totalPrice, downpaymentPrice), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { foreach (AirlinerOrder order in orders) { for (int i = 0; i < order.Amount; i++) { Guid id = Guid.NewGuid(); Airliner airliner = new Airliner(id.ToString(), order.Type, GameObject.GetInstance().HumanAirline.Profile.Country.TailNumbers.getNextTailNumber(), dpDate.SelectedDate.Value); airliner.clearAirlinerClasses(); foreach (AirlinerClass aClass in order.Classes) { AirlinerClass tClass = new AirlinerClass(aClass.Type, aClass.SeatingCapacity); tClass.RegularSeatingCapacity = aClass.RegularSeatingCapacity; foreach (AirlinerFacility facility in aClass.getFacilities()) tClass.setFacility(GameObject.GetInstance().HumanAirline, facility); airliner.addAirlinerClass(tClass); } Airliners.AddAirliner(airliner); FleetAirliner.PurchasedType pType = FleetAirliner.PurchasedType.BoughtDownPayment; GameObject.GetInstance().HumanAirline.addAirliner(pType, airliner, airport); } } if (contractedOrder) GameObject.GetInstance().HumanAirline.Contract.PurchasedAirliners += orders.Sum(o => o.Amount); AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -downpaymentPrice); PageNavigator.NavigateTo(new PageAirliners()); } } } else { if (totalPrice > GameObject.GetInstance().HumanAirline.Money) { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2001"), Translator.GetInstance().GetString("MessageBox", "2001", "message"), WPFMessageBoxButtons.Ok); } else { if (orders.Sum(o => o.Amount) > 0) { WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2008"), string.Format(Translator.GetInstance().GetString("MessageBox", "2008", "message"), totalPrice), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { if (contractedOrder) AirlineHelpers.OrderAirliners(GameObject.GetInstance().HumanAirline, orders, airport, dpDate.SelectedDate.Value, GameObject.GetInstance().HumanAirline.Contract.Discount); else AirlineHelpers.OrderAirliners(GameObject.GetInstance().HumanAirline, orders, airport, dpDate.SelectedDate.Value); PageNavigator.NavigateTo(new PageAirliners()); } if (contractedOrder) GameObject.GetInstance().HumanAirline.Contract.PurchasedAirliners += orders.Sum(o => o.Amount); } } } } this.ParentPage.updatePage(); } }
public static object ShowPopUp(Airliner airliner) { PopUpWindow window = new PopUpAirlinerConfiguration(airliner); window.ShowDialog(); return window.Selected; }
//creates the airliner classes for an airliner public static void CreateAirlinerClasses(Airliner airliner) { if (airliner.Type is AirlinerPassengerType) { Configuration airlinerTypeConfiguration = Configurations.GetConfigurations(Configuration.ConfigurationType.AirlinerType).Find(c=>((AirlinerTypeConfiguration)c).Airliner == airliner.Type && ((AirlinerTypeConfiguration)c).Period.From <= airliner.BuiltDate && ((AirlinerTypeConfiguration)c).Period.To> airliner.BuiltDate) ; if (airlinerTypeConfiguration == null) { airliner.clearAirlinerClasses(); AirlinerConfiguration configuration = null; int classes = rnd.Next(0, ((AirlinerPassengerType)airliner.Type).MaxAirlinerClasses) +1; if (GameObject.GetInstance().GameTime.Year >= (int)AirlinerClass.ClassType.Business_Class) { if (classes == 1) configuration = (AirlinerConfiguration)Configurations.GetStandardConfiguration("200"); if (classes == 2) configuration = (AirlinerConfiguration)Configurations.GetStandardConfiguration("202"); if (classes == 3) configuration = (AirlinerConfiguration)Configurations.GetStandardConfiguration("203"); } else { if (classes == 1) configuration = (AirlinerConfiguration)Configurations.GetStandardConfiguration("200"); if (classes == 2) configuration = (AirlinerConfiguration)Configurations.GetStandardConfiguration("201"); if (classes == 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(airliner.Airline, facility); airlinerClass.SeatingCapacity = Convert.ToInt16(Convert.ToDouble(airlinerClass.RegularSeatingCapacity) / airlinerClass.getFacility(AirlinerFacility.FacilityType.Seat).SeatUses); airliner.addAirlinerClass(airlinerClass); } int seatingDiff = ((AirlinerPassengerType)airliner.Type).MaxSeatingCapacity - configuration.MinimumSeats; airliner.getAirlinerClass(AirlinerClass.ClassType.Economy_Class).RegularSeatingCapacity += seatingDiff; AirlinerFacility seatingFacility = airliner.getAirlinerClass(AirlinerClass.ClassType.Economy_Class).getFacility(AirlinerFacility.FacilityType.Seat); int extraSeats = (int)(seatingDiff / seatingFacility.SeatUses); airliner.getAirlinerClass(AirlinerClass.ClassType.Economy_Class).SeatingCapacity += extraSeats; } else { airliner.clearAirlinerClasses(); 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(airliner.Airline, facility); airlinerClass.SeatingCapacity = Convert.ToInt16(Convert.ToDouble(airlinerClass.RegularSeatingCapacity) / airlinerClass.getFacility(AirlinerFacility.FacilityType.Seat).SeatUses); airliner.addAirlinerClass(airlinerClass); } } } else if (airliner.Type is AirlinerCargoType) { airliner.clearAirlinerClasses(); AirlinerClass cargoClass = new AirlinerClass(AirlinerClass.ClassType.Economy_Class, 0); airliner.addAirlinerClass(cargoClass); } }
/*! create a random airliner with a minimum range. */ private static Airliner CreateAirliner(double minRange) { Guid id = Guid.NewGuid(); List<AirlinerType> types = AirlinerTypes.GetTypes(delegate(AirlinerType t) { return t.Range >= minRange && t.Produced.From.Year < GameObject.GetInstance().GameTime.Year && t.Produced.To > GameObject.GetInstance().GameTime.AddYears(-30); }); int typeNumber = rnd.Next(types.Count); AirlinerType type = types[typeNumber]; int countryNumber = rnd.Next(Countries.GetCountries().Count() - 1); Country country = Countries.GetCountries()[countryNumber]; int builtYear = rnd.Next(Math.Max(type.Produced.From.Year, GameObject.GetInstance().GameTime.Year - 30), Math.Min(GameObject.GetInstance().GameTime.Year-1, type.Produced.To.Year)); Airliner airliner = new Airliner(id.ToString(), type, country.TailNumbers.getNextTailNumber(), new DateTime(builtYear, 1, 1)); if (airliner.TailNumber.Length < 2) typeNumber = 0; int age = MathHelpers.CalculateAge(airliner.BuiltDate, GameObject.GetInstance().GameTime); long kmPerYear = rnd.Next(100000, 1000000); long km = kmPerYear * age; airliner.Flown = km; CreateAirlinerClasses(airliner); return airliner; }
/*!creates the start data for an airline */ private static void CreateAirlineStartData(Airline airline, AirlineStartData startData) { AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1); AirportFacility cargoTerminal = AirportFacilities.GetFacilities(AirportFacility.FacilityType.Cargo).Find(f => f.TypeLevel > 0); // int difficultyFactor = GameObject.GetInstance().Difficulty.AILevel > 1 ? 2 : 1; //level easy int startDataFactor = Convert.ToInt16(GameObject.GetInstance().Difficulty.StartDataLevel); var startroutes = startData.Routes.FindAll(r => r.Opened <= GameObject.GetInstance().GameTime.Year && r.Closed >= GameObject.GetInstance().GameTime.Year); //creates the routes var sRoutes = startroutes.GetRange(0, startroutes.Count / startDataFactor); Parallel.ForEach(sRoutes, startRoute => { Airport dest1 = Airports.GetAirport(startRoute.Destination1); Airport dest2 = Airports.GetAirport(startRoute.Destination2); if (dest1 != null && dest2 != null) { //if (dest1.getAirportFacility(airline, AirportFacility.FacilityType.CheckIn).TypeLevel == 0) //dest1.addAirportFacility(airline, checkinFacility, GameObject.GetInstance().GameTime); //if (dest2.getAirportFacility(airline, AirportFacility.FacilityType.CheckIn).TypeLevel == 0) //dest2.addAirportFacility(airline, checkinFacility, GameObject.GetInstance().GameTime); if (dest1.getAirportFacility(airline, AirportFacility.FacilityType.Cargo).TypeLevel == 0 && dest1.getAirportFacility(null, AirportFacility.FacilityType.Cargo).TypeLevel == 0 && airline.AirlineRouteFocus == Route.RouteType.Cargo) dest1.addAirportFacility(airline, cargoTerminal, GameObject.GetInstance().GameTime); if (dest2.getAirportFacility(airline, AirportFacility.FacilityType.Cargo).TypeLevel == 0 && dest2.getAirportFacility(null, AirportFacility.FacilityType.Cargo).TypeLevel == 0 && airline.AirlineRouteFocus == Route.RouteType.Cargo) dest2.addAirportFacility(airline, cargoTerminal, GameObject.GetInstance().GameTime); if (!AirportHelpers.HasFreeGates(dest1, airline)) AirportHelpers.RentGates(dest1, airline, AirportContract.ContractType.Low_Service); if (!AirportHelpers.HasFreeGates(dest2, airline)) AirportHelpers.RentGates(dest2, airline, AirportContract.ContractType.Low_Service); Guid id = Guid.NewGuid(); Route route = null; double price = PassengerHelpers.GetPassengerPrice(dest1, dest2); if (startRoute.RouteType == Route.RouteType.Mixed || startRoute.RouteType == Route.RouteType.Passenger) { route = new PassengerRoute(id.ToString(), dest1, dest2, GameObject.GetInstance().GameTime, price); } if (startRoute.RouteType == Route.RouteType.Cargo) route = new CargoRoute(id.ToString(), dest1, dest2, GameObject.GetInstance().GameTime, PassengerHelpers.GetCargoPrice(dest1, dest2)); KeyValuePair<Airliner, Boolean>? airliner = null; if (startRoute.Type != null) { double distance = MathHelpers.GetDistance(dest1, dest2); if (startRoute.Type.Range > distance) { airliner = new KeyValuePair<Airliner, bool>(Airliners.GetAirlinersForSale(a => a.Type == startRoute.Type).FirstOrDefault(), true); if (airliner.Value.Key == null) { id = Guid.NewGuid(); Airliner nAirliner = new Airliner(id.ToString(), startRoute.Type, airline.Profile.Country.TailNumbers.getNextTailNumber(), GameObject.GetInstance().GameTime); Airliners.AddAirliner(nAirliner); nAirliner.clearAirlinerClasses(); AirlinerHelpers.CreateAirlinerClasses(nAirliner); airliner = new KeyValuePair<Airliner, bool>(nAirliner, true); } } } Boolean leaseAircraft = airline.Profile.PrimaryPurchasing == AirlineProfile.PreferedPurchasing.Leasing; if (airliner == null) { airliner = AIHelpers.GetAirlinerForRoute(airline, dest2, dest1, leaseAircraft, startRoute.RouteType == Route.RouteType.Cargo, true); if (airliner == null && airline.Profile.PrimaryPurchasing == AirlineProfile.PreferedPurchasing.Random) AIHelpers.GetAirlinerForRoute(airline, dest2, dest1, true, startRoute.RouteType == Route.RouteType.Cargo, true); } if (airliner != null) { FleetAirliner fAirliner = AirlineHelpers.AddAirliner(airline, airliner.Value.Key, airline.Airports[0],leaseAircraft); fAirliner.addRoute(route); fAirliner.Status = FleetAirliner.AirlinerStatus.To_route_start; AirlineHelpers.HireAirlinerPilots(fAirliner); route.LastUpdated = GameObject.GetInstance().GameTime; if (startRoute.RouteType == Route.RouteType.Mixed || startRoute.RouteType == Route.RouteType.Passenger) { AirlinerHelpers.CreateAirlinerClasses(fAirliner.Airliner); RouteClassesConfiguration configuration = AIHelpers.GetRouteConfiguration((PassengerRoute)route); foreach (RouteClassConfiguration classConfiguration in configuration.getClasses()) { ((PassengerRoute)route).getRouteAirlinerClass(classConfiguration.Type).FarePrice = price * GeneralHelpers.ClassToPriceFactor(classConfiguration.Type); foreach (RouteFacility rFacility in classConfiguration.getFacilities()) ((PassengerRoute)route).getRouteAirlinerClass(classConfiguration.Type).addFacility(rFacility); } AIHelpers.CreateRouteTimeTable(route, fAirliner); } if (startRoute.RouteType == Route.RouteType.Cargo) { AIHelpers.CreateCargoRouteTimeTable(route, fAirliner); } } airline.addRoute(route); } }); //adds the airliners Parallel.ForEach(startData.Airliners, airliners => { AirlinerType type = AirlinerTypes.GetType(airliners.Type); int totalSpan = 2010 - 1960; int yearSpan = GameObject.GetInstance().GameTime.Year - 1960; double valueSpan = Convert.ToDouble(airliners.AirlinersLate - airliners.AirlinersEarly); double span = valueSpan / Convert.ToDouble(totalSpan); int numbers = Math.Max(1, Convert.ToInt16(span * yearSpan) / startDataFactor); //type==null if (type.Produced.From <= GameObject.GetInstance().GameTime) { for (int i = 0; i < Math.Max(numbers, airliners.AirlinersEarly); i++) { Guid id = Guid.NewGuid(); int countryNumber = rnd.Next(Countries.GetCountries().Count() - 1); Country country = Countries.GetCountries()[countryNumber]; int builtYear = rnd.Next(type.Produced.From.Year, Math.Min(GameObject.GetInstance().GameTime.Year - 1, type.Produced.To.Year)); Airliner airliner = new Airliner(id.ToString(), type, country.TailNumbers.getNextTailNumber(), new DateTime(builtYear, 1, 1)); int age = MathHelpers.CalculateAge(airliner.BuiltDate, GameObject.GetInstance().GameTime); long kmPerYear = rnd.Next(100000, 1000000); long km = kmPerYear * age; airliner.Flown = km; Airliners.AddAirliner(airliner); Boolean leaseAircraft = airline.Profile.PrimaryPurchasing == AirlineProfile.PreferedPurchasing.Leasing; FleetAirliner fAirliner = AirlineHelpers.AddAirliner(airline, airliner, airline.Airports[0],leaseAircraft); fAirliner.Status = FleetAirliner.AirlinerStatus.Stopped; AirlineHelpers.HireAirlinerPilots(fAirliner); AirlinerHelpers.CreateAirlinerClasses(fAirliner.Airliner); } } }); //the origin routes Parallel.ForEach(startData.OriginRoutes, routes => { Airport origin = Airports.GetAirport(routes.Origin); if (origin != null) { for (int i = 0; i < Math.Min(routes.Destinations / startDataFactor, origin.Terminals.getFreeGates()); i++) { //if (origin.getAirportFacility(airline, AirportFacility.FacilityType.CheckIn).TypeLevel == 0) //origin.addAirportFacility(airline, checkinFacility, GameObject.GetInstance().GameTime); if (!AirportHelpers.HasFreeGates(origin, airline)) AirportHelpers.RentGates(origin, airline, AirportContract.ContractType.Low_Service); Airport destination = GetStartDataRoutesDestination(routes); //if (destination.getAirportFacility(airline, AirportFacility.FacilityType.CheckIn).TypeLevel == 0) //destination.addAirportFacility(airline, checkinFacility, GameObject.GetInstance().GameTime); if (!AirportHelpers.HasFreeGates(destination, airline)) AirportHelpers.RentGates(destination, airline, AirportContract.ContractType.Low_Service); Guid id = Guid.NewGuid(); Route route = null; double price = PassengerHelpers.GetPassengerPrice(origin, destination); if (routes.RouteType == Route.RouteType.Mixed || routes.RouteType == Route.RouteType.Passenger) route = new PassengerRoute(id.ToString(), origin, destination, GameObject.GetInstance().GameTime, price); if (routes.RouteType == Route.RouteType.Cargo) route = new CargoRoute(id.ToString(), origin, destination, GameObject.GetInstance().GameTime, PassengerHelpers.GetCargoPrice(origin, destination)); Boolean leaseAircraft = airline.Profile.PrimaryPurchasing == AirlineProfile.PreferedPurchasing.Leasing; KeyValuePair<Airliner, Boolean>? airliner = AIHelpers.GetAirlinerForRoute(airline, origin, destination, leaseAircraft, routes.RouteType == Route.RouteType.Cargo, true); if (airliner == null && airline.Profile.PrimaryPurchasing == AirlineProfile.PreferedPurchasing.Random) airliner = AIHelpers.GetAirlinerForRoute(airline, origin, destination, true, routes.RouteType == Route.RouteType.Cargo, true); double distance = MathHelpers.GetDistance(origin, destination); if (airliner != null) { FleetAirliner fAirliner = AirlineHelpers.AddAirliner(airline, airliner.Value.Key, airline.Airports[0], leaseAircraft); fAirliner.addRoute(route); fAirliner.Status = FleetAirliner.AirlinerStatus.To_route_start; AirlineHelpers.HireAirlinerPilots(fAirliner); route.LastUpdated = GameObject.GetInstance().GameTime; if (routes.RouteType == Route.RouteType.Passenger || routes.RouteType == Route.RouteType.Mixed) { AirlinerHelpers.CreateAirlinerClasses(fAirliner.Airliner); RouteClassesConfiguration configuration = AIHelpers.GetRouteConfiguration((PassengerRoute)route); foreach (RouteClassConfiguration classConfiguration in configuration.getClasses()) { ((PassengerRoute)route).getRouteAirlinerClass(classConfiguration.Type).FarePrice = price * GeneralHelpers.ClassToPriceFactor(classConfiguration.Type); foreach (RouteFacility rFacility in classConfiguration.getFacilities()) ((PassengerRoute)route).getRouteAirlinerClass(classConfiguration.Type).addFacility(rFacility); } AIHelpers.CreateRouteTimeTable(route, fAirliner); } if (routes.RouteType == Route.RouteType.Cargo) AIHelpers.CreateCargoRouteTimeTable(route, fAirliner); airline.addRoute(route); } } } }); }
//removes an airliner from the used list public void removeUsedAirliner(Airliner airliner) { lbUsedAirliners.Items.Remove(airliner); }
//orders a number of airliners for an airline public static void OrderAirliners(Airline airline, List<AirlinerOrder> orders, Airport airport, DateTime deliveryDate, double discount) { Guid id = Guid.NewGuid(); foreach (AirlinerOrder order in orders) { for (int i = 0; i < order.Amount; i++) { Airliner airliner = new Airliner(id.ToString(), order.Type, airline.Profile.Country.TailNumbers.getNextTailNumber(), deliveryDate); Airliners.AddAirliner(airliner); FleetAirliner.PurchasedType pType = FleetAirliner.PurchasedType.Bought; airline.addAirliner(pType, airliner, airport); airliner.clearAirlinerClasses(); foreach (AirlinerClass aClass in order.Classes) { AirlinerClass tClass = new AirlinerClass(aClass.Type, aClass.SeatingCapacity); tClass.RegularSeatingCapacity = aClass.RegularSeatingCapacity; foreach (AirlinerFacility facility in aClass.getFacilities()) tClass.setFacility(airline, facility); airliner.addAirlinerClass(tClass); } } } int totalAmount = orders.Sum(o => o.Amount); double price = orders.Sum(o => o.Type.Price * o.Amount); double totalPrice = price * ((1 - GeneralHelpers.GetAirlinerOrderDiscount(totalAmount))) * ((100 - discount) / 100); AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -totalPrice); }
private void btnOrder_Click(object sender, RoutedEventArgs e) { Boolean hasHomebases = true; foreach (AirlinerOrderMVVM order in this.Orders.Orders) { if (order.Homebase == null) hasHomebases = false; } Boolean contractedOrder = false; Boolean tryOrder = true; DateTime deliveryDate = this.Orders.getDeliveryDate(); if (!hasHomebases) { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2002"), Translator.GetInstance().GetString("MessageBox", "2002", "message"), WPFMessageBoxButtons.Ok); } else { if (GameObject.GetInstance().HumanAirline.Contract != null) { if (GameObject.GetInstance().HumanAirline.Contract.Manufacturer == this.Manufacturer) contractedOrder = true; else { double terminationFee = GameObject.GetInstance().HumanAirline.Contract.getTerminationFee(); WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2010"), string.Format(Translator.GetInstance().GetString("MessageBox", "2010", "message"), GameObject.GetInstance().HumanAirline.Contract.Manufacturer.Name, terminationFee), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -terminationFee); GameObject.GetInstance().HumanAirline.Contract = null; this.Contract.Contracted = null; } tryOrder = result == WPFMessageBoxResult.Yes; } } if (tryOrder) { int totalAmount = this.Orders.Orders.Sum(o => o.Amount); double price = this.Orders.Orders.Sum(o => o.Type.Price * o.Amount); double totalPrice = price * ((1 - GeneralHelpers.GetAirlinerOrderDiscount(totalAmount))); if (contractedOrder) totalPrice = totalPrice * ((100 - GameObject.GetInstance().HumanAirline.Contract.Discount) / 100); double downpaymentPrice = 0; downpaymentPrice = totalPrice * (GameObject.GetInstance().Difficulty.PriceLevel / 10); if (cbDownPayment.IsChecked.Value) { if (downpaymentPrice > GameObject.GetInstance().HumanAirline.Money) { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2001"), Translator.GetInstance().GetString("MessageBox", "2001", "message"), WPFMessageBoxButtons.Ok); } else { WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2009"), string.Format(Translator.GetInstance().GetString("MessageBox", "2009", "message"), totalPrice, downpaymentPrice), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { foreach (AirlinerOrderMVVM order in this.Orders.Orders) { for (int i = 0; i < order.Amount; i++) { Guid id = Guid.NewGuid(); Airliner airliner = new Airliner(id.ToString(), order.Type, GameObject.GetInstance().HumanAirline.Profile.Country.TailNumbers.getNextTailNumber(), deliveryDate); airliner.clearAirlinerClasses(); foreach (AirlinerClass aClass in order.Classes) { AirlinerClass tClass = new AirlinerClass(aClass.Type, aClass.SeatingCapacity); tClass.RegularSeatingCapacity = aClass.RegularSeatingCapacity; foreach (AirlinerFacility facility in aClass.getFacilities()) tClass.setFacility(GameObject.GetInstance().HumanAirline, facility); airliner.addAirlinerClass(tClass); } Model.AirlinerModel.Airliners.AddAirliner(airliner); FleetAirliner.PurchasedType pType = FleetAirliner.PurchasedType.BoughtDownPayment; GameObject.GetInstance().HumanAirline.addAirliner(pType, airliner, order.Homebase); } } if (contractedOrder) GameObject.GetInstance().HumanAirline.Contract.PurchasedAirliners += this.Orders.Orders.Sum(o => o.Amount); AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -downpaymentPrice); TabControl tab_main = UIHelpers.FindChild<TabControl>(this.Tag as Page, "tabMenu"); if (tab_main != null) { var matchingItem = tab_main.Items.Cast<TabItem>() .Where(item => item.Tag.ToString() == "Order") .FirstOrDefault(); tab_main.SelectedItem = matchingItem; } } } } else { if (totalPrice > GameObject.GetInstance().HumanAirline.Money) { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2001"), Translator.GetInstance().GetString("MessageBox", "2001", "message"), WPFMessageBoxButtons.Ok); } else { if (this.Orders.Orders.Sum(o => o.Amount) > 0) { WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2008"), string.Format(Translator.GetInstance().GetString("MessageBox", "2008", "message"), totalPrice), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { orderAirliners(contractedOrder ? GameObject.GetInstance().HumanAirline.Contract.Discount : 0); TabControl tab_main = UIHelpers.FindChild<TabControl>(this.Tag as Page, "tabMenu"); if (tab_main != null) { var matchingItem = tab_main.Items.Cast<TabItem>() .Where(item => item.Tag.ToString() == "Order") .FirstOrDefault(); tab_main.SelectedItem = matchingItem; } } if (contractedOrder) GameObject.GetInstance().HumanAirline.Contract.PurchasedAirliners += this.Orders.Orders.Sum(o => o.Amount); } } } } } }
//loads a game public static void LoadGame(string name) { if (null == name || name == "") { WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "101"), Translator.GetInstance().GetString("MessageBox", "101", "message"), WPFMessageBoxButtons.Ok); return; } string fileName = AppSettings.getCommonApplicationDataPath() + "\\saves\\" + name + ".sav"; XmlDocument doc = new XmlDocument(); using (FileStream fs = new FileStream(fileName, FileMode.Open)) { Stream s; s = new GZipStream(fs, CompressionMode.Decompress); doc.Load(s); s.Close(); } //doc.Load(AppSettings.getDataPath() + "\\saves\\" + name + ".xml"); XmlElement root = doc.DocumentElement; DateTime gameTime = DateTime.Parse(root.Attributes["time"].Value, new CultureInfo("de-DE")); GameObject.GetInstance().GameTime = gameTime; XmlNodeList tailnumbersList = root.SelectNodes("//tailnumbers/tailnumber"); foreach (XmlElement tailnumberNode in tailnumbersList) { Country country = Countries.GetCountry(tailnumberNode.Attributes["country"].Value); if (country != null) country.TailNumbers.LastTailNumber = tailnumberNode.Attributes["value"].Value; } XmlNodeList airlinerTypesList = root.SelectNodes("//airlinertypes/airlinertype"); foreach (XmlElement airlinerTypeNode in airlinerTypesList) { AirlinerType.TypeOfAirliner airlinerType = (AirlinerType.TypeOfAirliner)Enum.Parse(typeof(AirlinerType.TypeOfAirliner), airlinerTypeNode.Attributes["type"].Value); AirlinerType baseType = AirlinerTypes.GetType(airlinerTypeNode.Attributes["basetype"].Value); string airlinerTypeName = airlinerTypeNode.Attributes["name"].Value; AirlinerType type = null; if (airlinerType == AirlinerType.TypeOfAirliner.Passenger) { int cabincrew = Convert.ToInt16(airlinerTypeNode.Attributes["cabincrew"].Value); int passengers = Convert.ToInt16(airlinerTypeNode.Attributes["passengers"].Value); int maxclasses = Convert.ToInt16(airlinerTypeNode.Attributes["maxclasses"].Value); type = new AirlinerPassengerType(baseType.Manufacturer,airlinerTypeName,"",passengers,baseType.CockpitCrew,cabincrew,baseType.CruisingSpeed,baseType.Range,baseType.Wingspan,baseType.Length,baseType.FuelConsumption,baseType.Price,maxclasses,baseType.MinRunwaylength,baseType.FuelCapacity,baseType.Body,baseType.RangeType,baseType.Engine,baseType.Produced,baseType.ProductionRate,false,false); } if (airlinerType == AirlinerType.TypeOfAirliner.Cargo) { double cargo = Convert.ToDouble(airlinerTypeNode.Attributes["cargo"].Value,new CultureInfo("de-DE", false)); type = new AirlinerCargoType(baseType.Manufacturer,airlinerTypeName,"",baseType.CockpitCrew,cargo,baseType.CruisingSpeed,baseType.Range,baseType.Wingspan,baseType.Length,baseType.FuelConsumption,baseType.Price,baseType.MinRunwaylength,baseType.FuelCapacity,baseType.Body,baseType.RangeType,baseType.Engine,baseType.Produced,baseType.ProductionRate,false, false); } type.BaseType = baseType; AirlinerTypes.AddType(type); } Airliners.Clear(); XmlNodeList airlinersList = root.SelectNodes("//airliners/airliner"); Parallel.For(0, airlinersList.Count, i => //foreach (XmlElement airlinerNode in airlinersList) { XmlElement airlinerNode = (XmlElement)airlinersList[i]; AirlinerType type = AirlinerTypes.GetType(airlinerNode.Attributes["type"].Value); if (type != null) { string tailnumber = airlinerNode.Attributes["tailnumber"].Value; string id = airlinerNode.HasAttribute("id") ? airlinerNode.Attributes["id"].Value : tailnumber; string last_service = airlinerNode.Attributes["last_service"].Value; DateTime built = DateTime.Parse(airlinerNode.Attributes["built"].Value, new CultureInfo("de-DE", false)); double flown = Convert.ToDouble(airlinerNode.Attributes["flown"].Value, new CultureInfo("de-DE", false)); double damaged = Convert.ToDouble(airlinerNode.Attributes["damaged"].Value, new CultureInfo("de-DE", false)); Airliner airliner = new Airliner(id, type, tailnumber, built); airliner.Condition = damaged; airliner.Flown = flown; airliner.clearAirlinerClasses(); XmlNodeList airlinerClassList = airlinerNode.SelectNodes("classes/class"); foreach (XmlElement airlinerClassNode in airlinerClassList) { AirlinerClass.ClassType airlinerClassType = (AirlinerClass.ClassType)Enum.Parse(typeof(AirlinerClass.ClassType), airlinerClassNode.Attributes["type"].Value); int airlinerClassSeating = Convert.ToInt16(airlinerClassNode.Attributes["seating"].Value); AirlinerClass aClass = new AirlinerClass(airlinerClassType, airlinerClassSeating); // chs, 2011-13-10 added for loading of airliner facilities XmlNodeList airlinerClassFacilitiesList = airlinerClassNode.SelectNodes("facilities/facility"); foreach (XmlElement airlinerClassFacilityNode in airlinerClassFacilitiesList) { AirlinerFacility.FacilityType airlinerFacilityType = (AirlinerFacility.FacilityType)Enum.Parse(typeof(AirlinerFacility.FacilityType), airlinerClassFacilityNode.Attributes["type"].Value); AirlinerFacility aFacility = AirlinerFacilities.GetFacility(airlinerFacilityType, airlinerClassFacilityNode.Attributes["uid"].Value); aClass.forceSetFacility(aFacility); } airliner.addAirlinerClass(aClass); } Airliners.AddAirliner(airliner); } }); Airlines.Clear(); XmlNodeList airlinesList = root.SelectNodes("//airlines/airline[@subsidiary='False']"); foreach (XmlElement airlineNode in airlinesList) LoadAirline(airlineNode); XmlNodeList subsidiaryList = root.SelectNodes("//airlines/airline[@subsidiary='True']"); foreach (XmlElement airlineNode in subsidiaryList) LoadAirline(airlineNode); XmlNodeList airportsList = root.SelectNodes("//airports/airport"); List<Airport> airportsToKeep = new List<Airport>(); foreach (XmlElement airportNode in airportsList) { Airport airport = Airports.GetAirportFromID(airportNode.Attributes["id"].Value); airportsToKeep.Add(airport); /* * XmlElement airportPaxNode = xmlDoc.CreateElement("paxvalue"); airportPaxNode.SetAttribute("from", paxValue.FromYear.ToString()); airportPaxNode.SetAttribute("to", paxValue.ToYear.ToString()); airportPaxNode.SetAttribute("size", paxValue.Size.ToString()); airportPaxNode.SetAttribute("pax", paxValue.Pax.ToString()); airportPaxNode.SetAttribute("inflationbefore", paxValue.InflationBeforeYear.ToString()); airportPaxNode.SetAttribute("inflationafter", paxValue.InflationAfterYear.ToString()); */ airport.Income = Convert.ToInt64(airportNode.Attributes["income"].Value); airport.Profile.PaxValues.Clear(); XmlNodeList paxvaluesList = airportNode.SelectNodes("paxvalues/paxvalue"); foreach (XmlElement paxElement in paxvaluesList) { int fromYear = Convert.ToInt16(paxElement.Attributes["from"].Value); int toYear = Convert.ToInt16(paxElement.Attributes["to"].Value); GeneralHelpers.Size airportSize = (GeneralHelpers.Size)Enum.Parse(typeof(GeneralHelpers.Size), paxElement.Attributes["size"].Value); double pax = Convert.ToDouble(paxElement.Attributes["pax"].Value); double inflationBefore = Convert.ToDouble(paxElement.Attributes["inflationbefore"].Value); double inflationAfter = Convert.ToDouble(paxElement.Attributes["inflationafter"].Value); PaxValue paxValue = new PaxValue(fromYear, toYear, airportSize, pax); paxValue.InflationAfterYear = inflationAfter; paxValue.InflationBeforeYear = inflationBefore; airport.Profile.PaxValues.Add(paxValue); } XmlNodeList runwaysList = airportNode.SelectNodes("runways/runway"); foreach (XmlElement runwayElement in runwaysList) { string runwayName = runwayElement.Attributes["name"].Value; long runwayLenght = Convert.ToInt64(runwayElement.Attributes["lenght"].Value); Runway.SurfaceType runwaySurface = (Runway.SurfaceType)Enum.Parse(typeof(Runway.SurfaceType), runwayElement.Attributes["surface"].Value); DateTime runwayDate = DateTime.Parse(runwayElement.Attributes["date"].Value, new CultureInfo("de-DE", false)); airport.Runways.Add(new Runway(runwayName, runwayLenght, runwaySurface, runwayDate, false)); } XmlNodeList airportHubsList = airportNode.SelectNodes("hubs/hub"); // airport.Hubs.Clear(); foreach (XmlElement airportHubElement in airportHubsList) { Airline airline = Airlines.GetAirline(airportHubElement.Attributes["airline"].Value); // airport.Hubs.Add(new Hub(airline,null)); } XmlNodeList airportWeatherList = airportNode.SelectNodes("weathers/weather"); for (int i = 0; i < airportWeatherList.Count; i++) { XmlElement airportWeatherElement = airportWeatherList[i] as XmlElement; DateTime weatherDate = DateTime.Parse(airportWeatherElement.Attributes["date"].Value, new CultureInfo("de-DE", false)); Weather.WindDirection windDirection = (Weather.WindDirection)Enum.Parse(typeof(Weather.WindDirection), airportWeatherElement.Attributes["direction"].Value); Weather.eWindSpeed windSpeed = (Weather.eWindSpeed)Enum.Parse(typeof(Weather.eWindSpeed), airportWeatherElement.Attributes["windspeed"].Value); Weather.CloudCover cover = airportWeatherElement.HasAttribute("cover") ? (Weather.CloudCover)Enum.Parse(typeof(Weather.CloudCover), airportWeatherElement.Attributes["cover"].Value) : Weather.CloudCover.Clear; Weather.Precipitation precip = airportWeatherElement.HasAttribute("precip") ? (Weather.Precipitation)Enum.Parse(typeof(Weather.Precipitation), airportWeatherElement.Attributes["precip"].Value) : Weather.Precipitation.None; double temperatureLow = airportWeatherElement.HasAttribute("temperatureLow") ? Convert.ToDouble(airportWeatherElement.Attributes["temperaturelow"].Value, new CultureInfo("de-DE", false)) : 0; double temperatureHigh = airportWeatherElement.HasAttribute("temperatureHigh") ? Convert.ToDouble(airportWeatherElement.Attributes["temperaturehigh"].Value, new CultureInfo("de-DE", false)) : 20; XmlNodeList airportTemperatureList = airportWeatherElement.SelectNodes("temperatures/temperature"); HourlyWeather[] temperatures = new HourlyWeather[airportTemperatureList.Count]; int t = 0; foreach (XmlElement airportTemperatureNode in airportTemperatureList) { double hourlyTemperature = Convert.ToDouble(airportTemperatureNode.Attributes["temp"].Value, new CultureInfo("de-DE", false)); Weather.CloudCover hourlyCover = (Weather.CloudCover)Enum.Parse(typeof(Weather.CloudCover), airportTemperatureNode.Attributes["cover"].Value); Weather.Precipitation hourlyPrecip = (Weather.Precipitation)Enum.Parse(typeof(Weather.Precipitation), airportTemperatureNode.Attributes["precip"].Value); Weather.eWindSpeed hourlyWindspeed = (Weather.eWindSpeed)Enum.Parse(typeof(Weather.eWindSpeed), airportTemperatureNode.Attributes["windspeed"].Value); Weather.WindDirection hourlyDirection = (Weather.WindDirection)Enum.Parse(typeof(Weather.WindDirection), airportTemperatureNode.Attributes["direction"].Value); temperatures[t] = new HourlyWeather(hourlyTemperature, hourlyCover, hourlyPrecip, hourlyWindspeed, hourlyDirection); t++; } airport.Weather[i] = new Weather(weatherDate, windSpeed, windDirection, cover, precip, temperatures, temperatureLow, temperatureHigh); } XmlNodeList airportStatList = airportNode.SelectNodes("stats/stat"); foreach (XmlElement airportStatNode in airportStatList) { int year = Convert.ToInt32(airportStatNode.Attributes["year"].Value); Airline airline = Airlines.GetAirline(airportStatNode.Attributes["airline"].Value); string statType = airportStatNode.Attributes["type"].Value; int statValue = Convert.ToInt32(airportStatNode.Attributes["value"].Value); airport.Statistics.setStatisticsValue(year, airline, StatisticsTypes.GetStatisticsType(statType), statValue); } XmlNodeList airportFacilitiesList = airportNode.SelectNodes("facilities/facility"); airport.clearFacilities(); foreach (XmlElement airportFacilityNode in airportFacilitiesList) { Airline airline = Airlines.GetAirline(airportFacilityNode.Attributes["airline"].Value); AirportFacility airportFacility = AirportFacilities.GetFacility(airportFacilityNode.Attributes["name"].Value); DateTime finishedDate = DateTime.Parse(airportFacilityNode.Attributes["finished"].Value, new CultureInfo("de-DE", false)); airport.addAirportFacility(airline, airportFacility, finishedDate); } airport.Terminals.clear(); XmlNodeList terminalsList = airportNode.SelectNodes("terminals/terminal"); foreach (XmlElement terminalNode in terminalsList) { DateTime deliveryDate = DateTime.Parse(terminalNode.Attributes["delivery"].Value, new CultureInfo("de-DE", false)); Airline owner = Airlines.GetAirline(terminalNode.Attributes["owner"].Value); string terminalName = terminalNode.Attributes["name"].Value; int gates = Convert.ToInt32(terminalNode.Attributes["totalgates"].Value); Terminal terminal = new Terminal(airport, owner, terminalName, gates, deliveryDate); terminal.Gates.clear(); XmlNodeList airportGatesList = terminalNode.SelectNodes("gates/gate"); foreach (XmlElement airportGateNode in airportGatesList) { DateTime gateDeliveryDate = DateTime.Parse(airportGateNode.Attributes["delivery"].Value, new CultureInfo("de-DE", false)); Gate gate = new Gate(gateDeliveryDate); terminal.Gates.addGate(gate); } airport.addTerminal(terminal); } airport.clearAirlineContracts(); XmlNodeList contractsList = airportNode.SelectNodes("contracts/contract"); foreach (XmlElement contractNode in contractsList) { Airline contractAirline = Airlines.GetAirline(contractNode.Attributes["airline"].Value); int contractLength = Convert.ToInt16(contractNode.Attributes["length"].Value); DateTime contractDate = DateTime.Parse(contractNode.Attributes["date"].Value, new CultureInfo("de-DE", false)); int contractGates = Convert.ToInt16(contractNode.Attributes["gates"].Value); double contractPayment = Convert.ToDouble(contractNode.Attributes["payment"].Value, new CultureInfo("de-DE", false)); Boolean contractExclusive = Convert.ToBoolean(contractNode.Attributes["exclusive"].Value); Terminal contractTerminal = contractNode.HasAttribute("terminal") ? airport.Terminals.AirportTerminals.Find(t => t.Name == contractNode.Attributes["terminal"].Value) : null; AirportContract contract = new AirportContract(contractAirline, airport,AirportContract.ContractType.Full, contractDate, contractGates, contractLength, contractPayment,true,false, contractExclusive, contractTerminal); AirportHelpers.AddAirlineContract(contract); } } Airports.RemoveAirports(a => !airportsToKeep.Contains(a)); XmlNodeList airportDestinationsList = root.SelectNodes("//airportdestinations/airportdestination"); foreach (XmlElement airportDestinationElement in airportDestinationsList) { Airport targetAirport = Airports.GetAirport(airportDestinationElement.Attributes["id"].Value); if (targetAirport != null) { targetAirport.clearDestinationPassengers(); XmlNodeList destinationsList = airportDestinationElement.SelectNodes("destinations/destination"); Parallel.For(0, destinationsList.Count, i => //foreach (XmlElement destinationElement in destinationsList) { XmlElement destinationElement = (XmlElement)destinationsList[i]; Airport destAirport = Airports.GetAirport(destinationElement.Attributes["id"].Value); if (destAirport != null) { ushort rate = ushort.Parse(destinationElement.Attributes["rate"].Value); long destPassengers = Convert.ToInt64(destinationElement.Attributes["passengers"].Value); targetAirport.addPassengerDestinationStatistics(destAirport, destPassengers); targetAirport.addDestinationPassengersRate(new DestinationDemand(destAirport.Profile.IATACode, rate)); if (destinationElement.HasAttribute("cargo")) { targetAirport.addDestinationCargoRate(new DestinationDemand(destAirport.Profile.IATACode, ushort.Parse(destinationElement.Attributes["cargo"].Value))); targetAirport.addCargoDestinationStatistics(destAirport, Convert.ToDouble(destinationElement.Attributes["cargostats"].Value, new CultureInfo("de-DE", false))); } } }); } } Instructors.Clear(); XmlNodeList instructorsList = root.SelectNodes("//instructors/instructor"); foreach (XmlElement instructorNode in instructorsList) { string firstname = instructorNode.Attributes["firstname"].Value; string lastname = instructorNode.Attributes["lastname"].Value; DateTime birthdate = DateTime.Parse(instructorNode.Attributes["birthdate"].Value, new CultureInfo("de-DE", false)); Town town = Towns.GetTown(instructorNode.Attributes["town"].Value); //Pilot.PilotRating rating = (Pilot.PilotRating)Enum.Parse(typeof(Pilot.PilotRating), instructorNode.Attributes["rating"].Value); string id = instructorNode.Attributes["id"].Value; Instructor instructor = new Instructor(new PilotProfile(firstname, lastname, birthdate, town),PilotRatings.GetRating("A")); if (id != "-") { FlightSchool fs = Airlines.GetAllAirlines().SelectMany(a => a.FlightSchools).Where(f => f.ID == id).FirstOrDefault(); instructor.FlightSchool = fs; fs.addInstructor(instructor); } XmlNodeList studentsList = instructorNode.SelectNodes("students/student"); foreach (XmlElement studentNode in studentsList) { PilotStudent student = instructor.FlightSchool.Students.Find(s => s.Profile.Name == studentNode.Attributes["name"].Value); student.Instructor = instructor; instructor.addStudent(student); } Instructors.AddInstructor(instructor); } if (Instructors.GetInstructors().Count == 0) GeneralHelpers.CreateInstructors(75 * Airlines.GetAllAirlines().Count); Pilots.Clear(); XmlNodeList pilotsList = root.SelectNodes("//pilots/pilot"); foreach (XmlElement pilotNode in pilotsList) { string firstname = pilotNode.Attributes["firstname"].Value; string lastname = pilotNode.Attributes["lastname"].Value; DateTime birthdate = DateTime.Parse(pilotNode.Attributes["birthdate"].Value, new CultureInfo("de-DE", false)); Town town = Towns.GetTown(pilotNode.Attributes["town"].Value); DateTime educationdate = DateTime.Parse(pilotNode.Attributes["education"].Value, new CultureInfo("de-DE", false)); //Pilot.PilotRating rating = (Pilot.PilotRating)Enum.Parse(typeof(Pilot.PilotRating), pilotNode.Attributes["rating"].Value); Pilot pilot = new Pilot(new PilotProfile(firstname, lastname, birthdate, town), educationdate, PilotRatings.GetRating("B")); if (pilotNode.Attributes["airline"].Value != "-") { Airline pilotAirline = Airlines.GetAirline(pilotNode.Attributes["airline"].Value); DateTime airlinesigneddate = DateTime.Parse(pilotNode.Attributes["airlinesigned"].Value, new CultureInfo("de-DE", false)); pilotAirline.addPilot(pilot); pilot.AirlineSignedDate = airlinesigneddate; if (pilotNode.Attributes["airliner"].Value != "-") { FleetAirliner airliner = pilotAirline.Fleet.Find(f => f.Airliner.ID == pilotNode.Attributes["airliner"].Value); if (airliner != null) { pilot.Airliner = airliner; airliner.addPilot(pilot); } } } Pilots.AddPilot(pilot); } if (Pilots.GetNumberOfPilots() == 0) { Random rnd = new Random(); GeneralHelpers.CreatePilots(100 * Airlines.GetAllAirlines().Count); foreach (FleetAirliner airliner in Airlines.GetAllAirlines().SelectMany(a => a.Fleet)) { Pilot pilot = Pilots.GetPilots()[rnd.Next(Pilots.GetNumberOfPilots())]; airliner.Airliner.Airline.addPilot(pilot); pilot.Airliner = airliner; airliner.addPilot(pilot); } } Alliances.Clear(); XmlNodeList alliancesList = root.SelectNodes("//alliances/alliance"); foreach (XmlElement allianceNode in alliancesList) { string allianceName = allianceNode.Attributes["name"].Value; DateTime formationDate = DateTime.Parse(allianceNode.Attributes["formation"].Value, new CultureInfo("de-DE")); Airport allianceHeadquarter = Airports.GetAirport(allianceNode.Attributes["headquarter"].Value); Alliance alliance = new Alliance(formationDate, allianceName, allianceHeadquarter); XmlNodeList membersList = allianceNode.SelectNodes("members/member"); foreach (XmlElement memberNode in membersList) { Airline allianceMember = Airlines.GetAirline(memberNode.Attributes["airline"].Value); DateTime joinedDate = DateTime.Parse(memberNode.Attributes["joined"].Value, new CultureInfo("de-DE")); if (allianceMember != null) alliance.addMember(new AllianceMember(allianceMember, joinedDate)); } XmlNodeList pendingsList = allianceNode.SelectNodes("pendings/pending"); foreach (XmlElement pendingNode in pendingsList) { Airline pendingAirline = Airlines.GetAirline(pendingNode.Attributes["airline"].Value); DateTime pendingDate = DateTime.Parse(pendingNode.Attributes["date"].Value, new CultureInfo("de-DE")); PendingAllianceMember.AcceptType pendingType = (PendingAllianceMember.AcceptType)Enum.Parse(typeof(PendingAllianceMember.AcceptType), pendingNode.Attributes["type"].Value); alliance.addPendingMember(new PendingAllianceMember(pendingDate, alliance, pendingAirline, pendingType)); } Alliances.AddAlliance(alliance); } Configurations.Clear(); XmlNodeList configurationsList = root.SelectNodes("//configurations/configuration"); foreach (XmlElement confElement in configurationsList) { string confName = confElement.Attributes["name"].Value; string confid = confElement.Attributes["id"].Value; Boolean standard = Convert.ToBoolean(confElement.Attributes["standard"].Value); int minimumSeats = Convert.ToInt16(confElement.Attributes["minimumseats"].Value); AirlinerConfiguration configuration = new AirlinerConfiguration(confName, minimumSeats, standard); configuration.ID = confid; XmlNodeList classesList = confElement.SelectNodes("classes/class"); foreach (XmlElement classElement in classesList) { int seating = Convert.ToInt16(classElement.Attributes["seating"].Value); int regularseating = Convert.ToInt16(classElement.Attributes["regularseating"].Value); AirlinerClass.ClassType classType = (AirlinerClass.ClassType)Enum.Parse(typeof(AirlinerClass.ClassType), classElement.Attributes["type"].Value); AirlinerClassConfiguration classConf = new AirlinerClassConfiguration(classType, seating, regularseating); foreach (AirlinerFacility.FacilityType facType in Enum.GetValues(typeof(AirlinerFacility.FacilityType))) { string facUid = classElement.Attributes[facType.ToString()].Value; classConf.addFacility(AirlinerFacilities.GetFacility(facType, facUid)); } configuration.addClassConfiguration(classConf); } Configurations.AddConfiguration(configuration); } XmlNodeList routeConfigurationsList = root.SelectNodes("//routeclassesconfigurations/routeclassesconfiguration"); foreach (XmlElement confElement in routeConfigurationsList) { string routeConfName = confElement.Attributes["name"].Value; string confid = confElement.Attributes["id"].Value; Boolean standard = Convert.ToBoolean(confElement.Attributes["standard"].Value); XmlNodeList classesList = confElement.SelectNodes("classes/class"); RouteClassesConfiguration classesConfiguration = new RouteClassesConfiguration(routeConfName, standard); classesConfiguration.ID = confid; foreach (XmlElement classElement in classesList) { AirlinerClass.ClassType classType = (AirlinerClass.ClassType)Enum.Parse(typeof(AirlinerClass.ClassType), classElement.Attributes["type"].Value); RouteClassConfiguration classConf = new RouteClassConfiguration(classType); foreach (RouteFacility.FacilityType facType in Enum.GetValues(typeof(RouteFacility.FacilityType))) { if (classElement.HasAttribute(facType.ToString())) { string facilityName = classElement.Attributes[facType.ToString()].Value; classConf.addFacility(RouteFacilities.GetFacilities(facType).Find(f => f.Name == facilityName)); } } classesConfiguration.addClass(classConf); } Configurations.AddConfiguration(classesConfiguration); } XmlElement difficultyNode = (XmlElement)root.SelectSingleNode("//difficulty"); string difficultyName = difficultyNode.Attributes["name"].Value; double moneyLevel = Convert.ToDouble(difficultyNode.Attributes["money"].Value,new CultureInfo("de-DE", false)); double priceLevel = Convert.ToDouble(difficultyNode.Attributes["price"].Value, new CultureInfo("de-DE", false)); double loanLevel = Convert.ToDouble(difficultyNode.Attributes["loan"].Value, new CultureInfo("de-DE", false)); double passengersLevel = Convert.ToDouble(difficultyNode.Attributes["passengers"].Value, new CultureInfo("de-DE", false)); double aiLevel = Convert.ToDouble(difficultyNode.Attributes["ai"].Value, new CultureInfo("de-DE", false)); GameObject.GetInstance().Difficulty = new DifficultyLevel(difficultyName, moneyLevel, loanLevel, passengersLevel, priceLevel, aiLevel,1); XmlElement scenarioNode = (XmlElement)root.SelectSingleNode("//scenario"); if (scenarioNode != null) { Scenario scenario = Scenarios.GetScenario(scenarioNode.Attributes["name"].Value); ScenarioObject so = new ScenarioObject(scenario); so.IsSuccess = Convert.ToBoolean(scenarioNode.Attributes["success"].Value); if (scenarioNode.HasAttribute("failed")) so.ScenarioFailed = scenario.Failures.Find(f => f.ID == scenarioNode.Attributes["failed"].Value); XmlNodeList failuresList = scenarioNode.SelectNodes("failures/failure"); foreach (XmlElement failureNode in failuresList) { ScenarioFailure failure = scenario.Failures.Find(f => f.ID == failureNode.Attributes["id"].Value); int failureCount = Convert.ToInt16(failureNode.Attributes["count"].Value); DateTime lastFailureTime = DateTime.Parse(failureNode.Attributes["lastfailuretime"].Value, new CultureInfo("de-DE", false)); so.getScenarioFailure(failure).LastFailureTime = lastFailureTime; so.getScenarioFailure(failure).Failures = failureCount; } GameObject.GetInstance().Scenario = so; } XmlElement gameSettingsNode = (XmlElement)root.SelectSingleNode("//gamesettings"); GameObject.GetInstance().Name = gameSettingsNode.Attributes["name"].Value; Airline humanAirline = Airlines.GetAirline(gameSettingsNode.Attributes["human"].Value); GameObject.GetInstance().setHumanAirline(humanAirline); Airline mainAirline = Airlines.GetAirline(gameSettingsNode.Attributes["mainairline"].Value); GameObject.GetInstance().MainAirline = mainAirline; double fuelPrice = Convert.ToDouble(gameSettingsNode.Attributes["fuelprice"].Value, new CultureInfo("de-DE", false)); GameObject.GetInstance().FuelPrice = fuelPrice; GameTimeZone timezone = TimeZones.GetTimeZones().Find(delegate(GameTimeZone gtz) { return gtz.UTCOffset == TimeSpan.Parse(gameSettingsNode.Attributes["timezone"].Value); }); GameObject.GetInstance().TimeZone = timezone; Settings.GetInstance().MailsOnLandings = Convert.ToBoolean(gameSettingsNode.Attributes["mailonlandings"].Value); Settings.GetInstance().MailsOnBadWeather = Convert.ToBoolean(gameSettingsNode.Attributes["mailonbadweather"].Value); Settings.GetInstance().AirportCodeDisplay = (Settings.AirportCode)Enum.Parse(typeof(Settings.AirportCode), gameSettingsNode.Attributes["airportcode"].Value); if (gameSettingsNode.HasAttribute("minutesperturn")) Settings.GetInstance().MinutesPerTurn = Convert.ToInt16(gameSettingsNode.Attributes["minutesperturn"].Value); AppSettings.GetInstance().setLanguage(Languages.GetLanguage(gameSettingsNode.Attributes["language"].Value)); GameObject.GetInstance().DayRoundEnabled = Convert.ToBoolean(gameSettingsNode.Attributes["dayround"].Value); XmlNodeList itemsList = gameSettingsNode.SelectNodes("calendaritems/calendaritem"); CalendarItems.Clear(); foreach (XmlElement itemNode in itemsList) { CalendarItem.ItemType itemType = (CalendarItem.ItemType)Enum.Parse(typeof(CalendarItem.ItemType), itemNode.Attributes["type"].Value); DateTime itemDate = DateTime.Parse(itemNode.Attributes["date"].Value, new CultureInfo("de-DE", false)); string itemHeader = itemNode.Attributes["header"].Value; string itemSubject = itemNode.Attributes["subject"].Value; CalendarItems.AddCalendarItem(new CalendarItem(itemType, itemDate, itemHeader, itemSubject)); } XmlNodeList newsList = gameSettingsNode.SelectNodes("news/new"); GameObject.GetInstance().NewsBox.clear(); foreach (XmlElement newsNode in newsList) { DateTime newsDate = DateTime.Parse(newsNode.Attributes["date"].Value, new CultureInfo("de-DE", false)); News.NewsType newsType = (News.NewsType)Enum.Parse(typeof(News.NewsType), newsNode.Attributes["type"].Value); string newsSubject = newsNode.Attributes["subject"].Value; string newsBody = newsNode.Attributes["body"].Value; Boolean newsIsRead = Convert.ToBoolean(newsNode.Attributes["isread"].Value); News news = new News(newsType, newsDate, newsSubject, newsBody); news.IsRead = newsIsRead; GameObject.GetInstance().NewsBox.addNews(news); } /* foreach (Airline airline in Airlines.GetAllAirlines()) { foreach (Route route in airline.Routes) { Gate gate1 = route.Destination1.Terminals.getEmptyGate(airline); Gate gate2 = route.Destination2.Terminals.getEmptyGate(airline); if (gate1!=null) gate1.Route = route; if (gate2!=null) gate2.Route = route; } } */ }
//orders the airliners private void orderAirliners(Airport airport, double discount = 0) { DateTime deliveryDate = getDeliveryDate(); Guid id = Guid.NewGuid(); foreach (AirlinerTypeMVVM type in this.SelectedAirliners) { Airliner airliner = new Airliner(id.ToString(), type.Type, GameObject.GetInstance().HumanAirline.Profile.Country.TailNumbers.getNextTailNumber(), deliveryDate); Model.AirlinerModel.Airliners.AddAirliner(airliner); FleetAirliner.PurchasedType pType = FleetAirliner.PurchasedType.Bought; GameObject.GetInstance().HumanAirline.addAirliner(pType, airliner, airport); airliner.clearAirlinerClasses(); AirlinerHelpers.CreateAirlinerClasses(airliner); foreach (AirlinerClass aClass in airliner.Classes) { foreach (AirlinerFacility facility in aClass.getFacilities()) aClass.setFacility(GameObject.GetInstance().HumanAirline, facility); } } int totalAmount = this.SelectedAirliners.Count; double price = this.SelectedAirliners.Sum(a => a.Type.Price); double totalPrice = price * ((1 - GeneralHelpers.GetAirlinerOrderDiscount(totalAmount))) * ((100 - discount) / 100); AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -totalPrice); }