Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add max contract salvage percentage to campaign options #3821

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ chkVariableContractLength.text=Variable Contract Length
chkVariableContractLength.toolTipText=The length of the contract has a duration variance instead of just using the constant base length for the mission type.
chkContractMarketReportRefresh.text=Contract Market Refresh Report
chkContractMarketReportRefresh.toolTipText=Adds a report to the daily log when the contract market refreshes.
lblContractMaxSalvagePercentage.text=Max salvage percentage
lblContractMaxSalvagePercentage.toolTipText=Used to limit the salvage roll when creating a new contract
##end Markets Tab

## RATs Tab
Expand Down
13 changes: 13 additions & 0 deletions MekHQ/src/mekhq/campaign/CampaignOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ public static String getTransitUnitName(final int unit) {
private int contractSearchRadius;
private boolean variableContractLength;
private boolean contractMarketReportRefresh;
private int contractMaxSalvagePercentage;
//endregion Markets Tab

//region RATs Tab
Expand Down Expand Up @@ -916,6 +917,7 @@ public CampaignOptions() {
setContractSearchRadius(800);
setVariableContractLength(true);
setContractMarketReportRefresh(true);
setContractMaxSalvagePercentage(100);
//endregion Markets Tab

//region RATs Tab
Expand Down Expand Up @@ -2546,6 +2548,14 @@ public boolean isContractMarketReportRefresh() {
public void setContractMarketReportRefresh(final boolean contractMarketReportRefresh) {
this.contractMarketReportRefresh = contractMarketReportRefresh;
}

public int getContractMaxSalvagePercentage() {
return contractMaxSalvagePercentage;
}

public void setContractMaxSalvagePercentage(final int contractMaxSalvagePercentage) {
this.contractMaxSalvagePercentage = contractMaxSalvagePercentage;
}
//endregion Contract Market
//endregion Markets Tab

Expand Down Expand Up @@ -3795,6 +3805,7 @@ public void writeToXml(final PrintWriter pw, int indent) {
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "contractSearchRadius", getContractSearchRadius());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "variableContractLength", isVariableContractLength());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "contractMarketReportRefresh", isContractMarketReportRefresh());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "contractMaxSalvagePercentage", getContractMaxSalvagePercentage());
//endregion Contract Market
//endregion Markets Tab

Expand Down Expand Up @@ -4562,6 +4573,8 @@ public static CampaignOptions generateCampaignOptionsFromXml(Node wn, Version ve
retVal.setVariableContractLength(Boolean.parseBoolean(wn2.getTextContent().trim()));
} else if (wn2.getNodeName().equalsIgnoreCase("contractMarketReportRefresh")) {
retVal.setContractMarketReportRefresh(Boolean.parseBoolean(wn2.getTextContent().trim()));
} else if (wn2.getNodeName().equalsIgnoreCase("contractMaxSalvagePercentage")) {
retVal.setContractMaxSalvagePercentage(Integer.parseInt(wn2.getTextContent().trim()));
//endregion Contract Market
//endregion Markets Tab

Expand Down
10 changes: 5 additions & 5 deletions MekHQ/src/mekhq/campaign/market/ContractMarket.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void rerollClause(AtBContract c, int clause, Campaign campaign) {
rollCommandClause(c, clauseMods.get(c.getId()).mods[clause]);
break;
case CLAUSE_SALVAGE:
rollSalvageClause(c, clauseMods.get(c.getId()).mods[clause]);
rollSalvageClause(c, clauseMods.get(c.getId()).mods[clause], campaign.getCampaignOptions().getContractMaxSalvagePercentage());
break;
case CLAUSE_TRANSPORT:
rollTransportClause(c, clauseMods.get(c.getId()).mods[clause]);
Expand Down Expand Up @@ -759,7 +759,7 @@ protected void setAtBContractClauses(AtBContract contract, int unitRatingMod, Ca
} else {
contract.setCommandRights(ContractCommandRights.INTEGRATED);
}
rollSalvageClause(contract, mods.mods[CLAUSE_SALVAGE]);
rollSalvageClause(contract, mods.mods[CLAUSE_SALVAGE], campaign.getCampaignOptions().getContractMaxSalvagePercentage());
rollSupportClause(contract, mods.mods[CLAUSE_SUPPORT]);
rollTransportClause(contract, mods.mods[CLAUSE_TRANSPORT]);
}
Expand All @@ -777,7 +777,7 @@ private void rollCommandClause(final Contract contract, final int modifier) {
}
}

