Skip to content

Commit

Permalink
Merge pull request #4905 from IllianiCBT/unit_defaultMaintenanceTime
Browse files Browse the repository at this point in the history
Added Default Maintenance Time Campaign Setting
  • Loading branch information
HammerGS authored Sep 26, 2024
2 parents 4cd657f + 138be90 commit dfffab5
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ checkMaintenance.toolTipText=If checked, each unit will make a parts-specific ma
lblMaintenanceDays.text=Maintenance cycle length in days
lblMaintenanceBonus.text=Maintenance modifier
spnMaintenanceBonus.toolTipText=When checking by parts, Strat Ops applies a -1 bonus to the maintenance check target - you can change this modifier with this value
lblDefaultMaintenanceTime.text=Default Maintenance Time
lblDefaultMaintenanceTime.toolTipText=This setting determines the maintenance time modifier applied to all new units.
useQualityMaintenance.text=Use quality modifiers in maintenance checks
useQualityMaintenance.toolTipText=If checked, quality modifiers will be added to maintenance checks (WARNING: this will lead to unstable quality ratings over time)
reverseQualityNames.text=Reverse quality names (Resets Finance Tab)
Expand Down
1 change: 1 addition & 0 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@ public Unit addNewUnit(Entity en, boolean allowNewPilots, int days, int quality)
}

Unit unit = new Unit(en, this);
unit.setMaintenanceMultiplier(getCampaignOptions().getDefaultMaintenanceTime());
getHangar().addUnit(unit);

