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

MekHQ Options: New Day: Auto-hiring Pool Options #2584

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 @@ -35,7 +35,12 @@ labelSavedGamesCount.text=Maximum number of autosaved games

#New Day Tab
newDayTab.title=New Day Options
optionNewDayMRMS.text=Run Mass Repair/Mass Salvage on New Day
optionNewDayAstechPoolFill.text=Fill Astech Pool
optionNewDayAstechPoolFill.toolTipText=Automatically fill the Astech pool immediately upon selecting new day.
optionNewDayMedicPoolFill.text=Fill Medic Pool
optionNewDayMedicPoolFill.toolTipText=Automatically fill the Medic pool immediately upon selecting new day.
optionNewDayMRMS.text=Run Mass Repair/Mass Salvage
optionNewDayMRMS.toolTipText=Automatically run Mass Repair and/or Mass Salvage (based on the currently saved options) during new day processing.

#Campaign XML Save Tab
campaignXMLSaveTab.title=Campaign XML Save Options
Expand Down
18 changes: 17 additions & 1 deletion MekHQ/src/mekhq/MekHQOptions.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 - The MekHQ Team. All Rights Reserved.
* Copyright (c) 2020-2021 - The MekHQ Team. All Rights Reserved.
*
* This file is part of MekHQ.
*
Expand Down Expand Up @@ -162,6 +162,22 @@ public void setMaximumNumberOfAutosavesValue(int value) {
//endregion Autosave

//region New Day
public boolean getNewDayAstechPoolFill() {
return userPreferences.node(MekHqConstants.NEW_DAY_NODE).getBoolean(MekHqConstants.NEW_DAY_ASTECH_POOL_FILL, true);
}

public void setNewDayAstechPoolFill(final boolean value) {
userPreferences.node(MekHqConstants.NEW_DAY_NODE).putBoolean(MekHqConstants.NEW_DAY_ASTECH_POOL_FILL, value);
}

public boolean getNewDayMedicPoolFill() {
return userPreferences.node(MekHqConstants.NEW_DAY_NODE).getBoolean(MekHqConstants.NEW_DAY_MEDIC_POOL_FILL, true);
}

public void setNewDayMedicPoolFill(final boolean value) {
userPreferences.node(MekHqConstants.NEW_DAY_NODE).putBoolean(MekHqConstants.NEW_DAY_MEDIC_POOL_FILL, value);
}

public boolean getNewDayMRMS() {
return userPreferences.node(MekHqConstants.NEW_DAY_NODE).getBoolean(MekHqConstants.NEW_DAY_MRMS, false);
}
Expand Down
12 changes: 7 additions & 5 deletions MekHQ/src/mekhq/MekHqConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public final class MekHqConstants {

//region New Day
public static final String NEW_DAY_NODE = "mekhq/prefs/newDay";
public static final String NEW_DAY_ASTECH_POOL_FILL = "newDayAstechPoolFill";
public static final String NEW_DAY_MEDIC_POOL_FILL = "newDayMedicPoolFill";
public static final String NEW_DAY_MRMS = "newDayMRMS";
//endregion New Day

Expand Down Expand Up @@ -87,11 +89,11 @@ public final class MekHqConstants {
public static final String FILENAME_DATE_FORMAT = "yyyyMMdd";

public static final int MAXIMUM_D6_VALUE = 6;

/**
* Paths to StratCon definition files
*/

public static final String STRATCON_REQUIRED_HOSTILE_FACILITY_MODS = "./data/scenariomodifiers/requiredHostileFacilityModifiers.xml";
public static final String STRATCON_HOSTILE_FACILITY_MODS = "./data/scenariomodifiers/hostileFacilityModifiers.xml";
public static final String STRATCON_ALLIED_FACILITY_MODS = "./data/scenariomodifiers/alliedFacilityModifiers.xml";
Expand All @@ -107,10 +109,10 @@ public final class MekHqConstants {
public static final String STRATCON_CONTRACT_MANIFEST = "./data/stratconcontractdefinitions/ContractDefinitionManifest.xml";
public static final String STRATCON_USER_CONTRACT_MANIFEST = "./data/stratconcontractdefinitions/UserContractDefinitionManifest.xml";
public static final String STRATCON_CONTRACT_PATH = "./data/stratconcontractdefinitions/";

public static String HOSTILE_FACILITY_SCENARIO = "Hostile Facility.xml";
public static String ALLIED_FACILITY_SCENARIO = "Allied Facility.xml";

public static final String SCENARIO_MODIFIER_ALLIED_GROUND_UNITS = "PrimaryAlliesGround.xml";
public static final String SCENARIO_MODIFIER_ALLIED_AIR_UNITS = "PrimaryAlliesAir.xml";
public static final String SCENARIO_MODIFIER_LIAISON_GROUND = "LiaisonGround.xml";
Expand All @@ -124,5 +126,5 @@ public final class MekHqConstants {
public static final String SCENARIO_MODIFIER_ALLIED_GROUND_SUPPORT = "AlliedGroundSupportImmediate.xml";
public static final String SCENARIO_MODIFIER_ALLIED_AIR_SUPPORT = "AlliedAirSupportImmediate.xml";
public static final String SCENARIO_MODIFIER_ALLIED_ARTY_SUPPORT = "AlliedArtillerySupportImmediate.xml";

}
22 changes: 21 additions & 1 deletion MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -3397,8 +3397,20 @@ public void processNewDayUnits() {
}
}

/** @return <code>true</code> if the new day arrived */
/**
* @return <code>true</code> if the new day arrived
*/
public boolean newDay() {
// Refill Automated Pools, if the options are selected
if (MekHQ.getMekHQOptions().getNewDayAstechPoolFill() && requiresAdditionalAstechs()) {
fillAstechPool();
}

if (MekHQ.getMekHQOptions().getNewDayMedicPoolFill() && requiresAdditionalMedics()) {
fillMedicPool();
}

// Ensure we don't have anything that would prevent the new day
if (MekHQ.triggerEvent(new DayEndingEvent(this))) {
return false;
}
Expand Down Expand Up @@ -5256,6 +5268,10 @@ public int getMedicPool() {
return medicPool;
}

public boolean requiresAdditionalAstechs() {
return getAstechNeed() > 0;
}

public int getAstechNeed() {
return (Math.toIntExact(getActivePersonnel().stream().filter(Person::isTech).count()) * 6)
- getNumberAstechs();
Expand Down Expand Up @@ -5387,6 +5403,10 @@ public int getNumberMedics() {
return medics;
}

public boolean requiresAdditionalMedics() {
return getMedicsNeed() > 0;
}

public int getMedicsNeed() {
return (getDoctors().size() * 4) - getNumberMedics();
}
Expand Down
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/gui/dialog/MassRepairSalvageDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ private JPanel createActionButtons() {

private void btnStartMassRepairActionPerformed(ActionEvent evt) {
// Not enough Astechs to run the tech teams
if (campaignGUI.getCampaign().getAstechNeed() > 0) {
if (campaignGUI.getCampaign().requiresAdditionalAstechs()) {
int savePrompt = JOptionPane.showConfirmDialog(null,
resources.getString("NotEnoughAstechs.error"),
resources.getString("NotEnoughAstechs.errorTitle"),
Expand Down
33 changes: 26 additions & 7 deletions MekHQ/src/mekhq/gui/dialog/MekHqOptionsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class MekHqOptionsDialog extends AbstractMHQButtonDialog {
//endregion Autosave

//region New Day
private JCheckBox optionNewDayAstechPoolFill;
private JCheckBox optionNewDayMedicPoolFill;
private JCheckBox optionNewDayMRMS;
//endregion New Day

Expand Down Expand Up @@ -289,31 +291,44 @@ private JPanel createAutosaveTab() {
}

private JPanel createNewDayTab() {
//region Create Graphical Components
// Create Panel Components
optionNewDayAstechPoolFill = new JCheckBox(resources.getString("optionNewDayAstechPoolFill.text"));
optionNewDayAstechPoolFill.setToolTipText(resources.getString("optionNewDayAstechPoolFill.toolTipText"));
optionNewDayAstechPoolFill.setName("optionNewDayAstechPoolFill");

optionNewDayMedicPoolFill = new JCheckBox(resources.getString("optionNewDayMedicPoolFill.text"));
optionNewDayMedicPoolFill.setToolTipText(resources.getString("optionNewDayMedicPoolFill.toolTipText"));
optionNewDayMedicPoolFill.setName("optionNewDayMedicPoolFill");

optionNewDayMRMS = new JCheckBox(resources.getString("optionNewDayMRMS.text"));
//endregion Create Graphical Components
optionNewDayMRMS.setToolTipText(resources.getString("optionNewDayMRMS.toolTipText"));
optionNewDayMRMS.setName("optionNewDayMRMS");

//region Layout
// Layout the UI
JPanel body = new JPanel();
GroupLayout layout = new GroupLayout(body);
body.setLayout(layout);
final JPanel panel = new JPanel();
panel.setName("newDayPanel");
final GroupLayout layout = new GroupLayout(panel);
panel.setLayout(layout);

layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);

layout.setVerticalGroup(
layout.createSequentialGroup()
.addComponent(optionNewDayAstechPoolFill)
.addComponent(optionNewDayMedicPoolFill)
.addComponent(optionNewDayMRMS)
);

layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(optionNewDayAstechPoolFill)
.addComponent(optionNewDayMedicPoolFill)
.addComponent(optionNewDayMRMS)
);
//endregion Layout

return body;
return panel;
}

private JPanel createCampaignXMLSaveTab() {
Expand Down Expand Up @@ -416,6 +431,8 @@ protected void okAction() {
MekHQ.getMekHQOptions().setAutosaveBeforeMissionsValue(checkSaveBeforeMissions.isSelected());
MekHQ.getMekHQOptions().setMaximumNumberOfAutosavesValue((Integer) spinnerSavedGamesCount.getValue());

MekHQ.getMekHQOptions().setNewDayAstechPoolFill(optionNewDayAstechPoolFill.isSelected());
MekHQ.getMekHQOptions().setNewDayMedicPoolFill(optionNewDayMedicPoolFill.isSelected());
MekHQ.getMekHQOptions().setNewDayMRMS(optionNewDayMRMS.isSelected());

MekHQ.getMekHQOptions().setPreferGzippedOutput(optionPreferGzippedOutput.isSelected());
Expand Down Expand Up @@ -444,6 +461,8 @@ private void setInitialState() {
checkSaveBeforeMissions.setSelected(MekHQ.getMekHQOptions().getAutosaveBeforeMissionsValue());
spinnerSavedGamesCount.setValue(MekHQ.getMekHQOptions().getMaximumNumberOfAutosavesValue());

optionNewDayAstechPoolFill.setSelected(MekHQ.getMekHQOptions().getNewDayAstechPoolFill());
optionNewDayMedicPoolFill.setSelected(MekHQ.getMekHQOptions().getNewDayMedicPoolFill());
optionNewDayMRMS.setSelected(MekHQ.getMekHQOptions().getNewDayMRMS());

optionPreferGzippedOutput.setSelected(MekHQ.getMekHQOptions().getPreferGzippedOutput());
Expand Down
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/gui/model/DocTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private String getDocDesc(Person doc) {

toReturn.append(String.format(" (%d XP)", doc.getXP()));

if (campaign.getMedicsNeed() > 0) {
if (campaign.requiresAdditionalMedics()) {
toReturn.append("</font><font size='2' color='red'>, ")
.append(campaign.getMedicsPerDoctor())
.append(" medics</font><font size='2'><br/>");
Expand Down
4 changes: 2 additions & 2 deletions MekHQ/src/mekhq/service/MassRepairService.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static String performSingleUnitMassRepairOrSalvage(Campaign campaign, Uni
unit.isSalvage() ? resources.getString("Salvage") : resources.getString("Repair"));
campaign.addReport(msg);
return msg;
} else if (campaign.getAstechNeed() > 0) {
} else if (campaign.requiresAdditionalAstechs()) {
String message = resources.getString("MRMS.InsufficientAstechs.report");
campaign.addReport(message);
return message;
Expand Down Expand Up @@ -197,7 +197,7 @@ public static void massRepairSalvageAllUnits(Campaign campaign) {
if (!configuredOptions.isEnabled()) {
campaign.addReport(resources.getString("MRMS.CompleteDisabled.report"));
return;
} else if (campaign.getAstechNeed() > 0) {
} else if (campaign.requiresAdditionalAstechs()) {
campaign.addReport(resources.getString("MRMS.InsufficientAstechs.report"));
return;
}
Expand Down