Exemplo n.º 1
0
 public AirlinerClassConfiguration(AirlinerClass.ClassType type, int seating, int regularseating)
 {
     this.SeatingCapacity = seating;
     this.RegularSeatingCapacity = regularseating;
     this.Type = type;
     this.Facilities = new List<AirlinerFacility>();
 }
Exemplo n.º 2
0
        public AirlinerClassMVVM(AirlinerClass type, int seating, int regularSeating, int maxseats,  Boolean changeableSeats = false)
        {
            this.Type = type.Type;
            this.Seating = seating;
            this.RegularSeatingCapacity = regularSeating;
            this.ChangeableSeats = changeableSeats;
            this.MaxSeats = maxseats;
            this.MaxSeatsCapacity = maxseats;
            this.ChangedFacility = false;

            this.Facilities = new ObservableCollection<AirlinerFacilityMVVM>();

            foreach (AirlinerFacility.FacilityType facType in Enum.GetValues(typeof(AirlinerFacility.FacilityType)))
            {
                AirlinerFacilityMVVM facility = new AirlinerFacilityMVVM(facType,this);

                foreach (AirlinerFacility fac in AirlinerFacilities.GetFacilities(facType))
                    facility.Facilities.Add(fac);

                AirlinerFacility selectedFacility = type.getFacility(facType) == null ? AirlinerFacilities.GetBasicFacility(facType) : type.getFacility(facType);
                facility.SelectedFacility = selectedFacility;

               this.Facilities.Add(facility);

            }
        }
Exemplo n.º 3
0
        public Airliner(string id, AirlinerType type, string tailNumber, DateTime builtDate)
        {
            this.ID               = id;
            this.BuiltDate        = new DateTime(builtDate.Year, builtDate.Month, builtDate.Day);
            this.Type             = type;
            this.LastServiceCheck = 0;
            this.TailNumber       = tailNumber;
            this.Flown            = 0;
            this.Condition        = rnd.Next(90, 100);
            this.Classes          = new List <AirlinerClass>();

            if (this.Type.TypeAirliner == AirlinerType.TypeOfAirliner.Passenger)
            {
                AirlinerClass aClass = new AirlinerClass(AirlinerClass.ClassType.Economy_Class, ((AirlinerPassengerType)this.Type).MaxSeatingCapacity);
                aClass.createBasicFacilities(this.Airline);
                this.Classes.Add(aClass);
            }

            if (this.Type.TypeAirliner == AirlinerType.TypeOfAirliner.Cargo)
            {
                AirlinerClass aClass = new AirlinerClass(AirlinerClass.ClassType.Economy_Class, 0);
                aClass.createBasicFacilities(this.Airline);
                this.Classes.Add(aClass);
            }
        }
        public static object ShowPopUp(AirlinerClass aClass)
        {
            PopUpWindow window = new PopUpAirlinerClassConfiguration(aClass);
            window.ShowDialog();

            return window.Selected;
        }
Exemplo n.º 5
0
        public Airliner(string id, AirlinerType type, string tailNumber, DateTime builtDate)
        {
            this.ID = id;
            this.BuiltDate = new DateTime(builtDate.Year, builtDate.Month, builtDate.Day);
            this.Type = type;
            this.LastServiceCheck = 0;
            this.TailNumber = tailNumber;
            this.Flown = 0;
            this.Condition = rnd.Next(90, 100);
            this.Classes = new List<AirlinerClass>();

            if (this.Type.TypeAirliner == AirlinerType.TypeOfAirliner.Passenger)
            {
                AirlinerClass aClass = new AirlinerClass(AirlinerClass.ClassType.Economy_Class, ((AirlinerPassengerType)this.Type).MaxSeatingCapacity);
                aClass.createBasicFacilities(this.Airline);
                this.Classes.Add(aClass);
            }

            if (this.Type.TypeAirliner == AirlinerType.TypeOfAirliner.Cargo)
            {
                AirlinerClass aClass = new AirlinerClass(AirlinerClass.ClassType.Economy_Class, 0);
                aClass.createBasicFacilities(this.Airline);
                this.Classes.Add(aClass);

            }
        }
        public PopUpAirlinerFacility(AirlinerClass airlinerClass, AirlinerFacility.FacilityType type)
        {
            InitializeComponent();

            this.AirlinerClass = airlinerClass;
            this.Type = type;

            this.Title = "Select " + type.ToString().ToLower();

            this.Width = 400;

            this.Height = 120;

            this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;

            StackPanel mainPanel = new StackPanel();
            mainPanel.Margin = new Thickness(10, 10, 10, 10);

            cbFacility = new ComboBox();
            cbFacility.ItemTemplate = this.Resources["AirlinerFacilityItem"] as DataTemplate;
            cbFacility.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle");

            foreach (AirlinerFacility facility in AirlinerFacilities.GetFacilities(this.Type,GameObject.GetInstance().GameTime.Year))
                cbFacility.Items.Add(facility);

            cbFacility.SelectedItem = this.AirlinerClass.getFacility(this.Type);

            mainPanel.Children.Add(cbFacility);

            mainPanel.Children.Add(createButtonsPanel());

            this.Content = mainPanel;
               // int serviceLevel, double percentOfSeats, double pricePerSeat
        }
        public static object ShowPopUp(AirlinerClass airlinerClass, AirlinerFacility.FacilityType type)
        {
            PopUpWindow window = new PopUpAirlinerFacility(airlinerClass, type);

            window.ShowDialog();

            return window.Selected == null ? null : window.Selected;
        }
