Skip to content

Commit

Permalink
Merge pull request #5232 from jslater89/issue-5181-manual-stratcon-co…
Browse files Browse the repository at this point in the history
…ntract

Generate required lances for manual AtB contracts for StratCon init
  • Loading branch information
HammerGS authored Nov 23, 2024
2 parents 1416cbe + 65f2aa2 commit e396704
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion MekHQ/src/mekhq/campaign/mission/AtBContract.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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());

Expand Down
2 changes: 2 additions & 0 deletions MekHQ/src/mekhq/gui/dialog/NewAtBContractDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit e396704

Please sign in to comment.