상속: BaseModel
        public static object ShowPopUp(FleetAirliner airliner)
        {
            PopUpNewAirlinerHomebase window = new PopUpNewAirlinerHomebase(airliner);
            window.ShowDialog();

            return window.Selected == null ? null : window.Selected;
        }
        public PageFleetAirliner(FleetAirliner airliner)
        {
            this.Airliner = new FleetAirlinerMVVM(airliner);
            this.Loaded += this.PageFleetAirliner_Loaded;

            this.InitializeComponent();
        }
        //adds entries for a specific destination and time for each day of the week assigned to an airliner
        public void AddDailyEntries(RouteEntryDestination destination, TimeSpan time, FleetAirliner airliner)
        {
            foreach (DayOfWeek day in Enum.GetValues(typeof (DayOfWeek)))
            {
                var entry = new RouteTimeTableEntry(this, day, time, destination) {Airliner = airliner};

                Entries.Add(entry);
            }
        }
        private static void CheckForService(FleetAirliner airliner)
        {
            const double serviceCheck = 500000000;
            double sinceLastService = airliner.Airliner.Flown - airliner.Airliner.LastServiceCheck;

            if (sinceLastService > serviceCheck)
            {
                SimulateService(airliner);
            }
        }
        //returns the delay time because of the age of an airliner
        public static int GetAirlinerAgeDelay(FleetAirliner airliner)
        {
            int age = airliner.Airliner.Age;

            int tAge = 100 - (age*2);

            bool delayed = Rnd.Next(100) > tAge;

            if (delayed)
                return Rnd.Next(0, age)*2;
            return 0;
        }
