public static object ShowPopUp(AirportContract contract)
        {
            PopUpWindow window = new PopUpExtendContract(contract);
            window.ShowDialog();

            return window.Selected;
        }
 public PopUpAirportContract(AirportContract contract)
     : this(contract.Airport,contract.Airport.Terminals.getFreeGates() + contract.NumberOfGates)
 {
     this.Contract = contract;
     nudGates.Value = contract.NumberOfGates;
     cbLength.SelectedItem = contract.Length;
 }
Ejemplo n.º 3
0
 public void addAirlineContract(AirportContract contract)
 {
     this.Airport.addAirlineContract(contract);
     this.IsHuman = GameObject.GetInstance().HumanAirline.Airports.Contains(this.Airport);
     this.NumberOfFreeGates = this.Airport.Terminals.NumberOfFreeGates;
     this.NumberOfAirlines = this.Airport.AirlineContracts.Select(c => c.Airline).Distinct().Count();
     this.NumberOfRoutes = AirportHelpers.GetAirportRoutes(this.Airport).Count;
 }
Ejemplo n.º 4
0
        //removes a terminal from the airport
        public void removeTerminal(Terminal terminal)
        {
            AirportContract terminalContract = this.AirlineContracts.Find(c => c.Terminal != null && c.Terminal == terminal);

            if (terminalContract != null)
            {
                removeAirlineContract(terminalContract);
            }

            this.Terminals.removeTerminal(terminal);
        }
Ejemplo n.º 5
0
        //removes an airline airport contract from the airport
        public void removeAirlineContract(AirportContract contract)
        {
            lock (this._Contracts)
            {
                this._Contracts.Remove(contract);
            }

            if (!this.AirlineContracts.Exists(c => c.Airline == contract.Airline))
            {
                contract.Airline.removeAirport(this);
            }
        }
        public PopUpExtendContract(AirportContract contract)
        {
            this.Contract = contract;
            this.DataContext = contract;

            this.ExpireDate = this.Contract.ExpireDate;
            this.NumberOfGates = this.Contract.NumberOfGates;

            this.HasFreeGates = this.Contract.Airport.Terminals.getFreeGates() > 0;

            InitializeComponent();
        }
Ejemplo n.º 7
0
        //adds an airline airport contract to the airport
        public void addAirlineContract(AirportContract contract)
        {
            lock (this._Contracts)
            {
                this._Contracts.Add(contract);
            }

            if (!contract.Airline.Airports.Contains(this))
            {
                contract.Airline.addAirport(this);
            }
        }
Ejemplo n.º 8
0
        //adds an airport contract for an airline to an airport
        public static void AddAirlineContract(AirportContract contract)
        {
            contract.Airport.addAirlineContract(contract);

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

            if (contract.Type == AirportContract.ContractType.Full_Service)
            {
                if (contract.Airport.getAirlineAirportFacility(null,AirportFacility.FacilityType.Cargo).Facility.TypeLevel < cargoTerminal.TypeLevel)
                    contract.Airport.addAirportFacility(null, cargoTerminal, GameObject.GetInstance().GameTime);

                if (contract.Airport.getAirlineAirportFacility(null,AirportFacility.FacilityType.CheckIn).Facility.TypeLevel < checkinFacility.TypeLevel)
                    contract.Airport.addAirportFacility(null, checkinFacility, GameObject.GetInstance().GameTime);

                if (contract.Airport.getAirlineAirportFacility(null,AirportFacility.FacilityType.TicketOffice).Facility.TypeLevel < ticketFacility.TypeLevel)
                    contract.Airport.addAirportFacility(null, ticketFacility, GameObject.GetInstance().GameTime);

                if (contract.Airport.getAirlineAirportFacility(null,AirportFacility.FacilityType.Service).Facility.TypeLevel < serviceFacility.TypeLevel)
                    contract.Airport.addAirportFacility(null, serviceFacility, GameObject.GetInstance().GameTime);
            }
            if (contract.Type == AirportContract.ContractType.Medium_Service)
            {
                if (contract.Airport.getAirlineAirportFacility(null, AirportFacility.FacilityType.CheckIn).Facility.TypeLevel < checkinFacility.TypeLevel)
                    contract.Airport.addAirportFacility(null, checkinFacility, GameObject.GetInstance().GameTime);

                if (contract.Airport.getAirlineAirportFacility(null, AirportFacility.FacilityType.TicketOffice).Facility.TypeLevel < ticketFacility.TypeLevel)
                    contract.Airport.addAirportFacility(null, ticketFacility, GameObject.GetInstance().GameTime);

            }
            if (contract.Type == AirportContract.ContractType.Low_Service)
            {
                if (contract.Airport.getAirlineAirportFacility(null, AirportFacility.FacilityType.CheckIn).Facility.TypeLevel < checkinFacility.TypeLevel)
                    contract.Airport.addAirportFacility(null, checkinFacility, GameObject.GetInstance().GameTime);

            }
        }
Ejemplo n.º 9
0
        private void btnContract_Click(object sender, RoutedEventArgs e)
        {
            AirportMVVM airport = (AirportMVVM)((Button)sender).Tag;

            Boolean hasCheckin = airport.Airport.getAirportFacility(GameObject.GetInstance().HumanAirline, AirportFacility.FacilityType.CheckIn).TypeLevel > 0;

            int gates = Math.Min(2, airport.Airport.Terminals.NumberOfFreeGates);

               //WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2222"), string.Format(Translator.GetInstance().GetString("MessageBox", "2222", "message"),gates, airport.Airport.Profile.Name), WPFMessageBoxButtons.YesNo);

               object o = PopUpAirportContract.ShowPopUp(airport.Airport);

               if (o != null)
               {
               AirportContract.ContractType contractType = (AirportContract.ContractType)o;

               if (!hasCheckin && contractType == AirportContract.ContractType.Full)
               {
                   AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1);

                   airport.Airport.addAirportFacility(GameObject.GetInstance().HumanAirline, checkinFacility, GameObject.GetInstance().GameTime);
                   AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -checkinFacility.Price);

               }

               //AirportHelpers.RentGates(airport.Airport, GameObject.GetInstance().HumanAirline, contractType, gates, 2);

               double yearlyPayment = AirportHelpers.GetYearlyContractPayment(airport.Airport,contractType, gates,2);

               AirportContract contract = new AirportContract(GameObject.GetInstance().HumanAirline,airport.Airport,contractType,GameObject.GetInstance().GameTime,gates,2,yearlyPayment,true);

               airport.addAirlineContract(contract);

               for (int i = 0; i < gates; i++)
               {
                   Gate gate = airport.Airport.Terminals.getGates().Where(g => g.Airline == null).First();
                   gate.Airline = GameObject.GetInstance().HumanAirline;
               }

            }
        }
Ejemplo n.º 10
0
        //removes an airline airport contract from the airport
        public void removeAirlineContract(AirportContract contract)
        {
            lock (this._Contracts)
            {
                this._Contracts.Remove(contract);
            }

            if (!this.AirlineContracts.Exists(c => c.Airline == contract.Airline))
                contract.Airline.removeAirport(this);
        }
Ejemplo n.º 11
0
 //returns if an airline has a contract of a specific type
 public Boolean hasContractType(Airline airline, AirportContract.ContractType type)
 {
     return this.AirlineContracts.Exists(c => c.Airline == airline && c.Type == type);
 }
Ejemplo n.º 12
0
        //adds an airline airport contract to the airport
        public void addAirlineContract(AirportContract contract)
        {
            lock (this._Contracts)
            {
                this._Contracts.Add(contract);
            }

            if (!contract.Airline.Airports.Contains(this))
                contract.Airline.addAirport(this);
        }
Ejemplo n.º 13
0
        private void btnSignContract_Click(object sender, RoutedEventArgs e)
        {
            int gates = Convert.ToInt16(slContractGates.Value);
            int length = Convert.ToInt16(slContractLenght.Value);

            Boolean hasCheckin = this.Airport.Airport.getAirportFacility(GameObject.GetInstance().HumanAirline, AirportFacility.FacilityType.CheckIn).TypeLevel > 0;
            AirportContract.ContractType contractType = (AirportContract.ContractType)cbContractType.SelectedItem;

            Boolean autoRenew = cbAutoRenew.IsChecked.Value;

            double yearlyPayment = AirportHelpers.GetYearlyContractPayment(this.Airport.Airport,contractType, gates, length);

            Boolean payFull = length <= 2;

            AirportContract contract = new AirportContract(GameObject.GetInstance().HumanAirline, this.Airport.Airport, contractType, GameObject.GetInstance().GameTime, gates, length, yearlyPayment,autoRenew, payFull);

            if (!hasCheckin && contractType == AirportContract.ContractType.Full)
            {
                AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1);

                this.Airport.Airport.addAirportFacility(GameObject.GetInstance().HumanAirline, checkinFacility, GameObject.GetInstance().GameTime);
                AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -checkinFacility.Price);

            }

            //25 % off if paying up front
            if (contract.PayFull && contractType == AirportContract.ContractType.Full)
            {
                double payment = (contract.YearlyPayment * contract.Length) * 0.75;
                AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Rents, -payment);
                contract.YearlyPayment = 0;
            }

            for (int i = 0; i < gates; i++)
            {
                Gate gate = this.Airport.Airport.Terminals.getGates().Where(g => g.Airline == null).First();
                gate.Airline = GameObject.GetInstance().HumanAirline;
            }

            this.Airport.addAirlineContract(contract);
        }
        public static void RentGates(Airport airport, Airline airline, int gates)
        {
            AirportContract contract = new AirportContract(airline, airport, GameObject.GetInstance().GameTime, gates, 20, GetYearlyContractPayment(airport, gates, 20));

            airport.addAirlineContract(contract);
        }
 public static void CreateAirportContract(Airport airport, Airline airline, int gates, int length, double yearlypayment)
 {
     AirportContract contract = new AirportContract(airline, airport, GameObject.GetInstance().GameTime, gates, length, yearlypayment);
     airport.addAirlineContract(contract);
 }
