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

Updated Divorce and Death Handling #4440

Merged
merged 5 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion MekHQ/resources/mekhq/resources/LogEntries.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ returnedFromMissing.text=Returned from Missing status
resurrected.text=Resurrected
rehired.text=Rehired
spouseKia.text=Spouse, {0}, was killed in action
relativeHasDied.text={0}, {1}, has died.
orphaned.text=Orphaned
promotedTo.text=Promoted to {0}
demotedTo.text=Demoted to {0}
participatedInScenarioDuringMission.text=Participated in {0} during mission {1}
Expand Down Expand Up @@ -60,6 +62,7 @@ diedFromPregnancyComplications.text=Died of complications relating to their preg
deliveredBaby.text=Delivered a healthy baby {0}!
hasConceived.text=Has conceived
divorcedFrom.text=Divorced from {0}
widowedBy.text=Widowed by {0}
marries.text=Married {0}
marriageNameChange.text=Changed {0} surname from {1} to {2} when marrying {3}
marriageNameChange.emptyMaidenName.text=nothing
Expand All @@ -71,7 +74,6 @@ spouseConceived.text=Spouse {0} has conceived
ourChildBorn.text={0} has delivered our healthy baby {1}!
removedAward.text=Removed award {0} of the award set {1}
awarded.text=Awarded {0} of the {1} award set: {2}
orphaned.text=Orphaned
eduEnrolled.text=Enrolled at {0} studying a {1} course.
eduGraduated.text=Graduated from {0} completing a {1} course.
eduGraduatedPlus.text=Graduated {0} from {1} completing a {2} course.
Expand Down
5 changes: 4 additions & 1 deletion MekHQ/resources/mekhq/resources/Personnel.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ cannotDivorce.RandomPrisoner.text=They are a prisoner, and random prisoner divor
cannotDivorce.RandomPrisonerSpouse.text=Their spouse is a prisoner, and random prisoner divorce is disabled.
cannotDivorce.OppositeSexDivorceDisabled.text=They cannot randomly divorce as they are in an opposite sex marriage and opposite sex random divorce is disabled.
cannotDivorce.SameSexDivorceDisabled.text=They cannot randomly divorce as they are in a same-sex marriage and same-sex random divorce is disabled.
divorce.report=%s has divorced %s!
divorce.report=%s has divorced %s.
widowed.report=%s has widowed %s.



