Inheritance: BaseModel
        //sets the airport expansion to an airport
        public static void SetAirportExpansion(Airport airport, AirportExpansion expansion, bool onStartUp = false)
        {
            if (expansion.Type == AirportExpansion.ExpansionType.Name)
            {
                if (expansion.NotifyOnChange && !onStartUp)
                {
                    GameObject.GetInstance()
                              .NewsBox.AddNews(
                                  new News(
                                      News.NewsType.AirportNews,
                                      GameObject.GetInstance().GameTime,
                                      "Airport Name Changed",
                                      $"[LI airport={airport.Profile.IATACode}]({new AirportCodeConverter().Convert(airport)}) has changed its name to {expansion.Name}"));
                }

                airport.Profile.Name = expansion.Name;
            }
            if (expansion.Type == AirportExpansion.ExpansionType.NewRunway)
            {
                var runway = new Runway(expansion.Name, expansion.Length, Runway.RunwayType.Regular, expansion.Surface, expansion.Date, true);
                airport.Runways.Add(runway);

                if (expansion.NotifyOnChange && !onStartUp)
                {
                    GameObject.GetInstance()
                              .NewsBox.AddNews(
                                  new News(
                                      News.NewsType.AirportNews,
                                      GameObject.GetInstance().GameTime,
                                      "New Runway",
                                      $"[LI airport={airport.Profile.IATACode}]({new AirportCodeConverter().Convert(airport)}) has created a new runway"));
                }
            }
            if (expansion.Type == AirportExpansion.ExpansionType.RunwayLength)
            {
                Runway runway = airport.Runways.FirstOrDefault(r => r.Name == expansion.Name);

                if (runway != null)
                {
                    if (expansion.NotifyOnChange && !onStartUp)
                    {
                        GameObject.GetInstance()
                                  .NewsBox.AddNews(
                                      new News(
                                          News.NewsType.AirportNews,
                                          GameObject.GetInstance().GameTime,
                                          "New Terminal",
                                          $"[LI airport={airport.Profile.IATACode}]({new AirportCodeConverter().Convert(airport)}) has changed the length of the runway {expansion.Name} to {new SmallDistanceToUnitConverter().Convert(expansion.Length, null, null, null)}"));
                    }
                }
            }
            if (expansion.Type == AirportExpansion.ExpansionType.NewTerminal)
            {
                var terminal = new Terminal(airport, expansion.Name, expansion.Gates, expansion.Date, expansion.TerminalType);
                airport.AddTerminal(terminal);

                if (expansion.NotifyOnChange && !onStartUp)
                {
                    GameObject.GetInstance()
                              .NewsBox.AddNews(
                                  new News(
                                      News.NewsType.AirportNews,
                                      GameObject.GetInstance().GameTime,
                                      "New Terminal",
                                      $"[LI airport={airport.Profile.IATACode}]({new AirportCodeConverter().Convert(airport)}) has created a new terminal with {expansion.Gates} gates"));
                }
            }
            if (expansion.Type == AirportExpansion.ExpansionType.ExtraGates)
            {
                Terminal terminal = airport.Terminals.AirportTerminals.FirstOrDefault(t => t.Name == expansion.Name);

                if (terminal != null)
                {
                    for (int i = 0; i < expansion.Gates; i++)
                        terminal.Gates.AddGate(new Gate(expansion.Date));

                    if (expansion.NotifyOnChange && !onStartUp)
                    {
                        GameObject.GetInstance()
                                  .NewsBox.AddNews(
                                      new News(
                                          News.NewsType.AirportNews,
                                          GameObject.GetInstance().GameTime,
                                          "New Gates at Airport",
                                          $"[LI airport={airport.Profile.IATACode}]({new AirportCodeConverter().Convert(airport)}) has created {expansion.Gates} gates in {expansion.Name}"));
                    }
                }
            }
            if (expansion.Type == AirportExpansion.ExpansionType.CloseTerminal)
            {
                Terminal terminal = airport.Terminals.AirportTerminals.FirstOrDefault(t => t.Name == expansion.Name);

                if (terminal != null)
                {
                    airport.RemoveTerminal(terminal);

                    if (expansion.NotifyOnChange && !onStartUp)
                    {
                        GameObject.GetInstance()
                                  .NewsBox.AddNews(
                                      new News(
                                          News.NewsType.AirportNews,
                                          GameObject.GetInstance().GameTime,
                                          "Closed Terminal",
                                          $"[LI airport={airport.Profile.IATACode}]({new AirportCodeConverter().Convert(airport)}) has closed its terminal {expansion.Name}"));
                    }
                }
            }
            //close terminal
        }
