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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
55 changes: 29 additions & 26 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -1448,27 +1448,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.RANDOMIZE);
} 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 @@ -2250,13 +2255,11 @@ private void updatePartInUseData(PartInUse partInUse, Part incomingPart,
boolean ignoreMothballedUnits, PartQuality ignoreSparesUnderQuality) {

if (ignoreMothballedUnits && (null != incomingPart.getUnit()) && incomingPart.getUnit().isMothballed()) {
return;
} else if ((incomingPart.getUnit() != null) || (incomingPart instanceof MissingPart)) {
partInUse.setUseCount(partInUse.getUseCount() + getQuantity(incomingPart));
} else {
if (incomingPart.isPresent()) {
if (incomingPart.getQuality().toNumeric() < ignoreSparesUnderQuality.toNumeric()) {
return;
} else {
partInUse.setStoreCount(partInUse.getStoreCount() + getQuantity(incomingPart));
partInUse.addSpare(incomingPart);
Expand All @@ -2273,7 +2276,7 @@ private void updatePartInUseData(PartInUse partInUse, Part incomingPart,
* @param ignoreMothballedUnits don't count parts in mothballed units
* @param ignoreSparesUnderQuality don't count spare parts lower than this quality
*/
public void updatePartInUse(PartInUse partInUse, boolean ignoreMothballedUnits,
public void updatePartInUse(PartInUse partInUse, boolean ignoreMothballedUnits,
PartQuality ignoreSparesUnderQuality) {
partInUse.setUseCount(0);
partInUse.setStoreCount(0);
Expand All @@ -2290,7 +2293,7 @@ public void updatePartInUse(PartInUse partInUse, boolean ignoreMothballedUnits,
PartInUse newPiu = getPartInUse((Part) maybePart);
if (partInUse.equals(newPiu)) {
partInUse.setPlannedCount(partInUse.getPlannedCount()
+ getQuantity((maybePart instanceof MissingPart) ?
+ getQuantity((maybePart instanceof MissingPart) ?
((MissingPart) maybePart).getNewPart() :
(Part) maybePart) * maybePart.getQuantity());
}
Expand Down Expand Up @@ -2334,7 +2337,7 @@ public Set<PartInUse> getPartsInUse(boolean ignoreMothballedUnits,
inUse.put(partInUse, partInUse);
}
partInUse.setPlannedCount(partInUse.getPlannedCount()
+ getQuantity((maybePart instanceof MissingPart) ?
+ getQuantity((maybePart instanceof MissingPart) ?
((MissingPart) maybePart).getNewPart() :
(Part) maybePart) * maybePart.getQuantity());

Expand Down Expand Up @@ -4462,7 +4465,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 Expand Up @@ -8002,7 +8005,7 @@ private String doMaintenanceOnUnitPart(Unit u, Part p, Map<Part, Integer> partsT
// }
break;
}
if (p.getQuality().toNumeric() > oldQuality.toNumeric()) {
if (p.getQuality().toNumeric() > oldQuality.toNumeric()) {
partReport += ": " + ReportingUtilities.messageSurroundedBySpanWithColor(
MekHQ.getMHQOptions().getFontColorPositiveHexColor(),
"new quality is " + p.getQualityName());
Expand Down
5 changes: 2 additions & 3 deletions MekHQ/src/mekhq/campaign/mission/AtBContract.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import mekhq.campaign.mission.atb.AtBScenarioFactory;
import mekhq.campaign.mission.enums.AtBContractType;
import mekhq.campaign.mission.enums.AtBMoraleLevel;
import mekhq.campaign.mission.enums.ContractCommandRights;
import mekhq.campaign.personnel.Bloodname;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.personnel.backgrounds.BackgroundsController;
Expand Down Expand Up @@ -662,7 +661,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 Expand Up @@ -1934,7 +1933,7 @@ private static double estimateMekStrength(Campaign campaign, String factionCode,
// getMekSummary(int index) is NULL for salvage.
int genericBattleValue = unitTable.getMekSummary(i).loadEntity().getGenericBattleValue();
int weight = unitTable.getEntryWeight(i); // NOT 0 for salvage

totalBattleValue += battleValue * weight;
totalGBV += genericBattleValue * weight;
rollingCount += weight;
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