Exemplo n.º 8
0
        //adds a new airliner class to the airliner
        public void addAirlinerClass(AirlinerClass airlinerClass)
        {
            this.Classes.Add(airlinerClass);

            if (airlinerClass.getFacilities().Count == 0)
            {
                airlinerClass.createBasicFacilities(this.Airline);
            }
        }
Exemplo n.º 9
0
        //adds a new airliner class to the airliner
        public void addAirlinerClass(AirlinerClass airlinerClass)
        {
            if (airlinerClass != null && !this.Classes.Exists(c => c.Type == airlinerClass.Type))
            {
                this.Classes.Add(airlinerClass);

                if (airlinerClass.getFacilities().Count == 0)
                {
                    airlinerClass.createBasicFacilities(this.Airline);
                }
            }
        }
Exemplo n.º 10
0
        //returns the code for an airliner class
        public static string GetAirlinerClassCode(AirlinerClass aClass)
        {
            string symbol = "Y";

            if (aClass.Type == AirlinerClass.ClassType.Business_Class)
                symbol = "C";

            if (aClass.Type == AirlinerClass.ClassType.First_Class)
                symbol = "F";

            if (aClass.Type == AirlinerClass.ClassType.Economy_Class)
                symbol = "Y";

            return string.Format("{0}{1}", aClass.SeatingCapacity, symbol);
        }
        public PopUpAirlinerClassConfiguration(AirlinerClass aClass)
        {
            InitializeComponent();

            this.AirlinerClass = aClass;

            this.Title = new TextUnderscoreConverter().Convert(aClass.Type.ToString()).ToString();

            this.Width = 400;

            this.Height = 200;

            this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;

            StackPanel panelClassFacilities = new StackPanel();

            TextBlock txtHeader = new TextBlock();
            txtHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            txtHeader.SetResourceReference(TextBlock.BackgroundProperty, "HeaderBackgroundBrush");
            txtHeader.FontWeight = FontWeights.Bold;
            txtHeader.Text = string.Format("{0}", new TextUnderscoreConverter().Convert(aClass.Type, null, null, null));

            panelClassFacilities.Children.Add(txtHeader);

            lbFacilities = new ListBox[Enum.GetValues(typeof(AirlinerFacility.FacilityType)).Length];

            int i = 0;
            foreach (AirlinerFacility.FacilityType type in Enum.GetValues(typeof(AirlinerFacility.FacilityType)))
            {
                AirlinerFacility facility = aClass.getFacility(type);

                lbFacilities[i] = new ListBox();
                lbFacilities[i].ItemContainerStyleSelector = new ListBoxItemStyleSelector();
                lbFacilities[i].ItemTemplate = this.Resources["FleetFacilityItem"] as DataTemplate;

                panelClassFacilities.Children.Add(lbFacilities[i]);

                i++;

            }
            panelClassFacilities.Children.Add(createButtonsPanel());

            this.Content = panelClassFacilities;

            showFacilities();
        }
        public AirlinerOrderMVVM(AirlinerType type, int amount = 1)
        {
            this.Type = type;
            this.Amount = amount;
            this.Classes = new List<AirlinerClass>();
            this.Homebases = new List<Airport>();

            if (this.Type.TypeAirliner == AirlinerType.TypeOfAirliner.Passenger)
            {
                AirlinerClass eClass = new AirlinerClass(AirlinerClass.ClassType.Economy_Class, ((AirlinerPassengerType)type).MaxSeatingCapacity);
                eClass.createBasicFacilities(null);
                this.Classes.Add(eClass);
            }

            long minRequiredRunway = this.Type.MinRunwaylength;

            foreach (var homebase in GameObject.GetInstance().HumanAirline.Airports.FindAll(a => a.getCurrentAirportFacility(GameObject.GetInstance().HumanAirline, AirportFacility.FacilityType.Service).TypeLevel > 0 && a.getMaxRunwayLength() >= minRequiredRunway))
                this.Homebases.Add(homebase);
        }
        public AirlinerClassMVVM(AirlinerClass.ClassType type, int seating, int regularSeating, int maxseats, Boolean changeableSeats = false)
        {
            this.Type = type;
            this.Seating = seating;
            this.RegularSeatingCapacity = regularSeating;
            this.ChangeableSeats = changeableSeats;
            this.MaxSeats = maxseats;
            this.MaxSeatsCapacity = maxseats;

            this.Facilities = new List<AirlinerFacilityMVVM>();

            foreach (AirlinerFacility.FacilityType facType in Enum.GetValues(typeof(AirlinerFacility.FacilityType)))
            {
                AirlinerFacilityMVVM facility = new AirlinerFacilityMVVM(facType,this);

                foreach (AirlinerFacility fac in AirlinerFacilities.GetFacilities(facType))
                    facility.Facilities.Add(fac);

                this.Facilities.Add(facility);

            }
        }
