private void cbDestination_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (cbDestination1 != null && cbDestination2 != null && txtDistance != null) { Airport destination1 = (Airport)cbDestination1.SelectedItem; Airport destination2 = (Airport)cbDestination2.SelectedItem; if (destination1 != null && destination2 != null) { foreach (MVVMRouteClass rClass in this.Classes) { rClass.FarePrice = PassengerHelpers.GetPassengerPrice(destination1, destination2) * GeneralHelpers.ClassToPriceFactor(rClass.Type); } txtDistance.Text = new DistanceToUnitConverter().Convert(MathHelpers.GetDistance(destination1, destination2)).ToString(); var codesharingRoutes = GameObject.GetInstance().HumanAirline.Codeshares.Where(c => c.Airline2 == GameObject.GetInstance().HumanAirline || c.Type == Model.AirlineModel.CodeshareAgreement.CodeshareType.Both_Ways).Select(c => c.Airline1 == GameObject.GetInstance().HumanAirline ? c.Airline2 : c.Airline1).SelectMany(a => a.Routes); var humanConnectingRoutes = GameObject.GetInstance().HumanAirline.Routes.Where(r => r.Destination1 == destination1 || r.Destination2 == destination1 || r.Destination1 == destination2 || r.Destination2 == destination2); var codesharingConnectingRoutes = codesharingRoutes.Where(r => r.Destination1 == destination1 || r.Destination2 == destination1 || r.Destination1 == destination2 || r.Destination2 == destination2); this.ConnectingRoutes.Clear(); foreach (Route route in humanConnectingRoutes) { this.ConnectingRoutes.Add(route); } foreach (Route route in codesharingConnectingRoutes) { this.ConnectingRoutes.Add(route); } var opponentRoutes = Airlines.GetAllAirlines().Where(a => !a.IsHuman).SelectMany(a => a.Routes).Where(r => (r.Destination1 == destination1 && r.Destination2 == destination2) || (r.Destination2 == destination1 && r.Destination1 == destination2)); if (opponentRoutes.Count() == 0) { this.RouteInformationText = ""; } else { var airlines = opponentRoutes.Select(r => r.Airline).Distinct(); if (airlines.Count() == 1) { this.RouteInformationText = string.Format("{0} also operates a route between {1} and {2}", airlines.ElementAt(0).Profile.Name, destination1.Profile.Name, destination2.Profile.Name); } else { this.RouteInformationText = string.Format("{0} other airlines do also operate a route between {1} and {2}", airlines.Count(), destination1.Profile.Name, destination2.Profile.Name); } } } } }
private void cbDestination_SelectionChanged(object sender, SelectionChangedEventArgs e) { Airport destination1 = (Airport)cbDestination1.SelectedItem; Airport destination2 = (Airport)cbDestination2.SelectedItem; if (destination1 != null && destination2 != null) { foreach (MVVMRouteClass rClass in this.Classes) { rClass.FarePrice = PassengerHelpers.GetPassengerPrice(destination1, destination2) * GeneralHelpers.ClassToPriceFactor(rClass.Type); } txtDistance.Text = new DistanceToUnitConverter().Convert(MathHelpers.GetDistance(destination1, destination2)).ToString(); } }
//sets up an scenario airline route private static void SetupScenarioRoute(ScenarioAirlineRoute saroute, Airline airline) { SetupScenarioAirport(airline, saroute.Destination1, saroute.Quantity); SetupScenarioAirport(airline, saroute.Destination2, saroute.Quantity); double price = PassengerHelpers.GetPassengerPrice(saroute.Destination1, saroute.Destination2); for (int i = 0; i < saroute.Quantity; i++) { Guid id = Guid.NewGuid(); PassengerRoute route = new PassengerRoute(id.ToString(), saroute.Destination1, saroute.Destination2, price); RouteClassesConfiguration configuration = AIHelpers.GetRouteConfiguration(route); foreach (RouteClassConfiguration classConfiguration in configuration.getClasses()) { route.getRouteAirlinerClass(classConfiguration.Type).FarePrice = price * GeneralHelpers.ClassToPriceFactor(classConfiguration.Type); foreach (RouteFacility rfacility in classConfiguration.getFacilities()) { route.getRouteAirlinerClass(classConfiguration.Type).addFacility(rfacility); } } airline.addRoute(route); FleetAirliner fAirliner = AirlineHelpers.CreateAirliner(airline, saroute.AirlinerType); airline.addAirliner(fAirliner); fAirliner.addRoute(route); AIHelpers.CreateRouteTimeTable(route, fAirliner); fAirliner.Status = FleetAirliner.AirlinerStatus.To_route_start; AirlineHelpers.HireAirlinerPilots(fAirliner); route.LastUpdated = GameObject.GetInstance().GameTime; } }
private void cbDestination_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (cbDestination2.SelectedItem != null && cbDestination1.SelectedItem != null) { Airport airport1 = (Airport)cbDestination1.SelectedItem; Airport airport2 = (Airport)cbDestination2.SelectedItem; Airport stopover1 = ucStopover1.Value; Airport stopover2 = ucStopover2.Value; List <double> distances = new List <double>(); List <Airport> destinations = new List <Airport>(); destinations.Add(airport1); Boolean isRouteOk = false; if (stopover1 == null && stopover2 == null) { distances.Add(MathHelpers.GetDistance(airport1, airport2)); isRouteOk = checkRouteOk(airport1, airport2); } if (stopover1 == null && stopover2 != null) { distances.Add(MathHelpers.GetDistance(airport1, stopover2)); distances.Add(MathHelpers.GetDistance(stopover2, airport2)); isRouteOk = checkRouteOk(airport1, stopover2) && checkRouteOk(stopover2, airport2); destinations.Add(stopover2); } if (stopover1 != null && stopover2 == null) { distances.Add(MathHelpers.GetDistance(airport1, stopover1)); distances.Add(MathHelpers.GetDistance(stopover1, airport2)); isRouteOk = checkRouteOk(airport1, stopover1) && checkRouteOk(stopover1, airport2); destinations.Add(stopover1); } if (stopover1 != null && stopover2 != null) { distances.Add(MathHelpers.GetDistance(airport1, stopover1)); distances.Add(MathHelpers.GetDistance(stopover1, stopover2)); distances.Add(MathHelpers.GetDistance(stopover2, airport2)); isRouteOk = checkRouteOk(airport1, stopover1) && checkRouteOk(stopover1, stopover2) && checkRouteOk(stopover2, airport2); destinations.Add(stopover1); destinations.Add(stopover2); } destinations.Add(airport2); foreach (RouteAirlinerClass aClass in this.Classes.Values) { aClass.FarePrice = PassengerHelpers.GetPassengerPrice(airport1, airport2) * GeneralHelpers.ClassToPriceFactor(aClass.Type); } double maxDistance = distances.Max(); double minDistance = distances.Min(); txtDistance.Text = string.Format("{0:0} {1}", new NumberToUnitConverter().Convert(maxDistance), new StringToLanguageConverter().Convert("km.")); btnSave.IsEnabled = minDistance > 50 && maxDistance < this.MaxDistance && isRouteOk; btnLoad.IsEnabled = btnSave.IsEnabled; txtInvalidRoute.Visibility = isRouteOk ? Visibility.Collapsed : Visibility.Visible; if (this.RouteType == Route.RouteType.Cargo && !AIHelpers.IsCargoRouteDestinationsCorrect(airport1, airport2, GameObject.GetInstance().HumanAirline)) { txtInvalidRoute.Text = Translator.GetInstance().GetString("PanelNewRoute", "1009"); } txtRoute.Text = string.Join(" <-> ", from d in destinations select new AirportCodeConverter().Convert(d).ToString()); } if (sender is ComboBox) { Airport airport = (Airport)((ComboBox)sender).SelectedItem; TextBlock txtDestinationGates = cbDestination2 == ((ComboBox)sender) ? txtDestination2Gates : txtDestination1Gates; txtDestinationGates.Text = string.Format(Translator.GetInstance().GetString("PanelNewRoute", "206"), airport.Terminals.getFreeSlotsPercent(GameObject.GetInstance().HumanAirline)); } }