示例#1
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;
            }
        }
示例#2
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);
        }
示例#3
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Boolean isEnabled = true;

            Airport airport = ((HumanFacilityType)value).Airport;

            AirportFacility.FacilityType type = ((HumanFacilityType)value).CurrentFacility.Type;

            string buttonType = (string)parameter;

            List <AirportFacility> facilities = AirportFacilities.GetFacilities(type);

            facilities.Sort((delegate(AirportFacility f1, AirportFacility f2) { return(f1.TypeLevel.CompareTo(f2.TypeLevel)); }));

            int index = facilities.FindIndex(f => f.Uid == airport.getAirportFacility(GameObject.GetInstance().HumanAirline, type).Uid);

            if (buttonType == "Buy" && type != AirportFacility.FacilityType.CheckIn)
            {
                int gates = airport.Terminals.getNumberOfGates(GameObject.GetInstance().HumanAirline);
                isEnabled = index < facilities.Count - 1 && gates > 0 && airport.getAirlineAirportFacility(GameObject.GetInstance().HumanAirline, type).FinishedDate < GameObject.GetInstance().GameTime;
            }
            if (buttonType == "Sell" && type != AirportFacility.FacilityType.CheckIn)
            {
                isEnabled = index > 0 && airport.getAirlineAirportFacility(GameObject.GetInstance().HumanAirline, type).FinishedDate < GameObject.GetInstance().GameTime;
            }
            if (buttonType == "Buy" && type == AirportFacility.FacilityType.CheckIn)
            {
                isEnabled = index < facilities.Count - 1 && airport.getAirlineAirportFacility(GameObject.GetInstance().HumanAirline, type).FinishedDate < GameObject.GetInstance().GameTime;
            }
            if (buttonType == "Sell" && type == AirportFacility.FacilityType.CheckIn)
            {
                isEnabled = index > 0 && airport.Terminals.getNumberOfGates(GameObject.GetInstance().HumanAirline) == 0 && airport.getAirlineAirportFacility(GameObject.GetInstance().HumanAirline, type).FinishedDate < GameObject.GetInstance().GameTime;
            }
            return(isEnabled);
        }
示例#4
0
        private void btnQuickUpgradeFacility_Click(object sender, RoutedEventArgs e)
        {
            AirlineAirportFacilityMVVM currentFacility = (AirlineAirportFacilityMVVM)((Button)sender).Tag;

            List <AirportFacility> facilities = AirportFacilities.GetFacilities(currentFacility.Facility.Facility.Type);

            facilities = facilities.OrderBy(f => f.TypeLevel).ToList();

            int index = facilities.FindIndex(f => currentFacility.Facility.Facility == f);

            AirportFacility facility = facilities[index + 1];

            if (facility.Price > GameObject.GetInstance().HumanAirline.Money)
            {
                WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2201"), Translator.GetInstance().GetString("MessageBox", "2201", "message"), WPFMessageBoxButtons.Ok);
            }
            else
            {
                WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2202"), string.Format(Translator.GetInstance().GetString("MessageBox", "2202", "message"), facility.Name, new ValueCurrencyConverter().Convert(facility.Price)), WPFMessageBoxButtons.YesNo);

                if (result == WPFMessageBoxResult.Yes)
                {
                    double price = facility.Price;

                    if (this.Airport.Airport.Profile.Country != GameObject.GetInstance().HumanAirline.Profile.Country)
                    {
                        price = price * 1.25;
                    }

                    AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -price);

                    this.Airport.addAirlineFacility(facility);
                }
            }
        }
        //sets up the different scenario setting
        private static void SetupScenario()
        {
            Parallel.ForEach(Airports.GetAllAirports(), airport =>
            {
                foreach (Airline airline in Airlines.GetAllAirlines())
                {
                    foreach (AirportFacility.FacilityType type in Enum.GetValues(typeof(AirportFacility.FacilityType)))
                    {
                        AirportFacility noneFacility = AirportFacilities.GetFacilities(type).Find((delegate(AirportFacility facility) { return(facility.TypeLevel == 0); }));

                        airport.addAirportFacility(airline, noneFacility, GameObject.GetInstance().GameTime);
                    }
                }
                AirportHelpers.CreateAirportWeather(airport);
            });

            foreach (Airline airline in Airlines.GetAllAirlines())
            {
                if (airline.IsHuman)
                {
                    airline.Money = GameObject.GetInstance().StartMoney;
                }
                airline.StartMoney = airline.Money;
                airline.Fees       = new AirlineFees();
                airline.addAirlinePolicy(new AirlinePolicy("Cancellation Minutes", 150));
            }
        }
        private void btnContract_Click(object sender, RoutedEventArgs e)
        {
            Airport airport    = this.Airport;
            Boolean hasCheckin = airport.getAirportFacility(GameObject.GetInstance().HumanAirline, AirportFacility.FacilityType.CheckIn).TypeLevel > 0;

            object o = PopUpAirportContract.ShowPopUp(airport);

            if (o != null)
            {
                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);
                }
                AirportContract contract = (AirportContract)o;

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

                showGatesInformation();
                showContracts();
                showTerminals();
            }
        }