Beispiel #2
0
        /*! sets up the statistics types.
         */
        private static void SetupMainGame()
        {
            CreatePilots();

            //creates the facilities for pilot training
            IEnumerable<string> aircraftFamilies =
                AirlinerTypes.GetTypes(
                    t =>
                    t.Produced.From.Year < GameObject.GetInstance().GameTime.Year
                    && t.Produced.To > GameObject.GetInstance().GameTime.AddYears(-30))
                             .Select(a => a.AirlinerFamily)
                             .Distinct();

            foreach (string family in aircraftFamilies)
            {
                AirlineFacilities.AddFacility(
                    new PilotTrainingFacility(
                        "airlinefacilities",
                        family,
                        9000,
                        1000,
                        GameObject.GetInstance().GameTime.Year,
                        0,
                        0,
                        family));
            }

            //sets all the facilities at an airport to none for all airlines
            Parallel.ForEach(
                Airports.GetAllAirports(),
                airport =>
                    {
                        foreach (Airline airline in Airlines.GetAllAirlines())
                        {
                            foreach (
                                AirportFacility.FacilityType type in Enum.GetValues(typeof (AirportFacility.FacilityType)))
                            {
                                AirportFacility noneFacility =
                                    AirportFacilities.GetFacilities(type)
                                                     .Find((facility => facility.TypeLevel == 0));

                                airport.AddAirportFacility(airline, noneFacility, GameObject.GetInstance().GameTime);
                            }
                        }
                        if (airport.Profile.Size == GeneralHelpers.Size.Largest
                            || airport.Profile.Size == GeneralHelpers.Size.VeryLarge
                            || airport.Profile.Size == GeneralHelpers.Size.Large)
                        {
                            if (!airport.Runways.Exists(r => r.Type == Runway.RunwayType.Helipad))
                            {
                                var helipad = new Runway("H1", Rnd.Next(17, 25), Runway.RunwayType.Helipad, Runway.SurfaceType.Concrete, GameObject.GetInstance().GameTime, true);

                                airport.Runways.Add(helipad);
                            }
                        }
                        if (airport.Profile.Cargo == GeneralHelpers.Size.VeryLarge
                            || airport.Profile.Cargo == GeneralHelpers.Size.Largest
                            || airport.Profile.Size == GeneralHelpers.Size.Largest
                            || airport.Profile.Size == GeneralHelpers.Size.VeryLarge)
                        {
                            AirportFacility cargoTerminal =
                                AirportFacilities.GetFacilities(AirportFacility.FacilityType.Cargo)
                                                 .Find(f => f.TypeLevel > 0);

                            airport.AddAirportFacility(null, cargoTerminal, GameObject.GetInstance().GameTime);

                            if (!airport.Terminals.AirportTerminals.Exists(t => t.Type == Terminal.TerminalType.Cargo))
                            {
                                airport.Terminals.AddTerminal(new Terminal(airport, "Cargo Terminal", ((int) airport.Profile.Cargo) + 5, GameObject.GetInstance().GameTime, Terminal.TerminalType.Cargo));
                            }
                        }

                        AirportHelpers.CreateAirportWeather(airport);

                        //creates the already existing expansions
                        IEnumerable<AirportExpansion> expansions = airport.Profile.Expansions.Where(e => GameObject.GetInstance().GameTime > e.Date);

                        foreach (AirportExpansion expansion in expansions)
                            AirportHelpers.SetAirportExpansion(airport, expansion, true);
                    });

            foreach (Airline airline in Airlines.GetAllAirlines())
            {
                airline.Money = GameObject.GetInstance().StartMoney;

                if (airline.IsHuman)
                {
                    GameObject.GetInstance().HumanMoney = airline.Money;
                }

                airline.StartMoney = airline.Money;
                airline.Fees = new AirlineFees();
                airline.AddAirlinePolicy(new AirlinePolicy("Cancellation Minutes", 150));

                AirlineHelpers.CreateStandardAirlineShares(airline);

                if (!airline.IsHuman)
                {
                    airline.Profile.Country = airline.Profile.Countries[Rnd.Next(airline.Profile.Countries.Count)];

                    CreateComputerRoutes(airline);
                }
            }

            /*
            Airports.GetAirport("BOS").Terminals.rentGate(GameObject.GetInstance().HumanAirline);
            Airports.GetAirport("AAR").Terminals.rentGate(GameObject.GetInstance().HumanAirline);
            Airports.GetAirport("CPH").Terminals.rentGate(GameObject.GetInstance().HumanAirline);
            Airports.GetAirport("CPH").Terminals.rentGate(GameObject.GetInstance().HumanAirline);
            Airports.GetAirport("SBY").Terminals.rentGate(GameObject.GetInstance().HumanAirline);

            Airliner airliner = Airliners.GetAirlinersForSale(a => a.Type.Name == "Boeing 737-900ER").First();
            AirlineHelpers.BuyAirliner(GameObject.GetInstance().HumanAirline, airliner, GameObject.GetInstance().HumanAirline.Airports[0]);
            */
            SetupAlliances();
            SetupMergers();
        }
        public static void CheckForExtendRunway(Airport airport)
        {
            bool isOnlyHeliport = !airport.Runways.Exists(r => r.Type == Runway.RunwayType.Regular);

            if (!isOnlyHeliport)
            {
                const int minYearsBetweenExpansions = 5;

                long maxRunwayLenght = (from r in airport.Runways select r.Length).Max();
                long longestRequiredRunwayLenght =
                    AirlinerTypes.GetTypes(
                        a =>
                        a.Produced.From <= GameObject.GetInstance().GameTime
                        && a.Produced.To >= GameObject.GetInstance().GameTime).Max(a => a.MinRunwaylength);

                List<Route> airportRoutes = GetAirportRoutes(airport);
                IEnumerable<FleetAirliner> routeAirliners = airportRoutes.SelectMany(r => r.GetAirliners());

                var fleetAirliners = routeAirliners as FleetAirliner[] ?? routeAirliners.ToArray();
                long longestRunwayInUse = fleetAirliners.Any()
                                              ? fleetAirliners.Max(a => a.Airliner.MinRunwaylength)
                                              : 0;

                if (maxRunwayLenght < longestRequiredRunwayLenght/2 && maxRunwayLenght < longestRunwayInUse*3/4
                    && GameObject.GetInstance().GameTime.AddYears(-minYearsBetweenExpansions) > airport.LastExpansionDate)
                {
                    List<string> runwayNames =
                        (from r in Airports.GetAllAirports().SelectMany(a => a.Runways) select r.Name).Distinct().ToList();

                    foreach (Runway r in airport.Runways)
                    {
                        runwayNames.Remove(r.Name);
                    }

                    Runway.SurfaceType surface = airport.Runways[0].Surface;
                    long length = Math.Min(longestRequiredRunwayLenght*3/4, longestRunwayInUse*2);

                    var runway = new Runway(
                        runwayNames[Rnd.Next(runwayNames.Count)],
                        length,
                        Runway.RunwayType.Regular,
                        surface,
                        GameObject.GetInstance().GameTime.AddDays(90),
                        false);
                    airport.Runways.Add(runway);

                    airport.LastExpansionDate = GameObject.GetInstance().GameTime;
                }
            }
        }