public PageShowPilot(Pilot pilot) { Pilot = pilot; InitializeComponent(); Salary = AirlineHelpers.GetPilotSalary(GameObject.GetInstance().HumanAirline, Pilot); }
//removes a pilot from the list public static void RemovePilot(Pilot pilot) { pilots.Remove(pilot); }
public static void AddPilot(Pilot pilot) { lock (pilots) { if (pilot != null) { pilots.Add(pilot); } } }
//adds a pilot to the airliner public void AddPilot(Pilot pilot) { lock (Pilots) { Pilots.Add(pilot); pilot.Airliner = this; } }
public void RemovePilot(Pilot pilot) { lock (Pilots) { Pilots.Remove(pilot); pilot.Airliner = null; } }
public void AddPilot(Pilot pilot) { if (pilot == null) { throw new NullReferenceException("Pilot is null at Airline.cs/addPilot"); } lock (Pilots) { Pilots.Add(pilot); pilot.Airline = this; } }
public void RemovePilot(Pilot pilot) { Pilots.Remove(pilot); pilot.Airline = null; pilot.Airliner?.RemovePilot(pilot); }
public PilotMVVM(Pilot pilot) { Pilot = pilot; OnTraining = Pilot.OnTraining; }
public static void LoadGame(string name) { if (string.IsNullOrEmpty(name)) { WPFMessageBoxResult result = WPFMessageBox.Show( Translator.GetInstance().GetString("MessageBox", "101"), Translator.GetInstance().GetString("MessageBox", "101", "message"), WPFMessageBoxButtons.Ok); return; } string fileName = AppSettings.GetCommonApplicationDataPath() + "\\saves\\" + name + ".sav"; var doc = new XmlDocument(); using (var fs = new FileStream(fileName, FileMode.Open)) { Stream s = new GZipStream(fs, CompressionMode.Decompress); doc.Load(s); s.Close(); } //doc.Load(AppSettings.getDataPath() + "\\saves\\" + name + ".xml"); XmlElement root = doc.DocumentElement; if (root != null) { DateTime gameTime = DateTime.Parse(root.Attributes["time"].Value, new CultureInfo("de-DE")); GameObject.GetInstance().GameTime = gameTime; } if (root != null) { XmlNodeList tailnumbersList = root.SelectNodes("//tailnumbers/tailnumber"); if (tailnumbersList != null) foreach (XmlElement tailnumberNode in tailnumbersList) { Country country = Countries.GetCountry(tailnumberNode.Attributes["country"].Value); if (country != null) { country.TailNumbers.LastTailNumber = tailnumberNode.Attributes["value"].Value; } } } if (root != null) { XmlNodeList airlinerTypesList = root.SelectNodes("//airlinertypes/airlinertype"); if (airlinerTypesList != null) foreach (XmlElement airlinerTypeNode in airlinerTypesList) { var airlinerType = (AirlinerType.TypeOfAirliner) Enum.Parse(typeof (AirlinerType.TypeOfAirliner), airlinerTypeNode.Attributes["type"].Value); AirlinerType baseType = AirlinerTypes.GetType(airlinerTypeNode.Attributes["basetype"].Value); string airlinerTypeName = airlinerTypeNode.Attributes["name"].Value; AirlinerType type = null; if (airlinerType == AirlinerType.TypeOfAirliner.Passenger) { int cabincrew = Convert.ToInt16(airlinerTypeNode.Attributes["cabincrew"].Value); int passengers = Convert.ToInt16(airlinerTypeNode.Attributes["passengers"].Value); int maxclasses = Convert.ToInt16(airlinerTypeNode.Attributes["maxclasses"].Value); type = new AirlinerPassengerType( baseType.Manufacturer, airlinerTypeName, "", passengers, baseType.CockpitCrew, cabincrew, 0, 0, baseType.Wingspan, baseType.Length, baseType.Weight, 0, baseType.Price, maxclasses, 0, baseType.FuelCapacity, baseType.Body, baseType.RangeType, baseType.Engine, baseType.Produced, baseType.ProductionRate, false, false); } if (airlinerType == AirlinerType.TypeOfAirliner.Cargo) { double cargo = Convert.ToDouble( airlinerTypeNode.Attributes["cargo"].Value, new CultureInfo("de-DE", false)); type = new AirlinerCargoType( baseType.Manufacturer, airlinerTypeName, "", baseType.CockpitCrew, cargo, 0, 0, baseType.Wingspan, baseType.Length, baseType.Weight, 0, baseType.Price, 0, baseType.FuelCapacity, baseType.Body, baseType.RangeType, baseType.Engine, baseType.Produced, baseType.ProductionRate, false, false); } if (type != null) { type.BaseType = baseType; AirlinerTypes.AddType(type); } } } Airliners.Clear(); if (root != null) { XmlNodeList airlinersList = root.SelectNodes("//airliners/airliner"); if (airlinersList != null) Parallel.For( 0, airlinersList.Count, i => //foreach (XmlElement airlinerNode in airlinersList) { var airlinerNode = (XmlElement) airlinersList[i]; AirlinerType type = AirlinerTypes.GetType(airlinerNode.Attributes["type"].Value); if (type != null) { string tailnumber = airlinerNode.Attributes["tailnumber"].Value; string id = airlinerNode.HasAttribute("id") ? airlinerNode.Attributes["id"].Value : tailnumber; string last_service = airlinerNode.Attributes["last_service"].Value; DateTime built = DateTime.Parse( airlinerNode.Attributes["built"].Value, new CultureInfo("de-DE", false)); double flown = Convert.ToDouble( airlinerNode.Attributes["flown"].Value, new CultureInfo("de-DE", false)); double damaged = Convert.ToDouble( airlinerNode.Attributes["damaged"].Value, new CultureInfo("de-DE", false)); var airliner = new Airliner(id, type, tailnumber, built) {Condition = damaged, Flown = flown}; airliner.ClearAirlinerClasses(); XmlNodeList airlinerClassList = airlinerNode.SelectNodes("classes/class"); if (airlinerClassList != null) foreach (XmlElement airlinerClassNode in airlinerClassList) { var airlinerClassType = (AirlinerClass.ClassType) Enum.Parse( typeof (AirlinerClass.ClassType), airlinerClassNode.Attributes["type"].Value); int airlinerClassSeating = Convert.ToInt16(airlinerClassNode.Attributes["seating"].Value); var aClass = new AirlinerClass(airlinerClassType, airlinerClassSeating); // chs, 2011-13-10 added for loading of airliner facilities XmlNodeList airlinerClassFacilitiesList = airlinerClassNode.SelectNodes("facilities/facility"); if (airlinerClassFacilitiesList != null) foreach (XmlElement airlinerClassFacilityNode in airlinerClassFacilitiesList) { var airlinerFacilityType = (AirlinerFacility.FacilityType) Enum.Parse( typeof (AirlinerFacility.FacilityType), airlinerClassFacilityNode.Attributes["type"].Value); AirlinerFacility aFacility = AirlinerFacilities.GetFacility( airlinerFacilityType, airlinerClassFacilityNode.Attributes["uid"].Value); aClass.ForceSetFacility(aFacility); } airliner.AddAirlinerClass(aClass); } Airliners.AddAirliner(airliner); } }); } Airlines.Clear(); if (root != null) { XmlNodeList airlinesList = root.SelectNodes("//airlines/airline[@subsidiary='False']"); if (airlinesList != null) foreach (XmlElement airlineNode in airlinesList) { LoadAirline(airlineNode); } } if (root != null) { XmlNodeList subsidiaryList = root.SelectNodes("//airlines/airline[@subsidiary='True']"); if (subsidiaryList != null) foreach (XmlElement airlineNode in subsidiaryList) { LoadAirline(airlineNode); } } if (root != null) { XmlNodeList airportsList = root.SelectNodes("//airports/airport"); var airportsToKeep = new List<Airport>(); if (airportsList != null) foreach (XmlElement airportNode in airportsList) { Airport airport = Airports.GetAirportFromID(airportNode.Attributes["id"].Value); airportsToKeep.Add(airport); /* * XmlElement airportPaxNode = xmlDoc.CreateElement("paxvalue"); airportPaxNode.SetAttribute("from", paxValue.FromYear.ToString()); airportPaxNode.SetAttribute("to", paxValue.ToYear.ToString()); airportPaxNode.SetAttribute("size", paxValue.Size.ToString()); airportPaxNode.SetAttribute("pax", paxValue.Pax.ToString()); airportPaxNode.SetAttribute("inflationbefore", paxValue.InflationBeforeYear.ToString()); airportPaxNode.SetAttribute("inflationafter", paxValue.InflationAfterYear.ToString()); */ airport.Income = Convert.ToInt64(airportNode.Attributes["income"].Value); airport.Profile.PaxValues.Clear(); XmlNodeList paxvaluesList = airportNode.SelectNodes("paxvalues/paxvalue"); foreach (XmlElement paxElement in paxvaluesList) { int fromYear = Convert.ToInt16(paxElement.Attributes["from"].Value); int toYear = Convert.ToInt16(paxElement.Attributes["to"].Value); var airportSize = (GeneralHelpers.Size) Enum.Parse(typeof (GeneralHelpers.Size), paxElement.Attributes["size"].Value); double pax = Convert.ToDouble(paxElement.Attributes["pax"].Value); double inflationBefore = Convert.ToDouble(paxElement.Attributes["inflationbefore"].Value); double inflationAfter = Convert.ToDouble(paxElement.Attributes["inflationafter"].Value); var paxValue = new PaxValue(fromYear, toYear, airportSize, pax) {InflationAfterYear = inflationAfter, InflationBeforeYear = inflationBefore}; airport.Profile.PaxValues.Add(paxValue); } XmlNodeList runwaysList = airportNode.SelectNodes("runways/runway"); foreach (XmlElement runwayElement in runwaysList) { string runwayName = runwayElement.Attributes["name"].Value; long runwayLenght = Convert.ToInt64(runwayElement.Attributes["lenght"].Value); var runwaySurface = (Runway.SurfaceType) Enum.Parse(typeof (Runway.SurfaceType), runwayElement.Attributes["surface"].Value); DateTime runwayDate = DateTime.Parse( runwayElement.Attributes["date"].Value, new CultureInfo("de-DE", false)); airport.Runways.Add(new Runway(runwayName, runwayLenght, Runway.RunwayType.Regular, runwaySurface, runwayDate, false)); } XmlNodeList airportHubsList = airportNode.SelectNodes("hubs/hub"); // airport.Hubs.Clear(); foreach (XmlElement airportHubElement in airportHubsList) { Airline airline = Airlines.GetAirline(airportHubElement.Attributes["airline"].Value); // airport.Hubs.Add(new Hub(airline,null)); } XmlNodeList airportWeatherList = airportNode.SelectNodes("weathers/weather"); for (int i = 0; i < airportWeatherList.Count; i++) { var airportWeatherElement = airportWeatherList[i] as XmlElement; DateTime weatherDate = DateTime.Parse( airportWeatherElement.Attributes["date"].Value, new CultureInfo("de-DE", false)); var windDirection = (Weather.WindDirection) Enum.Parse( typeof (Weather.WindDirection), airportWeatherElement.Attributes["direction"].Value); var windSpeed = (Weather.eWindSpeed) Enum.Parse(typeof (Weather.eWindSpeed), airportWeatherElement.Attributes["windspeed"].Value); Weather.CloudCover cover = airportWeatherElement.HasAttribute("cover") ? (Weather.CloudCover) Enum.Parse(typeof (Weather.CloudCover), airportWeatherElement.Attributes["cover"].Value) : Weather.CloudCover.Clear; Weather.Precipitation precip = airportWeatherElement.HasAttribute("precip") ? (Weather.Precipitation) Enum.Parse(typeof (Weather.Precipitation), airportWeatherElement.Attributes["precip"].Value) : Weather.Precipitation.None; double temperatureLow = airportWeatherElement.HasAttribute("temperatureLow") ? Convert.ToDouble( airportWeatherElement.Attributes["temperaturelow"].Value, new CultureInfo("de-DE", false)) : 0; double temperatureHigh = airportWeatherElement.HasAttribute("temperatureHigh") ? Convert.ToDouble( airportWeatherElement.Attributes["temperaturehigh"].Value, new CultureInfo("de-DE", false)) : 20; XmlNodeList airportTemperatureList = airportWeatherElement.SelectNodes("temperatures/temperature"); var temperatures = new HourlyWeather[airportTemperatureList.Count]; int t = 0; foreach (XmlElement airportTemperatureNode in airportTemperatureList) { double hourlyTemperature = Convert.ToDouble( airportTemperatureNode.Attributes["temp"].Value, new CultureInfo("de-DE", false)); var hourlyCover = (Weather.CloudCover) Enum.Parse(typeof (Weather.CloudCover), airportTemperatureNode.Attributes["cover"].Value); var hourlyPrecip = (Weather.Precipitation) Enum.Parse( typeof (Weather.Precipitation), airportTemperatureNode.Attributes["precip"].Value); var hourlyWindspeed = (Weather.eWindSpeed) Enum.Parse( typeof (Weather.eWindSpeed), airportTemperatureNode.Attributes["windspeed"].Value); var hourlyDirection = (Weather.WindDirection) Enum.Parse( typeof (Weather.WindDirection), airportTemperatureNode.Attributes["direction"].Value); temperatures[t] = new HourlyWeather( hourlyTemperature, hourlyCover, hourlyPrecip, hourlyWindspeed, hourlyDirection); t++; } airport.Weather[i] = new Weather( weatherDate, windSpeed, windDirection, cover, precip, temperatures, temperatureLow, temperatureHigh); } XmlNodeList airportStatList = airportNode.SelectNodes("stats/stat"); foreach (XmlElement airportStatNode in airportStatList) { int year = Convert.ToInt32(airportStatNode.Attributes["year"].Value); Airline airline = Airlines.GetAirline(airportStatNode.Attributes["airline"].Value); string statType = airportStatNode.Attributes["type"].Value; int statValue = Convert.ToInt32(airportStatNode.Attributes["value"].Value); airport.Statistics.SetStatisticsValue( year, airline, StatisticsTypes.GetStatisticsType(statType), statValue); } XmlNodeList airportFacilitiesList = airportNode.SelectNodes("facilities/facility"); airport.ClearFacilities(); foreach (XmlElement airportFacilityNode in airportFacilitiesList) { Airline airline = Airlines.GetAirline(airportFacilityNode.Attributes["airline"].Value); AirportFacility airportFacility = AirportFacilities.GetFacility(airportFacilityNode.Attributes["name"].Value); DateTime finishedDate = DateTime.Parse( airportFacilityNode.Attributes["finished"].Value, new CultureInfo("de-DE", false)); airport.AddAirportFacility(airline, airportFacility, finishedDate); } airport.Terminals.Clear(); XmlNodeList terminalsList = airportNode.SelectNodes("terminals/terminal"); foreach (XmlElement terminalNode in terminalsList) { DateTime deliveryDate = DateTime.Parse( terminalNode.Attributes["delivery"].Value, new CultureInfo("de-DE", false)); Airline owner = Airlines.GetAirline(terminalNode.Attributes["owner"].Value); string terminalName = terminalNode.Attributes["name"].Value; int gates = Convert.ToInt32(terminalNode.Attributes["totalgates"].Value); var terminal = new Terminal(airport, owner, terminalName, gates, deliveryDate, Terminal.TerminalType.Passenger); terminal.Gates.Clear(); XmlNodeList airportGatesList = terminalNode.SelectNodes("gates/gate"); foreach (XmlElement airportGateNode in airportGatesList) { DateTime gateDeliveryDate = DateTime.Parse( airportGateNode.Attributes["delivery"].Value, new CultureInfo("de-DE", false)); var gate = new Gate(gateDeliveryDate); terminal.Gates.AddGate(gate); } airport.AddTerminal(terminal); } airport.ClearAirlineContracts(); XmlNodeList contractsList = airportNode.SelectNodes("contracts/contract"); foreach (XmlElement contractNode in contractsList) { Airline contractAirline = Airlines.GetAirline(contractNode.Attributes["airline"].Value); int contractLength = Convert.ToInt16(contractNode.Attributes["length"].Value); DateTime contractDate = DateTime.Parse( contractNode.Attributes["date"].Value, new CultureInfo("de-DE", false)); int contractGates = Convert.ToInt16(contractNode.Attributes["gates"].Value); double contractPayment = Convert.ToDouble( contractNode.Attributes["payment"].Value, new CultureInfo("de-DE", false)); Boolean contractExclusive = Convert.ToBoolean(contractNode.Attributes["exclusive"].Value); Terminal contractTerminal = contractNode.HasAttribute("terminal") ? airport.Terminals.AirportTerminals.Find( t => t.Name == contractNode.Attributes["terminal"].Value) : null; var contract = new AirportContract( contractAirline, airport, AirportContract.ContractType.Full, Terminal.TerminalType.Passenger, contractDate, contractGates, contractLength, contractPayment, true, false, contractExclusive, contractTerminal); AirportHelpers.AddAirlineContract(contract); } } Airports.RemoveAirports(a => !airportsToKeep.Contains(a)); } XmlNodeList airportDestinationsList = root.SelectNodes("//airportdestinations/airportdestination"); foreach (XmlElement airportDestinationElement in airportDestinationsList) { Airport targetAirport = Airports.GetAirport(airportDestinationElement.Attributes["id"].Value); if (targetAirport != null) { targetAirport.ClearDestinationPassengers(); XmlNodeList destinationsList = airportDestinationElement.SelectNodes("destinations/destination"); Parallel.For( 0, destinationsList.Count, i => //foreach (XmlElement destinationElement in destinationsList) { var destinationElement = (XmlElement) destinationsList[i]; Airport destAirport = Airports.GetAirport(destinationElement.Attributes["id"].Value); if (destAirport != null) { ushort rate = ushort.Parse(destinationElement.Attributes["rate"].Value); long destPassengers = Convert.ToInt64(destinationElement.Attributes["passengers"].Value); targetAirport.AddPassengerDestinationStatistics(destAirport, destPassengers); targetAirport.AddDestinationPassengersRate( new DestinationDemand(destAirport.Profile.IATACode, rate)); if (destinationElement.HasAttribute("cargo")) { targetAirport.AddDestinationCargoRate( new DestinationDemand( destAirport.Profile.IATACode, ushort.Parse(destinationElement.Attributes["cargo"].Value))); targetAirport.AddCargoDestinationStatistics( destAirport, Convert.ToDouble( destinationElement.Attributes["cargostats"].Value, new CultureInfo("de-DE", false))); } } }); } } Instructors.Clear(); XmlNodeList instructorsList = root.SelectNodes("//instructors/instructor"); foreach (XmlElement instructorNode in instructorsList) { string firstname = instructorNode.Attributes["firstname"].Value; string lastname = instructorNode.Attributes["lastname"].Value; DateTime birthdate = DateTime.Parse( instructorNode.Attributes["birthdate"].Value, new CultureInfo("de-DE", false)); Town town = Towns.GetTown(instructorNode.Attributes["town"].Value); //Pilot.PilotRating rating = (Pilot.PilotRating)Enum.Parse(typeof(Pilot.PilotRating), instructorNode.Attributes["rating"].Value); string id = instructorNode.Attributes["id"].Value; var instructor = new Instructor( new PilotProfile(firstname, lastname, birthdate, town), PilotRatings.GetRating("A")); if (id != "-") { FlightSchool fs = Airlines.GetAllAirlines() .SelectMany(a => a.FlightSchools).FirstOrDefault(f => f.ID == id); instructor.FlightSchool = fs; fs.AddInstructor(instructor); } XmlNodeList studentsList = instructorNode.SelectNodes("students/student"); foreach (XmlElement studentNode in studentsList) { PilotStudent student = instructor.FlightSchool.Students.Find( s => s.Profile.Name == studentNode.Attributes["name"].Value); student.Instructor = instructor; instructor.AddStudent(student); } Instructors.AddInstructor(instructor); } if (Instructors.GetInstructors().Count == 0) { GeneralHelpers.CreateInstructors(75*Airlines.GetAllAirlines().Count); } Pilots.Clear(); XmlNodeList pilotsList = root.SelectNodes("//pilots/pilot"); foreach (XmlElement pilotNode in pilotsList) { string firstname = pilotNode.Attributes["firstname"].Value; string lastname = pilotNode.Attributes["lastname"].Value; DateTime birthdate = DateTime.Parse( pilotNode.Attributes["birthdate"].Value, new CultureInfo("de-DE", false)); Town town = Towns.GetTown(pilotNode.Attributes["town"].Value); DateTime educationdate = DateTime.Parse( pilotNode.Attributes["education"].Value, new CultureInfo("de-DE", false)); //Pilot.PilotRating rating = (Pilot.PilotRating)Enum.Parse(typeof(Pilot.PilotRating), pilotNode.Attributes["rating"].Value); var pilot = new Pilot( new PilotProfile(firstname, lastname, birthdate, town), educationdate, PilotRatings.GetRating("B")); if (pilotNode.Attributes["airline"].Value != "-") { Airline pilotAirline = Airlines.GetAirline(pilotNode.Attributes["airline"].Value); DateTime airlinesigneddate = DateTime.Parse( pilotNode.Attributes["airlinesigned"].Value, new CultureInfo("de-DE", false)); pilotAirline.AddPilot(pilot); pilot.AirlineSignedDate = airlinesigneddate; if (pilotNode.Attributes["airliner"].Value != "-") { FleetAirliner airliner = pilotAirline.Fleet.Find(f => f.Airliner.ID == pilotNode.Attributes["airliner"].Value); if (airliner != null) { pilot.Airliner = airliner; airliner.AddPilot(pilot); } } } Pilots.AddPilot(pilot); } if (Pilots.GetNumberOfPilots() == 0) { var rnd = new Random(); GeneralHelpers.CreatePilots(100*Airlines.GetAllAirlines().Count); foreach (FleetAirliner airliner in Airlines.GetAllAirlines().SelectMany(a => a.Fleet)) { Pilot pilot = Pilots.GetPilots()[rnd.Next(Pilots.GetNumberOfPilots())]; airliner.Airliner.Airline.AddPilot(pilot); pilot.Airliner = airliner; airliner.AddPilot(pilot); } } Alliances.Clear(); XmlNodeList alliancesList = root.SelectNodes("//alliances/alliance"); foreach (XmlElement allianceNode in alliancesList) { string allianceName = allianceNode.Attributes["name"].Value; DateTime formationDate = DateTime.Parse( allianceNode.Attributes["formation"].Value, new CultureInfo("de-DE")); Airport allianceHeadquarter = Airports.GetAirport(allianceNode.Attributes["headquarter"].Value); var alliance = new Alliance(formationDate, allianceName, allianceHeadquarter); XmlNodeList membersList = allianceNode.SelectNodes("members/member"); foreach (XmlElement memberNode in membersList) { Airline allianceMember = Airlines.GetAirline(memberNode.Attributes["airline"].Value); DateTime joinedDate = DateTime.Parse( memberNode.Attributes["joined"].Value, new CultureInfo("de-DE")); if (allianceMember != null) { alliance.AddMember(new AllianceMember(allianceMember, joinedDate)); } } XmlNodeList pendingsList = allianceNode.SelectNodes("pendings/pending"); foreach (XmlElement pendingNode in pendingsList) { Airline pendingAirline = Airlines.GetAirline(pendingNode.Attributes["airline"].Value); DateTime pendingDate = DateTime.Parse( pendingNode.Attributes["date"].Value, new CultureInfo("de-DE")); var pendingType = (PendingAllianceMember.AcceptType) Enum.Parse(typeof (PendingAllianceMember.AcceptType), pendingNode.Attributes["type"].Value); alliance.AddPendingMember( new PendingAllianceMember(pendingDate, alliance, pendingAirline, pendingType)); } Alliances.AddAlliance(alliance); } Configurations.Clear(); XmlNodeList configurationsList = root.SelectNodes("//configurations/configuration"); foreach (XmlElement confElement in configurationsList) { string confName = confElement.Attributes["name"].Value; string confid = confElement.Attributes["id"].Value; Boolean standard = Convert.ToBoolean(confElement.Attributes["standard"].Value); int minimumSeats = Convert.ToInt16(confElement.Attributes["minimumseats"].Value); var configuration = new AirlinerConfiguration(confName, minimumSeats, standard) {ID = confid}; XmlNodeList classesList = confElement.SelectNodes("classes/class"); foreach (XmlElement classElement in classesList) { int seating = Convert.ToInt16(classElement.Attributes["seating"].Value); int regularseating = Convert.ToInt16(classElement.Attributes["regularseating"].Value); var classType = (AirlinerClass.ClassType) Enum.Parse(typeof (AirlinerClass.ClassType), classElement.Attributes["type"].Value); var classConf = new AirlinerClassConfiguration(classType, seating, regularseating); foreach ( AirlinerFacility.FacilityType facType in Enum.GetValues(typeof (AirlinerFacility.FacilityType))) { string facUid = classElement.Attributes[facType.ToString()].Value; classConf.AddFacility(AirlinerFacilities.GetFacility(facType, facUid)); } configuration.AddClassConfiguration(classConf); } Configurations.AddConfiguration(configuration); } XmlNodeList routeConfigurationsList = root.SelectNodes("//routeclassesconfigurations/routeclassesconfiguration"); foreach (XmlElement confElement in routeConfigurationsList) { string routeConfName = confElement.Attributes["name"].Value; string confid = confElement.Attributes["id"].Value; Boolean standard = Convert.ToBoolean(confElement.Attributes["standard"].Value); XmlNodeList classesList = confElement.SelectNodes("classes/class"); var classesConfiguration = new RouteClassesConfiguration(routeConfName, standard) {ID = confid}; foreach (XmlElement classElement in classesList) { var classType = (AirlinerClass.ClassType) Enum.Parse(typeof (AirlinerClass.ClassType), classElement.Attributes["type"].Value); var classConf = new RouteClassConfiguration(classType); foreach (RouteFacility.FacilityType facType in Enum.GetValues(typeof (RouteFacility.FacilityType))) { if (classElement.HasAttribute(facType.ToString())) { string facilityName = classElement.Attributes[facType.ToString()].Value; classConf.AddFacility( RouteFacilities.GetFacilities(facType).Find(f => f.Name == facilityName)); } } classesConfiguration.AddClass(classConf); } Configurations.AddConfiguration(classesConfiguration); } var difficultyNode = (XmlElement) root.SelectSingleNode("//difficulty"); string difficultyName = difficultyNode.Attributes["name"].Value; double moneyLevel = Convert.ToDouble( difficultyNode.Attributes["money"].Value, new CultureInfo("de-DE", false)); double priceLevel = Convert.ToDouble( difficultyNode.Attributes["price"].Value, new CultureInfo("de-DE", false)); double loanLevel = Convert.ToDouble( difficultyNode.Attributes["loan"].Value, new CultureInfo("de-DE", false)); double passengersLevel = Convert.ToDouble( difficultyNode.Attributes["passengers"].Value, new CultureInfo("de-DE", false)); double aiLevel = Convert.ToDouble(difficultyNode.Attributes["ai"].Value, new CultureInfo("de-DE", false)); GameObject.GetInstance().Difficulty = new DifficultyLevel( difficultyName, moneyLevel, loanLevel, passengersLevel, priceLevel, aiLevel, 1); var scenarioNode = (XmlElement) root.SelectSingleNode("//scenario"); if (scenarioNode != null) { Scenario scenario = Scenarios.GetScenario(scenarioNode.Attributes["name"].Value); var so = new ScenarioObject(scenario) {IsSuccess = Convert.ToBoolean(scenarioNode.Attributes["success"].Value)}; if (scenarioNode.HasAttribute("failed")) { so.ScenarioFailed = scenario.Failures.Find(f => f.ID == scenarioNode.Attributes["failed"].Value); } XmlNodeList failuresList = scenarioNode.SelectNodes("failures/failure"); foreach (XmlElement failureNode in failuresList) { ScenarioFailure failure = scenario.Failures.Find(f => f.ID == failureNode.Attributes["id"].Value); int failureCount = Convert.ToInt16(failureNode.Attributes["count"].Value); DateTime lastFailureTime = DateTime.Parse( failureNode.Attributes["lastfailuretime"].Value, new CultureInfo("de-DE", false)); so.GetScenarioFailure(failure).LastFailureTime = lastFailureTime; so.GetScenarioFailure(failure).Failures = failureCount; } GameObject.GetInstance().Scenario = so; } var gameSettingsNode = (XmlElement) root.SelectSingleNode("//gamesettings"); GameObject.GetInstance().Name = gameSettingsNode.Attributes["name"].Value; Airline humanAirline = Airlines.GetAirline(gameSettingsNode.Attributes["human"].Value); GameObject.GetInstance().SetHumanAirline(humanAirline); Airline mainAirline = Airlines.GetAirline(gameSettingsNode.Attributes["mainairline"].Value); GameObject.GetInstance().MainAirline = mainAirline; double fuelPrice = Convert.ToDouble( gameSettingsNode.Attributes["fuelprice"].Value, new CultureInfo("de-DE", false)); GameTimeZone timezone = TimeZones.GetTimeZones() .Find( gtz => gtz.UTCOffset == TimeSpan.Parse(gameSettingsNode.Attributes["timezone"].Value)); GameObject.GetInstance().TimeZone = timezone; Infrastructure.Settings.GetInstance().MailsOnLandings = Convert.ToBoolean(gameSettingsNode.Attributes["mailonlandings"].Value); Infrastructure.Settings.GetInstance().MailsOnBadWeather = Convert.ToBoolean(gameSettingsNode.Attributes["mailonbadweather"].Value); Infrastructure.Settings.GetInstance().AirportCodeDisplay = (AirportCode) Enum.Parse(typeof (AirportCode), gameSettingsNode.Attributes["airportcode"].Value); if (gameSettingsNode.HasAttribute("minutesperturn")) { Infrastructure.Settings.GetInstance().MinutesPerTurn = Convert.ToInt16(gameSettingsNode.Attributes["minutesperturn"].Value); } AppSettings.GetInstance().SetLanguage(Languages.GetLanguage(gameSettingsNode.Attributes["language"].Value)); GameObject.GetInstance().DayRoundEnabled = Convert.ToBoolean(gameSettingsNode.Attributes["dayround"].Value); XmlNodeList itemsList = gameSettingsNode.SelectNodes("calendaritems/calendaritem"); CalendarItems.Clear(); foreach (XmlElement itemNode in itemsList) { var itemType = (CalendarItem.ItemType) Enum.Parse(typeof (CalendarItem.ItemType), itemNode.Attributes["type"].Value); DateTime itemDate = DateTime.Parse(itemNode.Attributes["date"].Value, new CultureInfo("de-DE", false)); string itemHeader = itemNode.Attributes["header"].Value; string itemSubject = itemNode.Attributes["subject"].Value; CalendarItems.AddCalendarItem(new CalendarItem(itemType, itemDate, itemHeader, itemSubject)); } XmlNodeList newsList = gameSettingsNode.SelectNodes("news/new"); GameObject.GetInstance().NewsBox.Clear(); foreach (XmlElement newsNode in newsList) { DateTime newsDate = DateTime.Parse(newsNode.Attributes["date"].Value, new CultureInfo("de-DE", false)); var newsType = (News.NewsType) Enum.Parse(typeof (News.NewsType), newsNode.Attributes["type"].Value); string newsSubject = newsNode.Attributes["subject"].Value; string newsBody = newsNode.Attributes["body"].Value; Boolean newsIsRead = Convert.ToBoolean(newsNode.Attributes["isread"].Value); var news = new News(newsType, newsDate, newsSubject, newsBody) {IsRead = newsIsRead}; GameObject.GetInstance().NewsBox.AddNews(news); } /* foreach (Airline airline in Airlines.GetAllAirlines()) { foreach (Route route in airline.Routes) { Gate gate1 = route.Destination1.Terminals.getEmptyGate(airline); Gate gate2 = route.Destination2.Terminals.getEmptyGate(airline); if (gate1!=null) gate1.Route = route; if (gate2!=null) gate2.Route = route; } } */ }
//send a pilot for an airline on training public static void SendForTraining(Airline airline, Pilot pilot, string airlinerfamily, int trainingdays, double price) { AddAirlineInvoice(airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.AirlineExpenses, -price); pilot.Training = new PilotTraining(airlinerfamily, GameObject.GetInstance().GameTime.AddDays(trainingdays)); }
//returns the salary for a pilot at an airline public static double GetPilotSalary(Airline airline, Pilot pilot) { double pilotBasePrice = airline.Fees.GetValue(FeeTypes.GetType("Pilot Base Salary")); //GeneralHelpers.GetInflationPrice(133.53);< double pilotExperienceFee = pilot.Aircrafts.Count*GeneralHelpers.GetInflationPrice(20.3); return pilot.Rating.CostIndex*pilotBasePrice + pilotExperienceFee; }
//returns the number of training days a pilot public static int GetTrainingDays(Pilot pilot, string airlinerfamily) { Manufacturer manufacturer = AirlinerTypes.GetTypes(t => t.AirlinerFamily == airlinerfamily).Select(t => t.Manufacturer).FirstOrDefault(); bool hasManufacturer = false; if (manufacturer != null) { foreach (string family in pilot.Aircrafts) { string family1 = family; Manufacturer tManufacturer = AirlinerTypes.GetTypes(t => t.AirlinerFamily == family1).Select(t => t.Manufacturer).FirstOrDefault(); if (tManufacturer != null && tManufacturer.ShortName == manufacturer.ShortName) hasManufacturer = true; } } if (hasManufacturer) return 2; return 14; }
//returns the price for training a pilot public static double GetTrainingPrice(Pilot pilot, string airlinerfamily) { double dayTrainingPrice = GeneralHelpers.GetInflationPrice(750); int days = GetTrainingDays(pilot, airlinerfamily); if (HasTrainingFacility(pilot.Airline, airlinerfamily)) return dayTrainingPrice; return days*dayTrainingPrice; }
//adds a pilot to the airliner //removes a pilot from the airliner public void removePilot(Pilot pilot) { Pilots.Remove(pilot); Airliner.RemovePilot(pilot); IsMissingPilots = true; }
public void addPilot(Pilot pilot) { Pilots.Add(pilot); Airliner.AddPilot(pilot); IsMissingPilots = Airliner.Airliner.Type.CockpitCrew > Pilots.Count; }
private static void DoDailyUpdate() { //Clear stats when it on daily update if (Infrastructure.Settings.GetInstance().ClearStats == Intervals.Daily) { ClearAllUsedStats(); } //Auto save when it on daily if (Infrastructure.Settings.GetInstance().AutoSave == Intervals.Daily) { SerializedLoadSaveHelpers.SaveGame("autosave"); } //Clearing stats as an RAM work-a-round Airports.GetAllAirports().ForEach(a => a.ClearDestinationPassengerStatistics()); Airports.GetAllAirports().ForEach(a => a.ClearDestinationCargoStatistics()); List<Airline> humanAirlines = Airlines.GetAirlines(a => a.IsHuman); //Console.WriteLine(GameObject.GetInstance().GameTime.ToShortDateString() + ": " + DateTime.Now.Subtract(LastTime).TotalMilliseconds + " ms." + " : routes: " + totalRoutes + " airliners on route: " + totalAirlinersOnRoute); _lastTime = DateTime.Now; //changes the fuel prices double fuelDiff = Inflations.GetInflation(GameObject.GetInstance().GameTime.Year + 1).FuelPrice - Inflations.GetInflation(GameObject.GetInstance().GameTime.Year).FuelPrice; double fuelPrice = (Rnd.NextDouble()*(fuelDiff/4)); GameObject.GetInstance().FuelPrice = Inflations.GetInflation(GameObject.GetInstance().GameTime.Year).FuelPrice + fuelPrice; //checks for airports due to close in 14 days List<Airport> closingAirports = Airports.GetAllAirports( a => a.Profile.Period.To.ToShortDateString() == GameObject.GetInstance().GameTime.AddDays(14).ToShortDateString()); List<Airport> openingAirports = Airports.GetAllAirports( a => a.Profile.Period.From.ToShortDateString() == GameObject.GetInstance().GameTime.AddDays(14).ToShortDateString()); foreach (Airport airport in closingAirports) { Airport reallocatedAirport = openingAirports.Find(a => a.Profile.Town == airport.Profile.Town); if (reallocatedAirport == null) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.AirportNews, GameObject.GetInstance().GameTime, "Airport closing", $"The airport [LI airport={airport.Profile.IATACode}]({new AirportCodeConverter().Convert(airport)}) is closing in 14 days.\n\rPlease move all routes to another destination.")); } else { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.AirportNews, GameObject.GetInstance().GameTime, "Airport closing", string.Format( "The airport [LI airport={0}]({1}) is closing in 14 days.\n\rThe airport will be replaced by {2}({3}) and all gates and routes from {0} will be reallocated to {2}.", airport.Profile.IATACode, new AirportCodeConverter().Convert(airport), reallocatedAirport.Profile.Name, new AirportCodeConverter().Convert(reallocatedAirport)))); } CalendarItems.AddCalendarItem( new CalendarItem( CalendarItem.ItemType.AirportClosing, airport.Profile.Period.To, "Airport closing", $"{airport.Profile.Name}, {((Country) new CountryCurrentCountryConverter().Convert(airport.Profile.Country)).Name}")); } foreach (Airport airport in openingAirports) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.AirportNews, GameObject.GetInstance().GameTime, "Airport opening", $"A new airport {airport.Profile.Name}({new AirportCodeConverter().Convert(airport)}) is opening in 14 days in {airport.Profile.Town.Name}, {((Country) new CountryCurrentCountryConverter().Convert(airport.Profile.Country)).Name}.")); CalendarItems.AddCalendarItem( new CalendarItem( CalendarItem.ItemType.AirportOpening, airport.Profile.Period.From, "Airport opening", $"{airport.Profile.Name}, {((Country) new CountryCurrentCountryConverter().Convert(airport.Profile.Country)).Name}")); } //checks for new airports which are opening List<Airport> openedAirports = Airports.GetAllAirports( a => a.Profile.Period.From.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()); List<Airport> closedAirports = Airports.GetAllAirports( a => a.Profile.Period.To.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()); //checks for airports which are closing down foreach (Airport airport in closedAirports) { //check for airport which are reallocated Airport reallocatedAirport = openedAirports.Find(a => a.Profile.Town == airport.Profile.Town); if (reallocatedAirport != null) { IEnumerable<Airline> airlines = new List<Airline>(from c in airport.AirlineContracts select c.Airline).Distinct(); foreach (Airline airline in airlines) { AirlineHelpers.ReallocateAirport(airport, reallocatedAirport, airline); if (airline.IsHuman) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.AirportNews, GameObject.GetInstance().GameTime, "Airport operations changed", $"All your gates, routes and facilities has been moved from {airport.Profile.Name}({new AirportCodeConverter().Convert(airport)}) to [LI airport={reallocatedAirport.Profile.IATACode}]({new AirportCodeConverter().Convert(reallocatedAirport)})")); } } } GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.AirportNews, GameObject.GetInstance().GameTime, "Airport closed", $"The airport {airport.Profile.Name}({new AirportCodeConverter().Convert(airport)}) has now been closed. \n\rAll routes to and from the airports has been cancelled.")); Airport airport1 = airport; IEnumerable<Route> obsoleteRoutes = (from r in Airlines.GetAllAirlines().SelectMany(a => a.Routes) where r.Destination1 == airport1 || r.Destination2 == airport1 select r); foreach (Route route in obsoleteRoutes) { route.Banned = true; foreach (FleetAirliner airliner in route.GetAirliners()) { if (airliner.Homebase == airport) { if (airliner.Airliner.Airline.IsHuman) { airliner.Homebase = (Airport) PopUpNewAirlinerHomebase.ShowPopUp(airliner); } else { AIHelpers.SetAirlinerHomebase(airliner); } } } } } //checks for new airliner types for purchase foreach ( AirlinerType aType in AirlinerTypes.GetTypes( a => a.Produced.From.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()) ) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.AirlinerNews, GameObject.GetInstance().GameTime, "New airliner type available", $"{aType.Manufacturer.Name} has finished the design of {aType.Name} and it is now available for purchase")); if ( !AirlineFacilities.GetFacilities(f => f is PilotTrainingFacility) .Exists(f => ((PilotTrainingFacility) f).AirlinerFamily == aType.AirlinerFamily)) { AirlineFacilities.AddFacility( new PilotTrainingFacility( "airlinefacilities", aType.AirlinerFamily, 9000, 1000, GameObject.GetInstance().GameTime.Year, 0, 0, aType.AirlinerFamily)); } } //checks for airliner types which are out of production foreach ( AirlinerType aType in AirlinerTypes.GetTypes( a => a.Produced.To.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()) ) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.AirlinerNews, GameObject.GetInstance().GameTime, "Airliner type out of production", $"{aType.Manufacturer.Name} has taken {aType.Name} out of production")); Boolean lastFromManufacturer = AirlinerTypes.GetAllTypes().Count(t => (t.Manufacturer == aType.Manufacturer && t.Produced.To > GameObject.GetInstance().GameTime)) == 0; if (lastFromManufacturer) { AirlinerType type = aType; IEnumerable<Airline> manufacturerContracts = Airlines.GetAllAirlines() .Where(a => a.Contract != null && a.Contract.Manufacturer == type.Manufacturer); foreach (Airline contractedAirline in manufacturerContracts) { contractedAirline.Contract = null; } } } //checks for airport facilities for the human airline IEnumerable<AirlineAirportFacility> humanAirportFacilities = (from f in humanAirlines.SelectMany(ai => ai.Airports.SelectMany(a => a.GetAirportFacilities(ai))) where f.FinishedDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString() select f); foreach (AirlineAirportFacility facility in humanAirportFacilities) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.AirportNews, GameObject.GetInstance().GameTime, "Airport facility", $"Your airport facility {facility.Facility.Name} at [LI airport={facility.Airport.Profile.IATACode}] is now finished building")); facility.FinishedDate = GameObject.GetInstance().GameTime; } //checks for changed flight restrictions foreach ( FlightRestriction restriction in FlightRestrictions.GetRestrictions() .FindAll( r => r.StartDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString() || r.EndDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString())) { string restrictionNewsText = ""; if (restriction.Type == FlightRestriction.RestrictionType.Flights) { restrictionNewsText = string.Format(restriction.StartDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString() ? "All flights from {0} to {1} have been banned" : "The ban for all flights from {0} to {1} have been lifted", restriction.From.Name, restriction.To.Name); } if (restriction.Type == FlightRestriction.RestrictionType.Airlines) { restrictionNewsText = string.Format(restriction.StartDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString() ? "All airlines flying from {0} flying to {1} have been blacklisted" : "The blacklist on all airlines from {0} flying to {1} have been lifted", restriction.From.Name, restriction.To.Name); } if (restriction.StartDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()) { if (restriction.Type == FlightRestriction.RestrictionType.Flights) { IEnumerable<Route> bannedRoutes = (from r in Airlines.GetAllAirlines().SelectMany(a => a.Routes) where FlightRestrictions.HasRestriction( r.Destination1.Profile.Country, r.Destination2.Profile.Country, GameObject.GetInstance().GameTime) select r); foreach (Route route in bannedRoutes) { route.Banned = true; } } } GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.StandardNews, GameObject.GetInstance().GameTime, "Flight restriction", restrictionNewsText)); } //checks for historic events foreach (HistoricEvent e in HistoricEvents.GetHistoricEvents(GameObject.GetInstance().GameTime)) { GameObject.GetInstance() .NewsBox.AddNews( new News(News.NewsType.StandardNews, GameObject.GetInstance().GameTime, e.Name, e.Text)); foreach (HistoricEventInfluence influence in e.Influences) { SetHistoricEventInfluence(influence, false); } } //checks for historic events influences ending foreach ( HistoricEventInfluence influence in HistoricEvents.GetHistoricEventInfluences(GameObject.GetInstance().GameTime)) { SetHistoricEventInfluence(influence, true); } //updates airports //Parallel.ForEach( // Airports.GetAllActiveAirports(), // airport => foreach (Airport airport in Airports.GetAllActiveAirports()) { //AirportHelpers.CreateAirportWeather(airport); if (Infrastructure.Settings.GetInstance().MailsOnBadWeather && humanAirlines.SelectMany(a => a.Airports.FindAll(aa => aa == airport)).Any() && (airport.Weather[airport.Weather.Length - 1].WindSpeed == Weather.eWindSpeed.ViolentStorm || airport.Weather[airport.Weather.Length - 1].WindSpeed == Weather.eWindSpeed.Hurricane)) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.AirportNews, GameObject.GetInstance().GameTime, Translator.GetInstance().GetString("News", "1002"), string.Format( Translator.GetInstance().GetString("News", "1002", "message"), airport.Profile.IATACode, GameObject.GetInstance().GameTime.AddDays(airport.Weather.Length - 1).DayOfWeek))); } // chs, 2011-01-11 changed for delivery of terminals foreach (Terminal terminal in airport.Terminals.GetTerminals()) { if (terminal.DeliveryDate.Year == GameObject.GetInstance().GameTime.Year && terminal.DeliveryDate.Month == GameObject.GetInstance().GameTime.Month && terminal.DeliveryDate.Day == GameObject.GetInstance().GameTime.Day) { if (terminal.Airline == null) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.AirportNews, GameObject.GetInstance().GameTime, "Construction of terminal", $"[LI airport={airport.Profile.IATACode}], {airport.Profile.Country.Name} has build a new terminal with {terminal.Gates.NumberOfGates} gates")); } if (terminal.Airline != null && terminal.Airline.IsHuman) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.AirportNews, GameObject.GetInstance().GameTime, "Construction of terminal", $"Your terminal at [LI airport={airport.Profile.IATACode}], {airport.Profile.Country.Name} is now finished and ready for use.")); } if (terminal.Airline != null) { Terminal terminal1 = terminal; IEnumerable<AirportContract> oldContracts = new List<AirportContract>(airport.GetAirlineContracts(terminal.Airline)).Where(c => c.TerminalType == terminal1.Type); var airportContracts = oldContracts as AirportContract[] ?? oldContracts.ToArray(); if (airportContracts.Any()) { int totalGates = airportContracts.Sum(c => c.NumberOfGates); int gatesDiff = totalGates - terminal.Gates.NumberOfGates; if (gatesDiff > 0) { int length = airportContracts.Max(c => c.Length); var newContract = new AirportContract( terminal.Airline, airport, AirportContract.ContractType.Full, terminal.Type, GameObject.GetInstance().GameTime, gatesDiff, length, AirportHelpers.GetYearlyContractPayment( airport, AirportContract.ContractType.Full, gatesDiff, length)/2, true); AirportHelpers.AddAirlineContract(newContract); } foreach (AirportContract oldContract in airportContracts) { airport.RemoveAirlineContract(oldContract); for (int i = 0; i < oldContract.NumberOfGates; i++) { Gate oldGate = airport.Terminals.GetGates().First(g => terminal != null && g.Airline == terminal.Airline); oldGate.Airline = null; } } } double yearlyPayment = AirportHelpers.GetYearlyContractPayment( airport, AirportContract.ContractType.Full, terminal.Gates.NumberOfGates, 20); AirportHelpers.AddAirlineContract( new AirportContract( terminal.Airline, airport, AirportContract.ContractType.Full, terminal.Type, GameObject.GetInstance().GameTime, terminal.Gates.NumberOfGates, 20, yearlyPayment*0.75, true)); if ( terminal.Airport.GetAirportFacility( terminal.Airline, AirportFacility.FacilityType.CheckIn).TypeLevel == 0) { AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn) .Find(f => f.TypeLevel == 1); terminal.Airport.AddAirportFacility( terminal.Airline, checkinFacility, GameObject.GetInstance().GameTime); } } } //new gates in an existing terminal else { int numberOfNewGates = terminal.Gates.GetGates() .Count( g => g.DeliveryDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()); if (numberOfNewGates > 0) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.AirportNews, GameObject.GetInstance().GameTime, "Expansion of terminal", $"[LI airport={airport.Profile.IATACode}], {airport.Profile.Country.Name} has expanded {terminal.Name} with {numberOfNewGates} gates")); double yearlyPayment = AirportHelpers.GetYearlyContractPayment( airport, AirportContract.ContractType.Full, numberOfNewGates + terminal.Gates.NumberOfGates, 20); AirportContract terminalContract = airport.AirlineContracts.Find(c => c.Terminal != null && c.Terminal == terminal); if (terminalContract != null) { terminalContract.NumberOfGates += numberOfNewGates; terminalContract.YearlyPayment = yearlyPayment; for (int i = 0; i < numberOfNewGates; i++) { Gate newGate = airport.Terminals.GetGates().First(g => g.Airline == null); newGate.Airline = terminalContract.Airline; } } } } //expired contracts var airlineContracts = new List<AirportContract>( airport.AirlineContracts.FindAll( c => c.ExpireDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString())); foreach (AirportContract contract in airlineContracts) { if (contract.AutoRenew) { contract.ContractDate = GameObject.GetInstance().GameTime; contract.ExpireDate = GameObject.GetInstance().GameTime.AddYears(contract.Length); if (contract.Airline.IsHuman) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.AirportNews, GameObject.GetInstance().GameTime, "Airport contract renewed", $"Your contract for {contract.NumberOfGates} gates at [LI airport={contract.Airport.Profile.IATACode}], {contract.Airport.Profile.Country.Name} is now been renewed")); } } else { for (int i = 0; i < contract.NumberOfGates; i++) { Gate gate = airport.Terminals.GetGates().First(g => contract != null && g.Airline == contract.Airline); gate.Airline = null; } if (contract.Airline.IsHuman) { int totalContractGates = airport.AirlineContracts.Where(c => c.Airline.IsHuman).Sum(c => c.NumberOfGates); var airlineRoutes = new List<Route>(AirportHelpers.GetAirportRoutes(airport, contract.Airline)); var remainingContracts = new List<AirportContract>( airport.AirlineContracts.FindAll( c => c.Airline == contract.Airline && c != contract)); Boolean canFillRoutes = AirportHelpers.CanFillRoutesEntries( airport, contract.Airline, remainingContracts, Weather.Season.AllYear); if (!canFillRoutes) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.AirportNews, GameObject.GetInstance().GameTime, "Airport contract expired", $"Your contract for {contract.NumberOfGates} gates at [LI airport={contract.Airport.Profile.IATACode}], {contract.Airport.Profile.Country.Name} is now expired, and a number of routes has been cancelled")); int currentRoute = 0; while (!canFillRoutes) { Route routeToDelete = airlineRoutes[currentRoute]; foreach (FleetAirliner fAirliner in routeToDelete.GetAirliners()) { fAirliner.Status = FleetAirliner.AirlinerStatus.Stopped; fAirliner.RemoveRoute(routeToDelete); } contract.Airline.RemoveRoute(routeToDelete); currentRoute++; canFillRoutes = AirportHelpers.CanFillRoutesEntries( airport, contract.Airline, remainingContracts, Weather.Season.AllYear); } } else { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.AirportNews, GameObject.GetInstance().GameTime, "Airport contract expired", $"Your contract for {contract.NumberOfGates} gates at [LI airport={contract.Airport.Profile.IATACode}], {contract.Airport.Profile.Country.Name} is now expired")); } airport.RemoveAirlineContract(contract); } else { int numberOfRoutes = AirportHelpers.GetAirportRoutes(airport, contract.Airline).Count; if (numberOfRoutes > 0) { contract.ContractDate = GameObject.GetInstance().GameTime; contract.ExpireDate = GameObject.GetInstance().GameTime.AddYears(contract.Length); } else { airport.RemoveAirlineContract(contract); } } } } } //checks for airport expansions foreach (AirportExpansion expansion in airport.Profile.Expansions.Where(e => e.Date.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString())) { AirportHelpers.SetAirportExpansion(airport, expansion); } } //); //checks for airliners for the human airline foreach ( FleetAirliner airliner in humanAirlines.SelectMany( a => a.Fleet.FindAll( f => f.Airliner.BuiltDate == GameObject.GetInstance().GameTime && f.Purchased != FleetAirliner.PurchasedType.BoughtDownPayment))) { if (airliner.Airliner.Airline == GameObject.GetInstance().HumanAirline) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.FleetNews, GameObject.GetInstance().GameTime, "Delivery of airliner", $"Your new airliner [LI airliner={airliner.Airliner.TailNumber}] as been delivered to your fleet.\nThe airliner is currently at [LI airport={airliner.Homebase.Profile.IATACode}], {airliner.Homebase.Profile.Country.Name}")); } else { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.FleetNews, GameObject.GetInstance().GameTime, "Delivery of airliner", $"The new airliner [LI airliner={airliner.Airliner.TailNumber}] as been delivered for [LI airline={airliner.Airliner.Airline.Profile.IATACode}].\nThe airliner is currently at [LI airport={airliner.Homebase.Profile.IATACode}], {airliner.Homebase.Profile.Country.Name}")); } } //Parallel.ForEach( // Airlines.GetAllAirlines(), // airline => foreach (Airline airline in Airlines.GetAllAirlines()) { lock (airline.Fleet) { var fleet = new List<FleetAirliner>(airline.Fleet); foreach (FleetAirliner airliner in fleet.FindAll( a => a != null && a.Airliner.BuiltDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString() && a.Purchased == FleetAirliner.PurchasedType.BoughtDownPayment)) { if (airline.Money >= airliner.Airliner.Type.Price) { AirlineHelpers.AddAirlineInvoice( airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -airliner.Airliner.Type.Price); airliner.Purchased = FleetAirliner.PurchasedType.Bought; } else { airline.RemoveAirliner(airliner); if (airline.IsHuman) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.FleetNews, GameObject.GetInstance().GameTime, "Delivery of airliner", $"Your new airliner {airliner.Name} can't be delivered to your fleet.\nYou don't have enough money to purchase it.")); } } } } if (airline.Contract != null && airline.Contract.ExpireDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()) { int missingAirliners = airline.Contract.Airliners - airline.Contract.PurchasedAirliners; if (missingAirliners > 0) { double missingFee = (airline.Contract.GetTerminationFee()/(airline.Contract.Length*2)) *missingAirliners; AirlineHelpers.AddAirlineInvoice( airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -missingFee); if (airline.IsHuman) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.FleetNews, GameObject.GetInstance().GameTime, "Contract expired", $"Your contract with {airline.Contract.Manufacturer.Name} has now expired.\nYou didn't purchased enough airliners with costs a fee of {missingFee:C} for missing {missingAirliners} airliners")); } } else if (airline.IsHuman) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.FleetNews, GameObject.GetInstance().GameTime, "Contract expired", $"Your contract with {airline.Contract.Manufacturer.Name} has now expired.")); } airline.Contract = null; } //checks for students educated IEnumerable<PilotStudent> educatedStudents = airline.FlightSchools.SelectMany( f => f.Students.FindAll( s => s.EndDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString())); foreach (PilotStudent student in educatedStudents) { var pilot = new Pilot(student.Profile, GameObject.GetInstance().GameTime, student.Rating); if (student.AirlinerFamily != "") { pilot.AddAirlinerFamily(student.AirlinerFamily); } student.Instructor.RemoveStudent(student); student.Instructor.FlightSchool.RemoveStudent(student); student.Instructor = null; airline.AddPilot(pilot); if (airline.IsHuman) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.FlightNews, GameObject.GetInstance().GameTime, Translator.GetInstance().GetString("News", "1006"), string.Format( Translator.GetInstance().GetString("News", "1006", "message"), pilot.Profile.Name))); } } IEnumerable<Pilot> trainedPilots = airline.Pilots.Where( p => p.Training != null && p.Training.EndDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()); foreach (Pilot pilot in trainedPilots) { pilot.AddAirlinerFamily(pilot.Training.AirlinerFamily); if (airline.IsHuman) { GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.FlightNews, GameObject.GetInstance().GameTime, Translator.GetInstance().GetString("News", "1015"), string.Format( Translator.GetInstance().GetString("News", "1015", "message"), pilot.Profile.Name, pilot.Training.AirlinerFamily))); } pilot.Training = null; } } //); //checks for mergers foreach (AirlineMerger merger in AirlineMergers.GetAirlineMergers(GameObject.GetInstance().GameTime)) { if (merger.Type == AirlineMerger.MergerType.Merger) { AirlineHelpers.SwitchAirline(merger.Airline2, merger.Airline1); Airlines.RemoveAirline(merger.Airline2); if (merger.NewName != null && merger.NewName.Length > 1) { merger.Airline1.Profile.Name = merger.NewName; } } if (merger.Type == AirlineMerger.MergerType.Subsidiary) { string oldLogo = merger.Airline2.Profile.Logo; var sAirline = new SubsidiaryAirline( merger.Airline1, merger.Airline2.Profile, merger.Airline2.Mentality, merger.Airline2.MarketFocus, merger.Airline2.License, merger.Airline2.AirlineRouteFocus); AirlineHelpers.SwitchAirline(merger.Airline2, merger.Airline1); merger.Airline1.AddSubsidiaryAirline(sAirline); Airlines.RemoveAirline(merger.Airline2); sAirline.Profile.Logos = merger.Airline2.Profile.Logos; sAirline.Profile.Color = merger.Airline2.Profile.Color; } GameObject.GetInstance() .NewsBox.AddNews( new News( News.NewsType.AirlineNews, GameObject.GetInstance().GameTime, "Airline merger", merger.Name)); } /* //does monthly budget work DateTime budgetExpires = GameObject.GetInstance().HumanAirline.Budget.BudgetExpires; if (budgetExpires <= GameObject.GetInstance().GameTime.AddDays(30)) { GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airline_News, GameObject.GetInstance().GameTime, "Budget Expires Soon", "Your budget will expire within the next 30 days. Please go to the budget screen and adjust it as needed and click 'Apply'.")); } else if (budgetExpires <= GameObject.GetInstance().GameTime) { //GraphicsModel.PageModel.PageFinancesModel.PageFinances.ResetValues(); } if (GameObject.GetInstance().HumanAirline.Money < GameObject.GetInstance().HumanAirline.Budget.TotalBudget / 12) { WPFMessageBox.Show("Low Cash!", "Your current cash is less than your budget deduction for the month! Decrease your budget immediately or you will be negative!", WPFMessageBoxButtons.Ok); } else { GameObject.GetInstance().HumanAirline.Money -= GameObject.GetInstance().HumanAirline.Budget.TotalBudget / 12; } * */ //check for insurance settlements and do maintenance foreach (Airline a in Airlines.GetAllAirlines()) { AirlineHelpers.CheckInsuranceSettlements(a); var airliners = new List<FleetAirliner>(a.Fleet); foreach (FleetAirliner airliner in airliners) { if (airliner != null) { FleetAirlinerHelpers.DoMaintenance(airliner); FleetAirlinerHelpers.RestoreMaintRoutes(airliner); } } //checks for special contracts var sContracts = new List<SpecialContract>(a.SpecialContracts.Where(s => s.Date <= GameObject.GetInstance().GameTime)); foreach (SpecialContract sc in sContracts) { if (sc.Date.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString() && sc.Type.IsFixedDate) { foreach (SpecialContractRoute route in sc.Type.Routes) { PassengerHelpers.ChangePaxDemand(route.Departure, route.Destination, (int) route.PassengersPerDay); if (route.BothWays) PassengerHelpers.ChangePaxDemand(route.Destination, route.Departure, (int) route.PassengersPerDay); } } if (AirlineHelpers.CheckSpecialContract(sc)) { a.SpecialContracts.Remove(sc); if (sc.Type.IsFixedDate) { foreach (SpecialContractRoute route in sc.Type.Routes) { PassengerHelpers.ChangePaxDemand(route.Departure, route.Destination, -(int) route.PassengersPerDay); if (route.BothWays) PassengerHelpers.ChangePaxDemand(route.Destination, route.Departure, -(int) route.PassengersPerDay); } } } } } if (GameObject.GetInstance().GameTime.Day%7 == 0) { foreach (Airline airline in Airlines.GetAllAirlines()) airline.OverallScore += StatisticsHelpers.GetWeeklyScore(airline); // GameObject.GetInstance().HumanAirline.OverallScore += // StatisticsHelpers.GetWeeklyScore(GameObject.GetInstance().HumanAirline); } //checks for new special contract types List<SpecialContractType> randomSpecialContracts = SpecialContractTypes.GetRandomTypes(); List<SpecialContractType> fixedSpecialContracts = SpecialContractTypes.GetTypes().FindAll(s => s.IsFixedDate && GameObject.GetInstance().GameTime.ToShortDateString() == s.Period.From.AddMonths(-1).ToShortDateString()); var existingContracts = new List<SpecialContractType>(GameObject.GetInstance().Contracts); foreach (SpecialContractType sct in existingContracts) { if (sct.LastDate.AddMonths(1).ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()) GameObject.GetInstance().Contracts.Remove(sct); else { Boolean taken = false; int i = 0; while (!taken && i < Airlines.GetAirlines(a => !a.IsHuman).Count) { Airline airline = Airlines.GetAirlines(a => !a.IsHuman)[i]; taken = AIHelpers.WillTakeSpecialContract(airline, sct); if (taken) { DateTime startdate = sct.IsFixedDate ? sct.Period.From : GameObject.GetInstance().GameTime; var sc = new SpecialContract(sct, startdate, airline); airline.SpecialContracts.Add(sc); GameObject.GetInstance().Contracts.Remove(sct); } i++; } } } foreach (SpecialContractType sct in fixedSpecialContracts) { if (sct.LastDate == DateTime.MinValue) sct.LastDate = GameObject.GetInstance().GameTime; GameObject.GetInstance().Contracts.Add(sct); } foreach (SpecialContractType sct in randomSpecialContracts) { if (sct.LastDate == DateTime.MinValue) sct.LastDate = GameObject.GetInstance().GameTime; int monthsSinceLast = MathHelpers.GetAgeMonths(sct.LastDate); int monthsFrequency = 12/sct.Frequency; //mf = 12, ms = 1 => procent = lille, mf = 6, ms = 6 => procent = medium, mf = 1, ms = 12 => procent = høj int value = 100 - (monthsSinceLast - monthsFrequency); Boolean createContract = !GameObject.GetInstance().Contracts.Contains(sct) && Rnd.Next(value) == 0; if (createContract) { sct.LastDate = GameObject.GetInstance().GameTime; GameObject.GetInstance().Contracts.Add(sct); } } }