Skip to content

Commit

Permalink
Merge pull request #5140 from IllianiCBT/fatigue_fieldKitchenFilters
Browse files Browse the repository at this point in the history
Refactored Field Kitchen Personnel Count Logic
  • Loading branch information
HammerGS authored Oct 29, 2024
2 parents cb7a453 + 019ce1d commit f570833
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
15 changes: 9 additions & 6 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -4598,16 +4598,19 @@ private void processFatigueNewDay() {
// otherwise we would need to check it once for each active person in the
// campaign
if (campaignOptions.isUseFatigue()) {
long validPersonnel;
int personnelCount;

if (campaignOptions.isUseFieldKitchenIgnoreNonCombatants()) {
validPersonnel = getActivePersonnel().stream()
.filter(person -> person.getPrimaryRole().isCombat() || person.getSecondaryRole().isCombat())
.count();
personnelCount = (int) getActivePersonnel().stream()
.filter(person -> !(person.getPrisonerStatus().isFree() && person.getPrimaryRole().isNone()))
.filter(person -> person.getPrimaryRole().isCombat() || person.getSecondaryRole().isCombat())
.count();
} else {
validPersonnel = getActivePersonnel().size();
personnelCount = (int) getActivePersonnel().stream()
.filter(person -> !(person.getPrisonerStatus().isFree() && person.getPrimaryRole().isNone()))
.count();
}
fieldKitchenWithinCapacity = validPersonnel <= Fatigue.checkFieldKitchenCapacity(this);
fieldKitchenWithinCapacity = personnelCount <= Fatigue.checkFieldKitchenCapacity(this);
} else {
fieldKitchenWithinCapacity = false;
}
Expand Down
51 changes: 31 additions & 20 deletions MekHQ/src/mekhq/campaign/CampaignSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@
*/
package mekhq.campaign;

import static mekhq.campaign.personnel.turnoverAndRetention.RetirementDefectionTracker.getAdministrativeStrain;
import static mekhq.campaign.personnel.turnoverAndRetention.RetirementDefectionTracker.getAdministrativeStrainModifier;
import static mekhq.campaign.personnel.turnoverAndRetention.RetirementDefectionTracker.getCombinedSkillValues;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import megamek.common.Entity;
import megamek.common.Infantry;
import megamek.common.UnitType;
Expand All @@ -40,6 +30,15 @@
import mekhq.campaign.unit.CargoStatistics;
import mekhq.campaign.unit.HangarStatistics;
import mekhq.campaign.unit.Unit;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static mekhq.campaign.personnel.turnoverAndRetention.RetirementDefectionTracker.getAdministrativeStrain;
import static mekhq.campaign.personnel.turnoverAndRetention.RetirementDefectionTracker.getAdministrativeStrainModifier;
import static mekhq.campaign.personnel.turnoverAndRetention.RetirementDefectionTracker.getCombinedSkillValues;

/**
* calculates and stores summary information on a campaign for use in reporting,
Expand Down Expand Up @@ -220,7 +219,7 @@ public void updateInformation() {
/**
* A report that gives numbers of combat and support personnel as well as
* injuries
*
*
* @return a <code>String</code> of the report
*/
public String getPersonnelReport() {
Expand All @@ -230,7 +229,7 @@ public String getPersonnelReport() {

/**
* A report that gives the number of units in different damage states
*
*
* @return a <code>String</code> of the report
*/
public String getForceRepairReport() {
Expand All @@ -243,7 +242,7 @@ public String getForceRepairReport() {
/**
* A report that gives the percentage composition of the force in mek, armor,
* infantry, and aero units.
*
*
* @return a <code>String</code> of the report
*/
public String getForceCompositionReport() {
Expand All @@ -265,7 +264,7 @@ public String getForceCompositionReport() {

/**
* A report that gives the percentage of successful missions
*
*
* @return a <code>String</code> of the report
*/
public String getMissionSuccessReport() {
Expand All @@ -276,7 +275,7 @@ public String getMissionSuccessReport() {

/**
* A report that gives capacity and existing tonnage of all cargo
*
*
* @return a <code>String</code> of the report
*/
public StringBuilder getCargoCapacityReport() {
Expand Down Expand Up @@ -310,7 +309,7 @@ public StringBuilder getCargoCapacityReport() {

/**
* A report that gives information about the transportation capacity
*
*
* @return a <code>String</code> of the report
*/
public String getTransportCapacity() {
Expand Down Expand Up @@ -358,24 +357,36 @@ public String getAdministrativeCapacityReport(Campaign campaign) {
* @return A summary of fatigue related facilities.
*/
public String getFacilityReport() {
int personnelCount = campaign.getActivePersonnel().size();
CampaignOptions campaignOptions = campaign.getCampaignOptions();
int personnelCount;

if (campaignOptions.isUseFieldKitchenIgnoreNonCombatants()) {
personnelCount = (int) campaign.getActivePersonnel().stream()
.filter(person -> !(person.getPrisonerStatus().isFree() && person.getPrimaryRole().isNone()))
.filter(person -> person.getPrimaryRole().isCombat() || person.getSecondaryRole().isCombat())
.count();
} else {
personnelCount = (int) campaign.getActivePersonnel().stream()
.filter(person -> !(person.getPrisonerStatus().isFree() && person.getPrimaryRole().isNone()))
.count();
}

StringBuilder report = new StringBuilder();

if (campaign.getCampaignOptions().isUseFatigue()) {
if (campaignOptions.isUseFatigue()) {
report.append(String.format("Kitchens (%s/%s) ",
personnelCount,
Fatigue.checkFieldKitchenCapacity(campaign)));
}

if (campaign.getCampaignOptions().isUseAdvancedMedical()) {
if (campaignOptions.isUseAdvancedMedical()) {
int patients = (int) campaign.getPatients().stream()
.filter(patient -> patient.getDoctorId() != null)
.count();

int doctorCapacity = campaign.getActivePersonnel().stream()
.filter(person -> (person.getPrimaryRole().isDoctor()) || (person.getSecondaryRole().isDoctor()))
.mapToInt(person -> campaign.getCampaignOptions().getMaximumPatients())
.mapToInt(person -> campaignOptions.getMaximumPatients())
.sum();

report.append(String.format("Hospital Beds (%s/%s)",
Expand Down

0 comments on commit f570833

Please sign in to comment.