Skip to content

Commit

Permalink
Merge pull request #5228 from IllianiCBT/stratCon_adminTransport
Browse files Browse the repository at this point in the history
Added Monthly StratCon Support Points Generation
  • Loading branch information
HammerGS authored Nov 23, 2024
2 parents 5a15764 + fb0b5a8 commit 1416cbe
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
4 changes: 4 additions & 0 deletions MekHQ/resources/mekhq/resources/Campaign.properties
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ newAtBScenario.format=New scenario "{0}" will occur on {1}.
atbScenarioToday.format=Scenario "{0}" is today, deploy a force from your TOE!
atbScenarioTodayWithForce.format=Scenario "{0}" is today, {1} has been deployed!
generalFallbackAddress.text=Commander
stratConWeeklySupportPoints.text=The skill of your Admin/Transport personnel has created %s<b>%s</b>%s\
\ additional Support Points for contract %s.
stratConWeeklySupportPointsFailed.text=Your Admin/Transport personnel %s<b>failed</b>%s to create\
\ any additional Support Points for contract %s.
80 changes: 80 additions & 0 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -3793,6 +3793,10 @@ private void processNewDayATB() {
}
}

if (campaignOptions.isUseStratCon() && (currentDay.getDayOfMonth() == 1)) {
negotiateAdditionalSupportPoints();
}

processNewDayATBScenarios();

for (AtBContract contract : getActiveAtBContracts()) {
Expand All @@ -3807,6 +3811,82 @@ private void processNewDayATB() {
}
}

/**
* Handles monthly negotiation of additional support points for active AtB Contracts.
* Admin/Transport personnel skill levels and contract start dates are considered during negotiations.
* Side effects include state changes and report generation.
*/
private void negotiateAdditionalSupportPoints() {
// Fetch a list of all Admin/Transport personnel
List<Person> adminTransport = new ArrayList<>();

for (Person person : getAdmins()) {
if (person.getPrimaryRole().isAdministratorTransport()
|| person.getSecondaryRole().isAdministratorTransport()) {
adminTransport.add(person);
}
}

// Sort that list based on skill
adminTransport.sort((person1, person2) -> {
Skill person1Skill = person1.getSkill(SkillType.S_ADMIN);
int person1SkillValue = person1Skill.getLevel() + person1Skill.getBonus();

Skill person2Skill = person2.getSkill(SkillType.S_ADMIN);
int person2SkillValue = person2Skill.getLevel() + person2Skill.getBonus();

return Double.compare(person1SkillValue, person2SkillValue);
});

// Fetch a list of all active AtB Contracts and sort that list oldest -> newest
List<AtBContract> activeContracts = getActiveAtBContracts();

List<AtBContract> sortedContracts = activeContracts.stream()
.sorted(Comparator.comparing(AtBContract::getStartDate))
.toList();

// Loop through available contracts, rolling for additional Support Points until we run
// out of Admin/Transport personnel, or we run out of active contracts
for (AtBContract contract : sortedContracts) {
int negoatiatedSupportPoints = 0;
int tracks = contract.getStratconCampaignState().getTracks().size();

if (adminTransport.isEmpty()) {
break;
}

int availableAdmins = adminTransport.size();

for (int i = 0; i < availableAdmins; i++) {
Person assignedAdmin = adminTransport.get(0);
adminTransport.remove(0);

int targetNumber = assignedAdmin.getSkill(SkillType.S_ADMIN).getFinalSkillValue();
int roll = Compute.d6(2);

if (roll >= targetNumber) {
negoatiatedSupportPoints++;
}

if (negoatiatedSupportPoints >= tracks) {
break;
}
}

if (negoatiatedSupportPoints > 0) {
contract.getStratconCampaignState().addSupportPoints(negoatiatedSupportPoints);

addReport(String.format(resources.getString("stratConWeeklySupportPoints.text"),
ReportingUtilities.spanOpeningWithCustomColor(MekHQ.getMHQOptions().getFontColorPositiveHexColor()),
negoatiatedSupportPoints, CLOSING_SPAN_TAG, contract.getName()));
} else {
addReport(String.format(resources.getString("stratConWeeklySupportPointsFailed.text"),
ReportingUtilities.spanOpeningWithCustomColor(MekHQ.getMHQOptions().getFontColorNegativeHexColor()),
CLOSING_SPAN_TAG, contract.getName()));
}
}
}

/**
* Processes the new day for all personnel present in the campaign.
* <p>
Expand Down

0 comments on commit 1416cbe

Please sign in to comment.