public PageManufacturer(Manufacturer manufacturer) { this.NumberOfAirliners = new List <int>(); for (int i = 1; i <= 50; i++) { this.NumberOfAirliners.Add(i); } this.Manufacturer = manufacturer; this.Orders = new AirlinerOrdersMVVM(); this.Airliners = new ObservableCollection <AirlinerType>(); AirlinerTypes.GetTypes(a => a.Manufacturer == manufacturer && a.Produced.From <= GameObject.GetInstance().GameTime&& a.Produced.To >= GameObject.GetInstance().GameTime).ForEach(t => this.Airliners.Add(t)); this.DataContext = this.Airliners; this.Contract = new ManufacturerContractMVVM(this.Manufacturer, GameObject.GetInstance().HumanAirline.Contract != null ? GameObject.GetInstance().HumanAirline.Contract.Manufacturer : null); InitializeComponent(); lvAirliners.ItemsSource = this.Airliners; CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(lvAirliners.ItemsSource); view.GroupDescriptions.Clear(); PropertyGroupDescription groupDescription = new PropertyGroupDescription("AirlinerFamily"); view.GroupDescriptions.Add(groupDescription); }
/*!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); }
/*! 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); }
public PageAirliners() { this.NewestAircrafts = AirlinerTypes.GetTypes(a => a.Produced.From <= GameObject.GetInstance().GameTime).OrderByDescending(a => a.Produced.From).Take(5).ToList(); this.MostUsedAircrafts = new List <AirlineFleetSizeMVVM>(); var query = GameObject.GetInstance().HumanAirline.Fleet.GroupBy(a => a.Airliner.Type) .Select(group => new { Type = group.Key, Fleet = group }) .OrderByDescending(g => g.Fleet.Count()); var aircrafts = query.Take(Math.Min(query.Count(), 5)); foreach (var group in aircrafts) { this.MostUsedAircrafts.Add(new AirlineFleetSizeMVVM(group.Type, group.Fleet.Count())); } this.Loaded += PageAirliners_Loaded; InitializeComponent(); }
//checks an airport for extending of runway public static void CheckForExtendRunway(Airport airport) { int minYearsBetweenExpansions = 5; long maxRunwayLenght = (from r in airport.Runways select r.Length).Max(); long longestRequiredRunwayLenght = AirlinerTypes.GetTypes(a => a.Produced.From <= GameObject.GetInstance().GameTime&& a.Produced.To >= GameObject.GetInstance().GameTime).Max(a => a.MinRunwaylength); var airportRoutes = AirportHelpers.GetAirportRoutes(airport); var routeAirliners = airportRoutes.SelectMany(r => r.getAirliners()); long longestRunwayInUse = routeAirliners.Count() > 0 ? routeAirliners.Max(a => a.Airliner.Type.MinRunwaylength) : 0; if (maxRunwayLenght < longestRequiredRunwayLenght / 2 && maxRunwayLenght < longestRunwayInUse * 3 / 4 && GameObject.GetInstance().GameTime.AddYears(-minYearsBetweenExpansions) > airport.LastExpansionDate) { List <string> runwayNames = (from r in Airports.GetAllAirports().SelectMany(a => a.Runways) select r.Name).Distinct().ToList(); foreach (Runway r in airport.Runways) { runwayNames.Remove(r.Name); } Runway.SurfaceType surface = airport.Runways[0].Surface; long lenght = Math.Min(longestRequiredRunwayLenght * 3 / 4, longestRunwayInUse * 2); Runway runway = new Runway(runwayNames[rnd.Next(runwayNames.Count)], lenght, surface, GameObject.GetInstance().GameTime.AddDays(90), false); airport.Runways.Add(runway); airport.LastExpansionDate = GameObject.GetInstance().GameTime; } }
public PageNewAirliners() { this.AllTypes = new List <AirlinerTypeMVVM>(); this.SelectedAirliners = new ObservableCollection <AirlinerTypeMVVM>(); this.RangeRanges = new List <FilterValue>() { new FilterValue("<1500", 0, 1499), new FilterValue("1500-2999", 1500, 2999), new FilterValue("3000-5999", 3000, 5999), new FilterValue("6000+", 6000, int.MaxValue) }; this.SpeedRanges = new List <FilterValue>() { new FilterValue("<400", 0, 399), new FilterValue("400-599", 400, 599), new FilterValue("600+", 600, int.MaxValue) }; this.RunwayRanges = new List <FilterValue>() { new FilterValue("<5000", 0, 4999), new FilterValue("5000-7999", 5000, 7999), new FilterValue("8000+", 8000, int.MaxValue) }; this.CapacityRanges = new List <FilterValue>() { new FilterValue("<100", 0, 99), new FilterValue("100-199", 100, 199), new FilterValue("200-299", 200, 299), new FilterValue("300-399", 300, 399), new FilterValue("400-499", 400, 499), new FilterValue("500+", 500, int.MaxValue) }; this.AllTypes = new List <AirlinerTypeMVVM>(); AirlinerTypes.GetTypes(t => t.Produced.From <= GameObject.GetInstance().GameTime&& t.Produced.To > GameObject.GetInstance().GameTime).ForEach(t => this.AllTypes.Add(new AirlinerTypeMVVM(t))); InitializeComponent(); }
/*! create some game airliners. */ public static void CreateStartUpAirliners() { int number = AirlinerTypes.GetTypes(delegate(AirlinerType t) { return(t.Produced.From <= GameObject.GetInstance().GameTime&& t.Produced.To >= GameObject.GetInstance().GameTime.AddYears(-30)); }).Count * 25; for (int i = 0; i < number; i++) { Airliners.AddAirliner(CreateAirliner(0)); } }
/*! create some game airliners. */ public static void CreateStartUpAirliners() { int number = AirlinerTypes.GetTypes(delegate(AirlinerType t) { return(t.Produced.From <= GameObject.GetInstance().GameTime&& t.Produced.To.AddYears(-10) >= GameObject.GetInstance().GameTime.AddYears(-30)); }).Count *rnd.Next(1, 3); int airlines = Airlines.GetNumberOfAirlines(); number = (airlines * number) / 5; for (int i = 0; i < number; i++) { Airliners.AddAirliner(CreateAirliner(0)); } }
public PageShowFlightSchool(FlightSchool fs) { this.FlightSchool = new FlightSchoolMVVM(fs); this.Instructors = new ObservableCollection <Instructor>(); this.AirlinerFamilies = AirlinerTypes.GetTypes(t => t.Produced.From.Year <= GameObject.GetInstance().GameTime.Year&& t.Produced.To > GameObject.GetInstance().GameTime.AddYears(-30)).Select(t => t.AirlinerFamily).Distinct().OrderBy(a => a).ToList(); this.DataContext = this.FlightSchool; setHireStudentsStatus(); InitializeComponent(); }
private void btnTrainPilot_Click(object sender, RoutedEventArgs e) { double substituteDayPrice = 500; PilotMVVM pilot = (PilotMVVM)((Button)sender).Tag; ComboBox cbAirlinerFamily = new ComboBox(); cbAirlinerFamily.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbAirlinerFamily.ItemTemplate = this.Resources["TrainingFacility"] as DataTemplate; cbAirlinerFamily.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; cbAirlinerFamily.Width = 350; var airlinerFamilies = AirlinerTypes.GetTypes(t => t.Produced.From.Year <= GameObject.GetInstance().GameTime.Year&& t.Produced.To > GameObject.GetInstance().GameTime.AddYears(-30)).Select(t => t.AirlinerFamily).Where(t => !pilot.Pilot.Aircrafts.Contains(t)).Distinct().OrderBy(a => a); foreach (string family in airlinerFamilies) { double price = AirlineHelpers.GetTrainingPrice(pilot.Pilot, family);; cbAirlinerFamily.Items.Add(new PilotTrainingMVVM(family, AirlineHelpers.GetTrainingDays(pilot.Pilot, family), price)); } cbAirlinerFamily.SelectedIndex = 0; if (PopUpSingleElement.ShowPopUp(Translator.GetInstance().GetString("PageAirlineEmployees", "1014"), cbAirlinerFamily) == PopUpSingleElement.ButtonSelected.OK && cbAirlinerFamily.SelectedItem != null) { PilotTrainingMVVM pilotTraining = (PilotTrainingMVVM)cbAirlinerFamily.SelectedItem; if (pilot.Pilot.Airliner == null) { AirlineHelpers.SendForTraining(GameObject.GetInstance().HumanAirline, pilot.Pilot, pilotTraining.Family, pilotTraining.TrainingDays, pilotTraining.Price); pilot.OnTraining = true; } else { double substitutePrice = GeneralHelpers.GetInflationPrice(pilotTraining.TrainingDays * substituteDayPrice); WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2129"), string.Format(Translator.GetInstance().GetString("MessageBox", "2129", "message"), new ValueCurrencyConverter().Convert(substitutePrice), pilotTraining.TrainingDays), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { AirlineHelpers.AddAirlineInvoice(this.Airline.Airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Airline_Expenses, -substitutePrice); AirlineHelpers.SendForTraining(GameObject.GetInstance().HumanAirline, pilot.Pilot, pilotTraining.Family, pilotTraining.TrainingDays, pilotTraining.Price); pilot.OnTraining = true; } } } }
public PanelNewRoute(PageRoutes parent) { this.Classes = new Dictionary <AirlinerClass.ClassType, RouteAirlinerClass>(); this.CargoPrice = 10; var query = from a in AirlinerTypes.GetTypes(delegate(AirlinerType t) { return(t.Produced.From < GameObject.GetInstance().GameTime); }) select a.Range; this.MaxDistance = query.Max(); this.ParentPage = parent; this.Margin = new Thickness(0, 0, 50, 0); TextBlock txtHeader = new TextBlock(); txtHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; txtHeader.SetResourceReference(TextBlock.BackgroundProperty, "HeaderBackgroundBrush2"); txtHeader.FontWeight = FontWeights.Bold; txtHeader.Text = Translator.GetInstance().GetString("PanelNewRoute", "201"); this.Children.Add(txtHeader); WrapPanel panelRouteType = new WrapPanel(); rbPassenger = new RadioButton(); rbPassenger.GroupName = "RouteType"; rbPassenger.Content = Translator.GetInstance().GetString("PanelNewRoute", "1005"); rbPassenger.Checked += rbRouteType_Checked; rbPassenger.Tag = Route.RouteType.Passenger; panelRouteType.Children.Add(rbPassenger); rbCargo = new RadioButton(); rbCargo.Margin = new Thickness(10, 0, 0, 0); rbCargo.GroupName = "RouteType"; rbCargo.Content = Translator.GetInstance().GetString("PanelNewRoute", "1006"); rbCargo.Tag = Route.RouteType.Cargo; //rbCargo.IsEnabled = false; rbCargo.Checked += rbRouteType_Checked; panelRouteType.Children.Add(rbCargo); this.Children.Add(panelRouteType); panelRouteInfo = new StackPanel(); this.Children.Add(panelRouteInfo); //rbPassenger.IsChecked = true; }
//creates a number of airliner families a pilot can fly public static List <string> GetPilotAircrafts(Pilot pilot) { int year = GameObject.GetInstance().GameTime.Year; var airlinerFamilies = AirlinerTypes.GetTypes(t => t.Produced.From.Year <= GameObject.GetInstance().GameTime.Year&& t.Produced.To > GameObject.GetInstance().GameTime.AddYears(-30)).Select(a => a.AirlinerFamily).Distinct(); Random rnd = new Random(); List <string> families = new List <string>(); int numberOfAircrafts = PilotRatings.GetRatings().IndexOf(pilot.Rating) + 1; for (int i = 0; i < numberOfAircrafts; i++) { var freeFamilies = airlinerFamilies.Where(a => !families.Contains(a)).ToList(); string family = freeFamilies[rnd.Next(freeFamilies.Count)]; families.Add(family); } return(families); }