8000 feat: add actual board for acar by Scoppio · Pull Request #6938 · MegaMek/mekhq · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add actual board for acar #6938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions MekHQ/src/mekhq/MekHQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
import mekhq.service.AutosaveService;
import mekhq.service.IAutosaveService;
import mekhq.utilities.MHQInternationalization;
import mekhq.utilities.ScenarioUtils;

/**
* The main class of the application.
Expand Down Expand Up @@ -754,25 +755,27 @@ public IconPackage getIconPackage() {
*
* @param units The list of player units involved in the scenario
*/
public void startAutoResolve(AtBScenario scenario, List<Unit> units) {
public void startAutoResolve(Scenario scenario, List<Unit> units) {

this.autosaveService.requestBeforeScenarioAutosave(getCampaign());

Board board = ScenarioUtils.getBoardFor(scenario);
if (getCampaign().getCampaignOptions().isAutoResolveVictoryChanceEnabled()) {

var proceed = AutoResolveChanceDialog.showDialog(campaignGUI.getFrame(),
getCampaign().getCampaignOptions().getAutoResolveNumberOfScenarios(),
Runtime.getRuntime().availableProcessors(),
1,
new AtBSetupForces(getCampaign(), units, scenario, new SingletonForces()),
new Board(scenario.getBaseMapX(), scenario.getBaseMapY())) == JOptionPane.YES_OPTION;
board) == JOptionPane.YES_OPTION;
if (!proceed) {
return;
}
}

var event = AutoResolveProgressDialog.showDialog(campaignGUI.getFrame(),
new AtBSetupForces(getCampaign(), units, scenario, new SingletonForces()),
new Board(scenario.getBaseMapX(), scenario.getBaseMapY()));
board);

var autoResolveBattleReport = new AutoResolveSimulationLogDialog(campaignGUI.getFrame(), event.getLogFile());
autoResolveBattleReport.setModal(true);
Expand Down
6 changes: 2 additions & 4 deletions MekHQ/src/mekhq/gui/BriefingTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ private void runAbstractCombatAutoResolve(Scenario scenario) {
if (chosen.isEmpty()) {
return;
}
getCampaign().getApp().startAutoResolve((AtBScenario) scenario, chosen);
getCampaign().getApp().startAutoResolve(scenario, chosen);
}

private void runPrincessAutoResolve() {
Expand Down Expand Up @@ -1546,9 +1546,7 @@ public void refreshScenarioView() {
}

btnResolveScenario.setEnabled(canStartGame);
if (scenario instanceof AtBScenario) {
btnAutoResolveScenario.setEnabled(canStartGame);
}
btnAutoResolveScenario.setEnabled(canStartGame);
btnPrintRS.setEnabled(canStartGame);
}