Ejemplo n.º 16
0
        private void btnSignContract_Click(object sender, RoutedEventArgs e)
        {
            int gates = Convert.ToInt16(slContractGates.Value);
            int lenght = Convert.ToInt16(slContractLenght.Value);

            Boolean hasCheckin = this.Airport.Airport.getAirportFacility(GameObject.GetInstance().HumanAirline, AirportFacility.FacilityType.CheckIn).TypeLevel > 0;
            double yearlyPayment = AirportHelpers.GetYearlyContractPayment(this.Airport.Airport, gates, lenght);

            Boolean payFull = lenght <= 2;

            AirportContract contract = new AirportContract(GameObject.GetInstance().HumanAirline, this.Airport.Airport, GameObject.GetInstance().GameTime, gates, lenght, yearlyPayment, payFull);

            if (!hasCheckin)
            {
                AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1);

                this.Airport.Airport.addAirportFacility(GameObject.GetInstance().HumanAirline, checkinFacility, GameObject.GetInstance().GameTime);
                AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -checkinFacility.Price);

            }

            //25 % off if paying up front
            if (contract.PayFull)
            {
                double payment = (contract.YearlyPayment * contract.Length) * 0.75;
                AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Rents, -payment);
                contract.YearlyPayment = 0;
            }

            this.Airport.addAirlineContract(contract);
        }
Ejemplo n.º 17
0
        private void btnDemandContract_Click(object sender, RoutedEventArgs e)
        {
            DemandMVVM demand = (DemandMVVM)((Button)sender).Tag;

            Airport airport = demand.Destination;

            Boolean hasCheckin = airport.getAirportFacility(GameObject.GetInstance().HumanAirline, AirportFacility.FacilityType.CheckIn).TypeLevel > 0;

            int gates = Math.Min(2, airport.Terminals.NumberOfFreeGates);

            WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2222"), string.Format(Translator.GetInstance().GetString("MessageBox", "2222", "message"), gates, airport.Profile.Name), WPFMessageBoxButtons.YesNo);

            if (result == WPFMessageBoxResult.Yes)
            {
                if (!hasCheckin)
                {
                    AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1);

                    airport.addAirportFacility(GameObject.GetInstance().HumanAirline, checkinFacility, GameObject.GetInstance().GameTime);
                    AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -checkinFacility.Price);

                }

                double yearlyPayment = AirportHelpers.GetYearlyContractPayment(airport, gates, 2);

                AirportContract contract = new AirportContract(GameObject.GetInstance().HumanAirline, airport, GameObject.GetInstance().GameTime, gates, 2, yearlyPayment);

                airport.addAirlineContract(contract);

                demand.Contracted = true;
            }
        }
Ejemplo n.º 18
0
 public ContractMVVM(AirportContract contract)
 {
     this.Contract = contract;
     this.Airline = this.Contract.Airline;
     this.NumberOfGates = this.Contract.NumberOfGates;
     this.MonthsLeft = this.Contract.MonthsLeft;
 }
Ejemplo n.º 19
0
        //adds an airline contract to the airport
        public void addAirlineContract(AirportContract contract)
        {
            this.Airport.addAirlineContract(contract);

            this.Contracts.Add(new ContractMVVM(contract));

            this.FreeGates = this.Airport.Terminals.NumberOfFreeGates;

            this.CanBuildHub = this.Contracts.Count(c => c.Airline == GameObject.GetInstance().HumanAirline) > 0;

            foreach (AirportTerminalMVVM terminal in Terminals)
            {
                terminal.FreeGates = terminal.Terminal.getFreeGates();
            }
        }
