From cb4bdecba096ba8aea428b91c4f23a6bea2aae33 Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Sun, 20 Oct 2024 21:44:00 -0500 Subject: [PATCH] Fixed Outsourcing of Baby Origins Babies are now correctly born into the right faction and on the right planet. --- MekHQ/src/mekhq/campaign/Campaign.java | 55 ++++++++++--------- .../mekhq/campaign/mission/AtBContract.java | 5 +- .../personnel/marriage/AbstractMarriage.java | 2 +- .../procreation/AbstractProcreation.java | 15 ++++- 4 files changed, 45 insertions(+), 32 deletions(-) diff --git a/MekHQ/src/mekhq/campaign/Campaign.java b/MekHQ/src/mekhq/campaign/Campaign.java index ac638a50d4..7ef49db101 100644 --- a/MekHQ/src/mekhq/campaign/Campaign.java +++ b/MekHQ/src/mekhq/campaign/Campaign.java @@ -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); } /** @@ -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); @@ -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); @@ -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()); } @@ -2334,7 +2337,7 @@ public Set 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()); @@ -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); @@ -8002,7 +8005,7 @@ private String doMaintenanceOnUnitPart(Unit u, Part p, Map 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()); diff --git a/MekHQ/src/mekhq/campaign/mission/AtBContract.java b/MekHQ/src/mekhq/campaign/mission/AtBContract.java index 81eb316b13..562ca4338e 100644 --- a/MekHQ/src/mekhq/campaign/mission/AtBContract.java +++ b/MekHQ/src/mekhq/campaign/mission/AtBContract.java @@ -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; @@ -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); } } @@ -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; diff --git a/MekHQ/src/mekhq/campaign/personnel/marriage/AbstractMarriage.java b/MekHQ/src/mekhq/campaign/personnel/marriage/AbstractMarriage.java index 3f5ef99913..b2e0183c50 100644 --- a/MekHQ/src/mekhq/campaign/personnel/marriage/AbstractMarriage.java +++ b/MekHQ/src/mekhq/campaign/personnel/marriage/AbstractMarriage.java @@ -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 diff --git a/MekHQ/src/mekhq/campaign/personnel/procreation/AbstractProcreation.java b/MekHQ/src/mekhq/campaign/personnel/procreation/AbstractProcreation.java index 7d2794d92e..ec222bdc44 100644 --- a/MekHQ/src/mekhq/campaign/personnel/procreation/AbstractProcreation.java +++ b/MekHQ/src/mekhq/campaign/personnel/procreation/AbstractProcreation.java @@ -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; @@ -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); @@ -436,7 +439,15 @@ public List 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()));