public static double GetFlightCargo(Airport airportCurrent, Airport airportDestination, FleetAirliner airliner) { double destinationFacilityFactor = airportDestination.GetAirportFacility( GameObject.GetInstance().HumanAirline, AirportFacility.FacilityType.Cargo, true).ServiceLevel; double distance = MathHelpers.GetDistance(airportCurrent, airportDestination); double capacity = 0; var type = airliner.Airliner.Type as AirlinerCargoType; if (type != null) capacity = type.CargoSize; var combiType = airliner.Airliner.Type as AirlinerCombiType; if (combiType != null) capacity = combiType.CargoSize; double demand = airportCurrent.GetDestinationCargoRate(airportDestination) *(destinationFacilityFactor/100); double cargoDemand = demand*1000; 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.Cargo || 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.Cargo) .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; cargoDemand = cargoDemand/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.Type as AirlinerCombiType)?.CargoSize ?? ((AirlinerCargoType) a.Airliner.Type).CargoSize)); //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 = cargoDemand > totalCapacity ? 1 : cargoDemand/totalCapacity; double basicCargoPrice = GetCargoPrice(airportCurrent, airportDestination); double cargoPrice = airliner.CurrentFlight.GetCargoPrice(); double priceDiff = basicCargoPrice/cargoPrice; double cargoPriceDiff = priceDiff < 0.75 ? priceDiff : 1; cargoPriceDiff *= GameObject.GetInstance().Difficulty.PriceLevel; double randomCargo = Convert.ToDouble(Rnd.Next(97, 103))/100; var cargo = (int) Math.Min(capacity, (capacity*capacityPercent*randomCargo*cargoPriceDiff)); return cargo; }
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)); } }