diff --git a/MekHQ/src/mekhq/campaign/Campaign.java b/MekHQ/src/mekhq/campaign/Campaign.java index ac638a50d4..eccafcfa45 100644 --- a/MekHQ/src/mekhq/campaign/Campaign.java +++ b/MekHQ/src/mekhq/campaign/Campaign.java @@ -896,7 +896,7 @@ public void addForce(Force force, Force superForce) { int id = lastForceId + 1; force.setId(id); superForce.addSubForce(force, true); - force.setScenarioId(superForce.getScenarioId()); + force.setScenarioId(superForce.getScenarioId(), this); forceIds.put(id, force); lastForceId = id; @@ -917,15 +917,7 @@ public void moveForce(Force force, Force superForce) { } superForce.addSubForce(force, true); - force.setScenarioId(superForce.getScenarioId()); - - for (Object o : force.getAllChildren(this)) { - if (o instanceof Unit) { - ((Unit) o).setScenarioId(superForce.getScenarioId()); - } else if (o instanceof Force) { - ((Force) o).setScenarioId(superForce.getScenarioId()); - } - } + force.setScenarioId(superForce.getScenarioId(), this); // repopulate formation levels across the TO&E Force.populateFormationLevelsFromOrigin(this); @@ -3697,14 +3689,8 @@ && getLocation().getJumpPath().getLastSystem().getId().equals(contract.getSystem } if (!forceUnderRepair) { - forceIds.get(forceId).setScenarioId(s.getId()); + forceIds.get(forceId).setScenarioId(s.getId(), this); s.addForces(forceId); - for (UUID uid : forceIds.get(forceId).getAllUnits(true)) { - Unit u = getHangar().getUnit(uid); - if (u != null) { - u.setScenarioId(s.getId()); - } - } addReport(MessageFormat.format( resources.getString("atbScenarioTodayWithForce.format"), diff --git a/MekHQ/src/mekhq/campaign/force/Force.java b/MekHQ/src/mekhq/campaign/force/Force.java index 008822a834..6fb6ce545a 100644 --- a/MekHQ/src/mekhq/campaign/force/Force.java +++ b/MekHQ/src/mekhq/campaign/force/Force.java @@ -183,10 +183,16 @@ public int getScenarioId() { return scenarioId; } - public void setScenarioId(int i) { - this.scenarioId = i; + public void setScenarioId(int scenarioId, Campaign campaign) { + this.scenarioId = scenarioId; for (Force sub : getSubForces()) { - sub.setScenarioId(i); + sub.setScenarioId(scenarioId, campaign); + } + for (UUID uid : getUnits()) { + Unit unit = campaign.getUnit(uid); + if (null != unit) { + unit.setScenarioId(scenarioId); + } } } @@ -410,7 +416,7 @@ public void clearScenarioIds(Campaign c, boolean killSub) { c.getScenario(getScenarioId()).addUnit(uid); } } - setScenarioId(-1); + setScenarioId(-1,c); } public int getId() { diff --git a/MekHQ/src/mekhq/campaign/storyarc/storypoint/ScenarioStoryPoint.java b/MekHQ/src/mekhq/campaign/storyarc/storypoint/ScenarioStoryPoint.java index 947dcd0066..bf7d6b11f6 100644 --- a/MekHQ/src/mekhq/campaign/storyarc/storypoint/ScenarioStoryPoint.java +++ b/MekHQ/src/mekhq/campaign/storyarc/storypoint/ScenarioStoryPoint.java @@ -95,13 +95,7 @@ public void start() { Force force = getCampaign().getForce(deployedForceId); if (null != force) { scenario.addForces(force.getId()); - force.setScenarioId(scenario.getId()); - for (UUID uid : force.getAllUnits(true)) { - Unit u = getCampaign().getUnit(uid); - if (null != u) { - u.setScenarioId(scenario.getId()); - } - } + force.setScenarioId(scenario.getId(), getCampaign()); } } } diff --git a/MekHQ/src/mekhq/campaign/stratcon/StratconRulesManager.java b/MekHQ/src/mekhq/campaign/stratcon/StratconRulesManager.java index a1b6ff1c53..28dce4c76b 100644 --- a/MekHQ/src/mekhq/campaign/stratcon/StratconRulesManager.java +++ b/MekHQ/src/mekhq/campaign/stratcon/StratconRulesManager.java @@ -723,7 +723,7 @@ public static void commitPrimaryForces(Campaign campaign, StratconScenario scena for (int forceID : scenario.getPlayerTemplateForceIDs()) { Force force = campaign.getForce(forceID); force.clearScenarioIds(campaign, true); - force.setScenarioId(scenario.getBackingScenarioID()); + force.setScenarioId(scenario.getBackingScenarioID(), campaign); } scenario.commitPrimaryForces(); diff --git a/MekHQ/src/mekhq/campaign/stratcon/StratconScenario.java b/MekHQ/src/mekhq/campaign/stratcon/StratconScenario.java index 2ddc5c7ae4..6ae8c6135a 100644 --- a/MekHQ/src/mekhq/campaign/stratcon/StratconScenario.java +++ b/MekHQ/src/mekhq/campaign/stratcon/StratconScenario.java @@ -17,6 +17,7 @@ import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import mekhq.MekHQ; import mekhq.adapter.DateAdapter; +import mekhq.campaign.Campaign; import mekhq.campaign.event.DeploymentChangedEvent; import mekhq.campaign.force.Force; import mekhq.campaign.mission.AtBDynamicScenario; @@ -91,10 +92,10 @@ public void addPrimaryForce(int forceID) { * Add a force to the backing scenario, trying to associate it with the given template. * Does some scenario and force house-keeping, fires a deployment changed event. */ - public void addForce(Force force, String templateID) { + public void addForce(Force force, String templateID, Campaign campaign) { if (!getBackingScenario().getForceIDs().contains(force.getId())) { backingScenario.addForce(force.getId(), templateID); - force.setScenarioId(getBackingScenarioID()); + force.setScenarioId(getBackingScenarioID(), campaign); MekHQ.triggerEvent(new DeploymentChangedEvent(force, getBackingScenario())); } } diff --git a/MekHQ/src/mekhq/gui/CampaignGUI.java b/MekHQ/src/mekhq/gui/CampaignGUI.java index 3f4abf8356..4c4febd789 100644 --- a/MekHQ/src/mekhq/gui/CampaignGUI.java +++ b/MekHQ/src/mekhq/gui/CampaignGUI.java @@ -2419,7 +2419,7 @@ public void undeployForce(Force f, boolean killSubs) { continue; } scenario.addForces(sub.getId()); - sub.setScenarioId(scenario.getId()); + sub.setScenarioId(scenario.getId(), getCampaign()); } prevId = parent.getId(); } diff --git a/MekHQ/src/mekhq/gui/adapter/TOEMouseAdapter.java b/MekHQ/src/mekhq/gui/adapter/TOEMouseAdapter.java index a27365809e..fae28bb097 100644 --- a/MekHQ/src/mekhq/gui/adapter/TOEMouseAdapter.java +++ b/MekHQ/src/mekhq/gui/adapter/TOEMouseAdapter.java @@ -361,13 +361,7 @@ public void actionPerformed(ActionEvent action) { force.clearScenarioIds(gui.getCampaign(), true); if (null != scenario) { scenario.addForces(force.getId()); - force.setScenarioId(scenario.getId()); - for (UUID uid : force.getAllUnits(true)) { - Unit u = gui.getCampaign().getUnit(uid); - if (null != u) { - u.setScenarioId(scenario.getId()); - } - } + force.setScenarioId(scenario.getId(), gui.getCampaign()); } MekHQ.triggerEvent(new DeploymentChangedEvent(force, scenario)); } diff --git a/MekHQ/src/mekhq/gui/dialog/ForceTemplateAssignmentDialog.java b/MekHQ/src/mekhq/gui/dialog/ForceTemplateAssignmentDialog.java index b58d2e4fd8..49c4db64e6 100644 --- a/MekHQ/src/mekhq/gui/dialog/ForceTemplateAssignmentDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ForceTemplateAssignmentDialog.java @@ -208,7 +208,7 @@ private void assignForceToTemplate() { // all this stuff apparently needs to happen when assigning a force to a scenario campaignGUI.undeployForce(force); force.clearScenarioIds(campaignGUI.getCampaign(), true); - force.setScenarioId(currentScenario.getId()); + force.setScenarioId(currentScenario.getId(),campaignGUI.getCampaign()); currentScenario.addForce(forceID, templateList.getSelectedValue().getForceName()); for (UUID uid : force.getAllUnits(true)) { Unit u = campaignGUI.getCampaign().getUnit(uid); diff --git a/MekHQ/src/mekhq/gui/stratcon/StratconScenarioWizard.java b/MekHQ/src/mekhq/gui/stratcon/StratconScenarioWizard.java index b305727c8e..de1869a70b 100644 --- a/MekHQ/src/mekhq/gui/stratcon/StratconScenarioWizard.java +++ b/MekHQ/src/mekhq/gui/stratcon/StratconScenarioWizard.java @@ -470,7 +470,7 @@ private void btnCommitClicked(ActionEvent e) { } } - currentScenario.addForce(force, templateID); + currentScenario.addForce(force, templateID, campaign); } }