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 Population Check to Education Module #4281

Merged
merged 10 commits into from
Jun 27, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,8 @@ chkEnablePrestigiousAcademies.text=Enable Prestigious Academies
chkEnablePrestigiousAcademies.toolTip=Allows personnel to enroll in named, canonical, academies.

showIneligible.title=Eligibility Criteria
chkShowPopulationConflict.text=No Population
chkShowPopulationConflict.toolTip=Show academies in unpopulated systems.
chkShowAgeConflict.text=Too Old/Young
chkShowAgeConflict.toolTip=Show academies the selected person is too old, or young, to attend
chkShowUnqualified.text=Unqualified
Expand Down
2 changes: 1 addition & 1 deletion MekHQ/resources/mekhq/resources/GUI.properties
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ sack.text=Sack
eduEducation.text=Education
eduCivilian.text=Civilian
eduMilitary.text=Military
eduClan.text=Clan
eduPopulationConflict.text=---<i>Unpopulated system</i></html>
eduAgeConflictRange.text=---<i>Requires ages %s-%s</i></html>
eduAgeConflictPlus.text=---<i>Requires ages %s+</i></html>
eduUnqualified.text=---<i>Education Level %s+ Required</i></html>
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 @@ -390,6 +390,7 @@ public static String getTransitUnitName(final int unit) {
private boolean enableLocalAcademies;
private boolean enablePrestigiousAcademies;
private boolean enableShowIneligibleAcademies;
private boolean enablePopulationConflict;
private boolean enableShowAgeConflict;
private boolean enableShowUnqualified;
private boolean enableShowFactionConflict;
Expand Down Expand Up @@ -901,6 +902,7 @@ public CampaignOptions() {
setEnableLocalAcademies(true);
setEnablePrestigiousAcademies(true);
setEnableShowIneligibleAcademies(true);
setEnablePopulationConflict(true);
setEnableShowAgeConflict(false);
setEnableShowUnqualified(true);
setEnableShowFactionConflict(true);
Expand Down Expand Up @@ -2740,6 +2742,14 @@ public void setEnableShowIneligibleAcademies(boolean enableShowIneligibleAcademi
this.enableShowIneligibleAcademies = enableShowIneligibleAcademies;
}

public boolean isEnablePopulationConflict() {
return enablePopulationConflict;
}

public void setEnablePopulationConflict(final boolean enablePopulationConflict) {
this.enablePopulationConflict = enablePopulationConflict;
}

public boolean isEnableShowAgeConflict() {
return enableShowAgeConflict;
}
Expand Down Expand Up @@ -4745,6 +4755,7 @@ public void writeToXml(final PrintWriter pw, int indent) {
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "enableLocalAcademies", isEnableLocalAcademies());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "enablePrestigiousAcademies", isEnablePrestigiousAcademies());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "enableShowIneligibleAcademies", isEnableShowIneligibleAcademies());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "enablePopulationConflict", isEnablePopulationConflict());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "enableShowAgeConflict", isEnableShowAgeConflict());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "enableShowUnqualified", isEnableShowUnqualified());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "enableShowFactionConflict", isEnableShowFactionConflict());
Expand Down Expand Up @@ -5503,6 +5514,8 @@ public static CampaignOptions generateCampaignOptionsFromXml(Node wn, Version ve
retVal.setEnableShowIneligibleAcademies(Boolean.parseBoolean(wn2.getTextContent().trim()));
} else if (wn2.getNodeName().equalsIgnoreCase("enableShowAgeConflict")) {
retVal.setEnableShowAgeConflict(Boolean.parseBoolean(wn2.getTextContent().trim()));
} else if (wn2.getNodeName().equalsIgnoreCase("enablePopulationConflict")) {
retVal.setEnablePopulationConflict(Boolean.parseBoolean(wn2.getTextContent().trim()));
} else if (wn2.getNodeName().equalsIgnoreCase("enableShowUnqualified")) {
retVal.setEnableShowUnqualified(Boolean.parseBoolean(wn2.getTextContent().trim()));
} else if (wn2.getNodeName().equalsIgnoreCase("enableShowFactionConflict")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,13 @@ private static void processNewWeekChecks(Campaign campaign, Academy academy, Per
}
}

