Skip to content

Commit

Permalink
Update StratCon scenario generation to handle deployment delays
Browse files Browse the repository at this point in the history
Modified `generateScenario` to include an optional `daysTilDeployment` parameter, allowing scenarios to account for deployment delays. Improved documentation to clarify functionality and integration with the campaign and StratCon tracks.
  • Loading branch information
IllianiCBT committed Dec 21, 2024
1 parent 5f28335 commit a01b3fe
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions MekHQ/src/mekhq/campaign/stratcon/StratconRulesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ public static void deployForceToCoords(StratconCoords coords, int forceID, Campa
if (template != null) {
scenario = generateScenario(campaign, contract, track, forceID, coords, template, daysTilDeployment);
} else {
scenario = generateScenario(campaign, contract, track, forceID, coords);
scenario = generateScenario(campaign, contract, track, forceID, coords, daysTilDeployment);
}

if (scenario == null) {
Expand Down Expand Up @@ -1602,20 +1602,34 @@ private static Map<MapLocation, List<Integer>> sortForcesByMapType(List<Integer>
}

/**
* Worker function that generates stratcon scenario at the given coords, for the
* given force, on the
* given track. Also registers it with the track and campaign.
* Generates a StratCon scenario at the specified coordinates for the given force on the specified track.
* The scenario is determined based on a random template suitable for the unit type of the specified force,
* and it is optionally configured with a deployment delay.
*
* <p>This method selects a random scenario template based on the primary unit type of the force,
* then delegates the scenario creation and configuration to another overloaded {@code generateScenario} method
* which handles specific template-based scenario generation.</p>
*
* @param campaign the {@link Campaign} managing the overall gameplay state
* @param contract the {@link AtBContract} governing the StratCon campaign
* @param track the {@link StratconTrackState} where the scenario is placed
* @param forceID the ID of the force for which the scenario is generated
* @param coords the {@link StratconCoords} specifying where the scenario will be generated
* @param daysTilDeployment the number of days until the scenario is deployed; if {@code null},
* deployment dates are determined dynamically
* @return the generated {@link StratconScenario}, or {@code null} if scenario generation fails
*/
private static @Nullable StratconScenario generateScenario(Campaign campaign, AtBContract contract,
StratconTrackState track, int forceID,
StratconCoords coords) {
StratconCoords coords,
@Nullable Integer daysTilDeployment) {
int unitType = campaign.getForce(forceID).getPrimaryUnitType(campaign);
ScenarioTemplate template = StratconScenarioFactory.getRandomScenario(unitType);
// useful for debugging specific scenario types
// template = StratconScenarioFactory.getSpecificScenario("Defend Grounded
// Dropship.xml");

return generateScenario(campaign, contract, track, forceID, coords, template, -1);
return generateScenario(campaign, contract, track, forceID, coords, template, daysTilDeployment);
}

/**
Expand Down

0 comments on commit a01b3fe

Please sign in to comment.