private void rollSalvageClause(AtBContract contract, int mod) {
private void rollSalvageClause(AtBContract contract, int mod, int contractMaxSalvagePercentage) {
contract.setSalvageExchange(false);
int roll = Math.min(Compute.d6(2) + mod, 13);
if (roll < 2) {
Expand All @@ -788,9 +788,9 @@ private void rollSalvageClause(AtBContract contract, int mod) {
do {
r = Compute.d6(2);
} while (r < 4);
contract.setSalvagePct(Math.min((r - 3) * 10, 100));
contract.setSalvagePct(Math.min((r - 3) * 10, contractMaxSalvagePercentage));
} else {
contract.setSalvagePct(Math.min((roll - 3) * 10, 100));
contract.setSalvagePct(Math.min((roll - 3) * 10, contractMaxSalvagePercentage));
}
}

Expand Down
20 changes: 20 additions & 0 deletions MekHQ/src/mekhq/gui/panes/CampaignOptionsPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ public class CampaignOptionsPane extends AbstractMHQTabbedPane {
private JSpinner spnContractSearchRadius;
private JCheckBox chkVariableContractLength;
private JCheckBox chkContractMarketReportRefresh;
private JSpinner spnContractMaxSalvagePercentage;
//endregion Markets Tab

//region RATs Tab
Expand Down Expand Up @@ -5632,6 +5633,7 @@ public Component getListCellRendererComponent(final JList<?> list, final Object
private JPanel createContractMarketPanel() {
// Initialize Labels Used in ActionListeners
final JLabel lblContractSearchRadius = new JLabel();
final JLabel lblCoontractMaxSalvagePercentage = new JLabel();

// Create Panel Components
final JLabel lblContractMarketMethod = new JLabel(resources.getString("lblContractMarketMethod.text"));
Expand Down Expand Up @@ -5662,6 +5664,7 @@ public Component getListCellRendererComponent(final JList<?> list, final Object
spnContractSearchRadius.setEnabled(enabled);
chkVariableContractLength.setEnabled(enabled);
chkContractMarketReportRefresh.setEnabled(enabled);
spnContractMaxSalvagePercentage.setEnabled(enabled);
});
comboContractMarketMethod.setEnabled(false); // TODO : AbstractContractMarket : Remove line

Expand All @@ -5681,9 +5684,18 @@ public Component getListCellRendererComponent(final JList<?> list, final Object
chkContractMarketReportRefresh.setToolTipText(resources.getString("chkContractMarketReportRefresh.toolTipText"));
chkContractMarketReportRefresh.setName("chkContractMarketReportRefresh");

lblCoontractMaxSalvagePercentage.setText(resources.getString("lblContractMaxSalvagePercentage.text"));
lblCoontractMaxSalvagePercentage.setToolTipText(resources.getString("lblContractMaxSalvagePercentage.toolTipText"));
lblCoontractMaxSalvagePercentage.setName("lblContractSearchRadius");

spnContractMaxSalvagePercentage = new JSpinner(new SpinnerNumberModel(100, 0, 100, 10));
spnContractMaxSalvagePercentage.setToolTipText(resources.getString("lblContractMaxSalvagePercentage.toolTipText"));
spnContractMaxSalvagePercentage.setName("spnContractMaxSalvagePercentage");

// Programmatically Assign Accessibility Labels
lblContractMarketMethod.setLabelFor(comboContractMarketMethod);
lblContractSearchRadius.setLabelFor(spnContractSearchRadius);
lblCoontractMaxSalvagePercentage.setLabelFor(spnContractMaxSalvagePercentage);

// Layout the UI
contractMarketPanel = new JDisableablePanel("contractMarketPanel");
Expand All @@ -5704,6 +5716,9 @@ public Component getListCellRendererComponent(final JList<?> list, final Object
.addComponent(spnContractSearchRadius, Alignment.LEADING))
.addComponent(chkVariableContractLength)
.addComponent(chkContractMarketReportRefresh)
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblCoontractMaxSalvagePercentage)
.addComponent(spnContractMaxSalvagePercentage, Alignment.LEADING))
);

layout.setHorizontalGroup(
Expand All @@ -5716,6 +5731,9 @@ public Component getListCellRendererComponent(final JList<?> list, final Object
.addComponent(spnContractSearchRadius))
.addComponent(chkVariableContractLength)
.addComponent(chkContractMarketReportRefresh)
.addGroup(layout.createSequentialGroup()
.addComponent(lblCoontractMaxSalvagePercentage)
.addComponent(spnContractMaxSalvagePercentage))
);

return contractMarketPanel;
Expand Down Expand Up @@ -6334,6 +6352,7 @@ public void setOptions(@Nullable CampaignOptions options,
spnContractSearchRadius.setValue(options.getContractSearchRadius());
chkVariableContractLength.setSelected(options.isVariableContractLength());
chkContractMarketReportRefresh.setSelected(options.isContractMarketReportRefresh());
spnContractMaxSalvagePercentage.setValue(options.getContractMaxSalvagePercentage());
//endregion Markets Tab

//region RATs Tab
Expand Down Expand Up @@ -6771,6 +6790,7 @@ public void updateOptions() {
options.setContractSearchRadius((Integer) spnContractSearchRadius.getValue());
options.setVariableContractLength(chkVariableContractLength.isSelected());
options.setContractMarketReportRefresh(chkContractMarketReportRefresh.isSelected());
options.setContractMaxSalvagePercentage((Integer) spnContractMaxSalvagePercentage.getValue());
//endregion Markets Tab

//region RATs Tab
Expand Down
Loading