// has the system been depopulated? Nominally similar to the above, but here we use actual system data, so it's more dynamic.
if (campaign.getSystemById(person.getEduAcademySystem()).getPopulation(campaign.getLocalDate()) == 0) {
if (checkForAcademyDestruction(campaign, academy, person, resources)) {
return;
}
}

// is the academy faction at war with person faction, or the campaign faction?
if (checkForAcademyFactionConflict(campaign, academy, person, resources)) {
return;
Expand Down Expand Up @@ -658,7 +665,9 @@ private static boolean checkForAcademyClosure(Campaign campaign, Academy academy
* @return true if the academy has been destroyed, false otherwise
*/
private static boolean checkForAcademyDestruction(Campaign campaign, Academy academy, Person person, ResourceBundle resources) {
if (campaign.getLocalDate().getYear() >= academy.getDestructionYear()) {
// we assume that if the system's population has been depleted, the academy has been destroyed too.
if ((campaign.getLocalDate().getYear() >= academy.getDestructionYear())
|| (campaign.getSystemById(person.getEduAcademySystem()).getPopulation(campaign.getLocalDate()) == 0)) {
if ((!person.isChild(campaign.getLocalDate())) || (campaign.getCampaignOptions().isAllAges())) {
if (Compute.d6(2) >= 5) {
campaign.addReport(person.getHyperlinkedName() + ' ' + resources.getString("eventDestruction.text"));
Expand Down
18 changes: 15 additions & 3 deletions MekHQ/src/mekhq/gui/adapter/PersonnelTableMouseAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2607,10 +2607,16 @@ private void buildEducationMenusSingleton(Campaign campaign, Person person, Acad
if ((campaign.getGameYear() >= academy.getConstructionYear())
&& (campaign.getGameYear() < academy.getDestructionYear())
&& (campaign.getGameYear() < academy.getClosureYear())) {
// is the applicant within the right age bracket?
int personAge = person.getAge(campaign.getLocalDate());
// is the planet populated?
if (campaign.getCurrentSystem().getPopulation(campaign.getLocalDate()) == 0) {
if ((showIneligibleAcademies) && (campaign.getCampaignOptions().isEnablePopulationConflict())) {
JMenuItem academyOption = new JMenuItem("<html>" + academy.getName()
+ resources.getString("eduPopulationConflict.text") + "</html>");

if ((personAge >= academy.getAgeMax()) || (personAge < academy.getAgeMin())) {
educationJMenuItemAdder(academy, militaryMenu, civilianMenu, academyOption);
}
// is the applicant within the right age bracket?
} else if ((person.getAge(campaign.getLocalDate()) >= academy.getAgeMax()) || (person.getAge(campaign.getLocalDate()) < academy.getAgeMin())) {
if ((showIneligibleAcademies) && (campaign.getCampaignOptions().isEnableShowAgeConflict())) {
JMenuItem academyOption;

Expand Down Expand Up @@ -2706,6 +2712,12 @@ private void buildEducationMenusMassEnroll(Campaign campaign, List<Person> perso
if ((campaign.getGameYear() >= academy.getConstructionYear())
&& (campaign.getGameYear() < academy.getDestructionYear())
&& (campaign.getGameYear() < academy.getClosureYear())) {

// is the planet populated?
if (campaign.getCurrentSystem().getPopulation(campaign.getLocalDate()) == 0) {
return;
}

// are all the applicants within the right age bracket?
// are all the applicants qualified?
boolean arePersonnelEligible = personnel.stream()
Expand Down
13 changes: 12 additions & 1 deletion MekHQ/src/mekhq/gui/panes/CampaignOptionsPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ public class CampaignOptionsPane extends AbstractMHQTabbedPane {
private JCheckBox chkEnableLocalAcademies;
private JCheckBox chkEnablePrestigiousAcademies;
private JCheckBox chkShowIneligibleAcademies;
private JCheckBox chkShowPopulationConflict;
private JCheckBox chkShowAgeConflict;
private JCheckBox chkShowUnqualified;
private JCheckBox chkShowFactionConflict;
Expand Down Expand Up @@ -6074,6 +6075,7 @@ private JPanel createEducationPanel() {
chkShowIneligibleAcademies.addActionListener(evt -> {
final boolean isEnabled = chkShowIneligibleAcademies.isSelected();

chkShowPopulationConflict.setEnabled(isEnabled);
chkShowAgeConflict.setEnabled(isEnabled);
chkShowUnqualified.setEnabled(isEnabled);
chkShowFactionConflict.setEnabled(isEnabled);
Expand Down Expand Up @@ -6110,6 +6112,7 @@ private JPanel createEducationPanel() {

enableShowIneligiblePanel.setEnabled(isEnabled);
chkShowIneligibleAcademies.setEnabled(isEnabled);
chkShowPopulationConflict.setEnabled(isEnabled);
chkShowAgeConflict.setEnabled(isEnabled);
chkShowUnqualified.setEnabled(isEnabled);
chkShowFactionConflict.setEnabled(isEnabled);
Expand Down Expand Up @@ -6237,6 +6240,10 @@ private JPanel createStandardSetsPanel() {
}

private JPanel createShowIneligiblePanel() {
chkShowPopulationConflict = new JCheckBox(resources.getString("chkShowPopulationConflict.text"));
chkShowPopulationConflict.setToolTipText(resources.getString("chkShowPopulationConflict.toolTip"));
chkShowPopulationConflict.setName("chkShowPopulationConflict");

chkShowAgeConflict = new JCheckBox(resources.getString("chkShowAgeConflict.text"));
chkShowAgeConflict.setToolTipText(resources.getString("chkShowAgeConflict.toolTip"));
chkShowAgeConflict.setName("chkShowAgeConflict");
Expand All @@ -6255,6 +6262,7 @@ private JPanel createShowIneligiblePanel() {

// this prevents a really annoying bug where disabled options don't stay disabled when
// reloading Campaign Options
chkShowPopulationConflict.setEnabled(campaign.getCampaignOptions().isEnableShowIneligibleAcademies());
chkShowAgeConflict.setEnabled(campaign.getCampaignOptions().isEnableShowIneligibleAcademies());
chkShowUnqualified.setEnabled(campaign.getCampaignOptions().isEnableShowIneligibleAcademies());
chkShowFactionConflict.setEnabled(campaign.getCampaignOptions().isEnableShowIneligibleAcademies());
Expand All @@ -6272,6 +6280,7 @@ private JPanel createShowIneligiblePanel() {

layout.setVerticalGroup(
layout.createParallelGroup(Alignment.LEADING)
.addComponent(chkShowPopulationConflict)
.addComponent(chkShowAgeConflict)
.addComponent(chkShowUnqualified)
.addComponent(chkShowFactionConflict)
Expand All @@ -6280,6 +6289,7 @@ private JPanel createShowIneligiblePanel() {

layout.setHorizontalGroup(
layout.createSequentialGroup()
.addComponent(chkShowPopulationConflict)
.addComponent(chkShowAgeConflict)
.addComponent(chkShowUnqualified)
.addComponent(chkShowFactionConflict)
Expand Down Expand Up @@ -8238,6 +8248,7 @@ public void setOptions(@Nullable CampaignOptions options,
chkEnableLocalAcademies.setSelected(options.isEnableLocalAcademies());
chkEnablePrestigiousAcademies.setSelected(options.isEnablePrestigiousAcademies());
chkShowIneligibleAcademies.setSelected(options.isEnableShowIneligibleAcademies());
chkShowPopulationConflict.setSelected(options.isEnablePopulationConflict());
chkShowAgeConflict.setSelected(options.isEnableShowAgeConflict());
chkShowUnqualified.setSelected(options.isEnableShowUnqualified());
chkShowFactionConflict.setSelected(options.isEnableShowFactionConflict());
Expand Down Expand Up @@ -8904,7 +8915,7 @@ public void updateOptions() {
options.setEnableLocalAcademies(chkEnableLocalAcademies.isSelected());
options.setEnablePrestigiousAcademies(chkEnablePrestigiousAcademies.isSelected());
options.setEnableShowIneligibleAcademies(chkShowIneligibleAcademies.isSelected());
options.setEnableShowAgeConflict(chkShowAgeConflict.isSelected());
options.setEnablePopulationConflict(chkShowPopulationConflict.isSelected());
options.setEnableShowUnqualified(chkShowUnqualified.isSelected());
options.setEnableShowFactionConflict(chkShowFactionConflict.isSelected());
options.setEnableShowRangeConflict(chkShowRangeConflict.isSelected());
Expand Down
Loading