From a80cee34cce3f69d60ad37d062790aa22ce91fd8 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Mon, 7 Oct 2024 20:30:37 -0400 Subject: [PATCH] correct issues with fixed map generation --- .../mission/AtBDynamicScenarioFactory.java | 34 +-------------- .../mekhq/campaign/mission/AtBScenario.java | 43 +++++++++++++++---- .../mekhq/gui/view/AtBScenarioViewPanel.java | 12 ++++-- 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/MekHQ/src/mekhq/campaign/mission/AtBDynamicScenarioFactory.java b/MekHQ/src/mekhq/campaign/mission/AtBDynamicScenarioFactory.java index 6babbd0f52..22a1970890 100644 --- a/MekHQ/src/mekhq/campaign/mission/AtBDynamicScenarioFactory.java +++ b/MekHQ/src/mekhq/campaign/mission/AtBDynamicScenarioFactory.java @@ -213,7 +213,7 @@ public static void finalizeScenario(AtBDynamicScenario scenario, AtBContract con // approximate estimate, anyway. scenario.setLanceCount(generatedLanceCount + (playerForceUnitCount / 4)); setScenarioMapSize(scenario); - setScenarioMap(scenario, campaign.getCampaignOptions().getFixedMapChance()); + scenario.setScenarioMap(campaign.getCampaignOptions().getFixedMapChance()); setDeploymentZones(scenario); setDestinationZones(scenario); @@ -1387,38 +1387,6 @@ public static void setScenarioMapSize(AtBDynamicScenario scenario) { scenario.setMapSizeY(mapSizeY); } - /** - * If there are maps of the appropriate size available and we roll higher than - * the given threshold, replace the scenario's generated map with a fixed map - * from data/boards - */ - private static void setScenarioMap(AtBDynamicScenario scenario, int mapChance) { - if (scenario.getBoardType() != Scenario.T_SPACE - && scenario.getTerrainType().equals("Space") - && (scenario.getMapSizeX() > 0) - && (scenario.getMapSizeY() > 0) - && (Compute.randomInt(100) <= mapChance)) { - BoardClassifier bc = BoardClassifier.getInstance(); - List maps = bc.getMatchingBoards(scenario.getMapSizeX(), scenario.getMapSizeY(), 5, 5, - new ArrayList<>()); - - if (!maps.isEmpty()) { - String mapPath = ObjectUtility.getRandomItem(maps); - MegaMekFile mapFile = new MegaMekFile(mapPath); - BoardDimensions dimensions = Board.getSize(mapFile.getFile()); - - scenario.setMap(bc.getBoardPaths().get(mapPath)); - scenario.setMapSizeX(dimensions.width()); - scenario.setMapSizeY(dimensions.height()); - scenario.setUsingFixedMap(true); - return; - } - } - - scenario.setUsingFixedMap(false); - scenario.setMapFile(); - } - /** * Randomly generates the number of scenario modifiers for a scenario, * for each random scenario in the count a random modifier is applied to the diff --git a/MekHQ/src/mekhq/campaign/mission/AtBScenario.java b/MekHQ/src/mekhq/campaign/mission/AtBScenario.java index 438fefed78..d8ccf140f5 100644 --- a/MekHQ/src/mekhq/campaign/mission/AtBScenario.java +++ b/MekHQ/src/mekhq/campaign/mission/AtBScenario.java @@ -26,6 +26,9 @@ import java.time.LocalDate; import java.util.*; +import megamek.common.*; +import megamek.common.util.fileUtils.MegaMekFile; +import megamek.utilities.BoardClassifier; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -33,14 +36,6 @@ import megamek.Version; import megamek.client.generator.TeamLoadOutGenerator; import megamek.codeUtilities.ObjectUtility; -import megamek.common.Board; -import megamek.common.Compute; -import megamek.common.Entity; -import megamek.common.EntityWeightClass; -import megamek.common.Infantry; -import megamek.common.TargetRoll; -import megamek.common.UnitType; -import megamek.common.WeatherRestriction; import megamek.common.annotations.Nullable; import megamek.common.enums.SkillLevel; import megamek.common.icons.Camouflage; @@ -492,6 +487,38 @@ public void setMapFile() { setMapFile(getTerrainType()); } + /** + * If there are maps of the appropriate size available and we roll higher than + * the given threshold, replace the scenario's generated map with a fixed map + * from data/boards + */ + public void setScenarioMap(int mapChance) { + if (getBoardType() != Scenario.T_SPACE + && !getTerrainType().equals("Space") + && (getMapSizeX() > 0) + && (getMapSizeY() > 0) + && (Compute.randomInt(100) <= mapChance)) { + BoardClassifier bc = BoardClassifier.getInstance(); + List maps = bc.getMatchingBoards(getMapSizeX(), getMapSizeY(), 7, 7, + new ArrayList<>()); + + if (!maps.isEmpty()) { + String mapPath = ObjectUtility.getRandomItem(maps); + MegaMekFile mapFile = new MegaMekFile(mapPath); + BoardDimensions dimensions = Board.getSize(mapFile.getFile()); + + setMap(bc.getBoardPaths().get(mapPath)); + setMapSizeX(dimensions.width()); + setMapSizeY(dimensions.height()); + setUsingFixedMap(true); + return; + } + } + + setUsingFixedMap(false); + setMapFile(); + } + public boolean canRerollTerrain() { return canRerollMap(); } diff --git a/MekHQ/src/mekhq/gui/view/AtBScenarioViewPanel.java b/MekHQ/src/mekhq/gui/view/AtBScenarioViewPanel.java index 19662c9272..5cd771046c 100644 --- a/MekHQ/src/mekhq/gui/view/AtBScenarioViewPanel.java +++ b/MekHQ/src/mekhq/gui/view/AtBScenarioViewPanel.java @@ -797,22 +797,26 @@ private void countRerollBoxes() { private void rerollBattleConditions() { if (chkReroll[REROLL_TERRAIN] != null && chkReroll[REROLL_TERRAIN].isSelected()) { scenario.setTerrain(); - scenario.setMapFile(); + scenario.setScenarioMap(campaign.getCampaignOptions().getFixedMapChance()); scenario.useReroll(); chkReroll[REROLL_TERRAIN].setSelected(false); lblTerrainDesc.setText(scenario.getTerrainType()); - lblMapDesc.setText(scenario.getMap()); + lblMapDesc.setText(scenario.getMapForDisplay()); + lblMapSizeDesc.setText(scenario.getMapSizeX() + "x" + scenario.getMapSizeY()); } if (chkReroll[REROLL_MAP] != null && chkReroll[REROLL_MAP].isSelected()) { - scenario.setMapFile(); + scenario.setScenarioMap(campaign.getCampaignOptions().getFixedMapChance()); scenario.useReroll(); chkReroll[REROLL_MAP].setSelected(false); - lblMapDesc.setText(scenario.getMap()); + lblMapDesc.setText(scenario.getMapForDisplay()); + lblMapSizeDesc.setText(scenario.getMapSizeX() + "x" + scenario.getMapSizeY()); } if (chkReroll[REROLL_MAPSIZE] != null && chkReroll[REROLL_MAPSIZE].isSelected()) { scenario.setMapSize(); + scenario.setScenarioMap(campaign.getCampaignOptions().getFixedMapChance()); scenario.useReroll(); chkReroll[REROLL_MAPSIZE].setSelected(false); + lblMapDesc.setText(scenario.getMapForDisplay()); lblMapSizeDesc.setText(scenario.getMapSizeX() + "x" + scenario.getMapSizeY()); } if (chkReroll[REROLL_LIGHT] != null && chkReroll[REROLL_LIGHT].isSelected()) {