Inheritance: BaseModel
        public ScenarioObject(Scenario scenario)
        {
            Scenario = scenario;
            IsSuccess = false;
            _failures = new List<ScenarioFailureObject>();

            foreach (ScenarioFailure failure in Scenario.Failures)
            {
                _failures.Add(new ScenarioFailureObject(failure));
            }
        }
Example #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);
            }
        }
 private static void SetupScenarioPassengerDemand(Scenario scenario)
 {
     foreach (ScenarioPassengerDemand demand in scenario.PassengerDemands)
     {
         if (demand.Airport != null)
         {
             PassengerHelpers.ChangePaxDemand(demand.Factor);
         }
         if (demand.Country != null)
         {
             ScenarioPassengerDemand demand1 = demand;
             PassengerHelpers.ChangePaxDemand(
                 Airports.GetAllAirports(a => a.Profile.Country == demand1.Country),
                 demand.Factor);
         }
     }
 }
        private static void SetupScenarioAirlines(Scenario scenario)
        {
            var airlines = new List<Airline> {scenario.Airline};

            foreach (ScenarioAirline airline in scenario.OpponentAirlines)
            {
                airlines.Add(airline.Airline);
                SetupOpponentAirline(airline);
            }

            Airlines.Clear();

            airlines.ForEach(Airlines.AddAirline);

            SetupHumanAirline(scenario);
        }
        //sets up the passenger demand for a scenario
        //sets up the human airline
        private static void SetupHumanAirline(Scenario scenario)
        {
            foreach (Airport destination in scenario.Destinations)
            {
                SetupScenarioAirport(GameObject.GetInstance().HumanAirline, destination);
            }

            foreach (var fleetAirliner in scenario.Fleet)
            {
                for (int i = 0; i < fleetAirliner.Value; i++)
                {
                    GameObject.GetInstance()
                              .HumanAirline.AddAirliner(
                                  AirlineHelpers.CreateAirliner(GameObject.GetInstance().HumanAirline, fleetAirliner.Key));
                }
            }
            foreach (ScenarioAirlineRoute route in scenario.Routes)
            {
                SetupScenarioRoute(route, GameObject.GetInstance().HumanAirline);
            }
        }
        public static void SetupScenario(Scenario scenario)
        {
            Airline airline = scenario.Airline;

            GameObject.GetInstance().DayRoundEnabled = true;
            GameObject.GetInstance().TimeZone = scenario.Homebase.Profile.TimeZone;
            GameObject.GetInstance().Difficulty = scenario.Difficulty;
            GameObject.GetInstance().GameTime = new DateTime(scenario.StartYear, 1, 1);
            GameObject.GetInstance().StartDate = GameObject.GetInstance().GameTime;
            //sets the fuel price
            GameObject.GetInstance().FuelPrice =
                Inflations.GetInflation(GameObject.GetInstance().GameTime.Year).FuelPrice;

            GameObject.GetInstance().SetHumanAirline(airline);
            GameObject.GetInstance().MainAirline = GameObject.GetInstance().HumanAirline;
            //GameObject.GetInstance().HumanAirline.Money = scenario.StartCash;

            GameObject.GetInstance().Scenario = new ScenarioObject(scenario);

            Airport airport = scenario.Homebase;

            SetupScenarioAirport(airline, airport);

            // PassengerHelpers.CreateDestinationPassengers();

            AirlinerHelpers.CreateStartUpAirliners();

            int pilotsPool = 100*Airlines.GetAllAirlines().Count;

            GeneralHelpers.CreatePilots(pilotsPool);

            int instructorsPool = 75*Airlines.GetAllAirlines().Count;

            GeneralHelpers.CreateInstructors(instructorsPool);

            SetupScenarioAirlines(scenario);
            SetupScenario();
            Setup.SetupAlliances();

            PassengerHelpers.CreateAirlineDestinationDemand();

            GeneralHelpers.CreateHolidays(GameObject.GetInstance().GameTime.Year);
            GameObjectWorker.GetInstance().Start();

            PageNavigator.NavigateTo(new PageAirline(GameObject.GetInstance().HumanAirline));

            PageNavigator.ClearNavigator();

            // GameObject.GetInstance().HumanAirline.Money = 1000000000;

            GameObject.GetInstance()
                      .NewsBox.AddNews(
                          new News(
                              News.NewsType.StandardNews,
                              GameObject.GetInstance().GameTime,
                              Translator.GetInstance().GetString("News", "1001"),
                              string.Format(
                                  Translator.GetInstance().GetString("News", "1001", "message"),
                                  GameObject.GetInstance().HumanAirline.Profile.CEO,
                                  GameObject.GetInstance().HumanAirline.Profile.IATACode)));

            Action<object> action = obj =>
                {
                    PassengerHelpers.CreateDestinationDemand();

                    SetupScenarioPassengerDemand(scenario);
                };

            Task t2 = Task.Factory.StartNew(action, "passengers");
        }
 public static void AddScenario(Scenario scenario)
 {
     scenarios.Add(scenario);
 }
 private void cbScenario_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     this.Scenario = (Scenario)((ComboBox)sender).SelectedItem;
     this.DataContext = this.Scenario;
 }