//adds an opponent airline to the scenario
 public void addOpponentAirline(ScenarioAirline airline)
 {
     this.OpponentAirlines.Add(airline);
 }
Example #2
0
        private static void LoadScenario(string filename)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(filename);
            XmlElement element = doc.DocumentElement;

            try
            {
                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);

                string description = element.SelectSingleNode("intro").Attributes["text"].Value;
                string successText = element.SelectSingleNode("success").Attributes["text"].Value;

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

                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);

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

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

                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");

                foreach (XmlElement destinationElement in destinationsList)
                    scenario.addDestination(Airports.GetAirport(destinationElement.Attributes["airport"].Value));

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

                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");

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

                    ScenarioAirline scenarioAirline = new ScenarioAirline(aiAirline, aiHomebase);

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

                    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");

                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);

                    DateTime 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;
                    ScenarioFailure.FailureType 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;

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

                    scenario.addScenarioFailure(failure);
                }
            }
            catch (Exception e)
            {

                string s = e.ToString();
            }
        }
Example #3
0
        //sets up an opponent airline
        private static void SetupOpponentAirline(ScenarioAirline airline)
        {
            AirportHelpers.RentGates(airline.Homebase, airline.Airline);

            AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1);
            AirportFacility facility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.Service).Find((delegate(AirportFacility f) { return 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);
            }
        }
Example #4
0
 //adds an opponent airline to the scenario
 public void addOpponentAirline(ScenarioAirline airline)
 {
     this.OpponentAirlines.Add(airline);
 }