Skip to content

Commit

Permalink
Refactored Stratcon scenario reinforcement handling.
Browse files Browse the repository at this point in the history
Simplified and streamlined logic for reinforcing and committing primary forces in Stratcon scenarios. Consolidated redundant functionality, improved code consistency, and ensured proper initialization of scenario dates and states.
  • Loading branch information
IllianiCBT committed Jan 8, 2025
1 parent afa1d92 commit adb33bd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 50 deletions.
20 changes: 15 additions & 5 deletions MekHQ/src/mekhq/campaign/stratcon/StratconRulesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1282,11 +1282,21 @@ public static void processForceDeployment(StratconCoords coords, int forceID, Ca
}

StratconScenario scenario = track.getScenario(coords);
// if we're deploying on top of a scenario, and it's "cloaked" then we have to activate it
if ((scenario != null) && scenario.getBackingScenario().isCloaked()) {
scenario.getBackingScenario().setCloaked(false);
setScenarioDates(0, track, campaign, scenario); // must be called before commitPrimaryForces
MekHQ.triggerEvent(new ScenarioChangedEvent(scenario.getBackingScenario()));

if (scenario != null) {
AtBDynamicScenario backingScenario = scenario.getBackingScenario();

if (backingScenario != null) {
if (backingScenario.isCloaked()) {
backingScenario.setCloaked(false);
}

if (backingScenario.getDate() == null) {
setScenarioDates(0, track, campaign, scenario);
}

MekHQ.triggerEvent(new ScenarioChangedEvent(backingScenario));
}
}

// Traverse neighboring coordinates up to the specified distance
Expand Down
54 changes: 9 additions & 45 deletions MekHQ/src/mekhq/gui/stratcon/StratconScenarioWizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@
import mekhq.campaign.Campaign;
import mekhq.campaign.Campaign.AdministratorSpecialization;
import mekhq.campaign.force.Force;
import mekhq.campaign.mission.AtBDynamicScenarioFactory;
import mekhq.campaign.mission.ScenarioForceTemplate;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.stratcon.StratconCampaignState;
import mekhq.campaign.stratcon.StratconRulesManager;
import mekhq.campaign.stratcon.StratconRulesManager.ReinforcementEligibilityType;
import mekhq.campaign.stratcon.StratconRulesManager.ReinforcementResultsType;
import mekhq.campaign.stratcon.StratconRulesManager.*;
import mekhq.campaign.stratcon.StratconScenario;
import mekhq.campaign.stratcon.StratconScenario.ScenarioState;
import mekhq.campaign.stratcon.StratconTrackState;
Expand All @@ -50,12 +48,9 @@

import static mekhq.campaign.mission.AtBDynamicScenarioFactory.translateTemplateObjectives;
import static mekhq.campaign.personnel.SkillType.S_LEADER;
import static mekhq.campaign.stratcon.StratconRulesManager.BASE_LEADERSHIP_BUDGET;
import static mekhq.campaign.stratcon.StratconRulesManager.*;
import static mekhq.campaign.stratcon.StratconRulesManager.ReinforcementResultsType.DELAYED;
import static mekhq.campaign.stratcon.StratconRulesManager.ReinforcementResultsType.FAILED;
import static mekhq.campaign.stratcon.StratconRulesManager.calculateReinforcementTargetNumber;
import static mekhq.campaign.stratcon.StratconRulesManager.getEligibleLeadershipUnits;
import static mekhq.campaign.stratcon.StratconRulesManager.processReinforcementDeployment;
import static mekhq.gui.baseComponents.AbstractMHQNagDialog.getSpeakerDescription;
import static mekhq.gui.dialog.resupplyAndCaches.ResupplyDialogUtilities.getSpeakerIcon;
import static mekhq.utilities.ImageUtilities.scaleImageIconToWidth;
Expand Down Expand Up @@ -557,7 +552,7 @@ private String buildForceCost(int forceID) {
StringBuilder costBuilder = new StringBuilder();
costBuilder.append('(');

switch (StratconRulesManager.getReinforcementType(forceID, currentTrackState, campaign, currentCampaignState)) {
switch (getReinforcementType(forceID, currentTrackState, campaign, currentCampaignState)) {
case REGULAR:
costBuilder.append(resources.getString("regular.text"));
break;
Expand Down Expand Up @@ -858,23 +853,9 @@ private void btnCommitClicked(ActionEvent evt, @Nullable Integer reinforcementTa
// go through all the force lists and add the selected forces to the scenario
for (String templateID : availableForceLists.keySet()) {
for (Force force : availableForceLists.get(templateID).getSelectedValuesList()) {
if (templateID.equals(ScenarioForceTemplate.PRIMARY_FORCE_TEMPLATE_ID)) {
if (currentScenario.getCurrentState() == ScenarioState.UNRESOLVED) {
currentScenario.addForce(force, templateID, campaign);
}
} else if (currentScenario.getCurrentState() == ScenarioState.PRIMARY_FORCES_COMMITTED) {
ReinforcementEligibilityType reinforcementType = StratconRulesManager.getReinforcementType(
force.getId(), currentTrackState,
campaign, currentCampaignState);

// if we failed to deploy as reinforcements, move on to the next force
if (reinforcementTargetNumber == null) {
// If we've passed a null value into a reinforcement attempt, treat it as
// an impossibly large number, so that it's clear something is wrong.
reinforcementTargetNumber = 999;
logger.error("null reinforcementTargetNumber incorrectly passed into" +
" btnCommitClicked for reinforcement attempt");
}
if (currentScenario.getCurrentState() == ScenarioState.PRIMARY_FORCES_COMMITTED) {
ReinforcementEligibilityType reinforcementType = getReinforcementType(
force.getId(), currentTrackState, campaign, currentCampaignState);

ReinforcementResultsType reinforcementResults = processReinforcementDeployment(force,
reinforcementType, currentCampaignState, currentScenario, campaign,
Expand Down Expand Up @@ -923,30 +904,13 @@ private void btnCommitClicked(ActionEvent evt, @Nullable Integer reinforcementTa
forceID, campaign, currentTrackState, false);
}

// scenarios that haven't had primary forces committed yet get those committed
// now and the scenario gets published to the campaign and may be played immediately
// from the briefing room that being said, give the player a chance to commit reinforcements too
if (currentScenario.getCurrentState() == ScenarioState.UNRESOLVED) {
// if we've already generated forces and applied modifiers, no need to do it twice
if (!currentScenario.getBackingScenario().isFinalized()) {
AtBDynamicScenarioFactory.finalizeScenario(currentScenario.getBackingScenario(),
currentCampaignState.getContract(), campaign);
StratconRulesManager.setScenarioParametersFromBiome(currentTrackState, currentScenario);
}

setCurrentScenario(currentScenario, currentTrackState, currentCampaignState, true);
currentScenario.updateMinefieldCount(Minefield.TYPE_CONVENTIONAL, getNumMinefields());
StratconRulesManager.commitPrimaryForces(campaign, currentScenario, currentTrackState);
setVisible(true);
// if we've just committed reinforcements then simply close it down
} else {
currentScenario.updateMinefieldCount(Minefield.TYPE_CONVENTIONAL, getNumMinefields());
setVisible(false);
}
currentScenario.updateMinefieldCount(Minefield.TYPE_CONVENTIONAL, getNumMinefields());

translateTemplateObjectives(currentScenario.getBackingScenario(), campaign);

this.getParent().repaint();

dispose();
}

/**
Expand Down

0 comments on commit adb33bd

Please sign in to comment.