Ejemplo n.º 20
0
        //do the daily update
        private static void DoDailyUpdate()
        {
            //Clear stats when it on daily update
            if (Settings.GetInstance().ClearStats == Settings.Intervals.Daily)
                ClearAllUsedStats();

            //Auto save when it on daily
            if (Settings.GetInstance().AutoSave == Settings.Intervals.Daily)
                SerializedLoadSaveHelpers.SaveGame("autosave");

            //Clearing stats as an RAM work-a-round
            Airports.GetAllAirports().ForEach(a => a.clearDestinationPassengerStatistics());
            Airports.GetAllAirports().ForEach(a => a.clearDestinationCargoStatistics());

            var humanAirlines = Airlines.GetAirlines(a => a.IsHuman);

            //Console.WriteLine(GameObject.GetInstance().GameTime.ToShortDateString() + ": " + DateTime.Now.Subtract(LastTime).TotalMilliseconds + " ms." + " : routes: " + totalRoutes + " airliners on route: " + totalAirlinersOnRoute);

            LastTime = DateTime.Now;
            //changes the fuel prices
            double fuelDiff = Inflations.GetInflation(GameObject.GetInstance().GameTime.Year + 1).FuelPrice - Inflations.GetInflation(GameObject.GetInstance().GameTime.Year).FuelPrice;
            double fuelPrice = (rnd.NextDouble() * (fuelDiff / 4));

            GameObject.GetInstance().FuelPrice = Inflations.GetInflation(GameObject.GetInstance().GameTime.Year).FuelPrice + fuelPrice;
            //checks for airports due to close in 14 days
            var closingAirports = Airports.GetAllAirports(a => a.Profile.Period.To.ToShortDateString() == GameObject.GetInstance().GameTime.AddDays(14).ToShortDateString());
            var openingAirports = Airports.GetAllAirports(a => a.Profile.Period.From.ToShortDateString() == GameObject.GetInstance().GameTime.AddDays(14).ToShortDateString());

            foreach (Airport airport in closingAirports)
            {
                Airport reallocatedAirport = openingAirports.Find(a => a.Profile.Town == airport.Profile.Town);

                if (reallocatedAirport == null)
                    GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airport_News, GameObject.GetInstance().GameTime, "Airport closing", string.Format("The airport [LI airport={0}]({1}) is closing in 14 days.\n\rPlease move all routes to another destination.", airport.Profile.IATACode, new AirportCodeConverter().Convert(airport).ToString())));
                else
                    GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airport_News, GameObject.GetInstance().GameTime, "Airport closing", string.Format("The airport [LI airport={0}]({1}) is closing in 14 days.\n\rThe airport will be replaced by {2}({3}) and all gates and routes from {0} will be reallocated to {2}.", airport.Profile.IATACode, new AirportCodeConverter().Convert(airport).ToString(), reallocatedAirport.Profile.Name, new AirportCodeConverter().Convert(reallocatedAirport).ToString())));

                CalendarItems.AddCalendarItem(new CalendarItem(CalendarItem.ItemType.Airport_Closing, airport.Profile.Period.To, "Airport closing", string.Format("{0}, {1}", airport.Profile.Name, ((Country)new CountryCurrentCountryConverter().Convert(airport.Profile.Country)).Name)));
            }

            foreach (Airport airport in openingAirports)
            {
                GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airport_News, GameObject.GetInstance().GameTime, "Airport opening", string.Format("A new airport {0}({1}) is opening in 14 days in {2}, {3}.", airport.Profile.Name, new AirportCodeConverter().Convert(airport).ToString(), airport.Profile.Town.Name, ((Country)new CountryCurrentCountryConverter().Convert(airport.Profile.Country)).Name)));
                CalendarItems.AddCalendarItem(new CalendarItem(CalendarItem.ItemType.Airport_Opening, airport.Profile.Period.From, "Airport opening", string.Format("{0}, {1}", airport.Profile.Name, ((Country)new CountryCurrentCountryConverter().Convert(airport.Profile.Country)).Name)));

            }
            //checks for new airports which are opening
            List<Airport> openedAirports = Airports.GetAllAirports(a => a.Profile.Period.From.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString());
            List<Airport> closedAirports = Airports.GetAllAirports(a => a.Profile.Period.To.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString());

            //checks for airports which are closing down
            foreach (Airport airport in closedAirports)
            {
                //check for airport which are reallocated
                Airport reallocatedAirport = openedAirports.Find(a => a.Profile.Town == airport.Profile.Town);

                if (reallocatedAirport != null)
                {

                    var airlines = new List<Airline>(from c in airport.AirlineContracts select c.Airline).Distinct();
                    foreach (Airline airline in airlines)
                    {
                        AirlineHelpers.ReallocateAirport(airport, reallocatedAirport, airline);

                        if (airline.IsHuman)
                            GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airport_News, GameObject.GetInstance().GameTime, "Airport operations changed", string.Format("All your gates, routes and facilities has been moved from {0}({1}) to [LI airport={2}]({3})", airport.Profile.Name, new AirportCodeConverter().Convert(airport).ToString(), reallocatedAirport.Profile.IATACode, new AirportCodeConverter().Convert(reallocatedAirport).ToString())));
                    }
                }

                GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airport_News, GameObject.GetInstance().GameTime, "Airport closed", string.Format("The airport {0}({1}) has now been closed. \n\rAll routes to and from the airports has been cancelled.", airport.Profile.Name, new AirportCodeConverter().Convert(airport).ToString())));

                var obsoleteRoutes = (from r in Airlines.GetAllAirlines().SelectMany(a => a.Routes) where r.Destination1 == airport || r.Destination2 == airport select r);

                foreach (Route route in obsoleteRoutes)
                {
                    route.Banned = true;

                    foreach (FleetAirliner airliner in route.getAirliners())
                    {
                        if (airliner.Homebase == airport)
                        {
                            if (airliner.Airliner.Airline.IsHuman)
                            {

                                airliner.Homebase = (Airport)PopUpNewAirlinerHomebase.ShowPopUp(airliner);

                            }
                            else
                            {
                                AIHelpers.SetAirlinerHomebase(airliner);
                            }

                        }

                    }
                }
            }
            //checks for new airliner types for purchase
            foreach (AirlinerType aType in AirlinerTypes.GetTypes(a => a.Produced.From.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()))
            {
                GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airliner_News, GameObject.GetInstance().GameTime, "New airliner type available", string.Format("{0} has finished the design of {1} and it is now available for purchase", aType.Manufacturer.Name, aType.Name)));

                if (!AirlineFacilities.GetFacilities(f => f is PilotTrainingFacility).Exists(f => ((PilotTrainingFacility)f).AirlinerFamily == aType.AirlinerFamily))
                    AirlineFacilities.AddFacility(new PilotTrainingFacility("airlinefacilities", aType.AirlinerFamily, 9000, 1000, GameObject.GetInstance().GameTime.Year, 0, 0, aType.AirlinerFamily));
            }
            //checks for airliner types which are out of production
            foreach (AirlinerType aType in AirlinerTypes.GetTypes(a => a.Produced.To.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()))
            {
                GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airliner_News, GameObject.GetInstance().GameTime, "Airliner type out of production", string.Format("{0} has taken {1} out of production", aType.Manufacturer.Name, aType.Name)));

                Boolean lastFromManufacturer = AirlinerTypes.GetAllTypes().Where(t=>t.Manufacturer == aType.Manufacturer && t.Produced.To > GameObject.GetInstance().GameTime).Count() == 0;

                if (lastFromManufacturer)
                {
                    var manufacturerContracts = Airlines.GetAllAirlines().Where(a => a.Contract != null && a.Contract.Manufacturer == aType.Manufacturer);

                    foreach (Airline contractedAirline in manufacturerContracts)
                        contractedAirline.Contract = null;
                }
            }
            //checks for airport facilities for the human airline
            var humanAirportFacilities = (from f in humanAirlines.SelectMany(ai => ai.Airports.SelectMany(a => a.getAirportFacilities(ai))) where f.FinishedDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString() select f);

            foreach (AirlineAirportFacility facility in humanAirportFacilities)
            {
                GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airport_News, GameObject.GetInstance().GameTime, "Airport facility", string.Format("Your airport facility {0} at [LI airport={1}] is now finished building", facility.Facility.Name, facility.Airport.Profile.IATACode)));
                facility.FinishedDate = GameObject.GetInstance().GameTime;
            }
            //checks for changed flight restrictions
            foreach (FlightRestriction restriction in FlightRestrictions.GetRestrictions().FindAll(r => r.StartDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString() || r.EndDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()))
            {
                string restrictionNewsText = "";
                if (restriction.Type == FlightRestriction.RestrictionType.Flights)
                {
                    if (restriction.StartDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString())
                        restrictionNewsText = string.Format("All flights from {0} to {1} have been banned", restriction.From.Name, restriction.To.Name);
                    else
                        restrictionNewsText = string.Format("The ban for all flights from {0} to {1} have been lifted", restriction.From.Name, restriction.To.Name);
                }
                if (restriction.Type == FlightRestriction.RestrictionType.Airlines)
                {
                    if (restriction.StartDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString())
                        restrictionNewsText = string.Format("All airlines flying from {0} flying to {1} have been blacklisted", restriction.From.Name, restriction.To.Name);
                    else
                        restrictionNewsText = string.Format("The blacklist on all airlines from {0} flying to {1} have been lifted", restriction.From.Name, restriction.To.Name);

                }
                if (restriction.StartDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString())
                {
                    if (restriction.Type == FlightRestriction.RestrictionType.Flights)
                    {
                        var bannedRoutes = (from r in Airlines.GetAllAirlines().SelectMany(a => a.Routes) where FlightRestrictions.HasRestriction(r.Destination1.Profile.Country, r.Destination2.Profile.Country, GameObject.GetInstance().GameTime) select r);

                        foreach (Route route in bannedRoutes)
                        {
                            route.Banned = true;
                        }
                    }
                }
                GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Standard_News, GameObject.GetInstance().GameTime, "Flight restriction", restrictionNewsText));

            }
            //checks for historic events
            foreach (HistoricEvent e in HistoricEvents.GetHistoricEvents(GameObject.GetInstance().GameTime))
            {
                GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Standard_News, GameObject.GetInstance().GameTime, e.Name, e.Text));

                foreach (HistoricEventInfluence influence in e.Influences)
                {
                    SetHistoricEventInfluence(influence, false);
                }
            }
            //checks for historic events influences ending
            foreach (HistoricEventInfluence influence in HistoricEvents.GetHistoricEventInfluences(GameObject.GetInstance().GameTime))
            {
                SetHistoricEventInfluence(influence, true);
            }

            //updates airports
            Parallel.ForEach(Airports.GetAllActiveAirports(), airport =>
               {

               //AirportHelpers.CreateAirportWeather(airport);

               if (Settings.GetInstance().MailsOnBadWeather && humanAirlines.SelectMany(a => a.Airports.FindAll(aa => aa == airport)).Count() > 0 && (airport.Weather[airport.Weather.Length - 1].WindSpeed == Weather.eWindSpeed.Violent_Storm || airport.Weather[airport.Weather.Length - 1].WindSpeed == Weather.eWindSpeed.Hurricane))
               {
                   GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airport_News, GameObject.GetInstance().GameTime, Translator.GetInstance().GetString("News", "1002"), string.Format(Translator.GetInstance().GetString("News", "1002", "message"), airport.Profile.IATACode, GameObject.GetInstance().GameTime.AddDays(airport.Weather.Length - 1).DayOfWeek)));
               }
               // chs, 2011-01-11 changed for delivery of terminals
               foreach (Terminal terminal in airport.Terminals.getTerminals())
               {
                   if (terminal.DeliveryDate.Year == GameObject.GetInstance().GameTime.Year && terminal.DeliveryDate.Month == GameObject.GetInstance().GameTime.Month && terminal.DeliveryDate.Day == GameObject.GetInstance().GameTime.Day)
                   {
                       if (terminal.Airline == null)
                           GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airport_News, GameObject.GetInstance().GameTime, "Construction of terminal", string.Format("[LI airport={0}], {1} has build a new terminal with {2} gates", airport.Profile.IATACode, airport.Profile.Country.Name, terminal.Gates.NumberOfGates)));

                       if (terminal.Airline != null && terminal.Airline.IsHuman)
                           GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airport_News, GameObject.GetInstance().GameTime, "Construction of terminal", string.Format("Your terminal at [LI airport={0}], {1} is now finished and ready for use.", airport.Profile.IATACode, airport.Profile.Country.Name)));

                       if (terminal.Airline != null)
                       {
                           List<AirportContract> oldContracts = new List<AirportContract>(airport.getAirlineContracts(terminal.Airline));

                           if (oldContracts.Count > 0)
                           {
                               int totalGates = oldContracts.Sum(c => c.NumberOfGates);

                               int gatesDiff = totalGates - terminal.Gates.NumberOfGates;

                               if (gatesDiff > 0)
                               {
                                   int length = oldContracts.Max(c => c.Length);
                                   AirportContract newContract = new AirportContract(terminal.Airline, airport, AirportContract.ContractType.Full, GameObject.GetInstance().GameTime, gatesDiff, length, AirportHelpers.GetYearlyContractPayment(airport, AirportContract.ContractType.Full, gatesDiff, length) / 2, true);

                                   AirportHelpers.AddAirlineContract(newContract);

                               }

                               foreach (AirportContract oldContract in oldContracts)
                               {
                                   airport.removeAirlineContract(oldContract);

                                   for (int i = 0; i < oldContract.NumberOfGates; i++)
                                   {
                                       Gate oldGate = airport.Terminals.getGates().Where(g => g.Airline == terminal.Airline).First();
                                       oldGate.Airline = null;
                                   }
                               }

                           }
                           double yearlyPayment = AirportHelpers.GetYearlyContractPayment(airport, AirportContract.ContractType.Full, terminal.Gates.NumberOfGates, 20);

                           AirportHelpers.AddAirlineContract(new AirportContract(terminal.Airline, airport, AirportContract.ContractType.Full, GameObject.GetInstance().GameTime, terminal.Gates.NumberOfGates, 20, yearlyPayment * 0.75, true, false, false));

                           if (terminal.Airport.getAirportFacility(terminal.Airline, AirportFacility.FacilityType.CheckIn).TypeLevel == 0)
                           {

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

                               terminal.Airport.addAirportFacility(terminal.Airline, checkinFacility, GameObject.GetInstance().GameTime);

                           }

                       }

                   }
                   //new gates in an existing terminal
                   else
                   {
                       int numberOfNewGates = terminal.Gates.getGates().Count(g => g.DeliveryDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString());

                       if (numberOfNewGates > 0)
                       {
                           GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airport_News, GameObject.GetInstance().GameTime, "Expansion of terminal", string.Format("[LI airport={0}], {1} has expanded {2} with {3} gates", airport.Profile.IATACode, airport.Profile.Country.Name, terminal.Name, numberOfNewGates)));

                           double yearlyPayment = AirportHelpers.GetYearlyContractPayment(airport, AirportContract.ContractType.Full, numberOfNewGates + terminal.Gates.NumberOfGates, 20);

                           AirportContract terminalContract = airport.AirlineContracts.Find(c => c.Terminal != null && c.Terminal == terminal);

                           if (terminalContract != null)
                           {
                               terminalContract.NumberOfGates += numberOfNewGates;
                               terminalContract.YearlyPayment = yearlyPayment;

                               for (int i = 0; i < numberOfNewGates; i++)
                               {
                                   Gate newGate = airport.Terminals.getGates().Where(g => g.Airline == null).First();
                                   newGate.Airline = terminalContract.Airline;
                               }
                           }
                       }

                   }
                   //expired contracts
                   var airlineContracts = new List<AirportContract>(airport.AirlineContracts.FindAll(c => c.ExpireDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()));

                   foreach (AirportContract contract in airlineContracts)
                   {
                       if (contract.AutoRenew)
                       {
                           contract.ContractDate = GameObject.GetInstance().GameTime;
                           contract.ExpireDate = GameObject.GetInstance().GameTime.AddYears(contract.Length);

                           if (contract.Airline.IsHuman)
                               GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airport_News, GameObject.GetInstance().GameTime, "Airport contract renewed", string.Format("Your contract for {0} gates at [LI airport={1}], {2} is now been renewed", contract.NumberOfGates, contract.Airport.Profile.IATACode, contract.Airport.Profile.Country.Name)));

                       }
                       else
                       {
                           for (int i = 0; i < contract.NumberOfGates; i++)
                           {
                               Gate gate = airport.Terminals.getGates().Where(g => g.Airline == contract.Airline).First();
                               gate.Airline = null;

                           }

                           if (contract.Airline.IsHuman)
                           {
                               int totalContractGates = airport.AirlineContracts.Where(c => c.Airline.IsHuman).Sum(c => c.NumberOfGates);

                               var airlineRoutes = new List<Route>(AirportHelpers.GetAirportRoutes(airport, contract.Airline));

                               var remainingContracts = new List<AirportContract>(airport.AirlineContracts.FindAll(c => c.Airline == contract.Airline && c != contract));

                               Boolean canFillRoutes = AirportHelpers.CanFillRoutesEntries(airport, contract.Airline, remainingContracts, Weather.Season.All_Year);

                               if (!canFillRoutes)
                               {
                                   GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airport_News, GameObject.GetInstance().GameTime, "Airport contract expired", string.Format("Your contract for {0} gates at [LI airport={1}], {2} is now expired, and a number of routes has been cancelled", contract.NumberOfGates, contract.Airport.Profile.IATACode, contract.Airport.Profile.Country.Name)));

                                   int currentRoute = 0;
                                   while (!canFillRoutes)
                                   {
                                       Route routeToDelete = airlineRoutes[currentRoute];

                                       foreach (FleetAirliner fAirliner in routeToDelete.getAirliners())
                                       {
                                           fAirliner.Status = FleetAirliner.AirlinerStatus.Stopped;
                                           fAirliner.removeRoute(routeToDelete);
                                       }

                                       contract.Airline.removeRoute(routeToDelete);

                                       currentRoute++;

                                       canFillRoutes = AirportHelpers.CanFillRoutesEntries(airport, contract.Airline, remainingContracts, Weather.Season.All_Year);
                                   }

                               }
                               else
                               {
                                   GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airport_News, GameObject.GetInstance().GameTime, "Airport contract expired", string.Format("Your contract for {0} gates at [LI airport={1}], {2} is now expired", contract.NumberOfGates, contract.Airport.Profile.IATACode, contract.Airport.Profile.Country.Name)));

                               }

                               airport.removeAirlineContract(contract);
                           }
                           else
                           {
                               int numberOfRoutes = AirportHelpers.GetAirportRoutes(airport, contract.Airline).Count;

                               if (numberOfRoutes > 0)
                               {
                                   contract.ContractDate = GameObject.GetInstance().GameTime;
                                   contract.ExpireDate = GameObject.GetInstance().GameTime.AddYears(contract.Length);
                               }
                               else
                                   airport.removeAirlineContract(contract);
                           }
                       }
                   }

               }

               }
               );
            //checks for airliners for the human airline
            foreach (FleetAirliner airliner in humanAirlines.SelectMany(a => a.Fleet.FindAll(f => f.Airliner.BuiltDate == GameObject.GetInstance().GameTime && f.Purchased != FleetAirliner.PurchasedType.BoughtDownPayment)))
            {
                if (airliner.Airliner.Airline == GameObject.GetInstance().HumanAirline)
                    GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Fleet_News, GameObject.GetInstance().GameTime, "Delivery of airliner", string.Format("Your new airliner [LI airliner={0}] as been delivered to your fleet.\nThe airliner is currently at [LI airport={1}], {2}", airliner.Airliner.TailNumber, airliner.Homebase.Profile.IATACode, airliner.Homebase.Profile.Country.Name)));
                else
                    GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Fleet_News, GameObject.GetInstance().GameTime, "Delivery of airliner", string.Format("The new airliner [LI airliner={0}] as been delivered for [LI airline={1}].\nThe airliner is currently at [LI airport={2}], {3}", airliner.Airliner.TailNumber, airliner.Airliner.Airline.Profile.IATACode, airliner.Homebase.Profile.IATACode, airliner.Homebase.Profile.Country.Name)));

            }

            Parallel.ForEach(Airlines.GetAllAirlines(), airline =>
            {
                lock (airline.Fleet)
                {
                    var fleet = new List<FleetAirliner>(airline.Fleet);
                    foreach (FleetAirliner airliner in fleet.FindAll(a => a != null && a.Airliner.BuiltDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString() && a.Purchased == FleetAirliner.PurchasedType.BoughtDownPayment))
                    {
                        if (airline.Money >= airliner.Airliner.Type.Price)
                        {
                            AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -airliner.Airliner.Type.Price);
                            airliner.Purchased = FleetAirliner.PurchasedType.Bought;

                        }
                        else
                        {
                            airline.removeAirliner(airliner);

                            if (airline.IsHuman)
                                GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Fleet_News, GameObject.GetInstance().GameTime, "Delivery of airliner", string.Format("Your new airliner {0} can't be delivered to your fleet.\nYou don't have enough money to purchase it.", airliner.Name)));

                        }
                    }
                }

                if (airline.Contract != null && airline.Contract.ExpireDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString())
                {
                    int missingAirliners = airline.Contract.Airliners - airline.Contract.PurchasedAirliners;

                    if (missingAirliners > 0)
                    {
                        double missingFee = (airline.Contract.getTerminationFee() / (airline.Contract.Length * 2)) * missingAirliners;
                        AirlineHelpers.AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -missingFee);

                        if (airline.IsHuman)
                            GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Fleet_News, GameObject.GetInstance().GameTime, "Contract expired", string.Format("Your contract with {0} has now expired.\nYou didn't purchased enough airliners with costs a fee of {1:C} for missing {2} airliners", airline.Contract.Manufacturer.Name, missingFee, missingAirliners)));
                    }
                    else
                        if (airline.IsHuman)
                            GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Fleet_News, GameObject.GetInstance().GameTime, "Contract expired", string.Format("Your contract with {0} has now expired.", airline.Contract.Manufacturer.Name)));

                    airline.Contract = null;

                }
                //checks for students educated
                var educatedStudents = airline.FlightSchools.SelectMany(f => f.Students.FindAll(s => s.EndDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()));

                foreach (PilotStudent student in educatedStudents)
                {
                    Pilot pilot = new Pilot(student.Profile, GameObject.GetInstance().GameTime, student.Rating);

                    if (student.AirlinerFamily != "")
                        pilot.addAirlinerFamily(student.AirlinerFamily);

                    student.Instructor.removeStudent(student);
                    student.Instructor.FlightSchool.removeStudent(student);
                    student.Instructor = null;

                    airline.addPilot(pilot);

                    if (airline.IsHuman)
                        GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Flight_News, GameObject.GetInstance().GameTime, Translator.GetInstance().GetString("News", "1006"), string.Format(Translator.GetInstance().GetString("News", "1006", "message"), pilot.Profile.Name)));

                }

                var trainedPilots = airline.Pilots.Where(p => p.Training != null && p.Training.EndDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString());

                foreach (Pilot pilot in trainedPilots)
                {
                    pilot.addAirlinerFamily(pilot.Training.AirlinerFamily);

                    if (airline.IsHuman)
                        GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Flight_News, GameObject.GetInstance().GameTime, Translator.GetInstance().GetString("News", "1015"), string.Format(Translator.GetInstance().GetString("News", "1015", "message"), pilot.Profile.Name, pilot.Training.AirlinerFamily)));

                    pilot.Training = null;

                }

            }

            );
            //checks for mergers
            foreach (AirlineMerger merger in AirlineMergers.GetAirlineMergers(GameObject.GetInstance().GameTime))
            {
                if (merger.Type == AirlineMerger.MergerType.Merger)
                {
                    AirlineHelpers.SwitchAirline(merger.Airline2, merger.Airline1);

                    Airlines.RemoveAirline(merger.Airline2);

                    if (merger.NewName != null && merger.NewName.Length > 1)
                        merger.Airline1.Profile.Name = merger.NewName;
                }
                if (merger.Type == AirlineMerger.MergerType.Subsidiary)
                {
                    string oldLogo = merger.Airline2.Profile.Logo;

                    SubsidiaryAirline sAirline = new SubsidiaryAirline(merger.Airline1, merger.Airline2.Profile, merger.Airline2.Mentality, merger.Airline2.MarketFocus, merger.Airline2.License, merger.Airline2.AirlineRouteFocus);

                    AirlineHelpers.SwitchAirline(merger.Airline2, merger.Airline1);

                    merger.Airline1.addSubsidiaryAirline(sAirline);

                    Airlines.RemoveAirline(merger.Airline2);

                    sAirline.Profile.Logos = merger.Airline2.Profile.Logos;
                    sAirline.Profile.Color = merger.Airline2.Profile.Color;

                }

                GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airline_News, GameObject.GetInstance().GameTime, "Airline merger", merger.Name));

            }
            /*
            //does monthly budget work
               DateTime budgetExpires = GameObject.GetInstance().HumanAirline.Budget.BudgetExpires;
            if (budgetExpires <= GameObject.GetInstance().GameTime.AddDays(30))
            {
                GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airline_News, GameObject.GetInstance().GameTime, "Budget Expires Soon", "Your budget will expire within the next 30 days. Please go to the budget screen and adjust it as needed and click 'Apply'."));
            }
            else if (budgetExpires <= GameObject.GetInstance().GameTime)
            {
                //GraphicsModel.PageModel.PageFinancesModel.PageFinances.ResetValues();
            }

            if (GameObject.GetInstance().HumanAirline.Money < GameObject.GetInstance().HumanAirline.Budget.TotalBudget / 12)
            {
                WPFMessageBox.Show("Low Cash!", "Your current cash is less than your budget deduction for the month! Decrease your budget immediately or you will be negative!", WPFMessageBoxButtons.Ok);
            }
            else { GameObject.GetInstance().HumanAirline.Money -= GameObject.GetInstance().HumanAirline.Budget.TotalBudget / 12; }
             * */

            //check for insurance settlements and do maintenance
            foreach (Airline a in Airlines.GetAllAirlines())
            {
                AirlineHelpers.CheckInsuranceSettlements(a);

                var airliners = new List<FleetAirliner>(a.Fleet);
                foreach (FleetAirliner airliner in airliners)
                {
                    if (airliner != null)
                    {
                        FleetAirlinerHelpers.DoMaintenance(airliner);
                        FleetAirlinerHelpers.RestoreMaintRoutes(airliner);
                    }
                }
            }

            if (GameObject.GetInstance().GameTime.Day % 7 == 0)
            {
                GameObject.GetInstance().HumanAirline.OverallScore += StatisticsHelpers.GetWeeklyScore(GameObject.GetInstance().HumanAirline);
            }
        }
