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.static final recordThe victory and defeat points a contract's recent scenarios count for in the morale check (seegetPerformanceTally(LocalDate, AbstractContract)). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intHow many points one side must out-score the other by, over a month, for the result to be decisive (seeMHQMorale.PerformanceTally.outcome()).static final StringThe scenario modifier for an enemy fighting short of ammunition.static final intstatic final StringThe scenario modifier for an enemy fighting with damage it has had no chance to repair.static final intA garrison-type contract's enemy raids on a roll of 0 on a die of this size each month: a 1 in 4 chance.static final intstatic final doubleThe share of a contract's Contract Victory Point target a monthly setback costs (seeapplyMonthlySetback(mekhq.campaign.mission.contract.AbstractContract, boolean, boolean)).static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcheckMorale(Campaign campaign, AbstractContract contract, boolean showDialog) Runs the monthly morale update for a contract.static voiddetermineStartingMorale(AbstractContract contract, Campaign campaign) Sets a newly generated contract's starting morale with a morale check.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.getMoraleScenarioModifierKeys(ContractMoraleLevel moraleLevel) Returns the scenario modifiers a beaten enemy brings into battle at its morale level: aContractMoraleLevel.SCATTEREDenemy fights short of ammunition and with unrepaired damage, and aContractMoraleLevel.CRITICALone with one of the two, picked at random.static MHQMorale.PerformanceTallygetPerformanceTally(LocalDate today, AbstractContract contract) Tallies the victory and defeat points the contract's scenarios within the last month count for in the morale check.static intgetReliabilityModifier(int adjustedSkillLevel) Calculates the reliability modifier based on the provided skill value.static booleanisScenarioOutcomeAffectingMorale(ScenarioType stratConScenarioType, AbstractContract contract) Decides whether a scenario's outcome shifts the enemy's morale directly (seeprocessMoraleChangeFromScenario(mekhq.campaign.mission.contract.AbstractContract, mekhq.campaign.mission.scenarios.ScenarioStatus, mekhq.campaign.mission.scenarios.ScenarioType)).static booleanisSetbackDue(AbstractContract contract) Whether the next monthly morale check would bring a setback (seeapplyMonthlySetback(mekhq.campaign.mission.contract.AbstractContract, boolean, boolean)) if the enemy's morale stays where it is: the enemy is Dominating or Overwhelming on a contract run with StratCon.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 voidprocessMoraleChangeFromScenario(AbstractContract contract, ScenarioStatus scenarioStatus, ScenarioType stratConScenarioType) Applies a simplified morale check as the result of a scenario whose outcome moves the enemy's morale directly (seeisScenarioOutcomeAffectingMorale(mekhq.campaign.mission.scenarios.ScenarioType, mekhq.campaign.mission.contract.AbstractContract)).
-
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:
-
DECISIVE_MARGIN
public static final int DECISIVE_MARGINHow many points one side must out-score the other by, over a month, for the result to be decisive (seeMHQMorale.PerformanceTally.outcome()).- See Also:
-
RAID_DIE_SIZE
public static final int RAID_DIE_SIZEA garrison-type contract's enemy raids on a roll of 0 on a die of this size each month: a 1 in 4 chance.- See Also:
-
SETBACK_VICTORY_POINT_SHARE
public static final double SETBACK_VICTORY_POINT_SHAREThe share of a contract's Contract Victory Point target a monthly setback costs (seeapplyMonthlySetback(mekhq.campaign.mission.contract.AbstractContract, boolean, boolean)).- See Also:
-
LOW_AMMUNITION_MODIFIER
The scenario modifier for an enemy fighting short of ammunition.- See Also:
-
POOR_REPAIR_MODIFIER
The scenario modifier for an enemy fighting with damage it has had no chance to repair.- 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
-
getPerformanceTally
public static MHQMorale.PerformanceTally getPerformanceTally(LocalDate today, AbstractContract contract) Tallies the victory and defeat points the contract's scenarios within the last month count for in the morale check.- Decisive victory: 2 victory points
- Victory: 1 victory point
- Pyrrhic victory: 1 victory point and 1 defeat point
- Defeat or fleet in being: 1 defeat point
- Decisive defeat or refused engagement: 2 defeat points
- Parameters:
today- The current date for the evaluation.contract- The contract to evaluate scenarios for.- Returns:
- The victory and defeat points over the last month.
- Since:
- 0.51.01
-
isScenarioOutcomeAffectingMorale
public static boolean isScenarioOutcomeAffectingMorale(ScenarioType stratConScenarioType, @Nullable AbstractContract contract) Decides whether a scenario's outcome shifts the enemy's morale directly (seeprocessMoraleChangeFromScenario(mekhq.campaign.mission.contract.AbstractContract, mekhq.campaign.mission.scenarios.ScenarioStatus, mekhq.campaign.mission.scenarios.ScenarioType)). That is up to the scenario's type, with one exception: a riot moves morale only on a Riot Duty contract, where quelling riots is the work. Riots fought elsewhere - such as a scheduled parade disrupted on a Retainer contract - leave morale to the ordinary morale check.- Parameters:
stratConScenarioType- the scenario's typecontract- the contract the scenario belongs to, ornullif it has none- Returns:
trueif the scenario's outcome shifts the enemy's morale- Since:
- 0.51.01
-
processMoraleChangeFromScenario
public static void processMoraleChangeFromScenario(AbstractContract contract, ScenarioStatus scenarioStatus, ScenarioType stratConScenarioType) Applies a simplified morale check as the result of a scenario whose outcome moves the enemy's morale directly (seeisScenarioOutcomeAffectingMorale(mekhq.campaign.mission.scenarios.ScenarioType, mekhq.campaign.mission.contract.AbstractContract)).This method does not use the full morale calculation. Instead, it forces a fixed roll based on the overall outcome of the 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.
- Parameters:
contract- the contract whose morale is being updatedscenarioStatus- the outcome of the scenario used to determine the forced rollstratConScenarioType- the type of scenario.- Since:
- 0.50.10
- Overall victory: roll is treated as
-
getMoraleScenarioModifierKeys
Returns the scenario modifiers a beaten enemy brings into battle at its morale level: aContractMoraleLevel.SCATTEREDenemy fights short of ammunition and with unrepaired damage, and aContractMoraleLevel.CRITICALone with one of the two, picked at random. Any other enemy brings none.- Parameters:
moraleLevel- the enemy's morale level- Returns:
- the keys of the scenario modifiers to add, in no particular order; empty if none
- Since:
- 0.51.01
-
checkMorale
@Nullable public static String checkMorale(Campaign campaign, AbstractContract contract, boolean showDialog) Runs the monthly morale update for a contract.On most contracts this is the morale check (see
rollMorale(mekhq.campaign.Campaign, mekhq.campaign.mission.contract.AbstractContract)). A garrison-type contract follows a raid model instead (seeContractObjectiveType.isGarrisonType()): the enemy is only tested after a month in which it raided, so between raids its morale holds where it was, and each month there is then a1 in 4chance of a raid (seeapplyRaidRoll(mekhq.campaign.Campaign, mekhq.campaign.mission.contract.AbstractContract, boolean, boolean)). Throughout an emergency extension (seeisInEmergencyExtension(mekhq.campaign.mission.contract.AbstractContract, java.time.LocalDate)) the enemy raids every month.After the check, an enemy left Dominating or Overwhelming costs the employer a setback (see
applyMonthlySetback(mekhq.campaign.mission.contract.AbstractContract, boolean, boolean)). It is shown with the check, and returned for the daily report, so the caller can place it after its own report of the morale change.- Parameters:
campaign- the current campaigncontract- the contract whose morale is updatedshowDialog- whether to show the player the morale check and any raid that begins- Returns:
- the report of the month's setback, or
nullif there was none
-
isSetbackDue
Whether the next monthly morale check would bring a setback (seeapplyMonthlySetback(mekhq.campaign.mission.contract.AbstractContract, boolean, boolean)) if the enemy's morale stays where it is: the enemy is Dominating or Overwhelming on a contract run with StratCon.- Parameters:
contract- the contract- Returns:
trueif a setback is due- Since:
- 0.51.01
-
determineStartingMorale
Sets a newly generated contract's starting morale with a morale check. The enemy never startsContractMoraleLevel.SCATTERED, and on a Relief Duty contract it starts a level higher. A garrison-type contract also starts peaceful (seeContractObjectiveType.isGarrisonType()), so its first raid roll comes at the start of the next month.- Parameters:
contract- the newly generated contractcampaign- the current campaign
-