Exemplo n.º 14
0
        //returns the number of passengers for a flight
        public static int GetFlightPassengers(FleetAirliner airliner, AirlinerClass.ClassType type)
        {
            Airport airportCurrent = airliner.CurrentFlight.getDepartureAirport();
            Airport airportDestination = airliner.CurrentFlight.Entry.Destination.Airport;

            return GetFlightPassengers(airportCurrent, airportDestination, airliner, type);
        }
Exemplo n.º 15
0
        //orders a number of airliners for an airline
        public static void OrderAirliners(Airline airline, List<AirlinerOrder> orders, Airport airport, DateTime deliveryDate, double discount)
        {
            Guid id = Guid.NewGuid();

            foreach (AirlinerOrder order in orders)
            {
                for (int i = 0; i < order.Amount; i++)
                {
                    Airliner airliner = new Airliner(id.ToString(), order.Type, airline.Profile.Country.TailNumbers.getNextTailNumber(), deliveryDate);
                    Airliners.AddAirliner(airliner);

                    FleetAirliner.PurchasedType pType = FleetAirliner.PurchasedType.Bought;
                    airline.addAirliner(pType, airliner, airport);

                    airliner.clearAirlinerClasses();

                    foreach (AirlinerClass aClass in order.Classes)
                    {
                        AirlinerClass tClass = new AirlinerClass(aClass.Type, aClass.SeatingCapacity);
                        tClass.RegularSeatingCapacity = aClass.RegularSeatingCapacity;

                        foreach (AirlinerFacility facility in aClass.getFacilities())
                            tClass.setFacility(airline, facility);

                        airliner.addAirlinerClass(tClass);
                    }


                }



            }

            int totalAmount = orders.Sum(o => o.Amount);
            double price = orders.Sum(o => o.Type.Price * o.Amount);

            double totalPrice = price * ((1 - GeneralHelpers.GetAirlinerOrderDiscount(totalAmount))) * ((100 - discount) / 100);

            AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -totalPrice);
        }
Exemplo n.º 16
0
        //public int CabinCrew { get; set; }
        public MVVMRouteClass(AirlinerClass.ClassType type, RouteAirlinerClass.SeatingType seating, double fareprice)
        {
            this.Type = type;
            this.Seating = seating;
            this.FarePrice = 10;

            this.Facilities = new List<MVVMRouteFacility>();

            foreach (RouteFacility.FacilityType facType in Enum.GetValues(typeof(RouteFacility.FacilityType)))
            {
                if (GameObject.GetInstance().GameTime.Year >= (int)facType)
                {

                    MVVMRouteFacility facility = new MVVMRouteFacility(facType);

                    foreach (RouteFacility fac in RouteFacilities.GetFacilities(facType))
                        facility.Facilities.Add(fac);

                    this.Facilities.Add(facility);
                }
            }
        }
        private void btnSaveChanges_Click(object sender, RoutedEventArgs e)
        {
            this.Airliner.Airliner.Airliner.clearAirlinerClasses();

            foreach (AirlinerClassMVVM aClass in this.Airliner.Classes)
            {
                AirlinerClass nClass = new AirlinerClass(aClass.Type, aClass.RegularSeatingCapacity);
                nClass.SeatingCapacity = aClass.Seating;

                foreach (AirlinerFacilityMVVM aFacility in aClass.Facilities)
                {

                    nClass.forceSetFacility(aFacility.SelectedFacility);

                }

                this.Airliner.Airliner.Airliner.addAirlinerClass(nClass);
            }
        }
