Ejemplo n.º 1
0
        //sets the values
        private void setValues()
        {
            this.Finances.Clear();

            foreach (Invoice.InvoiceType type in Enum.GetValues(typeof(Invoice.InvoiceType)))
            {
                this.Finances.Add(new AirlineFinanceMVVM(this.Airline, type));
            }

            this.Money   = this.Airline.Money;
            this.Balance = this.Airline.Money - this.Airline.StartMoney;
            double tMoney = GameObject.GetInstance().HumanMoney;

            this.CockpitCrew     = this.Airline.Pilots.Count;
            this.CabinCrew       = this.Airline.Routes.Where(r => r.Type == Route.RouteType.Passenger).Sum(r => ((PassengerRoute)r).getTotalCabinCrew());
            this.SupportCrew     = this.Airline.Airports.SelectMany(a => a.getCurrentAirportFacilities(this.Airline)).Where(a => a.EmployeeType == AirportFacility.EmployeeTypes.Support).Sum(a => a.NumberOfEmployees);
            this.MaintenanceCrew = this.Airline.Airports.SelectMany(a => a.getCurrentAirportFacilities(this.Airline)).Where(a => a.EmployeeType == AirportFacility.EmployeeTypes.Maintenance).Sum(a => a.NumberOfEmployees);

            foreach (AirlineFacility facility in AirlineFacilities.GetFacilities(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).OrderBy(f => f.Name))
            {
                this.Facilities.Add(new AirlineFacilityMVVM(this.Airline, facility, this.Airline.Facilities.Exists(f => f.Uid == facility.Uid) ? AirlineFacilityMVVM.MVVMType.Purchased : AirlineFacilityMVVM.MVVMType.Available));
            }

            foreach (AdvertisementType.AirlineAdvertisementType type in Enum.GetValues(typeof(AdvertisementType.AirlineAdvertisementType)))
            {
                if (GameObject.GetInstance().GameTime.Year >= (int)type)
                {
                    AirlineAdvertisementMVVM advertisement = new AirlineAdvertisementMVVM(type);

                    advertisement.Types = AdvertisementTypes.GetTypes(type);

                    this.Advertisements.Add(advertisement);
                }
            }

            this.MaxSubsidiaryMoney = this.Airline.Money / 2;
            this.License            = this.Airline.License;

            if (this.Airline.IsSubsidiary)
            {
                this.AirlineAirlines.Add(((SubsidiaryAirline)this.Airline).Airline);

                foreach (SubsidiaryAirline airline in ((SubsidiaryAirline)this.Airline).Airline.Subsidiaries)
                {
                    this.AirlineAirlines.Add(airline);
                }
            }
            else
            {
                foreach (SubsidiaryAirline airline in this.Subsidiaries)
                {
                    this.AirlineAirlines.Add(airline);
                }

                this.AirlineAirlines.Add(this.Airline);
            }

            this.MaxLoan = AirlineHelpers.GetMaxLoanAmount(this.Airline);
        }
Ejemplo n.º 2
0
        //shows the list of facilities
        private void showFacilities()
        {
            int year = GameObject.GetInstance().GameTime.Year;

            lbFacilities.Items.Clear();
            lbNewFacilities.Items.Clear();

            this.Airline.Facilities.ForEach(f => lbFacilities.Items.Add(new KeyValuePair <Airline, AirlineFacility>(this.Airline, f)));

            List <AirlineFacility> facilitiesNew = AirlineFacilities.GetFacilities();

            facilitiesNew.RemoveAll(f => this.Airline.Facilities.Exists(a => a.Uid == f.Uid));

            foreach (AirlineFacility facility in facilitiesNew.FindAll(f => f.FromYear <= year))
            {
                lbNewFacilities.Items.Add(facility);
            }
        }
Ejemplo n.º 3
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);
             *  }
             * }
             */
        }