Skip to content

Commit

Permalink
Refactored morale initialization for StratCon contracts
Browse files Browse the repository at this point in the history
Updated the morale initialization logic to differentiate between garrison and relief duty contracts. Utilized the 'min' function to adjust morale levels more accurately and corrected a typo in the contract type check.
  • Loading branch information
IllianiCBT committed Nov 24, 2024
1 parent 0a8c48f commit 519101f
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import java.util.List;
import java.util.Random;

import static java.lang.Math.min;

/**
* This class handles StratCon state initialization when a contract is signed.
*/
Expand Down Expand Up @@ -200,7 +202,7 @@ public static void initializeCampaignState(AtBContract contract, Campaign campai
}

// Determine starting morale
if (contract.getContractType().isGarrisonDuty()) {
if (contract.getContractType().isGarrisonType()) {
contract.setMoraleLevel(AtBMoraleLevel.ROUTED);

LocalDate routEnd = contract.getStartDate().plusMonths(Math.max(1, Compute.d6() - 3)).minusDays(1);
Expand All @@ -211,6 +213,12 @@ public static void initializeCampaignState(AtBContract contract, Campaign campai
if (contract.getMoraleLevel().isRouted()) {
contract.setMoraleLevel(AtBMoraleLevel.CRITICAL);
}

if (contract.getContractType().isReliefDuty()) {
int currentMoraleLevel = min(6, contract.getMoraleLevel().ordinal() + 1);

contract.setMoraleLevel(AtBMoraleLevel.parseFromString(String.valueOf(currentMoraleLevel)));
}
}

// now we're done
Expand Down

0 comments on commit 519101f

Please sign in to comment.