Exemplo n.º 18
0
        public AirlinerOrderMVVM(AirlinerType type, AirlinerOrdersMVVM order, int amount = 1)
        {
            this.Type = type;
            this.Order = order;
            this.Amount = amount;
            this._classes = new List<AirlinerClass>();
            this.Homebases = new List<Airport>();

            if (this.Type.TypeAirliner == AirlinerType.TypeOfAirliner.Passenger)
            {
                AirlinerClass eClass = new AirlinerClass(AirlinerClass.ClassType.Economy_Class, ((AirlinerPassengerType)type).MaxSeatingCapacity);
                eClass.createBasicFacilities(null);
                this.Classes.Add(eClass);
            }

            long minRunway = this.Type.MinRunwaylength;

            //var homebases = GameObject.GetInstance().HumanAirline.Airports.FindAll(a => (a.hasContractType(GameObject.GetInstance().HumanAirline, AirportContract.ContractType.Full_Service) || a.getCurrentAirportFacility(GameObject.GetInstance().HumanAirline, AirportFacility.FacilityType.Service).TypeLevel > 0) && a.getMaxRunwayLength() >= minRunway);

            var homebases = AirlineHelpers.GetHomebases(GameObject.GetInstance().HumanAirline, minRunway);

            foreach (var homebase in homebases)
                this.Homebases.Add(homebase);
        }
 public AirlinerClassItem(AirlinerClass aClass, Boolean canDelete)
 {
     this.AirlinerClass = aClass;
     this.CanDelete = canDelete;
 }
        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            int seating = (int)((Button)sender).Tag;

              AirlinerClass aClass = new AirlinerClass(this.CurrentClass, seating);

            aClass.forceSetFacility(this.Classes[0].getFacility(AirlinerFacility.FacilityType.Audio));
            aClass.forceSetFacility(this.Classes[0].getFacility(AirlinerFacility.FacilityType.Seat));
            aClass.forceSetFacility(this.Classes[0].getFacility(AirlinerFacility.FacilityType.Video));

            this.Classes.Add(aClass);

            // chs, 2011-11-10 added so seat capacity is correctly calculated
            this.Classes[0].SeatingCapacity -= aClass.SeatingCapacity;
            this.Classes[0].RegularSeatingCapacity -= aClass.SeatingCapacity;

            showAirlinerClasses();
        }
Exemplo n.º 21
0
        //returns the passenger demand from nearby airport with no routes for a destination
        private static double GetNearbyPassengerDemand(Airport airportCurrent, Airport airportDestination, FleetAirliner airliner, AirlinerClass.ClassType type)
        {
            TimeSpan flightTime = MathHelpers.GetFlightTime(airportCurrent, airportDestination, airliner.Airliner.Type);

            double maxDistance = (flightTime.TotalHours * 0.5) * 100;

            var nearbyAirports = AirportHelpers.GetAirportsNearAirport(airportCurrent, maxDistance).DefaultIfEmpty().Where(a => !AirportHelpers.HasRoute(a, airportDestination));

            double demand = 0;

            foreach (Airport airport in nearbyAirports)
            {
                if (airport != null)
                {
                    double distance = MathHelpers.GetDistance(airportCurrent, airport);

                    double airportDemand = (double)airport.getDestinationPassengersRate(airportDestination, type);

                    if (distance < 150)
                        demand += airportDemand * 0.75;

                    if (distance >= 150 && distance < 225)
                        demand += airportDemand * 0.5;

                    if (distance >= 225 && distance < 300)
                        demand += airportDemand * 0.25;

                    if (distance >= 300 && distance < 400)
                        demand += airportDemand * 0.10;
                }
            }

            return demand;
        }
Exemplo n.º 22
0
 //removes an airliner class from the airliner
 public void removeAirlinerClass(AirlinerClass airlinerClass)
 {
     this.Classes.Remove(airlinerClass);
 }
Exemplo n.º 23
0
        //orders the airliners
        private void orderAirliners(double discount = 0)
        {
            DateTime deliveryDate = this.Orders.getDeliveryDate();

            Guid id = Guid.NewGuid();

            foreach (AirlinerOrderMVVM order in this.Orders.Orders)
            {
                for (int i = 0; i < order.Amount; i++)
                {
                    Airliner airliner = new Airliner(id.ToString(), order.Type, GameObject.GetInstance().HumanAirline.Profile.Country.TailNumbers.getNextTailNumber(), deliveryDate);
                    Model.AirlinerModel.Airliners.AddAirliner(airliner);

                    FleetAirliner.PurchasedType pType = FleetAirliner.PurchasedType.Bought;
                    GameObject.GetInstance().HumanAirline.addAirliner(pType, airliner, order.Homebase);

                    airliner.clearAirlinerClasses();

                    foreach (AirlinerClass aClass in order.Classes)
                    {
                        AirlinerClass tClass = new AirlinerClass(aClass.Type, aClass.SeatingCapacity);
                        tClass.RegularSeatingCapacity = aClass.RegularSeatingCapacity;

                        foreach (AirlinerFacility facility in aClass.getFacilities())
                            tClass.setFacility(GameObject.GetInstance().HumanAirline, facility);

                        airliner.addAirlinerClass(tClass);
                    }

                }

            }

            int totalAmount = this.Orders.Orders.Sum(o => o.Amount);
            double price = this.Orders.Orders.Sum(o => o.Type.Price * o.Amount);

            double totalPrice = price * ((1 - GeneralHelpers.GetAirlinerOrderDiscount(totalAmount))) * ((100 - discount) / 100);

            AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -totalPrice);
        }
