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

Fix #6545: Prevented Self-Crewed Unit Crew from Going on Maternity Leave Mid-Refit, Mid-Repair, or Mid-Mothballing #6582

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
74 changes: 74 additions & 0 deletions MekHQ/src/mekhq/campaign/personnel/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>This method checks:</p>
* <ol>
* <li>If the personnel is active (i.e., has an active {@link PersonnelStatus}).</li>
* <li>Special cases for units that are self-crewed, including activities such as
* mothballing, refitting, or undergoing repairs, during which crew members are
* considered busy.</li>
* <li>If the personnel is a technician, by reviewing their current tech assignments,
* such as units being mothballed, refitted, or repaired.</li>
* <li>If the personnel has a unit assignment and whether that unit is currently deployed.</li>
* </ol>
*
* @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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -537,7 +537,7 @@ private static void logAndUpdateFamily(Campaign campaign, LocalDate today, Perso
* @return the babies
*/
public List<Person> birthHistoric(final Campaign campaign, final LocalDate today, final Person mother,
@Nullable final Person father) {
@Nullable final Person father) {
List<Person> babies = new ArrayList<>();

// Determine the number of children
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
Expand Down
Loading