GetHubs() публичный Метод

public GetHubs ( ) : List
Результат List
        //returns if an airline can create a hub at an airport
        public static bool CanCreateHub(Airline airline, Airport airport, HubType type)
        {
            Terminal.TerminalType terminaltype = airline.AirlineRouteFocus == Route.RouteType.Cargo ? Terminal.TerminalType.Cargo : Terminal.TerminalType.Passenger;

            bool airlineHub = airport.GetHubs().Exists(h => h.Airline == airline);

            int airlineValue = (int) airline.GetAirlineValue() + 1;

            int totalAirlineHubs = airline.GetHubs().Count; // 'Airports.GetAllActiveAirports().Sum(a => a.Hubs.Count(h => h.Airline == airline));
            double airlineGatesPercent = Convert.ToDouble(airport.Terminals.GetNumberOfGates(airline))/Convert.ToDouble(airport.Terminals.GetNumberOfGates(terminaltype))*100;

            switch (type.Type)
            {
                case HubType.TypeOfHub.FocusCity:
                    return !airlineHub && airline.Money > AirportHelpers.GetHubPrice(airport, type);
                case HubType.TypeOfHub.RegionalHub:
                    return !airlineHub && airline.Money > AirportHelpers.GetHubPrice(airport, type) &&
                           (airport.Profile.Size == GeneralHelpers.Size.Large || airport.Profile.Size == GeneralHelpers.Size.Medium) && airport.GetHubs().Count < 7;
                case HubType.TypeOfHub.FortressHub:
                    return !airlineHub && airline.Money > AirportHelpers.GetHubPrice(airport, type) && (airport.Profile.Size > GeneralHelpers.Size.Medium) && airlineGatesPercent > 70 &&
                           (totalAirlineHubs < airlineValue);
                case HubType.TypeOfHub.Hub:
                    return !airlineHub && airline.Money > AirportHelpers.GetHubPrice(airport, type) && (airlineGatesPercent > 20) && (totalAirlineHubs < airlineValue) &&
                           (airport.GetHubs(HubType.TypeOfHub.Hub).Count < (int) airport.Profile.Size);
            }

            return false;
        }
        public static int GetFlightPassengers(
            Airport airportCurrent,
            Airport airportDestination,
            FleetAirliner airliner,
            AirlinerClass.ClassType type)
        {
            double distance = MathHelpers.GetDistance(airportCurrent, airportDestination);

            Route currentRoute =
                airliner.Routes.Find(
                    r =>
                    r.Stopovers.SelectMany(s => s.Legs)
                     .ToList()
                     .Exists(
                         l =>
                         (l.Destination1 == airportCurrent || l.Destination1 == airportDestination)
                         && (l.Destination2 == airportDestination || l.Destination2 == airportCurrent))
                    || (r.Destination1 == airportCurrent || r.Destination1 == airportDestination)
                    && (r.Destination2 == airportDestination || r.Destination2 == airportCurrent));

            if (currentRoute == null)
            {
                return 0;
            }

            //double basicPrice = GetPassengerPrice(currentRoute.Destination1, currentRoute.Destination2, type);
            //double routePrice = ((PassengerRoute)currentRoute).getFarePrice(type);

            //double priceDiff = basicPrice / routePrice;

            double routeScoreFactor = RouteHelpers.GetRouteTotalScore(currentRoute)/5;

            double demand = airportCurrent.GetDestinationPassengersRate(airportDestination, type);

            double passengerDemand = (demand
                                      + GetFlightConnectionPassengers(
                                          airportCurrent,
                                          airportDestination,
                                          airliner,
                                          type)
                                      + GetNearbyPassengerDemand(airportCurrent, airportDestination, airliner, type))
                                     *GetSeasonFactor(airportDestination)*GetHolidayFactor(airportDestination)
                                     *GetHolidayFactor(airportCurrent);

            passengerDemand *= GameObject.GetInstance().Difficulty.PassengersLevel;
            passengerDemand *= routeScoreFactor;

            if (airliner.Airliner.Airline.MarketFocus == AirlineFocus.Global && distance > 3000
                && airportCurrent.Profile.Country != airportDestination.Profile.Country)
            {
                passengerDemand = passengerDemand*(115/100);
            }

            if (airliner.Airliner.Airline.MarketFocus == AirlineFocus.Regional && distance < 1500)
            {
                passengerDemand = passengerDemand*(115/100);
            }

            if (airliner.Airliner.Airline.MarketFocus == AirlineFocus.Domestic && distance < 1500
                && airportDestination.Profile.Country == airportCurrent.Profile.Country)
            {
                passengerDemand = passengerDemand*(115/100);
            }

            if (airliner.Airliner.Airline.MarketFocus == AirlineFocus.Local && distance < 1000)
            {
                passengerDemand = passengerDemand*(115/100);
            }

            Hub hub = airportDestination.GetHubs().Find(h => h.Airline == airliner.Airliner.Airline);

            if (hub != null)
            {
                switch (hub.Type.Type)
                {
                    case HubType.TypeOfHub.FocusCity:
                        if (airportDestination.Profile.Country == airportCurrent.Profile.Country)
                        {
                            passengerDemand = passengerDemand*1.15;
                        }
                        break;

                    case HubType.TypeOfHub.RegionalHub:
                        if (airportDestination.Profile.Country.Region == airportCurrent.Profile.Country.Region)
                        {
                            passengerDemand = passengerDemand*1.20;
                        }
                        break;

                    case HubType.TypeOfHub.Hub:
                        passengerDemand = passengerDemand*1.20;
                        break;

                    case HubType.TypeOfHub.FortressHub:
                        passengerDemand = passengerDemand*1.30;
                        break;
                }
            }

            var routes = new List<Route>();

            foreach (Airline airline in Airlines.GetAllAirlines())
            {
                var aRoutes = new List<Route>(airline.Routes);

                routes.AddRange(
                    aRoutes.Where(r => r.Type == Route.RouteType.Passenger || r.Type == Route.RouteType.Mixed)
                           .Where(
                               r =>
                               (r.HasAirliner)
                               && (r.Destination1 == airportCurrent || r.Destination1 == airportDestination)
                               && (r.Destination2 == airportDestination || r.Destination2 == airportCurrent)));
                routes.AddRange(
                    aRoutes.Where(r => r.Type == Route.RouteType.Mixed || r.Type == Route.RouteType.Passenger)
                           .Where(
                               r =>
                               r.Stopovers.SelectMany(
                                   s =>
                                   s.Legs.Where(
                                       l =>
                                       r.HasAirliner
                                       && (l.Destination1 == airportCurrent
                                           || l.Destination1 == airportDestination)
                                       && (l.Destination2 == airportDestination
                                           || l.Destination2 == airportCurrent))).Any()));
            }

            double flightsPerDay = Convert.ToDouble(routes.Sum(r => r.TimeTable.Entries.Count))/7;

            passengerDemand = passengerDemand/flightsPerDay;

            double totalCapacity;
            if (routes.Count > 0 && routes.Count(r => r.HasAirliner) > 0)
            {
                totalCapacity =
                    routes.Where(r => r.HasAirliner)
                          .Sum(r => r.GetAirliners().Max(a => a.Airliner.GetTotalSeatCapacity()));
                //SelectMany(r => r.Stopovers.Where(s=>s.Legs.Count >0))).Sum(s=>s.;//a => a.Routes.SelectMany(r=>r.Stopovers.SelectMany(s=>s.Legs.Where(l=>r.HasAirliner && (l.Destination1 == airportCurrent || l.Destination1 == airportDestination) && (l.Destination2 == airportDestination || l.Destination2 == airportCurrent))).Sum(r=>r.getAirliners().Max(a=>a.Airliner.getTotalSeatCapacity()));
            }
            else
            {
                totalCapacity = 0;
                // routes.Where(r => r.HasAirliner).Sum(r => r.getAirliners().Max(a => a.Airliner.getTotalSeatCapacity()));
            }

            double capacityPercent = passengerDemand > totalCapacity ? 1 : passengerDemand/totalCapacity;

            var rations = new Dictionary<Route, double>();

            foreach (Route route in routes)
            {
                double level = ((PassengerRoute) route).GetServiceLevel(type)
                               /((PassengerRoute) route).GetFarePrice(type);

                rations.Add(route, level);
            }

            double totalRatio = rations.Values.Sum();

            double routeRatioPercent = 1;

            if (rations.ContainsKey(currentRoute))
            {
                routeRatioPercent = Math.Max(1, rations[currentRoute]/Math.Max(1, totalRatio));
            }

            IDictionary<Airline, double> airlineScores = new Dictionary<Airline, double>();

            foreach (Airline airline in Airlines.GetAllAirlines())
            {
                airlineScores.Add(airline, airportCurrent.GetAirlineReputation(airline));
            }

            double reputation = StatisticsHelpers.GetRatingScale(airlineScores)[airliner.Airliner.Airline];

            if (reputation < 76)
            {
                reputation = 75;
            }

            double reputationPercent = reputation/100;

            double routePriceDiff = 1; // priceDiff < 0.75 ? priceDiff : 1;

            routePriceDiff *= GameObject.GetInstance().Difficulty.PriceLevel;

            double randomPax = Convert.ToDouble(Rnd.Next(97, 103))/100;

            var pax =
                (int)
                Math.Min(
                    airliner.Airliner.GetAirlinerClass(type).SeatingCapacity,
                    (airliner.Airliner.GetAirlinerClass(type).SeatingCapacity*routeRatioPercent
                     *reputationPercent*capacityPercent*routePriceDiff*randomPax));

            if (pax < 0)
            {
                pax = 0;
            }

            return pax;
        }
