示例#1
0
        //loads a route
        private static Route LoadRoute(XmlElement routeNode, Airline airline, Route.RouteType routetype = Route.RouteType.Passenger)
        {
            string id = routeNode.Attributes["id"].Value;
            Airport dest1 = Airports.GetAirport(routeNode.Attributes["destination1"].Value);
            Airport dest2 = Airports.GetAirport(routeNode.Attributes["destination2"].Value);
            Boolean isBanned = Convert.ToBoolean(routeNode.Attributes["isbanned"].Value);

            if (routeNode.HasAttribute("type"))
                routetype = (Route.RouteType)Enum.Parse(typeof(Route.RouteType), routeNode.Attributes["type"].Value);

            Route route;

            if (routetype == Route.RouteType.Passenger || routetype == Route.RouteType.Mixed)
                route = new PassengerRoute(id, dest1, dest2, DateTime.Now,0);
            else
                route = new CargoRoute(id, dest1, dest2, DateTime.Now,0);

            route.Banned = isBanned;

            /* foreach (StopoverRoute stopover in route.Stopovers)
            {
                XmlElement routeStopoverNode = xmlDoc.CreateElement("stopover");
                routeStopoverNode.SetAttribute("airport", stopover.Stopover.Profile.ID);

                XmlElement stopoverLegsNode = xmlDoc.CreateElement("legs");
                foreach (Route leg in stopover.Legs)
                {
                    XmlElement stopoverLegNode = xmlDoc.CreateElement("leg");

                    stopoverLegNode.AppendChild(SaveRoute(xmlDoc, leg));

                    stopoverLegsNode.AppendChild(stopoverLegNode);
                }
                routeStopoverNode.AppendChild(stopoverLegsNode);
                routeStopoversNode.AppendChild(routeStopoverNode);*/

            XmlNodeList routeStopoverList = routeNode.SelectNodes("stopovers/stopover");

            foreach (XmlElement routeStopoverNode in routeStopoverList)
            {
                Airport stopoverAirport = Airports.GetAirportFromID(routeStopoverNode.Attributes["airport"].Value);

                StopoverRoute stopoverRoute = new StopoverRoute(stopoverAirport);

                XmlNodeList legsList = routeStopoverNode.SelectNodes("legs/leg");

                foreach (XmlElement legNode in legsList)
                {

                    stopoverRoute.addLeg(LoadRoute((XmlElement)legNode.SelectSingleNode("route"), airline, routetype));
                }

                route.addStopover(stopoverRoute);

            }

            if (routetype == Route.RouteType.Passenger || routetype == Route.RouteType.Mixed)
            {
                ((PassengerRoute)route).Classes.Clear();

                XmlNodeList routeClassList = routeNode.SelectNodes("routeclasses/routeclass");

                foreach (XmlElement routeClassNode in routeClassList)
                {
                    AirlinerClass.ClassType airlinerClassType = (AirlinerClass.ClassType)Enum.Parse(typeof(AirlinerClass.ClassType), routeClassNode.Attributes["type"].Value);
                    double fareprice = Convert.ToDouble(routeClassNode.Attributes["fareprice"].Value,new CultureInfo("de-DE", false));
                    RouteAirlinerClass.SeatingType seatingType = (RouteAirlinerClass.SeatingType)Enum.Parse(typeof(RouteAirlinerClass.SeatingType), routeClassNode.Attributes["seating"].Value);

                    RouteAirlinerClass rClass = new RouteAirlinerClass(airlinerClassType, RouteAirlinerClass.SeatingType.Reserved_Seating, fareprice);
                    rClass.Seating = seatingType;

                    foreach (RouteFacility.FacilityType ftype in Enum.GetValues(typeof(RouteFacility.FacilityType)))
                    {
                        if (routeClassNode.HasAttribute(ftype.ToString()))
                        {
                            RouteFacility facility = RouteFacilities.GetFacility(routeClassNode.Attributes[ftype.ToString()].Value);
                            rClass.addFacility(facility);
                        }
                    }

                    ((PassengerRoute)route).addRouteAirlinerClass(rClass);

                }
            }
            if (routetype == Route.RouteType.Mixed || routetype == Route.RouteType.Cargo)
            {
                XmlElement routeCargoNode = (XmlElement)routeNode.SelectSingleNode("cargo");
                double unitPrice = Convert.ToDouble(routeCargoNode.Attributes["priceperunit"].Value,new CultureInfo("de-DE", false));

                ((CargoRoute)route).PricePerUnit = unitPrice;

            }

            RouteTimeTable timeTable = new RouteTimeTable(route);

            XmlNodeList timetableList = routeNode.SelectNodes("timetable/timetableentry");

            foreach (XmlElement entryNode in timetableList)
            {
                Airport entryDest = Airports.GetAirport(entryNode.Attributes["destination"].Value);
                string flightCode = entryNode.Attributes["flightcode"].Value;
                DayOfWeek day = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), entryNode.Attributes["day"].Value);
                TimeSpan time = TimeSpan.Parse(entryNode.Attributes["time"].Value);
                FleetAirliner airliner = entryNode.Attributes["airliner"].Value == "-" ? null : airline.Fleet.Find(a => a.Airliner.ID == entryNode.Attributes["airliner"].Value); ;

                RouteTimeTableEntry entry = new RouteTimeTableEntry(timeTable, day, time, new RouteEntryDestination(entryDest, flightCode,null),null);

                if (entryNode.HasAttribute("id"))
                    entry.ID = entryNode.Attributes["id"].Value;

                if (entryNode.HasAttribute("mainentry")) entry.MainEntry = airline.Routes.SelectMany(r => r.TimeTable.Entries).ToList().Find(e => e.ID == entryNode.Attributes["mainentry"].Value);

                entry.Airliner = airliner;

                if (airliner != null && !airliner.Routes.Contains(route))
                    airliner.Routes.Add(route);

                timeTable.addEntry(entry);
            }
            route.TimeTable = timeTable;

            XmlNodeList routeInvoiceList = routeNode.SelectNodes("invoices/invoice");

            foreach (XmlElement routeInvoiceNode in routeInvoiceList)
            {
                Invoice.InvoiceType type = (Invoice.InvoiceType)Enum.Parse(typeof(Invoice.InvoiceType), routeInvoiceNode.Attributes["type"].Value);
                int invoiceYear = Convert.ToInt16(routeInvoiceNode.Attributes["year"].Value);
                int invoiceMonth = Convert.ToInt16(routeInvoiceNode.Attributes["month"].Value);
                double invoiceAmount = Convert.ToDouble(routeInvoiceNode.Attributes["amount"].Value, new CultureInfo("de-DE", false));

                route.setRouteInvoice(type, invoiceYear, invoiceMonth, invoiceAmount);
            }

            return route;
        }
        //creates the stop over route based on the main route
        public static StopoverRoute CreateStopoverRoute(Airport dest1, Airport stopover, Airport dest2, Route mainroute, Boolean oneLegged,Route.RouteType type)
        {
            StopoverRoute stopoverRoute = new StopoverRoute(stopover);

            Guid id = Guid.NewGuid();

            if (!oneLegged)
            {
                if (mainroute.Type == Route.RouteType.Passenger || mainroute.Type == Route.RouteType.Mixed)
                {
                    PassengerRoute routeLegTwo = new PassengerRoute(id.ToString(), dest1, stopover, 0);

                    foreach (RouteAirlinerClass aClass in ((PassengerRoute)mainroute).Classes)
                    {
                        //routeLegTwo.getRouteAirlinerClass(aClass.Type).FarePrice = aClass.FarePrice;
                        routeLegTwo.getRouteAirlinerClass(aClass.Type).FarePrice = PassengerHelpers.GetPassengerPrice(dest1, stopover) * GeneralHelpers.ClassToPriceFactor(aClass.Type);

                        foreach (RouteFacility facility in aClass.getFacilities())
                            routeLegTwo.getRouteAirlinerClass(aClass.Type).addFacility(facility);

                        routeLegTwo.getRouteAirlinerClass(aClass.Type).Seating = aClass.Seating;

                    }


                    stopoverRoute.addLeg(routeLegTwo);
                }
                if (mainroute.Type == Route.RouteType.Cargo || mainroute.Type == Route.RouteType.Mixed)
                {
                    CargoRoute routeLegTwo = new CargoRoute(id.ToString(), dest1, stopover, ((CargoRoute)mainroute).PricePerUnit);

                    stopoverRoute.addLeg(routeLegTwo);
                }

            }

            if (mainroute.Type == Route.RouteType.Mixed || mainroute.Type == Route.RouteType.Passenger)
            {
                id = Guid.NewGuid();

                PassengerRoute routeLegOne = new PassengerRoute(id.ToString(), stopover, dest2, 0);

                foreach (RouteAirlinerClass aClass in ((PassengerRoute)mainroute).Classes)
                {
                    //routeLegOne.getRouteAirlinerClass(aClass.Type).FarePrice = aClass.FarePrice;

                    routeLegOne.getRouteAirlinerClass(aClass.Type).FarePrice = PassengerHelpers.GetPassengerPrice(stopover, dest2) * GeneralHelpers.ClassToPriceFactor(aClass.Type);


                    foreach (RouteFacility facility in aClass.getFacilities())
                        routeLegOne.getRouteAirlinerClass(aClass.Type).addFacility(facility);

                    routeLegOne.getRouteAirlinerClass(aClass.Type).Seating = aClass.Seating;

                }

                stopoverRoute.addLeg(routeLegOne);
            }
            if (mainroute.Type == Route.RouteType.Cargo || mainroute.Type == Route.RouteType.Mixed)
            {
                CargoRoute routeLegOne = new CargoRoute(id.ToString(), stopover, dest2, ((CargoRoute)mainroute).PricePerUnit);

                stopoverRoute.addLeg(routeLegOne);
              
            }
           

            return stopoverRoute;
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            Airline airline = GameObject.GetInstance().HumanAirline;
            Airport dest1 = (Airport)cbDestination1.SelectedItem;
            Airport dest2 = (Airport)cbDestination2.SelectedItem;
            Airport stopover1 = ucStopover1.Value;
            Airport stopover2 = ucStopover2.Value;

            Boolean stopoverOk = (stopover1 == null ? true : AirportHelpers.HasFreeGates(stopover1, airline)) && (stopover2 == null ? true : AirportHelpers.HasFreeGates(stopover2, airline));

            if (AirportHelpers.HasFreeGates(dest1, airline) && AirportHelpers.HasFreeGates(dest2, airline) && stopoverOk)
            {
                Route route = null;
                Guid id = Guid.NewGuid();

                if (this.RouteType == Route.RouteType.Passenger)
                {
                    route = new PassengerRoute(id.ToString(), dest1, dest2, 0);

                    foreach (RouteAirlinerClass aClass in this.Classes.Values)
                    {
                        ((PassengerRoute)route).getRouteAirlinerClass(aClass.Type).FarePrice = aClass.FarePrice;

                        foreach (RouteFacility facility in aClass.getFacilities())
                            ((PassengerRoute)route).getRouteAirlinerClass(aClass.Type).addFacility(facility);

                        ((PassengerRoute)route).getRouteAirlinerClass(aClass.Type).Seating = aClass.Seating;

                    }
                }
                if (this.RouteType == Route.RouteType.Cargo)
                {
                    route = new CargoRoute(id.ToString(), dest1, dest2, this.CargoPrice);
                }

                if (stopover1 != null)
                {
                    if (stopover2 != null)
                        route.addStopover(FleetAirlinerHelpers.CreateStopoverRoute(dest1, stopover1, stopover2, route, false, this.RouteType));
                    else
                        route.addStopover(FleetAirlinerHelpers.CreateStopoverRoute(dest1, stopover1, dest2, route, false, this.RouteType));
                }

                if (stopover2 != null)
                {
                    if (stopover1 != null)
                        route.addStopover(FleetAirlinerHelpers.CreateStopoverRoute(stopover1, stopover2, dest2, route, true, this.RouteType));
                    else
                        route.addStopover(FleetAirlinerHelpers.CreateStopoverRoute(dest1, stopover2, dest2, route, false, this.RouteType));
                }

                airline.addRoute(route);

                PageNavigator.NavigateTo(new PageRoutes());

                this.Visibility = System.Windows.Visibility.Collapsed;

                route.LastUpdated = GameObject.GetInstance().GameTime;
            }
            else
                WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2501"), Translator.GetInstance().GetString("MessageBox", "2501", "message"), WPFMessageBoxButtons.Ok);
        }
