From 65f2aa2548811524925cb59d7631901360e4038d Mon Sep 17 00:00:00 2001 From: Jay Slater Date: Thu, 21 Nov 2024 17:28:41 -0500 Subject: [PATCH] Generate required lances for manual AtB contracts for StratCon init StratCon initialization requires a nonzero requiredLances to generate a nonzero number of tracks, and zero tracks causes a division by zero further along in initialization. --- MekHQ/src/mekhq/campaign/mission/AtBContract.java | 12 +++++++++++- MekHQ/src/mekhq/gui/dialog/NewAtBContractDialog.java | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/MekHQ/src/mekhq/campaign/mission/AtBContract.java b/MekHQ/src/mekhq/campaign/mission/AtBContract.java index 9b45452716..9d00a34e03 100644 --- a/MekHQ/src/mekhq/campaign/mission/AtBContract.java +++ b/MekHQ/src/mekhq/campaign/mission/AtBContract.java @@ -375,6 +375,16 @@ public void calculateLength(final boolean variable) { setLength(getContractType().calculateLength(variable, this)); } + /** + * Calculates the number of lances required for this contract, based on [campaign]. + * + * @param campaign The campaign to reference. + * @return The number of lances required. + */ + public static int calculateRequiredLances(Campaign campaign) { + return Math.max(getEffectiveNumUnits(campaign) / 6, 1); + } + public static int getEffectiveNumUnits(Campaign campaign) { double numUnits = 0; for (UUID uuid : campaign.getForces().getAllUnits(true)) { @@ -1477,7 +1487,7 @@ public AtBContract(Contract c, Campaign campaign) { enemyCode = "REB"; } - requiredLances = Math.max(getEffectiveNumUnits(campaign) / 6, 1); + requiredLances = calculateRequiredLances(campaign); setPartsAvailabilityLevel(getContractType().calculatePartsAvailabilityLevel()); diff --git a/MekHQ/src/mekhq/gui/dialog/NewAtBContractDialog.java b/MekHQ/src/mekhq/gui/dialog/NewAtBContractDialog.java index 98e8cfaa87..7590900e68 100644 --- a/MekHQ/src/mekhq/gui/dialog/NewAtBContractDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/NewAtBContractDialog.java @@ -527,6 +527,8 @@ protected void btnOKActionPerformed(ActionEvent evt) { contract.setDesc(txtDesc.getText()); contract.setCommandRights(choiceCommand.getSelectedItem()); + contract.setRequiredLances(AtBContract.calculateRequiredLances(campaign)); + contract.setEnemyCode(getCurrentEnemyCode()); contract.setAllySkill(comboAllySkill.getSelectedItem()); contract.setAllyQuality(cbAllyQuality.getSelectedIndex());