//returns all the calendaritems for the current date private List <CalendarItem> getCalendarItems(DateTime date) { List <CalendarItem> items = new List <CalendarItem>(); var airlineCountries = (from a in GameObject.GetInstance().HumanAirline.Airports select a.Profile.Country).Distinct(); var holidayGroups = from h in HolidayYear.GetHolidays(date) where (this.ShowAll || airlineCountries.Contains(h.Holiday.Country)) orderby h.Date group h by h.Holiday.Name into gh select new { Holiday = gh.First(), Countries = gh }; foreach (var hg in holidayGroups) { List <Country> countries = new List <Country>(); foreach (var n in hg.Countries) { if (!countries.Contains(n.Holiday.Country)) { countries.Add(n.Holiday.Country); } } items.Add(new CalendarItem(CalendarItem.ItemType.Holiday, date, hg.Holiday.Holiday.Name, string.Join("\r\n", from c in countries select c.Name))); } var airliners = GameObject.GetInstance().HumanAirline.Fleet.FindAll((a => a.Airliner.BuiltDate.ToShortDateString() == date.ToShortDateString() && date > GameObject.GetInstance().GameTime)); if (airliners.Count > 0) { items.Add(new CalendarItem(CalendarItem.ItemType.Airliner_Order, date, "Delivery of airliners", string.Join("\r\n", from a in airliners select a.Name))); } foreach (CalendarItem item in CalendarItems.GetCalendarItems(date)) { items.Add(item); } return(items); }
//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(); }
//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); * } * } */ }