Skip to content

Commit 389d034

Browse files
authored
Merge pull request #6582 from IllianiBird/busyBusy
Fix #6545: Prevented Self-Crewed Unit Crew from Going on Maternity Leave Mid-Refit, Mid-Repair, or Mid-Mothballing
2 parents f88cb5d + 142a3d2 commit 389d034

File tree

2 files changed

+79
-5
lines changed

2 files changed

+79
-5
lines changed

MekHQ/src/mekhq/campaign/personnel/Person.java

+74
Original file line numberDiff line numberDiff line change
@@ -4452,6 +4452,80 @@ public boolean isMothballing() {
44524452
return isTech() && techUnits.stream().anyMatch(Unit::isMothballing);
44534453
}
44544454

4455+
/**
4456+
* Determines whether this {@code Person} is considered "busy" based on their current status, unit assignment, and
4457+
* associated tasks.
4458+
*
4459+
* <p>This method checks:</p>
4460+
* <ol>
4461+
* <li>If the personnel is active (i.e., has an active {@link PersonnelStatus}).</li>
4462+
* <li>Special cases for units that are self-crewed, including activities such as
4463+
* mothballing, refitting, or undergoing repairs, during which crew members are
4464+
* considered busy.</li>
4465+
* <li>If the personnel is a technician, by reviewing their current tech assignments,
4466+
* such as units being mothballed, refitted, or repaired.</li>
4467+
* <li>If the personnel has a unit assignment and whether that unit is currently deployed.</li>
4468+
* </ol>
4469+
*
4470+
* @return {@code true} if the person is deemed busy due to one of the above conditions; {@code false} otherwise.
4471+
*/
4472+
public boolean isBusy() {
4473+
// Personnel status
4474+
if (!status.isActive()) {
4475+
return false;
4476+
}
4477+
4478+
final boolean hasUnitAssignment = unit != null;
4479+
final Entity entity = hasUnitAssignment ? unit.getEntity() : null;
4480+
final boolean isSpecialCase = entity != null && unit.isSelfCrewed();
4481+
4482+
// Special case handlers (self crewed units have their tech teams formed as a composite of their crew, so all
4483+
// crew are considered to be busy during these states)
4484+
if (isSpecialCase) {
4485+
if (unit.isMothballing()) {
4486+
return true;
4487+
}
4488+
4489+
if (unit.isRefitting()) {
4490+
return true;
4491+
}
4492+
4493+
if (unit.isUnderRepair()) {
4494+
return true;
4495+
}
4496+
}
4497+
4498+
// Tech assignments
4499+
if (isTech()) {
4500+
for (Unit unit : techUnits) {
4501+
boolean isActiveTech = Objects.equals(unit.getRefit().getTech(), this);
4502+
4503+
if (unit.isMothballing() && isActiveTech) {
4504+
return true;
4505+
}
4506+
4507+
if (unit.isRefitting() && isActiveTech) {
4508+
return true;
4509+
}
4510+
4511+
if (unit.isUnderRepair()) {
4512+
for (Part part : unit.getParts()) {
4513+
if (Objects.equals(part.getTech(), this)) {
4514+
return true;
4515+
}
4516+
}
4517+
}
4518+
}
4519+
}
4520+
4521+
// Unit assignments
4522+
if (hasUnitAssignment) {
4523+
return unit.isDeployed();
4524+
}
4525+
4526+
return false;
4527+
}
4528+
44554529
public @Nullable Unit getUnit() {
44564530
return unit;
44574531
}

MekHQ/src/mekhq/campaign/personnel/procreation/AbstractProcreation.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public void addPregnancy(final Campaign campaign, final LocalDate today, final P
335335
* @param isNoReport true if no message should be posted to the daily report
336336
*/
337337
public void addPregnancy(final Campaign campaign, final LocalDate today, final Person mother, final int size,
338-
boolean isNoReport) {
338+
boolean isNoReport) {
339339
if (size < 1) {
340340
return;
341341
}
@@ -506,7 +506,7 @@ public void birth(final Campaign campaign, final LocalDate today, final Person m
506506
* @param father the father of the baby, null if unknown
507507
*/
508508
private static void logAndUpdateFamily(Campaign campaign, LocalDate today, Person mother, Person baby,
509-
Person father) {
509+
Person father) {
510510
if (campaign.getCampaignOptions().isLogProcreation()) {
511511
MedicalLogger.deliveredBaby(mother, baby, today);
512512
if (father != null) {
@@ -537,7 +537,7 @@ private static void logAndUpdateFamily(Campaign campaign, LocalDate today, Perso
537537
* @return the babies
538538
*/
539539
public List<Person> birthHistoric(final Campaign campaign, final LocalDate today, final Person mother,
540-
@Nullable final Person father) {
540+
@Nullable final Person father) {
541541
List<Person> babies = new ArrayList<>();
542542

543543
// Determine the number of children
@@ -668,7 +668,7 @@ public void processNewWeek(final Campaign campaign, final LocalDate today, final
668668
}
669669

670670
if (campaign.getCampaignOptions().isUseMaternityLeave()) {
671-
if (person.getStatus().isActive() && (person.getDueDate().minusWeeks(20).isBefore(today))) {
671+
if (!person.isBusy() && (person.getDueDate().minusWeeks(20).isBefore(today))) {
672672
person.changeStatus(campaign, today, PersonnelStatus.ON_MATERNITY_LEAVE);
673673
}
674674
}
@@ -690,7 +690,7 @@ public void processNewWeek(final Campaign campaign, final LocalDate today, final
690690
* @param isNoReport true, if the player shouldn't be informed, otherwise false
691691
*/
692692
public void processRandomProcreationCheck(final Campaign campaign, final LocalDate today, final Person person,
693-
boolean isNoReport) {
693+
boolean isNoReport) {
694694
if (randomlyProcreates(today, person)) {
695695
addPregnancy(campaign, today, person, isNoReport);
696696
}

0 commit comments

Comments
 (0)