Exemplo n.º 24
0
        //returns the destination passengers for a specific destination for a class
        public ushort getDestinationPassengersRate(Airport destination, AirlinerClass.ClassType type)
        {
            DestinationDemand pax = this.DestinationPassengers.Find(a => a.Destination == destination.Profile.IATACode);

            var values = Enum.GetValues(typeof(AirlinerClass.ClassType));

            int classFactor = 0;

            int i = 1;

            foreach (AirlinerClass.ClassType value in values)
            {
                if (value == type)
                    classFactor = i;
                i++;
            }

            if (pax == null)
                return this.Statics.getDestinationPassengersRate(destination, type);
            else
            {
                return (ushort)(this.Statics.getDestinationPassengersRate(destination, type) + (ushort)(pax.Rate / classFactor));
            }
        }
        private void link_Click(object sender, RoutedEventArgs e)
        {
            AirlinerType type = this.AirlinersToMaintain[0].Airliner.Type;
            if (this.Classes == null)
            {
                AirlinerClass eClass = new AirlinerClass(AirlinerClass.ClassType.Economy_Class, ((AirlinerPassengerType)type).MaxSeatingCapacity);
                eClass.createBasicFacilities(null);
                this.Classes.Add(eClass);
            }

            AirlinerClass aClass = (AirlinerClass)((Hyperlink)sender).Tag;

            AirlinerClass newClass = (AirlinerClass)PopUpAirlinerClassConfiguration.ShowPopUp(aClass);

            AirlinerClass economyClass = this.Classes.Find(c => c.Type == AirlinerClass.ClassType.Economy_Class);
            if (newClass != null)
            {
                AirlinerClass airlinerClass = new AirlinerClass(newClass.Type, newClass.SeatingCapacity);
                airlinerClass.RegularSeatingCapacity = newClass.RegularSeatingCapacity;

                int seatingDiff = ((AirlinerPassengerType)type).MaxSeatingCapacity;

                economyClass.RegularSeatingCapacity += seatingDiff;

                AirlinerFacility seatingFacility = economyClass.getFacility(AirlinerFacility.FacilityType.Seat);

                int extraSeats = (int)(seatingDiff / seatingFacility.SeatUses);

                economyClass.SeatingCapacity += extraSeats;

            }
        }
        private void cbAirliner_Checked(object sender, RoutedEventArgs e)
        {
            int maxNumberOfAirliners = this.AirlineFacility.ServiceLevel;

            FleetAirliner airliner = (FleetAirliner)((CheckBox)sender).Tag;

            if (this.AirlinersToMaintain.Count == 0 || (this.AirlinersToMaintain.Exists(a => a.Airliner.Type == airliner.Airliner.Type) && this.AirlinersToMaintain.Count + 1 <= maxNumberOfAirliners))
            {
                this.AirlinersToMaintain.Add(airliner);

                AirlinerType type = this.AirlinersToMaintain[0].Airliner.Type;
                if (this.Classes == null || this.Classes.Count == 0)
                {
                    AirlinerClass eClass = new AirlinerClass(AirlinerClass.ClassType.Economy_Class, ((AirlinerPassengerType)type).MaxSeatingCapacity);
                    eClass.createBasicFacilities(null);
                    this.Classes.Add(eClass);

                    showClasses();
                }

                btnEquipped.IsEnabled = true;
                btnApply.IsEnabled = true;
            }
            else
            {
                if (this.AirlinersToMaintain.Count == maxNumberOfAirliners)
                    WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2901"), string.Format(Translator.GetInstance().GetString("MessageBox", "2901","message"), maxNumberOfAirliners), WPFMessageBoxButtons.Ok);

                ((CheckBox)sender).IsChecked = false;
            }
        }
        //creates a hyperlink for an airliner class
        private TextBlock createAirlineClassLink(AirlinerClass aClass)
        {
            TextBlock txtLink = new TextBlock();
            txtLink.Margin = new Thickness(0, 0, 20, 0);

            Hyperlink link = new Hyperlink();
            link.Tag = aClass;
            link.Click += link_Click;
            link.Inlines.Add(new TextUnderscoreConverter().Convert(aClass.Type).ToString());
            txtLink.Inlines.Add(link);

            return txtLink;
        }
Exemplo n.º 28
0
 public static double GetPassengerPrice(Airport dest1, Airport dest2, AirlinerClass.ClassType type)
 {
     return GetPassengerPrice(dest1, dest2) * GeneralHelpers.ClassToPriceFactor(type);
 }
        private void btnApply_Click(object sender, RoutedEventArgs e)
        {
            int serviceDays = 3;
            WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2902"), string.Format(Translator.GetInstance().GetString("MessageBox", "2902","message"), serviceDays), WPFMessageBoxButtons.YesNo);

            if (result == WPFMessageBoxResult.Yes)
            {
                foreach (FleetAirliner airliner in this.AirlinersToMaintain)
                {
                    serviceDays = airliner.Airliner.Classes.Count == this.Classes.Count ? 1 : 3;

                    airliner.Airliner.clearAirlinerClasses();

                    foreach (AirlinerClass aClass in this.Classes)
                    {
                        AirlinerClass tClass = new AirlinerClass(aClass.Type, aClass.SeatingCapacity);
                        tClass.RegularSeatingCapacity = aClass.RegularSeatingCapacity;

                        foreach (AirlinerFacility facility in aClass.getFacilities())
                            tClass.setFacility(GameObject.GetInstance().HumanAirline, facility);

                        airliner.Airliner.addAirlinerClass(tClass);
                    }
                    airliner.GroundedToDate = GameObject.GetInstance().GameTime.AddDays(serviceDays);
                }
            }
        }
