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 TotalGenericBattleValue Tag to MUL Export #5070

Merged
merged 1 commit into from
Oct 21, 2024
Merged
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
28 changes: 26 additions & 2 deletions MekHQ/src/mekhq/gui/BriefingTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -1146,10 +1146,13 @@ private void deployListFile() {
chosen.clear();
chosen.addAll(((AtBScenario) scenario).getAlliesPlayer());
file = determineMULFilePath(scenario, ((AtBContract) mission).getEmployer());

int genericBattleValue = calculateGenericBattleValue(chosen);

if (file != null) {
try {
// Save the player's allied entities to the file.
EntityListFile.saveTo(file, chosen);
EntityListFile.saveTo(file, chosen, genericBattleValue);
} catch (Exception ex) {
logger.error("", ex);
}
Expand All @@ -1164,17 +1167,38 @@ private void deployListFile() {
continue;
}
file = determineMULFilePath(scenario, botForce.getName());

int genericBattleValue = calculateGenericBattleValue(chosen);

if (file != null) {
try {
// Save the bot force's entities to the file.
EntityListFile.saveTo(file, chosen);
EntityListFile.saveTo(file, chosen, genericBattleValue);
} catch (Exception ex) {
logger.error("", ex);
}
}
}
}

/**
* Calculates the total generic battle value of the entities chosen.
* If the use of generic battle value option is enabled in the campaign options, the generic battle
* value of each entity in the list is summed up and returned as the total generic battle value.
* If the said option is disabled, the method returns 0.
*
* @param chosen the list of entities for which the generic battle value is to be calculated.
* @return the total generic battle value or 0 if the generic battle value usage is turned off in
* campaign options.
*/
private int calculateGenericBattleValue(ArrayList<Entity> chosen) {
int genericBattleValue = 0;
if (getCampaign().getCampaignOptions().isUseGenericBattleValue()) {
genericBattleValue = chosen.stream().mapToInt(Entity::getGenericBattleValue).sum();
}
return genericBattleValue;
}

private @Nullable File determineMULFilePath(final Scenario scenario, final String name) {
final Optional<File> maybeUnitFile = FileDialogs.saveDeployUnits(getFrame(), scenario, name);
if (maybeUnitFile.isEmpty()) {
Expand Down