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

Enhanced Random-Death Reporting #4879

Merged
merged 5 commits into from
Sep 25, 2024
Merged
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
39 changes: 24 additions & 15 deletions MekHQ/src/mekhq/campaign/personnel/death/AbstractDeath.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022 - The MegaMek Team. All Rights Reserved.
* Copyright (c) 2020-2024 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MekHQ.
*
Expand All @@ -18,18 +18,6 @@
*/
package mekhq.campaign.personnel.death;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import megamek.Version;
import megamek.common.annotations.Nullable;
import megamek.common.enums.Gender;
Expand All @@ -45,6 +33,20 @@
import mekhq.campaign.personnel.enums.RandomDeathMethod;
import mekhq.campaign.personnel.enums.TenYearAgeRange;
import mekhq.utilities.MHQXMLUtility;
import mekhq.utilities.ReportingUtilities;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

import static mekhq.utilities.ReportingUtilities.CLOSING_SPAN_TAG;

public abstract class AbstractDeath {
private static final MMLogger logger = MMLogger.create(AbstractDeath.class);
Expand Down Expand Up @@ -116,7 +118,7 @@ public Map<Gender, Map<TenYearAgeRange, WeightedDoubleMap<PersonnelStatus>>> get

/**
* This is used to determine if a person can die.
*
*
* @param person the person to determine for
* @param ageGroup the age group of the person in question
* @param randomDeath if this is for random death or manual death
Expand Down Expand Up @@ -144,7 +146,7 @@ public Map<Gender, Map<TenYearAgeRange, WeightedDoubleMap<PersonnelStatus>>> get
// region New Day
/**
* Processes new day random death for an individual.
*
*
* @param campaign the campaign to process
* @param today the current day
* @param person the person to process
Expand All @@ -158,6 +160,13 @@ public boolean processNewDay(final Campaign campaign, final LocalDate today,
}

if (randomlyDies(age, person.getGender())) {
// We double-report here, to make sure the user definitely notices that a random death has occurred.
// Prior to this change, it was exceptionally easy to miss these events.
String color = MekHQ.getMHQOptions().getFontColorNegativeHexColor();
String formatOpener = ReportingUtilities.spanOpeningWithCustomColor(color);
campaign.addReport(String.format("%s has %s<b>died</b>%s.",
person.getHyperlinkedFullTitle(), formatOpener, CLOSING_SPAN_TAG));

person.changeStatus(campaign, today, getCause(person, ageGroup, age));
return person.getStatus().isDead();
} else {
Expand Down