示例#4
0
        /*! creates some airliners and routes for a computer airline.
         */
        private static void CreateComputerRoutes(Airline airline)
        {
            Boolean leaseAircraft = airline.Profile.PrimaryPurchasing == AirlineProfile.PreferedPurchasing.Leasing;

            Airport airportHomeBase = FindComputerHomeBase(airline);

            AirportFacility serviceFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.Service).Find(f => f.TypeLevel == 1);
            AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1);
            AirportFacility cargoTerminal = AirportFacilities.GetFacilities(AirportFacility.FacilityType.Cargo).Find(f => f.TypeLevel > 0);

            airportHomeBase.addAirportFacility(airline, serviceFacility, GameObject.GetInstance().GameTime);
            airportHomeBase.addAirportFacility(airline, checkinFacility, GameObject.GetInstance().GameTime);

            if (airline.AirlineRouteFocus == Route.RouteType.Cargo)
                airportHomeBase.addAirportFacility(airline, cargoTerminal, GameObject.GetInstance().GameTime);

            AirlineStartData startData = AirlineStartDatas.GetAirlineStartData(airline);

            //creates the start data for an airline
            if (startData != null)
            {
                AirportHelpers.RentGates(airportHomeBase, airline, AirportContract.ContractType.Full);

                CreateAirlineStartData(airline, startData);
            }
            else
            {
                List<Airport> airportDestinations = AIHelpers.GetDestinationAirports(airline, airportHomeBase);

                if (airportDestinations.Count == 0)
                {
                    airportDestinations = Airports.GetAirports(a => a.Profile.Country.Region == airportHomeBase.Profile.Country.Region && a != airportHomeBase);
                }

                KeyValuePair<Airliner, Boolean>? airliner = null;
                Airport airportDestination = null;

                int counter = 0;

                while ((airportDestination == null || airliner == null || !airliner.HasValue) && airportDestinations.Count > counter)
                {
                    airportDestination = airportDestinations[counter];

                    airliner = AIHelpers.GetAirlinerForRoute(airline, airportHomeBase, airportDestination, leaseAircraft, airline.AirlineRouteFocus == Route.RouteType.Cargo, true);

                    counter++;

                }

                if (airportDestination == null || !airliner.HasValue)
                {
                    CreateComputerRoutes(airline);

                }
                else
                {

                    AirportHelpers.AddAirlineContract(new AirportContract(airline, airportHomeBase, AirportContract.ContractType.Full, GameObject.GetInstance().GameTime, 2, 25, 0, true));

                    AirportHelpers.RentGates(airportDestination, airline, AirportContract.ContractType.Low_Service);
                    //airportDestination.addAirportFacility(airline, checkinFacility, GameObject.GetInstance().GameTime);

                    Guid id = Guid.NewGuid();

                    double price = PassengerHelpers.GetPassengerPrice(airportDestination, airline.Airports[0]);

                    Route route = null;
                    if (airline.AirlineRouteFocus == Route.RouteType.Passenger)
                    {
                        route = new PassengerRoute(id.ToString(), airportDestination, airline.Airports[0], GameObject.GetInstance().GameTime, price);

                        RouteClassesConfiguration configuration = AIHelpers.GetRouteConfiguration((PassengerRoute)route);

                        foreach (RouteClassConfiguration classConfiguration in configuration.getClasses())
                        {
                            ((PassengerRoute)route).getRouteAirlinerClass(classConfiguration.Type).FarePrice = price * GeneralHelpers.ClassToPriceFactor(classConfiguration.Type);

                            foreach (RouteFacility rFacility in classConfiguration.getFacilities())
                                ((PassengerRoute)route).getRouteAirlinerClass(classConfiguration.Type).addFacility(rFacility);
                        }
                    }
                    if (airline.AirlineRouteFocus == Route.RouteType.Cargo)
                    {
                        route = new CargoRoute(id.ToString(), airportDestination, airline.Airports[0], GameObject.GetInstance().GameTime, PassengerHelpers.GetCargoPrice(airportDestination, airline.Airports[0]));

                        airportDestination.addAirportFacility(airline, cargoTerminal, GameObject.GetInstance().GameTime);

                    }
                    if (leaseAircraft)
                        AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Rents, -airliner.Value.Key.LeasingPrice * 2);
                    else
                        AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -airliner.Value.Key.getPrice());

                    FleetAirliner fAirliner = new FleetAirliner(leaseAircraft ? FleetAirliner.PurchasedType.Leased : FleetAirliner.PurchasedType.Bought, GameObject.GetInstance().GameTime, airline, airliner.Value.Key, airportHomeBase);
                    fAirliner.Status = FleetAirliner.AirlinerStatus.To_route_start;
                    fAirliner.addRoute(route);
                    AirlinerHelpers.CreateAirlinerClasses(fAirliner.Airliner);
                    AirlineHelpers.HireAirlinerPilots(fAirliner);

                    airline.addAirliner(fAirliner);

                    airline.addRoute(route);
                    route.LastUpdated = GameObject.GetInstance().GameTime;

                    if (route.Type == Route.RouteType.Passenger || route.Type == Route.RouteType.Mixed)
                    {
                        AIHelpers.CreateRouteTimeTable(route, fAirliner);
                    }
                    if (route.Type == Route.RouteType.Cargo)
                    {
                        AIHelpers.CreateCargoRouteTimeTable(route, fAirliner);
                    }

                }
            }
        }
