private void cbAutoRoute_SelectionChanged(object sender, SelectionChangedEventArgs e) { Route route = (Route)cbRoute.SelectedItem; if (route != null) { TimeSpan routeFlightTime = route.getFlightTime(this.Airliner.Airliner.Type); TimeSpan minFlightTime = routeFlightTime.Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(this.Airliner)); int maxHours = 22 - 6; //from 06.00 to 22.00 int flightsPerDay = Convert.ToInt16(maxHours * 60 / (2 * minFlightTime.TotalMinutes)); cbFlightsPerDay.Items.Clear(); for (int i = 0; i < Math.Max(1, flightsPerDay); i++) { cbFlightsPerDay.Items.Add(i + 1); } cbFlightsPerDay.SelectedIndex = 0; cbBusinessRoute.Visibility = minFlightTime.TotalMinutes <= maxBusinessRouteTime ? Visibility.Visible : System.Windows.Visibility.Collapsed; if (minFlightTime.TotalMinutes > maxBusinessRouteTime) { cbBusinessRoute.IsChecked = false; } } }
private void cbAutoRoute_SelectionChanged(object sender, SelectionChangedEventArgs e) { Route route = (Route)cbRoute.SelectedItem; if (route != null) { TimeSpan routeFlightTime = route.getFlightTime(this.Airliner.Airliner.Type); TimeSpan minFlightTime = routeFlightTime.Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(this.Airliner)); cbDelayMinutes.Items.Clear(); int minDelayMinutes = (int)FleetAirlinerHelpers.GetMinTimeBetweenFlights(this.Airliner).TotalMinutes; for (int i = minDelayMinutes; i < minDelayMinutes + 120; i += 15) { cbDelayMinutes.Items.Add(i); } cbDelayMinutes.SelectedIndex = 0; //cbBusinessRoute.Visibility = minFlightTime.TotalMinutes <= maxBusinessRouteTime ? Visibility.Visible : System.Windows.Visibility.Collapsed; //if (minFlightTime.TotalMinutes > maxBusinessRouteTime) // cbBusinessRoute.IsChecked = false; if (this.RouteChanged != null) { this.RouteChanged(route); } } }
//returns the flight time for the route for a specific airliner type public TimeSpan getFlightTime(AirlinerType type) { if (this.HasStopovers) { double totalMinutes = this.Stopovers.SelectMany(s => s.Legs).Sum(l => l.getFlightTime(type).TotalMinutes); double totalRestTime = FleetAirlinerHelpers.GetMinTimeBetweenFlights(type).TotalMinutes *(this.Stopovers.SelectMany(s => s.Legs).Count() - 1); int time = (int)(totalRestTime + totalMinutes); return(new TimeSpan(0, time, 0)); } else { return(MathHelpers.GetFlightTime(this.Destination1, this.Destination2, type)); } }
//sets the next entry public void setNextEntry() { RouteTimeTableEntry entry = null; if (isPassengerFlight()) { entry = this.AllClasses.Keys.ElementAt(CurrentFlight); } if (isCargoFlight()) { entry = this.AllCargo.Keys.ElementAt(CurrentFlight); } this.Entry = entry; if (entry.TimeTable.Route.Type == Route.RouteType.Mixed || entry.TimeTable.Route.Type == Route.RouteType.Passenger) { this.Classes = this.AllClasses[entry]; } if (entry.TimeTable.Route.Type == Route.RouteType.Mixed || entry.TimeTable.Route.Type == Route.RouteType.Cargo) { this.Cargo = this.AllCargo[entry]; } this.Airliner = this.Entry.Airliner; if (CurrentFlight == 0) { this.FlightTime = MathHelpers.ConvertEntryToDate(this.Entry, 0); } else { this.FlightTime = GameObject.GetInstance().GameTime.Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(this.Airliner)); } this.IsOnTime = true; this.DistanceToDestination = MathHelpers.GetDistance(entry.Destination.Airport.Profile.Coordinates.convertToGeoCoordinate(), entry.DepartureAirport.Profile.Coordinates.convertToGeoCoordinate()); CurrentFlight++; }
private void btnAdd_Click(object sender, RoutedEventArgs e) { Route route = (Route)cbRoute.SelectedItem; RouteTimeTable rt; int flightsPerDay = (int)cbFlightsPerDay.SelectedItem; int flightsPerWeek = (int)cbFlightsPerWeek.SelectedItem; int delayMinutes = (int)cbDelayMinutes.SelectedItem; TimeSpan startTime = (TimeSpan)cbStartTime.SelectedItem; string flightcode1 = cbFlightCode.SelectedItem.ToString(); string flightcode2 = this.Airliner.Airliner.Airline.getFlightCodes()[this.Airliner.Airliner.Airline.getFlightCodes().IndexOf(flightcode1) + 1]; if (flightsPerDay > 0) { if (this.RouteOperations == RouteOperationsType.Business) { flightsPerDay = (int)(route.getFlightTime(this.Airliner.Airliner.Type).Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(this.Airliner)).TotalMinutes / 2 / maxBusinessRouteTime); rt = AIHelpers.CreateBusinessRouteTimeTable(route, this.Airliner, Math.Max(1, flightsPerDay), flightcode1, flightcode2); } else { if (this.Interval == FlightInterval.Daily) { rt = AIHelpers.CreateAirlinerRouteTimeTable(route, this.Airliner, flightsPerDay, true, delayMinutes, startTime, flightcode1, flightcode2); } else { rt = AIHelpers.CreateAirlinerRouteTimeTable(route, this.Airliner, flightsPerWeek, false, delayMinutes, startTime, flightcode1, flightcode2); } } } else { rt = null; } if (!TimeTableHelpers.IsTimeTableValid(rt, this.Airliner, this.ParentPage.Entries, false)) { WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2705"), Translator.GetInstance().GetString("MessageBox", "2705", "message"), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { this.ParentPage.NewestEntries.Clear(); this.ParentPage.clearTimeTable(); if (!this.ParentPage.Entries.ContainsKey(route)) { this.ParentPage.Entries.Add(route, new List <RouteTimeTableEntry>()); } foreach (RouteTimeTableEntry entry in rt.Entries) { if (!TimeTableHelpers.IsRouteEntryInOccupied(entry, this.Airliner)) { this.ParentPage.Entries[route].Add(entry); this.ParentPage.NewestEntries.Add(entry); } } } } else { if (!this.ParentPage.Entries.ContainsKey(route)) { this.ParentPage.Entries.Add(route, new List <RouteTimeTableEntry>()); } foreach (RouteTimeTableEntry entry in rt.Entries) { if (!TimeTableHelpers.IsRouteEntryInOccupied(entry, this.Airliner)) { this.ParentPage.Entries[route].Add(entry); this.ParentPage.NewestEntries.Add(entry); } } } this.ParentPage.showFlights(); }
//creates the entries for the stopoverflight private void createEntries(RouteTimeTableEntry mainEntry) { List <Route> routes = mainEntry.TimeTable.Route.Stopovers.SelectMany(s => s.Legs).ToList(); TimeSpan time = mainEntry.Time; Boolean isInbound = mainEntry.DepartureAirport == mainEntry.TimeTable.Route.Destination2; if (isInbound) { routes.Reverse(); } foreach (Route route in routes) { RouteTimeTable timetable = new RouteTimeTable(route); RouteTimeTableEntry entry; //inbound if (isInbound) { entry = new RouteTimeTableEntry(timetable, mainEntry.Day, time, new RouteEntryDestination(route.Destination1, mainEntry.Destination.FlightCode)); time = time.Add(entry.TimeTable.Route.getFlightTime(mainEntry.Airliner.Airliner.Type)).Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(mainEntry.Airliner)); entry.Airliner = mainEntry.Airliner; entry.MainEntry = mainEntry; } //outbound else { entry = new RouteTimeTableEntry(timetable, mainEntry.Day, time, new RouteEntryDestination(route.Destination2, mainEntry.Destination.FlightCode)); entry.Airliner = mainEntry.Airliner; entry.MainEntry = mainEntry; time = time.Add(entry.TimeTable.Route.getFlightTime(mainEntry.Airliner.Airliner.Type)).Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(mainEntry.Airliner)); } if (route.Type == Route.RouteType.Passenger || route.Type == Route.RouteType.Mixed) { List <FlightAirlinerClass> classes = new List <FlightAirlinerClass>(); foreach (AirlinerClass aClass in this.Airliner.Airliner.Classes) { FlightAirlinerClass faClass; if (isInbound) { faClass = new FlightAirlinerClass(((PassengerRoute)route).getRouteAirlinerClass(aClass.Type), PassengerHelpers.GetStopoverFlightPassengers(this.Airliner, aClass.Type, route.Destination2, route.Destination1, routes, isInbound)); } else { faClass = new FlightAirlinerClass(((PassengerRoute)route).getRouteAirlinerClass(aClass.Type), PassengerHelpers.GetStopoverFlightPassengers(this.Airliner, aClass.Type, route.Destination1, route.Destination2, routes, isInbound)); } classes.Add(faClass); } this.AllClasses.Add(entry, classes); } if (route.Type == Route.RouteType.Cargo || route.Type == Route.RouteType.Mixed) { if (isInbound) { this.AllCargo.Add(entry, PassengerHelpers.GetStopoverFlightCargo(this.Airliner, route.Destination2, route.Destination1, routes, isInbound)); } else { this.AllCargo.Add(entry, PassengerHelpers.GetStopoverFlightCargo(this.Airliner, route.Destination1, route.Destination2, routes, isInbound)); } } } }
private void cbHomebound_SelectionChanged(object sender, SelectionChangedEventArgs e) { Route route = (Route)cbHomebound.SelectedItem; if (route != null) { this.IsLongRoute = MathHelpers.GetFlightTime(route.Destination1, route.Destination2, this.Airliner.Airliner.Type).Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(this.Airliner.Airliner.Type)).TotalHours > 12; } else { this.IsLongRoute = false; } }
private void btnAddGenerator_Click(object sender, RoutedEventArgs e) { Route route = (Route)cbRoute.SelectedItem; RouteTimeTable rt = null; IntervalType intervalType = (IntervalType)cbIntervalType.SelectedItem; int interval = Convert.ToInt16(cbInterval.SelectedItem); OpsType opsType = (OpsType)cbSchedule.SelectedItem; int delayMinutes = (int)cbDelayMinutes.SelectedItem; double maxBusinessRouteTime = new TimeSpan(2, 0, 0).TotalMinutes; TimeSpan startTime = (TimeSpan)cbStartTime.SelectedItem; string flightcode1 = this.Airliner.Airliner.Airline.Profile.IATACode + txtFlightNumber.Text; int indexOf = this.Airliner.Airliner.Airline.getFlightCodes().IndexOf(flightcode1); string flightcode2; if (indexOf == this.Airliner.Airliner.Airline.getFlightCodes().Count) { flightcode2 = ""; } else { flightcode2 = this.Airliner.Airliner.Airline.getFlightCodes()[indexOf + 1]; } if (opsType == OpsType.Business) { int flightsPerDay = (int)(route.getFlightTime(this.Airliner.Airliner.Type).Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(this.Airliner)).TotalMinutes / 2 / maxBusinessRouteTime); rt = AIHelpers.CreateBusinessRouteTimeTable(route, this.Airliner, Math.Max(1, flightsPerDay), flightcode1, flightcode2); } if (intervalType == IntervalType.Day && opsType != OpsType.Business) { rt = AIHelpers.CreateAirlinerRouteTimeTable(route, this.Airliner, interval, true, delayMinutes, startTime, flightcode1, flightcode2); } if (intervalType == IntervalType.Week && opsType != OpsType.Business) { rt = AIHelpers.CreateAirlinerRouteTimeTable(route, this.Airliner, interval, false, delayMinutes, startTime, flightcode1, flightcode2); } if (!TimeTableHelpers.IsTimeTableValid(rt, this.Airliner, this.Entries.ToList(), false)) { WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2705"), Translator.GetInstance().GetString("MessageBox", "2705", "message"), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { clearTimeTable(); foreach (RouteTimeTableEntry entry in rt.Entries) { if (!TimeTableHelpers.IsRouteEntryInOccupied(entry, this.Airliner)) { this.Entries.Add(entry); } } } } else { foreach (RouteTimeTableEntry entry in rt.Entries) { if (!TimeTableHelpers.IsRouteEntryInOccupied(entry, this.Airliner)) { this.Entries.Add(entry); } } } setFlightNumbers(); }
//checks if an entry is valid private static Boolean IsRouteEntryValid(RouteTimeTableEntry entry, FleetAirliner airliner, List <RouteTimeTableEntry> entries, Boolean withSlots) { TimeSpan flightTime = entry.TimeTable.Route.getFlightTime(airliner.Airliner.Type).Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(airliner)); TimeSpan startTime = new TimeSpan((int)entry.Day, entry.Time.Hours, entry.Time.Minutes, entry.Time.Seconds); TimeSpan endTime = startTime.Add(flightTime); if (endTime.Days == 7) { endTime = new TimeSpan(0, endTime.Hours, endTime.Minutes, endTime.Seconds); } List <RouteTimeTableEntry> airlinerEntries = entries; if (withSlots) { if (IsRouteEntryInOccupied(entry, airliner)) { return(false); } } // airlinerEntries.AddRange(entry.TimeTable.Entries.FindAll(e => e.Destination.Airport == entry.Destination.Airport)); foreach (RouteTimeTableEntry e in airlinerEntries) { TimeSpan eStartTime = new TimeSpan((int)e.Day, e.Time.Hours, e.Time.Minutes, e.Time.Seconds); TimeSpan eFlightTime = e.TimeTable.Route.getFlightTime(airliner.Airliner.Type).Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(airliner)); TimeSpan eEndTime = eStartTime.Add(eFlightTime); double diffStartTime = Math.Abs(eStartTime.Subtract(startTime).TotalMinutes); double diffEndTime = Math.Abs(eEndTime.Subtract(endTime).TotalMinutes); if (eEndTime.Days == 7) { eEndTime = new TimeSpan(0, eEndTime.Hours, eEndTime.Minutes, eEndTime.Seconds); } if ((eStartTime >= startTime && endTime >= eStartTime) || (eEndTime >= startTime && endTime >= eEndTime) || (endTime >= eStartTime && eEndTime >= endTime) || (startTime >= eStartTime && eEndTime >= startTime)) { if (e.Airliner == airliner || diffEndTime < 15 || diffStartTime < 15) { return(false); } } } double minutesPerWeek = 7 * 24 * 60; RouteTimeTableEntry nextEntry = GetNextEntry(entry, airliner, entries); RouteTimeTableEntry previousEntry = GetPreviousEntry(entry, airliner, entries); if (nextEntry != null && previousEntry != null) { TimeSpan flightTimeNext = MathHelpers.GetFlightTime(entry.Destination.Airport.Profile.Coordinates, nextEntry.DepartureAirport.Profile.Coordinates, airliner.Airliner.Type.CruisingSpeed).Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(airliner)); TimeSpan flightTimePrevious = MathHelpers.GetFlightTime(entry.DepartureAirport.Profile.Coordinates, previousEntry.Destination.Airport.Profile.Coordinates, airliner.Airliner.Type.CruisingSpeed).Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(airliner)); TimeSpan prevDate = new TimeSpan((int)previousEntry.Day, previousEntry.Time.Hours, previousEntry.Time.Minutes, previousEntry.Time.Seconds); TimeSpan nextDate = new TimeSpan((int)nextEntry.Day, nextEntry.Time.Hours, nextEntry.Time.Minutes, nextEntry.Time.Seconds); TimeSpan currentDate = new TimeSpan((int)entry.Day, entry.Time.Hours, entry.Time.Minutes, entry.Time.Seconds); double timeToNext = currentDate.Subtract(nextDate).TotalMinutes > 0 ? minutesPerWeek - currentDate.Subtract(nextDate).TotalMinutes : Math.Abs(currentDate.Subtract(nextDate).TotalMinutes); double timeFromPrev = prevDate.Subtract(currentDate).TotalMinutes > 0 ? minutesPerWeek - prevDate.Subtract(currentDate).TotalMinutes : Math.Abs(prevDate.Subtract(currentDate).TotalMinutes); if (timeFromPrev > previousEntry.TimeTable.Route.getFlightTime(airliner.Airliner.Type).TotalMinutes + flightTimePrevious.TotalMinutes && timeToNext > entry.TimeTable.Route.getFlightTime(airliner.Airliner.Type).TotalMinutes + flightTimeNext.TotalMinutes) { return(true); } else { return(false); } } else { return(true); } }
//checks if an entry is valid private Boolean isRouteEntryValid(RouteTimeTableEntry entry, Boolean showMessageBoxOnError) { TimeSpan flightTime = entry.TimeTable.Route.getFlightTime(this.Airliner.Airliner.Type).Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(this.Airliner)); TimeSpan startTime = new TimeSpan((int)entry.Day, entry.Time.Hours, entry.Time.Minutes, entry.Time.Seconds); TimeSpan endTime = startTime.Add(flightTime); if (endTime.Days == 7) { endTime = new TimeSpan(0, endTime.Hours, endTime.Minutes, endTime.Seconds); } List <RouteTimeTableEntry> airlinerEntries = this.Airliner.Routes.SelectMany(r => r.TimeTable.Entries.FindAll(e => e.Airliner == this.Airliner)).ToList(); airlinerEntries.AddRange(this.Entries.Keys.SelectMany(r => this.Entries[r])); //var deletable = this.EntriesToDelete.Keys.SelectMany(r => this.Entries.ContainsKey(r) ? this.Entries[r] : null); List <RouteTimeTableEntry> deletable = new List <RouteTimeTableEntry>(); deletable.AddRange(this.EntriesToDelete.Keys.SelectMany(r => this.EntriesToDelete[r])); foreach (Route route in this.EntriesToDelete.Keys) { if (this.Entries.ContainsKey(route)) { deletable.AddRange(this.Entries[route]); } } foreach (RouteTimeTableEntry e in deletable) { if (airlinerEntries.Contains(e)) { airlinerEntries.Remove(e); } } airlinerEntries.AddRange(entry.TimeTable.Entries.FindAll(e => e.Destination.Airport == entry.Destination.Airport)); foreach (RouteTimeTableEntry e in airlinerEntries) { TimeSpan eStartTime = new TimeSpan((int)e.Day, e.Time.Hours, e.Time.Minutes, e.Time.Seconds); TimeSpan eFlightTime = e.TimeTable.Route.getFlightTime(this.Airliner.Airliner.Type).Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(this.Airliner)); TimeSpan eEndTime = eStartTime.Add(eFlightTime); double diffStartTime = Math.Abs(eStartTime.Subtract(startTime).TotalMinutes); double diffEndTime = Math.Abs(eEndTime.Subtract(endTime).TotalMinutes); if (eEndTime.Days == 7) { eEndTime = new TimeSpan(0, eEndTime.Hours, eEndTime.Minutes, eEndTime.Seconds); } if ((eStartTime >= startTime && endTime >= eStartTime) || (eEndTime >= startTime && endTime >= eEndTime) || (endTime >= eStartTime && eEndTime >= endTime) || (startTime >= eStartTime && eEndTime >= startTime)) { if (e.Airliner == this.Airliner || diffEndTime < 15 || diffStartTime < 15) { if (showMessageBoxOnError) { if (e.Airliner == this.Airliner) { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2702"), string.Format(Translator.GetInstance().GetString("MessageBox", "2702", "message")), WPFMessageBoxButtons.Ok); } else { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2703"), string.Format(Translator.GetInstance().GetString("MessageBox", "2703", "message")), WPFMessageBoxButtons.Ok); } } return(false); } } } double minutesPerWeek = 7 * 24 * 60; RouteTimeTableEntry nextEntry = getNextEntry(entry); RouteTimeTableEntry previousEntry = getPreviousEntry(entry); if (nextEntry != null && previousEntry != null) { TimeSpan flightTimeNext = MathHelpers.GetFlightTime(entry.Destination.Airport.Profile.Coordinates, nextEntry.DepartureAirport.Profile.Coordinates, this.Airliner.Airliner.Type.CruisingSpeed).Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(this.Airliner)); TimeSpan flightTimePrevious = MathHelpers.GetFlightTime(entry.DepartureAirport.Profile.Coordinates, previousEntry.Destination.Airport.Profile.Coordinates, this.Airliner.Airliner.Type.CruisingSpeed).Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(this.Airliner)); TimeSpan prevDate = new TimeSpan((int)previousEntry.Day, previousEntry.Time.Hours, previousEntry.Time.Minutes, previousEntry.Time.Seconds); TimeSpan nextDate = new TimeSpan((int)nextEntry.Day, nextEntry.Time.Hours, nextEntry.Time.Minutes, nextEntry.Time.Seconds); TimeSpan currentDate = new TimeSpan((int)entry.Day, entry.Time.Hours, entry.Time.Minutes, entry.Time.Seconds); double timeToNext = currentDate.Subtract(nextDate).TotalMinutes > 0 ? minutesPerWeek - currentDate.Subtract(nextDate).TotalMinutes : Math.Abs(currentDate.Subtract(nextDate).TotalMinutes); double timeFromPrev = prevDate.Subtract(currentDate).TotalMinutes > 0 ? minutesPerWeek - prevDate.Subtract(currentDate).TotalMinutes : Math.Abs(prevDate.Subtract(currentDate).TotalMinutes); if (timeFromPrev > previousEntry.TimeTable.Route.getFlightTime(this.Airliner.Airliner.Type).TotalMinutes + flightTimePrevious.TotalMinutes && timeToNext > entry.TimeTable.Route.getFlightTime(this.Airliner.Airliner.Type).TotalMinutes + flightTimeNext.TotalMinutes) { return(true); } else { if (showMessageBoxOnError) { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2704"), string.Format(Translator.GetInstance().GetString("MessageBox", "2704", "message")), WPFMessageBoxButtons.Ok); } return(false); } } else { return(true); } }
private void btnOk_Click(object sender, RoutedEventArgs e) { Route route = (Route)cbRoute.SelectedItem; int flightsPerDay = (int)cbFlightsPerDay.SelectedItem; string flightcode1 = cbFlightCode.SelectedItem.ToString(); string flightcode2 = this.Airliner.Airliner.Airline.getFlightCodes()[this.Airliner.Airliner.Airline.getFlightCodes().IndexOf(flightcode1) + 1]; if (flightsPerDay > 0) { if (cbBusinessRoute.IsChecked.Value) { flightsPerDay = (int)(route.getFlightTime(this.Airliner.Airliner.Type).Add(FleetAirlinerHelpers.GetMinTimeBetweenFlights(this.Airliner)).TotalMinutes / 2 / maxBusinessRouteTime); this.Selected = AIHelpers.CreateBusinessRouteTimeTable(route, this.Airliner, Math.Max(1, flightsPerDay), flightcode1, flightcode2); } else { this.Selected = AIHelpers.CreateAirlinerRouteTimeTable(route, this.Airliner, flightsPerDay, flightcode1, flightcode2); } } else { this.Selected = null; } this.Close(); }