Class MHQMorale
Provides utility methods to evaluate contract performance, calculate morale outcomes, and generate result reports based on recent scenarios and modifiers.
- Since:
- 0.50.10
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents possible morale check results for a contract.static enumRepresents possible performance outcomes for a contract's recent scenarios. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckMorale(Campaign campaign, AbstractContract contract, boolean showDialog) Checks and updates the morale which depends on various conditions such as the rout end date, skill levels, victories, defeats, etc.static voiddetermineStartingMorale(AbstractContract contract, Campaign campaign) static StringReturns the localized title used for the morale check report UI.static MHQMorale.MoraleOutcomegetMoraleOutcome(AbstractContract contract, int roll) Determines the morale outcome based on the contract's current morale level and roll value.static intgetReliabilityModifier(int adjustedSkillLevel) Calculates the reliability modifier based on the provided skill value.static StringperformMoraleCheck(LocalDate today, AbstractContract contract, int decisiveVictoryModifier, int victoryModifier, int decisiveDefeatModifier, int defeatModifier) Performs a morale check for the given contract, using the current date and modifier values.static voidprocessCombatChallengeResults(Campaign campaign, AbstractContract contract, ScenarioStatus scenarioStatus) Applies a simplified morale check as the result of a combat challenge, updating the contract's morale level and triggering routed behavior if necessary.static voidroutedMoraleUpdate(Campaign campaign, AbstractContract contract) Applies follow-up effects when a contract's morale has reached a routed state.static voidupdateEnemy(Campaign campaign, LocalDate today, String enemyCode, AbstractContract contract) Updates the enemy faction and enemy bot name for this contract.static voidupdateEnemy(Campaign campaign, LocalDate today, AbstractContract contract)
-
Field Details
-
RALLYING_TARGET_NUMBER
public static final int RALLYING_TARGET_NUMBER- See Also:
-
NO_CHANGE_TARGET_NUMBER
public static final int NO_CHANGE_TARGET_NUMBER- See Also:
-
WAVERING_TARGET_NUMBER
public static final int WAVERING_TARGET_NUMBER- See Also:
-
-
Constructor Details
-
MHQMorale
public MHQMorale()
-
-
Method Details
-
getFormattedTitle
Returns the localized title used for the morale check report UI.The value is loaded from
RESOURCE_BUNDLEunder the keyMHQMorale.check.titleand is intended for use in dialogs or notifications that initiate a morale check.- Returns:
- the localized morale check title string
- Since:
- 0.50.10
-
performMoraleCheck
public static String performMoraleCheck(LocalDate today, AbstractContract contract, int decisiveVictoryModifier, int victoryModifier, int decisiveDefeatModifier, int defeatModifier) Performs a morale check for the given contract, using the current date and modifier values.Evaluates all relevant scenarios within the past month, calculates performance and morale outcomes, and returns a formatted status report.
- Parameters:
today- The current date of the check.contract- The contract to check morale for.decisiveVictoryModifier- The modifier to apply for decisive victories.victoryModifier- The modifier to apply for normal victories.decisiveDefeatModifier- The modifier to apply for decisive defeats.defeatModifier- The modifier to apply for normal defeats.- Returns:
- A formatted string containing the morale check report.
- Since:
- 0.50.10
-
getMoraleOutcome
Determines the morale outcome based on the contract's current morale level and roll value. Updates the morale level in the contract if it changes.A lower roll is better for the OpFor.
- Parameters:
contract- The contract to check and update morale for.roll- The result of the morale check roll.- Returns:
- The resulting MoraleOutcome after the check.
- Since:
- 0.50.10
-
getReliabilityModifier
public static int getReliabilityModifier(int adjustedSkillLevel) Calculates the reliability modifier based on the provided skill value.This modifier influences how likely the opposing force is to suffer morale loss or reliability degradation during campaign events. Lower skills improve reliability for the player, while extremely high skills reduce it to reflect elite forces being more difficult to destabilize.
- If
skill <= GREEN.getAdjustedValue(), the modifier is+1, improving reliability for the player. - If
skill >= ELITE.getAdjustedValue(), the modifier is-1, making reliability checks harder for the player. - All values between those thresholds return
0.
- Parameters:
adjustedSkillLevel- the skill rating to evaluate, compared against the adjusted GREEN and ELITE thresholds- Returns:
+1for low-skill forces (GREEN or worse),-1for elite forces (ELITE or better), and0otherwise- Since:
- 0.50.10
- If
-
processCombatChallengeResults
public static void processCombatChallengeResults(Campaign campaign, AbstractContract contract, ScenarioStatus scenarioStatus) Applies a simplified morale check as the result of a combat challenge, updating the contract's morale level and triggering routed behavior if necessary.This method does not use the full morale calculation. Instead, it forces a fixed roll based on the overall outcome of the most recent scenario:
- Overall victory: roll is treated as
WAVERING_TARGET_NUMBER(OpFor morale declines). - Overall defeat: roll is treated as
RALLYING_TARGET_NUMBER(OpFor morale improves). - Otherwise: roll defaults to
NO_CHANGE_TARGET_NUMBER.
After applying the morale outcome, if the contract's morale level is routed,
routedMoraleUpdate(Campaign, AbstractContract)is invoked to handle follow-up effects such as early contract end or prisoner handling.- Parameters:
campaign- the active campaign containing contract and prisoner statecontract- the contract whose morale is being updatedscenarioStatus- the outcome of the combat challenge scenario used to determine the forced roll- Since:
- 0.50.10
- Overall victory: roll is treated as
-
routedMoraleUpdate
Applies follow-up effects when a contract's morale has reached a routed state.If the contract is not in a routed morale state, this method performs no action.
When the contract is routed, one of two behaviors is applied, depending on whether the contract can end early and whether it is a garrison type:
- Garrison or non-early finish contracts:
- Sets a
routEnddate a short time in the future, based on a randomd6roll, resulting in a delay of roughly one to three months from the current in-game date. - Processes friendly and enemy prisoners via
PrisonerMissionEndEvent, if any are present. - Resets the temporary prisoner capacity to
PrisonerEventManager.DEFAULT_TEMPORARY_CAPACITY.
- Sets a
- Non-garrison contracts that can end early:
- Displays an immersive notification indicating that the contract is ending early due to routed morale.
- Calculates the remaining payout for the routed contract by multiplying the monthly payout by the number of months remaining after the next in-game day and stores the result on the contract as the routed payout.
- Sets the contract end date to the next in-game day.
This method should be called only after
AbstractContract.getMoraleLevel()has been updated to a routed state, and it assumes that the suppliedCampaignandAbstractContractare consistent with that state.- Parameters:
campaign- the campaign providing time, contract, and prisoner statecontract- the routed contract whose end behavior and prisoner state are being updated- Since:
- 0.50.10
- Garrison or non-early finish contracts:
-
checkMorale
Checks and updates the morale which depends on various conditions such as the rout end date, skill levels, victories, defeats, etc. This method also updates the enemy status based on the morale level. -
updateEnemy
-
updateEnemy
public static void updateEnemy(Campaign campaign, LocalDate today, @Nullable String enemyCode, AbstractContract contract) Updates the enemy faction and enemy bot name for this contract.- Parameters:
campaign- The current campaign.today- The current LocalDate object.enemyCode-Nullablethe code for the new faction, ifnullan appropriate random faction will be used
-
determineStartingMorale
-