Skip to content

Commit

Permalink
Merge pull request #4508 from IllianiCBT/autoAwards_finalThree
Browse files Browse the repository at this point in the history
Added autoAwards Support for the Final Three Awards from the Standard Set
  • Loading branch information
IllianiCBT authored Jul 31, 2024
2 parents e543654 + a74e05d commit 712fb53
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 77 deletions.
72 changes: 36 additions & 36 deletions MekHQ/data/universe/awards/standard.xml
Original file line number Diff line number Diff line change
@@ -1,37 +1,5 @@
<?xml version="1.0"?>
<awards>
<award>
<name>Manual Awards</name>
<description>Awards not tracked by the automated award eligibility tracker</description>
<item>Group</item>
</award>
<award>
<name>Drill Instructor</name>
<description>Served as basic training drill instructor.</description>
<group>Manual Awards</group>
<ribbon>4-04-5-DrillInstructor.png</ribbon>
<xp>2</xp>
<edge>1</edge>
<item>Ignore</item>
</award>
<award>
<name>Humanitarian Service</name>
<description>Defense of civilian person or structures.</description>
<group>Manual Awards</group>
<medal>HumanitarianServiceM.png</medal>
<ribbon>3-05-5-HumanitarianService.png</ribbon>
<edge>2</edge>
<item>Ignore</item>
</award>
<award>
<name>Support Person Of The Year</name>
<description>Awarded to the most outstanding non-combat member of the year.</description>
<group>Manual Awards</group>
<ribbon>3-02-8-SupportPersonOfTheYear.png</ribbon>
<xp>5</xp>
<edge>1</edge>
<item>Ignore</item>
</award>
<award>
<name>Education Awards</name>
<description>Awards earned when graduating from academies</description>
Expand Down Expand Up @@ -120,6 +88,26 @@
<qty>6</qty>
<item>Time</item>
</award>
<award>
<name>Drill Instructor</name>
<description>Served as basic training drill instructor.</description>
<group>Personal Awards</group>
<ribbon>4-04-5-DrillInstructor.png</ribbon>
<xp>2</xp>
<edge>1</edge>
<item>Misc</item>
<range>Drill Instructor</range>
</award>
<award>
<name>Support Person Of The Year</name>
<description>Awarded to the most outstanding non-combat member of the year.</description>
<group>Personal Awards</group>
<ribbon>3-02-8-SupportPersonOfTheYear.png</ribbon>
<xp>5</xp>
<edge>1</edge>
<item>Misc</item>
<range>Support Person of the Year</range>
</award>
<award>
<name>Prisoner of War</name>
<description>Taken prisoner during combat.</description>
Expand All @@ -141,9 +129,10 @@
<xp>10</xp>
<edge>3</edge>
<stackable>true</stackable>
<item>Medal Of Honor</item>
<size>20</size>
<range>5</range>
<qty>5</qty>
<item>Misc</item>
<size>10</size>
<range>Medal Of Honor</range>
</award>
<award>
<name>Scenario Awards</name>
Expand Down Expand Up @@ -209,6 +198,16 @@
<size>Individual</size>
<range>Scenario</range>
</award>
<award>
<name>Humanitarian Service</name>
<description>Defense of civilian person or structures.</description>
<group>Scenario Awards</group>
<medal>HumanitarianServiceM.png</medal>
<ribbon>3-05-5-HumanitarianService.png</ribbon>
<edge>2</edge>
<item>Misc</item>
<range>Civilian Help</range>
</award>
<award>
<name>Mission Awards</name>
<description>Awards earned during a Mission or Contract</description>
Expand Down Expand Up @@ -280,7 +279,8 @@
<group>Mission Awards</group>
<ribbon>4-05-1-CeremonialDuty.png</ribbon>
<xp>1</xp>
<item>Ceremonial Duty</item>
<item>Misc</item>
<range>Ceremonial Duty</range>
</award>
<award>
<name>Galactic War on Pirating</name>
Expand Down
Binary file modified MekHQ/docs/Personnel Modules/Awards Module.pdf
Binary file not shown.
2 changes: 2 additions & 0 deletions MekHQ/resources/mekhq/resources/AutoAwardsDialog.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ btnSelectAll.text=Select All
btnDone.text=Issue Awards
btnSkip.text=Skip
btnSkipAll.text=Skip All