예제 #6
0
        public FleetAirlinerMVVM(FleetAirliner airliner)
        {
            Airliner = airliner;
            HasRoute = Airliner.HasRoute;
            Status = Airliner.Status == FleetAirliner.AirlinerStatus.Stopped
                ? StatusMVVM.Stopped
                : StatusMVVM.Started;

            if (Airliner.Status == FleetAirliner.AirlinerStatus.OnCharter)
                Status = StatusMVVM.Charter;

            Routes = new ObservableCollection<Route>();

            foreach (Route route in Airliner.Routes)
                Routes.Add(route);
        }
        public PageAirlineEditAirliners(List<FleetAirliner> airliners)
        {
            Airliners = airliners;

            Loaded += PageAirlineEditAirliners_Loaded;

            DataContext = Airliners;

            Classes = new ObservableCollection<AirlinerClassMVVM>();
            Airliner = getMinimumAirliner();

            foreach (var aClass in Airliner.Airliner.Classes)
            {
                var maxCapacity = Airliner.Airliner.Type.TypeAirliner == AirlinerType.TypeOfAirliner.Passenger ? ((AirlinerPassengerType) Airliner.Airliner.Type).MaxSeatingCapacity : 100;

                var changeable = Airliner.Airliner.Classes.IndexOf(aClass) > 0;

                int maxSeats;

                if (Airliner.Airliner.Classes.Count == 3)
                {
                    if (Airliner.Airliner.Classes.IndexOf(aClass) == 1)
                    {
                        maxSeats = maxCapacity - 1 - Airliner.Airliner.Classes[2].RegularSeatingCapacity;
                    }
                    else
                    {
                        maxSeats = maxCapacity - 1 - Airliner.Airliner.Classes[1].RegularSeatingCapacity;
                    }
                }
                else
                {
                    maxSeats = maxCapacity - 1;
                }

                var amClass = new AirlinerClassMVVM(
                    aClass,
                    aClass.SeatingCapacity,
                    aClass.RegularSeatingCapacity,
                    maxSeats,
                    changeable);
                Classes.Add(amClass);
            }

            InitializeComponent();
        }
        //returns the number of delay minutes (0 if not delayed) for an airliner
        public static KeyValuePair<DelayType, int> GetDelayedMinutes(FleetAirliner airliner)
        {
            //has already been delayed
            if (!airliner.CurrentFlight.IsOnTime)
                return new KeyValuePair<DelayType, int>(DelayType.None, 0);

            var delays = new Dictionary<DelayType, int> {{DelayType.AirlinerProblems, GetAirlinerAgeDelay(airliner)}, {DelayType.BadWeather, 0}};

            //delays.Add(DelayType.Bad_weather, GetAirlinerWeatherDelay(airliner));

            var delay = new KeyValuePair<DelayType, int>(DelayType.None, 0);
            foreach (var d in delays)
            {
                if (d.Value > delay.Value)
                    delay = d;
            }

            return delay;
        }
        public PopUpNewAirlinerHomebase(FleetAirliner airliner)
        {
            this.Airliner = airliner;

            this.Title = string.Format("Select new homebase for {0}", airliner.Name);

            this.Width = 300;

            this.Height = 100;

            this.WindowStartupLocation = WindowStartupLocation.CenterScreen;

            this.WindowStyle = WindowStyle.SingleBorderWindow;

            StackPanel mainPanel = new StackPanel();
            mainPanel.Margin = new Thickness(10, 10, 10, 10);
            cbAirport = new ComboBox();
            cbAirport.SetResourceReference(ComboBox.ItemTemplateProperty, "AirportCountryItem");
            cbAirport.SetResourceReference(StyleProperty, "ComboBoxTransparentStyle");
            cbAirport.IsSynchronizedWithCurrentItem = true;
            cbAirport.HorizontalAlignment = HorizontalAlignment.Left;

            List<Airport> airports = this.Airliner.Airliner.Airline.Airports.FindAll(a => (a.GetCurrentAirportFacility(this.Airliner.Airliner.Airline, AirportFacility.FacilityType.Service).TypeLevel > 0 || a.HasContractType(this.Airliner.Airliner.Airline,AirportContract.ContractType.FullService)) && a.Profile.Period.From <= GameObject.GetInstance().GameTime && a.Profile.Period.To > GameObject.GetInstance().GameTime);

            if (airports.Count == 0)
                airports = this.Airliner.Airliner.Airline.Airports.FindAll(a => a.Profile.Period.From <= GameObject.GetInstance().GameTime && a.Profile.Period.To > GameObject.GetInstance().GameTime);

            airports.Sort(delegate(Airport a1, Airport a2) { return a1.Profile.Name.CompareTo(a2.Profile.Name); });

            foreach (Airport airport in airports)
                cbAirport.Items.Add(airport);

            cbAirport.SelectedIndex = 0;

            mainPanel.Children.Add(cbAirport);

            mainPanel.Children.Add(createButtonsPanel());

            this.Content = mainPanel;
        }
        //add insurance policy
        public static void CreatePolicy(Airline airline, FleetAirliner airliner, AirlinerInsurance.InsuranceType type, AirlinerInsurance.InsuranceScope scope, AirlinerInsurance.PaymentTerms terms,
                                        double length, int amount)
        {
            #region Method Setup

            var rnd = new Random();
            double hub = airline.GetHubs().Count()*0.1;
            var policy = new AirlinerInsurance(type, scope, terms, amount)
                {
                    InsuranceEffective = GameObject.GetInstance().GameTime,
                    InsuranceExpires = GameObject.GetInstance().GameTime.AddYears((int) length),
                    PolicyIndex = GameObject.GetInstance().GameTime.ToString(CultureInfo.InvariantCulture) + airline
                };
            switch (policy.InsTerms)
            {
                case AirlinerInsurance.PaymentTerms.Monthly:
                    policy.RemainingPayments = length*12;
                    break;
                case AirlinerInsurance.PaymentTerms.Quarterly:
                    policy.RemainingPayments = length*4;
                    break;
                case AirlinerInsurance.PaymentTerms.Biannual:
                    policy.RemainingPayments = length*2;
                    break;
                case AirlinerInsurance.PaymentTerms.Annual:
                    policy.RemainingPayments = length;
                    break;
            }
            //sets up multipliers based on the type and scope of insurance policy
            var typeMultipliers = new Dictionary<AirlinerInsurance.InsuranceType, double>();
            var scopeMultipliers = new Dictionary<AirlinerInsurance.InsuranceScope, double>();
            const double typeMLiability = 1;
            const double typeMGroundParked = 1.2;
            const double typeMGroundTaxi = 1.5;
            const double typeMGroundCombined = 1.8;
            const double typeMInFlight = 2.2;
            const double typeMFullCoverage = 2.7;

            const double scMAirport = 1;
            const double scMDomestic = 1.5;
            double scMHub = 1.5 + hub;
            double scMGlobal = 2.0 + hub;

            #endregion

            #region Domestic/Int'l Airport Counter

            int i = 0;
            int j = 0;
            foreach (Airport airport in GameObject.GetInstance().HumanAirline.Airports)
            {
                if (airport.Profile.Country != GameObject.GetInstance().HumanAirline.Profile.Country)
                {
                    i++;
                }
                else j++;
            }

            #endregion

            // all the decision making for monthly payment amounts and deductibles
            switch (type)
            {
                    #region Liability

                case AirlinerInsurance.InsuranceType.Liability:
                    switch (scope)
                    {
                        case AirlinerInsurance.InsuranceScope.Airport:
                            policy.Deductible = amount*0.005;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMLiability*scMAirport;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;

                            break;

                        case AirlinerInsurance.InsuranceScope.Domestic:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMLiability*scMDomestic;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Hub:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMLiability*scMHub;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Global:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMLiability*scMGlobal;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;
                    }
                    break;

                    #endregion

                    #region Ground Parked

                case AirlinerInsurance.InsuranceType.GroundParked:
                    switch (scope)
                    {
                        case AirlinerInsurance.InsuranceScope.Airport:
                            policy.Deductible = amount*0.005;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMGroundParked*scMAirport;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Domestic:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMGroundParked*scMDomestic;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Hub:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMGroundParked*scMHub;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Global:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMGroundParked*scMGlobal;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;
                    }
                    break;

                    #endregion

                    #region Ground Taxi

                case AirlinerInsurance.InsuranceType.GroundTaxi:
                    switch (scope)
                    {
                        case AirlinerInsurance.InsuranceScope.Airport:
                            policy.Deductible = amount*0.005;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMGroundTaxi*scMAirport;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Domestic:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMGroundTaxi*scMDomestic;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Hub:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMGroundTaxi*scMHub;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Global:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMGroundTaxi*scMGlobal;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;
                    }
                    break;

                    #endregion

                    #region Ground Combined

                case AirlinerInsurance.InsuranceType.CombinedGround:
                    switch (scope)
                    {
                        case AirlinerInsurance.InsuranceScope.Airport:
                            policy.Deductible = amount*0.005;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMGroundCombined*scMAirport;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Domestic:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMGroundCombined*scMDomestic;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Hub:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMGroundCombined*scMHub;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Global:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMGroundCombined*scMGlobal;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;
                    }
                    break;

                    #endregion

                    #region In Flight

                case AirlinerInsurance.InsuranceType.InFlight:
                    switch (scope)
                    {
                        case AirlinerInsurance.InsuranceScope.Airport:
                            policy.Deductible = amount*0.005;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMInFlight*scMAirport;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Domestic:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMInFlight*scMDomestic;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Hub:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMInFlight*scMHub;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Global:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMInFlight*scMGlobal;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;
                    }

                    break;

                    #endregion

                    #region Full Coverage

                case AirlinerInsurance.InsuranceType.FullCoverage:
                    switch (scope)
                    {
                        case AirlinerInsurance.InsuranceScope.Airport:
                            policy.Deductible = amount*0.005;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMFullCoverage*scMAirport;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Domestic:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMFullCoverage*scMDomestic;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Hub:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMFullCoverage*scMHub;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;

                        case AirlinerInsurance.InsuranceScope.Global:
                            policy.Deductible = amount*0.001;
                            policy.PaymentAmount = policy.InsuredAmount*(4/10)*typeMFullCoverage*scMGlobal;
                            if (terms == AirlinerInsurance.PaymentTerms.Annual) policy.PaymentAmount = policy.InsuredAmount/length;
                            if (terms == AirlinerInsurance.PaymentTerms.Biannual) policy.PaymentAmount = policy.InsuredAmount/length/2;
                            if (terms == AirlinerInsurance.PaymentTerms.Quarterly) policy.PaymentAmount = policy.InsuredAmount/length/4;
                            if (terms == AirlinerInsurance.PaymentTerms.Monthly) policy.PaymentAmount = policy.InsuredAmount/length/12;
                            break;
                    }
                    break;

                    #endregion
            }
        }
 public static void SetMaintenanceIntervals(FleetAirliner airliner, int a, int b, int c, int d)
 {
     airliner.AMaintenanceInterval = a;
     airliner.BMaintenanceInterval = b;
     airliner.CMaintenanceInterval = c;
     airliner.DMaintenanceInterval = d;
 }
        public static void SetMaintenanceIntervals(FleetAirliner airliner, int a, int b, int c)
        {
            if (airliner.CMaintenanceInterval == -1)
            {
                airliner.AMaintenanceInterval = a;
                airliner.BMaintenanceInterval = b;
                airliner.DMaintenanceInterval = c;
            }

            else if (airliner.DMaintenanceInterval == -1)
            {
                airliner.AMaintenanceInterval = a;
                airliner.BMaintenanceInterval = b;
                airliner.CMaintenanceInterval = c;
            }
        }
 //sets A and B check intervals
 public static void SetMaintenanceIntervals(FleetAirliner airliner, int a, int b)
 {
     airliner.AMaintenanceInterval = a;
     airliner.BMaintenanceInterval = b;
     airliner.CMaintenanceInterval = -1;
     airliner.DMaintenanceInterval = -1;
 }
        //restores routes removed for maintenance
        public static void RestoreMaintRoutes(FleetAirliner airliner)
        {
            if (airliner.OOSDate <= GameObject.GetInstance().GameTime)
            {
                foreach (Route r in airliner.MaintRoutes)
                {
                    airliner.Routes.Add(r);
                }

                airliner.MaintRoutes.Clear();
            }
        }
        //does the maintenance of a given type, sends the invoice, updates the last/next maintenance, and improves the aircraft's damage
        //make sure you pass this function a string value of either "A" "B" "C" or "D" or it will throw an error!
        public static void DoMaintenance(FleetAirliner airliner)
        {
            if (airliner.SchedAMaintenance == GameObject.GetInstance().GameTime.Date)
            {
                double expense = (airliner.Airliner.GetValue()*0.01) + 2000;
                GameObject.GetInstance().AddHumanMoney((long) -expense);
                var maintCheck = new Invoice(GameObject.GetInstance().GameTime, Invoice.InvoiceType.Maintenances, -expense);
                AirlineHelpers.AddAirlineInvoice(airliner.Airliner.Airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Maintenances, -expense);
                airliner.Airliner.Condition += Rnd.Next(3, 10);
                if (airliner.Airliner.Condition > 100) airliner.Airliner.Condition = 100;
                airliner.LastAMaintenance = GameObject.GetInstance().GameTime;
                airliner.SchedAMaintenance = airliner.SchedAMaintenance.AddDays(airliner.AMaintenanceInterval);
                airliner.MaintenanceHistory.Add(maintCheck, "A");
            }

            if (airliner.SchedBMaintenance == GameObject.GetInstance().GameTime.Date)
            {
                double expense = (airliner.Airliner.GetValue()*0.02) + 4500;
                GameObject.GetInstance().AddHumanMoney((long) -expense);
                var maintCheck = new Invoice(GameObject.GetInstance().GameTime, Invoice.InvoiceType.Maintenances, -expense);
                AirlineHelpers.AddAirlineInvoice(airliner.Airliner.Airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Maintenances, -expense);
                airliner.Airliner.Condition += Rnd.Next(12, 20);
                if (airliner.Airliner.Condition > 100) airliner.Airliner.Condition = 100;
                airliner.LastBMaintenance = GameObject.GetInstance().GameTime;
                airliner.SchedBMaintenance = airliner.SchedBMaintenance.AddDays(airliner.BMaintenanceInterval);
                airliner.MaintenanceHistory.Add(maintCheck, "B");
            }

            if (airliner.SchedCMaintenance == GameObject.GetInstance().GameTime.Date)
            {
                double expense = (airliner.Airliner.GetValue()*0.025) + 156000;
                airliner.OOSDate = airliner.SchedCMaintenance.AddDays(airliner.Airliner.Condition + 20);
                GameObject.GetInstance().AddHumanMoney((long) -expense);
                var maintCheck = new Invoice(GameObject.GetInstance().GameTime, Invoice.InvoiceType.Maintenances, -expense);
                AirlineHelpers.AddAirlineInvoice(airliner.Airliner.Airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Maintenances, -expense);
                airliner.Airliner.Condition += Rnd.Next(20, 30);
                if (airliner.Airliner.Condition > 100) airliner.Airliner.Condition = 100;
                airliner.LastCMaintenance = GameObject.GetInstance().GameTime;
                airliner.SchedCMaintenance = airliner.CMaintenanceInterval > -1
                                                 ? airliner.SchedCMaintenance.AddMonths(airliner.CMaintenanceInterval)
                                                 : airliner.DueCMaintenance = GameObject.GetInstance().GameTime.AddMonths(18);
                airliner.MaintenanceHistory.Add(maintCheck, "C");
                foreach (Route r in airliner.Routes.ToList())
                {
                    airliner.MaintRoutes.Add(r);
                    airliner.Routes.Remove(r);
                }
            }

            if (airliner.SchedDMaintenance == GameObject.GetInstance().GameTime.Date)
            {
                double expense = (airliner.Airliner.GetValue()*0.03) + 1200000;
                airliner.OOSDate = airliner.SchedDMaintenance.AddDays(airliner.Airliner.Condition + 50);
                GameObject.GetInstance().AddHumanMoney((long) -expense);
                var maintCheck = new Invoice(GameObject.GetInstance().GameTime, Invoice.InvoiceType.Maintenances, -expense);
                AirlineHelpers.AddAirlineInvoice(airliner.Airliner.Airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Maintenances, -expense);
                airliner.Airliner.Condition += Rnd.Next(35, 50);
                if (airliner.Airliner.Condition > 100) airliner.Airliner.Condition = 100;
                airliner.LastDMaintenance = GameObject.GetInstance().GameTime;
                airliner.SchedDMaintenance = airliner.DMaintenanceInterval > -1
                                                 ? airliner.SchedDMaintenance.AddMonths(airliner.DMaintenanceInterval)
                                                 : airliner.DueDMaintenance = GameObject.GetInstance().GameTime.AddMonths(60);
                airliner.DueDMaintenance = GameObject.GetInstance().GameTime.AddMonths(60);
                airliner.MaintenanceHistory.Add(maintCheck, "D");
                foreach (Route r in airliner.Routes.ToList())
                {
                    airliner.MaintRoutes.Add(r);
                    airliner.Routes.Remove(r);
                }
            }
        }
        //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();

            bool 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 Math.Min(airliner.Airliner.GetAirlinerClass(type).SeatingCapacity, passengers);
        }
        //converts a passenger airliner to a cargo airliner
        public static void ConvertPassengerToCargoAirliner(FleetAirliner airliner)
        {
            var oldType = (AirlinerPassengerType) airliner.Airliner.Type;

            double cargoSize = AirlinerHelpers.GetPassengerCargoSize(oldType);
            DateTime builtDate = GameObject.GetInstance().GameTime.AddDays(AirlinerHelpers.GetCargoConvertingDays(oldType));

            var newType = new AirlinerCargoType(oldType.Manufacturer, oldType.Name + "F", oldType.AirlinerFamily, oldType.CockpitCrew, cargoSize, oldType.CruisingSpeed, oldType.Range, oldType.Wingspan,
                                                oldType.Length, oldType.Weight, oldType.FuelConsumption, oldType.Price, oldType.MinRunwaylength, oldType.FuelCapacity, oldType.Body, oldType.RangeType,
                                                oldType.Engine, oldType.Produced, oldType.ProductionRate, false, false);

            airliner.Airliner.Type = newType;
            airliner.Airliner.BuiltDate = builtDate;
        }
 //extend or modify policy
 public static void ModifyPolicy(FleetAirliner airliner, string index, AirlinerInsurance newPolicy)
 {
     //AirlinerInsurance oldPolicy = airliner.InsurancePolicies[index];
     //use the index to compare the new policy passed in to the existing one and make changes
 }
        private static double GetFlightConnectionPassengers(
            Airport airportCurrent,
            Airport airportDestination,
            FleetAirliner airliner,
            AirlinerClass.ClassType type)
        {
            double legDistance = MathHelpers.GetDistance(airportCurrent, airportDestination);

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

            double demandDestination = (from PassengerRoute route in routesFromDestination
                                        let tDest = route.Destination1 == airportDestination ? route.Destination2 : route.Destination1
                                        let totalDistance = airportCurrent.Profile.Coordinates.ConvertToGeoCoordinate().GetDistanceTo(tDest.Profile.Coordinates.ConvertToGeoCoordinate())/1000
                                        let directRoutes = AirportHelpers.GetNumberOfAirportsRoutes(airportCurrent, tDest)
                                        where route.GetDistance() + legDistance < totalDistance*3 && directRoutes < 2
                                        select airportCurrent.GetDestinationPassengersRate(tDest, type)
                                        into demand select (demand*0.25)).Sum();

            double demandOrigin = (from PassengerRoute route in routesToOrigin
                                   let tDest = route.Destination1 == airportCurrent ? route.Destination2 : route.Destination1
                                   let totalDistance = tDest.Profile.Coordinates.ConvertToGeoCoordinate().GetDistanceTo(airportDestination.Profile.Coordinates.ConvertToGeoCoordinate())/1000
                                   let directRoutes = AirportHelpers.GetNumberOfAirportsRoutes(tDest, airportDestination)
                                   where route.GetDistance() + legDistance < totalDistance*3 && directRoutes < 2
                                   select tDest.GetDestinationPassengersRate(airportDestination, type)
                                   into demand select (demand*0.25)).Sum();
            //alliances & codesharings
            if (airliner.Airliner.Airline.Alliances.Count > 0 || airliner.Airliner.Airline.Codeshares.Count > 0)
            {
                IEnumerable<Route> 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)))));
                IEnumerable<Route> 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)))));

                IEnumerable<CodeshareAgreement> codeshares =
                    airliner.Airliner.Airline.Codeshares.Where(
                        a =>
                        (a.Airline2 == airliner.Airliner.Airline
                         && a.Type == CodeshareAgreement.CodeshareType.OneWay)
                        || a.Type == CodeshareAgreement.CodeshareType.BothWays);

                var codeshareAgreements = codeshares as CodeshareAgreement[] ?? codeshares.ToArray();
                IEnumerable<Route> codesharingRoutesFromDestination =
                    codeshareAgreements.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))));
                IEnumerable<Route> codesharingRoutesToOrigin =
                    codeshareAgreements.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.Where(r => !r.IsCargoRoute))
                {
                    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 = airportCurrent.GetDestinationPassengersRate(tDest, type);
                        demandDestination += demand;
                    }
                }

                foreach (PassengerRoute route in allianceRoutesToOrigin.Where(r => !r.IsCargoRoute))
                {
                    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 = tDest.GetDestinationPassengersRate(airportDestination, type);
                        demandOrigin += demand;
                    }
                }
            }

            return demandOrigin + demandDestination;
        }
        //returns the delay time because of the weather for an airliner
        public static int GetAirlinerWeatherDelay(FleetAirliner airliner)
        {
            Airport departureAirport = airliner.CurrentFlight.GetDepartureAirport();

            int windFactor = 0;

            if (departureAirport.Weather[0] == null)
                return 0;

            switch (departureAirport.Weather[0].WindSpeed)
            {
                case Weather.eWindSpeed.StrongBreeze:
                    windFactor = 2;
                    break;
                case Weather.eWindSpeed.NearGale:
                    windFactor = 4;
                    break;
                case Weather.eWindSpeed.Gale:
                    windFactor = 6;
                    break;
                case Weather.eWindSpeed.StrongGale:
                    windFactor = 8;
                    break;
                case Weather.eWindSpeed.Storm:
                    windFactor = 10;
                    break;
                case Weather.eWindSpeed.ViolentStorm:
                    windFactor = 12;
                    break;
                case Weather.eWindSpeed.Hurricane:
                    windFactor = 14;
                    break;
            }

            if ((departureAirport.Weather[0].Temperatures[GameObject.GetInstance().GameTime.Hour].Precip == Weather.Precipitation.None ||
                 departureAirport.Weather[0].Temperatures[GameObject.GetInstance().GameTime.Hour].Precip == Weather.Precipitation.LightRain) && windFactor == 0)
                return 0;

            int weatherFactor = 0;

            switch (departureAirport.Weather[0].Temperatures[GameObject.GetInstance().GameTime.Hour].Precip)
            {
                case Weather.Precipitation.IsolatedSnow:
                    weatherFactor = 2;
                    break;
                case Weather.Precipitation.LightSnow:
                    weatherFactor = 4;
                    break;
                case Weather.Precipitation.HeavySnow:
                    weatherFactor = 8;
                    break;
                case Weather.Precipitation.Fog:
                    weatherFactor = 4;
                    break;
                case Weather.Precipitation.Sleet:
                    weatherFactor = 4;
                    break;
                case Weather.Precipitation.FreezingRain:
                    weatherFactor = 6;
                    break;
                case Weather.Precipitation.MixedRainAndSnow:
                    weatherFactor = 6;
                    break;
                case Weather.Precipitation.IsolatedRain:
                    weatherFactor = 1;
                    break;
                case Weather.Precipitation.LightRain:
                    weatherFactor = 2;
                    break;
                case Weather.Precipitation.HeavyRain:
                    weatherFactor = 4;
                    break;
                case Weather.Precipitation.IsolatedThunderstorms:
                    weatherFactor = 5;
                    break;
                case Weather.Precipitation.Thunderstorms:
                    weatherFactor = 8;
                    break;
            }

            int delayTime = Rnd.Next((weatherFactor + windFactor), (weatherFactor + windFactor)*12);

            return delayTime;
        }
        //sets the flights stats for an airliner
        public static void SetFlightStats(FleetAirliner airliner)
        {
            TimeSpan flightTime = MathHelpers.GetFlightTime(airliner.CurrentFlight.Entry.DepartureAirport.Profile.Coordinates.ConvertToGeoCoordinate(),
                                                            airliner.CurrentFlight.Entry.Destination.Airport.Profile.Coordinates.ConvertToGeoCoordinate(), airliner.Airliner.Type);
            DateTime landingTime = airliner.CurrentFlight.FlightTime.Add(flightTime);

            airliner.Airliner.FlownHours = airliner.Airliner.FlownHours.Add(flightTime);

            Airport dest = airliner.CurrentFlight.Entry.Destination.Airport;
            Airport dept = airliner.CurrentFlight.Entry.DepartureAirport;

            //canellation and ontime-percent
            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);

            bool isOnTime = landingTime.Subtract(airliner.CurrentFlight.GetScheduledLandingTime()).Minutes < 15;

            if (isOnTime)
                airliner.Airliner.Airline.Statistics.AddStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("On-Time"), 1);

            airliner.Airliner.Airline.Statistics.AddStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Arrivals"), 1);
            dest.Statistics.AddStatisticsValue(GameObject.GetInstance().GameTime.Year, airliner.Airliner.Airline, StatisticsTypes.GetStatisticsType("Arrivals"), 1);
            airliner.CurrentFlight.Entry.TimeTable.Route.Statistics.AddStatisticsValue(StatisticsTypes.GetStatisticsType("Cargo"), 1);
            airliner.Statistics.AddStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Arrivals"), 1);

            double onTimePercent = airliner.Airliner.Airline.Statistics.GetStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("On-Time"))/
                                   airliner.Airliner.Airline.Statistics.GetStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Arrivals"));
            airliner.Airliner.Airline.Statistics.SetStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("On-Time%"), onTimePercent*100);


            if (airliner.CurrentFlight.IsCargoFlight())
            {
                airliner.CurrentFlight.Entry.TimeTable.Route.Statistics.AddStatisticsValue(StatisticsTypes.GetStatisticsType("Cargo"), (int) airliner.CurrentFlight.Cargo);
                double routePassengers = airliner.CurrentFlight.Entry.TimeTable.Route.Statistics.GetStatisticsValue(StatisticsTypes.GetStatisticsType("Cargo"));
                double routeDepartures = airliner.CurrentFlight.Entry.TimeTable.Route.Statistics.GetStatisticsValue(StatisticsTypes.GetStatisticsType("Arrivals"));
                airliner.CurrentFlight.Entry.TimeTable.Route.Statistics.SetStatisticsValue(StatisticsTypes.GetStatisticsType("Cargo%"), (int) (routePassengers/routeDepartures));

                double cargocapacity = 0;

                var type = airliner.Airliner.Type as AirlinerCargoType;
                if (type != null)
                    cargocapacity = type.CargoSize;

                var combiType = airliner.Airliner.Type as AirlinerCombiType;
                if (combiType != null)
                    cargocapacity = combiType.CargoSize;

                airliner.CurrentFlight.Entry.TimeTable.Route.Statistics.AddStatisticsValue(StatisticsTypes.GetStatisticsType("Capacity"), (int) cargocapacity);

                double airlinerCargo = airliner.Statistics.GetStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Cargo"));
                double airlinerDepartures = airliner.Statistics.GetStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Arrivals"));
                airliner.Statistics.SetStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Cargo%"), (int) (airlinerCargo/airlinerDepartures));

                airliner.Airliner.Airline.Statistics.AddStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Cargo"), airliner.CurrentFlight.Cargo);
                airliner.Statistics.AddStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Cargo"), airliner.CurrentFlight.Cargo);
                dest.Statistics.AddStatisticsValue(GameObject.GetInstance().GameTime.Year, airliner.Airliner.Airline, StatisticsTypes.GetStatisticsType("Cargo"), (int) airliner.CurrentFlight.Cargo);

                double destCargo = dest.Statistics.GetStatisticsValue(GameObject.GetInstance().GameTime.Year, airliner.Airliner.Airline, StatisticsTypes.GetStatisticsType("Cargo"));
                double destDepartures = dest.Statistics.GetStatisticsValue(GameObject.GetInstance().GameTime.Year, airliner.Airliner.Airline, StatisticsTypes.GetStatisticsType("Arrivals"));
                dest.Statistics.SetStatisticsValue(GameObject.GetInstance().GameTime.Year, airliner.Airliner.Airline, StatisticsTypes.GetStatisticsType("Cargo%"), (int) (destCargo/destDepartures));

                double airlineCargo = airliner.Airliner.Airline.Statistics.GetStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Cargo"));
                double airlineDepartures = airliner.Airliner.Airline.Statistics.GetStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Arrivals"));
                airliner.Airliner.Airline.Statistics.SetStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Cargo%"), (int) (airlineCargo/airlineDepartures));

                dept.AddCargoDestinationStatistics(dest, airliner.CurrentFlight.Cargo);
            }
            if (airliner.CurrentFlight.IsPassengerFlight())
            {
                foreach (FlightAirlinerClass fac in airliner.CurrentFlight.Classes)
                {
                    RouteAirlinerClass raClass = ((PassengerRoute) airliner.CurrentFlight.Entry.TimeTable.Route).GetRouteAirlinerClass(fac.AirlinerClass.Type);

                    airliner.CurrentFlight.Entry.TimeTable.Route.Statistics.AddStatisticsValue(raClass, StatisticsTypes.GetStatisticsType("Passengers"),
                                                                                               airliner.CurrentFlight.GetFlightAirlinerClass(raClass.Type).Passengers);
                    double routePassengers = airliner.CurrentFlight.Entry.TimeTable.Route.Statistics.GetStatisticsValue(raClass, StatisticsTypes.GetStatisticsType("Passengers"));
                    double routeDepartures = airliner.CurrentFlight.Entry.TimeTable.Route.Statistics.GetStatisticsValue(raClass, StatisticsTypes.GetStatisticsType("Arrivals"));
                    airliner.CurrentFlight.Entry.TimeTable.Route.Statistics.SetStatisticsValue(raClass, StatisticsTypes.GetStatisticsType("Passengers%"), (int) (routePassengers/routeDepartures));

                    airliner.CurrentFlight.Entry.TimeTable.Route.Statistics.AddStatisticsValue(raClass, StatisticsTypes.GetStatisticsType("Capacity"),
                                                                                               airliner.Airliner.GetAirlinerClass(raClass.Type).SeatingCapacity);
                }

                double airlinerPassengers = airliner.Statistics.GetStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Passengers"));
                double airlinerDepartures = airliner.Statistics.GetStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Arrivals"));
                airliner.Statistics.SetStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Passengers%"), (int) (airlinerPassengers/airlinerDepartures));


                airliner.Airliner.Airline.Statistics.AddStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Passengers"),
                                                                        airliner.CurrentFlight.GetTotalPassengers());
                airliner.Statistics.AddStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Passengers"), airliner.CurrentFlight.GetTotalPassengers());
                dest.Statistics.AddStatisticsValue(GameObject.GetInstance().GameTime.Year, airliner.Airliner.Airline, StatisticsTypes.GetStatisticsType("Passengers"),
                                                   airliner.CurrentFlight.GetTotalPassengers());


                double destPassengers = dest.Statistics.GetStatisticsValue(GameObject.GetInstance().GameTime.Year, airliner.Airliner.Airline, StatisticsTypes.GetStatisticsType("Passengers"));
                double destDepartures = dest.Statistics.GetStatisticsValue(GameObject.GetInstance().GameTime.Year, airliner.Airliner.Airline, StatisticsTypes.GetStatisticsType("Arrivals"));
                dest.Statistics.SetStatisticsValue(GameObject.GetInstance().GameTime.Year, airliner.Airliner.Airline, StatisticsTypes.GetStatisticsType("Passengers%"),
                                                   (int) (destPassengers/destDepartures));

                double airlinePassengers = airliner.Airliner.Airline.Statistics.GetStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Passengers"));
                double airlineDepartures = airliner.Airliner.Airline.Statistics.GetStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Arrivals"));
                airliner.Airliner.Airline.Statistics.SetStatisticsValue(GameObject.GetInstance().GameTime.Year, StatisticsTypes.GetStatisticsType("Passengers%"),
                                                                        (int) (airlinePassengers/airlineDepartures));

                //the statistics for destination airport
                dept.AddPassengerDestinationStatistics(dest, airliner.CurrentFlight.GetTotalPassengers());
            }
        }
 //returns the minimum time between flights for an airliner
 public static TimeSpan GetMinTimeBetweenFlights(FleetAirliner airliner)
 {
     return GetMinTimeBetweenFlights(airliner.Airliner.GetTotalSeatCapacity());
 }
        public PageRoutePlanner(FleetAirliner airliner)
        {
            ShowSeason = Weather.Season.AllYear;

            Airliner = airliner;
            Entries = new ObservableCollection<RouteTimeTableEntry>();
            Entries.CollectionChanged += Entries_CollectionChanged;

            ViewEntries = new ObservableCollection<RouteTimeTableEntry>();
            ViewEntries.CollectionChanged += ViewEntries_CollectionChanged;

            IsLongRoute = false;

            AllRoutes = new List<RoutePlannerItemMVVM>();
            Intervals = new ObservableCollection<int> { 1, 2, 3, 4, 5, 6 };

            Routes = new ObservableCollection<Route>();

            var routeType =
                (Route.RouteType)
                    Enum.Parse(typeof(Route.RouteType), Airliner.Airliner.Type.TypeAirliner.ToString(), true);
            ;

            foreach (
                Route route in
                    Airliner.Airliner.Airline.Routes.Where(
                        r => r.GetDistance() <= Airliner.Airliner.Range && r.Type == routeType))
            {
                Routes.Add(route);
            }

            AllRegions = new List<Region>();
            AllRegions.Add(Regions.GetRegion("100"));

            List<Region> routeRegions = Routes.Select(r => r.Destination1.Profile.Country.Region).ToList();
            routeRegions.AddRange(Routes.Select(r => r.Destination2.Profile.Country.Region));

            foreach (Region region in routeRegions.Distinct())
            {
                AllRegions.Add(region);
            }

            foreach (
                Route route in
                    Airliner.Airliner.Airline.Routes.Where(
                        r => r.GetDistance() <= Airliner.Airliner.Range && r.Type == routeType))
            {
                AllRoutes.Add(new RoutePlannerItemMVVM(route, Airliner.Airliner.Type));
            }

            OutboundAirports = new List<Airport>();
            List<Airport> routeAirports = Routes.Select(r => r.Destination1).ToList();
            routeAirports.AddRange(Routes.Select(r => r.Destination2));

            foreach (Airport airport in routeAirports.Distinct())
            {
                OutboundAirports.Add(airport);
            }

            StartTimes = new ObservableCollection<TimeSpan>();

            for (int i = 0; i < 20; i++)
            {
                StartTimes.Add(new TimeSpan(6, i * 15, 0));
            }

            StopoverMinutes = new List<int> { 45, 60, 75, 90, 105, 120 };

            setCanTransferSchedule();

            SpecialContractRoutes = new List<Route>();

            var humanSpecialRoutes = GameObject.GetInstance().HumanAirline.SpecialContracts.Where(s => !s.Type.IsFixedDate).SelectMany(s => s.Routes.Where(r=>!r.HasAirliner));

            foreach (Route sRoute in humanSpecialRoutes)
                SpecialContractRoutes.Add(sRoute);

            Loaded += PageRoutePlanner_Loaded;

            InitializeComponent();
        }
        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;

            IEnumerable<Airport> 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 = 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;
        }
 public static void AddPolicy(FleetAirliner airliner, AirlinerInsurance insurance)
 {
     airliner.InsurancePolicies.Add(insurance);
 }
        //returns the flight crusing speed based on the wind
        public static int GetCruisingSpeed(FleetAirliner airliner)
        {
            Airport dest = airliner.CurrentFlight.Entry.Destination.Airport;
            Airport dept = airliner.CurrentFlight.GetDepartureAirport();

            double windFirstHalf = ((int) dept.Weather[0].WindSpeed)*GetWindInfluence(airliner, dept.Weather[0]);

            double windSecondHalf = ((int) dest.Weather[0].WindSpeed)*GetWindInfluence(airliner, dest.Weather[0]);

            int speed = Convert.ToInt32(((airliner.Airliner.CruisingSpeed + windFirstHalf) + (airliner.Airliner.CruisingSpeed + windSecondHalf))/2);

            return speed;
        }
 public static void MakeInsurancePayment(FleetAirliner airliner, Airline airline)
 {
     foreach (AirlinerInsurance policy in airliner.InsurancePolicies)
     {
         if (policy.RemainingPayments > 0)
         {
             if (policy.NextPaymentDue.Month == GameObject.GetInstance().GameTime.Month)
             {
                 airline.Money -= policy.PaymentAmount;
                 //Invoice payment = new Invoice(GameObject.GetInstance().GameTime, Invoice.InvoiceType.Maintenances, policy.PaymentAmount);
                 AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Maintenances, -policy.PaymentAmount);
                 policy.RemainingPayments--;
                 switch (policy.InsTerms)
                 {
                     case AirlinerInsurance.PaymentTerms.Monthly:
                         policy.NextPaymentDue = GameObject.GetInstance().GameTime.AddMonths(1);
                         break;
                     case AirlinerInsurance.PaymentTerms.Quarterly:
                         policy.NextPaymentDue = GameObject.GetInstance().GameTime.AddMonths(3);
                         break;
                     case AirlinerInsurance.PaymentTerms.Biannual:
                         policy.NextPaymentDue = GameObject.GetInstance().GameTime.AddMonths(6);
                         break;
                     case AirlinerInsurance.PaymentTerms.Annual:
                         policy.NextPaymentDue = GameObject.GetInstance().GameTime.AddMonths(12);
                         break;
                 }
             }
         }
     }
 }
        //returns if the wind is tail (1), head (-1), or from side (0)
        private static int GetWindInfluence(FleetAirliner airliner, Weather currentWeather)
        {
            double direction = MathHelpers.GetDirection(airliner.CurrentFlight.GetDepartureAirport().Profile.Coordinates.ConvertToGeoCoordinate(),
                                                        airliner.CurrentFlight.GetNextDestination().Profile.Coordinates.ConvertToGeoCoordinate());

            Weather.WindDirection windDirection = MathHelpers.GetWindDirectionFromDirection(direction);

            int windDirectionLenght = Enum.GetValues(typeof (Weather.WindDirection)).Length;
            int indexCurrentPosition = Array.IndexOf(Enum.GetValues(typeof (Weather.WindDirection)), windDirection);
            //int indexWeather = Array.IndexOf(Enum.GetValues(typeof(Weather.WindDirection)),currentWeather.WindSpeed);

            //check for tail wind
            Weather.WindDirection windTailLeft = indexCurrentPosition > 0 ? (Weather.WindDirection) indexCurrentPosition - 1 : (Weather.WindDirection) windDirectionLenght - 1;
            Weather.WindDirection windTailRight = indexCurrentPosition < windDirectionLenght - 1 ? (Weather.WindDirection) indexCurrentPosition + 1 : 0;

            if (windTailLeft == currentWeather.Direction || windTailRight == currentWeather.Direction || windDirection == currentWeather.Direction)
                return 1;

            Weather.WindDirection windOpposite = indexCurrentPosition - (windDirectionLenght/2) > 0
                                                     ? (Weather.WindDirection) indexCurrentPosition - (windDirectionLenght/2)
                                                     : (Weather.WindDirection) windDirectionLenght - 1 - indexCurrentPosition - (windDirectionLenght/2);
            int indexOpposite = Array.IndexOf(Enum.GetValues(typeof (Weather.WindDirection)), windOpposite);

            Weather.WindDirection windHeadLeft = indexOpposite > 0 ? (Weather.WindDirection) indexOpposite - 1 : (Weather.WindDirection) windDirectionLenght - 1;
            Weather.WindDirection windHeadRight = indexOpposite < windDirectionLenght - 1 ? (Weather.WindDirection) indexOpposite + 1 : 0;

            if (windHeadLeft == currentWeather.Direction || windHeadRight == currentWeather.Direction || windOpposite == currentWeather.Direction)
                return -1;

            return 0;
        }