// reset the game object
Expand Down
21 changes: 21 additions & 0 deletions MekHQ/src/mekhq/campaign/CampaignOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public static String getTransitUnitName(final int unit) {
private boolean usePlanetaryModifiers;
private boolean useUnofficialMaintenance;
private boolean logMaintenance;
private int defaultMaintenanceTime;

// Mass Repair / Mass Salvage
private boolean mrmsUseRepair;
Expand Down Expand Up @@ -633,6 +634,7 @@ public CampaignOptions() {
setUsePlanetaryModifiers(true);
useUnofficialMaintenance = false;
logMaintenance = false;
defaultMaintenanceTime = 4;

// Mass Repair / Mass Salvage
setMRMSUseRepair(true);
Expand Down Expand Up @@ -1342,6 +1344,22 @@ public boolean isLogMaintenance() {
public void setLogMaintenance(final boolean logMaintenance) {
this.logMaintenance = logMaintenance;
}

/**
* @return the default maintenance time in minutes
*/
public int getDefaultMaintenanceTime() {
return defaultMaintenanceTime;
}

/**
* Sets the default maintenance time.
*
* @param defaultMaintenanceTime the default maintenance time multiplier
*/
public void setDefaultMaintenanceTime(final int defaultMaintenanceTime) {
this.defaultMaintenanceTime = defaultMaintenanceTime;
}
// endregion Maintenance

// region Mass Repair/ Mass Salvage
Expand Down Expand Up @@ -4656,6 +4674,7 @@ public void writeToXml(final PrintWriter pw, int indent) {
// region Repair and Maintenance Tab
// region Maintenance
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "logMaintenance", logMaintenance);
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "defaultMaintenanceTime", defaultMaintenanceTime);
// endregion Maintenance

// region Mass Repair / Mass Salvage
Expand Down Expand Up @@ -5231,6 +5250,8 @@ public static CampaignOptions generateCampaignOptionsFromXml(Node wn, Version ve
retVal.setUseUnofficialMaintenance(Boolean.parseBoolean(wn2.getTextContent()));
} else if (wn2.getNodeName().equalsIgnoreCase("logMaintenance")) {
retVal.logMaintenance = Boolean.parseBoolean(wn2.getTextContent());
} else if (wn2.getNodeName().equalsIgnoreCase("defaultMaintenanceTime")) {
retVal.defaultMaintenanceTime = Integer.parseInt(wn2.getTextContent());

// region Mass Repair / Mass Salvage
} else if (wn2.getNodeName().equalsIgnoreCase("mrmsUseRepair")) {
Expand Down
42 changes: 17 additions & 25 deletions MekHQ/src/mekhq/campaign/unit/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,6 @@
*/
package mekhq.campaign.unit;

import static mekhq.campaign.parts.Part.QUALITY_A;
import static mekhq.campaign.parts.Part.QUALITY_B;
import static mekhq.campaign.parts.Part.QUALITY_C;
import static mekhq.campaign.parts.Part.QUALITY_D;
import static mekhq.campaign.parts.Part.QUALITY_E;
import static mekhq.campaign.parts.Part.QUALITY_F;

import java.awt.Color;
import java.awt.Component;
import java.awt.Image;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import javax.swing.UIManager;

import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import megamek.Version;
import megamek.client.ui.swing.tileset.EntityImage;
import megamek.codeUtilities.MathUtility;
Expand Down Expand Up @@ -85,6 +61,22 @@
import mekhq.campaign.work.IAcquisitionWork;
import mekhq.campaign.work.IPartWork;
import mekhq.utilities.MHQXMLUtility;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.swing.*;
import java.awt.*;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.List;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static mekhq.campaign.parts.Part.*;

/**
* This is a wrapper class for entity, so that we can add some functionality to
Expand Down Expand Up @@ -194,7 +186,7 @@ public Unit(Entity en, Campaign c) {
this.history = "";
this.lastMaintenanceReport = "";
this.fluffName = "";
this.maintenanceMultiplier = 1;
this.maintenanceMultiplier = 4;
reCalc();
}

Expand Down
34 changes: 28 additions & 6 deletions MekHQ/src/mekhq/gui/panes/CampaignOptionsPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public class CampaignOptionsPane extends AbstractMHQTabbedPane {
private JCheckBox chkUsePlanetaryModifiers;
private JCheckBox useUnofficialMaintenance;
private JCheckBox logMaintenance;
private JSpinner spnDefaultMaintenanceTime;
// endregion Repair and Maintenance Tab

// region Supplies and Acquisitions Tab
Expand Down Expand Up @@ -1040,6 +1041,7 @@ private JScrollPane createRepairAndMaintenanceTab() {
chkUsePlanetaryModifiers.setEnabled(true);
spnMaintenanceBonus.setEnabled(true);
logMaintenance.setEnabled(true);
spnDefaultMaintenanceTime.setEnabled(true);
} else {
spnMaintenanceDays.setEnabled(false);
useQualityMaintenance.setEnabled(false);
Expand All @@ -1049,6 +1051,7 @@ private JScrollPane createRepairAndMaintenanceTab() {
chkUsePlanetaryModifiers.setEnabled(false);
spnMaintenanceBonus.setEnabled(false);
logMaintenance.setEnabled(false);
spnDefaultMaintenanceTime.setEnabled(false);
}
});

Expand All @@ -1074,20 +1077,37 @@ private JScrollPane createRepairAndMaintenanceTab() {
pnlMaintenanceBonus.add(spnMaintenanceBonus);
pnlMaintenanceBonus.add(new JLabel(resources.getString("lblMaintenanceBonus.text")));

spnDefaultMaintenanceTime = new JSpinner(new SpinnerNumberModel(4, 1, 4, 1));
((DefaultEditor) spnDefaultMaintenanceTime.getEditor()).getTextField().setEditable(false);
spnDefaultMaintenanceTime.setToolTipText(resources.getString("lblDefaultMaintenanceTime.toolTipText"));

JPanel pnlDefaultMaintenanceTime = new JPanel();
pnlDefaultMaintenanceTime.add(spnDefaultMaintenanceTime);
pnlDefaultMaintenanceTime.add(new JLabel(resources.getString("lblDefaultMaintenanceTime.text")));

gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.weightx = 0.0;
gridBagConstraints.weighty = 0.0;
gridBagConstraints.fill = GridBagConstraints.NONE;
gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
panSubMaintenance.add(pnlDefaultMaintenanceTime, gridBagConstraints);

gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.weightx = 0.0;
gridBagConstraints.weighty = 0.0;
gridBagConstraints.fill = GridBagConstraints.NONE;
gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
panSubMaintenance.add(pnlMaintenanceBonus, gridBagConstraints);

useQualityMaintenance = new JCheckBox(resources.getString("useQualityMaintenance.text"));
useQualityMaintenance.setToolTipText(resources.getString("useQualityMaintenance.toolTipText"));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.gridy = 4;
gridBagConstraints.fill = GridBagConstraints.NONE;
gridBagConstraints.weightx = 0.0;
gridBagConstraints.weighty = 0.0;
Expand All @@ -1098,7 +1118,7 @@ private JScrollPane createRepairAndMaintenanceTab() {
reverseQualityNames.setToolTipText(resources.getString("reverseQualityNames.toolTipText"));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
gridBagConstraints.gridy = 5;
gridBagConstraints.fill = GridBagConstraints.NONE;
gridBagConstraints.weightx = 0.0;
gridBagConstraints.weighty = 0.0;
Expand All @@ -1111,7 +1131,7 @@ private JScrollPane createRepairAndMaintenanceTab() {
chkUseRandomUnitQualities.setToolTipText(resources.getString("chkUseRandomUnitQualities.toolTipText"));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 5;
gridBagConstraints.gridy = 6;
gridBagConstraints.fill = GridBagConstraints.NONE;
gridBagConstraints.weightx = 0.0;
gridBagConstraints.weighty = 0.0;
Expand All @@ -1122,7 +1142,7 @@ private JScrollPane createRepairAndMaintenanceTab() {
chkUsePlanetaryModifiers.setToolTipText(resources.getString("chkUsePlanetaryModifiers.toolTipText"));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 6;
gridBagConstraints.gridy = 7;
gridBagConstraints.fill = GridBagConstraints.NONE;
gridBagConstraints.weightx = 0.0;
gridBagConstraints.weighty = 0.0;
Expand All @@ -1133,7 +1153,7 @@ private JScrollPane createRepairAndMaintenanceTab() {
useUnofficialMaintenance.setToolTipText(resources.getString("useUnofficialMaintenance.toolTipText"));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 7;
gridBagConstraints.gridy = 8;
gridBagConstraints.fill = GridBagConstraints.NONE;
gridBagConstraints.weightx = 0.0;
gridBagConstraints.weighty = 0.0;
Expand All @@ -1143,7 +1163,7 @@ private JScrollPane createRepairAndMaintenanceTab() {
logMaintenance = new JCheckBox(resources.getString("logMaintenance.text"));
logMaintenance.setToolTipText(resources.getString("logMaintenance.toolTipText"));
logMaintenance.setName("logMaintenance");
gridBagConstraints.gridy = 8;
gridBagConstraints.gridy = 9;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
panSubMaintenance.add(logMaintenance, gridBagConstraints);
Expand Down Expand Up @@ -8340,6 +8360,7 @@ public void setOptions(@Nullable CampaignOptions options,
}
spnMaintenanceDays.setValue(options.getMaintenanceCycleDays());
spnMaintenanceBonus.setValue(options.getMaintenanceBonus());
spnDefaultMaintenanceTime.setValue(options.getDefaultMaintenanceTime());
useQualityMaintenance.setSelected(options.isUseQualityMaintenance());
reverseQualityNames.setSelected(options.isReverseQualityNames());
chkUseRandomUnitQualities.setSelected(options.isUseRandomUnitQualities());
Expand Down Expand Up @@ -8997,6 +9018,7 @@ public void updateOptions() {
options.setUseUnofficialMaintenance(useUnofficialMaintenance.isSelected());
options.setLogMaintenance(logMaintenance.isSelected());
options.setMaintenanceBonus((Integer) spnMaintenanceBonus.getValue());
options.setDefaultMaintenanceTime((Integer) spnDefaultMaintenanceTime.getValue());
options.setMaintenanceCycleDays((Integer) spnMaintenanceDays.getValue());
options.setPayForParts(payForPartsBox.isSelected());
options.setPayForRepairs(payForRepairsBox.isSelected());
Expand Down

0 comments on commit dfffab5

Please sign in to comment.