Ejemplo n.º 21
0
        //rents a "standard" amount of gates at an airport for an airline
        public static Boolean RentGates(Airport airport, Airline airline, AirportContract.ContractType type)
        {
            int maxGates = airport.Terminals.getFreeGates();

            int gatesToRent = Math.Min(maxGates, (int)(airline.Mentality) + 2);

            if (gatesToRent == 0)
                return false;

            RentGates(airport, airline,type, gatesToRent);

            return true;
        }
Ejemplo n.º 22
0
        public static void RentGates(Airport airport, Airline airline, int gates)
        {
            int currentgates = airport.AirlineContracts.Where(a => a.Airline == airline).Sum(c => c.NumberOfGates);
            AirportContract contract = new AirportContract(airline, airport, GameObject.GetInstance().GameTime, gates, 20, GetYearlyContractPayment(airport, gates, 20));

            if (currentgates == 0)
            {
                airport.addAirlineContract(contract);
            }
            else
            {
                foreach (AirportContract c in airport.AirlineContracts.Where(a => a.Airline == airline))
                {
                c.NumberOfGates += gates;
                }
            }
        }
Ejemplo n.º 23
0
        //loads a game
        public static void LoadGame(string name)
        {
            if (null == name || name == "")
            {
                WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "101"), Translator.GetInstance().GetString("MessageBox", "101", "message"), WPFMessageBoxButtons.Ok);
                return;
            }
            string fileName = AppSettings.getCommonApplicationDataPath() + "\\saves\\" + name + ".sav";

            XmlDocument doc = new XmlDocument();

            using (FileStream fs = new FileStream(fileName, FileMode.Open))
            {
                Stream s;

                s = new GZipStream(fs, CompressionMode.Decompress);
                doc.Load(s);
                s.Close();

            }
            //doc.Load(AppSettings.getDataPath() + "\\saves\\" + name + ".xml");
            XmlElement root = doc.DocumentElement;

            DateTime gameTime = DateTime.Parse(root.Attributes["time"].Value, new CultureInfo("de-DE"));
            GameObject.GetInstance().GameTime = gameTime;

            XmlNodeList tailnumbersList = root.SelectNodes("//tailnumbers/tailnumber");

            foreach (XmlElement tailnumberNode in tailnumbersList)
            {
                Country country = Countries.GetCountry(tailnumberNode.Attributes["country"].Value);

                if (country != null)
                    country.TailNumbers.LastTailNumber = tailnumberNode.Attributes["value"].Value;

            }

            XmlNodeList airlinerTypesList = root.SelectNodes("//airlinertypes/airlinertype");

            foreach (XmlElement airlinerTypeNode in airlinerTypesList)
            {
                AirlinerType.TypeOfAirliner airlinerType = (AirlinerType.TypeOfAirliner)Enum.Parse(typeof(AirlinerType.TypeOfAirliner), airlinerTypeNode.Attributes["type"].Value);
                AirlinerType baseType = AirlinerTypes.GetType(airlinerTypeNode.Attributes["basetype"].Value);
                string airlinerTypeName = airlinerTypeNode.Attributes["name"].Value;

                AirlinerType type = null;

                if (airlinerType == AirlinerType.TypeOfAirliner.Passenger)
                {
                    int cabincrew = Convert.ToInt16(airlinerTypeNode.Attributes["cabincrew"].Value);
                    int passengers = Convert.ToInt16(airlinerTypeNode.Attributes["passengers"].Value);
                    int maxclasses = Convert.ToInt16(airlinerTypeNode.Attributes["maxclasses"].Value);

                    type = new AirlinerPassengerType(baseType.Manufacturer,airlinerTypeName,"",passengers,baseType.CockpitCrew,cabincrew,baseType.CruisingSpeed,baseType.Range,baseType.Wingspan,baseType.Length,baseType.FuelConsumption,baseType.Price,maxclasses,baseType.MinRunwaylength,baseType.FuelCapacity,baseType.Body,baseType.RangeType,baseType.Engine,baseType.Produced,baseType.ProductionRate,false,false);
                }
                if (airlinerType == AirlinerType.TypeOfAirliner.Cargo)
                {
                    double cargo = Convert.ToDouble(airlinerTypeNode.Attributes["cargo"].Value,new CultureInfo("de-DE", false));
                    type = new AirlinerCargoType(baseType.Manufacturer,airlinerTypeName,"",baseType.CockpitCrew,cargo,baseType.CruisingSpeed,baseType.Range,baseType.Wingspan,baseType.Length,baseType.FuelConsumption,baseType.Price,baseType.MinRunwaylength,baseType.FuelCapacity,baseType.Body,baseType.RangeType,baseType.Engine,baseType.Produced,baseType.ProductionRate,false, false);
                }
                type.BaseType = baseType;

                AirlinerTypes.AddType(type);

            }

             Airliners.Clear();

             XmlNodeList airlinersList = root.SelectNodes("//airliners/airliner");

             Parallel.For(0, airlinersList.Count, i =>
              //foreach (XmlElement airlinerNode in airlinersList)
              {
                  XmlElement airlinerNode = (XmlElement)airlinersList[i];
                  AirlinerType type = AirlinerTypes.GetType(airlinerNode.Attributes["type"].Value);

                  if (type != null)
                  {
                      string tailnumber = airlinerNode.Attributes["tailnumber"].Value;
                      string id = airlinerNode.HasAttribute("id") ? airlinerNode.Attributes["id"].Value : tailnumber;

                      string last_service = airlinerNode.Attributes["last_service"].Value;
                      DateTime built = DateTime.Parse(airlinerNode.Attributes["built"].Value, new CultureInfo("de-DE", false));
                      double flown = Convert.ToDouble(airlinerNode.Attributes["flown"].Value, new CultureInfo("de-DE", false));
                      double damaged = Convert.ToDouble(airlinerNode.Attributes["damaged"].Value, new CultureInfo("de-DE", false));

                      Airliner airliner = new Airliner(id, type, tailnumber, built);
                      airliner.Condition = damaged;
                      airliner.Flown = flown;
                      airliner.clearAirlinerClasses();

                      XmlNodeList airlinerClassList = airlinerNode.SelectNodes("classes/class");

                      foreach (XmlElement airlinerClassNode in airlinerClassList)
                      {
                          AirlinerClass.ClassType airlinerClassType = (AirlinerClass.ClassType)Enum.Parse(typeof(AirlinerClass.ClassType), airlinerClassNode.Attributes["type"].Value);
                          int airlinerClassSeating = Convert.ToInt16(airlinerClassNode.Attributes["seating"].Value);

                          AirlinerClass aClass = new AirlinerClass(airlinerClassType, airlinerClassSeating);
                          // chs, 2011-13-10 added for loading of airliner facilities
                          XmlNodeList airlinerClassFacilitiesList = airlinerClassNode.SelectNodes("facilities/facility");
                          foreach (XmlElement airlinerClassFacilityNode in airlinerClassFacilitiesList)
                          {
                              AirlinerFacility.FacilityType airlinerFacilityType = (AirlinerFacility.FacilityType)Enum.Parse(typeof(AirlinerFacility.FacilityType), airlinerClassFacilityNode.Attributes["type"].Value);

                              AirlinerFacility aFacility = AirlinerFacilities.GetFacility(airlinerFacilityType, airlinerClassFacilityNode.Attributes["uid"].Value);
                              aClass.forceSetFacility(aFacility);
                          }

                          airliner.addAirlinerClass(aClass);
                      }

                      Airliners.AddAirliner(airliner);
                  }
              });

             Airlines.Clear();

             XmlNodeList airlinesList = root.SelectNodes("//airlines/airline[@subsidiary='False']");

             foreach (XmlElement airlineNode in airlinesList)
                 LoadAirline(airlineNode);

             XmlNodeList subsidiaryList = root.SelectNodes("//airlines/airline[@subsidiary='True']");

             foreach (XmlElement airlineNode in subsidiaryList)
                 LoadAirline(airlineNode);

             XmlNodeList airportsList = root.SelectNodes("//airports/airport");

             List<Airport> airportsToKeep = new List<Airport>();

             foreach (XmlElement airportNode in airportsList)
             {
                 Airport airport = Airports.GetAirportFromID(airportNode.Attributes["id"].Value);
                 airportsToKeep.Add(airport);

                 /*
                  *   XmlElement airportPaxNode = xmlDoc.CreateElement("paxvalue");
                    airportPaxNode.SetAttribute("from", paxValue.FromYear.ToString());
                    airportPaxNode.SetAttribute("to", paxValue.ToYear.ToString());
                    airportPaxNode.SetAttribute("size", paxValue.Size.ToString());
                    airportPaxNode.SetAttribute("pax", paxValue.Pax.ToString());
                    airportPaxNode.SetAttribute("inflationbefore", paxValue.InflationBeforeYear.ToString());
                    airportPaxNode.SetAttribute("inflationafter", paxValue.InflationAfterYear.ToString());
            */

                 airport.Income = Convert.ToInt64(airportNode.Attributes["income"].Value);

                 airport.Profile.PaxValues.Clear();

                 XmlNodeList paxvaluesList = airportNode.SelectNodes("paxvalues/paxvalue");

                 foreach (XmlElement paxElement in paxvaluesList)
                 {
                     int fromYear = Convert.ToInt16(paxElement.Attributes["from"].Value);
                     int toYear = Convert.ToInt16(paxElement.Attributes["to"].Value);
                     GeneralHelpers.Size airportSize = (GeneralHelpers.Size)Enum.Parse(typeof(GeneralHelpers.Size), paxElement.Attributes["size"].Value);
                     double pax = Convert.ToDouble(paxElement.Attributes["pax"].Value);
                     double inflationBefore = Convert.ToDouble(paxElement.Attributes["inflationbefore"].Value);
                     double inflationAfter = Convert.ToDouble(paxElement.Attributes["inflationafter"].Value);

                     PaxValue paxValue = new PaxValue(fromYear, toYear, airportSize, pax);
                     paxValue.InflationAfterYear = inflationAfter;
                     paxValue.InflationBeforeYear = inflationBefore;

                     airport.Profile.PaxValues.Add(paxValue);
                 }

                  XmlNodeList runwaysList = airportNode.SelectNodes("runways/runway");

                 foreach (XmlElement runwayElement in runwaysList)
                 {
                     string runwayName = runwayElement.Attributes["name"].Value;
                     long runwayLenght = Convert.ToInt64(runwayElement.Attributes["lenght"].Value);
                     Runway.SurfaceType runwaySurface = (Runway.SurfaceType)Enum.Parse(typeof(Runway.SurfaceType), runwayElement.Attributes["surface"].Value);
                     DateTime runwayDate = DateTime.Parse(runwayElement.Attributes["date"].Value, new CultureInfo("de-DE", false));

                     airport.Runways.Add(new Runway(runwayName, runwayLenght, runwaySurface, runwayDate, false));
                 }

                 XmlNodeList airportHubsList = airportNode.SelectNodes("hubs/hub");
                // airport.Hubs.Clear();

                 foreach (XmlElement airportHubElement in airportHubsList)
                 {
                     Airline airline = Airlines.GetAirline(airportHubElement.Attributes["airline"].Value);
                    // airport.Hubs.Add(new Hub(airline,null));
                 }

                 XmlNodeList airportWeatherList = airportNode.SelectNodes("weathers/weather");

                 for (int i = 0; i < airportWeatherList.Count; i++)
                 {
                     XmlElement airportWeatherElement = airportWeatherList[i] as XmlElement;

                     DateTime weatherDate = DateTime.Parse(airportWeatherElement.Attributes["date"].Value, new CultureInfo("de-DE", false));
                     Weather.WindDirection windDirection = (Weather.WindDirection)Enum.Parse(typeof(Weather.WindDirection), airportWeatherElement.Attributes["direction"].Value);
                     Weather.eWindSpeed windSpeed = (Weather.eWindSpeed)Enum.Parse(typeof(Weather.eWindSpeed), airportWeatherElement.Attributes["windspeed"].Value);
                     Weather.CloudCover cover = airportWeatherElement.HasAttribute("cover") ? (Weather.CloudCover)Enum.Parse(typeof(Weather.CloudCover), airportWeatherElement.Attributes["cover"].Value) : Weather.CloudCover.Clear;
                     Weather.Precipitation precip = airportWeatherElement.HasAttribute("precip") ? (Weather.Precipitation)Enum.Parse(typeof(Weather.Precipitation), airportWeatherElement.Attributes["precip"].Value) : Weather.Precipitation.None;
                     double temperatureLow = airportWeatherElement.HasAttribute("temperatureLow") ? Convert.ToDouble(airportWeatherElement.Attributes["temperaturelow"].Value, new CultureInfo("de-DE", false)) : 0;
                     double temperatureHigh = airportWeatherElement.HasAttribute("temperatureHigh") ? Convert.ToDouble(airportWeatherElement.Attributes["temperaturehigh"].Value, new CultureInfo("de-DE", false)) : 20;

                     XmlNodeList airportTemperatureList = airportWeatherElement.SelectNodes("temperatures/temperature");
                     HourlyWeather[] temperatures = new HourlyWeather[airportTemperatureList.Count];

                     int t = 0;
                     foreach (XmlElement airportTemperatureNode in airportTemperatureList)
                     {
                         double hourlyTemperature = Convert.ToDouble(airportTemperatureNode.Attributes["temp"].Value, new CultureInfo("de-DE", false));
                         Weather.CloudCover hourlyCover = (Weather.CloudCover)Enum.Parse(typeof(Weather.CloudCover), airportTemperatureNode.Attributes["cover"].Value);
                         Weather.Precipitation hourlyPrecip = (Weather.Precipitation)Enum.Parse(typeof(Weather.Precipitation), airportTemperatureNode.Attributes["precip"].Value);
                         Weather.eWindSpeed hourlyWindspeed = (Weather.eWindSpeed)Enum.Parse(typeof(Weather.eWindSpeed), airportTemperatureNode.Attributes["windspeed"].Value);
                         Weather.WindDirection hourlyDirection = (Weather.WindDirection)Enum.Parse(typeof(Weather.WindDirection), airportTemperatureNode.Attributes["direction"].Value);

                         temperatures[t] = new HourlyWeather(hourlyTemperature, hourlyCover, hourlyPrecip, hourlyWindspeed, hourlyDirection);
                         t++;
                     }

                     airport.Weather[i] = new Weather(weatherDate, windSpeed, windDirection, cover, precip, temperatures, temperatureLow, temperatureHigh);
                 }

                 XmlNodeList airportStatList = airportNode.SelectNodes("stats/stat");

                 foreach (XmlElement airportStatNode in airportStatList)
                 {
                     int year = Convert.ToInt32(airportStatNode.Attributes["year"].Value);
                     Airline airline = Airlines.GetAirline(airportStatNode.Attributes["airline"].Value);
                     string statType = airportStatNode.Attributes["type"].Value;
                     int statValue = Convert.ToInt32(airportStatNode.Attributes["value"].Value);
                     airport.Statistics.setStatisticsValue(year, airline, StatisticsTypes.GetStatisticsType(statType), statValue);
                 }

                 XmlNodeList airportFacilitiesList = airportNode.SelectNodes("facilities/facility");
                 airport.clearFacilities();

                 foreach (XmlElement airportFacilityNode in airportFacilitiesList)
                 {
                     Airline airline = Airlines.GetAirline(airportFacilityNode.Attributes["airline"].Value);
                     AirportFacility airportFacility = AirportFacilities.GetFacility(airportFacilityNode.Attributes["name"].Value);
                     DateTime finishedDate = DateTime.Parse(airportFacilityNode.Attributes["finished"].Value, new CultureInfo("de-DE", false));

                     airport.addAirportFacility(airline, airportFacility, finishedDate);
                 }
                 airport.Terminals.clear();

                 XmlNodeList terminalsList = airportNode.SelectNodes("terminals/terminal");

                 foreach (XmlElement terminalNode in terminalsList)
                 {
                     DateTime deliveryDate = DateTime.Parse(terminalNode.Attributes["delivery"].Value, new CultureInfo("de-DE", false));
                     Airline owner = Airlines.GetAirline(terminalNode.Attributes["owner"].Value);
                     string terminalName = terminalNode.Attributes["name"].Value;
                     int gates = Convert.ToInt32(terminalNode.Attributes["totalgates"].Value);

                     Terminal terminal = new Terminal(airport, owner, terminalName, gates, deliveryDate);
                     terminal.Gates.clear();

                     XmlNodeList airportGatesList = terminalNode.SelectNodes("gates/gate");

                     foreach (XmlElement airportGateNode in airportGatesList)
                     {
                         DateTime gateDeliveryDate = DateTime.Parse(airportGateNode.Attributes["delivery"].Value, new CultureInfo("de-DE", false));
                         Gate gate = new Gate(gateDeliveryDate);

                         terminal.Gates.addGate(gate);
                     }

                     airport.addTerminal(terminal);

                 }
                 airport.clearAirlineContracts();

                 XmlNodeList contractsList = airportNode.SelectNodes("contracts/contract");

                 foreach (XmlElement contractNode in contractsList)
                 {
                     Airline contractAirline = Airlines.GetAirline(contractNode.Attributes["airline"].Value);
                     int contractLength = Convert.ToInt16(contractNode.Attributes["length"].Value);
                     DateTime contractDate = DateTime.Parse(contractNode.Attributes["date"].Value, new CultureInfo("de-DE", false));
                     int contractGates = Convert.ToInt16(contractNode.Attributes["gates"].Value);
                     double contractPayment = Convert.ToDouble(contractNode.Attributes["payment"].Value, new CultureInfo("de-DE", false));
                     Boolean contractExclusive = Convert.ToBoolean(contractNode.Attributes["exclusive"].Value);
                     Terminal contractTerminal = contractNode.HasAttribute("terminal") ? airport.Terminals.AirportTerminals.Find(t => t.Name == contractNode.Attributes["terminal"].Value) : null;

                     AirportContract contract = new AirportContract(contractAirline, airport,AirportContract.ContractType.Full, contractDate, contractGates, contractLength, contractPayment,true,false, contractExclusive, contractTerminal);
                     AirportHelpers.AddAirlineContract(contract);

                 }

             }

             Airports.RemoveAirports(a => !airportsToKeep.Contains(a));

             XmlNodeList airportDestinationsList = root.SelectNodes("//airportdestinations/airportdestination");

             foreach (XmlElement airportDestinationElement in airportDestinationsList)
             {
                 Airport targetAirport = Airports.GetAirport(airportDestinationElement.Attributes["id"].Value);

                 if (targetAirport != null)
                 {
                     targetAirport.clearDestinationPassengers();

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

                     Parallel.For(0, destinationsList.Count, i =>
                     //foreach (XmlElement destinationElement in destinationsList)
                     {
                         XmlElement destinationElement = (XmlElement)destinationsList[i];
                         Airport destAirport = Airports.GetAirport(destinationElement.Attributes["id"].Value);

                         if (destAirport != null)
                         {
                             ushort rate = ushort.Parse(destinationElement.Attributes["rate"].Value);
                             long destPassengers = Convert.ToInt64(destinationElement.Attributes["passengers"].Value);

                             targetAirport.addPassengerDestinationStatistics(destAirport, destPassengers);
                             targetAirport.addDestinationPassengersRate(new DestinationDemand(destAirport.Profile.IATACode, rate));

                             if (destinationElement.HasAttribute("cargo"))
                             {
                                 targetAirport.addDestinationCargoRate(new DestinationDemand(destAirport.Profile.IATACode, ushort.Parse(destinationElement.Attributes["cargo"].Value)));
                                 targetAirport.addCargoDestinationStatistics(destAirport, Convert.ToDouble(destinationElement.Attributes["cargostats"].Value, new CultureInfo("de-DE", false)));
                             }
                         }
                     });
                 }
             }
             Instructors.Clear();

             XmlNodeList instructorsList = root.SelectNodes("//instructors/instructor");

             foreach (XmlElement instructorNode in instructorsList)
             {
                 string firstname = instructorNode.Attributes["firstname"].Value;
                 string lastname = instructorNode.Attributes["lastname"].Value;
                 DateTime birthdate = DateTime.Parse(instructorNode.Attributes["birthdate"].Value, new CultureInfo("de-DE", false));
                 Town town = Towns.GetTown(instructorNode.Attributes["town"].Value);
                 //Pilot.PilotRating rating = (Pilot.PilotRating)Enum.Parse(typeof(Pilot.PilotRating), instructorNode.Attributes["rating"].Value);
                 string id = instructorNode.Attributes["id"].Value;

                 Instructor instructor = new Instructor(new PilotProfile(firstname, lastname, birthdate, town),PilotRatings.GetRating("A"));

                 if (id != "-")
                 {
                     FlightSchool fs = Airlines.GetAllAirlines().SelectMany(a => a.FlightSchools).Where(f => f.ID == id).FirstOrDefault();
                     instructor.FlightSchool = fs;
                     fs.addInstructor(instructor);
                 }

                 XmlNodeList studentsList = instructorNode.SelectNodes("students/student");

                 foreach (XmlElement studentNode in studentsList)
                 {
                     PilotStudent student = instructor.FlightSchool.Students.Find(s => s.Profile.Name == studentNode.Attributes["name"].Value);
                     student.Instructor = instructor;
                     instructor.addStudent(student);
                 }

                 Instructors.AddInstructor(instructor);
             }

             if (Instructors.GetInstructors().Count == 0)
                 GeneralHelpers.CreateInstructors(75 * Airlines.GetAllAirlines().Count);

             Pilots.Clear();

             XmlNodeList pilotsList = root.SelectNodes("//pilots/pilot");

             foreach (XmlElement pilotNode in pilotsList)
             {
                 string firstname = pilotNode.Attributes["firstname"].Value;
                 string lastname = pilotNode.Attributes["lastname"].Value;
                 DateTime birthdate = DateTime.Parse(pilotNode.Attributes["birthdate"].Value, new CultureInfo("de-DE", false));
                 Town town = Towns.GetTown(pilotNode.Attributes["town"].Value);
                 DateTime educationdate = DateTime.Parse(pilotNode.Attributes["education"].Value, new CultureInfo("de-DE", false));

                 //Pilot.PilotRating rating = (Pilot.PilotRating)Enum.Parse(typeof(Pilot.PilotRating), pilotNode.Attributes["rating"].Value);

                 Pilot pilot = new Pilot(new PilotProfile(firstname, lastname, birthdate, town), educationdate, PilotRatings.GetRating("B"));

                 if (pilotNode.Attributes["airline"].Value != "-")
                 {
                     Airline pilotAirline = Airlines.GetAirline(pilotNode.Attributes["airline"].Value);
                     DateTime airlinesigneddate = DateTime.Parse(pilotNode.Attributes["airlinesigned"].Value, new CultureInfo("de-DE", false));

                     pilotAirline.addPilot(pilot);
                     pilot.AirlineSignedDate = airlinesigneddate;

                     if (pilotNode.Attributes["airliner"].Value != "-")
                     {
                         FleetAirliner airliner = pilotAirline.Fleet.Find(f => f.Airliner.ID == pilotNode.Attributes["airliner"].Value);

                         if (airliner != null)
                         {
                             pilot.Airliner = airliner;
                             airliner.addPilot(pilot);
                         }
                     }

                   }

                 Pilots.AddPilot(pilot);
             }

             if (Pilots.GetNumberOfPilots() == 0)
             {
                 Random rnd = new Random();

                 GeneralHelpers.CreatePilots(100 * Airlines.GetAllAirlines().Count);

                 foreach (FleetAirliner airliner in Airlines.GetAllAirlines().SelectMany(a => a.Fleet))
                 {
                     Pilot pilot = Pilots.GetPilots()[rnd.Next(Pilots.GetNumberOfPilots())];
                     airliner.Airliner.Airline.addPilot(pilot);
                     pilot.Airliner = airliner;
                     airliner.addPilot(pilot);
                 }
             }

             Alliances.Clear();

             XmlNodeList alliancesList = root.SelectNodes("//alliances/alliance");

             foreach (XmlElement allianceNode in alliancesList)
             {
                 string allianceName = allianceNode.Attributes["name"].Value;
                 DateTime formationDate = DateTime.Parse(allianceNode.Attributes["formation"].Value, new CultureInfo("de-DE"));
                 Airport allianceHeadquarter = Airports.GetAirport(allianceNode.Attributes["headquarter"].Value);

                 Alliance alliance = new Alliance(formationDate, allianceName, allianceHeadquarter);

                 XmlNodeList membersList = allianceNode.SelectNodes("members/member");

                 foreach (XmlElement memberNode in membersList)
                 {
                     Airline allianceMember = Airlines.GetAirline(memberNode.Attributes["airline"].Value);
                     DateTime joinedDate = DateTime.Parse(memberNode.Attributes["joined"].Value, new CultureInfo("de-DE"));

                     if (allianceMember != null)
                         alliance.addMember(new AllianceMember(allianceMember, joinedDate));
                 }

                 XmlNodeList pendingsList = allianceNode.SelectNodes("pendings/pending");

                 foreach (XmlElement pendingNode in pendingsList)
                 {
                     Airline pendingAirline = Airlines.GetAirline(pendingNode.Attributes["airline"].Value);
                     DateTime pendingDate = DateTime.Parse(pendingNode.Attributes["date"].Value, new CultureInfo("de-DE"));
                     PendingAllianceMember.AcceptType pendingType = (PendingAllianceMember.AcceptType)Enum.Parse(typeof(PendingAllianceMember.AcceptType), pendingNode.Attributes["type"].Value);

                     alliance.addPendingMember(new PendingAllianceMember(pendingDate, alliance, pendingAirline, pendingType));
                 }

                 Alliances.AddAlliance(alliance);
             }
             Configurations.Clear();

             XmlNodeList configurationsList = root.SelectNodes("//configurations/configuration");

             foreach (XmlElement confElement in configurationsList)
             {
                 string confName = confElement.Attributes["name"].Value;
                 string confid = confElement.Attributes["id"].Value;
                 Boolean standard = Convert.ToBoolean(confElement.Attributes["standard"].Value);

                 int minimumSeats = Convert.ToInt16(confElement.Attributes["minimumseats"].Value);

                 AirlinerConfiguration configuration = new AirlinerConfiguration(confName, minimumSeats, standard);
                 configuration.ID = confid;

                 XmlNodeList classesList = confElement.SelectNodes("classes/class");

                 foreach (XmlElement classElement in classesList)
                 {
                     int seating = Convert.ToInt16(classElement.Attributes["seating"].Value);
                     int regularseating = Convert.ToInt16(classElement.Attributes["regularseating"].Value);
                     AirlinerClass.ClassType classType = (AirlinerClass.ClassType)Enum.Parse(typeof(AirlinerClass.ClassType), classElement.Attributes["type"].Value);

                     AirlinerClassConfiguration classConf = new AirlinerClassConfiguration(classType, seating, regularseating);
                     foreach (AirlinerFacility.FacilityType facType in Enum.GetValues(typeof(AirlinerFacility.FacilityType)))
                     {
                         string facUid = classElement.Attributes[facType.ToString()].Value;

                         classConf.addFacility(AirlinerFacilities.GetFacility(facType, facUid));
                     }

                     configuration.addClassConfiguration(classConf);
                 }
                 Configurations.AddConfiguration(configuration);
             }

             XmlNodeList routeConfigurationsList = root.SelectNodes("//routeclassesconfigurations/routeclassesconfiguration");

             foreach (XmlElement confElement in routeConfigurationsList)
             {
                 string routeConfName = confElement.Attributes["name"].Value;
                 string confid = confElement.Attributes["id"].Value;
                 Boolean standard = Convert.ToBoolean(confElement.Attributes["standard"].Value);

                 XmlNodeList classesList = confElement.SelectNodes("classes/class");

                 RouteClassesConfiguration classesConfiguration = new RouteClassesConfiguration(routeConfName, standard);
                 classesConfiguration.ID = confid;

                 foreach (XmlElement classElement in classesList)
                 {
                     AirlinerClass.ClassType classType = (AirlinerClass.ClassType)Enum.Parse(typeof(AirlinerClass.ClassType), classElement.Attributes["type"].Value);

                     RouteClassConfiguration classConf = new RouteClassConfiguration(classType);
                     foreach (RouteFacility.FacilityType facType in Enum.GetValues(typeof(RouteFacility.FacilityType)))
                     {
                         if (classElement.HasAttribute(facType.ToString()))
                         {
                             string facilityName = classElement.Attributes[facType.ToString()].Value;

                             classConf.addFacility(RouteFacilities.GetFacilities(facType).Find(f => f.Name == facilityName));
                         }
                     }

                     classesConfiguration.addClass(classConf);
                 }

                 Configurations.AddConfiguration(classesConfiguration);
             }

             XmlElement difficultyNode = (XmlElement)root.SelectSingleNode("//difficulty");
             string difficultyName = difficultyNode.Attributes["name"].Value;
             double moneyLevel = Convert.ToDouble(difficultyNode.Attributes["money"].Value,new CultureInfo("de-DE", false));
             double priceLevel = Convert.ToDouble(difficultyNode.Attributes["price"].Value, new CultureInfo("de-DE", false));
             double loanLevel = Convert.ToDouble(difficultyNode.Attributes["loan"].Value, new CultureInfo("de-DE", false));
             double passengersLevel = Convert.ToDouble(difficultyNode.Attributes["passengers"].Value, new CultureInfo("de-DE", false));
             double aiLevel = Convert.ToDouble(difficultyNode.Attributes["ai"].Value, new CultureInfo("de-DE", false));

             GameObject.GetInstance().Difficulty = new DifficultyLevel(difficultyName, moneyLevel, loanLevel, passengersLevel, priceLevel, aiLevel,1);

             XmlElement scenarioNode = (XmlElement)root.SelectSingleNode("//scenario");

             if (scenarioNode != null)
             {
                 Scenario scenario = Scenarios.GetScenario(scenarioNode.Attributes["name"].Value);

                 ScenarioObject so = new ScenarioObject(scenario);
                 so.IsSuccess = Convert.ToBoolean(scenarioNode.Attributes["success"].Value);

                 if (scenarioNode.HasAttribute("failed"))
                     so.ScenarioFailed = scenario.Failures.Find(f => f.ID == scenarioNode.Attributes["failed"].Value);

                 XmlNodeList failuresList = scenarioNode.SelectNodes("failures/failure");

                 foreach (XmlElement failureNode in failuresList)
                 {
                     ScenarioFailure failure = scenario.Failures.Find(f => f.ID == failureNode.Attributes["id"].Value);
                     int failureCount = Convert.ToInt16(failureNode.Attributes["count"].Value);
                     DateTime lastFailureTime = DateTime.Parse(failureNode.Attributes["lastfailuretime"].Value, new CultureInfo("de-DE", false));

                     so.getScenarioFailure(failure).LastFailureTime = lastFailureTime;
                     so.getScenarioFailure(failure).Failures = failureCount;
                 }

                 GameObject.GetInstance().Scenario = so;

             }

             XmlElement gameSettingsNode = (XmlElement)root.SelectSingleNode("//gamesettings");

             GameObject.GetInstance().Name = gameSettingsNode.Attributes["name"].Value;

             Airline humanAirline = Airlines.GetAirline(gameSettingsNode.Attributes["human"].Value);
             GameObject.GetInstance().setHumanAirline(humanAirline);

             Airline mainAirline = Airlines.GetAirline(gameSettingsNode.Attributes["mainairline"].Value);
             GameObject.GetInstance().MainAirline = mainAirline;

             double fuelPrice = Convert.ToDouble(gameSettingsNode.Attributes["fuelprice"].Value, new CultureInfo("de-DE", false));
             GameObject.GetInstance().FuelPrice = fuelPrice;

             GameTimeZone timezone = TimeZones.GetTimeZones().Find(delegate(GameTimeZone gtz) { return gtz.UTCOffset == TimeSpan.Parse(gameSettingsNode.Attributes["timezone"].Value); });
             GameObject.GetInstance().TimeZone = timezone;

             Settings.GetInstance().MailsOnLandings = Convert.ToBoolean(gameSettingsNode.Attributes["mailonlandings"].Value);
             Settings.GetInstance().MailsOnBadWeather = Convert.ToBoolean(gameSettingsNode.Attributes["mailonbadweather"].Value);

             Settings.GetInstance().AirportCodeDisplay = (Settings.AirportCode)Enum.Parse(typeof(Settings.AirportCode), gameSettingsNode.Attributes["airportcode"].Value);
             if (gameSettingsNode.HasAttribute("minutesperturn")) Settings.GetInstance().MinutesPerTurn = Convert.ToInt16(gameSettingsNode.Attributes["minutesperturn"].Value);
             AppSettings.GetInstance().setLanguage(Languages.GetLanguage(gameSettingsNode.Attributes["language"].Value));
             GameObject.GetInstance().DayRoundEnabled = Convert.ToBoolean(gameSettingsNode.Attributes["dayround"].Value);

             XmlNodeList itemsList = gameSettingsNode.SelectNodes("calendaritems/calendaritem");

             CalendarItems.Clear();

             foreach (XmlElement itemNode in itemsList)
             {
                 CalendarItem.ItemType itemType = (CalendarItem.ItemType)Enum.Parse(typeof(CalendarItem.ItemType), itemNode.Attributes["type"].Value);
                 DateTime itemDate = DateTime.Parse(itemNode.Attributes["date"].Value, new CultureInfo("de-DE", false));
                 string itemHeader = itemNode.Attributes["header"].Value;
                 string itemSubject = itemNode.Attributes["subject"].Value;

                 CalendarItems.AddCalendarItem(new CalendarItem(itemType, itemDate, itemHeader, itemSubject));
             }

             XmlNodeList newsList = gameSettingsNode.SelectNodes("news/new");
             GameObject.GetInstance().NewsBox.clear();

             foreach (XmlElement newsNode in newsList)
             {
                 DateTime newsDate = DateTime.Parse(newsNode.Attributes["date"].Value, new CultureInfo("de-DE", false));
                 News.NewsType newsType = (News.NewsType)Enum.Parse(typeof(News.NewsType), newsNode.Attributes["type"].Value);
                 string newsSubject = newsNode.Attributes["subject"].Value;
                 string newsBody = newsNode.Attributes["body"].Value;
                 Boolean newsIsRead = Convert.ToBoolean(newsNode.Attributes["isread"].Value);

                 News news = new News(newsType, newsDate, newsSubject, newsBody);
                 news.IsRead = newsIsRead;

                 GameObject.GetInstance().NewsBox.addNews(news);

             }
             /*
               foreach (Airline airline in Airlines.GetAllAirlines())
               {
                   foreach (Route route in airline.Routes)
                   {
                       Gate gate1 = route.Destination1.Terminals.getEmptyGate(airline);
                       Gate gate2 = route.Destination2.Terminals.getEmptyGate(airline);

                       if (gate1!=null) gate1.Route = route;
                       if (gate2!=null) gate2.Route = route;

                   }
               }

               */
        }
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            int gates = Convert.ToInt32(nudGates.Value);
            int lenght = Convert.ToInt32(cbLength.SelectedItem);

            double yearlyPayment = AirportHelpers.GetYearlyContractPayment(this.Airport,gates,lenght);

            if (this.Contract == null)
            {
                Boolean payFull = false;
                if (lenght <= 2)
                {
                     payFull = true;
                }
                AirportContract contract = new AirportContract(GameObject.GetInstance().HumanAirline, this.Airport, GameObject.GetInstance().GameTime, gates, lenght, yearlyPayment,payFull);
                this.Selected = contract;
            }
            else
            {
                this.Contract.NumberOfGates = gates;
                this.Contract.Length = lenght;
                this.Contract.YearlyPayment = yearlyPayment;
                this.Contract.ContractDate = GameObject.GetInstance().GameTime;
                this.Contract.ExpireDate = this.Contract.ExpireDate.AddYears(this.Contract.Length);
                this.Selected = this.Contract;
            }

            this.Close();
        }
