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

Refactored Kill Count and Personnel Filtering Methods #4409

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -194,42 +194,38 @@ public void PostGraduationController(Campaign c, List<UUID> personnel, HashMap<U
* Builds a list of personnel autoAwards should process
*/
private List<UUID> getPersonnel() {
List<UUID> personnel = campaign.getActivePersonnel()
boolean issuePosthumous = campaign.getCampaignOptions().isIssuePosthumousAwards();

List<UUID> personnel = campaign.getPersonnel()
.stream()
.filter(person ->
((!person.getStatus().isDepartedUnit()) && (!person.getPrisonerStatus().isCurrentPrisoner()) && (!person.hasRole(PersonnelRole.DEPENDENT)))
|| ((issuePosthumous) && (person.getStatus().isDead()) && (filterOutPersonnel(person)))
)
.map(Person::getId)
.collect(Collectors.toList());

// if posthumous Awards are enabled, we add the relevant dead people
if (campaign.getCampaignOptions().isIssuePosthumousAwards()) {
List<UUID> deadPeople = campaign.getPersonnel()
.stream().filter(person -> person.getStatus().isDead())
.map(Person::getId)
.collect(Collectors.toList());

LogManager.getLogger().info("deadPeople {}", deadPeople);

if (!deadPeople.isEmpty()) {
personnel.addAll(deadPeople);
}
}
LogManager.getLogger().debug("Personnel {}", personnel);

// Prisoners and Dependents are not eligible for Awards
if (!personnel.isEmpty()) {
removeDependentsAndPrisoners(personnel);
}
return personnel;
}

/**
* Filters out anyone with the Prisoner status, or Dependent role
* Filters out personnel based on specific criteria.
*
* @param personnel personnel to process
* @param person the person to be filtered
* @return true if the person should be filtered out, false otherwise
*/
private void removeDependentsAndPrisoners(List<UUID> personnel) {
if (!personnel.isEmpty()) {
personnel.removeIf(person -> (campaign.getPerson(person).hasRole(PersonnelRole.DEPENDENT))
|| (campaign.getPerson(person).getPrisonerStatus().isCurrentPrisoner()));
}
private boolean filterOutPersonnel(Person person) {
return !((person.getPrisonerStatus().isCurrentPrisoner()) || (person.hasRole(PersonnelRole.DEPENDENT)))
&&
!((person.getStatus().isRetired())
|| (person.getStatus().isResigned())
|| (person.getStatus().isSacked())
|| (person.getStatus().isDeserted())
|| (person.getStatus().isDefected())
|| (person.getStatus().isMissing())
|| (person.getStatus().isLeft()));
}

/**
Expand Down
57 changes: 21 additions & 36 deletions MekHQ/src/mekhq/campaign/personnel/autoAwards/KillAwards.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,40 +297,21 @@ public static Map<Integer, List<Object>> KillAwardProcessor(Campaign campaign, M
* @return the formation depth or -1 if an invalid size is provided or if the formation kill awards are disabled
*/
private static int getFormation(Campaign campaign, Award award){
int formationDepth;

switch (award.getSize().toLowerCase()) {
case "individual":
formationDepth = 0;
break;
case "lance":
formationDepth = 1;
break;
case "company":
formationDepth = 2;
break;
case "battalion":
formationDepth = 3;
break;
case "regiment":
formationDepth = 4;
break;
case "brigade":
formationDepth = 5;
break;
case "division":
formationDepth = 6;
break;
case "corps":
formationDepth = 7;
break;
case "army":
formationDepth = 8;
break;
default:
int formationDepth = switch (award.getSize().toLowerCase()) {
case "individual" -> 0;
case "lance" -> 1;
case "company" -> 2;
case "battalion" -> 3;
case "regiment" -> 4;
case "brigade" -> 5;
case "division" -> 6;
case "corps" -> 7;
case "army" -> 8;
default -> {
LogManager.getLogger().warn("Award {} from the {} set has invalid size value {}", award.getName(), award.getSet(), award.getSize());
formationDepth = -1;
}
yield -1;
}
};

switch (formationDepth) {
case -1:
Expand Down Expand Up @@ -405,7 +386,7 @@ private static int getForceKills(Campaign campaign, Mission mission, int forceId
* @param commander the unit commander whose kills are being counted
* @param filterOtherMissionKills true, if we should only count kills from the mission just completed
*/
private static int getIndividualKills(Campaign campaign, Mission mission, UUID commander, boolean filterOtherMissionKills){
private static int getIndividualKills(Campaign campaign, Mission mission, UUID commander, boolean filterOtherMissionKills) {
List<Kill> allKills;

try {
Expand All @@ -414,10 +395,14 @@ private static int getIndividualKills(Campaign campaign, Mission mission, UUID c
return 0;
}

long count = 0;

if (filterOtherMissionKills) {
allKills.removeIf(kill -> kill.getMissionId() != mission.getId());
count = allKills.stream()
.filter(kill -> kill.getMissionId() == mission.getId())
.count();
}

return allKills.size();
return (int) count;
}
}