예제 #1
0
        //creates the pilot rating for a pilot student
        public static PilotRating GetPilotStudentRating(Instructor instructor)
        {
            PilotRating instructorRanking = instructor.Rating;
            int         aircraftCoeff     = instructor.FlightSchool.TrainingAircrafts.Exists(a => a.Type.MaxNumberOfStudents > 5) ? 10 : 0;

            int instructorRankingIndex             = PilotRatings.GetRatings().IndexOf(instructorRanking);
            Dictionary <PilotRating, int> rankings = new Dictionary <PilotRating, int>();

            rankings.Add(instructorRanking, 50);

            if (instructorRankingIndex > 0)
            {
                PilotRating prevRating = PilotRatings.GetRatings()[instructorRankingIndex - 1];
                rankings.Add(prevRating, 35 - aircraftCoeff);
            }
            if (instructorRankingIndex < PilotRatings.GetRatings().Count)
            {
                PilotRating nextRating = PilotRatings.GetRatings()[instructorRankingIndex + 1];

                rankings.Add(nextRating, 15 + aircraftCoeff);
            }

            PilotRating rating = AIHelpers.GetRandomItem <PilotRating>(rankings);

            return(rating);
        }
예제 #2
0
        //creates a number of airliner families a pilot can fly
        public static List <string> GetPilotAircrafts(Pilot pilot)
        {
            int year = GameObject.GetInstance().GameTime.Year;

            var airlinerFamilies = AirlinerTypes.GetTypes(t => t.Produced.From.Year <= GameObject.GetInstance().GameTime.Year&& t.Produced.To > GameObject.GetInstance().GameTime.AddYears(-30)).Select(a => a.AirlinerFamily).Distinct();

            Random        rnd      = new Random();
            List <string> families = new List <string>();

            int numberOfAircrafts = PilotRatings.GetRatings().IndexOf(pilot.Rating) + 1;

            for (int i = 0; i < numberOfAircrafts; i++)
            {
                var    freeFamilies = airlinerFamilies.Where(a => !families.Contains(a)).ToList();
                string family       = freeFamilies[rnd.Next(freeFamilies.Count)];

                families.Add(family);
            }

            return(families);
        }
예제 #3
0
        private void btnHire_Click(object sender, RoutedEventArgs e)
        {
            var aircraftsTypesFree = this.FlightSchool.Aircrafts.Select(a => a.Type);

            Dictionary <TrainingAircraftType, int> types = this.FlightSchool.Aircrafts.GroupBy(a => a.Type).
                                                           Select(group =>
                                                                  new
            {
                Type  = group.Key,
                Count = group.Sum(g => g.Type.MaxNumberOfStudents)
            }).ToDictionary(g => g.Type, g => g.Count);;


            foreach (PilotStudent student in this.FlightSchool.Students)
            {
                var firstAircraft = student.Rating.Aircrafts.OrderBy(a => a.TypeLevel).FirstOrDefault(a => types.ContainsKey(a) && types[a] > 0);

                if (firstAircraft != null && types.ContainsKey(firstAircraft))
                {
                    types[firstAircraft]--;
                }
            }

            List <PilotRating> possibleRatings = new List <PilotRating>();

            foreach (PilotRating rating in PilotRatings.GetRatings())
            {
                if (rating.Aircrafts.Exists(a => types.ContainsKey(a) && types[a] > 0))
                {
                    possibleRatings.Add(rating);
                }
            }

            WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2811"), string.Format(Translator.GetInstance().GetString("MessageBox", "2811", "message")), WPFMessageBoxButtons.YesNo);

            if (result == WPFMessageBoxResult.Yes)
            {
                List <Town> towns = Towns.GetTowns(this.FlightSchool.FlightSchool.Airport.Profile.Country);

                Town         town      = towns[rnd.Next(towns.Count)];
                DateTime     birthdate = MathHelpers.GetRandomDate(GameObject.GetInstance().GameTime.AddYears(-35), GameObject.GetInstance().GameTime.AddYears(-23));
                PilotProfile profile   = new PilotProfile(Names.GetInstance().getRandomFirstName(town.Country), Names.GetInstance().getRandomLastName(town.Country), birthdate, town);

                Instructor instructor     = (Instructor)cbInstructor.SelectedItem;
                string     airlinerFamily = cbTrainAircraft.SelectedItem.ToString();

                PilotStudent student = new PilotStudent(profile, GameObject.GetInstance().GameTime, instructor, GeneralHelpers.GetPilotStudentRating(instructor, possibleRatings), airlinerFamily);

                TrainingAircraft aircraft = getStudentAircraft(student);

                student.Aircraft = aircraft;

                this.FlightSchool.addStudent(student);
                instructor.addStudent(student);

                setHireStudentsStatus();

                double studentPrice = GeneralHelpers.GetInflationPrice(PilotStudent.StudentCost);

                AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Airline_Expenses, -studentPrice);
            }
        }