Ejemplo n.º 25
0
        //returns the yearly payment for a number of gates
        public static double GetYearlyContractPayment(Airport airport, AirportContract.ContractType type, int gates, int length)
        {
            double basePrice = 0;

            if (type == AirportContract.ContractType.Full)
                basePrice = airport.getGatePrice() * 12;

            if (type == AirportContract.ContractType.Low_Service)
                basePrice = airport.getGatePrice() * 13;

            if (type == AirportContract.ContractType.Medium_Service)
                basePrice = airport.getGatePrice() * 17;

            if (type == AirportContract.ContractType.Full_Service)
                basePrice = airport.getGatePrice() * 20;

            double lengthFactor = 100 - length;

            return gates * (basePrice * (lengthFactor / 100));
        }
Ejemplo n.º 26
0
        private void btnExtendContract_Click(object sender, RoutedEventArgs e)
        {
            ContractMVVM tContract = (ContractMVVM)((Button)sender).Tag;

            AirportContract contract = new AirportContract(tContract.Contract.Airline,tContract.Contract.Airport,tContract.Contract.Type,tContract.Contract.ContractDate,tContract.Contract.NumberOfGates,tContract.Contract.Length,tContract.Contract.YearlyPayment,tContract.Contract.AutoRenew);

            object o = PopUpExtendContract.ShowPopUp(contract);

            if (o != null)
            {
                AirportContract nContract = (AirportContract)o;

                tContract.setNumberOfGates(nContract.NumberOfGates);
                tContract.setExpireDate(nContract.ExpireDate);
                tContract.Contract.AutoRenew = nContract.AutoRenew;

            }
        }
Ejemplo n.º 27
0
        public static void RentGates(Airport airport, Airline airline,AirportContract.ContractType type, int gates, int length = 20)
        {
            int currentgates = airport.AirlineContracts.Where(a => a.Airline == airline).Sum(c => c.NumberOfGates);
            AirportContract contract = new AirportContract(airline, airport,type, GameObject.GetInstance().GameTime, gates, length, GetYearlyContractPayment(airport,type, gates, length),true);

            if (currentgates == 0)
            {
                AddAirlineContract(contract);
            }
            else
            {
                foreach (AirportContract c in airport.AirlineContracts.Where(a => a.Airline == airline))
                {
                    c.NumberOfGates += gates;
                }
            }

            for (int i = 0; i < gates; i++)
            {
                Gate gate = airport.Terminals.getGates().Where(g => g.Airline == null).First();
                gate.Airline = airline;
            }
        }
Ejemplo n.º 28
0
 public ContractMVVM(AirportContract contract)
 {
     this.Contract = contract;
     this.Airline = this.Contract.Airline;
     this.NumberOfGates = this.Contract.NumberOfGates;
     this.MonthsLeft = this.Contract.MonthsLeft;
     this.IsHuman = this.Airline == GameObject.GetInstance().HumanAirline;
 }