/*! create some game airliners.
         */
        public static void CreateStartUpAirliners()
        {
            int number = AirlinerTypes.GetTypes(delegate(AirlinerType t) { return(t.Produced.From <= GameObject.GetInstance().GameTime&& t.Produced.To >= GameObject.GetInstance().GameTime.AddYears(-30)); }).Count * 25;

            for (int i = 0; i < number; i++)
            {
                Airliners.AddAirliner(CreateAirliner(0));
            }
        }
Beispiel #2
0
        /*! create some game airliners.
         */
        public static void CreateStartUpAirliners()
        {
            int number = AirlinerTypes.GetTypes(delegate(AirlinerType t) { return(t.Produced.From <= GameObject.GetInstance().GameTime&& t.Produced.To.AddYears(-10) >= GameObject.GetInstance().GameTime.AddYears(-30)); }).Count *rnd.Next(1, 3);

            int airlines = Airlines.GetNumberOfAirlines();

            number = (airlines * number) / 5;
            for (int i = 0; i < number; i++)
            {
                Airliners.AddAirliner(CreateAirliner(0));
            }
        }
        //loads a game
        public static void LoadGame(string file)
        {
            string fileName = AppSettings.getCommonApplicationDataPath() + "\\saves\\" + file + ".sav";

            DataContractSerializer serializer = new DataContractSerializer(typeof(SaveObject));
            SaveObject             deserializedSaveObject;

            using (FileStream stream = new FileStream(fileName, FileMode.Open))
            {
                using (DeflateStream decompress = new DeflateStream(stream, CompressionMode.Decompress))
                {
                    deserializedSaveObject =
                        (SaveObject)serializer.ReadObject(decompress);
                }
            }

            //Parrarel for loading the game
            Parallel.Invoke(() =>
            {
                Airlines.Clear();

                foreach (Airline airline in deserializedSaveObject.airlinesList)
                {
                    Airlines.AddAirline(airline);
                }
            },
                            () =>
            {
                Airports.Clear();

                foreach (Airport airport in deserializedSaveObject.airportsList)
                {
                    airport.Statics = new AirportStatics(airport);
                    Airports.AddAirport(airport);
                }
            },
                            () =>
            {
                Airliners.Clear();

                foreach (Airliner airliner in deserializedSaveObject.airlinersList)
                {
                    Airliners.AddAirliner(airliner);
                }
            },
                            () =>
            {
                CalendarItems.Clear();

                foreach (CalendarItem item in deserializedSaveObject.calendaritemsList)
                {
                    CalendarItems.AddCalendarItem(item);
                }

                Configurations.Clear();

                foreach (Configuration configuration in deserializedSaveObject.configurationList)
                {
                    Configurations.AddConfiguration(configuration);
                }
            },
                            () =>
            {
                RandomEvents.Clear();

                foreach (RandomEvent e in deserializedSaveObject.eventsList)
                {
                    RandomEvents.AddEvent(e);
                }
            },
                            () =>
            {
                Alliances.Clear();

                foreach (Alliance alliance in deserializedSaveObject.allianceList)
                {
                    Alliances.AddAlliance(alliance);
                }
            },
                            () =>
            {
                AirportFacilities.Clear();

                foreach (AirportFacility facility in deserializedSaveObject.Airportfacilitieslist)
                {
                    AirportFacilities.AddFacility(facility);
                }
            },
                            () =>
            {
                GameObject.SetInstance(deserializedSaveObject.instance);
            });  //close parallel.invoke

            //Maybe this helps? But i doubt this is the best way
            Action action = () =>
            {
                Stopwatch swPax = new Stopwatch();
                swPax.Start();

                PassengerHelpers.CreateDestinationDemand();

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

            //Create some pilots for the game
            int pilotsPool = 100 * Airlines.GetAllAirlines().Count;

            GeneralHelpers.CreatePilots(pilotsPool);
            int instructorsPool = 75 * Airlines.GetAllAirlines().Count;

            GeneralHelpers.CreateInstructors(instructorsPool);

            //Start the game paused
            GameObjectWorker.GetInstance().startPaused();

            //Task is needed this unlocks the game agian.
            Task.Factory.StartNew(action);
        }
        private void btnOrder_Click(object sender, RoutedEventArgs e)
        {
            Boolean contractedOrder = false;
            Boolean tryOrder        = true;

            Airport airport = (Airport)cbAirport.SelectedItem;

            if (airport == null)
            {
                WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2002"), Translator.GetInstance().GetString("MessageBox", "2002", "message"), WPFMessageBoxButtons.Ok);
            }
            else
            {
                if (GameObject.GetInstance().HumanAirline.Contract != null)
                {
                    if (GameObject.GetInstance().HumanAirline.Contract.Manufacturer == this.Manufacturer)
                    {
                        contractedOrder = true;
                    }
                    else
                    {
                        double terminationFee      = GameObject.GetInstance().HumanAirline.Contract.getTerminationFee();
                        WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2010"), string.Format(Translator.GetInstance().GetString("MessageBox", "2010", "message"), GameObject.GetInstance().HumanAirline.Contract.Manufacturer.Name, terminationFee), WPFMessageBoxButtons.YesNo);

                        if (result == WPFMessageBoxResult.Yes)
                        {
                            AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -terminationFee);
                            GameObject.GetInstance().HumanAirline.Contract = null;
                        }
                        tryOrder = result == WPFMessageBoxResult.Yes;
                    }
                }

                if (tryOrder)
                {
                    int    totalAmount = orders.Sum(o => o.Amount);
                    double price       = orders.Sum(o => o.Type.Price * o.Amount);

                    double totalPrice = price * ((1 - GeneralHelpers.GetAirlinerOrderDiscount(totalAmount)));

                    if (contractedOrder)
                    {
                        totalPrice = totalPrice * ((100 - GameObject.GetInstance().HumanAirline.Contract.Discount) / 100);
                    }

                    double downpaymentPrice = 0;

                    downpaymentPrice = totalPrice * (GameObject.GetInstance().Difficulty.PriceLevel / 10);

                    if (cbDownPayment.IsChecked.Value)
                    {
                        if (downpaymentPrice > GameObject.GetInstance().HumanAirline.Money)
                        {
                            WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2001"), Translator.GetInstance().GetString("MessageBox", "2001", "message"), WPFMessageBoxButtons.Ok);
                        }
                        else
                        {
                            WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2009"), string.Format(Translator.GetInstance().GetString("MessageBox", "2009", "message"), totalPrice, downpaymentPrice), WPFMessageBoxButtons.YesNo);

                            if (result == WPFMessageBoxResult.Yes)
                            {
                                foreach (AirlinerOrder order in orders)
                                {
                                    for (int i = 0; i < order.Amount; i++)
                                    {
                                        Guid id = Guid.NewGuid();

                                        Airliner airliner = new Airliner(id.ToString(), order.Type, GameObject.GetInstance().HumanAirline.Profile.Country.TailNumbers.getNextTailNumber(), dpDate.SelectedDate.Value);

                                        airliner.clearAirlinerClasses();

                                        foreach (AirlinerClass aClass in order.Classes)
                                        {
                                            AirlinerClass tClass = new AirlinerClass(aClass.Type, aClass.SeatingCapacity);
                                            tClass.RegularSeatingCapacity = aClass.RegularSeatingCapacity;

                                            foreach (AirlinerFacility facility in aClass.getFacilities())
                                            {
                                                tClass.setFacility(GameObject.GetInstance().HumanAirline, facility);
                                            }

                                            airliner.addAirlinerClass(tClass);
                                        }


                                        Airliners.AddAirliner(airliner);

                                        FleetAirliner.PurchasedType pType = FleetAirliner.PurchasedType.BoughtDownPayment;
                                        GameObject.GetInstance().HumanAirline.addAirliner(pType, airliner, airport);
                                    }
                                }
                                if (contractedOrder)
                                {
                                    GameObject.GetInstance().HumanAirline.Contract.PurchasedAirliners += orders.Sum(o => o.Amount);
                                }
                                AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -downpaymentPrice);

                                PageNavigator.NavigateTo(new PageAirliners());
                            }
                        }
                    }
                    else
                    {
                        if (totalPrice > GameObject.GetInstance().HumanAirline.Money)
                        {
                            WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2001"), Translator.GetInstance().GetString("MessageBox", "2001", "message"), WPFMessageBoxButtons.Ok);
                        }
                        else
                        {
                            if (orders.Sum(o => o.Amount) > 0)
                            {
                                WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2008"), string.Format(Translator.GetInstance().GetString("MessageBox", "2008", "message"), totalPrice), WPFMessageBoxButtons.YesNo);

                                if (result == WPFMessageBoxResult.Yes)
                                {
                                    if (contractedOrder)
                                    {
                                        AirlineHelpers.OrderAirliners(GameObject.GetInstance().HumanAirline, orders, airport, dpDate.SelectedDate.Value, GameObject.GetInstance().HumanAirline.Contract.Discount);
                                    }
                                    else
                                    {
                                        AirlineHelpers.OrderAirliners(GameObject.GetInstance().HumanAirline, orders, airport, dpDate.SelectedDate.Value);
                                    }

                                    PageNavigator.NavigateTo(new PageAirliners());
                                }

                                if (contractedOrder)
                                {
                                    GameObject.GetInstance().HumanAirline.Contract.PurchasedAirliners += orders.Sum(o => o.Amount);
                                }
                            }
                        }
                    }
                }
                this.ParentPage.updatePage();
            }
        }