示例#7
0
        private void btnRent_Click(object sender, RoutedEventArgs e)
        {
            KeyValuePair <DestinationDemand, int> v = (KeyValuePair <DestinationDemand, int>)((Button)sender).Tag;
            Airport airport = Airports.GetAirport(v.Key.Destination);

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

            object o = PopUpAirportContract.ShowPopUp(airport);

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

            if (o != null)
            {
                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);
                }

                airport.addAirlineContract((AirportContract)o);

                showDemand();
            }
        }
示例#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);
                }
            }
        }
示例#9
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            AirportFacility.FacilityType type = (AirportFacility.FacilityType)values[0];
            Airport airport = (Airport)values[1];

            AirlineAirportFacility currentFacility = airport.getAirlineAirportFacility(GameObject.GetInstance().HumanAirline, type);

            List <AirportFacility> facilities = AirportFacilities.GetFacilities(type);

            facilities = facilities.OrderBy(f => f.TypeLevel).ToList();

            int index = facilities.FindIndex(f => currentFacility.Facility == f);

            if (parameter.ToString() == "Name")
            {
                if (index < facilities.Count - 1)
                {
                    return(facilities[index + 1].Name);
                }
                else
                {
                    return("None");
                }
            }
            if (parameter.ToString() == "Price")
            {
                if (index < facilities.Count - 1)
                {
                    return(new ValueCurrencyConverter().Convert(facilities[index + 1].Price));
                }
                else
                {
                    return("-");
                }
            }
            if (parameter.ToString() == "Employees")
            {
                if (index < facilities.Count - 1)
                {
                    return(facilities[index + 1].NumberOfEmployees.ToString());
                }
                else
                {
                    return("-");
                }
            }

            return("-");
        }
示例#10
0
        //sets up an opponent airline
        private static void SetupOpponentAirline(ScenarioAirline airline)
        {
            AirportHelpers.RentGates(airline.Homebase, airline.Airline);

            AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1);
            AirportFacility facility        = AirportFacilities.GetFacilities(AirportFacility.FacilityType.Service).Find((delegate(AirportFacility f) { return(f.TypeLevel == 1); }));

            airline.Homebase.addAirportFacility(airline.Airline, facility, GameObject.GetInstance().GameTime);
            airline.Homebase.addAirportFacility(airline.Airline, checkinFacility, GameObject.GetInstance().GameTime);

            foreach (ScenarioAirlineRoute saroute in airline.Routes)
            {
                SetupScenarioRoute(saroute, airline.Airline);
            }
        }