Expand Down
155 changes: 155 additions & 0 deletions MekHQ/src/mekhq/utilities/ScenarioUtils.java
10000
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* Copyright (C) 2025 The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMek.
*
* MegaMek is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License (GPL),
* version 3 or (at your option) any later version,
* as published by the Free Software Foundation.
*
* MegaMek is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* A copy of the GPL should have been included with this project;
* if not, see <https://www.gnu.org/licenses/>.
*
* NOTICE: The MegaMek organization is a non-profit group of volunteers
* creating free software for the BattleTech community.
*
* MechWarrior, BattleMech, `Mech and AeroTech are registered trademarks
* of The Topps Company, Inc. All Rights Reserved.
*
* Catalyst Game Labs and the Catalyst Game Labs logo are trademarks of
* InMediaRes Productions, LLC.
*
* MechWarrior Copyright Microsoft Corporation. MegaMek was created under
* Microsoft's "Game Content Usage Rules"
* <https://www.xbox.com/en-US/developers/rules> and it is not endorsed by or
* affiliated with Microsoft.
*/
package mekhq.utilities;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import io.sentry.Sentry;
import megamek.common.Board;
import megamek.common.MapSettings;
import megamek.logging.MMLogger;
import megamek.server.ServerBoardHelper;
import mekhq.campaign.mission.AtBScenario;
import mekhq.campaign.mission.Scenario;

/**
* @author Luana Coppio
*/
public class ScenarioUtils {

private static final MMLogger LOGGER = MMLogger.create(ScenarioUtils.class);

private ScenarioUtils() {}

/**
* Creates a game board based on the settings in the provided Scenario.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool, I'm guessing this will allow you to better track the location of units for things like range and closing? Plus planetary effects?

* This method extracts map configuration from the scenario and delegates to the board creation logic.
*
* @param scenario The Scenario containing board configuration parameters
* @return A Board object configured according to the scenario settings, or a default board if invalid parameters
*/
public static Board getBoardFor(Scenario scenario) {
// Check for valid dimensions and map
if (scenario instanceof AtBScenario atBScenario) {
return getStratconBoardFor(atBScenario);
}
return getNonStratconBoardFor(scenario);
}

private static Board getNonStratconBoardFor(Scenario scenario) {
if (scenario == null || scenario.getMap() == null ||
scenario.getMapSizeX() <= 1 || scenario.getMapSizeY() <= 1) {
LOGGER.error("Invalid map settings provided for scenario {}",
scenario != null ? scenario.getName() : "null");
return ServerBoardHelper.getPossibleGameBoard(MapSettings.getInstance(), false);
}

boolean isSpace = scenario.getBoardType() == Scenario.T_SPACE;
boolean isAtmosphere = scenario.getBoardType() == Scenario.T_ATMOSPHERE;

return createBoard(
scenario.getMapSizeX(),
scenario.getMapSizeY(),
scenario.getMap(),
scenario.isUsingFixedMap(),
isSpace,
isAtmosphere
);
}

private static Board getStratconBoardFor(AtBScenario scenario) {
// Check for valid dimensions and map
if (scenario == null || scenario.getMap() == null) {
LOGGER.error("Invalid AtBScenario provided");
return ServerBoardHelper.getPossibleGameBoard(MapSettings.getInstance(), false);
}

boolean isSpace = scenario.getBoardType() == Scenario.T_SPACE ||
"Space".equals(scenario.getTerrainType());
boolean isAtmosphere = scenario.getBoardType() == Scenario.T_ATMOSPHERE;

return createBoard(
scenario.getMapX(),
scenario.getMapY(),
scenario.getMap(),
scenario.isUsingFixedMap(),
isSpace,
isAtmosphere
);
}

/**
* Creates a board based on the provided parameters
*/
private static Board createBoard(int mapSizeX, int mapSizeY, String mapName,
boolean isUsingFixedMap, boolean isSpace, boolean isAtmosphere) {
MapSettings mapSettings = MapSettings.getInstance();
mapSettings.setBoardSize(mapSizeX, mapSizeY);
mapSettings.setMapSize(1, 1);
mapSettings.getBoardsSelectedVector().clear();

if (isSpace) {
mapSettings.setMedium(MapSettings.MEDIUM_SPACE);
mapSettings.getBoardsSelectedVector().add(MapSettings.BOARD_GENERATED);
} else if (isUsingFixedMap) {
String board = mapName.replace(".board", "").replace("\\", "/");
mapSettings.getBoardsSelectedVector().add(board);

if (isAtmosphere) {
mapSettings.setMedium(MapSettings.MEDIUM_ATMOSPHERE);
}
} else {
File mapgenFile = new File("data/mapgen/" + mapName + ".xml");
Copy link
Preview
Copilot AI May 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting the hard-coded "data/mapgen/" directory into a named constant to improve maintainability and simplify future directory changes.

Copilot uses AI. Check for mistakes.

try (InputStream is = new FileInputStream(mapgenFile)) {
mapSettings = MapSettings.getInstance(is);
} catch (IOException ex) {
Sentry.captureException(ex);
LOGGER.error(ex, "Could not load map file data/mapgen/{}.xml", mapName);
}

if (isAtmosphere) {
mapSettings.setMedium(MapSettings.MEDIUM_ATMOSPHERE);
}

// Reset size parameters after getting new instance
mapSettings.setBoardSize(mapSizeX, mapSizeY);
mapSettings.setMapSize(1, 1);
mapSettings.getBoardsSelectedVector().add(MapSettings.BOARD_GENERATED);
}

return ServerBoardHelper.getPossibleGameBoard(mapSettings, false);
}
}
Loading
0