Beispiel #5
0
        //loads a game
        public static void LoadGame(string file)
        {
            string fileName = AppSettings.getCommonApplicationDataPath() + "\\saves\\" + file + ".sav";

            SaveObject deserializedSaveObject = FileSerializer.Deserialize <SaveObject>(fileName);

            /*
             *
             * DataContractSerializer serializer = new DataContractSerializer(typeof(SaveObject));
             * SaveObject deserializedSaveObject;
             * string loading;
             * int version;
             *
             * using (FileStream stream = new FileStream(fileName, FileMode.Open))
             * {
             * using (DeflateStream decompress = new DeflateStream(stream, CompressionMode.Decompress))
             * {
             *     deserializedSaveObject = (SaveObject)serializer.ReadObject(decompress);
             * }
             * }
             *
             * loading = deserializedSaveObject.savetype;
             * version = deserializedSaveObject.saveversionnumber;
             */
            //Parrarel for loading the game
            Parallel.Invoke(() =>
            {
                Airlines.Clear();

                foreach (Airline airline in deserializedSaveObject.airlinesList)
                {
                    Airlines.AddAirline(airline);
                }
            },
                            () =>
            {
                Setup.LoadAirports();

                var airports = Airports.GetAllAirports();

                Airports.Clear();

                foreach (Airport airport in deserializedSaveObject.airportsList)
                {
                    airport.Statics = new AirportStatics(airport);
                    Airports.AddAirport(airport);
                }

                foreach (string iata in deserializedSaveObject.airportsfromstringList)
                {
                    Airport airport = airports.FirstOrDefault(a => a.Profile.IATACode == iata);

                    if (airport != null)
                    {
                        Airports.AddAirport(airport);
                    }
                }
            },
                            () =>
            {
                Airliners.Clear();

                foreach (Airliner airliner in deserializedSaveObject.airlinersList)
                {
                    Airliners.AddAirliner(airliner);
                }
            },
                            () =>
            {
                CalendarItems.Clear();

                foreach (CalendarItem item in deserializedSaveObject.calendaritemsList)
                {
                    CalendarItems.AddCalendarItem(item);
                }
            },
                            () =>
            {
                Configurations.Clear();

                foreach (Configuration configuration in deserializedSaveObject.configurationList)
                {
                    Configurations.AddConfiguration(configuration);
                }
            },
                            () =>
            {
                RandomEvents.Clear();

                foreach (RandomEvent e in deserializedSaveObject.eventsList)
                {
                    RandomEvents.AddEvent(e);
                }
            },
                            () =>
            {
                Alliances.Clear();

                foreach (Alliance alliance in deserializedSaveObject.allianceList)
                {
                    Alliances.AddAlliance(alliance);
                }
            },
                            () =>
            {
                AirportFacilities.Clear();

                foreach (AirportFacility facility in deserializedSaveObject.Airportfacilitieslist)
                {
                    AirportFacilities.AddFacility(facility);
                }
            },
                            () =>
            {
                FeeTypes.Clear();

                foreach (FeeType type in deserializedSaveObject.feeTypeslist)
                {
                    FeeTypes.AddType(type);
                }
            },
                            () =>
            {
                AdvertisementTypes.Clear();

                foreach (AdvertisementType addtype in deserializedSaveObject.advertisementTypeslist)
                {
                    AdvertisementTypes.AddAdvertisementType(addtype);
                }
            },
                            () =>
            {
                AirlinerFacilities.Clear();

                foreach (AirlinerFacility airlinerfas in deserializedSaveObject.airlinerfacilitieslist)
                {
                    AirlinerFacilities.AddFacility(airlinerfas);
                }
            },
                            () =>
            {
                RouteFacilities.Clear();

                foreach (RouteFacility routefas in deserializedSaveObject.routefacilitieslist)
                {
                    RouteFacilities.AddFacility(routefas);
                }
            },
                            () =>
            {
                GameObject.SetInstance(deserializedSaveObject.instance);
                Settings.SetInstance(deserializedSaveObject.settings);
            },
                            () =>
            {
                if (deserializedSaveObject.airlinefacilitieslist != null)
                {
                    AirlineFacilities.Clear();

                    foreach (AirlineFacility airlinefac in deserializedSaveObject.airlinefacilitieslist)
                    {
                        AirlineFacilities.AddFacility(airlinefac);
                    }
                }
            }); //close parallel.invoke

            //for 0.3.9.2 and the issue with no saved facilities on a route classes
            var emptyRouteClassesFacilities = Configurations.GetConfigurations(Configuration.ConfigurationType.Routeclasses).SelectMany(c => ((RouteClassesConfiguration)c).Classes.Where(cl => cl.Facilities == null));

            foreach (RouteClassConfiguration rClassConfiguration in emptyRouteClassesFacilities)
            {
                rClassConfiguration.Facilities = new List <RouteFacility>();
            }

            Setup.SetupLoadedGame();
            //Maybe this helps? But i doubt this is the best way
            Action action = () =>
            {
                Stopwatch swPax = new Stopwatch();
                swPax.Start();

                PassengerHelpers.CreateDestinationDemand();

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

            //create some pilots for the game
            int pilotsPool = 100 * Airlines.GetAllAirlines().Count;

            GeneralHelpers.CreatePilots(pilotsPool);
            int instructorsPool = 75 * Airlines.GetAllAirlines().Count;

            GeneralHelpers.CreateInstructors(instructorsPool);

            //creates some airliners for the game
            AirlinerHelpers.CreateStartUpAirliners();

            //Start the game paused
            GameObjectWorker.GetInstance().startPaused();

            //Task is needed this unlocks the game agian.
            Task.Factory.StartNew(action);
        }