diff --git a/MekHQ/src/mekhq/campaign/mission/AtBScenario.java b/MekHQ/src/mekhq/campaign/mission/AtBScenario.java index ff74409af4..2e27c49fc3 100644 --- a/MekHQ/src/mekhq/campaign/mission/AtBScenario.java +++ b/MekHQ/src/mekhq/campaign/mission/AtBScenario.java @@ -466,12 +466,12 @@ public void setMapFile() { }; int actualTerrainType = terrainType; - - // we want to make sure the terrain type we pick is in bounds, + + // we want to make sure the terrain type we pick is in bounds, if ((terrainType < 0) || (terrainType >= maps.length)) { actualTerrainType = Compute.randomInt(maps.length); } - + map = maps[actualTerrainType][Compute.d6() - 1]; } @@ -2035,6 +2035,10 @@ public Entity getEntity(UUID id) { return entityIds.get(id); } + public List getBotForces() { + return botForces; + } + public void addBotForce(BotForce botForce) { botForces.add(botForce); diff --git a/MekHQ/src/mekhq/gui/BriefingTab.java b/MekHQ/src/mekhq/gui/BriefingTab.java index 48f10097c2..23df6c158e 100644 --- a/MekHQ/src/mekhq/gui/BriefingTab.java +++ b/MekHQ/src/mekhq/gui/BriefingTab.java @@ -25,12 +25,8 @@ import java.awt.GridLayout; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.ResourceBundle; -import java.util.UUID; -import java.util.Vector; +import java.util.*; +import java.util.stream.Collectors; import javax.swing.*; import javax.swing.table.TableColumn; @@ -473,7 +469,7 @@ private void addScenario() { scrollMissionView.repaint(); } - protected void clearAssignedUnits() { + private void clearAssignedUnits() { if (0 == JOptionPane.showConfirmDialog(null, "Do you really want to remove all units from this scenario?", "Clear Units?", JOptionPane.YES_NO_OPTION)) { int row = scenarioTable.getSelectedRow(); @@ -485,7 +481,7 @@ protected void clearAssignedUnits() { } } - protected void resolveScenario() { + private void resolveScenario() { int row = scenarioTable.getSelectedRow(); Scenario scenario = scenarioModel.getScenario(scenarioTable.convertRowIndexToModel(row)); if (null == scenario) { @@ -517,51 +513,60 @@ && getCampaign().getRetirementDefectionTracker().getRetirees().size() > 0) { MekHQ.triggerEvent(new ScenarioResolvedEvent(scenario)); } - protected void printRecordSheets() { - int row = scenarioTable.getSelectedRow(); + private void printRecordSheets() { + final int row = scenarioTable.getSelectedRow(); if (row < 0) { return; } - Scenario scenario = scenarioModel.getScenario(scenarioTable.convertRowIndexToModel(row)); + final Scenario scenario = scenarioModel.getScenario(scenarioTable.convertRowIndexToModel(row)); if (scenario == null) { return; } - Vector uids = scenario.getForces(getCampaign()).getAllUnits(true); - if (uids.size() == 0) { - return; - } - Vector chosen = new Vector<>(); - // ArrayList toDeploy = new ArrayList<>(); - StringBuilder undeployed = new StringBuilder(); + // First, we need to get all units assigned to the current scenario + final List unitIds = scenario.getForces(getCampaign()).getAllUnits(true); - for (UUID uid : uids) { - Unit u = getCampaign().getUnit(uid); - if (null != u.getEntity()) { - if (null == u.checkDeployment()) { - chosen.add(u.getEntity()); - } else { - undeployed.append("\n").append(u.getName()).append(" (").append(u.checkDeployment()).append(")"); - } + // Then, we need to convert the ids to units, and filter out any units that are null and + // any units with null entities + final List units = unitIds.stream().map(unitId -> getCampaign().getUnit(unitId)) + .filter(unit -> (unit != null) && (unit.getEntity() != null)) + .collect(Collectors.toList()); + + final List chosen = new ArrayList<>(); + final StringBuilder undeployed = new StringBuilder(); + + for (final Unit unit : units) { + if (unit.checkDeployment() == null) { + chosen.add(unit.getEntity()); + } else { + undeployed.append("\n").append(unit.getName()).append(" (").append(unit.checkDeployment()).append(")"); } } if (undeployed.length() > 0) { - Object[] options = { "Continue", "Cancel" }; - int n = JOptionPane.showOptionDialog(getFrame(), - "The following units could not be deployed:" + undeployed.toString(), "Could not deploy some units", - JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]); - if (n == 1) { + final Object[] options = { "Continue", "Cancel" }; + if (JOptionPane.showOptionDialog(getFrame(), + "The following units could not be deployed:" + undeployed, + "Could not deploy some units", JOptionPane.OK_CANCEL_OPTION, + JOptionPane.WARNING_MESSAGE, null, options, options[1]) == JOptionPane.NO_OPTION) { return; } } - if (chosen.size() > 0) { + if (scenario instanceof AtBScenario) { + // Also print off allied sheets and all bot force sheets + chosen.addAll(((AtBScenario) scenario).getAlliesPlayer()); + chosen.addAll(((AtBScenario) scenario).getBotForces().stream() + .flatMap(botForce -> botForce.getEntityList().stream()) + .collect(Collectors.toList())); + } + + if (!chosen.isEmpty()) { UnitPrintManager.printAllUnits(chosen, true); } } - protected void loadScenario() { + private void loadScenario() { int row = scenarioTable.getSelectedRow(); if (row < 0) { return; @@ -572,7 +577,7 @@ protected void loadScenario() { } } - protected void startScenario() { + private void startScenario() { int row = scenarioTable.getSelectedRow(); if (row < 0) { return; @@ -615,7 +620,7 @@ protected void startScenario() { if (undeployed.length() > 0) { Object[] options = { "Continue", "Cancel" }; int n = JOptionPane.showOptionDialog(getFrame(), - "The following units could not be deployed:" + undeployed.toString(), "Could not deploy some units", + "The following units could not be deployed:" + undeployed, "Could not deploy some units", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]); if (n == 1) { @@ -656,7 +661,7 @@ protected void startScenario() { } } - protected void joinScenario() { + private void joinScenario() { int row = scenarioTable.getSelectedRow(); if (row < 0) { return; @@ -693,7 +698,7 @@ protected void joinScenario() { if (undeployed.length() > 0) { Object[] options = { "Continue", "Cancel" }; int n = JOptionPane.showOptionDialog(getFrame(), - "The following units could not be deployed:" + undeployed.toString(), "Could not deploy some units", + "The following units could not be deployed:" + undeployed, "Could not deploy some units", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]); if (n == 1) { return; @@ -705,7 +710,7 @@ protected void joinScenario() { } } - protected void deployListFile() { + private void deployListFile() { int row = scenarioTable.getSelectedRow(); if (row < 0) { return; @@ -742,7 +747,7 @@ protected void deployListFile() { if (undeployed.length() > 0) { Object[] options = { "Continue", "Cancel" }; int n = JOptionPane.showOptionDialog(getFrame(), - "The following units could not be deployed:" + undeployed.toString(), "Could not deploy some units", + "The following units could not be deployed:" + undeployed, "Could not deploy some units", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]); if (n == 1) { return; @@ -751,7 +756,7 @@ protected void deployListFile() { Optional maybeUnitFile = FileDialogs.saveDeployUnits(getFrame(), scenario); - if (!maybeUnitFile.isPresent()) { + if (maybeUnitFile.isEmpty()) { return; }