Skip to content

Commit 6038bf1

Browse files
authored
Merge pull request #7200 from IllianiBird/civilianProfessionOptions
Improvement: #7196 Improved Civilian Generation to Include Better Control Over Random Profession Selection
2 parents 1011296 + b3e798e commit 6038bf1

File tree

5 files changed

+118
-5
lines changed

5 files changed

+118
-5
lines changed

MekHQ/resources/mekhq/resources/CampaignOptionsDialog.properties

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,21 @@ lblUseRandomDependentAddition.tooltip=This enables the monthly addition of rando
551551
lblUseRandomDependentRemoval.text=Random Removal
552552
lblUseRandomDependentRemoval.tooltip=This enables the monthly removal of random civilians from the\
553553
\ campaign.
554+
lblDependentProfessionDieSize.text=Dependent Profession Chance: \u26A0 <span style="color:#C344C3;">\u2605</span> 1 in
555+
lblDependentProfessionDieSize.tooltip=This is the number of sides on the die rolled to determine whether a\
556+
\ a civilian should generate with the Dependent profession.\
557+
<br>\
558+
<br>A civilian will generation with the Dependent profession on a roll of 1. Set to 0 to prevent Civilians from \
559+
spawning with the catch-all 'Professional' profession.
560+
lblCivilianProfessionDieSize.text=Civilian Profession Chance: \u26A0 <span style="color:#C344C3;">\u2605</span> 1 in
561+
lblCivilianProfessionDieSize.tooltip=This is the number of sides on the die rolled to determine whether a\
562+
\ a civilian should generate with a random non-Dependent profession.\
563+
<br>\
564+
<br>A civilian will generate with a non-Dependent profession on a roll of 1. Set to 0 to disable random \
565+
non-Dependent profession assignment.\
566+
<br>\
567+
<br><b>Warning:</b> This check is made <i>after</i> the check to see whether a character is generated as a \
568+
Dependent. That means the actual chance of a character generating as a Dependent will be lower than displayed.
554569
# createMedicalTab
555570
lblMedicalTab.text=Medical Options
556571
lblUseAdvancedMedical.text=Use Advanced Medical \u270E \u2318

MekHQ/src/mekhq/campaign/Campaign.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,7 @@ public Person newDependent(Gender gender) {
19111911
}
19121912

