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

Added the Automatic Release of the Commander Flag upon Commander Departure or Death, and Loyalty Reset upon Sudden Leadership Change #4393

Merged
merged 4 commits into from
Jul 14, 2024
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 @@ -189,6 +189,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
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 @@ -297,6 +297,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;
Expand Down Expand Up @@ -970,6 +971,7 @@ public CampaignOptions() {

setUseLoyaltyModifiers(true);
setUseHideLoyalty(false);
setUseLeadershipChangeRefresh(true);

setPayoutRateOfficer(3);
setPayoutRateEnlisted(3);
Expand Down Expand Up @@ -1892,6 +1894,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;
}
Expand Down Expand Up @@ -4608,6 +4618,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());
Expand Down Expand Up @@ -5601,6 +5612,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")) {
Expand Down
32 changes: 31 additions & 1 deletion MekHQ/src/mekhq/campaign/personnel/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -973,16 +973,23 @@ 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()));
ServiceLogger.defected(this, today);
if (campaign.getCampaignOptions().isUseRetirementDateTracking()) {
setRetirement(today);
}

refreshLoyalty(campaign);

break;
case PREGNANCY_COMPLICATIONS:
campaign.getProcreation().processPregnancyComplications(campaign, campaign.getLocalDate(), this);
Expand All @@ -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()) {
Expand All @@ -1023,6 +1032,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);
Expand All @@ -1038,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
Expand Down
11 changes: 11 additions & 0 deletions MekHQ/src/mekhq/gui/panes/CampaignOptionsPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ public class CampaignOptionsPane extends AbstractMHQTabbedPane {

private JPanel loyaltySubPanel = new JPanel();
private JCheckBox chkUseHideLoyalty;
private JCheckBox chkUseLeadershipChangeRefresh;

// Payout
private JPanel turnoverAndRetentionPayoutPanel = new JPanel();
Expand Down Expand Up @@ -4257,6 +4258,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));
Expand Down Expand Up @@ -4645,6 +4647,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());
Expand All @@ -4657,11 +4664,13 @@ private void createLoyaltySubPanel(boolean isUseTurnover) {
layout.setVerticalGroup(
layout.createSequentialGroup()
.addComponent(chkUseHideLoyalty)
.addComponent(chkUseLeadershipChangeRefresh)
);

layout.setHorizontalGroup(
layout.createParallelGroup(Alignment.LEADING)
.addComponent(chkUseHideLoyalty)
.addComponent(chkUseLeadershipChangeRefresh)
);
}

Expand Down Expand Up @@ -8048,6 +8057,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());
Expand Down Expand Up @@ -8736,6 +8746,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());
Expand Down