From 1913d87c6d6a4f351395f88e7cee82608316c52f Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Mon, 7 Apr 2025 13:34:54 -0500 Subject: [PATCH 1/2] Prevented Self-Crewed Unit Crew from Going on Maternity Leave Mid-Refit, Mid-Repair, or Mid-Mothballing - Replaced `isActive` check with the new `isBusy` method in maternity leave eligibility logic. - Added `isBusy` method in `Person` class to determine personnel activity based on status, unit assignments, and tasks. - Includes checks for self-crewed units, technicians, unit deployments, and various task states (mothballing, refitting, repairing). --- .../src/mekhq/campaign/personnel/Person.java | 74 +++++++++++++++++++ .../procreation/AbstractProcreation.java | 10 +-- 2 files changed, 79 insertions(+), 5 deletions(-) diff --git a/MekHQ/src/mekhq/campaign/personnel/Person.java b/MekHQ/src/mekhq/campaign/personnel/Person.java index b233c0645d..24b7ade2c5 100644 --- a/MekHQ/src/mekhq/campaign/personnel/Person.java +++ b/MekHQ/src/mekhq/campaign/personnel/Person.java @@ -4423,6 +4423,80 @@ public boolean isMothballing() { return isTech() && techUnits.stream().anyMatch(Unit::isMothballing); } + /** + * Determines whether this {@code Person} is considered "busy" based on their current status, unit assignment, and + * associated tasks. + * + *

This method checks:

+ *
    + *
  1. If the personnel is active (i.e., has an active {@link PersonnelStatus}).
  2. + *
  3. Special cases for units that are self-crewed, including activities such as + * mothballing, refitting, or undergoing repairs, during which crew members are + * considered busy.
  4. + *
  5. If the personnel is a technician, by reviewing their current tech assignments, + * such as units being mothballed, refitted, or repaired.
  6. + *
  7. If the personnel has a unit assignment and whether that unit is currently deployed.
  8. + * + * + * @return {@code true} if the person is deemed busy due to one of the above conditions; {@code false} otherwise. + */ + public boolean isBusy() { + // Personnel status + if (!status.isActive()) { + return false; + } + + final boolean hasUnitAssignment = unit != null; + final Entity entity = hasUnitAssignment ? unit.getEntity() : null; + final boolean isSpecialCase = entity != null && unit.isSelfCrewed(); + + // Special case handlers (self crewed units have their tech teams formed as a composite of their crew, so all + // crew are considered to be busy during these states) + if (isSpecialCase) { + if (unit.isMothballing()) { + return true; + } + + if (unit.isRefitting()) { + return true; + } + + if (unit.isUnderRepair()) { + return true; + } + } + + // Tech assignments + if (isTech()) { + for (Unit unit : techUnits) { + boolean isActiveTech = Objects.equals(unit.getRefit().getTech(), this); + + if (unit.isMothballing() && isActiveTech) { + return true; + } + + if (unit.isRefitting() && isActiveTech) { + return true; + } + + if (unit.isUnderRepair()) { + for (Part part : unit.getParts()) { + if (Objects.equals(part.getTech(), this)) { + return true; + } + } + } + } + } + + // Unit assignments + if (hasUnitAssignment) { + return unit.isDeployed(); + } + + return false; + } + public @Nullable Unit getUnit() { return unit; } diff --git a/MekHQ/src/mekhq/campaign/personnel/procreation/AbstractProcreation.java b/MekHQ/src/mekhq/campaign/personnel/procreation/AbstractProcreation.java index 02aa592646..eecc4809de 100644 --- a/MekHQ/src/mekhq/campaign/personnel/procreation/AbstractProcreation.java +++ b/MekHQ/src/mekhq/campaign/personnel/procreation/AbstractProcreation.java @@ -335,7 +335,7 @@ public void addPregnancy(final Campaign campaign, final LocalDate today, final P * @param isNoReport true if no message should be posted to the daily report */ public void addPregnancy(final Campaign campaign, final LocalDate today, final Person mother, final int size, - boolean isNoReport) { + boolean isNoReport) { if (size < 1) { return; } @@ -506,7 +506,7 @@ public void birth(final Campaign campaign, final LocalDate today, final Person m * @param father the father of the baby, null if unknown */ private static void logAndUpdateFamily(Campaign campaign, LocalDate today, Person mother, Person baby, - Person father) { + Person father) { if (campaign.getCampaignOptions().isLogProcreation()) { MedicalLogger.deliveredBaby(mother, baby, today); if (father != null) { @@ -537,7 +537,7 @@ private static void logAndUpdateFamily(Campaign campaign, LocalDate today, Perso * @return the babies */ public List birthHistoric(final Campaign campaign, final LocalDate today, final Person mother, - @Nullable final Person father) { + @Nullable final Person father) { List babies = new ArrayList<>(); // Determine the number of children @@ -668,7 +668,7 @@ public void processNewWeek(final Campaign campaign, final LocalDate today, final } if (campaign.getCampaignOptions().isUseMaternityLeave()) { - if (person.getStatus().isActive() && (person.getDueDate().minusWeeks(20).isBefore(today))) { + if (!person.isBusy() && (person.getDueDate().minusWeeks(20).isBefore(today))) { person.changeStatus(campaign, today, PersonnelStatus.ON_MATERNITY_LEAVE); } } @@ -690,7 +690,7 @@ public void processNewWeek(final Campaign campaign, final LocalDate today, final * @param isNoReport true, if the player shouldn't be informed, otherwise false */ public void processRandomProcreationCheck(final Campaign campaign, final LocalDate today, final Person person, - boolean isNoReport) { + boolean isNoReport) { if (randomlyProcreates(today, person)) { addPregnancy(campaign, today, person, isNoReport); } From 142a3d21dcc91e7bc42719c2d6a6e4cedb294489 Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Mon, 7 Apr 2025 14:33:44 -0500 Subject: [PATCH 2/2] - Corrected an invalid closing `
  9. ` tag to `
      ` in the Javadoc of the `isBusy` method in `Person.java`. --- MekHQ/src/mekhq/campaign/personnel/Person.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MekHQ/src/mekhq/campaign/personnel/Person.java b/MekHQ/src/mekhq/campaign/personnel/Person.java index 24b7ade2c5..b999c89132 100644 --- a/MekHQ/src/mekhq/campaign/personnel/Person.java +++ b/MekHQ/src/mekhq/campaign/personnel/Person.java @@ -4436,7 +4436,7 @@ public boolean isMothballing() { *
    1. If the personnel is a technician, by reviewing their current tech assignments, * such as units being mothballed, refitted, or repaired.
    2. *
    3. If the personnel has a unit assignment and whether that unit is currently deployed.
    4. - * + *
    * * @return {@code true} if the person is deemed busy due to one of the above conditions; {@code false} otherwise. */