Skip to content

Commit

Permalink
Merge pull request #5083 from WeaverThree/wvr-stratcon-deploy
Browse files Browse the repository at this point in the history
Fix StratCon vs Normal deployment status of units
  • Loading branch information
HammerGS authored Oct 21, 2024
2 parents b5530b6 + d1690ef commit 1abf171
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 41 deletions.
20 changes: 3 additions & 17 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -3695,14 +3687,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"),
Expand Down
19 changes: 15 additions & 4 deletions MekHQ/src/mekhq/campaign/force/Force.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,21 @@ public int getScenarioId() {
return scenarioId;
}

public void setScenarioId(int i) {
this.scenarioId = i;
/**
* Set scenario ID (e.g. deploy to scenario) for a force and all of its subforces and units
* @param scenarioId scenario to deploy to
* @param campaign campaign - required to update units
*/
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);
}
}
}

Expand Down Expand Up @@ -410,7 +421,7 @@ public void clearScenarioIds(Campaign c, boolean killSub) {
c.getScenario(getScenarioId()).addUnit(uid);
}
}
setScenarioId(-1);
setScenarioId(-1,c);
}

public int getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions MekHQ/src/mekhq/campaign/stratcon/StratconScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}
}
Expand Down
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/gui/CampaignGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2417,7 +2417,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();
}
Expand Down
8 changes: 1 addition & 7 deletions MekHQ/src/mekhq/gui/adapter/TOEMouseAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/gui/stratcon/StratconScenarioWizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ private void btnCommitClicked(ActionEvent e) {
}
}

currentScenario.addForce(force, templateID);
currentScenario.addForce(force, templateID, campaign);
}
}

Expand Down

0 comments on commit 1abf171

Please sign in to comment.