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

Fixed Outsourcing of Babies #5093

Merged
merged 2 commits into from
Oct 23, 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
45 changes: 25 additions & 20 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -1440,27 +1440,32 @@ public Unit getUnit(UUID id) {
// region Personnel
// region Person Creation
/**
* Creates a new {@link Person} instance who is a dependent.
* If {@code baby} is false and the random dependent origin option is enabled,
* the new person will have a random origin.
* Creates a new dependent with given gender. The origin faction and planet are set to null.
*
* @param baby a boolean indicating if the person is a baby or not
* @param gender the Gender enum for the person (should normally be Gender.RANDOMIZE)
* @return a new {@link Person} instance who is a dependent
*/
public Person newDependent(boolean baby, Gender gender) {
Person person;

if ((!baby) && (getCampaignOptions().getRandomOriginOptions().isRandomizeDependentOrigin())) {
person = newPerson(PersonnelRole.DEPENDENT, PersonnelRole.NONE,
new DefaultFactionSelector(getCampaignOptions().getRandomOriginOptions()),
new DefaultPlanetSelector(getCampaignOptions().getRandomOriginOptions()),
gender);
} else {
person = newPerson(PersonnelRole.DEPENDENT);
}
* @param gender The {@link Gender} of the new dependent.
* @return Return a {@link Person} object representing the new dependent.
*/
public Person newDependent(Gender gender) {
return newDependent(gender, null, null);
}

return person;
/**
* Creates a new dependent with given gender, origin faction and origin planet.
*
* @param gender The {@link Gender} of the new dependent.
* @param originFaction The {@link Faction} that represents the origin faction for the new dependent.
* This can be null, suggesting the faction will be chosen based on campaign options.
* @param originPlanet The {@link Planet} that represents the origin planet for the new dependent.
* This can be null, suggesting the planet will be chosen based on campaign options.
* @return Return a {@link Person} object representing the new dependent.
*/
public Person newDependent(Gender gender, @Nullable Faction originFaction,
@Nullable Planet originPlanet) {
return newPerson(PersonnelRole.DEPENDENT,
PersonnelRole.NONE,
new DefaultFactionSelector(getCampaignOptions().getRandomOriginOptions(), originFaction),
new DefaultPlanetSelector(getCampaignOptions().getRandomOriginOptions(), originPlanet),
gender);
}

/**
Expand Down Expand Up @@ -4451,7 +4456,7 @@ void dependentsAddNew(int dependentCount, int dependentCapacity) {
}

if (roll <= (getAtBUnitRatingMod() * 2)) {
final Person dependent = newDependent(false, Gender.RANDOMIZE);
final Person dependent = newDependent(Gender.RANDOMIZE);

recruitPerson(dependent, PrisonerStatus.FREE, true, false);

Expand Down
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/campaign/mission/AtBContract.java
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ public void doBonusRoll(Campaign campaign) {
campaign.addReport("Bonus: " + number + " dependent" + ((number > 1) ? "s" : ""));

for (int i = 0; i < number; i++) {
Person p = campaign.newDependent(false, Gender.RANDOMIZE);
Person p = campaign.newDependent(Gender.RANDOMIZE);
campaign.recruitPerson(p);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ protected void marryRandomSpouse(final Campaign campaign, final LocalDate today,
* @return the created external spouse
*/
Person createExternalSpouse(final Campaign campaign, final LocalDate today, final Person person, Gender gender) {
Person externalSpouse = campaign.newDependent(false, gender);
Person externalSpouse = campaign.newDependent(gender);


// Calculate person's age and the maximum and minimum allowable spouse ages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import mekhq.campaign.personnel.education.EducationController;
import mekhq.campaign.personnel.enums.*;
import mekhq.campaign.personnel.enums.education.EducationLevel;
import mekhq.campaign.universe.Faction;
import mekhq.campaign.universe.Planet;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
Expand Down Expand Up @@ -337,7 +339,8 @@ public void birth(final Campaign campaign, final LocalDate today, final Person m
// Create Babies
for (int i = 0; i < size; i++) {
// Create a baby
final Person baby = campaign.newDependent(true, Gender.RANDOMIZE);
final Person baby = campaign.newDependent(
Gender.RANDOMIZE, mother.getOriginFaction(), campaign.getLocation().getPlanet());
baby.setSurname(campaign.getCampaignOptions().getBabySurnameStyle()
.generateBabySurname(mother, father, baby.getGender()));
baby.setDateOfBirth(today);
Expand Down Expand Up @@ -436,7 +439,15 @@ public List<Person> birthHistoric(final Campaign campaign, final LocalDate today
// Create Babies
for (int i = 0; i < size; i++) {
// Create the babies
final Person baby = campaign.newDependent(true, Gender.RANDOMIZE);
Faction originFaction = mother.getOriginFaction();
Planet originPlanet = mother.getOriginPlanet();

if (father != null && Compute.randomInt(1) == 0) {
originFaction = father.getOriginFaction();
originPlanet = father.getOriginPlanet();
}

final Person baby = campaign.newDependent(Gender.RANDOMIZE, originFaction, originPlanet);

baby.setSurname(campaign.getCampaignOptions().getBabySurnameStyle()
.generateBabySurname(mother, father, baby.getGender()));
Expand Down