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; } } }
//converts the airliner to a cargo airliner public void convertToCargo() { FleetAirlinerHelpers.ConvertPassengerToCargoAirliner(this.Airliner); PageNavigator.NavigateTo(new PageAirline(this.Airliner.Airliner.Airline)); }
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); } } }
//creates a route and returns if success private Boolean createRoute() { Route route = null; Airport destination1 = (Airport)cbDestination1.SelectedItem; Airport destination2 = (Airport)cbDestination2.SelectedItem; Airport stopover1 = (Airport)cbStopover1.SelectedItem; Airport stopover2 = cbStopover2.Visibility == System.Windows.Visibility.Visible ? (Airport)cbStopover2.SelectedItem : null; try { if (AirlineHelpers.IsRouteDestinationsOk(GameObject.GetInstance().HumanAirline, destination1, destination2, rbPassenger.IsChecked.Value ? Route.RouteType.Passenger : Route.RouteType.Cargo, stopover1, stopover2)) { Guid id = Guid.NewGuid(); //passenger route if (rbPassenger.IsChecked.Value) { route = new PassengerRoute(id.ToString(), destination1, destination2, 0); foreach (MVVMRouteClass rac in this.Classes) { ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).FarePrice = rac.FarePrice; foreach (MVVMRouteFacility facility in rac.Facilities) { ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).addFacility(facility.SelectedFacility); } } } //cargo route else { double cargoPrice = Convert.ToDouble(txtCargoPrice.Text); route = new CargoRoute(id.ToString(), destination1, destination2, cargoPrice); } FleetAirlinerHelpers.CreateStopoverRoute(route, stopover1, stopover2); GameObject.GetInstance().HumanAirline.addRoute(route); return(true); } } catch (Exception ex) { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", ex.Message), Translator.GetInstance().GetString("MessageBox", ex.Message, "message"), WPFMessageBoxButtons.Ok); return(false); } return(false); }
//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)); } }
private void schedule_Maintenance() { //sets the values int aMI = (int)this.slMaintenanceA.Value; this.Airliner.SchedAMaintenance = GameObject.GetInstance().GameTime.AddDays(aMI); int bMI = (int)this.slMaintenanceB.Value; this.Airliner.SchedBMaintenance = GameObject.GetInstance().GameTime.AddDays(bMI); RadioButton rbDateC = UICreator.FindChild <RadioButton>(this, "rbDateC"); RadioButton rbDateD = UICreator.FindChild <RadioButton>(this, "rbDateD"); Slider slMaintenanceD = UICreator.FindChild <Slider>(this, "slMaintenanceD"); Slider slMaintenanceC = UICreator.FindChild <Slider>(this, "slMaintenanceC"); if (rbDateC.IsChecked == true && rbDateD.IsChecked == true) { this.Airliner.SchedCMaintenance = (DateTime)this.dpMaintenanceC.SelectedDate; this.Airliner.SchedDMaintenance = (DateTime)this.dpMaintenanceD.SelectedDate; FleetAirlinerHelpers.SetMaintenanceIntervals(this.Airliner, aMI, bMI); } else if (rbDateC.IsChecked == true && rbDateD.IsChecked == false) { this.Airliner.SchedCMaintenance = (DateTime)this.dpMaintenanceC.SelectedDate; int dMI = (int)slMaintenanceD.Value; this.Airliner.CMaintenanceInterval = -1; this.Airliner.SchedDMaintenance = GameObject.GetInstance().GameTime.AddMonths(dMI); FleetAirlinerHelpers.SetMaintenanceIntervals(this.Airliner, aMI, bMI, dMI); } else if (rbDateD.IsChecked == true && rbDateC.IsChecked == false) { this.Airliner.SchedDMaintenance = (DateTime)this.dpMaintenanceD.SelectedDate; this.Airliner.DMaintenanceInterval = -1; int cMI = (int)slMaintenanceC.Value; this.Airliner.SchedCMaintenance = GameObject.GetInstance().GameTime.AddMonths(cMI); FleetAirlinerHelpers.SetMaintenanceIntervals(this.Airliner, aMI, bMI, cMI); } else { int dMI = (int)slMaintenanceD.Value; this.Airliner.SchedDMaintenance = GameObject.GetInstance().GameTime.AddMonths(dMI); int cMI = (int)slMaintenanceC.Value; this.Airliner.SchedCMaintenance = GameObject.GetInstance().GameTime.AddMonths(cMI); FleetAirlinerHelpers.SetMaintenanceIntervals(this.Airliner, aMI, bMI, cMI, dMI); } }
//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++; }
//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); } }
//creates a route and returns if success private Boolean createRoute() { Route route = null; Airport destination1 = (Airport)cbDestination1.SelectedItem; Airport destination2 = (Airport)cbDestination2.SelectedItem; Airport stopover1 = (Airport)cbStopover1.SelectedItem; Airport stopover2 = cbStopover2.Visibility == System.Windows.Visibility.Visible ? (Airport)cbStopover2.SelectedItem : null; DateTime startDate = dpStartDate.IsEnabled && dpStartDate.SelectedDate.HasValue ? dpStartDate.SelectedDate.Value : GameObject.GetInstance().GameTime; Weather.Season season = rbSeasonAll.IsChecked.Value ? Weather.Season.All_Year : Weather.Season.Winter; season = rbSeasonSummer.IsChecked.Value ? Weather.Season.Summer : season; season = rbSeasonWinter.IsChecked.Value ? Weather.Season.Winter : season; try { if (AirlineHelpers.IsRouteDestinationsOk(GameObject.GetInstance().HumanAirline, destination1, destination2, this.RouteType, stopover1, stopover2)) { Guid id = Guid.NewGuid(); //passenger route if (this.RouteType == Route.RouteType.Passenger) { //Vis på showroute route = new PassengerRoute(id.ToString(), destination1, destination2, startDate, 0); foreach (MVVMRouteClass rac in this.Classes) { ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).FarePrice = rac.FarePrice; foreach (MVVMRouteFacility facility in rac.Facilities) { ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).addFacility(facility.SelectedFacility); } } } //cargo route else if (this.RouteType == Route.RouteType.Cargo) { double cargoPrice = Convert.ToDouble(txtCargoPrice.Text); route = new CargoRoute(id.ToString(), destination1, destination2, startDate, cargoPrice); } else if (this.RouteType == Route.RouteType.Mixed) { double cargoPrice = Convert.ToDouble(txtCargoPrice.Text); route = new CombiRoute(id.ToString(), destination1, destination2, startDate, 0, cargoPrice); foreach (MVVMRouteClass rac in this.Classes) { ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).FarePrice = rac.FarePrice; foreach (MVVMRouteFacility facility in rac.Facilities) { ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).addFacility(facility.SelectedFacility); } } } FleetAirlinerHelpers.CreateStopoverRoute(route, stopover1, stopover2); route.Season = season; GameObject.GetInstance().HumanAirline.addRoute(route); return(true); } } catch (Exception ex) { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", ex.Message), Translator.GetInstance().GetString("MessageBox", ex.Message, "message"), WPFMessageBoxButtons.Ok); return(false); } return(false); }
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 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(); }
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 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(); }
private void btnSave_Click(object sender, RoutedEventArgs e) { Airline airline = GameObject.GetInstance().HumanAirline; Airport dest1 = (Airport)cbDestination1.SelectedItem; Airport dest2 = (Airport)cbDestination2.SelectedItem; Airport stopover1 = ucStopover1.Value; Airport stopover2 = ucStopover2.Value; Boolean stopoverOk = (stopover1 == null ? true : AirportHelpers.HasFreeGates(stopover1, airline)) && (stopover2 == null ? true : AirportHelpers.HasFreeGates(stopover2, airline)); if (AirportHelpers.HasFreeGates(dest1, airline) && AirportHelpers.HasFreeGates(dest2, airline) && stopoverOk) { Route route = null; Guid id = Guid.NewGuid(); if (this.RouteType == Route.RouteType.Passenger) { route = new PassengerRoute(id.ToString(), dest1, dest2, 0); foreach (RouteAirlinerClass aClass in this.Classes.Values) { ((PassengerRoute)route).getRouteAirlinerClass(aClass.Type).FarePrice = aClass.FarePrice; foreach (RouteFacility facility in aClass.getFacilities()) { ((PassengerRoute)route).getRouteAirlinerClass(aClass.Type).addFacility(facility); } ((PassengerRoute)route).getRouteAirlinerClass(aClass.Type).Seating = aClass.Seating; } } if (this.RouteType == Route.RouteType.Cargo) { route = new CargoRoute(id.ToString(), dest1, dest2, this.CargoPrice); } if (stopover1 != null) { if (stopover2 != null) { route.addStopover(FleetAirlinerHelpers.CreateStopoverRoute(dest1, stopover1, stopover2, route, false, this.RouteType)); } else { route.addStopover(FleetAirlinerHelpers.CreateStopoverRoute(dest1, stopover1, dest2, route, false, this.RouteType)); } } if (stopover2 != null) { if (stopover1 != null) { route.addStopover(FleetAirlinerHelpers.CreateStopoverRoute(stopover1, stopover2, dest2, route, true, this.RouteType)); } else { route.addStopover(FleetAirlinerHelpers.CreateStopoverRoute(dest1, stopover2, dest2, route, false, this.RouteType)); } } airline.addRoute(route); PageNavigator.NavigateTo(new PageRoutes()); this.Visibility = System.Windows.Visibility.Collapsed; route.LastUpdated = GameObject.GetInstance().GameTime; } else { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2501"), Translator.GetInstance().GetString("MessageBox", "2501", "message"), WPFMessageBoxButtons.Ok); } }
//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); } }
//simulates a flight private static void SimulateFlight(RouteTimeTableEntry entry) { FleetAirliner airliner = entry.Airliner; if (entry.TimeTable.Route.HasStopovers || airliner.CurrentFlight is StopoverFlight) { if (airliner.CurrentFlight == null || ((StopoverFlight)airliner.CurrentFlight).IsLastTrip) { airliner.CurrentFlight = new StopoverFlight(entry); } ((StopoverFlight)airliner.CurrentFlight).setNextEntry(); } else { airliner.CurrentFlight = new Flight(entry); } KeyValuePair <FleetAirlinerHelpers.DelayType, int> delayedMinutes = FleetAirlinerHelpers.GetDelayedMinutes(airliner); //cancelled/delay if (delayedMinutes.Value >= Convert.ToInt16(airliner.Airliner.Airline.getAirlinePolicy("Cancellation Minutes").PolicyValue)) { if (airliner.Airliner.Airline.IsHuman) { Flight flight = airliner.CurrentFlight; switch (delayedMinutes.Key) { case FleetAirlinerHelpers.DelayType.Airliner_problems: GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Flight_News, GameObject.GetInstance().GameTime, Translator.GetInstance().GetString("News", "1004"), string.Format(Translator.GetInstance().GetString("News", "1004", "message"), flight.Entry.Destination.FlightCode, flight.Entry.DepartureAirport.Profile.IATACode, flight.Entry.Destination.Airport.Profile.IATACode))); break; case FleetAirlinerHelpers.DelayType.Bad_weather: GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Flight_News, GameObject.GetInstance().GameTime, Translator.GetInstance().GetString("News", "1005"), string.Format(Translator.GetInstance().GetString("News", "1005", "message"), flight.Entry.Destination.FlightCode, flight.Entry.DepartureAirport.Profile.IATACode, flight.Entry.Destination.Airport.Profile.IATACode))); break; } } airliner.Airliner.Airline.Statistics.addStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Cancellations"), 1); double cancellationPercent = airliner.Airliner.Airline.Statistics.getStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Cancellations")) / (airliner.Airliner.Airline.Statistics.getStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Arrivals")) + airliner.Airliner.Airline.Statistics.getStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Cancellations"))); airliner.Airliner.Airline.Statistics.setStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Cancellation%"), cancellationPercent * 100); airliner.CurrentFlight = null; } else { airliner.CurrentFlight.addDelayMinutes(delayedMinutes.Value); if (airliner.CurrentFlight.Entry.MainEntry == null) { if (airliner.CurrentFlight.isPassengerFlight()) { var classes = new List <AirlinerClass>(airliner.Airliner.Classes); foreach (AirlinerClass aClass in classes) { airliner.CurrentFlight.Classes.Add(new FlightAirlinerClass(((PassengerRoute)airliner.CurrentFlight.Entry.TimeTable.Route).getRouteAirlinerClass(aClass.Type), PassengerHelpers.GetFlightPassengers(airliner, aClass.Type))); //airliner.CurrentFlight.Classes.Add(new FlightAirlinerClass(((PassengerRoute)airliner.CurrentFlight.Entry.TimeTable.Route).getRouteAirlinerClass(aClass.Type),0)); } } if (airliner.CurrentFlight.isCargoFlight()) { airliner.CurrentFlight.Cargo = PassengerHelpers.GetFlightCargo(airliner); } } //SetTakeoffStatistics(airliner); if (airliner.CurrentFlight.ExpectedLanding.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()) { SimulateLanding(airliner); } } }
//simulates the landing of a flight private static void SimulateLanding(FleetAirliner airliner) { DateTime landingTime = airliner.CurrentFlight.FlightTime.Add(MathHelpers.GetFlightTime(airliner.CurrentFlight.Entry.DepartureAirport.Profile.Coordinates.convertToGeoCoordinate(), airliner.CurrentFlight.Entry.Destination.Airport.Profile.Coordinates.convertToGeoCoordinate(), airliner.Airliner.Type)); double fdistance = MathHelpers.GetDistance(airliner.CurrentFlight.getDepartureAirport(), airliner.CurrentFlight.Entry.Destination.Airport); TimeSpan flighttime = landingTime.Subtract(airliner.CurrentFlight.FlightTime); double groundTaxPerPassenger = 5; double tax = 0; if (airliner.CurrentFlight.Entry.Destination.Airport.Profile.Country != airliner.CurrentFlight.getDepartureAirport().Profile.Country) { tax = 2 * tax; } double ticketsIncome = 0; double feesIncome = 0; double mealExpenses = 0; double fuelExpenses = 0; if (airliner.CurrentFlight.isPassengerFlight()) { tax = groundTaxPerPassenger * airliner.CurrentFlight.getTotalPassengers(); fuelExpenses = FleetAirlinerHelpers.GetFuelExpenses(airliner, fdistance); foreach (FlightAirlinerClass fac in airliner.CurrentFlight.Classes) { ticketsIncome += fac.Passengers * ((PassengerRoute)airliner.CurrentFlight.Entry.TimeTable.Route).getRouteAirlinerClass(fac.AirlinerClass.Type).FarePrice; } FeeType employeeDiscountType = FeeTypes.GetType("Employee Discount"); double employeesDiscount = airliner.Airliner.Airline.Fees.getValue(employeeDiscountType); double totalDiscount = ticketsIncome * (employeeDiscountType.Percentage / 100.0) * (employeesDiscount / 100.0); ticketsIncome = ticketsIncome - totalDiscount; foreach (FeeType feeType in FeeTypes.GetTypes(FeeType.eFeeType.Fee)) { if (GameObject.GetInstance().GameTime.Year >= feeType.FromYear) { foreach (FlightAirlinerClass fac in airliner.CurrentFlight.Classes) { double percent = 0.10; double maxValue = Convert.ToDouble(feeType.Percentage) * (1 + percent); double minValue = Convert.ToDouble(feeType.Percentage) * (1 - percent); double value = Convert.ToDouble(rnd.Next((int)minValue, (int)maxValue)) / 100; feesIncome += fac.Passengers * value * airliner.Airliner.Airline.Fees.getValue(feeType); } } } foreach (FlightAirlinerClass fac in airliner.CurrentFlight.Classes) { foreach (RouteFacility facility in ((PassengerRoute)airliner.CurrentFlight.Entry.TimeTable.Route).getRouteAirlinerClass(fac.AirlinerClass.Type).getFacilities()) { if (facility.EType == RouteFacility.ExpenseType.Fixed) { mealExpenses += fac.Passengers * facility.ExpensePerPassenger; } else { FeeType feeType = facility.FeeType; double percent = 0.10; double maxValue = Convert.ToDouble(feeType.Percentage) * (1 + percent); double minValue = Convert.ToDouble(feeType.Percentage) * (1 - percent); double value = Convert.ToDouble(rnd.Next((int)minValue, (int)maxValue)) / 100; mealExpenses -= fac.Passengers * value * airliner.Airliner.Airline.Fees.getValue(feeType); } } } } if (airliner.CurrentFlight.isCargoFlight()) { tax = groundTaxPerPassenger * airliner.CurrentFlight.Cargo; fuelExpenses = FleetAirlinerHelpers.GetFuelExpenses(airliner, fdistance); ticketsIncome = airliner.CurrentFlight.Cargo * airliner.CurrentFlight.getCargoPrice(); } Airport dest = airliner.CurrentFlight.Entry.Destination.Airport; Airport dept = airliner.CurrentFlight.Entry.DepartureAirport; double dist = MathHelpers.GetDistance(dest.Profile.Coordinates.convertToGeoCoordinate(), dept.Profile.Coordinates.convertToGeoCoordinate()); double expenses = fuelExpenses + dest.getLandingFee() + tax; if (double.IsNaN(expenses)) { expenses = 0; } if (double.IsNaN(ticketsIncome) || ticketsIncome < 0) { ticketsIncome = 0; } FleetAirlinerHelpers.SetFlightStats(airliner); long airportIncome = Convert.ToInt64(dest.getLandingFee()); dest.Income += airportIncome; Airline airline = airliner.Airliner.Airline; var agreements = airline.Codeshares.Where(c => c.Airline1 == airline || c.Type == CodeshareAgreement.CodeshareType.Both_Ways); foreach (CodeshareAgreement agreement in agreements) { var tAirline = agreement.Airline1 == airline ? agreement.Airline2 : agreement.Airline1; double agreementIncome = ticketsIncome * (CodeshareAgreement.TicketSalePercent / 100); AirlineHelpers.AddAirlineInvoice(tAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Tickets, agreementIncome); } AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Flight_Expenses, -expenses); AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Tickets, ticketsIncome); AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.OnFlight_Income, -mealExpenses); AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Fees, feesIncome); airliner.CurrentFlight.Entry.TimeTable.Route.addRouteInvoice(new Invoice(GameObject.GetInstance().GameTime, Invoice.InvoiceType.Flight_Expenses, -expenses)); airliner.CurrentFlight.Entry.TimeTable.Route.addRouteInvoice(new Invoice(GameObject.GetInstance().GameTime, Invoice.InvoiceType.Tickets, ticketsIncome)); airliner.CurrentFlight.Entry.TimeTable.Route.addRouteInvoice(new Invoice(GameObject.GetInstance().GameTime, Invoice.InvoiceType.OnFlight_Income, -mealExpenses)); airliner.CurrentFlight.Entry.TimeTable.Route.addRouteInvoice(new Invoice(GameObject.GetInstance().GameTime, Invoice.InvoiceType.Fees, feesIncome)); double wages = 0; if (airliner.CurrentFlight.isPassengerFlight()) { int cabinCrew = ((AirlinerPassengerType)airliner.Airliner.Type).CabinCrew; wages = cabinCrew * flighttime.TotalHours * airliner.Airliner.Airline.Fees.getValue(FeeTypes.GetType("Cabin Wage"));// +(airliner.CurrentFlight.Entry.TimeTable.Route.getTotalCabinCrew() * airliner.Airliner.Airline.Fees.getValue(FeeTypes.GetType("Cabin kilometer rate")) * fdistance) + (airliner.Airliner.Type.CockpitCrew * airliner.Airliner.Airline.Fees.getValue(FeeTypes.GetType("Cockpit kilometer rate")) * fdistance); //wages AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Wages, -wages); HolidayYearEvent holiday = HolidayYear.GetHoliday(airline.Profile.Country, GameObject.GetInstance().GameTime); if (holiday != null && (holiday.Holiday.Travel == Holiday.TravelType.Both || holiday.Holiday.Travel == Holiday.TravelType.Normal)) { wages = wages * 1.50; } airliner.CurrentFlight.Entry.TimeTable.Route.addRouteInvoice(new Invoice(GameObject.GetInstance().GameTime, Invoice.InvoiceType.Wages, -wages)); CreatePassengersHappiness(airliner); } airliner.Statistics.addStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Airliner_Income"), ticketsIncome - expenses - mealExpenses + feesIncome - wages); airliner.Airliner.Flown += fdistance; if (airliner.CurrentFlight.isPassengerFlight()) { foreach (Cooperation cooperation in airliner.CurrentFlight.Entry.Destination.Airport.Cooperations.Where(c => c.Airline == airline)) { double incomePerPax = MathHelpers.GetRandomDoubleNumber(cooperation.Type.IncomePerPax * 0.9, cooperation.Type.IncomePerPax * 1.1); double incomeFromCooperation = Convert.ToDouble(airliner.CurrentFlight.getTotalPassengers()) * incomePerPax; AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.OnFlight_Income, incomeFromCooperation); } } if (airliner.Airliner.Airline.IsHuman && Settings.GetInstance().MailsOnLandings) { GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Flight_News, GameObject.GetInstance().GameTime, string.Format("{0} landed", airliner.Name), string.Format("Your airliner [LI airliner={0}] has landed in [LI airport={1}], {2} with {3} passengers.\nThe airliner flow from [LI airport={4}], {5}", new object[] { airliner.Airliner.TailNumber, dest.Profile.IATACode, dest.Profile.Country.Name, airliner.CurrentFlight.getTotalPassengers(), dept.Profile.IATACode, dept.Profile.Country.Name }))); } if (airliner.CurrentFlight is StopoverFlight && !((StopoverFlight)airliner.CurrentFlight).IsLastTrip) { SimulateFlight(airliner.CurrentFlight.Entry); } else { airliner.CurrentFlight = null; } }