public bool RemoveExpiration(string pcmName, string entry) { for (int i = _expireTimes.Count; i-- > 0;) { TrainingExpiration e = _expireTimes[i]; if (e.PcmName != pcmName) { continue; } for (int j = e.Entries.Count; j-- > 0;) { if (e.Entries[j] == entry) { e.Entries.RemoveAt(j); if (e.Entries.Count == 0) { _expireTimes.RemoveAt(i); } return(true); } } } return(false); }
private void ProcessCourses(double time) { bool anyCourseEnded = false; for (int i = ActiveCourses.Count; i-- > 0;) { ActiveCourse course = ActiveCourses[i]; if (course.ProgressTime(time)) //returns true when the course completes { ActiveCourses.RemoveAt(i); anyCourseEnded = true; } } for (int i = _expireTimes.Count; i-- > 0;) { TrainingExpiration e = _expireTimes[i]; if (time > e.Expiration) { ProtoCrewMember pcm = HighLogic.CurrentGame.CrewRoster[e.PcmName]; if (pcm != null) { for (int j = pcm.careerLog.Entries.Count; j-- > 0;) { if (e.Entries.Count == 0) { break; } FlightLog.Entry ent = pcm.careerLog[j]; for (int k = e.Entries.Count; k-- > 0;) { // Allow only mission trainings to expire. // This check is actually only needed for old savegames as only these can have expirations on proficiencies. if (ent.type == "TRAINING_mission" && e.Compare(k, ent)) { ScreenMessages.PostScreenMessage($"{pcm.name}: Expired: {GetPrettyCourseName(ent.type)}{ent.target}"); ent.type = "expired_" + ent.type; e.Entries.RemoveAt(k); } } } } _expireTimes.RemoveAt(i); } } if (anyCourseEnded) { MaintenanceHandler.Instance?.ScheduleMaintenanceUpdate(); } }
private double GetExpiration(string pcmName, FlightLog.Entry ent) { for (int i = _expireTimes.Count; i-- > 0;) { TrainingExpiration e = _expireTimes[i]; if (e.PcmName == pcmName) { for (int j = e.Entries.Count; j-- > 0;) { if (e.Compare(j, ent)) { return(e.Expiration); } } } } return(0d); }
private bool SetExpiration(string pcmName, FlightLog.Entry ent, double expirationUT) { for (int i = _expireTimes.Count; i-- > 0;) { TrainingExpiration e = _expireTimes[i]; if (e.PcmName == pcmName) { for (int j = e.Entries.Count; j-- > 0;) { if (e.Compare(j, ent)) { e.Expiration = expirationUT; return(true); } } } } return(false); }
public void CompleteCourse() { //assign rewards to all kerbals and set them to free if (Completed) { foreach (ProtoCrewMember student in Students) { if (student == null) { continue; } if (ExpireLog != null) { foreach (ConfigNode.Value v in ExpireLog.values) { for (int i = student.careerLog.Count; i-- > 0;) { FlightLog.Entry e = student.careerLog.Entries[i]; if (TrainingExpiration.Compare(v.value, e)) { e.type = "expired_" + e.type; CrewHandler.Instance.RemoveExpiration(student.name, v.value); break; } } } } if (RewardLog != null) { if (student.flightLog.Count > 0) { student.ArchiveFlightLog(); } TrainingExpiration exp = null; if (expiration > 0d) { exp = new TrainingExpiration(); exp.PcmName = student.name; exp.Expiration = expiration; if (expirationUseStupid) { exp.Expiration *= UtilMath.Lerp(CrewHandler.Settings.trainingProficiencyStupidMin, CrewHandler.Settings.trainingProficiencyStupidMax, student.stupidity); } exp.Expiration += Planetarium.GetUniversalTime(); } bool prevMissionsAlreadyExpired = false; foreach (ConfigNode.Value v in RewardLog.values) { string[] s = v.value.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); string trainingType = s[0]; string trainingTarget = s.Length == 1 ? null : s[1]; if (!prevMissionsAlreadyExpired && trainingType == "TRAINING_mission") { // Expire any previous mission trainings because only 1 should be active at a time for (int i = student.careerLog.Count; i-- > 0;) { FlightLog.Entry e = student.careerLog.Entries[i]; if (e.type == "TRAINING_mission") { e.type = "expired_" + e.type; CrewHandler.Instance.RemoveExpiration(student.name, v.value); student.ArchiveFlightLog(); prevMissionsAlreadyExpired = true; } } } student.flightLog.AddEntry(trainingType, trainingTarget); student.ArchiveFlightLog(); if (expiration > 0d) { exp.Entries.Add(v.value); } } if (expiration > 0d) { CrewHandler.Instance.AddExpiration(exp); } } if (rewardXP != 0) { student.ExtraExperience += rewardXP; } } } foreach (ProtoCrewMember student in Students) { student.inactive = false; } //fire an event }
public void AddExpiration(TrainingExpiration e) { _expireTimes.Add(e); }