Skip to content

Commit 71cdcb6

Browse files
authored
Merge pull request #5804 from IllianiCBT/contractExtension
Added Enemy Morale Spike to Justify Contract Extension Clause
2 parents 69e803c + 406c15c commit 71cdcb6

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

MekHQ/src/mekhq/campaign/mission/AtBContract.java

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@
7878
import java.util.List;
7979
import 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.*;
8582
import static megamek.client.ratgenerator.ModelRecord.NETWORK_NONE;
8683
import static megamek.client.ratgenerator.UnitTable.findTable;
8784
import static megamek.codeUtilities.ObjectUtility.getRandomItem;
@@ -97,6 +94,10 @@
9794
import static mekhq.campaign.force.FormationLevel.COMPANY;
9895
import static mekhq.campaign.mission.AtBDynamicScenarioFactory.getEntity;
9996
import 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;
100101
import static mekhq.campaign.rating.IUnitRating.*;
101102
import static mekhq.campaign.stratcon.StratconContractDefinition.getContractDefinition;
102103
import 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

Comments
 (0)