示例#11
0
        //sets up an airport for an airline
        private static void SetupScenarioAirport(Airline airline, Airport airport, int quantity = 2)
        {
            for (int i = 0; i < quantity; i++)
            {
                if (!AirportHelpers.HasFreeGates(airport, airline))
                {
                    AirportHelpers.RentGates(airport, airline);
                }
            }

            AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1);
            AirportFacility facility        = AirportFacilities.GetFacilities(AirportFacility.FacilityType.Service).Find((delegate(AirportFacility f) { return(f.TypeLevel == 1); }));

            airport.setAirportFacility(airline, facility, GameObject.GetInstance().GameTime);
            airport.setAirportFacility(airline, checkinFacility, GameObject.GetInstance().GameTime);
        }
示例#12
0
        //returns the next facility item for the specific type for the human airline
        private AirportFacility getHumanNextAirportFacility(AirportFacility.FacilityType type)
        {
            List <AirportFacility> facilities = AirportFacilities.GetFacilities(type);

            facilities.Sort((delegate(AirportFacility f1, AirportFacility f2) { return(f1.TypeLevel.CompareTo(f2.TypeLevel)); }));

            int index = facilities.FindIndex(f => f.Uid == this.Airport.getAirportFacility(GameObject.GetInstance().HumanAirline, type).Uid);

            if (index < facilities.Count - 1)
            {
                return(facilities[index + 1]);
            }
            else
            {
                return(facilities[0]);
            }
        }
示例#13
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            AirportFacility.FacilityType type = (AirportFacility.FacilityType)values[0];
            Airport airport = (Airport)values[1];

            var currentFacility  = airport.getCurrentAirportFacility(GameObject.GetInstance().HumanAirline, type);
            var buildingFacility = airport.getAirlineBuildingFacility(GameObject.GetInstance().HumanAirline, type);

            var facilities = new List <AirportFacility>();

            foreach (AirportFacility facility in AirportFacilities.GetFacilities(type).Where(f => f.TypeLevel > currentFacility.TypeLevel))
            {
                if (buildingFacility == null || facility.TypeLevel > buildingFacility.TypeLevel)
                {
                    facilities.Add(facility);
                }
            }

            return(facilities);
        }
示例#14
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);
        }
示例#15
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;
                }
            }
        }