Exemplo n.º 30
0
        //returns the number of passengers between two airports on a stopover route
        public static int GetStopoverFlightPassengers(FleetAirliner airliner, AirlinerClass.ClassType type, Airport dept, Airport dest, List<Route> routes, Boolean isInbound)
        {
            Route currentRoute = routes.Find(r => (r.Destination1 == dept && r.Destination2 == dest) || (r.Destination2 == dept && r.Destination1 == dest));
            int index = routes.IndexOf(currentRoute);

            int passengers = 0;
            for (int i = 0; i <= index; i++)
            {
                if (isInbound)
                {
                    passengers += GetFlightPassengers(routes[i].Destination2, dest, airliner, type);
                }
                else
                {
                    passengers += GetFlightPassengers(routes[i].Destination1, dest, airliner, type);
                }
            }

            if (passengers < 0)
                passengers = 0;

            return (int)Math.Min(airliner.Airliner.getAirlinerClass(type).SeatingCapacity, passengers);
        }
Exemplo n.º 31
0
        private void btnOrder_Click(object sender, RoutedEventArgs e)
        {
            Boolean hasHomebases = true;
            foreach (AirlinerOrderMVVM order in this.Orders.Orders)
            {
                if (order.Homebase == null)
                    hasHomebases = false;
            }
            Boolean contractedOrder = false;
            Boolean tryOrder = true;

            DateTime deliveryDate = this.Orders.getDeliveryDate();

            if (!hasHomebases)
            {
                WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2002"), Translator.GetInstance().GetString("MessageBox", "2002", "message"), WPFMessageBoxButtons.Ok);
            }
            else
            {
                if (GameObject.GetInstance().HumanAirline.Contract != null)
                {
                    if (GameObject.GetInstance().HumanAirline.Contract.Manufacturer == this.Manufacturer)
                        contractedOrder = true;
                    else
                    {
                        double terminationFee = GameObject.GetInstance().HumanAirline.Contract.getTerminationFee();
                        WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2010"), string.Format(Translator.GetInstance().GetString("MessageBox", "2010", "message"), GameObject.GetInstance().HumanAirline.Contract.Manufacturer.Name, terminationFee), WPFMessageBoxButtons.YesNo);

                        if (result == WPFMessageBoxResult.Yes)
                        {
                            AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -terminationFee);
                            GameObject.GetInstance().HumanAirline.Contract = null;

                            this.Contract.Contracted = null;

                        }
                        tryOrder = result == WPFMessageBoxResult.Yes;
                    }
                }

                if (tryOrder)
                {
                    int totalAmount = this.Orders.Orders.Sum(o => o.Amount);
                    double price = this.Orders.Orders.Sum(o => o.Type.Price * o.Amount);

                    double totalPrice = price * ((1 - GeneralHelpers.GetAirlinerOrderDiscount(totalAmount)));

                    if (contractedOrder)
                        totalPrice = totalPrice * ((100 - GameObject.GetInstance().HumanAirline.Contract.Discount) / 100);

                    double downpaymentPrice = 0;

                    downpaymentPrice = totalPrice * (GameObject.GetInstance().Difficulty.PriceLevel / 10);

                    if (cbDownPayment.IsChecked.Value)
                    {

                        if (downpaymentPrice > GameObject.GetInstance().HumanAirline.Money)
                        {
                            WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2001"), Translator.GetInstance().GetString("MessageBox", "2001", "message"), WPFMessageBoxButtons.Ok);
                        }
                        else
                        {
                            WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2009"), string.Format(Translator.GetInstance().GetString("MessageBox", "2009", "message"), totalPrice, downpaymentPrice), WPFMessageBoxButtons.YesNo);

                            if (result == WPFMessageBoxResult.Yes)
                            {
                                foreach (AirlinerOrderMVVM order in this.Orders.Orders)
                                {
                                    for (int i = 0; i < order.Amount; i++)
                                    {
                                        Guid id = Guid.NewGuid();

                                        Airliner airliner = new Airliner(id.ToString(), order.Type, GameObject.GetInstance().HumanAirline.Profile.Country.TailNumbers.getNextTailNumber(), deliveryDate);

                                        airliner.clearAirlinerClasses();

                                        foreach (AirlinerClass aClass in order.Classes)
                                        {
                                            AirlinerClass tClass = new AirlinerClass(aClass.Type, aClass.SeatingCapacity);
                                            tClass.RegularSeatingCapacity = aClass.RegularSeatingCapacity;

                                            foreach (AirlinerFacility facility in aClass.getFacilities())
                                                tClass.setFacility(GameObject.GetInstance().HumanAirline, facility);

                                            airliner.addAirlinerClass(tClass);
                                        }

                                        Model.AirlinerModel.Airliners.AddAirliner(airliner);

                                        FleetAirliner.PurchasedType pType = FleetAirliner.PurchasedType.BoughtDownPayment;
                                        GameObject.GetInstance().HumanAirline.addAirliner(pType, airliner, order.Homebase);

                                    }

                                }
                                if (contractedOrder)
                                    GameObject.GetInstance().HumanAirline.Contract.PurchasedAirliners += this.Orders.Orders.Sum(o => o.Amount);
                                AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -downpaymentPrice);

                                TabControl tab_main = UIHelpers.FindChild<TabControl>(this.Tag as Page, "tabMenu");

                                if (tab_main != null)
                                {
                                    var matchingItem =
                         tab_main.Items.Cast<TabItem>()
                           .Where(item => item.Tag.ToString() == "Order")
                           .FirstOrDefault();

                                    tab_main.SelectedItem = matchingItem;
                                }
                            }
                        }
                    }
                    else
                    {

                        if (totalPrice > GameObject.GetInstance().HumanAirline.Money)
                        {
                            WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2001"), Translator.GetInstance().GetString("MessageBox", "2001", "message"), WPFMessageBoxButtons.Ok);
                        }
                        else
                        {
                            if (this.Orders.Orders.Sum(o => o.Amount) > 0)
                            {
                                WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2008"), string.Format(Translator.GetInstance().GetString("MessageBox", "2008", "message"), totalPrice), WPFMessageBoxButtons.YesNo);

                                if (result == WPFMessageBoxResult.Yes)
                                {
                                    orderAirliners(contractedOrder ? GameObject.GetInstance().HumanAirline.Contract.Discount : 0);

                                    TabControl tab_main = UIHelpers.FindChild<TabControl>(this.Tag as Page, "tabMenu");

                                    if (tab_main != null)
                                    {
                                        var matchingItem =
                             tab_main.Items.Cast<TabItem>()
                               .Where(item => item.Tag.ToString() == "Order")
                               .FirstOrDefault();

                                        tab_main.SelectedItem = matchingItem;
                                    }
                                }

                                if (contractedOrder)
                                    GameObject.GetInstance().HumanAirline.Contract.PurchasedAirliners += this.Orders.Orders.Sum(o => o.Amount);

                            }
                        }
                    }
                }

            }
        }
