//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)); } }
//checks an airport for extending of runway public static void CheckForExtendRunway(Airport airport) { int minYearsBetweenExpansions = 5; long maxRunwayLenght = (from r in airport.Runways select r.Length).Max(); long longestRequiredRunwayLenght = AirlinerTypes.GetTypes(a => a.Produced.From <= GameObject.GetInstance().GameTime&& a.Produced.To >= GameObject.GetInstance().GameTime).Max(a => a.MinRunwaylength); var airportRoutes = AirportHelpers.GetAirportRoutes(airport); var routeAirliners = airportRoutes.SelectMany(r => r.getAirliners()); long longestRunwayInUse = routeAirliners.Count() > 0 ? routeAirliners.Max(a => a.Airliner.Type.MinRunwaylength) : 0; if (maxRunwayLenght < longestRequiredRunwayLenght / 2 && maxRunwayLenght < longestRunwayInUse * 3 / 4 && GameObject.GetInstance().GameTime.AddYears(-minYearsBetweenExpansions) > airport.LastExpansionDate) { List <string> runwayNames = (from r in Airports.GetAllAirports().SelectMany(a => a.Runways) select r.Name).Distinct().ToList(); foreach (Runway r in airport.Runways) { runwayNames.Remove(r.Name); } Runway.SurfaceType surface = airport.Runways[0].Surface; long lenght = Math.Min(longestRequiredRunwayLenght * 3 / 4, longestRunwayInUse * 2); Runway runway = new Runway(runwayNames[rnd.Next(runwayNames.Count)], lenght, surface, GameObject.GetInstance().GameTime.AddDays(90), false); airport.Runways.Add(runway); airport.LastExpansionDate = GameObject.GetInstance().GameTime; } }
//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); } }
//checks if an entry is in occupied slot public static Boolean IsRouteEntryInOccupied(RouteTimeTableEntry entry, FleetAirliner airliner) { var occupiedSlots1 = AirportHelpers.GetOccupiedSlotTimes(entry.DepartureAirport, airliner.Airliner.Airline); var occupiedSlots2 = AirportHelpers.GetOccupiedSlotTimes(entry.Destination.Airport, airliner.Airliner.Airline); TimeSpan gateTimeBefore = new TimeSpan(0, 15, 0); TimeSpan gateTimeAfter = new TimeSpan(0, 15, 0); TimeSpan entryTakeoffTime = new TimeSpan((int)entry.Day, entry.Time.Hours, entry.Time.Minutes, entry.Time.Seconds); TimeSpan entryLandingTime = entryTakeoffTime.Add(entry.TimeTable.Route.getFlightTime(entry.Airliner.Airliner.Type)); if (entryLandingTime.Days > 6) { entryLandingTime = new TimeSpan(0, entryLandingTime.Hours, entryLandingTime.Minutes, entryLandingTime.Seconds); } TimeSpan entryStartTakeoffTime = entryTakeoffTime.Subtract(gateTimeBefore); TimeSpan entryEndTakeoffTime = entryTakeoffTime.Add(gateTimeAfter); TimeSpan tTakeoffTime = new TimeSpan(entryStartTakeoffTime.Days, entryStartTakeoffTime.Hours, (entryStartTakeoffTime.Minutes / 15) * 15, 0); while (tTakeoffTime < entryEndTakeoffTime) { if (occupiedSlots1.Contains(tTakeoffTime)) { return(true); } tTakeoffTime = tTakeoffTime.Add(new TimeSpan(0, 15, 0)); } TimeSpan entryStartLandingTime = entryLandingTime.Subtract(gateTimeBefore); TimeSpan entryEndLandingTime = entryLandingTime.Add(gateTimeAfter); TimeSpan tLandingTime = new TimeSpan(entryStartLandingTime.Days, entryStartLandingTime.Hours, (entryStartLandingTime.Minutes / 15) * 15, 0); while (tLandingTime < entryEndLandingTime) { if (occupiedSlots2.Contains(tLandingTime)) { return(true); } tLandingTime = tLandingTime.Add(new TimeSpan(0, 15, 0)); } return(false); }
//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); }
//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); * } * } */ }