Skip to content

Commit

Permalink
Added detailed logging for force generation processes.
Browse files Browse the repository at this point in the history
Improved the logging by adding informative messages in the force generation process. This includes notifying force generation for specific templates, effective BV budgeting, and unit budget adjustments. These changes enhance the traceability and debugging capabilities during scenario generation.
  • Loading branch information
IllianiCBT committed Dec 2, 2024
1 parent 0ffc067 commit 64a7499
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
31 changes: 21 additions & 10 deletions MekHQ/src/mekhq/campaign/mission/AtBDynamicScenarioFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,13 @@ private static int generateForces(AtBDynamicScenario scenario, AtBContract contr
effectiveUnitCount = calculateEffectiveUnitCount(scenario, campaign, false);

for (ScenarioForceTemplate forceTemplate : currentForceTemplates) {
logger.info(String.format("++ Generating a force for the %s template ++",
forceTemplate.getForceName()).toUpperCase());

if (forceTemplate.getGenerationMethod() == ForceGenerationMethod.FixedMUL.ordinal()) {
generatedLanceCount += generateFixedForce(scenario, contract, campaign, forceTemplate);
} else {
int weightClass = randomForceWeight();
logger.info(String.format("++ Generating a force for the %s template ++", forceTemplate.getForceName()).toUpperCase());

generatedLanceCount += generateForce(scenario, contract, campaign,
effectiveBV, effectiveUnitCount, weightClass, forceTemplate, false);
}
Expand Down Expand Up @@ -398,6 +399,10 @@ public static int generateForce(AtBDynamicScenario scenario, AtBContract contrac
effectiveBV = (int) round(effectiveBV * difficultyMultiplier);
effectiveUnitCount = (int) round(effectiveUnitCount * difficultyMultiplier);

if (forceTemplate.getGenerationMethod() == ForceGenerationMethod.BVScaled.ordinal()) {
logger.info(String.format("Effective xBV Budget: %s (adjusted for difficulty)",
effectiveBV));
}
// Intentional fall-through: opposing third parties are either the contracted
// enemy or "Unidentified Hostiles" which are considered pirates or bandit caste
// with random quality and skill
Expand Down Expand Up @@ -445,12 +450,15 @@ public static int generateForce(AtBDynamicScenario scenario, AtBContract contrac
int forceBV = 0;
double forceMultiplier = forceTemplate.getForceMultiplier();

if (forceMultiplier == 0) {
forceMultiplier = 1;
}
if (forceTemplate.getGenerationMethod() == ForceGenerationMethod.BVScaled.ordinal()
|| forceTemplate.getGenerationMethod() == ForceGenerationMethod.UnitCountScaled.ordinal()) {
// This means force multiplier wasn't initialized in the template
if (forceMultiplier == 0) {
forceMultiplier = 1;
logger.warn(String.format("Force multiplier is zero for %s", forceTemplate.getForceName()));
}

if (forceMultiplier != 1) {
logger.info(String.format("Force BV Multiplier: %s (from scenario template)", forceMultiplier));
logger.info(String.format("Force Multiplier: %s (from scenario template)", forceMultiplier));
}

int forceBVBudget = (int) (effectiveBV * forceMultiplier);
Expand All @@ -459,15 +467,18 @@ public static int generateForce(AtBDynamicScenario scenario, AtBContract contrac
forceBVBudget = (int) (forceBVBudget * ((double) campaign.getCampaignOptions().getScenarioModBV() / 100));
}

if (forceTemplate.getForceMultiplier() != 1) {
logger.info(String.format("BV Budget was %s, now %s (includes Modifier settings and Multiplier)",
if (forceTemplate.getForceMultiplier() != 1 && forceTemplate.getGenerationMethod() == ForceGenerationMethod.BVScaled.ordinal()) {
logger.info(String.format("BV Budget was %s, now %s",
effectiveBV, forceBVBudget));
}

int forceUnitBudget = 0;

if (forceTemplate.getGenerationMethod() == ForceGenerationMethod.UnitCountScaled.ordinal()) {
forceUnitBudget = (int) (effectiveUnitCount * forceTemplate.getForceMultiplier());

logger.info(String.format("Unit Budget was %s, now %s",
effectiveUnitCount, forceUnitBudget));
} else if ((forceTemplate.getGenerationMethod() == ForceGenerationMethod.FixedUnitCount.ordinal())
|| (forceTemplate.getGenerationMethod() == ForceGenerationMethod.PlayerOrFixedUnitCount.ordinal())) {
forceUnitBudget = forceTemplate.getFixedUnitCount() == ScenarioForceTemplate.FIXED_UNIT_SIZE_LANCE ? lanceSize : forceTemplate.getFixedUnitCount();
Expand Down Expand Up @@ -2957,7 +2968,7 @@ public static int calculateEffectiveBV(AtBDynamicScenario scenario, Campaign cam
}
}

logger.info(String.format("Total Base %s Budget: %s (adjusted for campaign difficulty)",
logger.info(String.format("Total Base %s Budget: %s (may be adjusted by Effective Player BV Multiplier)",
generationMethod, bvBudget));

return bvBudget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ private static void postAddForce(Campaign campaign, AtBDynamicScenario scenario,

int weightClass = randomForceWeight();

logger.info(String.format("++ Generating a force for the %s template ++",
templateToApply.getForceName()).toUpperCase());

generateForce(scenario, scenario.getContract(campaign), campaign, effectiveBV,
effectiveUnitCount, weightClass, templateToApply, true);

Expand Down

0 comments on commit 64a7499

Please sign in to comment.