Exemplo n.º 32
0
        //returns the number of passengers for a flight on a stopover route
        public static int GetStopoverFlightPassengers(FleetAirliner airliner, AirlinerClass.ClassType type)
        {
            RouteTimeTableEntry mainEntry = airliner.CurrentFlight.Entry.MainEntry;
            RouteTimeTableEntry entry = airliner.CurrentFlight.Entry;

            List<Route> legs = mainEntry.TimeTable.Route.Stopovers.SelectMany(s => s.Legs).ToList();

            Boolean isInbound = mainEntry.DepartureAirport == mainEntry.TimeTable.Route.Destination2;

            int passengers;
            //inboound
            if (isInbound)
            {
                legs.Reverse();
                passengers = GetFlightPassengers(mainEntry.TimeTable.Route.Destination2, mainEntry.TimeTable.Route.Destination1, airliner, type);
            }
            else
                passengers = GetFlightPassengers(mainEntry.TimeTable.Route.Destination1, mainEntry.TimeTable.Route.Destination2, airliner, type);

            int index = legs.IndexOf(entry.TimeTable.Route);

            for (int i = index; i < legs.Count; i++)
            {
                if (isInbound)
                    passengers += GetFlightPassengers(entry.TimeTable.Route.Destination1, legs[i].Destination1, airliner, type);
                else
                    passengers += GetFlightPassengers(entry.TimeTable.Route.Destination1, legs[i].Destination2, airliner, type);
            }

            if (passengers < 0)
                passengers = 0;

            return (int)Math.Min(airliner.Airliner.getAirlinerClass(type).SeatingCapacity, passengers);
        }
Exemplo n.º 33
0
 //returns the passengers for an airliner
 public static int GetPassengers(FleetAirliner airliner, AirlinerClass.ClassType type)
 {
     return PassengerHelpers.GetFlightPassengers(airliner, type);
 }