Expand Down Expand Up @@ -714,3 +715,5 @@ returnedFromEducation.report=%s has returned from education or training
returnedFromMissing.report=%s has been recovered safe and sound
returnedFromAWOL.report=%s has returned from their unauthorized leave
rehired.report=%s has returned to active duty
relationParent.text=Parent
relationChild.text=Child
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ public boolean applyRetirement(Money totalPayout, Map<UUID, UUID> unitAssignment
child.changeStatus(this, getLocalDate(), PersonnelStatus.LEFT);
} else if (!child.getGenealogy().hasLivingParents()) {
addReport(child.getHyperlinkedFullTitle() + ' ' + resources.getString("orphaned.text"));
ServiceLogger.oprhaned(person, getLocalDate());
ServiceLogger.orphaned(person, getLocalDate());
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions MekHQ/src/mekhq/campaign/log/PersonalLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,28 @@
* @author Miguel Azevedo
*/
public class PersonalLogger {
private static final transient ResourceBundle resources = ResourceBundle.getBundle("mekhq.resources.LogEntries",
private static final ResourceBundle resources = ResourceBundle.getBundle("mekhq.resources.LogEntries",
MekHQ.getMHQOptions().getLocale());

public static void spouseKia(Person spouse, Person person, LocalDate date) {
String message = resources.getString("spouseKia.text");
spouse.addLogEntry(new PersonalLogEntry(date, MessageFormat.format(message, person.getFullName())));
}
public static void RelativeHasDied(Person person, Person relative, String relation, LocalDate date) {
String message = resources.getString("relativeHasDied.text");
person.addLogEntry(new PersonalLogEntry(date, MessageFormat.format(message, relation, relative.getFullName())));
}

public static void divorcedFrom(Person person, Person spouse, LocalDate date) {
String message = resources.getString("divorcedFrom.text");
person.addLogEntry(new PersonalLogEntry(date, MessageFormat.format(message, spouse.getFullName())));
}

public static void widowedBy(Person person, Person spouse, LocalDate date) {
String message = resources.getString("widowedBy.text");
person.addLogEntry(new PersonalLogEntry(date, MessageFormat.format(message, spouse.getFullName())));
}

public static void marriage(Person person, Person spouse, LocalDate date) {
String message = resources.getString("marries.text");
person.addLogEntry(new PersonalLogEntry(date, MessageFormat.format(message, spouse.getFullName())));
Expand Down Expand Up @@ -97,7 +106,7 @@ public static void spouseConceived(Person person, String spouseName, LocalDate d
String message = MessageFormat.format(resources.getString("spouseConceived.text"), spouseName);

if (sizeString != null) {
message += " " + sizeString;
message += ' ' + sizeString;
}

person.addLogEntry(new PersonalLogEntry(date, message));
Expand Down
14 changes: 9 additions & 5 deletions MekHQ/src/mekhq/campaign/log/ServiceLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @author Miguel Azevedo
*/
public class ServiceLogger {
private static final transient ResourceBundle logEntriesResourceMap = ResourceBundle.getBundle("mekhq.resources.LogEntries",
private static final ResourceBundle logEntriesResourceMap = ResourceBundle.getBundle("mekhq.resources.LogEntries",
MekHQ.getMHQOptions().getLocale());

public static void retireDueToWounds(Person person, LocalDate date) {
Expand Down Expand Up @@ -249,9 +249,13 @@ public static void removedFromTOEForce(Campaign campaign, Person person, LocalDa
}
}

public static void oprhaned(Person person, LocalDate date) {
String message = logEntriesResourceMap.getString("removedFromTOEForce.text");

person.addLogEntry(new ServiceLogEntry(date, message));
/**
* Adds a log entry to the specified {@link Person} when they become orphaned by the death of both parents.
*
* @param person The person who is becoming orphaned.
* @param date The date on which the person is becoming orphaned.
*/
public static void orphaned(Person person, LocalDate date) {
person.addLogEntry(new ServiceLogEntry(date, logEntriesResourceMap.getString("orphaned.text")));
}
}
26 changes: 24 additions & 2 deletions MekHQ/src/mekhq/campaign/personnel/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import mekhq.campaign.io.CampaignXmlParser;
import mekhq.campaign.log.LogEntry;
import mekhq.campaign.log.LogEntryFactory;
import mekhq.campaign.log.PersonalLogger;
import mekhq.campaign.log.ServiceLogger;
import mekhq.campaign.mod.am.InjuryUtil;
import mekhq.campaign.parts.Part;
Expand Down Expand Up @@ -1007,11 +1008,32 @@ public void changeStatus(final Campaign campaign, final LocalDate today,

if (status.isDead()) {
setDateOfDeath(today);
// Remember to tell the spouse
if (getGenealogy().hasSpouse() && !getGenealogy().getSpouse().getStatus().isDeadOrMIA()) {

if ((genealogy.hasSpouse()) && (!genealogy.getSpouse().getStatus().isDead())) {
campaign.getDivorce().widowed(campaign, campaign.getLocalDate(), getGenealogy().getSpouse());
}

// log death across genealogy
if (genealogy.hasChildren()) {
for (Person child : genealogy.getChildren()) {
if (!child.getStatus().isDead()) {
if (!child.getGenealogy().hasLivingParents()) {
ServiceLogger.orphaned(child, campaign.getLocalDate());
} else if (child.getGenealogy().hasLivingParents()) {
PersonalLogger.RelativeHasDied(child, this, resources.getString("relationParent.text"), campaign.getLocalDate());
}
}
}
}

if (genealogy.hasLivingParents()) {
for (Person parent : genealogy.getParents()) {
if (!parent.getStatus().isDead()) {
PersonalLogger.RelativeHasDied(parent, this, resources.getString("relationChild.text"), campaign.getLocalDate());
}
}
}

refreshLoyalty(campaign);
}

Expand Down
16 changes: 12 additions & 4 deletions MekHQ/src/mekhq/campaign/personnel/divorce/AbstractDivorce.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import mekhq.campaign.event.PersonChangedEvent;
import mekhq.campaign.log.PersonalLogger;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.personnel.enums.SplittingSurnameStyle;
import mekhq.campaign.personnel.enums.FormerSpouseReason;
import mekhq.campaign.personnel.enums.RandomDivorceMethod;
import mekhq.campaign.personnel.enums.SplittingSurnameStyle;
import mekhq.campaign.personnel.familyTree.FormerSpouse;

import java.time.LocalDate;
Expand Down Expand Up @@ -197,10 +197,18 @@ public void divorce(final Campaign campaign, final LocalDate today, final Person
reason = FormerSpouseReason.DIVORCE;

PersonalLogger.divorcedFrom(origin, spouse, today);
PersonalLogger.divorcedFrom(spouse, origin, today);

campaign.addReport(String.format(resources.getString("divorce.report"),
origin.getHyperlinkedName(), spouse.getHyperlinkedName()));
if (origin.getStatus().isDead()) {
PersonalLogger.widowedBy(spouse, origin, today);

campaign.addReport(String.format(resources.getString("widowed.report"),
origin.getHyperlinkedName(), spouse.getHyperlinkedName()));
} else {
PersonalLogger.divorcedFrom(spouse, origin, today);

campaign.addReport(String.format(resources.getString("divorce.report"),
origin.getHyperlinkedName(), spouse.getHyperlinkedName()));
}

spouse.setMaidenName(null);
origin.setMaidenName(null);
Expand Down