diff --git a/MekHQ/src/mekhq/campaign/personnel/Person.java b/MekHQ/src/mekhq/campaign/personnel/Person.java index b233c0645d..b999c89132 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); }