Пример #3
0
        public AirportMVVM(Airport airport)
        {
            Airport = airport;

            TerminalGatePrice = Airport.GetTerminalGatePrice();
            TerminalPrice = Airport.GetTerminalPrice();
            LandingFee = GeneralHelpers.GetInflationPrice(Airport.LandingFee);
            FuelPrice = AirportHelpers.GetFuelPrice(Airport);

            TotalPaxGates = Airport.Terminals.AirportTerminals.Where(t=>t.Type == Terminal.TerminalType.Passenger).Sum(t=>t.Gates.NumberOfDeliveredGates);
            TotalCargoGates = Airport.Terminals.AirportTerminals.Where(t=>t.Type == Terminal.TerminalType.Cargo).Sum(t=>t.Gates.NumberOfDeliveredGates);

            Cooperations = new ObservableCollection<Cooperation>();
            Terminals = new ObservableCollection<AirportTerminalMVVM>();
            BuildingTerminals = new ObservableCollection<AirportTerminalMVVM>();

            foreach (Terminal terminal in Airport.Terminals.GetTerminals())
            {
                Boolean isSellable = terminal.Airline != null
                                     && terminal.Airline == GameObject.GetInstance().HumanAirline;

                if (terminal.IsBuilt)
                {
                    Terminals.Add(new AirportTerminalMVVM(terminal, terminal.IsBuyable, isSellable));
                }
                else
                {
                    BuildingTerminals.Add(new AirportTerminalMVVM(terminal, terminal.IsBuyable, isSellable));
                }
            }
            Contracts = new ObservableCollection<ContractMVVM>();

            foreach (AirportContract contract in Airport.AirlineContracts)
            {
                Contracts.Add(new ContractMVVM(contract));
            }

            foreach (Cooperation cooperation in Airport.Cooperations)
            {
                Cooperations.Add(cooperation);
            }

            AirportHelpers.CreateAirportWeather(Airport);

            Weather = Airport.Weather.ToList();

            if (!GameObject.GetInstance().DayRoundEnabled)
            {
                CurrentWeather = Weather[0].Temperatures[GameObject.GetInstance().GameTime.Hour];
            }

            FreeGates = Airport.Terminals.NumberOfFreeGates;

            FreeCargoGates = Airport.Terminals.AirportTerminals.Where(t=>t.Type == Terminal.TerminalType.Cargo).Sum(t=>t.GetFreeGates());

            FreePaxGates = Airport.Terminals.AirportTerminals.Where(t => t.Type == Terminal.TerminalType.Passenger).Sum(t => t.GetFreeGates());

            DomesticDemands = new List<DemandMVVM>();
            IntlDemands = new List<DemandMVVM>();

            IOrderedEnumerable<Airport> demands =
                Airport.GetDestinationDemands()
                    .Where(a => a != null && GeneralHelpers.IsAirportActive(a))
                    .OrderByDescending(
                        a => Airport.GetDestinationPassengersRate(a, AirlinerClass.ClassType.EconomyClass));

            IEnumerable<Airport> internationalDemand =
                demands.Where(
                    a =>
                        new CountryCurrentCountryConverter().Convert(a.Profile.Country)
                        != new CountryCurrentCountryConverter().Convert(Airport.Profile.Country));
            IEnumerable<Airport> domesticDemand =
                demands.Where(
                    a =>
                        new CountryCurrentCountryConverter().Convert(a.Profile.Country)
                        == new CountryCurrentCountryConverter().Convert(Airport.Profile.Country));

            foreach (Airport destination in internationalDemand)
            {
                IntlDemands.Add(
                    new DemandMVVM(
                        destination,
                        Airport.GetDestinationPassengersRate(destination, AirlinerClass.ClassType.EconomyClass),
                        (int)Airport.Profile.Pax,
                        Airport.GetDestinationCargoRate(destination),MathHelpers.GetDistance(destination,Airport)));
            }

            foreach (Airport destination in domesticDemand)
            {
                DomesticDemands.Add(
                    new DemandMVVM(
                        destination,
                        Airport.GetDestinationPassengersRate(destination, AirlinerClass.ClassType.EconomyClass),
                        (int)Airport.Profile.Pax,
                        Airport.GetDestinationCargoRate(destination), MathHelpers.GetDistance(destination,Airport)));
            }

            AirportFacilities =
                Airport.GetAirportFacilities()
                    .FindAll(f => f.Airline == null && f.Facility.TypeLevel != 0)
                    .Select(f => f.Facility)
                    .Distinct()
                    .ToList();

            AirlineFacilities = new ObservableCollection<AirlineAirportFacilityMVVM>();
            BuildingAirlineFacilities = new ObservableCollection<AirlineAirportFacilityMVVM>();

            foreach (
                AirlineAirportFacility facility in Airport.GetAirportFacilities().FindAll(f => f.Airline != null))
            {
                if (facility.Facility.TypeLevel != 0)
                {
                    Alliance alliance = facility.Airline.Alliances.Count == 0 ? null : facility.Airline.Alliances[0];

                    var airlineFacility = new AirlineAirportFacilityMVVM(facility, alliance);

                    if (airlineFacility.IsDelivered)
                    {
                        if (facility == Airport.GetAirlineAirportFacility(facility.Airline, facility.Facility.Type))
                        {
                            AirlineFacilities.Add(airlineFacility);
                        }
                    }
                    else
                    {
                        BuildingAirlineFacilities.Add(airlineFacility);
                    }
                }
            }

            AirlineStatistics = new List<AirportStatisticsMVMM>();

            foreach (Airline airline in Airlines.GetAllAirlines())
            {
                StatisticsType passengersType = StatisticsTypes.GetStatisticsType("Passengers");
                StatisticsType passengersAvgType = StatisticsTypes.GetStatisticsType("Passengers%");
                StatisticsType arrivalsType = StatisticsTypes.GetStatisticsType("Arrivals");

                double passengers = Airport.Statistics.GetStatisticsValue(
                    GameObject.GetInstance().GameTime.Year,
                    airline,
                    passengersType);
                double passengersAvg = Airport.Statistics.GetStatisticsValue(
                    GameObject.GetInstance().GameTime.Year,
                    airline,
                    passengersAvgType);
                double arrivals = Airport.Statistics.GetStatisticsValue(
                    GameObject.GetInstance().GameTime.Year,
                    airline,
                    arrivalsType);

                int routes = airline.Routes.Count(r => r.Destination1 == Airport || r.Destination2 == Airport);

                AirlineStatistics.Add(
                    new AirportStatisticsMVMM(airline, passengers, passengersAvg, arrivals, routes));
            }

            Traffic = new List<AirportTrafficMVVM>();

            IOrderedEnumerable<Airport> passengerDestinations = from a in Airports.GetAllActiveAirports()
                orderby Airport.GetDestinationPassengerStatistics(a) descending
                select a;
            IOrderedEnumerable<Airport> cargoDestinations = from a in Airports.GetAllActiveAirports()
                orderby Airport.GetDestinationCargoStatistics(a) descending
                select a;

            foreach (Airport a in passengerDestinations.Take(20))
            {
                Traffic.Add(
                    new AirportTrafficMVVM(
                        a,
                        Airport.GetDestinationPassengerStatistics(a),
                        AirportTrafficMVVM.TrafficType.Passengers));
            }

            foreach (Airport a in cargoDestinations.Take(20))
            {
                Traffic.Add(
                    new AirportTrafficMVVM(
                        a,
                        Convert.ToInt64(Airport.GetDestinationCargoStatistics(a)),
                        AirportTrafficMVVM.TrafficType.Cargo));
            }

            Flights = new List<DestinationFlightsMVVM>();

            IEnumerable<Route> airportRoutes =
                AirportHelpers.GetAirportRoutes(Airport).Where(r => r.GetAirliners().Count > 0);

            foreach (Route airportRoute in airportRoutes)
            {
                double distance = MathHelpers.GetDistance(airportRoute.Destination1, airportRoute.Destination2);

                Airport destination = airportRoute.Destination1 == Airport
                    ? airportRoute.Destination2
                    : airportRoute.Destination1;
                if (Flights.Exists(f => f.Airline == airportRoute.Airline && f.Airport == destination))
                {
                    DestinationFlightsMVVM flight =
                        Flights.First(f => f.Airline == airportRoute.Airline && f.Airport == destination);

                    flight.Flights += airportRoute.TimeTable.GetEntries(destination).Count;

                    foreach (AirlinerType aircraft in airportRoute.GetAirliners().Select(a => a.Airliner.Type))
                    {
                        if (!flight.Aircrafts.Contains(aircraft))
                        {
                            flight.Aircrafts.Add(aircraft);
                        }
                    }
                }
                else
                {
                    Flights.Add(
                        new DestinationFlightsMVVM(
                            destination,
                            airportRoute.Airline,
                            distance,
                            airportRoute.GetAirliners().Select(a => a.Airliner.Type).ToList(),
                            airportRoute.TimeTable.GetEntries(destination).Count));
                }
            }
            /*
            Dictionary<Airport, int> destinations = new Dictionary<Airport, int>();
            foreach (Route route in AirportHelpers.GetAirportRoutes(this.Airport).FindAll(r => r.getAirliners().Count > 0))
            {
                if (route.Destination1 != this.Airport)
                {
                    if (!destinations.ContainsKey(route.Destination1))
                        destinations.Add(route.Destination1, 0);
                    destinations[route.Destination1] += route.TimeTable.getEntries(route.Destination1).Count;

                }
                if (route.Destination2 != this.Airport)
                {
                    if (!destinations.ContainsKey(route.Destination2))
                        destinations.Add(route.Destination2, 0);
                    destinations[route.Destination2] += route.TimeTable.getEntries(route.Destination2).Count;
                }
            }

            foreach (Airport a in destinations.Keys)
                this.Flights.Add(new DestinationFlightsMVVM(a, destinations[a]));
            */

            Hubs = new ObservableCollection<Hub>();

            foreach (Hub hub in Airport.GetHubs())
            {
                Hubs.Add(hub);
            }

            CanBuildHub = canBuildHub();
            CanMakeCooperation = GameObject.GetInstance().HumanAirline.Airports.Exists(a => a == Airport);

            LocalTime = MathHelpers.ConvertDateTimeToLoalTime(
                GameObject.GetInstance().GameTime,
                Airport.Profile.TimeZone);

            ShowLocalTime = !GameObject.GetInstance().DayRoundEnabled;

            AirlineReputations = new List<AirlineReputationMVVM>();

            IDictionary<Airline, double> airlineScores = new Dictionary<Airline, double>();

            foreach (Airline airline in Airlines.GetAllAirlines())
            {
                airlineScores.Add(airline, Airport.GetAirlineReputation(airline));
            }

            foreach (var score in StatisticsHelpers.GetRatingScale(airlineScores))
            {
                AirlineReputations.Add(new AirlineReputationMVVM(score.Key, (int)score.Value));
            }
        }