private void btnDemandContract_Click(object sender, RoutedEventArgs e) { DemandMVVM demand = (DemandMVVM)((Button)sender).Tag; Airport airport = demand.Destination; Boolean hasCheckin = airport.getAirportFacility(GameObject.GetInstance().HumanAirline, AirportFacility.FacilityType.CheckIn).TypeLevel > 0; int gates = Math.Min(2, airport.Terminals.NumberOfFreeGates); WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2222"), string.Format(Translator.GetInstance().GetString("MessageBox", "2222", "message"), gates, airport.Profile.Name), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { if (!hasCheckin) { AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1); airport.addAirportFacility(GameObject.GetInstance().HumanAirline, checkinFacility, GameObject.GetInstance().GameTime); AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -checkinFacility.Price); } double yearlyPayment = AirportHelpers.GetYearlyContractPayment(airport, gates, 2); AirportContract contract = new AirportContract(GameObject.GetInstance().HumanAirline, airport, GameObject.GetInstance().GameTime, gates, 2, yearlyPayment); airport.addAirlineContract(contract); demand.Contracted = true; } }
private void btnOk_Click(object sender, RoutedEventArgs e) { int gates = Convert.ToInt32(nudGates.Value); int lenght = Convert.ToInt32(cbLength.SelectedItem); double yearlyPayment = AirportHelpers.GetYearlyContractPayment(this.Airport, gates, lenght); if (this.Contract == null) { Boolean payFull = false; if (lenght <= 2) { payFull = true; } AirportContract contract = new AirportContract(GameObject.GetInstance().HumanAirline, this.Airport, GameObject.GetInstance().GameTime, gates, lenght, yearlyPayment, payFull); this.Selected = contract; } else { this.Contract.NumberOfGates = gates; this.Contract.Length = lenght; this.Contract.YearlyPayment = yearlyPayment; this.Contract.ContractDate = GameObject.GetInstance().GameTime; this.Contract.ExpireDate = this.Contract.ExpireDate.AddYears(this.Contract.Length); this.Selected = this.Contract; } this.Close(); }
private void btnBuildRunway_Click(object sender, RoutedEventArgs e) { Runway runway = (Runway)PopUpBuildRunway.ShowPopUp(this.Airport); if (runway != null) { double runwayPrice = AirportHelpers.GetAirportRunwayPrice(this.Airport, runway.Length); if (runwayPrice > GameObject.GetInstance().HumanAirline.Money) { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2219"), string.Format(Translator.GetInstance().GetString("MessageBox", "2219", "message"), this.Airport.Profile.Name, runwayPrice), WPFMessageBoxButtons.Ok); } else { WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2218"), string.Format(Translator.GetInstance().GetString("MessageBox", "2218", "message"), this.Airport.Profile.Name, runwayPrice), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { this.Airport.Runways.Add(runway); AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, runwayPrice); showRunways(); } } } }
public static List <RouteTimeTableEntry> GetAirportDepartures(Airport airport, int count) { List <RouteTimeTableEntry> entries = new List <RouteTimeTableEntry>(); foreach (Route route in AirportHelpers.GetAirportRoutes(airport)) { if (route.HasAirliner && route.getCurrentAirliner() != null) { RouteTimeTableEntry entry = route.getCurrentAirliner().CurrentFlight == null?route.TimeTable.getNextEntry(GameObject.GetInstance().GameTime, airport) : route.getCurrentAirliner().CurrentFlight.Entry; if (!entry.Destination.Airport.Profile.Coordinates.Equals(airport.Profile.Coordinates)) { entries.Add(entry); } while (entries.Count < 4) { entry = route.TimeTable.getNextEntry(entry); if (entry.Destination.Airport != airport) { entries.Add(entry); } } } } entries.Sort(delegate(RouteTimeTableEntry e1, RouteTimeTableEntry e2) { return(MathHelpers.ConvertEntryToDate(e1).CompareTo(MathHelpers.ConvertEntryToDate(e2))); }); return(entries.GetRange(0, Math.Min(entries.Count, count))); }
// chs, 2011-17-11 changed for showing departures and arrivals from one airport to another //returns the list of arrivals or departures from one airport to another public static List <RouteTimeTableEntry> GetAirportFlights(Airport fAirport, Airport tAirport, Boolean arrivals) { List <RouteTimeTableEntry> entries = new List <RouteTimeTableEntry>(); foreach (Route route in AirportHelpers.GetAirportRoutes(fAirport)) { if (route.HasAirliner && (route.Destination1 == tAirport || route.Destination2 == tAirport)) { RouteTimeTableEntry entry = route.getCurrentAirliner() == null || route.getCurrentAirliner().CurrentFlight == null || route.getCurrentAirliner().CurrentFlight.Entry == null?route.TimeTable.getNextEntry(GameObject.GetInstance().GameTime) : route.getCurrentAirliner().CurrentFlight.Entry; for (int i = 0; i < route.TimeTable.Entries.Count; i++) { if (!arrivals && entry.Destination.Airport == tAirport) { entries.Add(entry); } if (arrivals && entry.Destination.Airport == fAirport) { entries.Add(entry); } entry = route.TimeTable.getNextEntry(entry); } } } entries.Sort(delegate(RouteTimeTableEntry e1, RouteTimeTableEntry e2) { return(MathHelpers.ConvertEntryToDate(e1).CompareTo(MathHelpers.ConvertEntryToDate(e2))); }); return(entries); }
//returns the list of destinations for the airport private Dictionary <Airport, int> getDestinations() { Dictionary <Airport, int> destinations = new Dictionary <Airport, int>(); foreach (Route route in AirportHelpers.GetAirportRoutes(this.Airport).FindAll(r => r.getAirliners().Count > 0)) { if (route.Destination1 != this.Airport) { if (!destinations.ContainsKey(route.Destination1)) { destinations.Add(route.Destination1, 0); } destinations[route.Destination1] += route.TimeTable.getEntries(route.Destination1).Count; } if (route.Destination2 != this.Airport) { if (!destinations.ContainsKey(route.Destination2)) { destinations.Add(route.Destination2, 0); } destinations[route.Destination2] += route.TimeTable.getEntries(route.Destination2).Count; } } return(destinations); }
//creates the panel for the slot allocation for a day private ScrollViewer createSlotAllocationPanel(DayOfWeek day) { ScrollViewer scroller = new ScrollViewer(); scroller.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; scroller.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; scroller.MaxWidth = 800; StackPanel panelSlots = new StackPanel(); panelSlots.Margin = new Thickness(0, 10, 0, 0); Dictionary <TimeSpan, KeyValuePair <int, int> > values = new Dictionary <TimeSpan, KeyValuePair <int, int> >(); DateTime time = new DateTime(2000, 1, 1, 0, 0, 0); while (time.Day < 2) { TimeSpan ts = new TimeSpan(time.Hour, time.Minute, 0); values.Add(ts, new KeyValuePair <int, int>(AirportHelpers.GetAirportTakeoffs(this.Airport, day, ts, ts.Add(new TimeSpan(0, 15, 0))).Count, AirportHelpers.GetAirportLandings(this.Airport, day, ts, ts.Add(new TimeSpan(0, 15, 0))).Count)); time = time.AddMinutes(15); } panelSlots.Children.Add(createSlotsPanel(values, new TimeSpan(0, 0, 0), new TimeSpan(12, 0, 0))); panelSlots.Children.Add(createSlotsPanel(values, new TimeSpan(12, 0, 0), new TimeSpan(24, 0, 0))); scroller.Content = panelSlots; return(scroller); }
private void btnHub_Click(object sender, RoutedEventArgs e) { StackPanel panelHubs = new StackPanel(); foreach (HubType type in HubTypes.GetHubTypes()) { if (AirlineHelpers.CanCreateHub(GameObject.GetInstance().HumanAirline, this.Airport, type)) { panelHubs.Children.Add(createHubType(type, panelHubs)); } } if (panelHubs.Children.Count == 0) { panelHubs.Children.Add(UICreator.CreateTextBlock("You can't etablish any hubs at this airport")); } if (PopUpSingleElement.ShowPopUp("Select hub type", panelHubs) == PopUpSingleElement.ButtonSelected.OK && panelHubs.Tag != null) { HubType type = (HubType)panelHubs.Tag; if (AirportHelpers.GetHubPrice(this.Airport, type) > GameObject.GetInstance().HumanAirline.Money) { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2212"), Translator.GetInstance().GetString("MessageBox", "2212", "message"), WPFMessageBoxButtons.Ok); } else { this.Airport.addHub(new Hub(GameObject.GetInstance().HumanAirline, type)); showHubs(); AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -AirportHelpers.GetHubPrice(this.Airport, type)); } } }
private void btnRemoveContract_Click(object sender, RoutedEventArgs e) { ContractMVVM tContract = (ContractMVVM)((Button)sender).Tag; AirportContract contract = tContract.Contract; double penaltyFee = ((contract.YearlyPayment / 12) * contract.MonthsLeft) / 10; var contracts = this.Airport.Airport.AirlineContracts.Where(a => a.Airline == GameObject.GetInstance().HumanAirline&& a != contract).ToList(); if (!AirportHelpers.CanFillRoutesEntries(this.Airport.Airport, GameObject.GetInstance().HumanAirline, contracts)) { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2224"), Translator.GetInstance().GetString("MessageBox", "2224", "message"), WPFMessageBoxButtons.Ok); } else if (contract.Terminal != null) { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2226"), string.Format(Translator.GetInstance().GetString("MessageBox", "2226", "message"), contract.Terminal.Name), WPFMessageBoxButtons.Ok); } else { WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2225"), string.Format(Translator.GetInstance().GetString("MessageBox", "2225", "message"), new ValueCurrencyConverter().Convert(penaltyFee)), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -penaltyFee); this.Airport.removeAirlineContract(tContract); } } }
private void btnSignContract_Click(object sender, RoutedEventArgs e) { int gates = Convert.ToInt16(slContractGates.Value); int lenght = Convert.ToInt16(slContractLenght.Value); Boolean hasCheckin = this.Airport.Airport.getAirportFacility(GameObject.GetInstance().HumanAirline, AirportFacility.FacilityType.CheckIn).TypeLevel > 0; double yearlyPayment = AirportHelpers.GetYearlyContractPayment(this.Airport.Airport, gates, lenght); Boolean payFull = lenght <= 2; AirportContract contract = new AirportContract(GameObject.GetInstance().HumanAirline, this.Airport.Airport, GameObject.GetInstance().GameTime, gates, lenght, yearlyPayment, payFull); if (!hasCheckin) { AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1); this.Airport.Airport.addAirportFacility(GameObject.GetInstance().HumanAirline, checkinFacility, GameObject.GetInstance().GameTime); AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -checkinFacility.Price); } //25 % off if paying up front if (contract.PayFull) { double payment = (contract.YearlyPayment * contract.Length) * 0.75; AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Rents, -payment); contract.YearlyPayment = 0; } this.Airport.addAirlineContract(contract); }
public void addAirlineContract(AirportContract contract) { this.Airport.addAirlineContract(contract); this.IsHuman = GameObject.GetInstance().HumanAirline.Airports.Contains(this.Airport); this.NumberOfFreeGates = this.Airport.Terminals.NumberOfFreeGates; this.NumberOfAirlines = this.Airport.AirlineContracts.Select(c => c.Airline).Distinct().Count(); this.NumberOfRoutes = AirportHelpers.GetAirportRoutes(this.Airport).Count; }
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { int gates = System.Convert.ToInt16(values[0]); int lenght = System.Convert.ToInt16(values[1]); Airport airport = (Airport)values[2]; return(new ValueCurrencyConverter().Convert(AirportHelpers.GetYearlyContractPayment(airport, gates, lenght))); }
//purchases a terminal for an airline public void purchaseTerminal(Airline airline) { this.Airline = airline; double yearlyPayment = AirportHelpers.GetYearlyContractPayment(this.Airport, this.Gates.NumberOfGates, 20); this.Airport.addAirlineContract(new AirportContract(this.Airline, this.Airport, GameObject.GetInstance().GameTime, this.Gates.NumberOfGates, 20, yearlyPayment * 0.75)); }
public AirportMVVM(Airport airport) { this.Airport = airport; this.IsHuman = GameObject.GetInstance().HumanAirline.Airports.Contains(this.Airport); this.NumberOfFreeGates = this.Airport.Terminals.NumberOfFreeGates; this.NumberOfAirlines = this.Airport.AirlineContracts.Select(c => c.Airline).Distinct().Count(); this.NumberOfRoutes = AirportHelpers.GetAirportRoutes(this.Airport).Count; this.LongestRunway = this.Airport.Runways.Count == 0 ? 0 : this.Airport.Runways.Max(r => r.Length); }
//sets the yearly value private void setYearlyValue() { int gates = Convert.ToInt32(nudGates.Value); int lenght = Convert.ToInt32(cbLength.SelectedItem); double yearlyPayment = AirportHelpers.GetYearlyContractPayment(this.Airport, gates, lenght); txtYearlyPayment.Text = new ValueCurrencyConverter().Convert(yearlyPayment).ToString(); }
//returns the percent of free gate slots for the airport public double getFreeSlotsPercent(Airline airline) { double numberOfSlots = (22 - 6) * 4 * 7; //from 06.00 to 22.00 each quarter each day (7 days a week) double usedSlots = AirportHelpers.GetOccupiedSlotTimes(this.Airport, airline).Count; double percent = ((numberOfSlots - usedSlots) / numberOfSlots) * 100; return(percent); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { Airport airport = (Airport)values[0]; AirportContract.ContractType type = (AirportContract.ContractType)Enum.Parse(typeof(AirportContract.ContractType), values[1].ToString(), true); double price = AirportHelpers.GetYearlyContractPayment(airport, type, 2, 2); return(string.Format("({0})", new ValueCurrencyConverter().Convert(price))); }
/// <summary> /// Returns the distance between two airports /// </summary> /// <param name="o">Start airport</param> /// <param name="d">Destination airport</param> /// <returns></returns> private double getDistanceBetween(Airport o, Airport d) { if (AirportHelpers.GetAirportRoutes(o).Find(r => r.Destination1 == d || r.Destination2 == d) != null) { return(1); } else { return(0); } }
/// <summary> /// Returns all airports with a route from the an airport /// </summary> /// <param name="n">Airport</param> /// <returns></returns> private List <Airport> getNeighbors(Airport n) { List <Airport> neighbors = new List <Airport>(); foreach (Route route in AirportHelpers.GetAirportRoutes(n)) { Airport destination = route.Destination1 == n ? route.Destination2 : route.Destination1; if (this.Basis.Contains(n)) { neighbors.Add(destination); } } return(neighbors); }
//returns the list of arrivals for an airport public static List <RouteTimeTableEntry> GetAirportArrivals(Airport airport, DayOfWeek day) { List <RouteTimeTableEntry> entries = new List <RouteTimeTableEntry>(); foreach (Route route in AirportHelpers.GetAirportRoutes(airport)) { if (route.HasAirliner) { var rEntries = route.TimeTable.Entries.Where(e => e.Day == day && e.Destination.Airport == airport); entries.AddRange(rEntries); } } entries.Sort(delegate(RouteTimeTableEntry e1, RouteTimeTableEntry e2) { return(MathHelpers.ConvertEntryToDate(e1).CompareTo(MathHelpers.ConvertEntryToDate(e2))); }); return(entries); }
//adds an airline contract to the airport public void addAirlineContract(AirportContract contract) { AirportHelpers.AddAirlineContract(contract); this.Contracts.Add(new ContractMVVM(contract)); this.FreeGates = this.Airport.Terminals.NumberOfFreeGates; this.CanBuildHub = this.Contracts.Count(c => c.Airline == GameObject.GetInstance().HumanAirline) > 0; foreach (AirportTerminalMVVM terminal in Terminals) { terminal.FreeGates = terminal.Terminal.getFreeGates(); } this.CanMakeCooperation = GameObject.GetInstance().HumanAirline.Airports.Exists(a => a == this.Airport); }
//shows the passengers private void showDemand() { lbPassengers.Items.Clear(); List <Airport> airports; if (domesticDemand) { airports = Airports.GetAirports(a => a != this.Airport && a.Profile.Country == this.Airport.Profile.Country).OrderByDescending(a => this.Airport.getDestinationPassengersRate(a, AirlinerClass.ClassType.Economy_Class)).ToList(); } else { airports = Airports.GetAirports(a => a != this.Airport && a.Profile.Country != this.Airport.Profile.Country).OrderByDescending(a => this.Airport.getDestinationPassengersRate(a, AirlinerClass.ClassType.Economy_Class)).ToList(); } foreach (Airport airport in airports) { int passengers = this.Airport.getDestinationPassengersRate(airport, AirlinerClass.ClassType.Economy_Class); int cargo = this.Airport.getDestinationCargoRate(airport); if (passengers > 0 || cargo > 0) { DestinationDemand passengerDemand = new DestinationDemand(airport.Profile.IATACode, (ushort)passengers); DestinationDemand cargoDemand = new DestinationDemand(airport.Profile.IATACode, (ushort)cargo); int demand = passengers; int covered = 0; List <Route> routes = AirportHelpers.GetAirportRoutes(airport, this.Airport).Where(r => r.Type == Route.RouteType.Mixed || r.Type == Route.RouteType.Passenger).ToList(); foreach (Route route in routes) { RouteAirlinerClass raClass = ((PassengerRoute)route).getRouteAirlinerClass(AirlinerClass.ClassType.Economy_Class); double avgPassengers = route.Statistics.getStatisticsValue(raClass, StatisticsTypes.GetStatisticsType("Passengers%")); double flights = route.TimeTable.Entries.Count; double routeCovered = avgPassengers / (7.0 / flights); covered += (int)routeCovered; } KeyValuePair <DestinationDemand, int> paxDemand = new KeyValuePair <DestinationDemand, int>(passengerDemand, Math.Max(0, demand - covered)); KeyValuePair <DestinationDemand, int> cDemand = new KeyValuePair <DestinationDemand, int>(cargoDemand, 0); KeyValuePair <KeyValuePair <DestinationDemand, int>, KeyValuePair <DestinationDemand, int> > totalDemand = new KeyValuePair <KeyValuePair <DestinationDemand, int>, KeyValuePair <DestinationDemand, int> >(paxDemand, cDemand); lbPassengers.Items.Add(totalDemand); } } }
private void btnSignContract_Click(object sender, RoutedEventArgs e) { int gates = Convert.ToInt16(slContractGates.Value); int length = Convert.ToInt16(slContractLenght.Value); Boolean hasCheckin = this.Airport.Airport.getAirportFacility(GameObject.GetInstance().HumanAirline, AirportFacility.FacilityType.CheckIn).TypeLevel > 0; AirportContract.ContractType contractType = (AirportContract.ContractType)cbContractType.SelectedItem; Boolean autoRenew = cbAutoRenew.IsChecked.Value; double yearlyPayment = AirportHelpers.GetYearlyContractPayment(this.Airport.Airport, contractType, gates, length); Boolean payFull = length <= 2; AirportContract contract = new AirportContract(GameObject.GetInstance().HumanAirline, this.Airport.Airport, contractType, GameObject.GetInstance().GameTime, gates, length, yearlyPayment, autoRenew, payFull); if (!hasCheckin && contractType == AirportContract.ContractType.Full) { AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1); this.Airport.Airport.addAirportFacility(GameObject.GetInstance().HumanAirline, checkinFacility, GameObject.GetInstance().GameTime); AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -checkinFacility.Price); } //25 % off if paying up front if (contract.PayFull && contractType == AirportContract.ContractType.Full) { double payment = (contract.YearlyPayment * contract.Length) * 0.75; AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Rents, -payment); contract.YearlyPayment = 0; } for (int i = 0; i < gates; i++) { Gate gate = this.Airport.Airport.Terminals.getGates().Where(g => g.Airline == null).First(); gate.Airline = GameObject.GetInstance().HumanAirline; } this.Airport.addAirlineContract(contract); }
private void btnCreateHub_Click(object sender, RoutedEventArgs e) { HubType type = HubTypes.GetHubType(HubType.TypeOfHub.Hub);//(HubType)cbHubType.SelectedItem; if (AirportHelpers.GetHubPrice(this.Airport.Airport, type) > GameObject.GetInstance().HumanAirline.Money) { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2212"), Translator.GetInstance().GetString("MessageBox", "2212", "message"), WPFMessageBoxButtons.Ok); } else { WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2213"), string.Format(Translator.GetInstance().GetString("MessageBox", "2213", "message"), AirportHelpers.GetHubPrice(this.Airport.Airport, type)), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { this.Airport.addHub(new Hub(GameObject.GetInstance().HumanAirline, type)); AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -AirportHelpers.GetHubPrice(this.Airport.Airport, type)); } } }
private void btnContract_Click(object sender, RoutedEventArgs e) { AirportMVVM airport = (AirportMVVM)((Button)sender).Tag; Boolean hasCheckin = airport.Airport.getAirportFacility(GameObject.GetInstance().HumanAirline, AirportFacility.FacilityType.CheckIn).TypeLevel > 0; int gates = Math.Min(2, airport.Airport.Terminals.NumberOfFreeGates); //WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2222"), string.Format(Translator.GetInstance().GetString("MessageBox", "2222", "message"),gates, airport.Airport.Profile.Name), WPFMessageBoxButtons.YesNo); object o = PopUpAirportContract.ShowPopUp(airport.Airport); if (o != null) { AirportContract.ContractType contractType = (AirportContract.ContractType)o; if (!hasCheckin && contractType == AirportContract.ContractType.Full) { AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1); airport.Airport.addAirportFacility(GameObject.GetInstance().HumanAirline, checkinFacility, GameObject.GetInstance().GameTime); AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -checkinFacility.Price); } //AirportHelpers.RentGates(airport.Airport, GameObject.GetInstance().HumanAirline, contractType, gates, 2); double yearlyPayment = AirportHelpers.GetYearlyContractPayment(airport.Airport, contractType, gates, 2); AirportContract contract = new AirportContract(GameObject.GetInstance().HumanAirline, airport.Airport, contractType, GameObject.GetInstance().GameTime, gates, 2, yearlyPayment, true); airport.addAirlineContract(contract); for (int i = 0; i < gates; i++) { Gate gate = airport.Airport.Terminals.getGates().Where(g => g.Airline == null).First(); gate.Airline = GameObject.GetInstance().HumanAirline; } } }
public static List <RouteTimeTableEntry> GetAirportArrivals(Airport airport, int count) { List <RouteTimeTableEntry> entries = new List <RouteTimeTableEntry>(); foreach (Route route in AirportHelpers.GetAirportRoutes(airport)) { if (route.HasAirliner && route.getCurrentAirliner() != null) { RouteTimeTableEntry entry = route.getCurrentAirliner().CurrentFlight == null?route.TimeTable.getNextEntry(GameObject.GetInstance().GameTime, (airport == route.Destination1 ? route.Destination2 : route.Destination1)) : route.getCurrentAirliner().CurrentFlight.Entry; for (int i = 0; i < route.TimeTable.Entries.Count; i++) { if (entry.Destination.Airport == airport) { entries.Add(entry); } entry = route.TimeTable.getNextEntry(entry); } } } entries.Sort(delegate(RouteTimeTableEntry e1, RouteTimeTableEntry e2) { return(MathHelpers.ConvertEntryToDate(e1).CompareTo(MathHelpers.ConvertEntryToDate(e2))); }); return(entries.GetRange(0, Math.Min(entries.Count, count))); }
public AirportMVVM(Airport airport) { this.Airport = airport; this.TerminalGatePrice = this.Airport.getTerminalGatePrice(); this.TerminalPrice = this.Airport.getTerminalPrice(); this.Terminals = new ObservableCollection <AirportTerminalMVVM>(); foreach (Terminal terminal in this.Airport.Terminals.getTerminals()) { Boolean isSellable = terminal.Airline != null && terminal.Airline == GameObject.GetInstance().HumanAirline; this.Terminals.Add(new AirportTerminalMVVM(terminal, terminal.IsBuyable, isSellable)); } this.Contracts = new ObservableCollection <ContractMVVM>(); foreach (AirportContract contract in this.Airport.AirlineContracts) { this.Contracts.Add(new ContractMVVM(contract)); } AirportHelpers.CreateAirportWeather(this.Airport); this.Weather = this.Airport.Weather.ToList(); if (!GameObject.GetInstance().DayRoundEnabled) { this.CurrentWeather = this.Weather[0].Temperatures[GameObject.GetInstance().GameTime.Hour]; } this.FreeGates = this.Airport.Terminals.NumberOfFreeGates; this.Demands = new List <DemandMVVM>(); foreach (Airport destination in this.Airport.getDestinationDemands().Where(a => a != null && GeneralHelpers.IsAirportActive(a))) { this.Demands.Add(new DemandMVVM(destination, (int)this.Airport.getDestinationPassengersRate(destination, AirlinerClass.ClassType.Economy_Class), (int)this.Airport.getDestinationCargoRate(destination), new CountryCurrentCountryConverter().Convert(destination.Profile.Country) == new CountryCurrentCountryConverter().Convert(this.Airport.Profile.Country) ? DemandMVVM.DestinationType.Domestic : DemandMVVM.DestinationType.International)); } this.AirportFacilities = this.Airport.getAirportFacilities().FindAll(f => f.Airline == null).Select(f => f.Facility).ToList(); this.AirlineFacilities = new ObservableCollection <AirlineAirportFacilityMVVM>(); foreach (var facility in this.Airport.getAirportFacilities().FindAll(f => f.Airline != null)) { if (facility.Facility.TypeLevel != 0) { Alliance alliance = facility.Airline.Alliances.Count == 0 ? null : facility.Airline.Alliances[0]; this.AirlineFacilities.Add(new AirlineAirportFacilityMVVM(facility, alliance)); } } this.AirlineStatistics = new List <AirportStatisticsMVMM>(); foreach (Airline airline in Airlines.GetAllAirlines()) { StatisticsType passengersType = StatisticsTypes.GetStatisticsType("Passengers"); StatisticsType passengersAvgType = StatisticsTypes.GetStatisticsType("Passengers%"); StatisticsType arrivalsType = StatisticsTypes.GetStatisticsType("Arrivals"); double passengers = this.Airport.Statistics.getStatisticsValue(GameObject.GetInstance().GameTime.Year, airline, passengersType); double passengersAvg = this.Airport.Statistics.getStatisticsValue(GameObject.GetInstance().GameTime.Year, airline, passengersAvgType); double arrivals = this.Airport.Statistics.getStatisticsValue(GameObject.GetInstance().GameTime.Year, airline, arrivalsType); this.AirlineStatistics.Add(new AirportStatisticsMVMM(airline, passengers, passengersAvg, arrivals)); } this.Traffic = new List <AirportTrafficMVVM>(); var passengerDestinations = from a in Airports.GetAllActiveAirports() orderby this.Airport.getDestinationPassengerStatistics(a) descending select a; var cargoDestinations = from a in Airports.GetAllActiveAirports() orderby this.Airport.getDestinationCargoStatistics(a) descending select a; foreach (Airport a in passengerDestinations.Take(20)) { this.Traffic.Add(new AirportTrafficMVVM(a, this.Airport.getDestinationPassengerStatistics(a), AirportTrafficMVVM.TrafficType.Passengers)); } foreach (Airport a in cargoDestinations.Take(20)) { this.Traffic.Add(new AirportTrafficMVVM(a, Convert.ToInt64(this.Airport.getDestinationCargoStatistics(a)), AirportTrafficMVVM.TrafficType.Cargo)); } this.Flights = new List <DestinationFlightsMVVM>(); Dictionary <Airport, int> destinations = new Dictionary <Airport, int>(); foreach (Route route in AirportHelpers.GetAirportRoutes(this.Airport).FindAll(r => r.getAirliners().Count > 0)) { if (route.Destination1 != this.Airport) { if (!destinations.ContainsKey(route.Destination1)) { destinations.Add(route.Destination1, 0); } destinations[route.Destination1] += route.TimeTable.getEntries(route.Destination1).Count; } if (route.Destination2 != this.Airport) { if (!destinations.ContainsKey(route.Destination2)) { destinations.Add(route.Destination2, 0); } destinations[route.Destination2] += route.TimeTable.getEntries(route.Destination2).Count; } } foreach (Airport a in destinations.Keys) { this.Flights.Add(new DestinationFlightsMVVM(a, destinations[a])); } this.Hubs = new ObservableCollection <Hub>(); foreach (Hub hub in this.Airport.getHubs()) { this.Hubs.Add(hub); } this.CanBuildHub = canBuildHub(); this.LocalTime = MathHelpers.ConvertDateTimeToLoalTime(GameObject.GetInstance().GameTime, this.Airport.Profile.TimeZone); this.ShowLocalTime = !GameObject.GetInstance().DayRoundEnabled; }
//return the current size (pax) of the airport private GeneralHelpers.Size getCurrentSize() { return(AirportHelpers.ConvertAirportPaxToSize(getCurrentPaxValue())); }
//creates a new game private void createNewGame() { if (txtName.Text.Trim().Length > 2) { object o = null; int startYear = (int)cbStartYear.SelectedItem; int opponents = (int)cbOpponents.SelectedItem; Airline airline = (Airline)cbAirline.SelectedItem; Continent continent = (Continent)cbContinent.SelectedItem; Region region = (Region)cbRegion.SelectedItem; if (this.OpponentType == OpponentSelect.User) { if (cbSameRegion.IsChecked.Value) { o = PopUpSelectOpponents.ShowPopUp(airline, opponents, startYear, airline.Profile.Country.Region); } else { o = PopUpSelectOpponents.ShowPopUp(airline, opponents, startYear, region, continent); } } // popUpSplash.IsOpen = true; DoEvents(); GameTimeZone gtz = (GameTimeZone)cbTimeZone.SelectedItem; GameObject.GetInstance().DayRoundEnabled = cbDayTurnEnabled.IsChecked.Value; GameObject.GetInstance().TimeZone = gtz; GameObject.GetInstance().Difficulty = (DifficultyLevel)cbDifficulty.SelectedItem; GameObject.GetInstance().GameTime = new DateTime(startYear, 1, 1); GameObject.GetInstance().StartDate = GameObject.GetInstance().GameTime; //sets the fuel price GameObject.GetInstance().FuelPrice = Inflations.GetInflation(GameObject.GetInstance().GameTime.Year).FuelPrice; airline.Profile.Country = (Country)cbCountry.SelectedItem; airline.Profile.CEO = txtName.Text.Trim(); GameObject.GetInstance().setHumanAirline(airline); GameObject.GetInstance().MainAirline = GameObject.GetInstance().HumanAirline; if (cbLocalCurrency.IsChecked.Value) { GameObject.GetInstance().CurrencyCountry = airline.Profile.Country; } // AppSettings.GetInstance().resetCurrencyFormat(); Airport airport = (Airport)cbAirport.SelectedItem; AirportHelpers.RentGates(airport, airline, 2); AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1); AirportFacility facility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.Service).Find((delegate(AirportFacility f) { return(f.TypeLevel == 1); })); airport.addAirportFacility(GameObject.GetInstance().HumanAirline, facility, GameObject.GetInstance().GameTime); airport.addAirportFacility(GameObject.GetInstance().HumanAirline, checkinFacility, GameObject.GetInstance().GameTime); if (continent.Uid != "100" || region.Uid != "100") { var airlines = Airlines.GetAirlines(a => a.Profile.Country.Region == region || (region.Uid == "100" && continent.hasRegion(a.Profile.Country.Region)) && a.Profile.Founded <= startYear && a.Profile.Folded > startYear); var airports = Airports.GetAirports(a => a.Profile.Country.Region == region || (region.Uid == "100" && continent.hasRegion(a.Profile.Country.Region)) && a.Profile.Period.From.Year <= startYear && a.Profile.Period.To.Year > startYear); //Airports.RemoveAirports(a => (a.Profile.Country.Region != region && !continent.hasRegion(a.Profile.Country.Region)) || (a.Profile.Town.State != null && a.Profile.Town.State.IsOverseas)); Airports.Clear(); foreach (Airport a in airports) { Airports.AddAirport(a); } Airlines.Clear(); foreach (Airline a in airlines) { Airlines.AddAirline(a); } } PassengerHelpers.CreateAirlineDestinationDemand(); AirlinerHelpers.CreateStartUpAirliners(); if (this.OpponentType == OpponentSelect.Random || o == null) { Setup.SetupMainGame(opponents, cbSameRegion.IsChecked.Value); } else { Setup.SetupMainGame((List <Airline>)o); } airline.MarketFocus = (Airline.AirlineFocus)cbFocus.SelectedItem; GeneralHelpers.CreateHolidays(GameObject.GetInstance().GameTime.Year); //PassengerHelpers.CreateDestinationPassengers(); GameObjectWorker.GetInstance().start(); // AIWorker.GetInstance().start(); PageNavigator.NavigateTo(new PageAirline(GameObject.GetInstance().HumanAirline)); PageNavigator.ClearNavigator(); //GameObject.GetInstance().HumanAirline.Money = 10000000000000; GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Standard_News, GameObject.GetInstance().GameTime, Translator.GetInstance().GetString("News", "1001"), string.Format(Translator.GetInstance().GetString("News", "1001", "message"), GameObject.GetInstance().HumanAirline.Profile.CEO, GameObject.GetInstance().HumanAirline.Profile.IATACode))); popUpSplash.IsOpen = false; Action action = () => { Stopwatch swPax = new Stopwatch(); swPax.Start(); PassengerHelpers.CreateDestinationDemand(); Console.WriteLine("Demand have been created in {0} ms.", swPax.ElapsedMilliseconds); swPax.Stop(); }; Task.Factory.StartNew(action); //Task.Run(action); //Task t2 = Task.Factory.StartNew(action, "passengers"); } else { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2403"), Translator.GetInstance().GetString("MessageBox", "2403"), WPFMessageBoxButtons.Ok); } }
public CompareAirportMVVM(Airport airport) { this.Airport = airport; this.Routes = AirportHelpers.GetAirportRoutes(this.Airport).Count; this.ServingAirlines = this.Airport.AirlineContracts.Select(c => c.Airline).Distinct().Count(); }