Exemplo n.º 34
0
        //returns the passenger demand for routes with airportdestination as connection point
        private static double GetFlightConnectionPassengers(Airport airportCurrent, Airport airportDestination, FleetAirliner airliner, AirlinerClass.ClassType type)
        {
            double legDistance = MathHelpers.GetDistance(airportCurrent, airportDestination);

            double demandOrigin = 0;
            double demandDestination = 0;

            var routesFromDestination = airliner.Airliner.Airline.Routes.FindAll(r => ((r.Destination2 == airportDestination || r.Destination1 == airportDestination) && (r.Destination1 != airportCurrent && r.Destination2 != airportCurrent)));
            var routesToOrigin = airliner.Airliner.Airline.Routes.FindAll(r => ((r.Destination1 == airportCurrent || r.Destination2 == airportCurrent) && (r.Destination2 != airportDestination && r.Destination1 != airportDestination)));

            foreach (PassengerRoute route in routesFromDestination)
            {
                Airport tDest = route.Destination1 == airportDestination ? route.Destination2 : route.Destination1;

                double totalDistance = airportCurrent.Profile.Coordinates.convertToGeoCoordinate().GetDistanceTo(tDest.Profile.Coordinates.convertToGeoCoordinate()) / 1000;

                int directRoutes = AirportHelpers.GetNumberOfAirportsRoutes(airportCurrent, tDest);

                if (route.getDistance() + legDistance < totalDistance * 3 && directRoutes < 2)
                {
                    double demand = (double)airportCurrent.getDestinationPassengersRate(tDest, type);
                    demandDestination += (demand * 0.25);
                }
            }

            foreach (PassengerRoute route in routesToOrigin)
            {
                Airport tDest = route.Destination1 == airportCurrent ? route.Destination2 : route.Destination1;

                double totalDistance = tDest.Profile.Coordinates.convertToGeoCoordinate().GetDistanceTo(airportDestination.Profile.Coordinates.convertToGeoCoordinate()) / 1000;

                int directRoutes = AirportHelpers.GetNumberOfAirportsRoutes(tDest, airportDestination);

                if (route.getDistance() + legDistance < totalDistance * 3 && directRoutes < 2)
                {
                    double demand = (double)tDest.getDestinationPassengersRate(airportDestination, type);
                    demandOrigin += (demand * 0.25);
                }
            }
            //alliances & codesharings
            if (airliner.Airliner.Airline.Alliances.Count > 0 || airliner.Airliner.Airline.Codeshares.Count > 0)
            {
                var allianceRoutesFromDestination = airliner.Airliner.Airline.Alliances.SelectMany(a => a.Members.Where(m => m.Airline != airliner.Airliner.Airline).SelectMany(m => m.Airline.Routes.FindAll(r => ((r.Destination2 == airportDestination || r.Destination1 == airportDestination) && (r.Destination1 != airportCurrent && r.Destination2 != airportCurrent)))));
                var allianceRoutesToOrigin = airliner.Airliner.Airline.Alliances.SelectMany(a => a.Members.Where(m => m.Airline != airliner.Airliner.Airline).SelectMany(m => m.Airline.Routes.FindAll(r => ((r.Destination1 == airportCurrent || r.Destination2 == airportCurrent) && (r.Destination2 != airportDestination && r.Destination1 != airportDestination)))));

                var codeshares = airliner.Airliner.Airline.Codeshares.Where(a => (a.Airline2 == airliner.Airliner.Airline && a.Type == CodeshareAgreement.CodeshareType.One_Way) || a.Type == CodeshareAgreement.CodeshareType.Both_Ways);

                var codesharingRoutesFromDestination = codeshares.Select(a=>a.Airline1 == airliner.Airliner.Airline ? a.Airline2 : a.Airline1).SelectMany(a => a.Routes.FindAll(r => ((r.Destination2 == airportDestination || r.Destination1 == airportDestination) && (r.Destination1 != airportCurrent && r.Destination2 != airportCurrent))));
                var codesharingRoutesToOrigin= codeshares.Select(a=>a.Airline1 == airliner.Airliner.Airline ? a.Airline2 : a.Airline1).SelectMany(a => a.Routes.FindAll(r => ((r.Destination1 == airportCurrent || r.Destination2 == airportCurrent) && (r.Destination2 != airportDestination && r.Destination1 != airportDestination))));

                allianceRoutesFromDestination = allianceRoutesFromDestination.Union(codesharingRoutesFromDestination);
                allianceRoutesToOrigin = allianceRoutesToOrigin.Union(codesharingRoutesToOrigin);

                foreach (PassengerRoute route in allianceRoutesFromDestination)
                {
                    Airport tDest = route.Destination1 == airportDestination ? route.Destination2 : route.Destination1;

                    double totalDistance = airportCurrent.Profile.Coordinates.convertToGeoCoordinate().GetDistanceTo(tDest.Profile.Coordinates.convertToGeoCoordinate()) / 1000;

                    int directRoutes = AirportHelpers.GetNumberOfAirportsRoutes(airportCurrent, tDest);

                    if (route.getDistance() + legDistance < totalDistance * 3 && directRoutes < 2)
                    {
                        double demand = (double)airportCurrent.getDestinationPassengersRate(tDest, type);
                        demandDestination += demand;
                    }
                }

                foreach (PassengerRoute route in allianceRoutesToOrigin)
                {
                    Airport tDest = route.Destination1 == airportCurrent ? route.Destination2 : route.Destination1;

                    double totalDistance = tDest.Profile.Coordinates.convertToGeoCoordinate().GetDistanceTo(airportDestination.Profile.Coordinates.convertToGeoCoordinate()) / 1000;

                    int directRoutes = AirportHelpers.GetNumberOfAirportsRoutes(tDest, airportDestination);

                    if (route.getDistance() + legDistance < totalDistance * 3 && directRoutes < 2)
                    {
                        double demand = (double)tDest.getDestinationPassengersRate(airportDestination, type);
                        demandOrigin += demand;
                    }
                }
            }

            return demandOrigin + demandDestination;
        }