Skip to content

Commit 1913d87

Browse files
committed
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).
1 parent 7193b9a commit 1913d87

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
@@ -4423,6 +4423,80 @@ public boolean isMothballing() {
44234423
return isTech() && techUnits.stream().anyMatch(Unit::isMothballing);
44244424
}
44254425

4426+
/**
4427+
* Determines whether this {@code Person} is considered "busy" based on their current status, unit assignment, and
4428+
* associated tasks.
4429+
*
4430+
* <p>This method checks:</p>
4431+
* <ol>
4432+
* <li>If the personnel is active (i.e., has an active {@link PersonnelStatus}).</li>
4433+
* <li>Special cases for units that are self-crewed, including activities such as
4434+
* mothballing, refitting, or undergoing repairs, during which crew members are
4435+
* considered busy.</li>
4436+
* <li>If the personnel is a technician, by reviewing their current tech assignments,
4437+
* such as units being mothballed, refitted, or repaired.</li>
4438+
* <li>If the personnel has a unit assignment and whether that unit is currently deployed.</li>
4439+
* </li>
4440+
*
4441+
* @return {@code true} if the person is deemed busy due to one of the above conditions; {@code false} otherwise.
4442+
*/
4443+
public boolean isBusy() {
4444+
// Personnel status
4445+
if (!status.isActive()) {
4446+
return false;
4447+
}
4448+
4449+
final boolean hasUnitAssignment = unit != null;
4450+
final Entity entity = hasUnitAssignment ? unit.getEntity() : null;
4451+
final boolean isSpecialCase = entity != null && unit.isSelfCrewed();
4452+
4453+
// Special case handlers (self crewed units have their tech teams formed as a composite of their crew, so all
4454+
// crew are considered to be busy during these states)
4455+
if (isSpecialCase) {
4456+
if (unit.isMothballing()) {
4457+
return true;
4458+
}
4459+
4460+
if (unit.isRefitting()) {
4461+
return true;
4462+
}
4463+
4464+
if (unit.isUnderRepair()) {
4465+
return true;
4466+
}
4467+
}
4468+
4469+
// Tech assignments
4470+
if (isTech()) {
4471+
for (Unit unit : techUnits) {
4472+
boolean isActiveTech = Objects.equals(unit.getRefit().getTech(), this);
4473+
4474+
if (unit.isMothballing() && isActiveTech) {
4475+
return true;
4476+
}
4477+
4478+
if (unit.isRefitting() && isActiveTech) {
4479+
return true;
4480+
}
4481+
4482+
if (unit.isUnderRepair()) {
4483+
for (Part part : unit.getParts()) {
4484+
if (Objects.equals(part.getTech(), this)) {
4485+
return true;
4486+
}
4487+
}
4488+
}
4489+
}
4490+
}
4491+
4492+
// Unit assignments
4493+
if (hasUnitAssignment) {
4494+
return unit.isDeployed();
4495+
}
4496+
4497+
return false;
4498+
}
4499+
44264500
public @Nullable Unit getUnit() {
44274501
return unit;
44284502
}

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)