コード例 #1
0
        private static void SetupOpponentAirline(ScenarioAirline airline)
        {
            AirportHelpers.RentGates(airline.Homebase, airline.Airline, AirportContract.ContractType.Full,
                                     airline.Airline.AirlineRouteFocus == Route.RouteType.Cargo ? Terminal.TerminalType.Cargo : Terminal.TerminalType.Passenger);

            AirportFacility checkinFacility =
                AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1);
            AirportFacility facility =
                AirportFacilities.GetFacilities(AirportFacility.FacilityType.Service)
                                 .Find((f => f.TypeLevel == 1));

            airline.Homebase.AddAirportFacility(airline.Airline, facility, GameObject.GetInstance().GameTime);
            airline.Homebase.AddAirportFacility(airline.Airline, checkinFacility, GameObject.GetInstance().GameTime);

            foreach (ScenarioAirlineRoute saroute in airline.Routes)
            {
                SetupScenarioRoute(saroute, airline.Airline);
            }
        }
コード例 #2
0
        private static void LoadScenario(string filename)
        {
            var doc = new XmlDocument();
            doc.Load(filename);
            XmlElement element = doc.DocumentElement;

            try
            {
                if (element != null)
                {
                    string scenarioName = element.Attributes["name"].Value;
                    int startYear = Convert.ToInt32(element.Attributes["startYear"].Value);
                    long startCash = Convert.ToInt64(element.Attributes["startCash"].Value);
                    int endYear = Convert.ToInt32(element.Attributes["endYear"].Value);
                    DifficultyLevel difficulty = DifficultyLevels.GetDifficultyLevel(element.Attributes["difficulty"].Value);

                    var selectSingleNode = element.SelectSingleNode("intro");
                    if (selectSingleNode?.Attributes != null)
                    {
                        string description = selectSingleNode.Attributes["text"].Value;
                        var singleNode = element.SelectSingleNode("success");
                        if (singleNode?.Attributes != null)
                        {
                            string successText = singleNode.Attributes["text"].Value;
                        }

                        var startElement = (XmlElement) element.SelectSingleNode("start");

                        if (startElement != null)
                        {
                            Airline startAirline = Airlines.GetAirline(startElement.Attributes["airline"].Value);
                            Airport homebase = Airports.GetAirport(startElement.Attributes["homeBase"].Value);

                            if (startElement.HasAttribute("license"))
                            {
                                startAirline.License =
                                    (Airline.AirlineLicense)
                                        Enum.Parse(typeof (Airline.AirlineLicense), startElement.Attributes["license"].Value);
                            }

                            var scenario = new Scenario(
                                scenarioName,
                                description,
                                startAirline,
                                homebase,
                                startYear,
                                endYear,
                                startCash,
                                difficulty);
                            Scenarios.AddScenario(scenario);

                            XmlNodeList humanRoutesList = startElement.SelectNodes("routes/route");

                            if (humanRoutesList != null)
                                foreach (XmlElement humanRouteElement in humanRoutesList)
                                {
                                    Airport routeDestination1 = Airports.GetAirport(humanRouteElement.Attributes["departure"].Value);
                                    Airport routeDestination2 = Airports.GetAirport(humanRouteElement.Attributes["destination"].Value);
                                    AirlinerType routeAirlinerType =
                                        AirlinerTypes.GetType(humanRouteElement.Attributes["airliner"].Value);
                                    int routeQuantity = Convert.ToInt32(humanRouteElement.Attributes["quantity"].Value);

                                    scenario.AddRoute(
                                        new ScenarioAirlineRoute(routeDestination1, routeDestination2, routeAirlinerType, routeQuantity));
                                }

                            XmlNodeList destinationsList = startElement.SelectNodes("destinations/destination");

                            if (destinationsList != null)
                                foreach (XmlElement destinationElement in destinationsList)
                                {
                                    scenario.AddDestination(Airports.GetAirport(destinationElement.Attributes["airport"].Value));
                                }

                            XmlNodeList fleetList = startElement.SelectNodes("fleet/aircraft");

                            if (fleetList != null)
                                foreach (XmlElement fleetElement in fleetList)
                                {
                                    AirlinerType fleetAirlinerType = AirlinerTypes.GetType(fleetElement.Attributes["name"].Value);

                                    int fleetQuantity = Convert.ToInt32(fleetElement.Attributes["quantity"].Value);

                                    scenario.AddFleet(fleetAirlinerType, fleetQuantity);
                                }

                            XmlNodeList aiNodeList = startElement.SelectNodes("AI/airline");

                            if (aiNodeList != null)
                                foreach (XmlElement aiElement in aiNodeList)
                                {
                                    Airline aiAirline = Airlines.GetAirline(aiElement.Attributes["name"].Value, startYear);
                                    Airport aiHomebase = Airports.GetAirport(aiElement.Attributes["homeBase"].Value);

                                    var scenarioAirline = new ScenarioAirline(aiAirline, aiHomebase);

                                    XmlNodeList aiRoutesList = aiElement.SelectNodes("route");

                                    if (aiRoutesList != null)
                                        foreach (XmlElement aiRouteElement in aiRoutesList)
                                        {
                                            Airport aiRouteDestination1 = Airports.GetAirport(aiRouteElement.Attributes["departure"].Value);
                                            Airport aiRouteDestination2 = Airports.GetAirport(
                                                aiRouteElement.Attributes["destination"].Value);
                                            AirlinerType routeAirlinerType =
                                                AirlinerTypes.GetType(aiRouteElement.Attributes["airliner"].Value);
                                            int routeQuantity = Convert.ToInt32(aiRouteElement.Attributes["quantity"].Value);

                                            scenarioAirline.AddRoute(
                                                new ScenarioAirlineRoute(
                                                    aiRouteDestination1,
                                                    aiRouteDestination2,
                                                    routeAirlinerType,
                                                    routeQuantity));
                                        }

                                    scenario.AddOpponentAirline(scenarioAirline);
                                }

                            XmlNodeList modifiersList = element.SelectNodes("modifiers/paxDemand");

                            if (modifiersList != null)
                                foreach (XmlElement paxElement in modifiersList)
                                {
                                    Country country = null;
                                    Airport airport = null;

                                    if (paxElement.HasAttribute("country"))
                                    {
                                        country = Countries.GetCountry(paxElement.Attributes["country"].Value);
                                    }

                                    if (paxElement.HasAttribute("airport"))
                                    {
                                        airport = Airports.GetAirport(paxElement.Attributes["airport"].Value);
                                    }

                                    double factor = Convert.ToDouble(
                                        paxElement.Attributes["change"].Value,
                                        CultureInfo.GetCultureInfo("en-US").NumberFormat);

                                    var enddate =
                                        new DateTime(scenario.StartYear + Convert.ToInt32(paxElement.Attributes["length"].Value), 1, 1);

                                    scenario.AddPassengerDemand(new ScenarioPassengerDemand(factor, enddate, country, airport));
                                }

                            XmlNodeList parametersList = element.SelectNodes("parameters/failure");

                            foreach (XmlElement parameterElement in parametersList)
                            {
                                string id = parameterElement.Attributes["id"].Value;
                                var failureType =
                                    (ScenarioFailure.FailureType)
                                        Enum.Parse(typeof (ScenarioFailure.FailureType), parameterElement.Attributes["type"].Value);
                                object failureValue = parameterElement.Attributes["value"].Value;
                                double checkMonths = parameterElement.HasAttribute("at")
                                    ? 12
                                      *Convert.ToDouble(
                                          parameterElement.Attributes["at"].Value,
                                          CultureInfo.GetCultureInfo("en-US").NumberFormat)
                                    : 1;
                                string failureText = parameterElement.Attributes["text"].Value;
                                double monthsOfFailure = parameterElement.HasAttribute("for")
                                    ? 12
                                      *Convert.ToDouble(
                                          parameterElement.Attributes["for"].Value,
                                          CultureInfo.GetCultureInfo("en-US").NumberFormat)
                                    : 1;

                                var failure = new ScenarioFailure(
                                    id,
                                    failureType,
                                    (int) checkMonths,
                                    failureValue,
                                    failureText,
                                    (int) monthsOfFailure);

                                scenario.AddScenarioFailure(failure);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("Error loading scenario", e);
            }
        }
コード例 #3
0
 //adds an opponent airline to the scenario
 public void AddOpponentAirline(ScenarioAirline airline)
 {
     OpponentAirlines.Add(airline);
 }