19131913
/**
1914-
* Creates a new dependent with given gender, origin faction and origin planet.
1914+
* Creates a new dependent with the given gender, origin faction, and origin planet.
19151915
*
19161916
* @param gender The {@link Gender} of the new dependent.
19171917
* @param originFaction The {@link Faction} that represents the origin faction for the new dependent. This can be
@@ -1924,11 +1924,22 @@ public Person newDependent(Gender gender) {
19241924
public Person newDependent(Gender gender, @Nullable Faction originFaction, @Nullable Planet originPlanet) {
19251925
PersonnelRole civilianProfession = PersonnelRole.MISCELLANEOUS_JOB;
19261926

1927-
if (randomInt(20) == 0) {
1928-
List<PersonnelRole> civilianRoles = PersonnelRole.getCivilianRolesExceptNone();
1929-
civilianProfession = ObjectUtility.getRandomItem(civilianRoles);
1927+
int dependentProfessionDieSize = campaignOptions.getDependentProfessionDieSize();
1928+
if (dependentProfessionDieSize == 0 || randomInt(dependentProfessionDieSize) == 0) {
1929+
civilianProfession = PersonnelRole.DEPENDENT;
19301930
}
19311931

1932+
int civilianProfessionDieSize = campaignOptions.getCivilianProfessionDieSize();
1933+
if (civilianProfessionDieSize > 0) { // A value of 0 denotes that this system has been disabled
1934+
if (randomInt(civilianProfessionDieSize) == 0) {
1935+
List<PersonnelRole> civilianRoles = PersonnelRole.getCivilianRolesExceptNone();
1936+
civilianProfession = ObjectUtility.getRandomItem(civilianRoles);
1937+
}
1938+
}
1939+
1940+
// When a character is generated we include age checks to ensure they're old enough for the profession
1941+
// chosen, so we don't need to include age-checks here.
1942+
19321943
return newPerson(civilianProfession,
19331944
PersonnelRole.NONE,
19341945
new DefaultFactionSelector(getCampaignOptions().getRandomOriginOptions(), originFaction),

MekHQ/src/mekhq/campaign/CampaignOptions.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ public static String getTechLevelName(final int techLevel) {
277277
// Dependent
278278
private boolean useRandomDependentAddition;
279279
private boolean useRandomDependentRemoval;
280+
private int dependentProfessionDieSize;
281+
private int civilianProfessionDieSize;
280282

281283
// Personnel Removal
282284
private boolean usePersonnelRemoval;
@@ -833,6 +835,8 @@ public CampaignOptions() {
833835
// Dependent
834836
setUseRandomDependentAddition(false);
835837
setUseRandomDependentRemoval(false);
838+
setDependentProfessionDieSize(4);
839+
setCivilianProfessionDieSize(2);
836840

837841
// Personnel Removal
838842
setUsePersonnelRemoval(false);
@@ -2398,6 +2402,22 @@ public boolean isUseRandomDependentRemoval() {
23982402
public void setUseRandomDependentRemoval(final boolean useRandomDependentRemoval) {
23992403
this.useRandomDependentRemoval = useRandomDependentRemoval;
24002404
}
2405+
2406+
public int getDependentProfessionDieSize() {
2407+
return dependentProfessionDieSize;
2408+
}
2409+
2410+
public void setDependentProfessionDieSize(final int dependentProfessionDieSize) {
2411+
this.dependentProfessionDieSize = dependentProfessionDieSize;
2412+
}
2413+
2414+
public int getCivilianProfessionDieSize() {
2415+
return civilianProfessionDieSize;
2416+
}
2417+
2418+
public void setCivilianProfessionDieSize(final int civilianProfessionDieSize) {
2419+
this.civilianProfessionDieSize = civilianProfessionDieSize;
2420+
}
24012421
// endregion Dependent
24022422

24032423
// region Personnel Removal
@@ -5062,6 +5082,8 @@ public void writeToXml(final PrintWriter pw, int indent) {
50625082
// region Dependent
50635083
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "useRandomDependentAddition", isUseRandomDependentAddition());
50645084
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "useRandomDependentRemoval", isUseRandomDependentRemoval());
5085+
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "dependentProfessionDieSize", getDependentProfessionDieSize());
5086+
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "civilianProfessionDieSize", getCivilianProfessionDieSize());
50655087
// endregion Dependent
50665088

50675089
// region Personnel Removal
@@ -5911,6 +5933,10 @@ public static CampaignOptions generateCampaignOptionsFromXml(Node parentNod, Ver
59115933
campaignOptions.setUseRandomDependentAddition(Boolean.parseBoolean(nodeContents));
59125934
} else if (nodeName.equalsIgnoreCase("useRandomDependentRemoval")) {
59135935
campaignOptions.setUseRandomDependentRemoval(Boolean.parseBoolean(nodeContents));
5936+
} else if (nodeName.equalsIgnoreCase("dependentProfessionDieSize")) {
5937+
campaignOptions.setDependentProfessionDieSize(MathUtility.parseInt(nodeContents, 4));
5938+
} else if (nodeName.equalsIgnoreCase("civilianProfessionDieSize")) {
5939+
campaignOptions.setCivilianProfessionDieSize(MathUtility.parseInt(nodeContents, 2));
59145940
// endregion Dependent
59155941

59165942
// region Personnel Removal

MekHQ/src/mekhq/gui/campaignOptions/CampaignOptionsUtilities.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,25 @@ public static int processWrapSize(@Nullable Integer customWrapSize) {
245245
return customWrapSize == null ? 100 : customWrapSize;
246246
}
247247

248+
/**
249+
* Creates a {@link MouseAdapter} that updates the text of a {@link JLabel} within the specified panel to display a
250+
* tip string when the mouse enters a related component.
251+
*
252+
* <p>
253+
* When the mouse enters a component with the specified name, this adapter retrieves a localized tip string
254+
* associated with that component. If the tip contains fewer than five HTML line break tags ({@code <br>}), extra
255+
* line breaks are appended to ensure a minimum number of lines. The formatted tip is then set as the text of a
256+
* {@link JLabel} within the provided panel, specifically targeting labels whose name matches the required pattern.
257+
* </p>
258+
*
259+
* @param associatedHeaderPanel the {@link JPanel} containing the label to update
260+
* @param sourceComponentBaseName the name of the component whose tip string will be shown in the label
261+
*
262+
* @return a {@link MouseAdapter} instance that updates the label with formatted tip text on mouse enter
263+
*
264+
* @author Illiani
265+
* @since 0.50.06
266+
*/
248267
public static MouseAdapter createTipPanelUpdater(CampaignOptionsHeaderPanel associatedHeaderPanel,
249268
@Nullable String sourceComponentBaseName) {
250269
return createTipPanelUpdater(associatedHeaderPanel, sourceComponentBaseName, null);
@@ -263,6 +282,8 @@ public static MouseAdapter createTipPanelUpdater(CampaignOptionsHeaderPanel asso
263282
*
264283
* @param associatedHeaderPanel the {@link JPanel} containing the label to update
265284
* @param sourceComponentBaseName the name of the component whose tip string will be shown in the label
285+
* @param replacementText the specific text to use, or {@code null} if the text should be dynamically fetched
286+
* from the source component.
266287
*
267288
* @return a {@link MouseAdapter} instance that updates the label with formatted tip text on mouse enter
268289
*

MekHQ/src/mekhq/gui/campaignOptions/contents/PersonnelTab.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ public class PersonnelTab {
199199
private JPanel dependentsPanel;
200200
private JCheckBox chkUseRandomDependentAddition;
201201
private JCheckBox chkUseRandomDependentRemoval;
202+
private JLabel lblDependentProfessionDieSize;
203+
private JSpinner spnDependentProfessionDieSize;
204+
private JLabel lblCivilianProfessionDieSize;
205+
private JSpinner spnCivilianProfessionDieSize;
202206
//end Prisoners and Dependents Tab
203207
//end Salaries Tab
204208

@@ -239,6 +243,10 @@ private void initializePrisonersAndDependentsTab() {
239243
dependentsPanel = new JPanel();
240244
chkUseRandomDependentAddition = new JCheckBox();
241245
chkUseRandomDependentRemoval = new JCheckBox();
246+
lblDependentProfessionDieSize = new JLabel();
247+
spnDependentProfessionDieSize = new JSpinner();
248+
lblCivilianProfessionDieSize = new JLabel();
249+
spnCivilianProfessionDieSize = new JSpinner();
242250
}
243251

244252
/**
@@ -1050,7 +1058,7 @@ public JPanel createPrisonersAndDependentsTab() {
10501058
// Header
10511059
prisonersAndDependentsHeader = new CampaignOptionsHeaderPanel("PrisonersAndDependentsTab",
10521060
getImageDirectory() + "logo_illyrian_palatinate.png",
1053-
2);
1061+
9);
10541062

10551063
// Contents
10561064
prisonerPanel = createPrisonersPanel();
@@ -1133,10 +1141,27 @@ private JPanel createDependentsPanel() {
11331141
chkUseRandomDependentAddition = new CampaignOptionsCheckBox("UseRandomDependentAddition");
11341142
chkUseRandomDependentAddition.addMouseListener(createTipPanelUpdater(prisonersAndDependentsHeader,
11351143
"UseRandomDependentAddition"));
1144+
11361145
chkUseRandomDependentRemoval = new CampaignOptionsCheckBox("UseRandomDependentRemoval");
11371146
chkUseRandomDependentRemoval.addMouseListener(createTipPanelUpdater(prisonersAndDependentsHeader,
11381147
"UseRandomDependentRemoval"));
11391148

1149+
lblDependentProfessionDieSize = new CampaignOptionsLabel("DependentProfessionDieSize");
1150+
lblDependentProfessionDieSize.addMouseListener(createTipPanelUpdater(prisonersAndDependentsHeader,
1151+
"DependentProfessionDieSize"));
1152+
spnDependentProfessionDieSize = new CampaignOptionsSpinner("DependentProfessionDieSize",
1153+
4, 0, 100, 1);
1154+
spnDependentProfessionDieSize.addMouseListener(createTipPanelUpdater(prisonersAndDependentsHeader,
1155+
"DependentProfessionDieSize"));
1156+
1157+
lblCivilianProfessionDieSize = new CampaignOptionsLabel("CivilianProfessionDieSize");
1158+
lblCivilianProfessionDieSize.addMouseListener(createTipPanelUpdater(prisonersAndDependentsHeader,
1159+
"CivilianProfessionDieSize"));
1160+
spnCivilianProfessionDieSize = new CampaignOptionsSpinner("CivilianProfessionDieSize",
1161+
2, 0, 100, 1);
1162+
spnCivilianProfessionDieSize.addMouseListener(createTipPanelUpdater(prisonersAndDependentsHeader,
1163+
"CivilianProfessionDieSize"));
1164+
11401165
// Layout the Panel
11411166
final JPanel panel = new CampaignOptionsStandardPanel("DependentsPanel", true, "DependentsPanel");
11421167
final GridBagConstraints layout = new CampaignOptionsGridBagConstraints(panel);
@@ -1149,6 +1174,17 @@ private JPanel createDependentsPanel() {
11491174
layout.gridy++;
11501175
panel.add(chkUseRandomDependentRemoval, layout);
11511176

1177+
layout.gridy++;
1178+
panel.add(lblDependentProfessionDieSize, layout);
1179+
layout.gridx++;
1180+
panel.add(spnDependentProfessionDieSize, layout);
1181+
1182+
layout.gridx = 0;
1183+
layout.gridy++;
1184+
panel.add(lblCivilianProfessionDieSize, layout);
1185+
layout.gridx++;
1186+
panel.add(spnCivilianProfessionDieSize, layout);
1187+
11521188
return panel;
11531189
}
11541190

@@ -1308,6 +1344,8 @@ public void loadValuesFromCampaignOptions(@Nullable CampaignOptions presetCampai
13081344
comboPrisonerCaptureStyle.setSelectedItem(options.getPrisonerCaptureStyle());
13091345
chkUseRandomDependentAddition.setSelected(options.isUseRandomDependentAddition());
13101346
chkUseRandomDependentRemoval.setSelected(options.isUseRandomDependentRemoval());
1347+
spnDependentProfessionDieSize.setValue(options.getDependentProfessionDieSize());
1348+
spnCivilianProfessionDieSize.setValue(options.getCivilianProfessionDieSize());
13111349
}
13121350

13131351
/**
@@ -1400,5 +1438,7 @@ public void applyCampaignOptionsToCampaign(Campaign campaign, @Nullable Campaign
14001438
}
14011439
options.setUseRandomDependentAddition(chkUseRandomDependentAddition.isSelected());
14021440
options.setUseRandomDependentRemoval(chkUseRandomDependentRemoval.isSelected());
1441+
options.setDependentProfessionDieSize((int) spnDependentProfessionDieSize.getValue());
1442+
options.setCivilianProfessionDieSize((int) spnCivilianProfessionDieSize.getValue());
14031443
}
14041444
}

0 commit comments

Comments
 (0)