3232 */
3333package mekhq .campaign .personnel .education ;
3434
35+ import static java .lang .Math .max ;
36+ import static megamek .codeUtilities .MathUtility .clamp ;
3537import static megamek .common .compute .Compute .d6 ;
3638import static megamek .common .compute .Compute .randomInt ;
3739import static mekhq .campaign .enums .DailyReportType .FINANCES ;
4547import static mekhq .campaign .personnel .PersonnelOptions .COMPULSION_OTHER_FACTION_HATE ;
4648import static mekhq .campaign .personnel .PersonnelOptions .COMPULSION_PIRATE_HATE ;
4749import static mekhq .campaign .personnel .PersonnelOptions .FLAW_IN_FOR_LIFE ;
50+ import static mekhq .campaign .personnel .skills .SkillType .EXP_ELITE ;
51+ import static mekhq .campaign .personnel .skills .SkillType .EXP_GREEN ;
52+ import static mekhq .campaign .personnel .skills .SkillType .EXP_HEROIC ;
53+ import static mekhq .campaign .personnel .skills .SkillType .EXP_LEGENDARY ;
4854import static mekhq .campaign .personnel .skills .SkillType .EXP_REGULAR ;
55+ import static mekhq .campaign .personnel .skills .SkillType .EXP_ULTRA_GREEN ;
4956import static mekhq .campaign .personnel .skills .SkillType .EXP_VETERAN ;
5057import static mekhq .utilities .MHQInternationalization .getFormattedTextAt ;
5158import static mekhq .utilities .ReportingUtilities .CLOSING_SPAN_TAG ;
7986import mekhq .campaign .personnel .enums .education .EducationStage ;
8087import mekhq .campaign .personnel .familyTree .Genealogy ;
8188import mekhq .campaign .personnel .skills .Skill ;
89+ import mekhq .campaign .personnel .skills .SkillType ;
8290import mekhq .campaign .randomEvents .personalities .enums .Reasoning ;
8391import mekhq .campaign .universe .Faction ;
8492import mekhq .utilities .ReportingUtilities ;
@@ -400,7 +408,7 @@ public static void reEnrollPerson(Campaign campaign, Person person, Academy acad
400408 person .setEduJourneyTime (2 );
401409 person .setEduAcademySystem (campaign .getCurrentSystem ().getId ());
402410 } else {
403- person .setEduJourneyTime (Math . max (2 , person .getEduDaysOfTravel ()));
411+ person .setEduJourneyTime (max (2 , person .getEduDaysOfTravel ()));
404412 }
405413 }
406414
@@ -726,7 +734,7 @@ private static void beginJourneyHome(Campaign campaign, Person person, Academy a
726734 return ;
727735 }
728736
729- int travelTime = Math . max (2 ,
737+ int travelTime = max (2 ,
730738 campaign .getSimplifiedTravelTime (campaign .getSystemById (person .getEduAcademySystem ())));
731739
732740 campaign .addReport (PERSONNEL , String .format (resources .getString ("returningFromSchool.text" ),
@@ -746,7 +754,7 @@ private static void beginJourneyHome(Campaign campaign, Person person, Academy a
746754 */
747755 private static void processJourneyHome (Campaign campaign , Person person ) {
748756 // has the journey time changed?
749- int travelTime = Math . max (2 ,
757+ int travelTime = max (2 ,
750758 campaign .getSimplifiedTravelTime (campaign .getSystemById (person .getEduAcademySystem ())));
751759
752760 // if so, update the journey time
@@ -886,7 +894,7 @@ private static void checkForTrainingAccidents(Campaign campaign, Academy academy
886894 processTrainingInjury (campaign , academy , person , resources );
887895 } else {
888896 String resultString = String .format (resources .getString ("eventTrainingAccidentKilled.text" ),
889- spanOpeningWithCustomColor (ReportingUtilities . getWarningColor ()),
897+ spanOpeningWithCustomColor (getWarningColor ()),
890898 CLOSING_SPAN_TAG );
891899
892900 String reportMessage = String .format (resources .getString ("eventTrainingAccident.text" ),
@@ -917,7 +925,7 @@ private static void processTrainingInjury(Campaign campaign, Academy academy, Pe
917925 int roll = d6 (3 );
918926
919927 String resultString = String .format (resources .getString ("eventTrainingAccidentWounded.text" ),
920- spanOpeningWithCustomColor (ReportingUtilities . getWarningColor ()),
928+ spanOpeningWithCustomColor (getWarningColor ()),
921929 CLOSING_SPAN_TAG ,
922930 roll );
923931
@@ -990,7 +998,7 @@ private static boolean checkForDropout(Campaign campaign, Academy academy, Perso
990998 } else {
991999 String reportMessage = String .format (resources .getString ("dropOutRejected.text" ),
9921000 person .getHyperlinkedFullTitle (),
993- spanOpeningWithCustomColor (ReportingUtilities . getWarningColor ()),
1001+ spanOpeningWithCustomColor (getWarningColor ()),
9941002 CLOSING_SPAN_TAG );
9951003
9961004 campaign .addReport (PERSONNEL , reportMessage );
@@ -1001,7 +1009,7 @@ private static boolean checkForDropout(Campaign campaign, Academy academy, Perso
10011009 // might as well scare the player
10021010 String reportMessage = String .format (resources .getString ("dropOutRejected.text" ),
10031011 person .getHyperlinkedFullTitle (),
1004- spanOpeningWithCustomColor (ReportingUtilities . getWarningColor ()),
1012+ spanOpeningWithCustomColor (getWarningColor ()),
10051013 CLOSING_SPAN_TAG );
10061014
10071015 campaign .addReport (PERSONNEL , reportMessage );
@@ -1231,7 +1239,7 @@ private static boolean graduateAdult(Campaign campaign, Person person, Academy a
12311239
12321240 String reportMessage = String .format (resources .getString ("graduatedClassNeeded.text" ),
12331241 person .getHyperlinkedFullTitle (),
1234- spanOpeningWithCustomColor (ReportingUtilities . getWarningColor ()),
1242+ spanOpeningWithCustomColor (getWarningColor ()),
12351243 CLOSING_SPAN_TAG ,
12361244 roll );
12371245
@@ -1500,13 +1508,13 @@ private static void graduateChild(Campaign campaign, Person person, Academy acad
15001508 if (academy .isHomeSchool ()) {
15011509 reportMessage = String .format (resources .getString ("graduatedBarelyHomeSchooled.text" ),
15021510 person .getHyperlinkedFullTitle (),
1503- spanOpeningWithCustomColor (ReportingUtilities . getWarningColor ()),
1511+ spanOpeningWithCustomColor (getWarningColor ()),
15041512 CLOSING_SPAN_TAG );
15051513
15061514 } else {
15071515 reportMessage = String .format (resources .getString ("graduatedBarely.text" ),
15081516 person .getHyperlinkedFullTitle (),
1509- spanOpeningWithCustomColor (ReportingUtilities . getWarningColor ()),
1517+ spanOpeningWithCustomColor (getWarningColor ()),
15101518 CLOSING_SPAN_TAG );
15111519
15121520 }
@@ -1695,8 +1703,7 @@ private static void improveSkills(Campaign campaign, Person person, Academy acad
16951703 .map (String ::trim )
16961704 .toArray (String []::new );
16971705
1698- int educationLevel = Math .min (Math .max (academy .getEducationLevel (person ) + academy .getBaseAcademicSkillLevel (),
1699- 0 ), 5 );
1706+ int educationLevel = clamp (academy .getEducationLevel (person ) + academy .getBaseAcademicSkillLevel (), 0 , 5 );
17001707
17011708 if (!isGraduating ) {
17021709 educationLevel --;
@@ -1752,28 +1759,25 @@ private static void updateSkill(Person person, int educationLevel, String skill)
17521759 /**
17531760 * Adjusts the skill level of a person until the target level is reached.
17541761 *
1755- * @param person The person whose skill level needs adjustment.
1756- * @param skillParsed The name of the skill to adjust.
1757- * @param targetLevel The desired target level of the skill.
1758- * @param bonus The bonus to apply when increasing the skill level.
1762+ * @param person The person whose skill level needs adjustment.
1763+ * @param skillParsed The name of the skill to adjust.
1764+ * @param targetExperienceLevel The desired target level of the skill.
1765+ * @param bonus The bonus to apply when increasing the skill level.
17591766 */
1760- private static void adjustSkillLevel (Person person , String skillParsed , int targetLevel , int bonus ) {
1761- boolean underTarget = true ;
1762- while (underTarget ) {
1763- Skill skill = person .getSkill (skillParsed );
1764- if (skill == null ) {
1765- LOGGER .error ("Skill {} not found for person {}" , skillParsed , person .getFullTitle ());
1766- underTarget = false ;
1767- continue ;
1768- }
1767+ private static void adjustSkillLevel (Person person , String skillParsed , int targetExperienceLevel , int bonus ) {
1768+ Skill skill = person .getSkill (skillParsed );
1769+ if (skill == null ) {
1770+ LOGGER .error ("Skill {} not found for person {}" , skillParsed , person .getFullTitle ());
1771+ return ;
1772+ }
17691773
1770- int skillLevel = skill .getLevel ();
1771- int experienceLevel = skill .getType ().getExperienceLevel (skillLevel );
1774+ int currentLevel = skill .getLevel ();
1775+ SkillType type = skill .getType ();
1776+ int targetLevel = type .getLevelFromExperience (targetExperienceLevel );
17721777
1773- underTarget = experienceLevel <= targetLevel ;
1774- if (underTarget ) {
1775- person .addSkill (skillParsed , skillLevel + 1 , bonus );
1776- }
1778+ boolean underTarget = currentLevel <= targetLevel ;
1779+ if (underTarget ) {
1780+ person .addSkill (skillParsed , targetLevel , bonus );
17771781 }
17781782 }
17791783
@@ -1797,14 +1801,14 @@ private static void addFacultyXp(Campaign campaign, Person person, Academy acade
17971801 double bonusPercentage = (double ) bonusCount / 5 ;
17981802
17991803 if (EducationLevel .parseToInt (person .getEduHighestEducation ()) < academy .getEducationLevel (person )) {
1800- int xpRate = Math . max (1 , (12 - academy .getFacultySkill ()) * (academyDuration / 600 ));
1804+ int xpRate = max (1 , (12 - academy .getFacultySkill ()) * (academyDuration / 600 ));
18011805
18021806 xpRate *= campaign .getCampaignOptions ().getFacultyXpRate ();
18031807
1804- int bonusAmount = (int ) Math . max (bonusCount , xpRate * bonusPercentage );
1808+ int bonusAmount = (int ) max (bonusCount , xpRate * bonusPercentage );
18051809 person .awardXP (campaign , xpRate + bonusAmount );
18061810 } else {
1807- int bonusAmount = (int ) Math . max (bonusCount , 1 * bonusPercentage );
1811+ int bonusAmount = (int ) max (bonusCount , 1 * bonusPercentage );
18081812 person .awardXP (campaign , 1 + bonusAmount );
18091813 }
18101814 }
0 commit comments