7878import java .util .List ;
7979import java .util .*;
8080
81- import static java .lang .Math .ceil ;
82- import static java .lang .Math .floor ;
83- import static java .lang .Math .max ;
84- import static java .lang .Math .round ;
81+ import static java .lang .Math .*;
8582import static megamek .client .ratgenerator .ModelRecord .NETWORK_NONE ;
8683import static megamek .client .ratgenerator .UnitTable .findTable ;
8784import static megamek .codeUtilities .ObjectUtility .getRandomItem ;
9794import static mekhq .campaign .force .FormationLevel .COMPANY ;
9895import static mekhq .campaign .mission .AtBDynamicScenarioFactory .getEntity ;
9996import static mekhq .campaign .mission .BotForceRandomizer .UNIT_WEIGHT_UNSPECIFIED ;
97+ import static mekhq .campaign .mission .enums .AtBMoraleLevel .ADVANCING ;
98+ import static mekhq .campaign .mission .enums .AtBMoraleLevel .DOMINATING ;
99+ import static mekhq .campaign .mission .enums .AtBMoraleLevel .OVERWHELMING ;
100+ import static mekhq .campaign .mission .enums .AtBMoraleLevel .STALEMATE ;
100101import static mekhq .campaign .rating .IUnitRating .*;
101102import static mekhq .campaign .stratcon .StratconContractDefinition .getContractDefinition ;
102103import static mekhq .campaign .universe .Factions .getFactionLogo ;
@@ -234,7 +235,7 @@ public AtBContract(String name) {
234235
235236 sharesPct = 0 ;
236237 batchallAccepted = true ;
237- setMoraleLevel (AtBMoraleLevel . STALEMATE );
238+ setMoraleLevel (STALEMATE );
238239 routEnd = null ;
239240 priorLogisticsFailure = false ;
240241 specialEventScenarioDate = null ;
@@ -501,11 +502,11 @@ public void checkMorale(Campaign campaign, LocalDate today) {
501502 // This works with the regenerated Scenario Odds to crease very high intensity
502503 // spikes in otherwise low-key Garrison-type contracts.
503504 AtBMoraleLevel newMoraleLevel = switch (roll ) {
504- case 0 ,1 -> AtBMoraleLevel . STALEMATE ;
505- case 2 ,3 ,4 ,5 -> AtBMoraleLevel . ADVANCING ;
506- case 6 ,7 -> AtBMoraleLevel . DOMINATING ;
507- case 8 -> AtBMoraleLevel . OVERWHELMING ;
508- default -> AtBMoraleLevel . STALEMATE ;
505+ case 0 ,1 -> STALEMATE ;
506+ case 2 ,3 ,4 ,5 -> ADVANCING ;
507+ case 6 ,7 -> DOMINATING ;
508+ case 8 -> OVERWHELMING ;
509+ default -> STALEMATE ;
509510 };
510511
511512 // If we have a StratCon enabled contract, regenerate Scenario Odds
@@ -633,7 +634,7 @@ public void checkMorale(Campaign campaign, LocalDate today) {
633634 moraleLevel = moraleLevels [max (getMoraleLevel ().ordinal () - 1 , 0 )];
634635 logger .info ("Result: Morale Level -1" );
635636 } else if ((roll > 9 )) {
636- moraleLevel = moraleLevels [Math . min (getMoraleLevel ().ordinal () + 1 , moraleLevels .length - 1 )];
637+ moraleLevel = moraleLevels [min (getMoraleLevel ().ordinal () + 1 , moraleLevels .length - 1 )];
637638 logger .info ("Result: Morale Level +1" );
638639 } else {
639640 logger .info ("Result: Morale Unchanged" );
@@ -713,7 +714,7 @@ public int getRepairLocation(final int unitRating) {
713714 repairLocation ++;
714715 }
715716
716- return Math . min (repairLocation , Unit .SITE_FACTORY_CONDITIONS );
717+ return min (repairLocation , Unit .SITE_FACTORY_CONDITIONS );
717718 }
718719
719720 public void addMoraleMod (int mod ) {
@@ -1087,7 +1088,7 @@ public boolean contractExtended(final Campaign campaign) {
10871088 }
10881089
10891090 final int extension ;
1090- final int roll = d6 ();
1091+ int roll = d6 ();
10911092 if (roll == 1 ) {
10921093 extension = max (1 , getLength () / 2 );
10931094 } else if (roll == 2 ) {
@@ -1101,6 +1102,22 @@ public boolean contractExtended(final Campaign campaign) {
11011102 warName , extension , ((extension == 1 ) ? " month" : " months" )));
11021103 setEndDate (getEndingDate ().plusMonths (extension ));
11031104 extensionLength += extension ;
1105+
1106+ // We spike morale to create a jump in contract difficulty
1107+ // - essentially the reason why the employer is using the emergency clause.
1108+ int moraleOrdinal = moraleLevel .ordinal ();
1109+ roll = d6 (2 ) / 2 ;
1110+
1111+ // we need to reset routEnd to null otherwise we'll attempt to rally
1112+ if (routEnd != null ) {
1113+ routEnd = null ;
1114+ }
1115+
1116+ moraleOrdinal = min (moraleOrdinal + roll , OVERWHELMING .ordinal ());
1117+ moraleLevel = AtBMoraleLevel .values ()[moraleOrdinal ];
1118+
1119+ campaign .addReport (moraleLevel .getToolTipText ());
1120+
11041121 MekHQ .triggerEvent (new MissionChangedEvent (this ));
11051122 return true ;
11061123 }
@@ -1976,7 +1993,7 @@ public int calculateContractDifficulty(Campaign campaign) {
19761993 mappedValue = 5 + mappedValue ;
19771994 }
19781995
1979- return Math . min (max (mappedValue , 1 ), 10 );
1996+ return min (max (mappedValue , 1 ), 10 );
19801997 }
19811998
19821999 /**
0 commit comments