예제 #29
0
        private static void CreateComputerRoutes(Airline airline)
        {
            bool leaseAircraft = airline.Profile.PrimaryPurchasing == AirlineProfile.PreferedPurchasing.Leasing;

            Airport airportHomeBase = FindComputerHomeBase(airline);

            AirportFacility serviceFacility =
                AirportFacilities.GetFacilities(AirportFacility.FacilityType.Service).Find(f => f.TypeLevel == 1);
            AirportFacility checkinFacility =
                AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1);
            AirportFacility cargoTerminal =
                AirportFacilities.GetFacilities(AirportFacility.FacilityType.Cargo).Find(f => f.TypeLevel > 0);

            airportHomeBase.AddAirportFacility(airline, serviceFacility, GameObject.GetInstance().GameTime);
            airportHomeBase.AddAirportFacility(airline, checkinFacility, GameObject.GetInstance().GameTime);

            if (airline.AirlineRouteFocus == Route.RouteType.Cargo)
            {
                airportHomeBase.AddAirportFacility(airline, cargoTerminal, GameObject.GetInstance().GameTime);
            }

            AirlineStartData startData = AirlineStartDatas.GetAirlineStartData(airline);

            //creates the start data for an airline
            if (startData != null)
            {
                AirportHelpers.RentGates(airportHomeBase, airline, AirportContract.ContractType.Full);

                CreateAirlineStartData(airline, startData);
            }
            else
            {
                List<Airport> airportDestinations = AIHelpers.GetDestinationAirports(airline, airportHomeBase);

                if (airportDestinations.Count == 0)
                {
                    airportDestinations =
                        Airports.GetAirports(
                            a =>
                            a.Profile.Country.Region == airportHomeBase.Profile.Country.Region
                            && a != airportHomeBase);
                }

                KeyValuePair<Airliner, bool>? airliner = null;
                Airport airportDestination = null;

                int counter = 0;

                while ((airportDestination == null || airliner == null || !airliner.HasValue)
                       && airportDestinations.Count > counter)
                {
                    airportDestination = airportDestinations[counter];

                    airliner = AIHelpers.GetAirlinerForRoute(
                        airline,
                        airportHomeBase,
                        airportDestination,
                        leaseAircraft,
                        airline.AirlineRouteFocus,
                        true);

                    counter++;
                }

                if (airportDestination == null || !airliner.HasValue)
                {
                    CreateComputerRoutes(airline);
                }
                else
                {
                    AirportHelpers.AddAirlineContract(
                        new AirportContract(
                            airline,
                            airportHomeBase,
                            AirportContract.ContractType.Full,
                            airline.AirlineRouteFocus == Route.RouteType.Cargo ? Terminal.TerminalType.Cargo : Terminal.TerminalType.Passenger,
                            GameObject.GetInstance().GameTime,
                            2,
                            25,
                            0,
                            true));

                    AirportHelpers.RentGates(airportDestination, airline, AirportContract.ContractType.LowService);
                    //airportDestination.addAirportFacility(airline, checkinFacility, GameObject.GetInstance().GameTime);

                    Guid id = Guid.NewGuid();

                    double price = PassengerHelpers.GetPassengerPrice(airportDestination, airline.Airports[0]);

                    Route route = null;
                    if (airline.AirlineRouteFocus == Route.RouteType.Passenger)
                    {
                        route = new PassengerRoute(
                            id.ToString(),
                            airportDestination,
                            airline.Airports[0],
                            GameObject.GetInstance().GameTime,
                            price);

                        RouteClassesConfiguration configuration = AIHelpers.GetRouteConfiguration((PassengerRoute) route);

                        foreach (RouteClassConfiguration classConfiguration in configuration.GetClasses())
                        {
                            ((PassengerRoute) route).GetRouteAirlinerClass(classConfiguration.Type).FarePrice = price
                                                                                                                *GeneralHelpers
                                                                                                                     .ClassToPriceFactor
                                                                                                                     (
                                                                                                                         classConfiguration
                                                                                                                             .Type);

                            foreach (RouteFacility rFacility in classConfiguration.GetFacilities())
                            {
                                ((PassengerRoute) route).GetRouteAirlinerClass(classConfiguration.Type)
                                                        .AddFacility(rFacility);
                            }
                        }
                    }
                    if (airline.AirlineRouteFocus == Route.RouteType.Helicopter)
                    {
                        route = new HelicopterRoute(
                            id.ToString(),
                            airportDestination,
                            airline.Airports[0],
                            GameObject.GetInstance().GameTime,
                            price);

                        RouteClassesConfiguration configuration = AIHelpers.GetRouteConfiguration((HelicopterRoute) route);

                        foreach (RouteClassConfiguration classConfiguration in configuration.GetClasses())
                        {
                            ((HelicopterRoute) route).GetRouteAirlinerClass(classConfiguration.Type).FarePrice = price
                                                                                                                 *GeneralHelpers
                                                                                                                      .ClassToPriceFactor
                                                                                                                      (
                                                                                                                          classConfiguration
                                                                                                                              .Type);

                            foreach (RouteFacility rFacility in classConfiguration.GetFacilities())
                            {
                                ((HelicopterRoute) route).GetRouteAirlinerClass(classConfiguration.Type)
                                                         .AddFacility(rFacility);
                            }
                        }
                    }
                    if (airline.AirlineRouteFocus == Route.RouteType.Cargo)
                    {
                        route = new CargoRoute(
                            id.ToString(),
                            airportDestination,
                            airline.Airports[0],
                            GameObject.GetInstance().GameTime,
                            PassengerHelpers.GetCargoPrice(airportDestination, airline.Airports[0]));

                        airportDestination.AddAirportFacility(airline, cargoTerminal, GameObject.GetInstance().GameTime);
                    }
                    if (leaseAircraft)
                    {
                        AirlineHelpers.AddAirlineInvoice(
                            airline,
                            GameObject.GetInstance().GameTime,
                            Invoice.InvoiceType.Rents,
                            -airliner.Value.Key.LeasingPrice*2);
                    }
                    else
                    {
                        AirlineHelpers.AddAirlineInvoice(
                            airline,
                            GameObject.GetInstance().GameTime,
                            Invoice.InvoiceType.Purchases,
                            -airliner.Value.Key.GetPrice());
                    }

                    var fAirliner =
                        new FleetAirliner(
                            leaseAircraft ? FleetAirliner.PurchasedType.Leased : FleetAirliner.PurchasedType.Bought,
                            GameObject.GetInstance().GameTime,
                            airline,
                            airliner.Value.Key,
                            airportHomeBase) {Status = FleetAirliner.AirlinerStatus.ToRouteStart};
                    fAirliner.AddRoute(route);
                    AirlinerHelpers.CreateAirlinerClasses(fAirliner.Airliner);
                    AirlineHelpers.HireAirlinerPilots(fAirliner);

                    airline.AddAirliner(fAirliner);

                    airline.AddRoute(route);
                    if (route != null)
                    {
                        route.LastUpdated = GameObject.GetInstance().GameTime;

                        if (route.Type == Route.RouteType.Passenger || route.Type == Route.RouteType.Mixed)
                        {
                            AIHelpers.CreateRouteTimeTable(route, fAirliner);
                        }
                        if (route.Type == Route.RouteType.Cargo)
                        {
                            AIHelpers.CreateCargoRouteTimeTable(route, fAirliner);
                        }
                    }
                }
            }
        }
        //returns the fuel expenses for an airliner
        public static double GetFuelExpenses(FleetAirliner airliner, double distance)
        {
            Airport departureAirport = airliner.CurrentFlight.GetDepartureAirport();

            double fuelPrice = AirportHelpers.GetFuelPrice(departureAirport);

            if (airliner.CurrentFlight.IsPassengerFlight())
            {
                int pax = airliner.CurrentFlight.GetTotalPassengers();

                double basePrice = fuelPrice*distance*((AirlinerPassengerType) airliner.Airliner.Type).MaxSeatingCapacity*airliner.Airliner.FuelConsumption*0.55;
                double paxPrice = fuelPrice*distance*airliner.Airliner.FuelConsumption*airliner.CurrentFlight.GetTotalPassengers()*0.45;
                double seatsPrice =
                    airliner.CurrentFlight.Classes.Sum(c => (airliner.Airliner.GetAirlinerClass(c.AirlinerClass.Type).GetFacility(AirlinerFacility.FacilityType.Seat).SeatUses - 1)*c.Passengers);
                return basePrice + paxPrice + seatsPrice;
            }
            else
            {
                double basePrice = fuelPrice*distance*((AirlinerCargoType) airliner.Airliner.Type).CargoSize*airliner.Airliner.FuelConsumption*0.55;
                double cargoPrice = fuelPrice*airliner.Airliner.FuelConsumption*airliner.CurrentFlight.Cargo*distance*0.45;

                return basePrice + cargoPrice;
            }
        }