Skip to content

Commit

Permalink
Merge pull request #4391 from IllianiCBT/turnover_automatedBonuses
Browse files Browse the repository at this point in the history
Added Campaign Option to Automate Retention Bonus Payments Based on a Threshold
  • Loading branch information
IllianiCBT authored Jul 14, 2024
2 parents 6b84cc6 + 1c69c93 commit da91fdf
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ lblServiceContractDuration.text=Service Contract Duration
lblServiceContractDuration.toolTipText=Once recruited, this is the minimum amount of months personnel will remain with the unit (set to 0 to disable service contracts).
lblServiceContractModifier.text=Service Contract Modifier
lblServiceContractModifier.toolTipText=While personnel are under contract, this value reduces their Turnover target number.
chkPayBonusDefault.text=Enable Default Bonuses
chkPayBonusDefault.toolTipText=Selecting this option defaults Pay Bonus to true in the turnover dialog. Otherwise, Pay Bonus defaults to false.
chkPayBonusDefault.text=Automate Retention Bonuses
chkPayBonusDefault.toolTipText=Personnel with a turnover target number equal (or exceeding) the below threshold will have their retention bonus paid by default.
lblPayBonusDefaultThreshold.text=Bonus Threshold
lblPayBonusDefaultThreshold.toolTipText=This option sets the threshold for default bonus payouts (if the above option is enabled).

## Modifiers
turnoverAndRetentionModifiersPanel.title=Modifiers
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 @@ -284,6 +284,7 @@ public static String getTransitUnitName(final int unit) {
private int serviceContractDuration;
private int serviceContractModifier;
private boolean payBonusDefault;
private int payBonusDefaultThreshold;

private boolean useCustomRetirementModifiers;
private boolean useFatigueModifiers;
Expand Down Expand Up @@ -955,6 +956,7 @@ public CampaignOptions() {
setServiceContractDuration(36);
setServiceContractModifier(3);
setPayBonusDefault(false);
setPayBonusDefaultThreshold(3);

setUseCustomRetirementModifiers(true);
setUseFatigueModifiers(true);
Expand Down Expand Up @@ -2089,6 +2091,14 @@ public boolean isPayBonusDefault() {
public void setPayBonusDefault(final boolean payBonusDefault) {
this.payBonusDefault = payBonusDefault;
}

public int getPayBonusDefaultThreshold() {
return payBonusDefaultThreshold;
}

public void setPayBonusDefaultThreshold(final int payBonusDefaultThreshold) {
this.payBonusDefaultThreshold = payBonusDefaultThreshold;
}
//endregion Retirement

//region Family
Expand Down Expand Up @@ -4584,6 +4594,7 @@ public void writeToXml(final PrintWriter pw, int indent) {
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "serviceContractDuration", getServiceContractDuration());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "serviceContractModifier", getServiceContractModifier());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "payBonusDefault", isPayBonusDefault());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "payBonusDefaultThreshold", getPayBonusDefaultThreshold());

