public AirlineAirportFacility(Airline airline, Airport airport, AirportFacility facility, DateTime date)
 {
     Airline = airline;
     Facility = facility;
     FinishedDate = date;
     Airport = airport;
 }
Ejemplo n.º 2
0
        private static void LoadAirportFacilities()
        {
            var doc = new XmlDocument();
            doc.Load(AppSettings.GetDataPath() + "\\airportfacilities.xml");
            XmlElement root = doc.DocumentElement;

            XmlNodeList facilitiesList = root?.SelectNodes("//airportfacility");

            if (facilitiesList != null)
                foreach (XmlElement element in facilitiesList)
                {
                    string section = root.Name;
                    string uid = element.Attributes["uid"].Value;
                    string shortname = element.Attributes["shortname"].Value;
                    var type =
                        (AirportFacility.FacilityType)
                            Enum.Parse(typeof (AirportFacility.FacilityType), element.Attributes["type"].Value);
                    int typeLevel = Convert.ToInt16(element.Attributes["typelevel"].Value);

                    double price = XmlConvert.ToDouble(element.Attributes["price"].Value);
                    int buildingDays = XmlConvert.ToInt32(element.Attributes["buildingdays"].Value);

                    var levelElement = (XmlElement) element.SelectSingleNode("level");
                    if (levelElement != null)
                    {
                        int service = Convert.ToInt32(levelElement.Attributes["service"].Value);
                        int luxury = Convert.ToInt32(levelElement.Attributes["luxury"].Value);

                        var facility = new AirportFacility(
                            section,
                            uid,
                            shortname,
                            type,
                            buildingDays,
                            typeLevel,
                            price,
                            service,
                            luxury);

                        AirportFacilities.AddFacility(facility);

                        var employeesElement = (XmlElement) element.SelectSingleNode("employees");

                        if (employeesElement != null)
                        {
                            var employeestype =
                                (AirportFacility.EmployeeTypes)
                                    Enum.Parse(typeof (AirportFacility.EmployeeTypes), employeesElement.Attributes["type"].Value);
                            int numberofemployees = Convert.ToInt16(employeesElement.Attributes["numberofemployees"].Value);

                            facility.EmployeeType = employeestype;
                            facility.NumberOfEmployees = numberofemployees;
                        }
                    }

                    if (element.SelectSingleNode("translations") != null)
                    {
                        Translator.GetInstance()
                            .AddTranslation(
                                root.Name,
                                element.Attributes["uid"].Value,
                                element.SelectSingleNode("translations"));
                    }
                }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        private void btnBuyFacility_Click(object sender, RoutedEventArgs e)
        {
            AirportFacility facility = cbFacility.SelectedItem as AirportFacility;

            AirportFacility buildingFacility = this.Airport.Airport.getAirlineBuildingFacility(GameObject.GetInstance().HumanAirline, facility.Type);

            if (facility.Price > GameObject.GetInstance().HumanAirline.Money)
            {
                WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2201"), Translator.GetInstance().GetString("MessageBox", "2201", "message"), WPFMessageBoxButtons.Ok);
            }
            else
            {
                if (buildingFacility == null)
                {
                    if (facility.Type == AirportFacility.FacilityType.Cargo && !GameObject.GetInstance().HumanAirline.Airports.Contains(this.Airport.Airport))
                    {
                        GameObject.GetInstance().HumanAirline.addAirport(this.Airport.Airport);
                    }

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

                    ICollectionView view = CollectionViewSource.GetDefaultView(cbFacility.ItemsSource);
                    view.Refresh();
                }
                else
                {
                    WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2233"), Translator.GetInstance().GetString("MessageBox", "2233", "message"), WPFMessageBoxButtons.Ok);
                }
            }

            /*
             * AirportFacility.FacilityType type = (AirportFacility.FacilityType)cbNextFacility.SelectedItem;
             *
             * AirlineAirportFacility currentFacility = this.Airport.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 (facilities.Count > index + 1)
             * {
             * 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", "2229"), string.Format(Translator.GetInstance().GetString("MessageBox", "2229", "message"), facility.Name, new ValueCurrencyConverter().Convert(facility.Price)), WPFMessageBoxButtons.YesNo);
             *
             *     if (result == WPFMessageBoxResult.Yes)
             *     {
             *         if (facility.Type == AirportFacility.FacilityType.Cargo && !GameObject.GetInstance().HumanAirline.Airports.Contains(this.Airport.Airport))
             *             GameObject.GetInstance().HumanAirline.addAirport(this.Airport.Airport);
             *
             *         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);
             *
             *
             *         object o = cbNextFacility.SelectedItem;
             *         cbNextFacility.SelectedIndex = cbNextFacility.SelectedIndex == cbNextFacility.Items.Count - 1 ? 0 : (cbNextFacility.SelectedIndex+1);
             *
             *         cbNextFacility.SelectedItem = o;
             *
             *     }
             * }
             * }
             * */
        }
Ejemplo n.º 5
0
 //returns if an airline has any airliners with the airport as home base
 //removes the facility for an airline
 public void RemoveFacility(Airline airline, AirportFacility facility)
 {
     _facilities.RemoveAll(f => f.Airline == airline && f.Facility.Type == facility.Type);
 }
Ejemplo n.º 6
0
 //returns if an airline is building a facility
 public bool IsBuildingFacility(Airline airline, AirportFacility.FacilityType type)
 {
     var facilities = new List<AirlineAirportFacility>();
     lock (_facilities)
     {
         return facilities.Exists(f => f.Airline == airline && f.Facility.Type == type && f.FinishedDate > GameObject.GetInstance().GameTime);
     }
 }
Ejemplo n.º 7
0
 //returns if an airline has any facilities besides a specific type
 public Boolean HasFacilities(Airline airline, AirportFacility.FacilityType ftype)
 {
     Boolean hasFacilities = false;
     foreach (AirportFacility.FacilityType type in Enum.GetValues(typeof (AirportFacility.FacilityType)))
     {
         if (type != ftype)
         {
             if (GetAirportFacility(airline, type).TypeLevel > 0)
             {
                 hasFacilities = true;
             }
         }
     }
     return hasFacilities;
 }
Ejemplo n.º 8
0
        public AirportFacility GetCurrentAirportFacility(Airline airline, AirportFacility.FacilityType type)
        {
            List<AirportFacility> facilities;

            var tFacilities = new List<AirlineAirportFacility>(_facilities);
            lock (_facilities)
            {
                facilities = (from f in tFacilities
                              where
                                  f.Airline == airline && f.Facility.Type == type
                                  && f.FinishedDate <= GameObject.GetInstance().GameTime
                              orderby f.FinishedDate descending
                              select f.Facility).ToList();
                int numberOfFacilities = facilities.Count();

                if (numberOfFacilities == 0 && airline != null)
                {
                    AirportFacility noneFacility = AirportFacilities.GetFacilities(type).Find(f => f.TypeLevel == 0);
                    AddAirportFacility(airline, noneFacility, GameObject.GetInstance().GameTime);

                    facilities.Add(noneFacility);
                }
            }
            return facilities.FirstOrDefault();
        }
Ejemplo n.º 9
0
        public AirportFacility GetAirportFacility(
            Airline airline,
            AirportFacility.FacilityType type,
            Boolean useAirport = false)
        {
            if (!useAirport)
            {
                return GetAirlineAirportFacility(airline, type).Facility;
            }
            AirportFacility airlineFacility = GetCurrentAirportFacility(airline, type);
            AirportFacility airportFacility = GetCurrentAirportFacility(null, type);

            return airportFacility == null || airlineFacility.TypeLevel > airportFacility.TypeLevel
                       ? airlineFacility
                       : airportFacility;
        }
Ejemplo n.º 10
0
        public AirportFacility GetAirlineBuildingFacility(Airline airline, AirportFacility.FacilityType type)
        {
            AirlineAirportFacility facility =
                _facilities.FirstOrDefault(
                    f =>
                    f.Airline == airline && f.Facility.Type == type
                    && GameObject.GetInstance().GameTime < f.FinishedDate);

            return facility?.Facility;
        }
Ejemplo n.º 11
0
        public AirlineAirportFacility GetAirlineAirportFacility(Airline airline, AirportFacility.FacilityType type)
        {
            List<AirlineAirportFacility> facilities;
            lock (_facilities)
            {
                facilities = (from f in _facilities
                              where
                                  f.Airline == airline && f.Facility.Type == type
                                  && GameObject.GetInstance().GameTime >= f.FinishedDate
                              orderby f.FinishedDate descending
                              select f).ToList();

                if (!facilities.Any())
                {
                    AirportFacility noneFacility = AirportFacilities.GetFacilities(type).Find(f => f.TypeLevel == 0);
                    AddAirportFacility(airline, noneFacility, GameObject.GetInstance().GameTime);

                    facilities.Add(GetAirlineAirportFacility(airline, type));
                }
            }
            return facilities.FirstOrDefault();
        }
Ejemplo n.º 12
0
 public void AddAirportFacility(Airline airline, AirportFacility facility, DateTime finishedDate)
 {
     //this.Facilities.RemoveAll(f => f.Airline == airline && f.Facility.Type == facility.Type);
     _facilities.Add(new AirlineAirportFacility(airline, this, facility, finishedDate));
 }
Ejemplo n.º 13
0
 public HumanFacilityType(Airport airport, AirportFacility current, AirportFacility next)
 {
     this.Airport         = airport;
     this.CurrentFacility = current;
     this.NextFacility    = next;
 }
Ejemplo n.º 14
0
        public void addAirlineFacility(AirportFacility facility)
        {
            var nextFacility = new AirlineAirportFacility(
                GameObject.GetInstance().HumanAirline,
                Airport,
                facility,
                GameObject.GetInstance().GameTime.AddDays(facility.BuildingDays));
            Airport.AddAirportFacility(nextFacility);

            /*
            AirlineAirportFacilityMVVM currentFacility = this.AirlineFacilities.Where(f => f.Facility.Facility.Type == facility.Type).FirstOrDefault();

            if (currentFacility != null)
                removeAirlineFacility(currentFacility);

            Alliance alliance = nextFacility.Airline.Alliances.Count == 0 ? null : nextFacility.Airline.Alliances[0];

            this.AirlineFacilities.Add(new AirlineAirportFacilityMVVM(nextFacility,alliance));
             * */
            AirlineFacilities.Clear();
            BuildingAirlineFacilities.Clear();

            foreach (
                AirlineAirportFacility tFacility in Airport.GetAirportFacilities().FindAll(f => f.Airline != null))
            {
                if (tFacility.Facility.TypeLevel != 0)
                {
                    Alliance alliance = tFacility.Airline.Alliances.Count == 0 ? null : tFacility.Airline.Alliances[0];

                    var airlineFacility = new AirlineAirportFacilityMVVM(tFacility, alliance);

                    if (airlineFacility.IsDelivered)
                    {
                        AirlineFacilities.Add(airlineFacility);
                    }
                    else
                    {
                        BuildingAirlineFacilities.Add(airlineFacility);
                    }
                }
            }
        }