From e7ecfd7cf59b439e504dd482eb75870b3ef2cbe0 Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Fri, 12 Jul 2024 22:10:54 -0500 Subject: [PATCH 1/3] Released commander flag when a person is deceased In the event of a person's death, the program now also checks if the deceased was a commander. If they were, the commander flag is released, allowing for a potential new assignment. --- MekHQ/src/mekhq/campaign/personnel/Person.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MekHQ/src/mekhq/campaign/personnel/Person.java b/MekHQ/src/mekhq/campaign/personnel/Person.java index 73b718b7be..b46b515027 100644 --- a/MekHQ/src/mekhq/campaign/personnel/Person.java +++ b/MekHQ/src/mekhq/campaign/personnel/Person.java @@ -1004,6 +1004,11 @@ public void changeStatus(final Campaign campaign, final LocalDate today, if (getGenealogy().hasSpouse() && !getGenealogy().getSpouse().getStatus().isDeadOrMIA()) { campaign.getDivorce().widowed(campaign, campaign.getLocalDate(), getGenealogy().getSpouse()); } + + // release the commander flag. + if (isCommander()) { + setCommander(false); + } } if (status.isActive()) { From 8ddf853c0775d0c93876435370c08504f5dc0324 Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Fri, 12 Jul 2024 22:17:48 -0500 Subject: [PATCH 2/3] Removed commander flag in specific status change The code for removing the commander flag when a person's status changes has been modified. Previously, the flag was lifted anytime a person's status changed to isDead. Now, it occurs when the status is changed to 'departed unit', which isn't just limited to death. --- MekHQ/src/mekhq/campaign/personnel/Person.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MekHQ/src/mekhq/campaign/personnel/Person.java b/MekHQ/src/mekhq/campaign/personnel/Person.java index b46b515027..e4481b051c 100644 --- a/MekHQ/src/mekhq/campaign/personnel/Person.java +++ b/MekHQ/src/mekhq/campaign/personnel/Person.java @@ -1004,11 +1004,6 @@ public void changeStatus(final Campaign campaign, final LocalDate today, if (getGenealogy().hasSpouse() && !getGenealogy().getSpouse().getStatus().isDeadOrMIA()) { campaign.getDivorce().widowed(campaign, campaign.getLocalDate(), getGenealogy().getSpouse()); } - - // release the commander flag. - if (isCommander()) { - setCommander(false); - } } if (status.isActive()) { @@ -1028,6 +1023,11 @@ public void changeStatus(final Campaign campaign, final LocalDate today, removeAllTechJobs(campaign); } + // release the commander flag. + if ((isCommander()) && (status.isDepartedUnit())) { + setCommander(false); + } + // clean up the save entry this.setEduAcademyName(null); this.setEduAcademyFaction(null); From f1d5d8c64bf25c4b00ad3cf7bd65bea9fdecab4e Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Fri, 12 Jul 2024 22:36:17 -0500 Subject: [PATCH 3/3] Implemented leadership change loyalty refresh A new feature for refreshing loyalty upon major leadership changes was added. This occurs when a commander dies, deserts, or defects. An associated configuration option allows this feature to be toggled on or off according to the needs of the campaign. --- .../CampaignOptionsDialog.properties | 2 ++ MekHQ/src/mekhq/campaign/CampaignOptions.java | 13 +++++++++ .../src/mekhq/campaign/personnel/Person.java | 27 ++++++++++++++++++- .../mekhq/gui/panes/CampaignOptionsPane.java | 11 ++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/MekHQ/resources/mekhq/resources/CampaignOptionsDialog.properties b/MekHQ/resources/mekhq/resources/CampaignOptionsDialog.properties index f8d89ddd9f..4437b67bd0 100644 --- a/MekHQ/resources/mekhq/resources/CampaignOptionsDialog.properties +++ b/MekHQ/resources/mekhq/resources/CampaignOptionsDialog.properties @@ -187,6 +187,8 @@ chkUseLoyaltyModifiers.toolTipText=If enabled, personnel have a random loyalty r chkUseHideLoyalty.text=Hide Loyalty chkUseHideLoyalty.toolTipText=If enabled, loyalty modifiers will be hidden. +chkUseLeadershipChangeRefresh.text=Sudden Leadership Change Resets Loyalty +chkUseLeadershipChangeRefresh.toolTipText=If enabled, loyalty modifiers are rerolled when the campaign commander dies, deserts, or defects. ## Payouts turnoverAndRetentionPayoutPanel.title=Payouts diff --git a/MekHQ/src/mekhq/campaign/CampaignOptions.java b/MekHQ/src/mekhq/campaign/CampaignOptions.java index 4f03995984..7fe98735fa 100644 --- a/MekHQ/src/mekhq/campaign/CampaignOptions.java +++ b/MekHQ/src/mekhq/campaign/CampaignOptions.java @@ -296,6 +296,7 @@ public static String getTransitUnitName(final int unit) { private boolean useFamilyModifiers; private boolean useLoyaltyModifiers; private boolean useHideLoyalty; + private boolean useLeadershipChangeRefresh; private int payoutRateOfficer; private int payoutRateEnlisted; @@ -968,6 +969,7 @@ public CampaignOptions() { setUseLoyaltyModifiers(true); setUseHideLoyalty(false); + setUseLeadershipChangeRefresh(true); setPayoutRateOfficer(3); setPayoutRateEnlisted(3); @@ -1890,6 +1892,14 @@ public void setUseHideLoyalty(final boolean useHideLoyalty) { this.useHideLoyalty = useHideLoyalty; } + public boolean isUseLeadershipChangeRefresh() { + return useLeadershipChangeRefresh; + } + + public void setUseLeadershipChangeRefresh(final boolean useLeadershipChangeRefresh) { + this.useLeadershipChangeRefresh = useLeadershipChangeRefresh; + } + public boolean isUseRandomFounderTurnover() { return useRandomFounderTurnover; } @@ -4597,6 +4607,7 @@ public void writeToXml(final PrintWriter pw, int indent) { MHQXMLUtility.writeSimpleXMLTag(pw, indent, "useLoyaltyModifiers", isUseLoyaltyModifiers()); MHQXMLUtility.writeSimpleXMLTag(pw, indent, "useHideLoyalty", isUseHideLoyalty()); + MHQXMLUtility.writeSimpleXMLTag(pw, indent, "useLeadershipChangeRefresh", isUseLeadershipChangeRefresh()); MHQXMLUtility.writeSimpleXMLTag(pw, indent, "payoutRateOfficer", getPayoutRateOfficer()); MHQXMLUtility.writeSimpleXMLTag(pw, indent, "payoutRateEnlisted", getPayoutRateEnlisted()); @@ -5588,6 +5599,8 @@ public static CampaignOptions generateCampaignOptionsFromXml(Node wn, Version ve retVal.setUseLoyaltyModifiers(Boolean.parseBoolean(wn2.getTextContent().trim())); } else if (wn2.getNodeName().equalsIgnoreCase("useHideLoyalty")) { retVal.setUseHideLoyalty(Boolean.parseBoolean(wn2.getTextContent().trim())); + } else if (wn2.getNodeName().equalsIgnoreCase("useLeadershipChangeRefresh")) { + retVal.setUseLeadershipChangeRefresh(Boolean.parseBoolean(wn2.getTextContent().trim())); } else if (wn2.getNodeName().equalsIgnoreCase("payoutRateOfficer")) { retVal.setPayoutRateOfficer(Integer.parseInt(wn2.getTextContent().trim())); } else if (wn2.getNodeName().equalsIgnoreCase("payoutRateEnlisted")) { diff --git a/MekHQ/src/mekhq/campaign/personnel/Person.java b/MekHQ/src/mekhq/campaign/personnel/Person.java index e4481b051c..bc36c50952 100644 --- a/MekHQ/src/mekhq/campaign/personnel/Person.java +++ b/MekHQ/src/mekhq/campaign/personnel/Person.java @@ -973,9 +973,13 @@ public void changeStatus(final Campaign campaign, final LocalDate today, case DESERTED: campaign.addReport(String.format(status.getReportText(), getHyperlinkedFullTitle())); ServiceLogger.deserted(this, today); + if (campaign.getCampaignOptions().isUseRetirementDateTracking()) { setRetirement(today); } + + refreshLoyalty(campaign); + break; case DEFECTED: campaign.addReport(String.format(status.getReportText(), getHyperlinkedFullTitle())); @@ -983,6 +987,9 @@ public void changeStatus(final Campaign campaign, final LocalDate today, if (campaign.getCampaignOptions().isUseRetirementDateTracking()) { setRetirement(today); } + + refreshLoyalty(campaign); + break; case PREGNANCY_COMPLICATIONS: campaign.getProcreation().processPregnancyComplications(campaign, campaign.getLocalDate(), this); @@ -1000,10 +1007,12 @@ public void changeStatus(final Campaign campaign, final LocalDate today, if (status.isDead()) { setDateOfDeath(today); - // Don't forget to tell the spouse + // Remember to tell the spouse if (getGenealogy().hasSpouse() && !getGenealogy().getSpouse().getStatus().isDeadOrMIA()) { campaign.getDivorce().widowed(campaign, campaign.getLocalDate(), getGenealogy().getSpouse()); } + + refreshLoyalty(campaign); } if (status.isActive()) { @@ -1043,6 +1052,22 @@ public void changeStatus(final Campaign campaign, final LocalDate today, MekHQ.triggerEvent(new PersonStatusChangedEvent(this)); } + private void refreshLoyalty(Campaign campaign) { + if (isCommander()) { + if (campaign.getCampaignOptions().isUseLeadershipChangeRefresh()) { + for (Person person : campaign.getPersonnel()) { + if (person.getStatus().isDepartedUnit()) { + continue; + } + if (person.getPrisonerStatus().isCurrentPrisoner()) { + continue; + } + person.setLoyalty(Compute.d6(3)); + } + } + } + } + /** * This is used to directly set the Person's PersonnelStatus without any processing * @param status the person's new status diff --git a/MekHQ/src/mekhq/gui/panes/CampaignOptionsPane.java b/MekHQ/src/mekhq/gui/panes/CampaignOptionsPane.java index 0f485fa375..34ac221e7d 100644 --- a/MekHQ/src/mekhq/gui/panes/CampaignOptionsPane.java +++ b/MekHQ/src/mekhq/gui/panes/CampaignOptionsPane.java @@ -299,6 +299,7 @@ public class CampaignOptionsPane extends AbstractMHQTabbedPane { private JPanel loyaltySubPanel = new JPanel(); private JCheckBox chkUseHideLoyalty; + private JCheckBox chkUseLeadershipChangeRefresh; // Payout private JPanel turnoverAndRetentionPayoutPanel = new JPanel(); @@ -4255,6 +4256,7 @@ private JPanel createTurnoverAndRetentionHeaderPanel() { boolean isUseLoyaltyModifiers = chkUseLoyaltyModifiers.isSelected(); loyaltySubPanel.setEnabled((isEnabled) && (isUseLoyaltyModifiers)); chkUseHideLoyalty.setEnabled((isEnabled) && (isUseLoyaltyModifiers)); + chkUseLeadershipChangeRefresh.setEnabled((isEnabled) && (isUseLoyaltyModifiers)); boolean isUseServiceBonus = chkUsePayoutServiceBonus.isSelected(); payoutServiceBonusSubPanel.setEnabled((isEnabled) && (isUseServiceBonus)); @@ -4621,6 +4623,11 @@ private void createLoyaltySubPanel(boolean isUseTurnover) { chkUseHideLoyalty.setName("chkUseHideLoyalty"); chkUseHideLoyalty.setEnabled(isUseTurnover && campaign.getCampaignOptions().isUseLoyaltyModifiers()); + chkUseLeadershipChangeRefresh = new JCheckBox(resources.getString("chkUseLeadershipChangeRefresh.text")); + chkUseLeadershipChangeRefresh.setToolTipText(resources.getString("chkUseLeadershipChangeRefresh.toolTipText")); + chkUseLeadershipChangeRefresh.setName("chkUseLeadershipChangeRefresh"); + chkUseLeadershipChangeRefresh.setEnabled(isUseTurnover && campaign.getCampaignOptions().isUseLoyaltyModifiers()); + loyaltySubPanel.setBorder(BorderFactory.createTitledBorder("")); loyaltySubPanel.setName("loyaltySubPanel"); loyaltySubPanel.setEnabled(isUseTurnover && campaign.getCampaignOptions().isUseLoyaltyModifiers()); @@ -4633,11 +4640,13 @@ private void createLoyaltySubPanel(boolean isUseTurnover) { layout.setVerticalGroup( layout.createSequentialGroup() .addComponent(chkUseHideLoyalty) + .addComponent(chkUseLeadershipChangeRefresh) ); layout.setHorizontalGroup( layout.createParallelGroup(Alignment.LEADING) .addComponent(chkUseHideLoyalty) + .addComponent(chkUseLeadershipChangeRefresh) ); } @@ -8023,6 +8032,7 @@ public void setOptions(@Nullable CampaignOptions options, chkUseFamilyModifiers.setSelected(options.isUseFamilyModifiers()); chkUseLoyaltyModifiers.setSelected(options.isUseLoyaltyModifiers()); chkUseHideLoyalty.setSelected(options.isUseHideLoyalty()); + chkUseLeadershipChangeRefresh.setSelected(options.isUseLeadershipChangeRefresh()); // Payouts spnPayoutRateOfficer.setValue(options.getPayoutRateOfficer()); @@ -8710,6 +8720,7 @@ public void updateOptions() { options.setUseFamilyModifiers(chkUseFamilyModifiers.isSelected()); options.setUseLoyaltyModifiers(chkUseLoyaltyModifiers.isSelected()); options.setUseHideLoyalty(chkUseHideLoyalty.isSelected()); + options.setUseLeadershipChangeRefresh(chkUseLeadershipChangeRefresh.isSelected()); // Payouts options.setPayoutRateOfficer((Integer) spnPayoutRateOfficer.getValue());