-
Notifications
You must be signed in to change notification settings - Fork 188
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
Scoppio
wants to merge
2
commits into
MegaMek:master
Choose a base branch
from
Scoppio:feat/acar-blurb
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
10000 |
|
|
private static final MMLogger LOGGER = MMLogger.create(ScenarioUtils.class); | ||
|
||
private ScenarioUtils() {} | ||
|
||
/** | ||
* Creates a game board based on the settings in the provided Scenario. | ||
* 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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. Positive FeedbackNegative Feedback |
||
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); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?