示例#16
0
        //creates a new game
        private void createNewGame()
        {
            if (txtName.Text.Trim().Length > 2)
            {
                object    o         = null;
                int       startYear = (int)cbStartYear.SelectedItem;
                int       opponents = (int)cbOpponents.SelectedItem;
                Airline   airline   = (Airline)cbAirline.SelectedItem;
                Continent continent = (Continent)cbContinent.SelectedItem;
                Region    region    = (Region)cbRegion.SelectedItem;


                if (this.OpponentType == OpponentSelect.User)
                {
                    if (cbSameRegion.IsChecked.Value)
                    {
                        o = PopUpSelectOpponents.ShowPopUp(airline, opponents, startYear, airline.Profile.Country.Region);
                    }
                    else
                    {
                        o = PopUpSelectOpponents.ShowPopUp(airline, opponents, startYear, region, continent);
                    }
                }



                // popUpSplash.IsOpen = true;

                DoEvents();

                GameTimeZone gtz = (GameTimeZone)cbTimeZone.SelectedItem;
                GameObject.GetInstance().DayRoundEnabled = cbDayTurnEnabled.IsChecked.Value;
                GameObject.GetInstance().TimeZone        = gtz;
                GameObject.GetInstance().Difficulty      = (DifficultyLevel)cbDifficulty.SelectedItem;
                GameObject.GetInstance().GameTime        = new DateTime(startYear, 1, 1);
                GameObject.GetInstance().StartDate       = GameObject.GetInstance().GameTime;
                //sets the fuel price
                GameObject.GetInstance().FuelPrice = Inflations.GetInflation(GameObject.GetInstance().GameTime.Year).FuelPrice;

                airline.Profile.Country = (Country)cbCountry.SelectedItem;
                airline.Profile.CEO     = txtName.Text.Trim();

                GameObject.GetInstance().setHumanAirline(airline);
                GameObject.GetInstance().MainAirline = GameObject.GetInstance().HumanAirline;

                if (cbLocalCurrency.IsChecked.Value)
                {
                    GameObject.GetInstance().CurrencyCountry = airline.Profile.Country;
                }
                // AppSettings.GetInstance().resetCurrencyFormat();

                Airport airport = (Airport)cbAirport.SelectedItem;

                AirportHelpers.RentGates(airport, airline, 2);

                AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1);
                AirportFacility facility        = AirportFacilities.GetFacilities(AirportFacility.FacilityType.Service).Find((delegate(AirportFacility f) { return(f.TypeLevel == 1); }));

                airport.addAirportFacility(GameObject.GetInstance().HumanAirline, facility, GameObject.GetInstance().GameTime);
                airport.addAirportFacility(GameObject.GetInstance().HumanAirline, checkinFacility, GameObject.GetInstance().GameTime);

                if (continent.Uid != "100" || region.Uid != "100")
                {
                    var airlines = Airlines.GetAirlines(a => a.Profile.Country.Region == region || (region.Uid == "100" && continent.hasRegion(a.Profile.Country.Region)) && a.Profile.Founded <= startYear && a.Profile.Folded > startYear);
                    var airports = Airports.GetAirports(a => a.Profile.Country.Region == region || (region.Uid == "100" && continent.hasRegion(a.Profile.Country.Region)) && a.Profile.Period.From.Year <= startYear && a.Profile.Period.To.Year > startYear);

                    //Airports.RemoveAirports(a => (a.Profile.Country.Region != region && !continent.hasRegion(a.Profile.Country.Region)) || (a.Profile.Town.State != null && a.Profile.Town.State.IsOverseas));
                    Airports.Clear();
                    foreach (Airport a in airports)
                    {
                        Airports.AddAirport(a);
                    }

                    Airlines.Clear();
                    foreach (Airline a in airlines)
                    {
                        Airlines.AddAirline(a);
                    }
                }

                PassengerHelpers.CreateAirlineDestinationDemand();

                AirlinerHelpers.CreateStartUpAirliners();

                if (this.OpponentType == OpponentSelect.Random || o == null)
                {
                    Setup.SetupMainGame(opponents, cbSameRegion.IsChecked.Value);
                }
                else
                {
                    Setup.SetupMainGame((List <Airline>)o);
                }


                airline.MarketFocus = (Airline.AirlineFocus)cbFocus.SelectedItem;

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

                //PassengerHelpers.CreateDestinationPassengers();

                GameObjectWorker.GetInstance().start();
                // AIWorker.GetInstance().start();

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

                PageNavigator.ClearNavigator();

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

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

                popUpSplash.IsOpen = false;



                Action action = () =>
                {
                    Stopwatch swPax = new Stopwatch();
                    swPax.Start();

                    PassengerHelpers.CreateDestinationDemand();

                    Console.WriteLine("Demand have been created in {0} ms.", swPax.ElapsedMilliseconds);
                    swPax.Stop();
                };

                Task.Factory.StartNew(action);
                //Task.Run(action);
                //Task t2 = Task.Factory.StartNew(action, "passengers");
            }
            else
            {
                WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2403"), Translator.GetInstance().GetString("MessageBox", "2403"), WPFMessageBoxButtons.Ok);
            }
        }
