From 66f6a880e1b615fb97de9757be649fc18c10f049 Mon Sep 17 00:00:00 2001 From: Windchild292 Date: Tue, 4 May 2021 19:52:08 -0400 Subject: [PATCH] Implementing auto-hiring pool on new day --- .../resources/MekHqOptionsDialog.properties | 7 +++- MekHQ/src/mekhq/MekHQOptions.java | 18 +++++++++- MekHQ/src/mekhq/MekHqConstants.java | 12 ++++--- MekHQ/src/mekhq/campaign/Campaign.java | 22 ++++++++++++- .../gui/dialog/MassRepairSalvageDialog.java | 2 +- .../mekhq/gui/dialog/MekHqOptionsDialog.java | 33 +++++++++++++++---- MekHQ/src/mekhq/gui/model/DocTableModel.java | 2 +- .../src/mekhq/service/MassRepairService.java | 4 +-- 8 files changed, 81 insertions(+), 19 deletions(-) diff --git a/MekHQ/resources/mekhq/resources/MekHqOptionsDialog.properties b/MekHQ/resources/mekhq/resources/MekHqOptionsDialog.properties index ec80cc3d92..dc0fced95a 100644 --- a/MekHQ/resources/mekhq/resources/MekHqOptionsDialog.properties +++ b/MekHQ/resources/mekhq/resources/MekHqOptionsDialog.properties @@ -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 diff --git a/MekHQ/src/mekhq/MekHQOptions.java b/MekHQ/src/mekhq/MekHQOptions.java index c096089a54..a215c9b461 100644 --- a/MekHQ/src/mekhq/MekHQOptions.java +++ b/MekHQ/src/mekhq/MekHQOptions.java @@ -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. * @@ -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); } diff --git a/MekHQ/src/mekhq/MekHqConstants.java b/MekHQ/src/mekhq/MekHqConstants.java index f263ce961f..20dfc1f750 100644 --- a/MekHQ/src/mekhq/MekHqConstants.java +++ b/MekHQ/src/mekhq/MekHqConstants.java @@ -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 @@ -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"; @@ -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"; @@ -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"; - + } diff --git a/MekHQ/src/mekhq/campaign/Campaign.java b/MekHQ/src/mekhq/campaign/Campaign.java index 5b2e8c28e6..a1d17d7966 100644 --- a/MekHQ/src/mekhq/campaign/Campaign.java +++ b/MekHQ/src/mekhq/campaign/Campaign.java @@ -3397,8 +3397,20 @@ public void processNewDayUnits() { } } - /** @return true if the new day arrived */ + /** + * @return true 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; } @@ -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(); @@ -5387,6 +5403,10 @@ public int getNumberMedics() { return medics; } + public boolean requiresAdditionalMedics() { + return getMedicsNeed() > 0; + } + public int getMedicsNeed() { return (getDoctors().size() * 4) - getNumberMedics(); } diff --git a/MekHQ/src/mekhq/gui/dialog/MassRepairSalvageDialog.java b/MekHQ/src/mekhq/gui/dialog/MassRepairSalvageDialog.java index 6ba5f48d9c..7abfe93513 100644 --- a/MekHQ/src/mekhq/gui/dialog/MassRepairSalvageDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/MassRepairSalvageDialog.java @@ -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"), diff --git a/MekHQ/src/mekhq/gui/dialog/MekHqOptionsDialog.java b/MekHQ/src/mekhq/gui/dialog/MekHqOptionsDialog.java index 73019758ea..b4da81c648 100644 --- a/MekHQ/src/mekhq/gui/dialog/MekHqOptionsDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/MekHqOptionsDialog.java @@ -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 @@ -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() { @@ -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()); @@ -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()); diff --git a/MekHQ/src/mekhq/gui/model/DocTableModel.java b/MekHQ/src/mekhq/gui/model/DocTableModel.java index 72032d498c..10505c0813 100644 --- a/MekHQ/src/mekhq/gui/model/DocTableModel.java +++ b/MekHQ/src/mekhq/gui/model/DocTableModel.java @@ -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(", ") .append(campaign.getMedicsPerDoctor()) .append(" medics
"); diff --git a/MekHQ/src/mekhq/service/MassRepairService.java b/MekHQ/src/mekhq/service/MassRepairService.java index 95e76b11ca..c3d10728bd 100644 --- a/MekHQ/src/mekhq/service/MassRepairService.java +++ b/MekHQ/src/mekhq/service/MassRepairService.java @@ -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; @@ -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; }