MHQXMLUtility.writeSimpleXMLTag(pw, indent, "useCustomRetirementModifiers", isUseCustomRetirementModifiers());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "useFatigueModifiers", isUseFatigueModifiers());
Expand Down Expand Up @@ -5566,6 +5577,8 @@ public static CampaignOptions generateCampaignOptionsFromXml(Node wn, Version ve
retVal.setServiceContractModifier(Integer.parseInt(wn2.getTextContent().trim()));
} else if (wn2.getNodeName().equalsIgnoreCase("payBonusDefault")) {
retVal.setPayBonusDefault(Boolean.parseBoolean(wn2.getTextContent().trim()));
} else if (wn2.getNodeName().equalsIgnoreCase("payBonusDefaultThreshold")) {
retVal.setPayBonusDefaultThreshold(Integer.parseInt(wn2.getTextContent().trim()));
} else if (wn2.getNodeName().equalsIgnoreCase("useCustomRetirementModifiers")) {
retVal.setUseCustomRetirementModifiers(Boolean.parseBoolean(wn2.getTextContent().trim()));
} else if (wn2.getNodeName().equalsIgnoreCase("useFatigueModifiers")) {
Expand Down
7 changes: 5 additions & 2 deletions MekHQ/src/mekhq/gui/model/RetirementTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ public void setData(List<UUID> list, Map<UUID, UUID> unitAssignments) {
public void setData(Map<UUID, TargetRoll> targets) {
this.targets = targets;
data.clear();

for (UUID id : targets.keySet()) {
data.add(id);
payBonus.put(id, campaign.getCampaignOptions().isPayBonusDefault());
payBonus.put(id,
((campaign.getCampaignOptions().isPayBonusDefault())
&& (targets.get(id).getValue() >= campaign.getCampaignOptions().getPayBonusDefaultThreshold())));
miscMods.put(id, 0);
}
fireTableDataChanged();
Expand Down Expand Up @@ -221,7 +224,7 @@ public Object getValueAt(int row, int col) {
return bonusCost;
}
case COL_PAY_BONUS:
return payBonus.getOrDefault(p.getId(), campaign.getCampaignOptions().isPayBonusDefault());
return payBonus.getOrDefault(p.getId(), false);
case COL_MISC_MOD:
return miscMods.getOrDefault(p.getId(), 0);
case COL_SHARES:
Expand Down
26 changes: 26 additions & 0 deletions MekHQ/src/mekhq/gui/panes/CampaignOptionsPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ public class CampaignOptionsPane extends AbstractMHQTabbedPane {
private JLabel lblServiceContractModifier;
private JSpinner spnServiceContractModifier;
private JCheckBox chkPayBonusDefault;
private JLabel lblPayBonusDefaultThreshold;
private JSpinner spnPayBonusDefaultThreshold;

// Modifiers
private JPanel turnoverAndRetentionModifiersPanel = new JPanel();
Expand Down Expand Up @@ -4437,6 +4439,22 @@ public Component getListCellRendererComponent(final JList<?> list, final Object
chkPayBonusDefault.setToolTipText(resources.getString("chkPayBonusDefault.toolTipText"));
chkPayBonusDefault.setName("chkPayBonusDefault");
chkPayBonusDefault.setEnabled(isUseTurnover);
chkPayBonusDefault.addActionListener(evt -> {
boolean isEnabled = chkPayBonusDefault.isSelected();

lblPayBonusDefaultThreshold.setEnabled(isEnabled);
spnPayBonusDefaultThreshold.setEnabled(isEnabled);
});

lblPayBonusDefaultThreshold = new JLabel(resources.getString("lblPayBonusDefaultThreshold.text"));
lblPayBonusDefaultThreshold.setToolTipText(resources.getString("lblPayBonusDefaultThreshold.toolTipText"));
lblPayBonusDefaultThreshold.setName("lblPayBonusDefaultThreshold");
lblPayBonusDefaultThreshold.setEnabled((isUseTurnover) && (campaign.getCampaignOptions().isPayBonusDefault()));

spnPayBonusDefaultThreshold = new JSpinner(new SpinnerNumberModel(3, 0, 12, 1));
spnPayBonusDefaultThreshold.setToolTipText(resources.getString("lblPayBonusDefaultThreshold.toolTipText"));
spnPayBonusDefaultThreshold.setName("spnPayBonusDefaultThreshold");
spnPayBonusDefaultThreshold.setEnabled((isUseTurnover) && (campaign.getCampaignOptions().isPayBonusDefault()));

turnoverAndRetentionSettingsPanel.setBorder(BorderFactory.createTitledBorder(resources.getString("turnoverAndRetentionSettingsPanel.title")));
turnoverAndRetentionSettingsPanel.setName("turnoverAndRetentionSettingsPanel");
Expand Down Expand Up @@ -4474,6 +4492,9 @@ public Component getListCellRendererComponent(final JList<?> list, final Object
.addComponent(lblServiceContractModifier)
.addComponent(spnServiceContractModifier, Alignment.LEADING))
.addComponent(chkPayBonusDefault)
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblPayBonusDefaultThreshold)
.addComponent(spnPayBonusDefaultThreshold, Alignment.LEADING))
);

layout.setHorizontalGroup(
Expand Down Expand Up @@ -4503,6 +4524,9 @@ public Component getListCellRendererComponent(final JList<?> list, final Object
.addComponent(lblServiceContractModifier)
.addComponent(spnServiceContractModifier))
.addComponent(chkPayBonusDefault)
.addGroup(layout.createSequentialGroup()
.addComponent(lblPayBonusDefaultThreshold)
.addComponent(spnPayBonusDefaultThreshold))
);

return turnoverAndRetentionSettingsPanel;
Expand Down Expand Up @@ -8010,6 +8034,7 @@ public void setOptions(@Nullable CampaignOptions options,
spnServiceContractDuration.setValue(options.getServiceContractDuration());
spnServiceContractModifier.setValue(options.getServiceContractModifier());
chkPayBonusDefault.setSelected(options.isPayBonusDefault());
spnPayBonusDefaultThreshold.setValue(options.getPayBonusDefaultThreshold());

// Modifiers
chkUseCustomRetirementModifiers.setSelected(options.isUseCustomRetirementModifiers());
Expand Down Expand Up @@ -8697,6 +8722,7 @@ public void updateOptions() {
options.setServiceContractDuration((Integer) spnServiceContractDuration.getValue());
options.setServiceContractModifier((Integer) spnServiceContractModifier.getValue());
options.setPayBonusDefault(chkPayBonusDefault.isSelected());
options.setPayBonusDefaultThreshold((Integer) spnPayBonusDefaultThreshold.getValue());

// Modifiers
options.setUseCustomRetirementModifiers(chkUseCustomRetirementModifiers.isSelected());
Expand Down

0 comments on commit da91fdf

Please sign in to comment.