supportPersonOfTheYear.text=%s has been chosen for the %s award from the %s set. Unfortunately, they have been awarded this award previously and are not eligible to receive it again. Your command staff feel you should nominate someone manually.
8 changes: 7 additions & 1 deletion MekHQ/src/mekhq/MekHQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,14 @@ public void gameVictory(GameVictoryEvent gve) {
scenarioKills.put(personId, tracker.getPeopleStatus().get(personId).getKills());
}

boolean isCivilianHelp = false;

if (tracker.getScenario() instanceof AtBScenario) {
isCivilianHelp = ((AtBScenario) tracker.getScenario()).getScenarioType() == AtBScenario.CIVILIANHELP;
}

AutoAwardsController autoAwardsController = new AutoAwardsController();
autoAwardsController.PostScenarioController(getCampaign(), personnel, scenarioKills);
autoAwardsController.PostScenarioController(getCampaign(), personnel, scenarioKills, isCivilianHelp);
}

for (UUID personId : tracker.getPeopleStatus().keySet()) {
Expand Down
21 changes: 21 additions & 0 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -3489,6 +3489,27 @@ public void processNewDayPersonnel() {
18));
}
}

// autoAwards
if (getLocalDate().getDayOfMonth() == 1) {
double multiplier = 0;

int score = 0;

if (p.getPrimaryRole().isSupport(true)) {
score = Compute.d6(p.getExperienceLevel(this, false));
multiplier += 0.5;
}

if (p.getSecondaryRole().isSupport(true)) {
score += Compute.d6(p.getExperienceLevel(this, false));
multiplier += 0.5;
} else if (p.getSecondaryRole().isNone()) {
multiplier += 0.5;
}

p.changeAutoAwardSupportPoints((int) (score * multiplier));
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions MekHQ/src/mekhq/campaign/personnel/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ public class Person {
private List<LogEntry> personnelLog;
private List<LogEntry> scenarioLog;

// this is used by autoAwards to abstract the support person of the year award
private int autoAwardSupportPoints;

private LocalDate retirement;
private int loyalty;
private int fatigue;
Expand Down Expand Up @@ -344,6 +347,7 @@ public Person(final String preNominal, final String givenName, final String surn
dateOfDeath = null;
recruitment = null;
lastRankChangeDate = null;
autoAwardSupportPoints = 0;
retirement = null;
loyalty = 9;
fatigue = 0;
Expand Down Expand Up @@ -1352,6 +1356,20 @@ public Genealogy getGenealogy() {
return genealogy;
}

//region autoAwards
public int getAutoAwardSupportPoints() {
return autoAwardSupportPoints;
}

public void setAutoAwardSupportPoints(final int autoAwardSupportPoints) {
this.autoAwardSupportPoints = autoAwardSupportPoints;
}

public void changeAutoAwardSupportPoints(int change) {
autoAwardSupportPoints += change;
}
//endregion autoAwards

//region Turnover and Retention
public @Nullable LocalDate getRetirement() {
return retirement;
Expand Down Expand Up @@ -1889,6 +1907,7 @@ public void writeToXML(final PrintWriter pw, int indent, final Campaign campaign
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "deathday", getDateOfDeath());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "recruitment", getRecruitment());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "lastRankChangeDate", getLastRankChangeDate());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "autoAwardSupportPoints", getAutoAwardSupportPoints());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "retirement", getRetirement());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "loyalty", getLoyalty());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "fatigue", getFatigue());
Expand Down Expand Up @@ -2224,6 +2243,8 @@ public static Person generateInstanceFromXML(Node wn, Campaign c, Version versio
retVal.recruitment = MHQXMLUtility.parseDate(wn2.getTextContent().trim());
} else if (wn2.getNodeName().equalsIgnoreCase("lastRankChangeDate")) {
retVal.lastRankChangeDate = MHQXMLUtility.parseDate(wn2.getTextContent().trim());
} else if (wn2.getNodeName().equalsIgnoreCase("autoAwardSupportPoints")) {
retVal.setAutoAwardSupportPoints(Integer.parseInt(wn2.getTextContent().trim()));
} else if (wn2.getNodeName().equalsIgnoreCase("retirement")) {
retVal.setRetirement(MHQXMLUtility.parseDate(wn2.getTextContent().trim()));
} else if (wn2.getNodeName().equalsIgnoreCase("loyalty")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ public void PostMissionController(Campaign c, Mission m, Boolean missionWasSucce
* @param c the campaign
* @param personnel the personnel involved in the scenario, mapped by their UUID
* @param scenarioKills the kills made during the scenario, mapped by personnel UUID
* @param wasCivilianHelp whether the scenario (if any) was AtB Scenario CIVILIANHELP
*/
public void PostScenarioController(Campaign c, HashMap<UUID, Integer> personnel, HashMap<UUID, List<Kill>>scenarioKills) {
public void PostScenarioController(Campaign c, HashMap<UUID, Integer> personnel, HashMap<UUID, List<Kill>>scenarioKills, boolean wasCivilianHelp) {
LogManager.getLogger().info("autoAwards (Scenario Conclusion) has started");

campaign = c;
Expand Down Expand Up @@ -184,7 +185,7 @@ public void PostScenarioController(Campaign c, HashMap<UUID, Integer> personnel,

// beginning the processing & filtering of Misc Awards
if (!miscAwards.isEmpty()) {
processedData = MiscAwardsManager(personnel, false, true, scenarioKills);
processedData = MiscAwardsManager(personnel, false, true, wasCivilianHelp, scenarioKills);

if (processedData != null) {
allAwardData.put(allAwardDataKey, processedData);
Expand Down Expand Up @@ -621,7 +622,7 @@ private void ProcessAwards(List<UUID> personnel, Boolean missionWasSuccessful, @
personnelMap.put(person, 0);
}

processedData = MiscAwardsManager(personnelMap, missionWasSuccessful, false, null);
processedData = MiscAwardsManager(personnelMap, missionWasSuccessful, false, false, null);

if (processedData != null) {
allAwardData.put(allAwardDataKey, processedData);
Expand Down Expand Up @@ -891,14 +892,41 @@ private Map<Integer, List<Object>> ScenarioKillAwardsManager(List<UUID> personne
*
* @param personnel the personnel to be processed
* @param missionWasSuccessful true if the mission was successful, false otherwise
* @param wasCivilianHelp true if the scenario (if relevant) was AtB Scenario type CIVILIANHELP
* @param wasScenario true if the award is for a scenario, false otherwise
* @param scenarioKills a map of personnel and their corresponding list of Kills
* @return a map containing the award data, or null if no awards are applicable
*/
private Map<Integer, List<Object>> MiscAwardsManager(HashMap<UUID, Integer> personnel, boolean missionWasSuccessful, boolean wasScenario, HashMap<UUID, List<Kill>> scenarioKills) {
private Map<Integer, List<Object>> MiscAwardsManager(HashMap<UUID, Integer> personnel, boolean missionWasSuccessful, boolean wasScenario,
boolean wasCivilianHelp, HashMap<UUID, List<Kill>> scenarioKills) {
Map<Integer, List<Object>> awardData = new HashMap<>();
int awardDataKey = 0;

UUID supportPersonOfTheYear = null;

if (campaign.getLocalDate().getDayOfYear() == 1) {
int supportPoints = 0;


// we duplicate and shuffle the list to avoid giving personnel advantage based on name
List<UUID> temporaryPersonnelList = new ArrayList<>(personnel.keySet());
Collections.shuffle(temporaryPersonnelList);

// we do everybody here, as we want to capture personnel who were support personnel,
// even if they're not current support personnel
for (UUID person : temporaryPersonnelList) {
Person p = campaign.getPerson(person);

if (p.getAutoAwardSupportPoints() > supportPoints) {
supportPersonOfTheYear = person;
supportPoints = p.getAutoAwardSupportPoints();
}

// we reset them for next year
p.setAutoAwardSupportPoints(0);
}
}

for (UUID person : personnel.keySet()) {
Map<Integer, List<Object>> data;

Expand All @@ -913,7 +941,17 @@ private Map<Integer, List<Object>> MiscAwardsManager(HashMap<UUID, Integer> pers
}

try {
data = MiscAwards.MiscAwardsProcessor(campaign, mission, person, miscAwards, missionWasSuccessful, personalKills.size(), personnel.get(person));
data = MiscAwards.MiscAwardsProcessor(
campaign,
mission,
person,
miscAwards,
missionWasSuccessful,
wasCivilianHelp,
personalKills.size(),
personnel.get(person),
supportPersonOfTheYear
);
} catch (Exception e) {
data = null;
LogManager.getLogger().info("{} is not eligible for any Misc Awards.", campaign.getPerson(person).getFullName());
Expand Down
Loading

0 comments on commit 712fb53

Please sign in to comment.