Пример #1
0
        //adds another month for where the scenario parameter has not been fulfilled and returns if failing scenario
        private static Boolean UpdateFailureValue(ScenarioObject scenario, ScenarioFailure failure)
        {
            ScenarioFailureObject failureObject = scenario.getScenarioFailure(failure);
            int monthsSinceLastFailure = MathHelpers.GetMonthsBetween(failureObject.LastFailureTime,GameObject.GetInstance().GameTime);

            if (monthsSinceLastFailure == 1)
                failureObject.Failures++;
            else
                failureObject.Failures = 1;

            failureObject.LastFailureTime = GameObject.GetInstance().GameTime;

            return failureObject.Failures == failure.MonthsOfFailure;
        }
Пример #2
0
 //adds a failure to the scenario
 public void addScenarioFailure(ScenarioFailure failure)
 {
     this.Failures.Add(failure);
 }
Пример #3
0
 //returns a scenario failure object
 public ScenarioFailureObject getScenarioFailure(ScenarioFailure failure)
 {
     return this.Failures.Find(f => f.Failure == failure);
 }
Пример #4
0
 //ends a scenario
 private static void EndScenario(ScenarioFailure failure)
 {
     GameObject.GetInstance().Scenario.ScenarioFailed = failure;
 }
Пример #5
0
 public ScenarioFailureObject(ScenarioFailure failure)
 {
     this.Failure = failure;
     this.Failures = 0;
 }
Пример #6
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();
            }
        }
Пример #7
0
 //adds a failure to the scenario
 public void addScenarioFailure(ScenarioFailure failure)
 {
     this.Failures.Add(failure);
 }
Пример #8
0
 //returns a scenario failure object
 public ScenarioFailureObject getScenarioFailure(ScenarioFailure failure)
 {
     return(this.Failures.Find(f => f.Failure == failure));
 }
Пример #9
0
 public ScenarioFailureObject(ScenarioFailure failure)
 {
     this.Failure  = failure;
     this.Failures = 0;
 }