示例#5
0
        /*!creates the start data for an airline
         */
        private static void CreateAirlineStartData(Airline airline, AirlineStartData startData)
        {
            AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1);
            AirportFacility cargoTerminal = AirportFacilities.GetFacilities(AirportFacility.FacilityType.Cargo).Find(f => f.TypeLevel > 0);

            //  int difficultyFactor = GameObject.GetInstance().Difficulty.AILevel > 1 ? 2 : 1; //level easy

            int startDataFactor = Convert.ToInt16(GameObject.GetInstance().Difficulty.StartDataLevel);
            var startroutes = startData.Routes.FindAll(r => r.Opened <= GameObject.GetInstance().GameTime.Year && r.Closed >= GameObject.GetInstance().GameTime.Year);

            //creates the routes
            var sRoutes = startroutes.GetRange(0, startroutes.Count / startDataFactor);
            Parallel.ForEach(sRoutes, startRoute =>
            {
                Airport dest1 = Airports.GetAirport(startRoute.Destination1);
                Airport dest2 = Airports.GetAirport(startRoute.Destination2);

                if (dest1 != null && dest2 != null)
                {
                    //if (dest1.getAirportFacility(airline, AirportFacility.FacilityType.CheckIn).TypeLevel == 0)
                    //dest1.addAirportFacility(airline, checkinFacility, GameObject.GetInstance().GameTime);

                    //if (dest2.getAirportFacility(airline, AirportFacility.FacilityType.CheckIn).TypeLevel == 0)
                    //dest2.addAirportFacility(airline, checkinFacility, GameObject.GetInstance().GameTime);

                    if (dest1.getAirportFacility(airline, AirportFacility.FacilityType.Cargo).TypeLevel == 0 && dest1.getAirportFacility(null, AirportFacility.FacilityType.Cargo).TypeLevel == 0 && airline.AirlineRouteFocus == Route.RouteType.Cargo)
                        dest1.addAirportFacility(airline, cargoTerminal, GameObject.GetInstance().GameTime);

                    if (dest2.getAirportFacility(airline, AirportFacility.FacilityType.Cargo).TypeLevel == 0 && dest2.getAirportFacility(null, AirportFacility.FacilityType.Cargo).TypeLevel == 0 && airline.AirlineRouteFocus == Route.RouteType.Cargo)
                        dest2.addAirportFacility(airline, cargoTerminal, GameObject.GetInstance().GameTime);

                    if (!AirportHelpers.HasFreeGates(dest1, airline))
                        AirportHelpers.RentGates(dest1, airline, AirportContract.ContractType.Low_Service);

                    if (!AirportHelpers.HasFreeGates(dest2, airline))
                        AirportHelpers.RentGates(dest2, airline, AirportContract.ContractType.Low_Service);

                    Guid id = Guid.NewGuid();

                    Route route = null;

                    double price = PassengerHelpers.GetPassengerPrice(dest1, dest2);

                    if (startRoute.RouteType == Route.RouteType.Mixed || startRoute.RouteType == Route.RouteType.Passenger)
                    {
                        route = new PassengerRoute(id.ToString(), dest1, dest2, GameObject.GetInstance().GameTime, price);
                    }

                    if (startRoute.RouteType == Route.RouteType.Cargo)
                        route = new CargoRoute(id.ToString(), dest1, dest2, GameObject.GetInstance().GameTime, PassengerHelpers.GetCargoPrice(dest1, dest2));

                    KeyValuePair<Airliner, Boolean>? airliner = null;
                    if (startRoute.Type != null)
                    {
                        double distance = MathHelpers.GetDistance(dest1, dest2);

                        if (startRoute.Type.Range > distance)
                        {
                            airliner = new KeyValuePair<Airliner, bool>(Airliners.GetAirlinersForSale(a => a.Type == startRoute.Type).FirstOrDefault(), true);

                            if (airliner.Value.Key == null)
                            {
                                id = Guid.NewGuid();
                                Airliner nAirliner = new Airliner(id.ToString(), startRoute.Type, airline.Profile.Country.TailNumbers.getNextTailNumber(), GameObject.GetInstance().GameTime);
                                Airliners.AddAirliner(nAirliner);

                                nAirliner.clearAirlinerClasses();

                                AirlinerHelpers.CreateAirlinerClasses(nAirliner);

                                airliner = new KeyValuePair<Airliner, bool>(nAirliner, true);
                            }
                        }

                    }

                    Boolean leaseAircraft = airline.Profile.PrimaryPurchasing == AirlineProfile.PreferedPurchasing.Leasing;

                    if (airliner == null)
                    {

                        airliner = AIHelpers.GetAirlinerForRoute(airline, dest2, dest1, leaseAircraft, startRoute.RouteType == Route.RouteType.Cargo, true);

                        if (airliner == null && airline.Profile.PrimaryPurchasing == AirlineProfile.PreferedPurchasing.Random)
                            AIHelpers.GetAirlinerForRoute(airline, dest2, dest1, true, startRoute.RouteType == Route.RouteType.Cargo, true);

                    }

                    if (airliner != null)
                    {
                        FleetAirliner fAirliner = AirlineHelpers.AddAirliner(airline, airliner.Value.Key, airline.Airports[0],leaseAircraft);
                        fAirliner.addRoute(route);
                        fAirliner.Status = FleetAirliner.AirlinerStatus.To_route_start;
                        AirlineHelpers.HireAirlinerPilots(fAirliner);

                        route.LastUpdated = GameObject.GetInstance().GameTime;

                        if (startRoute.RouteType == Route.RouteType.Mixed || startRoute.RouteType == Route.RouteType.Passenger)
                        {
                            AirlinerHelpers.CreateAirlinerClasses(fAirliner.Airliner);

                            RouteClassesConfiguration configuration = AIHelpers.GetRouteConfiguration((PassengerRoute)route);

                            foreach (RouteClassConfiguration classConfiguration in configuration.getClasses())
                            {
                                ((PassengerRoute)route).getRouteAirlinerClass(classConfiguration.Type).FarePrice = price * GeneralHelpers.ClassToPriceFactor(classConfiguration.Type);

                                foreach (RouteFacility rFacility in classConfiguration.getFacilities())
                                    ((PassengerRoute)route).getRouteAirlinerClass(classConfiguration.Type).addFacility(rFacility);
                            }

                            AIHelpers.CreateRouteTimeTable(route, fAirliner);
                        }
                        if (startRoute.RouteType == Route.RouteType.Cargo)
                        {
                            AIHelpers.CreateCargoRouteTimeTable(route, fAirliner);
                        }
                    }
                    airline.addRoute(route);
                }

            });

            //adds the airliners
            Parallel.ForEach(startData.Airliners, airliners =>
            {
                AirlinerType type = AirlinerTypes.GetType(airliners.Type);

                int totalSpan = 2010 - 1960;
                int yearSpan = GameObject.GetInstance().GameTime.Year - 1960;
                double valueSpan = Convert.ToDouble(airliners.AirlinersLate - airliners.AirlinersEarly);
                double span = valueSpan / Convert.ToDouble(totalSpan);

                int numbers = Math.Max(1, Convert.ToInt16(span * yearSpan) / startDataFactor);
                //type==null
                if (type.Produced.From <= GameObject.GetInstance().GameTime)
                {
                    for (int i = 0; i < Math.Max(numbers, airliners.AirlinersEarly); i++)
                    {
                        Guid id = Guid.NewGuid();

                        int countryNumber = rnd.Next(Countries.GetCountries().Count() - 1);
                        Country country = Countries.GetCountries()[countryNumber];

                        int builtYear = rnd.Next(type.Produced.From.Year, Math.Min(GameObject.GetInstance().GameTime.Year - 1, type.Produced.To.Year));

                        Airliner airliner = new Airliner(id.ToString(), type, country.TailNumbers.getNextTailNumber(), new DateTime(builtYear, 1, 1));

                        int age = MathHelpers.CalculateAge(airliner.BuiltDate, GameObject.GetInstance().GameTime);

                        long kmPerYear = rnd.Next(100000, 1000000);
                        long km = kmPerYear * age;

                        airliner.Flown = km;

                        Airliners.AddAirliner(airliner);

                        Boolean leaseAircraft = airline.Profile.PrimaryPurchasing == AirlineProfile.PreferedPurchasing.Leasing;

                        FleetAirliner fAirliner = AirlineHelpers.AddAirliner(airline, airliner, airline.Airports[0],leaseAircraft);
                        fAirliner.Status = FleetAirliner.AirlinerStatus.Stopped;
                        AirlineHelpers.HireAirlinerPilots(fAirliner);

                        AirlinerHelpers.CreateAirlinerClasses(fAirliner.Airliner);

                    }
                }

            });

            //the origin routes
            Parallel.ForEach(startData.OriginRoutes, routes =>
            {
                Airport origin = Airports.GetAirport(routes.Origin);

                if (origin != null)
                {
                    for (int i = 0; i < Math.Min(routes.Destinations / startDataFactor, origin.Terminals.getFreeGates()); i++)
                    {
                        //if (origin.getAirportFacility(airline, AirportFacility.FacilityType.CheckIn).TypeLevel == 0)
                        //origin.addAirportFacility(airline, checkinFacility, GameObject.GetInstance().GameTime);

                        if (!AirportHelpers.HasFreeGates(origin, airline))
                            AirportHelpers.RentGates(origin, airline, AirportContract.ContractType.Low_Service);

                        Airport destination = GetStartDataRoutesDestination(routes);

                        //if (destination.getAirportFacility(airline, AirportFacility.FacilityType.CheckIn).TypeLevel == 0)
                        //destination.addAirportFacility(airline, checkinFacility, GameObject.GetInstance().GameTime);

                        if (!AirportHelpers.HasFreeGates(destination, airline))
                            AirportHelpers.RentGates(destination, airline, AirportContract.ContractType.Low_Service);

                        Guid id = Guid.NewGuid();

                        Route route = null;

                        double price = PassengerHelpers.GetPassengerPrice(origin, destination);

                        if (routes.RouteType == Route.RouteType.Mixed || routes.RouteType == Route.RouteType.Passenger)
                            route = new PassengerRoute(id.ToString(), origin, destination, GameObject.GetInstance().GameTime, price);

                        if (routes.RouteType == Route.RouteType.Cargo)
                            route = new CargoRoute(id.ToString(), origin, destination, GameObject.GetInstance().GameTime, PassengerHelpers.GetCargoPrice(origin, destination));

                        Boolean leaseAircraft = airline.Profile.PrimaryPurchasing == AirlineProfile.PreferedPurchasing.Leasing;

                        KeyValuePair<Airliner, Boolean>? airliner = AIHelpers.GetAirlinerForRoute(airline, origin, destination, leaseAircraft, routes.RouteType == Route.RouteType.Cargo, true);

                        if (airliner == null && airline.Profile.PrimaryPurchasing == AirlineProfile.PreferedPurchasing.Random)
                            airliner = AIHelpers.GetAirlinerForRoute(airline, origin, destination, true, routes.RouteType == Route.RouteType.Cargo, true);

                        double distance = MathHelpers.GetDistance(origin, destination);

                        if (airliner != null)
                        {
                            FleetAirliner fAirliner = AirlineHelpers.AddAirliner(airline, airliner.Value.Key, airline.Airports[0], leaseAircraft);
                            fAirliner.addRoute(route);
                            fAirliner.Status = FleetAirliner.AirlinerStatus.To_route_start;
                            AirlineHelpers.HireAirlinerPilots(fAirliner);

                            route.LastUpdated = GameObject.GetInstance().GameTime;

                            if (routes.RouteType == Route.RouteType.Passenger || routes.RouteType == Route.RouteType.Mixed)
                            {
                                AirlinerHelpers.CreateAirlinerClasses(fAirliner.Airliner);

                                RouteClassesConfiguration configuration = AIHelpers.GetRouteConfiguration((PassengerRoute)route);

                                foreach (RouteClassConfiguration classConfiguration in configuration.getClasses())
                                {
                                    ((PassengerRoute)route).getRouteAirlinerClass(classConfiguration.Type).FarePrice = price * GeneralHelpers.ClassToPriceFactor(classConfiguration.Type);

                                    foreach (RouteFacility rFacility in classConfiguration.getFacilities())
                                        ((PassengerRoute)route).getRouteAirlinerClass(classConfiguration.Type).addFacility(rFacility);
                                }

                                AIHelpers.CreateRouteTimeTable(route, fAirliner);
                            }
                            if (routes.RouteType == Route.RouteType.Cargo)
                                AIHelpers.CreateCargoRouteTimeTable(route, fAirliner);

                            airline.addRoute(route);

                        }
                    }
                }
            });
        }
        //creates a route and returns if success
        private Boolean createRoute()
        {
            Route route = null;
            Airport destination1 = (Airport)cbDestination1.SelectedItem;
            Airport destination2 = (Airport)cbDestination2.SelectedItem;
            Airport stopover1 = (Airport)cbStopover1.SelectedItem;
            Airport stopover2 = cbStopover2.Visibility == System.Windows.Visibility.Visible ? (Airport)cbStopover2.SelectedItem : null;
            DateTime startDate = dpStartDate.IsEnabled && dpStartDate.SelectedDate.HasValue ? dpStartDate.SelectedDate.Value : GameObject.GetInstance().GameTime;

            Weather.Season season = rbSeasonAll.IsChecked.Value ? Weather.Season.All_Year : Weather.Season.Winter;
            season = rbSeasonSummer.IsChecked.Value ? Weather.Season.Summer : season;
            season = rbSeasonWinter.IsChecked.Value ? Weather.Season.Winter : season;

            try
            {
                if (AirlineHelpers.IsRouteDestinationsOk(GameObject.GetInstance().HumanAirline, destination1, destination2, this.RouteType, stopover1, stopover2))
                {

                    Guid id = Guid.NewGuid();

                    //passenger route
                    if (this.RouteType == Route.RouteType.Passenger)
                    {
                        //Vis på showroute
                        route = new PassengerRoute(id.ToString(), destination1, destination2,startDate, 0);

                        foreach (MVVMRouteClass rac in this.Classes)
                        {
                            ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).FarePrice = rac.FarePrice;

                            foreach (MVVMRouteFacility facility in rac.Facilities)
                                ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).addFacility(facility.SelectedFacility);

                        }
                    }
                    //cargo route
                    else if (this.RouteType == Route.RouteType.Cargo)
                    {
                        double cargoPrice = Convert.ToDouble(txtCargoPrice.Text);
                        route = new CargoRoute(id.ToString(), destination1, destination2,startDate, cargoPrice);
                    }
                    else if (this.RouteType == Route.RouteType.Mixed)
                    {
                        double cargoPrice = Convert.ToDouble(txtCargoPrice.Text);

                        route = new CombiRoute(id.ToString(), destination1, destination2, startDate, 0, cargoPrice);

                        foreach (MVVMRouteClass rac in this.Classes)
                        {
                            ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).FarePrice = rac.FarePrice;

                            foreach (MVVMRouteFacility facility in rac.Facilities)
                                ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).addFacility(facility.SelectedFacility);

                        }
                    }

                    FleetAirlinerHelpers.CreateStopoverRoute(route, stopover1, stopover2);

                    route.Season = season;

                    GameObject.GetInstance().HumanAirline.addRoute(route);

                    return true;

                }
            }
            catch (Exception ex)
            {
                WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", ex.Message), Translator.GetInstance().GetString("MessageBox", ex.Message, "message"), WPFMessageBoxButtons.Ok);

                return false;
            }

            return false;
        }
        //creates a route and returns if success
        private Boolean createRoute()
        {
            Route route = null;
            Airport destination1 = (Airport)cbDestination1.SelectedItem;
            Airport destination2 = (Airport)cbDestination2.SelectedItem;
            Airport stopover1 = (Airport)cbStopover1.SelectedItem;
            Airport stopover2 = cbStopover2.Visibility == System.Windows.Visibility.Visible ? (Airport)cbStopover2.SelectedItem : null;

            try
            {
                if (AirlineHelpers.IsRouteDestinationsOk(GameObject.GetInstance().HumanAirline, destination1, destination2, rbPassenger.IsChecked.Value ? Route.RouteType.Passenger : Route.RouteType.Cargo, stopover1, stopover2))
                {

                    Guid id = Guid.NewGuid();

                    //passenger route
                    if (rbPassenger.IsChecked.Value)
                    {
                        route = new PassengerRoute(id.ToString(), destination1, destination2, 0);

                        foreach (MVVMRouteClass rac in this.Classes)
                        {
                            ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).FarePrice = rac.FarePrice;

                            foreach (MVVMRouteFacility facility in rac.Facilities)
                                ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).addFacility(facility.SelectedFacility);

                        }
                    }
                    //cargo route
                    else
                    {
                        double cargoPrice = Convert.ToDouble(txtCargoPrice.Text);
                        route = new CargoRoute(id.ToString(), destination1, destination2, cargoPrice);
                    }

                    FleetAirlinerHelpers.CreateStopoverRoute(route, stopover1, stopover2);

                    GameObject.GetInstance().HumanAirline.addRoute(route);

                    return true;

                }
            }
            catch (Exception ex)
            {
                WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", ex.Message), Translator.GetInstance().GetString("MessageBox", ex.Message, "message"), WPFMessageBoxButtons.Ok);

                return false;
            }

            return false;
        }