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

Added Monthly StratCon Support Points Generation #5228

Merged
merged 1 commit into from
Nov 23, 2024
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
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