示例#17
0
        //saves a game
        public static void SaveGame(string name)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            SaveObject so = new SaveObject();

            Parallel.Invoke(() =>
            {
                so.airportsList           = new List <Airport>();
                so.airportsfromstringList = new List <string>();

                var airportsInUse = Airports.GetAllAirports().Where(a => Airlines.GetAllAirlines().Exists(al => al.Airports.Contains(a)) || a.hasAirlineFacility());
                so.airportsList.AddRange(airportsInUse);

                foreach (Airport airport in Airports.GetAirports(a => !airportsInUse.Contains(a)))
                {
                    so.airportsfromstringList.Add(airport.Profile.IATACode);
                }
            }, () =>
            {
                so.airlinesList = new List <Airline>();
                so.airlinesList.AddRange(Airlines.GetAllAirlines());
            }, () =>
            {
                so.airlinersList = new List <Airliner>();
                so.airlinersList.AddRange(Airliners.GetAllAirliners().Where(a => a.Airline != null));
            }, () =>
            {
                so.calendaritemsList = new List <CalendarItem>();
                so.calendaritemsList.AddRange(CalendarItems.GetCalendarItems());
            }, () =>
            {
                so.configurationList = new List <Configuration>();
                so.configurationList.AddRange(Configurations.GetConfigurations());
            }, () =>
            {
                so.eventsList = new List <RandomEvent>();
                so.eventsList.AddRange(RandomEvents.GetEvents());
            }, () =>
            {
                so.allianceList = new List <Alliance>();
                so.allianceList.AddRange(Alliances.GetAlliances());
            }, () =>
            {
                so.Airportfacilitieslist = new List <AirportFacility>();
                so.Airportfacilitieslist.AddRange(AirportFacilities.GetFacilities());
            }, () =>
            {
                so.feeTypeslist = new List <FeeType>();
                so.feeTypeslist.AddRange(FeeTypes.GetTypes());
            }, () =>
            {
                so.advertisementTypeslist = new List <AdvertisementType>();
                so.advertisementTypeslist.AddRange(AdvertisementTypes.GetTypes());
            }, () =>
            {
                so.airlinerfacilitieslist = new List <AirlinerFacility>();
                so.airlinerfacilitieslist.AddRange(AirlinerFacilities.GetAllFacilities());
            }, () =>
            {
                so.routefacilitieslist = new List <RouteFacility>();
                so.routefacilitieslist.AddRange(RouteFacilities.GetAllFacilities());
            }, () =>
            {
                so.instance = GameObject.GetInstance();
                so.settings = Settings.GetInstance();
            }, () =>
            {
                so.airlinefacilitieslist = new List <AirlineFacility>();
                so.airlinefacilitieslist.AddRange(AirlineFacilities.GetFacilities());
            });

            string fileName = AppSettings.getCommonApplicationDataPath() + "\\saves\\" + name + ".sav";

            FileSerializer.Serialize(fileName, so);

            sw.Stop();
            Console.WriteLine("Saving: {0} ms", sw.ElapsedMilliseconds);



            //Clearing stats because there is no need for saving those.
            if (name != "autosave")
            {
                Airports.GetAllAirports().ForEach(a => a.clearDestinationPassengerStatistics());
                Airports.GetAllAirports().ForEach(a => a.clearDestinationCargoStatistics());
                AirlineHelpers.ClearRoutesStatistics();
                AirlineHelpers.ClearAirlinesStatistics();
                AirportHelpers.ClearAirportStatistics();
            }

            /*
             * SaveObject so = new SaveObject();
             * Parallel.Invoke(() =>
             * {
             *  so.airportsList = new List<Airport>();
             *  so.airportsList.AddRange(Airports.GetAllAirports());
             * }, () =>
             * {
             *  so.airlinesList = new List<Airline>();
             *  so.airlinesList.AddRange(Airlines.GetAllAirlines());
             * }, () =>
             * {
             *  so.airlinersList = new List<Airliner>();
             *  so.airlinersList.AddRange(Airliners.GetAllAirliners());
             * }, () =>
             * {
             *  so.calendaritemsList = new List<CalendarItem>();
             *  so.calendaritemsList.AddRange(CalendarItems.GetCalendarItems());
             * }, () =>
             * {
             *  so.configurationList = new List<Configuration>();
             *  so.configurationList.AddRange(Configurations.GetConfigurations());
             * }, () =>
             * {
             *  so.eventsList = new List<RandomEvent>();
             *  so.eventsList.AddRange(RandomEvents.GetEvents());
             * }, () =>
             * {
             *  so.allianceList = new List<Alliance>();
             *  so.allianceList.AddRange(Alliances.GetAlliances());
             * }, () =>
             * {
             *  so.Airportfacilitieslist = new List<AirportFacility>();
             *  so.Airportfacilitieslist.AddRange(AirportFacilities.GetFacilities());
             * }, () =>
             * {
             *  so.feeTypeslist = new List<FeeType>();
             *  so.feeTypeslist.AddRange(FeeTypes.GetTypes());
             * }, () =>
             * {
             *  so.advertisementTypeslist = new List<AdvertisementType>();
             *  so.advertisementTypeslist.AddRange(AdvertisementTypes.GetTypes());
             * }, () =>
             * {
             *  so.airlinerfacilitieslist = new List<AirlinerFacility>();
             *  so.airlinerfacilitieslist.AddRange(AirlinerFacilities.GetAllFacilities());
             * }, () =>
             * {
             *  so.routefacilitieslist = new List<RouteFacility>();
             *  so.routefacilitieslist.AddRange(RouteFacilities.GetAllFacilities());
             * }, () =>
             * {
             *  so.instance = GameObject.GetInstance();
             *  so.settings = Settings.GetInstance();
             *  so.savetype = "039";
             *  so.saveversionnumber = 1;
             * });
             */
            /*
             * DataContractSerializer serializer = new DataContractSerializer(typeof(SaveObject), null, Int32.MaxValue, false, true, null);
             *
             * using (Stream stream = new FileStream(fileName, FileMode.Create))
             * {
             *  using (DeflateStream compress = new DeflateStream(stream, CompressionLevel.Fastest))
             *  {
             *      serializer.WriteObject(compress, so);
             *  }
             * }
             */
        }
        //saves a game
        public static void SaveGame(string name)
        {
            //Pause the game so we can save without the clock running :)
            GameObjectWorker.GetInstance().pause();

            string fileName = AppSettings.getCommonApplicationDataPath() + "\\saves\\" + name + ".sav";

            Stopwatch sw = new Stopwatch();

            sw.Start();

            SaveObject so = new SaveObject();

            Parallel.Invoke(() =>
            {
                so.airportsList = new List <Airport>();
                so.airportsList.AddRange(Airports.GetAllAirports());
            }, () =>
            {
                so.airlinesList = new List <Airline>();
                so.airlinesList.AddRange(Airlines.GetAllAirlines());
            }, () =>
            {
                so.airlinersList = new List <Airliner>();
                so.airlinersList.AddRange(Airliners.GetAllAirliners());
            }, () =>
            {
                so.calendaritemsList = new List <CalendarItem>();
                so.calendaritemsList.AddRange(CalendarItems.GetCalendarItems());
            }, () =>
            {
                so.configurationList = new List <Configuration>();
                so.configurationList.AddRange(Configurations.GetConfigurations());
            }, () =>
            {
                so.eventsList = new List <RandomEvent>();
                so.eventsList.AddRange(RandomEvents.GetEvents());
            }, () =>
            {
                so.allianceList = new List <Alliance>();
                so.allianceList.AddRange(Alliances.GetAlliances());
            }, () =>
            {
                so.Airportfacilitieslist = new List <AirportFacility>();
                so.Airportfacilitieslist.AddRange(AirportFacilities.GetFacilities());
            }, () =>
            {
                so.instance = GameObject.GetInstance();
            });


            DataContractSerializer serializer = new DataContractSerializer(typeof(SaveObject), null,
                                                                           Int32.MaxValue,
                                                                           false,
                                                                           true,
                                                                           null);

            using (Stream stream = new FileStream(fileName, FileMode.Create))
            {
                using (DeflateStream compress = new DeflateStream(stream, CompressionMode.Compress))
                {
                    serializer.WriteObject(compress, so);
                }
            }

            sw.Stop();
        }