From b28bb1ae5366de6c47ffddd9d99e08938c868fa9 Mon Sep 17 00:00:00 2001 From: Scoppio Date: Sat, 14 Dec 2024 00:24:12 -0300 Subject: [PATCH] feat: config interface extracted --- .../ui/advancedsearch/TriStateItemList.java | 4 +- .../megamek/client/ui/swing/ClientGUI.java | 7 +- .../client/ui/swing/CommonSettingsDialog.java | 80 +++++------ .../client/ui/swing/EquipChoicePanel.java | 4 +- .../ui/swing/ForceGeneratorOptionsView.java | 2 +- .../client/ui/swing/GameOptionsDialog.java | 2 +- .../megamek/client/ui/swing/MegaMekGUI.java | 97 ++++++------- .../client/ui/swing/MovementDisplay.java | 4 +- .../megamek/client/ui/swing/QuirksPanel.java | 4 +- .../client/ui/swing/boardview/BoardView.java | 6 +- .../ui/swing/boardview/IsometricSprite.java | 4 +- .../boardview/SensorRangeSpriteHandler.java | 6 +- .../client/ui/swing/lobby/ChatLounge.java | 18 +-- .../client/ui/swing/lobby/LobbyMekPopup.java | 2 +- .../client/ui/swing/lobby/LobbyUtility.java | 24 ++-- .../ui/swing/lobby/MekForceTreeRenderer.java | 35 ++--- .../client/ui/swing/lobby/PlayerTable.java | 4 +- .../ui/swing/lobby/sorters/BVSorter.java | 3 +- .../swing/lobby/sorters/MekTableSorter.java | 19 +-- .../ui/swing/lobby/sorters/TonnageSorter.java | 9 +- .../client/ui/swing/util/TurnTimer.java | 4 +- .../ui/swing/widget/GeneralInfoMapSet.java | 4 +- megamek/src/megamek/common/Entity.java | 49 +++---- megamek/src/megamek/common/Game.java | 5 +- megamek/src/megamek/common/IGame.java | 3 +- .../megamek/common/InfantryWeaponMounted.java | 4 +- megamek/src/megamek/common/Mounted.java | 50 +++---- .../megamek/common/alphaStrike/ASGame.java | 3 +- ...tOptions.java => AbstractOptionsImpl.java} | 125 +++++----------- .../common/options/AbstractOptionsInfo.java | 57 ++++---- .../common/options/BasicGameOptions.java | 10 +- .../megamek/common/options/BasicOption.java | 3 + .../megamek/common/options/GameOptions.java | 31 ++-- .../megamek/common/options/IBasicOption.java | 24 ++-- .../megamek/common/options/IGameOptions.java | 135 ++++++++++++++++++ .../src/megamek/common/options/IOption.java | 24 ++-- .../megamek/common/options/IOptionGroup.java | 28 ++-- .../megamek/common/options/IOptionInfo.java | 40 +++--- .../megamek/common/options/IOptionsInfo.java | 8 +- .../src/megamek/common/options/Option.java | 42 +++--- .../megamek/common/options/OptionGroup.java | 31 ++-- .../common/options/OptionsConstants.java | 8 +- .../common/options/PartialRepairs.java | 16 +-- .../megamek/common/options/PilotOptions.java | 12 +- .../src/megamek/common/options/Quirks.java | 90 ++++++------ .../common/options/SBFRuleOptions.java | 6 +- .../megamek/common/options/WeaponQuirks.java | 97 ++++++------- .../pathfinder/AeroGroundPathFinder.java | 31 ++-- .../megamek/common/scenario/ScenarioV2.java | 8 +- .../src/megamek/common/util/EmailService.java | 12 +- .../common/util/SerializationHelper.java | 3 +- .../ArtilleryWeaponIndirectHomingHandler.java | 63 ++++---- .../megamek/common/weapons/CLIATMWeapon.java | 8 +- .../src/megamek/common/weapons/Weapon.java | 74 +++++----- .../artillery/ArtilleryCannonWeapon.java | 8 +- .../common/weapons/autocannons/ACWeapon.java | 8 +- .../weapons/battlearmor/CLBAMortarHeavy.java | 10 +- .../weapons/battlearmor/CLBAMortarLight.java | 8 +- .../battlearmor/ISBATubeArtillery.java | 8 +- .../weapons/gaussrifles/GaussWeapon.java | 18 +-- .../InfantrySupportLRMInfernoWeapon.java | 12 +- .../infantry/InfantrySupportLRMWeapon.java | 10 +- ...fantrySupportMortarHeavyInfernoWeapon.java | 10 +- .../InfantrySupportMortarHeavyWeapon.java | 8 +- ...fantrySupportMortarLightInfernoWeapon.java | 8 +- .../InfantrySupportMortarLightWeapon.java | 8 +- .../weapons/infantry/InfantryWeapon.java | 6 +- .../common/weapons/lasers/EnergyWeapon.java | 8 +- .../common/weapons/lasers/LaserWeapon.java | 7 +- .../common/weapons/lrms/LRMWeapon.java | 8 +- .../common/weapons/lrms/LRTWeapon.java | 8 +- .../common/weapons/missiles/MMLWeapon.java | 8 +- .../weapons/missiles/ThunderBoltWeapon.java | 12 +- .../weapons/mortars/MekMortarWeapon.java | 8 +- .../megamek/common/weapons/ppc/PPCWeapon.java | 8 +- megamek/src/megamek/server/Server.java | 37 ++--- .../server/totalwarfare/TWGameManager.java | 6 +- .../megamek/server/victory/VictoryHelper.java | 13 +- 78 files changed, 844 insertions(+), 843 deletions(-) rename megamek/src/megamek/common/options/{AbstractOptions.java => AbstractOptionsImpl.java} (71%) create mode 100644 megamek/src/megamek/common/options/IGameOptions.java diff --git a/megamek/src/megamek/client/ui/advancedsearch/TriStateItemList.java b/megamek/src/megamek/client/ui/advancedsearch/TriStateItemList.java index 370bc6d969b..7fc55071104 100644 --- a/megamek/src/megamek/client/ui/advancedsearch/TriStateItemList.java +++ b/megamek/src/megamek/client/ui/advancedsearch/TriStateItemList.java @@ -18,7 +18,7 @@ */ package megamek.client.ui.advancedsearch; -import megamek.common.options.AbstractOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.IOption; import megamek.common.options.IOptionGroup; @@ -34,7 +34,7 @@ class TriStateItemList { private final JList list = new JList<>(new DefaultListModel<>()); - TriStateItemList(AbstractOptions opts, int visibleRows) { + TriStateItemList(IGameOptions opts, int visibleRows) { List qs = new ArrayList<>(); for (final Enumeration optionGroups = opts.getGroups(); optionGroups.hasMoreElements(); ) { final IOptionGroup group = optionGroups.nextElement(); diff --git a/megamek/src/megamek/client/ui/swing/ClientGUI.java b/megamek/src/megamek/client/ui/swing/ClientGUI.java index 937c6bd9dad..a86cb9dd081 100644 --- a/megamek/src/megamek/client/ui/swing/ClientGUI.java +++ b/megamek/src/megamek/client/ui/swing/ClientGUI.java @@ -86,6 +86,7 @@ import megamek.common.equipment.WeaponMounted; import megamek.common.event.*; import megamek.common.icons.Camouflage; +import megamek.common.options.GameOptions; import megamek.common.preference.IPreferenceChangeListener; import megamek.common.preference.PreferenceChangeEvent; import megamek.common.util.AddBotUtil; @@ -688,7 +689,7 @@ private void showSettings() { private void showOptions() { getGameOptionsDialog().setEditable(client.getGame().getPhase().isLounge()); // Display the game options dialog. - getGameOptionsDialog().update(client.getGame().getOptions()); + getGameOptionsDialog().update((GameOptions) client.getGame().getOptions()); getGameOptionsDialog().setVisible(true); } @@ -1928,7 +1929,7 @@ protected void loadListFile(Player player, boolean reinforce) { try { // Read the units from the file. - final Vector loadedUnits = new MULParser(unitFile, getClient().getGame().getOptions()) + final Vector loadedUnits = new MULParser(unitFile, (GameOptions) getClient().getGame().getOptions()) .getEntities(); // in the Lounge, set default deployment to "Before Game Start", round 0 @@ -2416,7 +2417,7 @@ public void gameEnd(GameEndEvent e) { public void gameSettingsChange(GameSettingsChangeEvent evt) { if ((gameOptionsDialog != null) && gameOptionsDialog.isVisible() && !evt.isMapSettingsOnlyChange()) { - gameOptionsDialog.update(getClient().getGame().getOptions()); + gameOptionsDialog.update((GameOptions) getClient().getGame().getOptions()); } if (curPanel instanceof ChatLounge) { diff --git a/megamek/src/megamek/client/ui/swing/CommonSettingsDialog.java b/megamek/src/megamek/client/ui/swing/CommonSettingsDialog.java index ae77658b6b6..16374d47092 100644 --- a/megamek/src/megamek/client/ui/swing/CommonSettingsDialog.java +++ b/megamek/src/megamek/client/ui/swing/CommonSettingsDialog.java @@ -470,7 +470,7 @@ private void moveElement(DefaultListModel srcModel, int srcIndex, int trg private ClientGUI clientgui = null; private static final GUIPreferences GUIP = GUIPreferences.getInstance(); - private static final ClientPreferences CP = PreferenceManager.getClientPreferences(); + private static final ClientPreferences CLIENT_PREFERENCES = PreferenceManager.getClientPreferences(); private static final UnitDisplayOrderPreferences UDOP = UnitDisplayOrderPreferences.getInstance(); private static final ButtonOrderPreferences BOP = ButtonOrderPreferences.getInstance(); @@ -1942,7 +1942,7 @@ public void setVisible(boolean visible) { // Select the correct char set (give a nice default to start). unitStartChar.setSelectedIndex(0); for (int loop = 0; loop < unitStartChar.getItemCount(); loop++) { - if (unitStartChar.getItemAt(loop).charAt(0) == CP.getUnitStartChar()) { + if (unitStartChar.getItemAt(loop).charAt(0) == CLIENT_PREFERENCES.getUnitStartChar()) { unitStartChar.setSelectedIndex(loop); break; } @@ -1956,31 +1956,31 @@ public void setVisible(boolean visible) { tfSoundMuteMyTurnFileName.setText(GUIP.getSoundBingFilenameMyTurn()); tfSoundMuteOthersFileName.setText(GUIP.getSoundBingFilenameOthersTurn()); - maxPathfinderTime.setText(Integer.toString(CP.getMaxPathfinderTime())); + maxPathfinderTime.setText(Integer.toString(CLIENT_PREFERENCES.getMaxPathfinderTime())); - keepGameLog.setSelected(CP.keepGameLog()); + keepGameLog.setSelected(CLIENT_PREFERENCES.keepGameLog()); gameLogFilename.setEnabled(keepGameLog.isSelected()); - gameLogFilename.setText(CP.getGameLogFilename()); - userDir.setText(CP.getUserDir()); - mmlPath.setText(CP.getMmlPath()); - stampFilenames.setSelected(CP.stampFilenames()); + gameLogFilename.setText(CLIENT_PREFERENCES.getGameLogFilename()); + userDir.setText(CLIENT_PREFERENCES.getUserDir()); + mmlPath.setText(CLIENT_PREFERENCES.getMmlPath()); + stampFilenames.setSelected(CLIENT_PREFERENCES.stampFilenames()); stampFormat.setEnabled(stampFilenames.isSelected()); - stampFormat.setText(CP.getStampFormat()); - reportKeywordsTextPane.setText(CP.getReportKeywords()); - showIPAddressesInChat.setSelected(CP.getShowIPAddressesInChat()); - startSearchlightsOn.setSelected(CP.getStartSearchlightsOn()); + stampFormat.setText(CLIENT_PREFERENCES.getStampFormat()); + reportKeywordsTextPane.setText(CLIENT_PREFERENCES.getReportKeywords()); + showIPAddressesInChat.setSelected(CLIENT_PREFERENCES.getShowIPAddressesInChat()); + startSearchlightsOn.setSelected(CLIENT_PREFERENCES.getStartSearchlightsOn()); - defaultAutoejectDisabled.setSelected(CP.defaultAutoejectDisabled()); - useAverageSkills.setSelected(CP.useAverageSkills()); - useGPinUnitSelection.setSelected(CP.useGPinUnitSelection()); - generateNames.setSelected(CP.generateNames()); - showUnitId.setSelected(CP.getShowUnitId()); + defaultAutoejectDisabled.setSelected(CLIENT_PREFERENCES.defaultAutoejectDisabled()); + useAverageSkills.setSelected(CLIENT_PREFERENCES.useAverageSkills()); + useGPinUnitSelection.setSelected(CLIENT_PREFERENCES.useGPinUnitSelection()); + generateNames.setSelected(CLIENT_PREFERENCES.generateNames()); + showUnitId.setSelected(CLIENT_PREFERENCES.getShowUnitId()); int index = 0; - if (CP.getLocaleString().startsWith("de")) { + if (CLIENT_PREFERENCES.getLocaleString().startsWith("de")) { index = 1; } - if (CP.getLocaleString().startsWith("ru")) { + if (CLIENT_PREFERENCES.getLocaleString().startsWith("ru")) { index = 2; } displayLocale.setSelectedIndex(index); @@ -2008,7 +2008,7 @@ public void setVisible(boolean visible) { for (int i = 0; i < tileSets.size(); i++) { String name = tileSets.get(i); tileSetChoice.addItem(name.substring(0, name.length() - 8)); - if (name.equals(CP.getMapTileset())) { + if (name.equals(CLIENT_PREFERENCES.getMapTileset())) { tileSetChoice.setSelectedIndex(i); } } @@ -2413,7 +2413,7 @@ protected void okAction() { logger.error(ex, "okAction"); } GUIP.setValue(GUIPreferences.GUI_SCALE, (float) (guiScale.getValue()) / 10); - CP.setUnitStartChar(((String) unitStartChar.getSelectedItem()).charAt(0)); + CLIENT_PREFERENCES.setUnitStartChar(((String) unitStartChar.getSelectedItem()).charAt(0)); GUIP.setMouseWheelZoom(mouseWheelZoom.isSelected()); GUIP.setMouseWheelZoomFlip(mouseWheelZoomFlip.isSelected()); @@ -2430,33 +2430,33 @@ protected void okAction() { GUIP.setSoundBingFilenameOthersTurn(tfSoundMuteOthersFileName.getText()); try { - CP.setMaxPathfinderTime(Integer.parseInt(maxPathfinderTime.getText())); + CLIENT_PREFERENCES.setMaxPathfinderTime(Integer.parseInt(maxPathfinderTime.getText())); } catch (Exception ex) { logger.error(ex, "okAction"); } GUIP.setGetFocus(getFocus.isSelected()); - CP.setKeepGameLog(keepGameLog.isSelected()); - CP.setGameLogFilename(gameLogFilename.getText()); - CP.setUserDir(userDir.getText()); - CP.setMmlPath(mmlPath.getText()); - CP.setStampFilenames(stampFilenames.isSelected()); - CP.setStampFormat(stampFormat.getText()); - CP.setReportKeywords(reportKeywordsTextPane.getText()); - CP.setShowIPAddressesInChat(showIPAddressesInChat.isSelected()); - CP.setStartSearchlightsOn(startSearchlightsOn.isSelected()); - - CP.setDefaultAutoejectDisabled(defaultAutoejectDisabled.isSelected()); - CP.setUseAverageSkills(useAverageSkills.isSelected()); - CP.setUseGpInUnitSelection(useGPinUnitSelection.isSelected()); - CP.setGenerateNames(generateNames.isSelected()); - CP.setShowUnitId(showUnitId.isSelected()); + CLIENT_PREFERENCES.setKeepGameLog(keepGameLog.isSelected()); + CLIENT_PREFERENCES.setGameLogFilename(gameLogFilename.getText()); + CLIENT_PREFERENCES.setUserDir(userDir.getText()); + CLIENT_PREFERENCES.setMmlPath(mmlPath.getText()); + CLIENT_PREFERENCES.setStampFilenames(stampFilenames.isSelected()); + CLIENT_PREFERENCES.setStampFormat(stampFormat.getText()); + CLIENT_PREFERENCES.setReportKeywords(reportKeywordsTextPane.getText()); + CLIENT_PREFERENCES.setShowIPAddressesInChat(showIPAddressesInChat.isSelected()); + CLIENT_PREFERENCES.setStartSearchlightsOn(startSearchlightsOn.isSelected()); + + CLIENT_PREFERENCES.setDefaultAutoejectDisabled(defaultAutoejectDisabled.isSelected()); + CLIENT_PREFERENCES.setUseAverageSkills(useAverageSkills.isSelected()); + CLIENT_PREFERENCES.setUseGpInUnitSelection(useGPinUnitSelection.isSelected()); + CLIENT_PREFERENCES.setGenerateNames(generateNames.isSelected()); + CLIENT_PREFERENCES.setShowUnitId(showUnitId.isSelected()); if ((clientgui != null) && (clientgui.getBoardView() != null)) { clientgui.getBoardView().updateEntityLabels(); } - CP.setLocale(CommonSettingsDialog.LOCALE_CHOICES[displayLocale.getSelectedIndex()]); + CLIENT_PREFERENCES.setLocale(CommonSettingsDialog.LOCALE_CHOICES[displayLocale.getSelectedIndex()]); GUIP.setShowMapsheets(showMapsheets.isSelected()); GUIP.setAOHexShadows(aOHexShadows.isSelected()); @@ -2493,11 +2493,11 @@ protected void okAction() { if (tileSetChoice.getSelectedIndex() >= 0) { String tileSetFileName = tileSets.get(tileSetChoice.getSelectedIndex()); - if (!CP.getMapTileset().equals(tileSetFileName) && + if (!CLIENT_PREFERENCES.getMapTileset().equals(tileSetFileName) && (clientgui != null) && (clientgui.getBoardView() != null)) { clientgui.getBoardView().clearShadowMap(); } - CP.setMapTileset(tileSetFileName); + CLIENT_PREFERENCES.setMapTileset(tileSetFileName); } ToolTipManager.sharedInstance().setInitialDelay(GUIP.getTooltipDelay()); diff --git a/megamek/src/megamek/client/ui/swing/EquipChoicePanel.java b/megamek/src/megamek/client/ui/swing/EquipChoicePanel.java index dd75c80021d..f2aced1c259 100644 --- a/megamek/src/megamek/client/ui/swing/EquipChoicePanel.java +++ b/megamek/src/megamek/client/ui/swing/EquipChoicePanel.java @@ -43,7 +43,7 @@ import megamek.common.equipment.AmmoMounted; import megamek.common.equipment.MiscMounted; import megamek.common.equipment.WeaponMounted; -import megamek.common.options.AbstractOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.util.fileUtils.MegaMekFile; import megamek.common.verifier.EntityVerifier; @@ -586,7 +586,7 @@ private void setupMunitions() { GridBagLayout gbl = new GridBagLayout(); panMunitions.setLayout(gbl); Game game = clientgui.getClient().getGame(); - AbstractOptions gameOpts = game.getOptions(); + IGameOptions gameOpts = game.getOptions(); int gameYear = gameOpts.intOption(OptionsConstants.ALLOWED_YEAR); if (entity.usesWeaponBays() || entity instanceof Dropship) { diff --git a/megamek/src/megamek/client/ui/swing/ForceGeneratorOptionsView.java b/megamek/src/megamek/client/ui/swing/ForceGeneratorOptionsView.java index d325b9d6a8f..3814d1f10fb 100644 --- a/megamek/src/megamek/client/ui/swing/ForceGeneratorOptionsView.java +++ b/megamek/src/megamek/client/ui/swing/ForceGeneratorOptionsView.java @@ -926,7 +926,7 @@ void exportMUL(ForceDescriptor fd) { Player p = new Player(1, "Observer"); game.addPlayer(1, p); game.setOptions(clientGui.getClient().getGame().getOptions()); - list.stream().forEach(en -> { + list.forEach(en -> { en.setOwner(p); // If we don't set the id, the first unit will be left at -1, which in most // cases is interpreted diff --git a/megamek/src/megamek/client/ui/swing/GameOptionsDialog.java b/megamek/src/megamek/client/ui/swing/GameOptionsDialog.java index d77c0f96f68..c9a42e894a7 100644 --- a/megamek/src/megamek/client/ui/swing/GameOptionsDialog.java +++ b/megamek/src/megamek/client/ui/swing/GameOptionsDialog.java @@ -104,7 +104,7 @@ public class GameOptionsDialog extends AbstractButtonDialog implements ActionLis public GameOptionsDialog(ClientGUI cg) { super(cg.frame, "GameOptionsDialog", "GameOptionsDialog.title"); clientGui = cg; - init(cg.getFrame(), cg.getClient().getGame().getOptions()); + init(cg.getFrame(), (GameOptions) cg.getClient().getGame().getOptions()); } /** diff --git a/megamek/src/megamek/client/ui/swing/MegaMekGUI.java b/megamek/src/megamek/client/ui/swing/MegaMekGUI.java index 40ec3bf2f9d..f55bf6535a3 100644 --- a/megamek/src/megamek/client/ui/swing/MegaMekGUI.java +++ b/megamek/src/megamek/client/ui/swing/MegaMekGUI.java @@ -17,43 +17,6 @@ */ package megamek.client.ui.swing; -import static megamek.common.Compute.d6; - -import java.awt.*; -import java.awt.event.ActionListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.image.BaseMultiResolutionImage; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Properties; -import java.util.Vector; -import java.util.zip.GZIPInputStream; - -import javax.swing.JComponent; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.ToolTipManager; -import javax.swing.UIManager; -import javax.swing.filechooser.FileFilter; -import javax.xml.parsers.DocumentBuilder; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - import megamek.MMConstants; import megamek.MegaMek; import megamek.SuiteConstants; @@ -85,6 +48,7 @@ import megamek.common.*; import megamek.common.annotations.Nullable; import megamek.common.jacksonadapters.BotParser; +import megamek.common.options.GameOptions; import megamek.common.options.IBasicOption; import megamek.common.options.IOption; import megamek.common.preference.IPreferenceChangeListener; @@ -92,15 +56,37 @@ import megamek.common.preference.PreferenceManager; import megamek.common.scenario.Scenario; import megamek.common.scenario.ScenarioLoader; -import megamek.server.sbf.SBFGameManager; import megamek.common.util.EmailService; import megamek.common.util.ImageUtil; import megamek.common.util.fileUtils.MegaMekFile; import megamek.logging.MMLogger; import megamek.server.IGameManager; import megamek.server.Server; +import megamek.server.sbf.SBFGameManager; import megamek.server.totalwarfare.TWGameManager; import megamek.utilities.xml.MMXMLUtility; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import javax.swing.*; +import javax.swing.filechooser.FileFilter; +import javax.xml.parsers.DocumentBuilder; +import java.awt.*; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.image.BaseMultiResolutionImage; +import java.awt.image.BufferedImage; +import java.io.*; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; +import java.util.*; +import java.util.zip.GZIPInputStream; + +import static megamek.common.Compute.d6; public class MegaMekGUI implements IPreferenceChangeListener { private static final MMLogger logger = MMLogger.create(MegaMekGUI.class); @@ -438,7 +424,7 @@ public boolean startServer(@Nullable String serverPassword, int port, boolean is serverPassword = Server.validatePassword(serverPassword); port = Server.validatePort(port); } catch (Exception ex) { - logger.error(ex, "Failed to start Server"); + logger.error("Failed to start Server", ex); frame.setVisible(true); return false; } @@ -657,6 +643,19 @@ private boolean validateSaveVersion(final Node n) { return false; } + final Version version = getVersion(n); + if (SuiteConstants.VERSION.is(version)) { + return true; + } else { + final String message = String.format( + Messages.getString("MegaMek.LoadGameIncorrectVersion.message"), + version, SuiteConstants.VERSION); + logger.error(message, Messages.getString("MegaMek.LoadGameAlert.title")); + return false; + } + } + + private static Version getVersion(Node n) { final NodeList nl = n.getChildNodes(); String release = null; String major = null; @@ -686,16 +685,7 @@ private boolean validateSaveVersion(final Node n) { } } - final Version version = new Version(release, major, minor, snapshot); - if (SuiteConstants.VERSION.is(version)) { - return true; - } else { - final String message = String.format( - Messages.getString("MegaMek.LoadGameIncorrectVersion.message"), - version, SuiteConstants.VERSION); - logger.error(message, Messages.getString("MegaMek.LoadGameAlert.title")); - return false; - } + return new Version(release, major, minor, snapshot); } private void parsePlayerNames(final Node nodePlayers, final Vector playerNames) { @@ -775,9 +765,9 @@ void scenario() { } // popup options dialog - if (!scenario.hasFixedGameOptions() && game instanceof Game) { - GameOptionsDialog god = new GameOptionsDialog(frame, ((Game) game).getOptions(), false); - god.update(((Game) game).getOptions()); + if (!scenario.hasFixedGameOptions() && game instanceof Game twGame) { + GameOptionsDialog god = new GameOptionsDialog(frame, (GameOptions) twGame.getOptions(), false); + god.update((GameOptions) twGame.getOptions()); god.setEditable(true); god.setVisible(true); for (IBasicOption opt : god.getOptions()) { @@ -1182,8 +1172,7 @@ private BaseMultiResolutionImage getMultiResolutionSplashScreen(final List j = group.getSortedOptions(); j.hasMoreElements();) { IOption option = j.nextElement(); - if (null == option || !Quirks.isQuirkLegalFor(option, entity)) { + if (null == option || Quirks.isQuirkDisallowed(option, entity)) { continue; } @@ -98,7 +98,7 @@ public void refreshQuirks() { IOptionGroup group = i.nextElement(); for (Enumeration j = group.getSortedOptions(); j.hasMoreElements();) { IOption option = j.nextElement(); - if (!WeaponQuirks.isQuirkLegalFor(option, entity, m.getType())) { + if (WeaponQuirks.isQuirkDisallowed(option, entity, m.getType())) { continue; } addWeaponQuirk(key, option, editable); diff --git a/megamek/src/megamek/client/ui/swing/boardview/BoardView.java b/megamek/src/megamek/client/ui/swing/boardview/BoardView.java index f59f1134346..7d08de925e6 100644 --- a/megamek/src/megamek/client/ui/swing/boardview/BoardView.java +++ b/megamek/src/megamek/client/ui/swing/boardview/BoardView.java @@ -1321,9 +1321,9 @@ private void drawAllDeployment(Graphics g) { int drawHeight = (view.height / (int) (HEX_H * scale)) + 3; java.util.List players = game.getPlayersList(); - final GameOptions gOpts = game.getOptions(); + final var gOpts = game.getOptions(); - if (gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0)) { + if (gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER_0)) { players = new ArrayList<>( players.stream().filter(p -> p.isBot() || p.getId() == 0).collect(Collectors.toList())); } @@ -4294,7 +4294,7 @@ public void gameEntityRemove(GameEntityRemoveEvent e) { public void gameEntityChange(GameEntityChangeEvent e) { final Vector mp = e.getMovePath(); final Entity en = e.getEntity(); - final GameOptions gopts = game.getOptions(); + final var gopts = game.getOptions(); updateEcmList(); diff --git a/megamek/src/megamek/client/ui/swing/boardview/IsometricSprite.java b/megamek/src/megamek/client/ui/swing/boardview/IsometricSprite.java index 19bd201a9ba..f6078d1c712 100644 --- a/megamek/src/megamek/client/ui/swing/boardview/IsometricSprite.java +++ b/megamek/src/megamek/client/ui/swing/boardview/IsometricSprite.java @@ -28,7 +28,7 @@ import megamek.common.Entity; import megamek.common.GunEmplacement; import megamek.common.Player; -import megamek.common.options.AbstractOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; /** @@ -230,7 +230,7 @@ private boolean trackThisEntitiesVisibilityInfo(Entity e) { return false; } - AbstractOptions opts = this.bv.game.getOptions(); + IGameOptions opts = this.bv.game.getOptions(); return opts.booleanOption(OptionsConstants.ADVANCED_DOUBLE_BLIND) && ((e.getOwner().getId() == localPlayer.getId()) || (opts.booleanOption(OptionsConstants.ADVANCED_TEAM_VISION) diff --git a/megamek/src/megamek/client/ui/swing/boardview/SensorRangeSpriteHandler.java b/megamek/src/megamek/client/ui/swing/boardview/SensorRangeSpriteHandler.java index e36a70ca05d..04a5afdaed0 100644 --- a/megamek/src/megamek/client/ui/swing/boardview/SensorRangeSpriteHandler.java +++ b/megamek/src/megamek/client/ui/swing/boardview/SensorRangeSpriteHandler.java @@ -35,13 +35,13 @@ import java.util.Set; public class SensorRangeSpriteHandler extends BoardViewSpriteHandler implements IPreferenceChangeListener { - + private final Game game; // The last-used values are cached so they're available when the sensor range view is turned on private Entity currentEntity; private Coords currentPosition; - + public SensorRangeSpriteHandler(BoardView boardView, Game game) { super(boardView); this.game = game; @@ -86,7 +86,7 @@ public void setSensorRange(Entity entity, Coords assumedPosition) { int maxSensorRange = 0; int minAirSensorRange = 0; int maxAirSensorRange = 0; - GameOptions gameOptions = game.getOptions(); + var gameOptions = game.getOptions(); if (gameOptions.booleanOption(OptionsConstants.ADVANCED_TACOPS_SENSORS) || (gameOptions.booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_ADVANCED_SENSORS)) && entity.isSpaceborne()) { diff --git a/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java b/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java index 985774d18e8..560fb56bdae 100644 --- a/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java +++ b/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java @@ -1217,8 +1217,8 @@ public void previewGameBoard() { Board newBoard = ServerBoardHelper.getPossibleGameBoard(mapSettings, false); boardPreviewGame.setBoard(newBoard); previewBV.setLocalPlayer(client().getLocalPlayer()); - final GameOptions gOpts = game().getOptions(); - boardPreviewGame.setOptions(gOpts); + final var gOpts = game().getOptions(); + boardPreviewGame.setOptions((GameOptions) gOpts); previewBV.setShowLobbyPlayerDeployment(showPlayerDeployment.isSelected()); for (Player player : boardPreviewGame.getPlayersList()) { @@ -1254,7 +1254,7 @@ private void refreshMekTable() { allEntities.sort(activeSorter); boolean localUnits = false; - GameOptions opts = clientgui.getClient().getGame().getOptions(); + var opts = clientgui.getClient().getGame().getOptions(); for (Entity entity : allEntities) { // Remember if the local player has units. @@ -1709,7 +1709,7 @@ public void gameClientFeedbackRequest(GameCFREvent evt) { // Do nothing } - private ActionListener lobbyListener = new ActionListener() { + private final ActionListener lobbyListener = new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { // Are we ignoring events? @@ -1736,7 +1736,7 @@ public void actionPerformed(ActionEvent ev) { doBotSettings(); } else if (ev.getSource().equals(butOptions)) { clientgui.getGameOptionsDialog().setEditable(true); - clientgui.getGameOptionsDialog().update(clientgui.getClient().getGame().getOptions()); + clientgui.getGameOptionsDialog().update((GameOptions) clientgui.getClient().getGame().getOptions()); clientgui.getGameOptionsDialog().setVisible(true); } else if (ev.getSource().equals(butCompact)) { toggleCompact(); @@ -2176,7 +2176,7 @@ public void updateMapSettings(MapSettings newSettings) { /** OK Refreshes the Map Summary, Tech Level and Game Year labels. */ private void refreshLabels() { - GameOptions opts = clientgui.getClient().getGame().getOptions(); + var opts = clientgui.getClient().getGame().getOptions(); String txt = Messages.getString("ChatLounge.GameYear"); txt += opts.intOption(OptionsConstants.ALLOWED_YEAR); @@ -2221,7 +2221,7 @@ private void refreshLabels() { public void ready() { final Client client = clientgui.getClient(); final Game game = client.getGame(); - final GameOptions gOpts = game.getOptions(); + final var gOpts = game.getOptions(); // enforce exclusive deployment zones in double blind for (Player player : client.getGame().getPlayersList()) { @@ -2475,7 +2475,7 @@ private void setTeamSelectedItem(int team) { * shown/saved/etc. */ private boolean unitsVisible(Player player) { - GameOptions opts = clientgui.getClient().getGame().getOptions(); + var opts = clientgui.getClient().getGame().getOptions(); boolean isBlindDrop = opts.booleanOption(OptionsConstants.BASE_BLIND_DROP) || opts.booleanOption(OptionsConstants.BASE_REAL_BLIND_DROP); return !player.isEnemyOf(localPlayer()) || !isBlindDrop; @@ -3184,7 +3184,7 @@ public void mouseReleased(MouseEvent e) { private void sorterPopup(MouseEvent e) { ScalingPopup popup = new ScalingPopup(); - GameOptions opts = clientgui.getClient().getGame().getOptions(); + var opts = clientgui.getClient().getGame().getOptions(); for (MekTableSorter sorter : union(unitSorters, bvSorters)) { // Offer only allowed sorters and only one sorting direction if (sorter.isAllowed(opts) && sorter.getSortingDirection() != Sorting.ASCENDING) { diff --git a/megamek/src/megamek/client/ui/swing/lobby/LobbyMekPopup.java b/megamek/src/megamek/client/ui/swing/lobby/LobbyMekPopup.java index a7daaab301b..d65cda11c8e 100644 --- a/megamek/src/megamek/client/ui/swing/lobby/LobbyMekPopup.java +++ b/megamek/src/megamek/client/ui/swing/lobby/LobbyMekPopup.java @@ -129,7 +129,7 @@ static ScalingPopup getPopup(List entities, List forces, ActionLi ChatLounge lobby) { ClientGUI clientGui = lobby.getClientgui(); Game game = lobby.game(); - GameOptions opts = game.getOptions(); + var opts = game.getOptions(); boolean optBurstMG = opts.booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_BURST); boolean optLRMHotLoad = opts.booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_HOTLOAD); diff --git a/megamek/src/megamek/client/ui/swing/lobby/LobbyUtility.java b/megamek/src/megamek/client/ui/swing/lobby/LobbyUtility.java index af1dbc8e496..427538454ca 100644 --- a/megamek/src/megamek/client/ui/swing/lobby/LobbyUtility.java +++ b/megamek/src/megamek/client/ui/swing/lobby/LobbyUtility.java @@ -69,7 +69,7 @@ public class LobbyUtility { * with that of other players, if "Teams Share Vision" is off, or enemy players, * if "Teams Share Vision" is on. *

- * See also {@link #startPosOverlap(Player, Player)} + * See also {@link #startPosOverlap(int, int)} */ static boolean isValidStartPos(Game game, Player player) { return isValidStartPos(game, player, player.getStartingPos()); @@ -83,21 +83,21 @@ static boolean isValidStartPos(Game game, Player player) { * with that of other players, if "Teams Share Vision" is off, or enemy players, * if "Teams Share Vision" is on. *

- * See also {@link #startPosOverlap(Player, Player)} + * See also {@link #startPosOverlap(int, int)} */ static boolean isValidStartPos(Game game, Player player, int pos) { if (!isExclusiveDeployment(game)) { return true; } else { - final GameOptions gOpts = game.getOptions(); + final var gOpts = game.getOptions(); List players = game.getPlayersList(); - if (gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0) && !player.isBot() + if (gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER_0) && !player.isBot() && player.getId() != 0) { return true; } - if (gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0)) { + if (gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER_0)) { players = players.stream().filter(p -> p.isBot() || p.getId() == 0).collect(Collectors.toList()); } @@ -112,11 +112,11 @@ static boolean isValidStartPos(Game game, Player player, int pos) { } /** - * Returns true when double blind and exclusive deployment are on, + * Returns true when double-blind and exclusive deployment are on, * meaning that player's deployment zones may not overlap. */ static boolean isExclusiveDeployment(Game game) { - final GameOptions gOpts = game.getOptions(); + final var gOpts = game.getOptions(); return gOpts.booleanOption(OptionsConstants.ADVANCED_DOUBLE_BLIND) && gOpts.booleanOption(OptionsConstants.BASE_EXCLUSIVE_DB_DEPLOYMENT); } @@ -125,7 +125,7 @@ static boolean isExclusiveDeployment(Game game) { * Returns true when blind drop is on. */ static boolean isBlindDrop(Game game) { - final GameOptions gOpts = game.getOptions(); + final var gOpts = game.getOptions(); return gOpts.booleanOption(OptionsConstants.BASE_BLIND_DROP); } @@ -133,16 +133,16 @@ static boolean isBlindDrop(Game game) { * Returns true when real blind drop is on. */ static boolean isRealBlindDrop(Game game) { - final GameOptions gOpts = game.getOptions(); + final var gOpts = game.getOptions(); return gOpts.booleanOption(OptionsConstants.BASE_REAL_BLIND_DROP); } /** - * Returns true when teams share vision is on, reagardless of whether - * double blind is on. + * Returns true when teams share vision is on, regardless of whether + * double-blind is on. */ static boolean isTeamsShareVision(Game game) { - final GameOptions gOpts = game.getOptions(); + final var gOpts = game.getOptions(); return gOpts.booleanOption(OptionsConstants.ADVANCED_TEAM_VISION); } diff --git a/megamek/src/megamek/client/ui/swing/lobby/MekForceTreeRenderer.java b/megamek/src/megamek/client/ui/swing/lobby/MekForceTreeRenderer.java index ee02edff54d..ec81952e1e1 100644 --- a/megamek/src/megamek/client/ui/swing/lobby/MekForceTreeRenderer.java +++ b/megamek/src/megamek/client/ui/swing/lobby/MekForceTreeRenderer.java @@ -18,18 +18,6 @@ */ package megamek.client.ui.swing.lobby; -import java.awt.Color; -import java.awt.Component; -import java.awt.Font; -import java.awt.Image; -import java.awt.Rectangle; -import java.awt.event.MouseEvent; - -import javax.swing.ImageIcon; -import javax.swing.JTree; -import javax.swing.UIManager; -import javax.swing.tree.DefaultTreeCellRenderer; - import megamek.MMConstants; import megamek.client.ui.swing.tooltip.UnitToolTip; import megamek.client.ui.swing.util.UIUtil; @@ -44,33 +32,37 @@ import megamek.common.util.fileUtils.MegaMekFile; import megamek.logging.MMLogger; +import javax.swing.*; +import javax.swing.tree.DefaultTreeCellRenderer; +import java.awt.*; +import java.awt.event.MouseEvent; +import java.io.Serial; + /** A specialized renderer for the Mek Force tree. */ public class MekForceTreeRenderer extends DefaultTreeCellRenderer { private static final MMLogger logger = MMLogger.create(MekForceTreeRenderer.class); + @Serial private static final long serialVersionUID = -2002064111324279609L; private final String UNKNOWN_UNIT = new MegaMekFile(Configuration.miscImagesDir(), "unknown_unit.gif").toString(); - private ChatLounge lobby; - private boolean isSelected; - private Color selectionColor = Color.BLUE; + private final ChatLounge lobby; private Entity entity; private Player localPlayer; - private JTree tree; + private final JTree tree; private int row; @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { - isSelected = sel; Game game = lobby.getClientgui().getClient().getGame(); localPlayer = lobby.getClientgui().getClient().getLocalPlayer(); - selectionColor = UIManager.getColor("Tree.selectionBackground"); + Color selectionColor = UIManager.getColor("Tree.selectionBackground"); setOpaque(true); - if (isSelected) { + if (sel) { setBackground(new Color(selectionColor.getRGB())); } else { setForeground(null); @@ -102,11 +94,10 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean setIconTextGap(UIUtil.scaleForGUI(10)); setIcon(image, size); } - } else if (value instanceof Force) { + } else if (value instanceof Force force) { entity = null; Font scaledFont = new Font(MMConstants.FONT_DIALOG, Font.PLAIN, UIUtil.scaleForGUI(UIUtil.FONT_SCALE1 + 3)); setFont(scaledFont); - Force force = (Force) value; if (lobby.isCompact()) { setText(LobbyMekCellFormatter.formatForceCompact(force, lobby)); } else { @@ -134,7 +125,7 @@ private void setIcon(Image image, int height) { int width = height * image.getWidth(null) / image.getHeight(null); setIcon(new ImageIcon(ImageUtil.getScaledImage(image, width, height))); } else { - logger.error("Trying to resize a unit icon of height or width 0!"); + logger.debug("Trying to resize a unit icon of height or width 0!"); setIcon(null); } } diff --git a/megamek/src/megamek/client/ui/swing/lobby/PlayerTable.java b/megamek/src/megamek/client/ui/swing/lobby/PlayerTable.java index 1af36ae4e61..43248895590 100644 --- a/megamek/src/megamek/client/ui/swing/lobby/PlayerTable.java +++ b/megamek/src/megamek/client/ui/swing/lobby/PlayerTable.java @@ -208,8 +208,8 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole String msg_start = Messages.getString("ChatLounge.Start"); - final GameOptions gOpts = lobby.game().getOptions(); - if (gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0) && !player.isBot() && player.getId() != 0) { + final var gOpts = lobby.game().getOptions(); + if (gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER_0) && !player.isBot() && player.getId() != 0) { result.append(msg_start + ": " + Messages.getString("ChatLounge.Player0")); } else if ((!lobby.client().getLocalPlayer().isGameMaster() && (isEnemy) diff --git a/megamek/src/megamek/client/ui/swing/lobby/sorters/BVSorter.java b/megamek/src/megamek/client/ui/swing/lobby/sorters/BVSorter.java index 6b2c668a849..d10de88393f 100644 --- a/megamek/src/megamek/client/ui/swing/lobby/sorters/BVSorter.java +++ b/megamek/src/megamek/client/ui/swing/lobby/sorters/BVSorter.java @@ -21,6 +21,7 @@ import megamek.client.ui.swing.lobby.MekTableModel; import megamek.common.Entity; import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; /** A Lobby Mek Table sorter that sorts by BV. */ @@ -57,7 +58,7 @@ public int getColumnIndex() { } @Override - public boolean isAllowed(GameOptions opts) { + public boolean isAllowed(IGameOptions opts) { return !opts.booleanOption(OptionsConstants.BASE_BLIND_DROP); } diff --git a/megamek/src/megamek/client/ui/swing/lobby/sorters/MekTableSorter.java b/megamek/src/megamek/client/ui/swing/lobby/sorters/MekTableSorter.java index 4cd5b2d6f1f..c34459eb65c 100644 --- a/megamek/src/megamek/client/ui/swing/lobby/sorters/MekTableSorter.java +++ b/megamek/src/megamek/client/ui/swing/lobby/sorters/MekTableSorter.java @@ -22,40 +22,41 @@ import megamek.common.Entity; import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; /** An interface for the Comparators used for the lobby Mek table. */ public interface MekTableSorter extends Comparator { enum Sorting { ASCENDING, DESCENDING } - /** + /** * Returns the info that is displayed in the column header to show * the sorting that is used, such as "Team / BV". */ String getDisplayName(); - - /** - * Returns the column index of the Mek Table that this sorter is to be used with. + + /** + * Returns the column index of the Mek Table that this sorter is to be used with. */ int getColumnIndex(); - + /** * Returns true if this Sorter is currently allowed. Sorters might not be allowed * e.g. when they would give away info in blind drops. */ - default boolean isAllowed(GameOptions opts) { + default boolean isAllowed(IGameOptions opts) { return true; } - + /** Returns the sorting direction. */ default Sorting getSortingDirection() { return null; } - + /** Returns 1 if dir is ASCENDING, -1 otherwise. */ default int bigger(Sorting dir) { return dir == Sorting.ASCENDING ? 1 : -1; } - + /** Returns -1 if dir is ASCENDING, 1 otherwise. */ default int smaller(Sorting dir) { return dir == Sorting.ASCENDING ? -1 : 1; diff --git a/megamek/src/megamek/client/ui/swing/lobby/sorters/TonnageSorter.java b/megamek/src/megamek/client/ui/swing/lobby/sorters/TonnageSorter.java index 5c9e05babb8..ab9ffcf2f9a 100644 --- a/megamek/src/megamek/client/ui/swing/lobby/sorters/TonnageSorter.java +++ b/megamek/src/megamek/client/ui/swing/lobby/sorters/TonnageSorter.java @@ -21,13 +21,14 @@ import megamek.client.ui.swing.lobby.MekTableModel; import megamek.common.Entity; import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; /** A Lobby Mek Table sorter that sorts by tonnage. */ public class TonnageSorter implements MekTableSorter { - + private Sorting direction; - + /** A Lobby Mek Table sorter that sorts by tonnage. */ public TonnageSorter(MekTableSorter.Sorting dir) { direction = dir; @@ -55,9 +56,9 @@ public String getDisplayName() { public int getColumnIndex() { return MekTableModel.COL_UNIT; } - + @Override - public boolean isAllowed(GameOptions opts) { + public boolean isAllowed(IGameOptions opts) { return !opts.booleanOption(OptionsConstants.BASE_BLIND_DROP); } diff --git a/megamek/src/megamek/client/ui/swing/util/TurnTimer.java b/megamek/src/megamek/client/ui/swing/util/TurnTimer.java index 2449903295f..c197acc8b5a 100644 --- a/megamek/src/megamek/client/ui/swing/util/TurnTimer.java +++ b/megamek/src/megamek/client/ui/swing/util/TurnTimer.java @@ -65,7 +65,7 @@ public TurnTimer(int limit, AbstractPhaseDisplay pD, IClient client) { display.add(remaining); display.add(progressBar); - BasicGameOptions options = client.getGame().getOptions(); + var options = client.getGame().getOptions(); allowExtension = options.getOption(OptionsConstants.BASE_TURN_TIMER_ALLOW_EXTENSION).booleanValue(); listener = new ActionListener() { @@ -130,7 +130,7 @@ public boolean isTimerExpired() { public static TurnTimer init(AbstractPhaseDisplay phaseDisplay, IClient client) { // check if there should be a turn timer running - BasicGameOptions options = client.getGame().getOptions(); + var options = client.getGame().getOptions(); GamePhase phase = client.getGame().getPhase(); int timerLimit = 0; diff --git a/megamek/src/megamek/client/ui/swing/widget/GeneralInfoMapSet.java b/megamek/src/megamek/client/ui/swing/widget/GeneralInfoMapSet.java index 106e68853c4..315a6d327ec 100644 --- a/megamek/src/megamek/client/ui/swing/widget/GeneralInfoMapSet.java +++ b/megamek/src/megamek/client/ui/swing/widget/GeneralInfoMapSet.java @@ -29,7 +29,7 @@ import megamek.client.ui.swing.GUIPreferences; import megamek.client.ui.swing.tooltip.UnitToolTip; import megamek.common.*; -import megamek.common.options.AbstractOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.IOption; import megamek.common.options.IOptionGroup; import megamek.common.options.OptionsConstants; @@ -504,7 +504,7 @@ public void setEntity(Entity en) { * @param optionsInstance AbstractOptions instance * @param quirksAndPartReps */ - public void addOptionsToList(AbstractOptions optionsInstance, PMMultiLineLabel quirksAndPartReps) { + public void addOptionsToList(IGameOptions optionsInstance, PMMultiLineLabel quirksAndPartReps) { for (Enumeration optionGroups = optionsInstance.getGroups(); optionGroups.hasMoreElements();) { IOptionGroup group = optionGroups.nextElement(); if (optionsInstance.count(group.getKey()) > 0) { diff --git a/megamek/src/megamek/common/Entity.java b/megamek/src/megamek/common/Entity.java index 9ec423ce322..f5c94db9666 100644 --- a/megamek/src/megamek/common/Entity.java +++ b/megamek/src/megamek/common/Entity.java @@ -57,12 +57,7 @@ import megamek.common.hexarea.HexArea; import megamek.common.icons.Camouflage; import megamek.common.jacksonadapters.EntityDeserializer; -import megamek.common.options.GameOptions; -import megamek.common.options.IOption; -import megamek.common.options.IOptionGroup; -import megamek.common.options.OptionsConstants; -import megamek.common.options.PartialRepairs; -import megamek.common.options.Quirks; +import megamek.common.options.*; import megamek.common.planetaryconditions.Atmosphere; import megamek.common.planetaryconditions.PlanetaryConditions; import megamek.common.planetaryconditions.Wind; @@ -9901,7 +9896,7 @@ public boolean isEligibleForFiring() { } // check game options - if (!game.getOptions().booleanOption(OptionsConstants.BASE_SKIP_INELIGABLE_FIRING)) { + if (!game.getOptions().booleanOption(OptionsConstants.BASE_SKIP_INELIGIBLE_FIRING)) { return true; } @@ -9927,7 +9922,7 @@ public boolean isEligibleForMovement() { return false; } // check game options - if (!game.getOptions().booleanOption(OptionsConstants.BASE_SKIP_INELIGABLE_MOVEMENT)) { + if (!game.getOptions().booleanOption(OptionsConstants.BASE_SKIP_INELIGIBLE_MOVEMENT)) { return true; } // Must be active: this is slightly different from isActive(); @@ -10021,7 +10016,7 @@ && getCrew().isClanPilot() && !hasINarcPodsAttached() return true; } - if (!game.getOptions().booleanOption(OptionsConstants.BASE_SKIP_INELIGABLE_PHYSICAL)) { + if (!game.getOptions().booleanOption(OptionsConstants.BASE_SKIP_INELIGIBLE_PHYSICAL)) { return true; } @@ -11958,7 +11953,7 @@ public void setGameOptions() { return; } - final GameOptions gameOpts = game.getOptions(); + final var gameOpts = game.getOptions(); // if the small craft does not already have ECM, then give them a single // hex ECM so they can change the mode @@ -12960,8 +12955,8 @@ public int getStartingPos() { public int getStartingPos(boolean inheritFromOwner) { if (inheritFromOwner && startingPos == Board.START_NONE) { - final GameOptions gOpts = getGame().getOptions(); - if (!getOwner().isBot() && gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0)) { + final var gOpts = getGame().getOptions(); + if (!getOwner().isBot() && gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER_0)) { return game.getPlayer(0).getStartingPos(); } else { return getOwner().getStartingPos(); @@ -15411,8 +15406,8 @@ public int getStartingOffset(boolean inheritFromOwner) { // if we are given permission to use the owner's settings // and have specified entity-specific settings, use the owner's settings if (inheritFromOwner && (startingPos == Board.START_NONE)) { - final GameOptions gOpts = getGame().getOptions(); - if (!getOwner().isBot() && gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0)) { + final var gOpts = getGame().getOptions(); + if (!getOwner().isBot() && gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER_0)) { return game.getPlayer(0).getStartOffset(); } else { return getOwner().getStartOffset(); @@ -15434,8 +15429,8 @@ public int getStartingWidth(boolean inheritFromOwner) { // if we are given permission to use the owner's settings // and have specified entity-specific settings, use the owner's settings if (inheritFromOwner && (startingPos == Board.START_NONE)) { - final GameOptions gOpts = getGame().getOptions(); - if (!getOwner().isBot() && gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0)) { + final var gOpts = getGame().getOptions(); + if (!getOwner().isBot() && gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER_0)) { return game.getPlayer(0).getStartWidth(); } else { return getOwner().getStartWidth(); @@ -15457,8 +15452,8 @@ public int getStartingAnyNWx(boolean inheritFromOwner) { // if we are given permission to use the owner's settings // and have specified entity-specific settings, use the owner's settings if (inheritFromOwner && (startingPos == Board.START_NONE)) { - final GameOptions gOpts = getGame().getOptions(); - if (!getOwner().isBot() && gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0)) { + final var gOpts = getGame().getOptions(); + if (!getOwner().isBot() && gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER_0)) { return game.getPlayer(0).getStartingAnyNWx(); } else { return getOwner().getStartingAnyNWx(); @@ -15480,8 +15475,8 @@ public int getStartingAnyNWy(boolean inheritFromOwner) { // if we are given permission to use the owner's settings // and have specified entity-specific settings, use the owner's settings if (inheritFromOwner && (startingPos == Board.START_NONE)) { - final GameOptions gOpts = getGame().getOptions(); - if (!getOwner().isBot() && gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0)) { + final var gOpts = getGame().getOptions(); + if (!getOwner().isBot() && gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER_0)) { return game.getPlayer(0).getStartingAnyNWy(); } else { return getOwner().getStartingAnyNWy(); @@ -15503,8 +15498,8 @@ public int getStartingAnySEx(boolean inheritFromOwner) { // if we are given permission to use the owner's settings // and have specified entity-specific settings, use the owner's settings if (inheritFromOwner && (startingPos == Board.START_NONE)) { - final GameOptions gOpts = getGame().getOptions(); - if (!getOwner().isBot() && gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0)) { + final var gOpts = getGame().getOptions(); + if (!getOwner().isBot() && gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER_0)) { return game.getPlayer(0).getStartingAnySEx(); } else { return getOwner().getStartingAnySEx(); @@ -15526,8 +15521,8 @@ public int getStartingAnySEy(boolean inheritFromOwner) { // if we are given permission to use the owner's settings // and have specified entity-specific settings, use the owner's settings if (inheritFromOwner && (startingPos == Board.START_NONE)) { - final GameOptions gOpts = getGame().getOptions(); - if (!getOwner().isBot() && gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0)) { + final var gOpts = getGame().getOptions(); + if (!getOwner().isBot() && gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER_0)) { return game.getPlayer(0).getStartingAnySEy(); } else { return getOwner().getStartingAnySEy(); @@ -15690,9 +15685,9 @@ public BVCalculator getBvCalculator() { * calling game.getOptions() to avoid NPEs in places where game is null. * * @return The GameOptions of this Entity's game if it has one, otherwise a - * default options object. + * default options object. */ - protected final GameOptions gameOptions() { + protected final IGameOptions gameOptions() { return game != null ? game.getOptions() : new GameOptions(); } @@ -15759,7 +15754,7 @@ public void setIcon(String icon64) { /** * Returns true when this unit has an embedded icon, i.e. an icon stored in the * unit file rather than - * found by the mekset. Currently returns false when a mode-specific icon is + * found by the mekset. Currently, returns false when a mode-specific icon is * needed (LAMs/QVs) * * @return True when this unit has an embedded icon diff --git a/megamek/src/megamek/common/Game.java b/megamek/src/megamek/common/Game.java index 80b553b9c9f..05f4fadbac4 100644 --- a/megamek/src/megamek/common/Game.java +++ b/megamek/src/megamek/common/Game.java @@ -26,6 +26,7 @@ import megamek.common.equipment.AmmoMounted; import megamek.common.event.*; import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.planetaryconditions.PlanetaryConditions; import megamek.common.planetaryconditions.Wind; @@ -64,7 +65,7 @@ public final class Game extends AbstractGame implements Serializable, PlanetaryC */ public final Version version = MMConstants.VERSION; - private GameOptions options = new GameOptions(); + private IGameOptions options = new GameOptions(); private MapSettings mapSettings = MapSettings.getInstance(); @@ -300,7 +301,7 @@ public boolean containsVibrabomb(Minefield mf) { @Override public GameOptions getOptions() { - return options; + return (GameOptions) options; } public void setOptions(final @Nullable GameOptions options) { diff --git a/megamek/src/megamek/common/IGame.java b/megamek/src/megamek/common/IGame.java index fbfb88b1951..908d234b517 100644 --- a/megamek/src/megamek/common/IGame.java +++ b/megamek/src/megamek/common/IGame.java @@ -24,6 +24,7 @@ import megamek.common.event.GameListener; import megamek.common.force.Forces; import megamek.common.options.BasicGameOptions; +import megamek.common.options.IGameOptions; import megamek.server.scriptedevent.TriggeredEvent; import java.util.*; @@ -66,7 +67,7 @@ default boolean hasMoreTurns() { // endregion - BasicGameOptions getOptions(); + IGameOptions getOptions(); /** * @return The current game round, with 0 typically indicating deployment and 1 diff --git a/megamek/src/megamek/common/InfantryWeaponMounted.java b/megamek/src/megamek/common/InfantryWeaponMounted.java index 1f1c17b552e..c323aeec68b 100644 --- a/megamek/src/megamek/common/InfantryWeaponMounted.java +++ b/megamek/src/megamek/common/InfantryWeaponMounted.java @@ -15,7 +15,7 @@ package megamek.common; import megamek.common.equipment.WeaponMounted; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.weapons.Weapon; import megamek.common.weapons.infantry.InfantryWeapon; @@ -111,7 +111,7 @@ public boolean canInstantSwitch(int newMode) { } @Override - public void adaptToGameOptions(GameOptions options) { + public void adaptToGameOptions(IGameOptions options) { ((Weapon) getOtherWeapon()).adaptToGameOptions(options); super.adaptToGameOptions(options); rebuildModeList(); diff --git a/megamek/src/megamek/common/Mounted.java b/megamek/src/megamek/common/Mounted.java index cb5a95c9a5f..e0cdfac2463 100644 --- a/megamek/src/megamek/common/Mounted.java +++ b/megamek/src/megamek/common/Mounted.java @@ -25,7 +25,7 @@ import megamek.common.equipment.BombMounted; import megamek.common.equipment.MiscMounted; import megamek.common.equipment.WeaponMounted; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.options.WeaponQuirks; import megamek.common.weapons.AmmoWeapon; @@ -116,7 +116,7 @@ public class Mounted implements Serializable, RoundUpda // in MM they probably shouldn't need to be touched. They are used to keep track // of // whether a modular mount is in use or not for a particular trooper. - private boolean[] missingForTrooper = { false, false, false, false, false, false }; + private final boolean[] missingForTrooper = { false, false, false, false, false, false }; /** * Armor value, used for applicable equipment types like minesweepers. @@ -168,7 +168,7 @@ public class Mounted implements Serializable, RoundUpda private boolean armoredComponent = false; // called shots status, sort of like another mode - private CalledShot called = new CalledShot(); + private final CalledShot called = new CalledShot(); /** * Flag that keeps track of whether this Mounted is mounted as @@ -244,9 +244,9 @@ public boolean hasModeType(String mode) { return getType().hasModeType(mode); } - public void adaptToGameOptions(GameOptions options) { - if (getType() instanceof Weapon) { - ((Weapon) getType()).adaptToGameOptions(options); + public void adaptToGameOptions(IGameOptions options) { + if (getType() instanceof Weapon weapon) { + weapon.adaptToGameOptions(options); } } @@ -363,9 +363,8 @@ && getType().hasFlag(MiscType.F_COMMUNICATIONS)) { /** * Can the switch from the current mode to the new mode happen instantly? * - * @param newMode - * - integer for the new mode - * @return + * @param newMode - integer that represents the new mode + * @return true if the new mode can be switched instantly */ public boolean canInstantSwitch(int newMode) { String newModeName = type.getMode(newMode).getName(); @@ -597,13 +596,12 @@ public boolean isDestroyed() { * cannot be used in the current phase anymore. If it still can, use setHit * instead * - * @param destroyed + * @param destroyed set this object as detroyed * @see #setHit(boolean) */ public void setDestroyed(boolean destroyed) { this.destroyed = destroyed; - if ((destroyed == true) - && getType().hasFlag(MiscType.F_RADICAL_HEATSINK)) { + if (destroyed && getType().hasFlag(MiscType.F_RADICAL_HEATSINK)) { if (entity != null) { entity.setHasDamagedRHS(true); } @@ -660,13 +658,12 @@ public boolean isHit() { * stuff that was hit in a phase can still be used in that phase, if that's * not desired, use setDestroyed instead * - * @param hit + * @param hit sets the object as hit * @see #setDestroyed(boolean) */ public void setHit(boolean hit) { this.hit = hit; - if ((hit == true) - && getType().hasFlag(MiscType.F_RADICAL_HEATSINK)) { + if (hit && getType().hasFlag(MiscType.F_RADICAL_HEATSINK)) { if (entity != null) { entity.setHasDamagedRHS(true); } @@ -845,7 +842,7 @@ public double getSize() { /** * Sets the size of variable-sized equipment. * - * @param size + * @param size of the quipment * @see #getSize() */ public void setSize(double size) { @@ -909,7 +906,7 @@ && curMode().equals("HotLoad")) { /** * Sets the hotloading parameter for this weapons ammo. * - * @param hotload + * @param hotload set the ammo loaded as hotloaded or not */ public void setHotLoad(boolean hotload) { @@ -1145,8 +1142,7 @@ public void setSplit(boolean b) { } public int getExplosionDamage() { - if (type instanceof MiscType) { - MiscType mtype = (MiscType) type; + if (type instanceof MiscType mtype) { if (mtype.hasFlag(MiscType.F_PPC_CAPACITOR)) { if (curMode().equals("Charge") && (linked != null) && !linked.isFired()) { @@ -1251,10 +1247,7 @@ public boolean isCrippled() { return true; } } - if (isDWPMounted && (getLinkedBy() != null)) { - return true; - } - return false; + return isDWPMounted && (getLinkedBy() != null); } /** @@ -1414,7 +1407,7 @@ public void setQuirks(WeaponQuirks quirks) { * options, as it will not check game options for quirks. Use * Mounted#hasQuirk instead * - * @return + * @return the list of quirks */ public WeaponQuirks getQuirks() { return quirks; @@ -1659,22 +1652,21 @@ public boolean isAnyMissingTroopers() { } public String getMissingTrooperString() { - StringBuffer missings = new StringBuffer(); + StringBuilder missingTroopers = new StringBuilder(); for (int i = 0; i < missingForTrooper.length; i++) { - missings.append(missingForTrooper[i]).append("::"); + missingTroopers.append(missingForTrooper[i]).append("::"); } - return missings.toString(); + return missingTroopers.toString(); } /** * Returns true if this Mounted is ammunition in homing mode. */ public boolean isHomingAmmoInHomingMode() { - if (!(getType() instanceof AmmoType)) { + if (!(getType() instanceof AmmoType ammoType)) { return false; } - AmmoType ammoType = (AmmoType) getType(); return ammoType.getMunitionType().contains(AmmoType.Munitions.M_HOMING) && curMode().equals("Homing"); } diff --git a/megamek/src/megamek/common/alphaStrike/ASGame.java b/megamek/src/megamek/common/alphaStrike/ASGame.java index b9bebdc737a..180a5ab097e 100644 --- a/megamek/src/megamek/common/alphaStrike/ASGame.java +++ b/megamek/src/megamek/common/alphaStrike/ASGame.java @@ -21,6 +21,7 @@ import megamek.common.*; import megamek.common.enums.GamePhase; import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import java.util.List; @@ -48,7 +49,7 @@ public List getTurnsList() { } @Override - public GameOptions getOptions() { + public IGameOptions getOptions() { return null; } diff --git a/megamek/src/megamek/common/options/AbstractOptions.java b/megamek/src/megamek/common/options/AbstractOptionsImpl.java similarity index 71% rename from megamek/src/megamek/common/options/AbstractOptions.java rename to megamek/src/megamek/common/options/AbstractOptionsImpl.java index 6c3e49cfbc6..09fc81e48b5 100755 --- a/megamek/src/megamek/common/options/AbstractOptions.java +++ b/megamek/src/megamek/common/options/AbstractOptionsImpl.java @@ -15,39 +15,35 @@ import megamek.common.annotations.Nullable; +import java.io.Serial; import java.io.Serializable; import java.util.*; /** * Parent class for options settings */ -public abstract class AbstractOptions implements Serializable { +public abstract class AbstractOptionsImpl implements Serializable, IGameOptions { + + @Serial private static final long serialVersionUID = 6406883135074654379L; private final Hashtable optionsHash = new Hashtable<>(); - protected AbstractOptions() { + protected AbstractOptionsImpl() { initialize(); getOptionsInfoImp().finish(); } protected abstract void initialize(); - /** - * Returns a count of all options in this object. - * @return Option count. - */ - public int count() { + @Override + public int count() { return count(null); } - - /** - * Returns a count of all options in this object with the given group key. - * @param groupKey the group key to filter on. Null signifies to return all options indiscriminately. - * @return Option count. - */ + + @Override public int count(String groupKey) { int count = 0; - + for (Enumeration i = getGroups(); i.hasMoreElements(); ) { IOptionGroup group = i.nextElement(); if ((groupKey != null) && !group.getKey().equalsIgnoreCase(groupKey)) { @@ -61,44 +57,35 @@ public int count(String groupKey) { } } } - + return count; } - - /** - * Returns a string of all the quirk "codes" for this entity, using sep as - * the separator - * @param separator The separator to insert between codes, in addition to a space - */ + + @Override public String getOptionList(String separator) { return getOptionListString(separator, null); } - - /** - * Returns a string of all the quirk "codes" for this entity, using sep as - * the separator, filtering on a specific group key. - * @param separator The separator to insert between codes, in addition to a space - * @param groupKey The group key to use to filter options. Null signifies to return all options indiscriminately. - */ + + @Override public String getOptionListString(String separator, String groupKey) { StringBuilder listBuilder = new StringBuilder(); - + if (null == separator) { separator = ""; } for (Enumeration i = getGroups(); i.hasMoreElements();) { IOptionGroup group = i.nextElement(); - + if ((groupKey != null) && !group.getKey().equalsIgnoreCase(groupKey)) { continue; } - + for (Enumeration j = group.getOptions(); j .hasMoreElements();) { IOption option = j.nextElement(); if (option != null && option.booleanValue()) { - if (listBuilder.length() > 0) { + if (!listBuilder.isEmpty()) { listBuilder.append(separator); } listBuilder.append(option.getName()); @@ -113,63 +100,33 @@ public String getOptionListString(String separator, String groupKey) { return listBuilder.toString(); } - /** - * Returns the Enumeration of the option groups in thioptions container. - * - * @return Enumeration of the IOptionGroup - */ + @Override public Enumeration getGroups() { return new GroupsEnumeration(); } - /** - * Returns the Enumeration of the options in this options container. The order of - * options is not specified. - * - * @return Enumeration of the IOption - */ + @Override public Enumeration getOptions() { return optionsHash.elements(); } - /** - * Returns a collection of all of the options in this options container, regardless of whether they're - * active/selected or not. Note that this Collection is unmodifiable, but the contained IOptions are not - * copied, so changing their state will affect this options object. - * - * @return A collection containing all IOptions of this options object - */ + @Override public Collection getOptionsList() { return Collections.unmodifiableCollection(optionsHash.values()); } - /** - * Returns the UI specific data to allow the user to set the option - * - * @param name option name - * @return UI specific data - * @see IOptionInfo - */ + @Override public IOptionInfo getOptionInfo(String name) { return getOptionsInfo().getOptionInfo(name); } - /** - * Returns the option by name or null if there is no such option - * - * @param name option name - * @return the option or null if there is no such option - */ - public @Nullable IOption getOption(String name) { + @Nullable + @Override + public IOption getOption(String name) { return optionsHash.get(name); } - /** - * Returns the value of the desired option as the boolean - * - * @param name option name - * @return the value of the desired option as the boolean - */ + @Override public boolean booleanOption(String name) { IOption opt = getOption(name); if (opt == null) { @@ -179,37 +136,23 @@ public boolean booleanOption(String name) { } } - /** - * Returns the value of the desired option as the int - * - * @param name option name - * @return the value of the desired option as the int - */ + @Override public int intOption(String name) { return getOption(name).intValue(); } - /** - * Returns the value of the desired option as the float - * - * @param name option name - * @return the value of the desired option as the float - */ + @Override public float floatOption(String name) { return getOption(name).floatValue(); } - /** - * Returns the value of the desired option as the String - * - * @param name option name - * @return the value of the desired option as the String - */ + @Override public String stringOption(String name) { return getOption(name).stringValue(); } - IOptionsInfo getOptionsInfo() { + @Override + public IOptionsInfo getOptionsInfo() { return getOptionsInfoImp(); } @@ -254,7 +197,7 @@ protected void addOption(IBasicOptionGroup group, String name, int type, Object protected class GroupsEnumeration implements Enumeration { - private Enumeration groups; + private final Enumeration groups; GroupsEnumeration() { groups = getOptionsInfo().getGroups(); @@ -282,7 +225,7 @@ public IOptionGroup nextElement() { protected class GroupProxy implements IOptionGroup { - private IBasicOptionGroup group; + private final IBasicOptionGroup group; GroupProxy(IBasicOptionGroup group) { this.group = group; diff --git a/megamek/src/megamek/common/options/AbstractOptionsInfo.java b/megamek/src/megamek/common/options/AbstractOptionsInfo.java index c5c7ba67488..bf8d9a7fc0c 100755 --- a/megamek/src/megamek/common/options/AbstractOptionsInfo.java +++ b/megamek/src/megamek/common/options/AbstractOptionsInfo.java @@ -33,34 +33,34 @@ public class AbstractOptionsInfo implements IOptionsInfo { * The OptionsInfo name that must be unique. Every instance of the * AbstractOptionsInfo must have unique name, it's used to query the NLS * dependent information from the common resource bundle. - * - * @see getOptionDisplayableName - * @see getGroupDisplayableName - * @see getOptionDescription + * + * @see #getOptionDisplayableName + * @see #getGroupDisplayableName + * @see #getOptionDescription */ - private String name; + private final String name; /** * Hashtable of the OptionInfo used to store/find option * info. */ - private Hashtable optionsHash = new Hashtable<>(); + private final Hashtable optionsHash = new Hashtable<>(); /** * List of option groups. The order of groups is important. The first group * added by addGroup is the first in the * Enumeration returned by getGroups */ - private Vector groups = new Vector<>(); + private final Vector groups = new Vector<>(); /** * Flag that indicates that this filling the options info data is * completed. addGroup and addOptionInfo will * have no effect if it's true - * - * @see finish - * @see addGroup - * @see addOptionInfo + * + * @see #finish + * @see #addGroup + * @see #addOptionInfo */ private boolean finished; @@ -70,13 +70,13 @@ public class AbstractOptionsInfo implements IOptionsInfo { * * @see AbstractOptionsInfo() */ - private static HashSet names = new HashSet<>(); + private static final HashSet names = new HashSet<>(); /** * Protected constructor. It is called only by descendants. The name must be * unique because it's used to query the NLS dependent information from the * resource bundle. - * + * * @param name options info name */ protected AbstractOptionsInfo(String name) { @@ -89,7 +89,7 @@ protected AbstractOptionsInfo(String name) { /* * (non-Javadoc) - * + * * @see megamek.common.options.IOptionsInfo#getOptionInfo(java.lang.String) */ @Override @@ -99,7 +99,7 @@ public IOptionInfo getOptionInfo(String name) { /* * (non-Javadoc) - * + * * @see megamek.common.options.IOptionsInfo#getGroups() */ @Override @@ -132,8 +132,6 @@ IBasicOptionGroup addGroup(String name, String key) { void addOptionInfo(IBasicOptionGroup group, String name) { if (!finished) { - // TODO: I'm not happy about this cast but this is better than it - // was before. ((OptionGroup) group).addOptionName(name); setOptionInfo(name, new OptionInfo(name)); } @@ -142,8 +140,8 @@ void addOptionInfo(IBasicOptionGroup group, String name) { /** * Returns the user-friendly NLS dependent name suitable for displaying in * the options editor dialogs etc. - * - * @param groupName + * + * @param groupName the group name which we want the display format * @return group displayable name */ protected String getGroupDisplayableName(String groupName) { @@ -161,9 +159,9 @@ protected String getGroupDisplayableName(String groupName) { * Records that filling of this structure is finished. addGroup * and addOptionInfo will have no effect after call of this * function - * - * @see addGroup - * @see addOptionInfo + * + * @see #addGroup + * @see #addOptionInfo */ void finish() { finished = true; @@ -183,15 +181,12 @@ private String getOptionDescription(String optionName) { /** * Private model class to store the option info - * - * @see addOptionInfo - * @see getOptionInfo + * + * @see #addOptionInfo + * @see #getOptionInfo */ private class OptionInfo implements IOptionInfo { - private String name; - private int textFieldLength = 3; - - private boolean labelBeforeTextField = false; + private final String name; public OptionInfo(String optionName) { this.name = optionName; @@ -214,12 +209,12 @@ public String getDescription() { @Override public int getTextFieldLength() { - return textFieldLength; + return 3; // Default value of 3 } @Override public boolean isLabelBeforeTextField() { - return labelBeforeTextField; + return false; // Default value of false } } } diff --git a/megamek/src/megamek/common/options/BasicGameOptions.java b/megamek/src/megamek/common/options/BasicGameOptions.java index a581b598817..756e41d9384 100644 --- a/megamek/src/megamek/common/options/BasicGameOptions.java +++ b/megamek/src/megamek/common/options/BasicGameOptions.java @@ -21,15 +21,15 @@ import java.io.File; import java.util.Vector; -public abstract class BasicGameOptions extends AbstractOptions { +public abstract class BasicGameOptions extends AbstractOptionsImpl { @Override public synchronized void initialize() { IBasicOptionGroup base = addGroup("basic"); addOption(base, OptionsConstants.BASE_FRIENDLY_FIRE, false); - addOption(base, OptionsConstants.BASE_SKIP_INELIGABLE_MOVEMENT, false); - addOption(base, OptionsConstants.BASE_SKIP_INELIGABLE_FIRING, false); - addOption(base, OptionsConstants.BASE_SKIP_INELIGABLE_PHYSICAL, true); + addOption(base, OptionsConstants.BASE_SKIP_INELIGIBLE_MOVEMENT, false); + addOption(base, OptionsConstants.BASE_SKIP_INELIGIBLE_FIRING, false); + addOption(base, OptionsConstants.BASE_SKIP_INELIGIBLE_PHYSICAL, true); addOption(base, OptionsConstants.BASE_TEAM_INITIATIVE, true); addOption(base, OptionsConstants.BASE_AUTOSAVE_MSG, true); addOption(base, OptionsConstants.BASE_PARANOID_AUTOSAVE, false); @@ -39,7 +39,7 @@ public synchronized void initialize() { addOption(base, OptionsConstants.BASE_REAL_BLIND_DROP, false); addOption(base, OptionsConstants.BASE_SET_ARTY_PLAYER_HOMEEDGE, false); addOption(base, OptionsConstants.BASE_SET_DEFAULT_TEAM_1, false); - addOption(base, OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0, false); + addOption(base, OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER_0, false); addOption(base, OptionsConstants.BASE_RESTRICT_GAME_COMMANDS, false); addOption(base, OptionsConstants.BASE_DISABLE_LOCAL_SAVE, false); addOption(base, OptionsConstants.BASE_BRIDGECF, 0); diff --git a/megamek/src/megamek/common/options/BasicOption.java b/megamek/src/megamek/common/options/BasicOption.java index 309e41b9c11..aab78bccabb 100644 --- a/megamek/src/megamek/common/options/BasicOption.java +++ b/megamek/src/megamek/common/options/BasicOption.java @@ -18,6 +18,7 @@ import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.io.Serial; import java.io.Serializable; /** @@ -26,6 +27,7 @@ @XmlAccessorType(value = XmlAccessType.NONE) public class BasicOption implements IBasicOption, Serializable { + @Serial private static final long serialVersionUID = 916639704995096673L; @XmlElement(name = "optionname") @@ -43,6 +45,7 @@ public BasicOption(final String name, final Object value) { /** * Constructor that satisfies JAXB. */ + @SuppressWarnings("unused") public BasicOption() { } diff --git a/megamek/src/megamek/common/options/GameOptions.java b/megamek/src/megamek/common/options/GameOptions.java index a61247d238f..d66c465d30e 100755 --- a/megamek/src/megamek/common/options/GameOptions.java +++ b/megamek/src/megamek/common/options/GameOptions.java @@ -13,18 +13,6 @@ */ package megamek.common.options; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.io.PrintWriter; -import java.util.Enumeration; -import java.util.Vector; - -import javax.xml.namespace.QName; - -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - import jakarta.xml.bind.JAXBContext; import jakarta.xml.bind.JAXBElement; import jakarta.xml.bind.Marshaller; @@ -36,6 +24,13 @@ import megamek.common.TechConstants; import megamek.logging.MMLogger; import megamek.utilities.xml.MMXMLUtility; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import javax.xml.namespace.QName; +import java.io.*; +import java.util.Enumeration; +import java.util.Vector; /** * Contains the options determining play in the current game. @@ -45,6 +40,7 @@ public class GameOptions extends BasicGameOptions { private static final MMLogger logger = MMLogger.create(GameOptions.class); + @Serial private static final long serialVersionUID = 4916321960852747706L; private static final String GAME_OPTIONS_FILE_NAME = "mmconf/gameoptions.xml"; @@ -330,7 +326,7 @@ public synchronized Vector loadOptions(File file, boolean print) { } logger.info(logMessages.toString()); } catch (Exception e) { - logger.error("Error loading XML for game options: " + e.getMessage(), e); + logger.error("Error loading XML for game options: {}", e.getMessage(), e); } return changedOptions; @@ -370,12 +366,11 @@ private IOption parseOptionNode(final IBasicOption node, final boolean print, fi option = tempOption; } catch (Exception ex) { - logger.error(String.format( - "Error trying to load option '%s' with a value of '%s'!", name, value)); + logger.warn("Error trying to load option {} with a value of {}!", name, value); } } } else { - logger.warn("Invalid option '" + name + "' when trying to load options file!"); + logger.warn("Invalid option '{}' when trying to load options file!", name); } } @@ -390,7 +385,7 @@ public static void saveOptions(Vector options) { * Saves the given Vector of IBasicOption * * @param options Vector of IBasicOption - * @param file + * @param file string with the name of the file */ public static void saveOptions(Vector options, String file) { try { @@ -423,7 +418,7 @@ protected AbstractOptionsInfo getOptionsInfoImp() { } private static class GameOptionsInfo extends AbstractOptionsInfo { - private static AbstractOptionsInfo instance = new GameOptionsInfo(); + private static final AbstractOptionsInfo instance = new GameOptionsInfo(); protected GameOptionsInfo() { super("GameOptionsInfo"); diff --git a/megamek/src/megamek/common/options/IBasicOption.java b/megamek/src/megamek/common/options/IBasicOption.java index dd6e172855b..a253cae10bf 100644 --- a/megamek/src/megamek/common/options/IBasicOption.java +++ b/megamek/src/megamek/common/options/IBasicOption.java @@ -1,14 +1,14 @@ /* * MegaMek - Copyright (C) 2005 Ben Mazur (bmazur@sev.org) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) * any later version. - * - * This program 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 + * + * This program 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. */ @@ -24,17 +24,17 @@ public interface IBasicOption { /** * Returns the option name - * + * * @return name of the option */ - public abstract String getName(); + String getName(); /** * Returns the option value - * + * * @return option value */ - public abstract Object getValue(); + Object getValue(); /** @return True when this Option's name is equal to the given Option name. */ default boolean is(String otherName) { diff --git a/megamek/src/megamek/common/options/IGameOptions.java b/megamek/src/megamek/common/options/IGameOptions.java new file mode 100644 index 00000000000..bc69d898ccd --- /dev/null +++ b/megamek/src/megamek/common/options/IGameOptions.java @@ -0,0 +1,135 @@ +/* + * MegaMek - Copyright (C) 2024 - The MegaMek Team + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program 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. + */ +package megamek.common.options; + +import megamek.common.annotations.Nullable; + +import java.util.Collection; +import java.util.Enumeration; + +public interface IGameOptions { + + /** + * Returns a count of all options in this object. + * + * @return Option count. + */ + int count(); + + /** + * Returns a count of all options in this object with the given group key. + * + * @param groupKey the group key to filter on. Null signifies to return all options indiscriminately. + * @return Option count. + */ + int count(String groupKey); + + /** + * Returns a string of all the quirk "codes" for this entity, using sep as + * the separator + * + * @param separator The separator to insert between codes, in addition to a space + */ + String getOptionList(String separator); + + /** + * Returns a string of all the quirk "codes" for this entity, using sep as + * the separator, filtering on a specific group key. + * + * @param separator The separator to insert between codes, in addition to a space + * @param groupKey The group key to use to filter options. Null signifies to return all options indiscriminately. + */ + String getOptionListString(String separator, String groupKey); + + /** + * Returns the Enumeration of the option groups in thioptions container. + * + * @return Enumeration of the IOptionGroup + */ + Enumeration getGroups(); + + /** + * Returns the Enumeration of the options in this options container. The order of + * options is not specified. + * + * @return Enumeration of the IOption + */ + Enumeration getOptions(); + + /** + * Returns a collection of all of the options in this options container, regardless of whether they're + * active/selected or not. Note that this Collection is unmodifiable, but the contained IOptions are not + * copied, so changing their state will affect this options object. + * + * @return A collection containing all IOptions of this options object + */ + Collection getOptionsList(); + + /** + * Returns the UI specific data to allow the user to set the option + * + * @param name option name + * @return UI specific data + * @see IOptionInfo + */ + IOptionInfo getOptionInfo(String name); + + /** + * Returns the option by name or null if there is no such option + * + * @param name option name + * @return the option or null if there is no such option + */ + @Nullable + IOption getOption(String name); + + /** + * Returns the value of the desired option as the boolean + * + * @param name option name + * @return the value of the desired option as the boolean + */ + boolean booleanOption(String name); + + /** + * Returns the value of the desired option as the int + * + * @param name option name + * @return the value of the desired option as the int + */ + int intOption(String name); + + /** + * Returns the value of the desired option as the float + * + * @param name option name + * @return the value of the desired option as the float + */ + float floatOption(String name); + + /** + * Returns the value of the desired option as the String + * + * @param name option name + * @return the value of the desired option as the String + */ + String stringOption(String name); + + /** + * Returns the options info object for this options object. + * + * @return the options info object for this options object. + */ + IOptionsInfo getOptionsInfo(); +} diff --git a/megamek/src/megamek/common/options/IOption.java b/megamek/src/megamek/common/options/IOption.java index 366637c10e5..e07bb81fc5e 100755 --- a/megamek/src/megamek/common/options/IOption.java +++ b/megamek/src/megamek/common/options/IOption.java @@ -1,11 +1,11 @@ /* * MegaMek - Copyright (C) 2005 Ben Mazur (bmazur@sev.org) - * + * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. - * + * * This program 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 @@ -20,7 +20,7 @@ * the same across all clients. A settable option's primary purpose is to store * a value for the option. Its secondary purpose is to give the desired options * dialog enough data to allow the user to set the option. - * + * * @author Ben * @since April 26, 2002, 10:50 AM */ @@ -53,14 +53,14 @@ public interface IOption extends IBasicOption, IOptionInfo { /** * Returns this option container - GameOptions, PilotOptions etc - * + * * @return option container */ - AbstractOptions getOwner(); + IGameOptions getOwner(); /** * Returns option type. - * + * * @return option type * @see IOption#BOOLEAN etc */ @@ -68,7 +68,7 @@ public interface IOption extends IBasicOption, IOptionInfo { /** * Returns default option value - * + * * @return default option value */ Object getDefault(); @@ -95,35 +95,35 @@ public interface IOption extends IBasicOption, IOptionInfo { /** * Sets the value - * + * * @param value value to set */ void setValue(Object value); /** * Sets the String value - * + * * @param value value to set */ void setValue(String value); /** * Sets the boolean value - * + * * @param value value to set */ void setValue(boolean value); /** * Sets the int value - * + * * @param value value to set */ void setValue(int value); /** * Sets the float value - * + * * @param value value to set */ void setValue(float value); diff --git a/megamek/src/megamek/common/options/IOptionGroup.java b/megamek/src/megamek/common/options/IOptionGroup.java index dd9c46e2cf1..4ae1ddb15fc 100755 --- a/megamek/src/megamek/common/options/IOptionGroup.java +++ b/megamek/src/megamek/common/options/IOptionGroup.java @@ -1,14 +1,14 @@ /* * MegaMek - Copyright (C) 2005 Ben Mazur (bmazur@sev.org) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) * any later version. - * - * This program 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 + * + * This program 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. */ @@ -21,28 +21,28 @@ * IBasicOptionGroup and adds the ability to query the options * that belongs to this group. Instances of this interface are ONLY returned as * the members of the Enumeration returned by the AbstractOptions#getGroups() - * - * @see AbstractOptions#getGroups() + * + * @see AbstractOptionsImpl#getGroups() */ public interface IOptionGroup extends IBasicOptionGroup { /** - * Returns the user friendly NLS dependent name suitable for displaying in + * Returns the user-friendly NLS dependent name suitable for displaying in * the options editor dialogs etc. - * + * * @return displayable name */ String getDisplayableName(); /** * @return the Enumeration of the IOption - * @see AbstractOptions#getGroups() + * @see AbstractOptionsImpl#getGroups() */ Enumeration getOptions(); /** * @return the Enumeration of the IOption sorted in alpha-numerically ascending order. - * @see AbstractOptions#getGroups() + * @see AbstractOptionsImpl#getGroups() */ Enumeration getSortedOptions(); } diff --git a/megamek/src/megamek/common/options/IOptionInfo.java b/megamek/src/megamek/common/options/IOptionInfo.java index b1d1f175093..d3b73088950 100755 --- a/megamek/src/megamek/common/options/IOptionInfo.java +++ b/megamek/src/megamek/common/options/IOptionInfo.java @@ -1,14 +1,14 @@ /* * MegaMek - Copyright (C) 2005 Ben Mazur (bmazur@sev.org) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) * any later version. - * - * This program 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 + * + * This program 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. */ @@ -20,37 +20,37 @@ public interface IOptionInfo { /** - * Returns the user friendly name suitable for displaying in the options + * Returns the user-friendly name suitable for displaying in the options * editor dialogs etc. - * + * * @return displayable name */ - public abstract String getDisplayableName(); + String getDisplayableName(); /** - * Returns the user friendly name suitable for displaying in cases where not - * only the Name but also it value is required (like edge). - * + * Returns the user-friendly name suitable for displaying in cases where not + * only the Name, but also it value is required (like edge). + * * @return displayable name */ - public abstract String getDisplayableNameWithValue(); + String getDisplayableNameWithValue(); /** * Return verbose description of the option suitable for context help, tip * etc. - * + * * @return option description */ - public abstract String getDescription(); + String getDescription(); /** - * returns the length of the textfield (how many characters). + * returns the length of the text field (how many characters). */ - public abstract int getTextFieldLength(); + int getTextFieldLength(); /** * returns on which side of the text field the label is. */ - public abstract boolean isLabelBeforeTextField(); + boolean isLabelBeforeTextField(); } diff --git a/megamek/src/megamek/common/options/IOptionsInfo.java b/megamek/src/megamek/common/options/IOptionsInfo.java index 278db142895..76282e7f849 100755 --- a/megamek/src/megamek/common/options/IOptionsInfo.java +++ b/megamek/src/megamek/common/options/IOptionsInfo.java @@ -24,20 +24,20 @@ public interface IOptionsInfo { /** * Returns the IOptionInfo for the specified option - * + * * @param name option name * @return the IOptionInfo for the specified option * @see IOptionInfo */ - public abstract IOptionInfo getOptionInfo(String name); + IOptionInfo getOptionInfo(String name); /** * Returns the Enumeration of the * IBasicOptionGroup - * + * * @return the Enumeration of the * IBasicOptionGroup */ - public abstract Enumeration getGroups(); + Enumeration getGroups(); } diff --git a/megamek/src/megamek/common/options/Option.java b/megamek/src/megamek/common/options/Option.java index de99ea44594..2d5c790d323 100755 --- a/megamek/src/megamek/common/options/Option.java +++ b/megamek/src/megamek/common/options/Option.java @@ -18,12 +18,15 @@ import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; +import java.io.Serial; import java.io.Serializable; import java.util.Vector; @XmlRootElement(name = "gameoption") @XmlAccessorType(value = XmlAccessType.NONE) public class Option implements IOption, Serializable { + + @Serial private static final long serialVersionUID = 8310472250031962888L; @XmlElement(name = "optionname") private String name; @@ -31,31 +34,32 @@ public class Option implements IOption, Serializable { private Object defaultValue; @XmlElement(name = "optionvalue") private Object value; - private AbstractOptions owner; + private IGameOptions owner; private transient IOptionInfo info; - public Option(AbstractOptions owner, String name, String defaultValue) { + public Option(IGameOptions owner, String name, String defaultValue) { this(owner, name, STRING, defaultValue); } - public Option(AbstractOptions owner, String name, boolean defaultValue) { + public Option(IGameOptions owner, String name, boolean defaultValue) { this(owner, name, BOOLEAN, defaultValue); } - public Option(AbstractOptions owner, String name, int defaultValue) { + public Option(IGameOptions owner, String name, int defaultValue) { this(owner, name, INTEGER, defaultValue); } - public Option(AbstractOptions owner, String name, float defaultValue) { + public Option(IGameOptions owner, String name, float defaultValue) { this(owner, name, FLOAT, defaultValue); } - public Option(AbstractOptions owner, String name, Vector defaultValue) { + @SuppressWarnings("unused") + public Option(IGameOptions owner, String name, Vector defaultValue) { this(owner, name, CHOICE, ""); } - public Option(AbstractOptions owner, String name, int type, Object defaultValue) { + public Option(IGameOptions owner, String name, int type, Object defaultValue) { this.owner = owner; this.name = name; this.type = type; @@ -74,7 +78,7 @@ protected Option() { } @Override - public AbstractOptions getOwner() { + public IGameOptions getOwner() { return owner; } @@ -221,19 +225,13 @@ public void clearValue() { } private boolean isValidValue(Object object) { - switch (type) { - case STRING: - case CHOICE: - return object instanceof String; - case BOOLEAN: - return object instanceof Boolean; - case INTEGER: - return object instanceof Integer; - case FLOAT: - return object instanceof Float; - default: - return false; - } + return switch (type) { + case STRING, CHOICE -> object instanceof String; + case BOOLEAN -> object instanceof Boolean; + case INTEGER -> object instanceof Integer; + case FLOAT -> object instanceof Float; + default -> false; + }; } /** @@ -244,7 +242,7 @@ private void updateInfo() { info = owner.getOptionInfo(name); } } - + @Override public String toString() { return "Option - " + getName() + ": " + getValue(); diff --git a/megamek/src/megamek/common/options/OptionGroup.java b/megamek/src/megamek/common/options/OptionGroup.java index 8d9451e5c09..9fe43754fec 100644 --- a/megamek/src/megamek/common/options/OptionGroup.java +++ b/megamek/src/megamek/common/options/OptionGroup.java @@ -1,38 +1,37 @@ /* * MegaMek - Copyright (C) 2000-2002 Ben Mazur (bmazur@sev.org) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) * any later version. - * - * This program 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 + * + * This program 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. */ package megamek.common.options; +import java.io.Serial; import java.io.Serializable; import java.util.Enumeration; import java.util.Vector; public class OptionGroup implements IBasicOptionGroup, Serializable { - /** - * - */ + @Serial private static final long serialVersionUID = 6445683666789832313L; - private Vector optionNames = new Vector<>(); + private final Vector optionNames = new Vector<>(); - private String name; + private final String name; private String key; /** * Creates new OptionGroup - * + * * @param name group name * @param key optional key */ @@ -43,7 +42,7 @@ public OptionGroup(String name, String key) { /** * Creates new OptionGroup with empty key - * + * * @param name option name */ public OptionGroup(String name) { @@ -73,7 +72,7 @@ public Enumeration getOptionNames() { * Adds new option name to this group. The option names are unique, so if * there is already an option optionName this function does * nothing. - * + * * @param optionName new option name */ public void addOptionName(String optionName) { diff --git a/megamek/src/megamek/common/options/OptionsConstants.java b/megamek/src/megamek/common/options/OptionsConstants.java index 6850acaf3fb..259c20a1fca 100644 --- a/megamek/src/megamek/common/options/OptionsConstants.java +++ b/megamek/src/megamek/common/options/OptionsConstants.java @@ -274,9 +274,9 @@ public class OptionsConstants { public static final String BASE_TURN_TIMER_FIRING = "turn_timer_firing"; public static final String BASE_TURN_TIMER_PHYSICAL = "turn_timer_physical"; public static final String BASE_TURN_TIMER_ALLOW_EXTENSION = "turn_timer_allow_extension"; - public static final String BASE_SKIP_INELIGABLE_MOVEMENT = "skip_ineligable_movement"; - public static final String BASE_SKIP_INELIGABLE_FIRING = "skip_ineligable_firing"; - public static final String BASE_SKIP_INELIGABLE_PHYSICAL = "skip_ineligable_physical"; + public static final String BASE_SKIP_INELIGIBLE_MOVEMENT = "skip_ineligable_movement"; + public static final String BASE_SKIP_INELIGIBLE_FIRING = "skip_ineligable_firing"; + public static final String BASE_SKIP_INELIGIBLE_PHYSICAL = "skip_ineligable_physical"; public static final String BASE_PUSH_OFF_BOARD = "push_off_board"; public static final String BASE_TEAM_INITIATIVE = "team_initiative"; public static final String BASE_AUTOSAVE_MSG = "autosave_msg"; @@ -289,7 +289,7 @@ public class OptionsConstants { public static final String BASE_DUMPING_FROM_ROUND = "dumping_from_round"; public static final String BASE_SET_ARTY_PLAYER_HOMEEDGE = "set_arty_player_homeedge"; public static final String BASE_SET_DEFAULT_TEAM_1 = "set_default_team_1"; - public static final String BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0 = "set_player_deployment_to_player0"; + public static final String BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER_0 = "set_player_deployment_to_player0"; public static final String BASE_RESTRICT_GAME_COMMANDS = "restrict_game_commands"; public static final String BASE_DISABLE_LOCAL_SAVE = "disable_local_save"; public static final String BASE_BRIDGECF = "bridgeCF"; diff --git a/megamek/src/megamek/common/options/PartialRepairs.java b/megamek/src/megamek/common/options/PartialRepairs.java index 3db39acee0e..c8c35a51b5d 100644 --- a/megamek/src/megamek/common/options/PartialRepairs.java +++ b/megamek/src/megamek/common/options/PartialRepairs.java @@ -13,21 +13,17 @@ */ package megamek.common.options; -import megamek.common.Aero; -import megamek.common.Dropship; -import megamek.common.Entity; -import megamek.common.GunEmplacement; -import megamek.common.Jumpship; -import megamek.common.Mek; -import megamek.common.Tank; -import megamek.common.Warship; +import megamek.common.*; + +import java.io.Serial; /** * Contains the options for partial repair properties * * @author Neth (Thomas Pfau) */ -public class PartialRepairs extends AbstractOptions { +public class PartialRepairs extends AbstractOptionsImpl { + @Serial private static final long serialVersionUID = 7618380522964885742L; public static final String PART_REPAIRS = "PartRepairs"; @@ -133,7 +129,7 @@ public static boolean isPartRepLegalFor(IOption quirk, Entity en) { } private static class PartialRepairInfo extends AbstractOptionsInfo { - private static AbstractOptionsInfo instance = new PartialRepairInfo(); + private static final AbstractOptionsInfo instance = new PartialRepairInfo(); public static AbstractOptionsInfo getInstance() { return instance; diff --git a/megamek/src/megamek/common/options/PilotOptions.java b/megamek/src/megamek/common/options/PilotOptions.java index c080870853c..e7282c59784 100755 --- a/megamek/src/megamek/common/options/PilotOptions.java +++ b/megamek/src/megamek/common/options/PilotOptions.java @@ -14,6 +14,7 @@ package megamek.common.options; +import java.io.Serial; import java.util.Vector; /** @@ -21,7 +22,8 @@ * * @author Cord */ -public class PilotOptions extends AbstractOptions { +public class PilotOptions extends AbstractOptionsImpl { + @Serial private static final long serialVersionUID = 6628080570425023949L; public static final String LVL3_ADVANTAGES = "lvl3Advantages"; public static final String EDGE_ADVANTAGES = "edgeAdvantages"; @@ -191,12 +193,12 @@ protected AbstractOptionsInfo getOptionsInfoImp() { } private static class PilotOptionsInfo extends AbstractOptionsInfo { - private static boolean initliazed = false; - private static AbstractOptionsInfo instance = new PilotOptionsInfo(); + private static boolean initialized = false; + private static final AbstractOptionsInfo instance = new PilotOptionsInfo(); public static AbstractOptionsInfo getInstance() { - if (!initliazed) { - initliazed = true; + if (!initialized) { + initialized = true; // Create a new dummy PilotOptions; ensures values initialized // Otherwise, could have issues when loading saved games new PilotOptions(); diff --git a/megamek/src/megamek/common/options/Quirks.java b/megamek/src/megamek/common/options/Quirks.java index 663ffdea1ad..6dafb1cf0f6 100644 --- a/megamek/src/megamek/common/options/Quirks.java +++ b/megamek/src/megamek/common/options/Quirks.java @@ -16,6 +16,7 @@ import static java.util.stream.Collectors.toList; import static megamek.common.options.OptionsConstants.*; +import java.io.Serial; import java.util.List; import megamek.common.*; @@ -26,7 +27,8 @@ * * @author Taharqa (Jay Lawson) */ -public class Quirks extends AbstractOptions { +public class Quirks extends AbstractOptionsImpl { + @Serial private static final long serialVersionUID = 7618380522964885740L; public static final String POS_QUIRKS = "PosQuirks"; public static final String NEG_QUIRKS = "NegQuirks"; @@ -159,6 +161,10 @@ public List activeQuirks() { return getOptionsList().stream().filter(IOption::booleanValue).collect(toList()); } + public static boolean isQuirkDisallowed(IOption quirk, Entity en) { + return !isQuirkLegalFor(quirk, en); + } + public static boolean isQuirkLegalFor(IOption quirk, Entity en) { String qName = quirk.getName(); @@ -169,28 +175,21 @@ public static boolean isQuirkLegalFor(IOption quirk, Entity en) { } if (en instanceof Mek) { - switch (qName) { - case QUIRK_POS_BATTLE_FIST_LA: - return en.hasSystem(Mek.ACTUATOR_HAND, Mek.LOC_LARM); - case QUIRK_POS_BATTLE_FIST_RA: - return en.hasSystem(Mek.ACTUATOR_HAND, Mek.LOC_RARM); - case QUIRK_POS_BARREL_FIST_RA: - return en.hasSystem(Mek.ACTUATOR_LOWER_ARM, Mek.LOC_RARM) - && !en.hasSystem(Mek.ACTUATOR_HAND, Mek.LOC_RARM); - case QUIRK_POS_BARREL_FIST_LA: - return en.hasSystem(Mek.ACTUATOR_LOWER_ARM, Mek.LOC_LARM) - && !en.hasSystem(Mek.ACTUATOR_HAND, Mek.LOC_LARM); - case QUIRK_NEG_OVERSIZED: - return en.getWeight() >= 60; - case QUIRK_POS_COMPACT: - return en.getWeight() <= 55; - default: - return quirk.isNoneOf( - QUIRK_POS_ATMO_FLYER, QUIRK_NEG_ATMO_INSTABILITY, QUIRK_POS_DOCKING_ARMS, - QUIRK_NEG_FRAGILE_FUEL, QUIRK_POS_INTERNAL_BOMB, QUIRK_POS_TRAILER_HITCH, - QUIRK_NEG_LARGE_DROPPER, QUIRK_NEG_WEAK_UNDERCARRIAGE, QUIRK_POS_VTOL_ROTOR_COAXIAL, - QUIRK_POS_VTOL_ROTOR_DUAL, QUIRK_POS_POWER_REVERSE, QUIRK_NEG_UNSTREAMLINED); - } + return switch (qName) { + case QUIRK_POS_BATTLE_FIST_LA -> en.hasSystem(Mek.ACTUATOR_HAND, Mek.LOC_LARM); + case QUIRK_POS_BATTLE_FIST_RA -> en.hasSystem(Mek.ACTUATOR_HAND, Mek.LOC_RARM); + case QUIRK_POS_BARREL_FIST_RA -> en.hasSystem(Mek.ACTUATOR_LOWER_ARM, Mek.LOC_RARM) + && !en.hasSystem(Mek.ACTUATOR_HAND, Mek.LOC_RARM); + case QUIRK_POS_BARREL_FIST_LA -> en.hasSystem(Mek.ACTUATOR_LOWER_ARM, Mek.LOC_LARM) + && !en.hasSystem(Mek.ACTUATOR_HAND, Mek.LOC_LARM); + case QUIRK_NEG_OVERSIZED -> en.getWeight() >= 60; + case QUIRK_POS_COMPACT -> en.getWeight() <= 55; + default -> quirk.isNoneOf( + QUIRK_POS_ATMO_FLYER, QUIRK_NEG_ATMO_INSTABILITY, QUIRK_POS_DOCKING_ARMS, + QUIRK_NEG_FRAGILE_FUEL, QUIRK_POS_INTERNAL_BOMB, QUIRK_POS_TRAILER_HITCH, + QUIRK_NEG_LARGE_DROPPER, QUIRK_NEG_WEAK_UNDERCARRIAGE, QUIRK_POS_VTOL_ROTOR_COAXIAL, + QUIRK_POS_VTOL_ROTOR_DUAL, QUIRK_POS_POWER_REVERSE, QUIRK_NEG_UNSTREAMLINED); + }; } if (en instanceof Tank) { @@ -206,32 +205,25 @@ public static boolean isQuirkLegalFor(IOption quirk, Entity en) { QUIRK_NEG_SENSOR_GHOSTS); } - switch (qName) { - case QUIRK_POS_POWER_REVERSE: - return en.getMovementMode().isTrackedOrWheeled() && !en.isSupportVehicle(); - case QUIRK_NEG_FRAGILE_FUEL: - return (en.hasEngine() && en.getEngine().isICE()); - case QUIRK_POS_TRAILER_HITCH: - return !(en.getMovementMode().isHover() || en.getMovementMode().isVTOL()); - case QUIRK_POS_SCOUT_BIKE: - return (en.getMovementMode().isHover() || en.getMovementMode().isWheeled()) - && (en.getWeight() <= 10.0); - case QUIRK_POS_VTOL_ROTOR_COAXIAL: - case QUIRK_POS_VTOL_ROTOR_DUAL: - return en instanceof VTOL; - default: - return quirk.isAnyOf( - QUIRK_POS_ANTI_AIR, QUIRK_POS_BATTLE_COMP, QUIRK_POS_EASY_MAINTAIN, - QUIRK_POS_FAST_RELOAD, QUIRK_POS_GOOD_REP_1, QUIRK_POS_GOOD_REP_2, - QUIRK_POS_IMP_COM, QUIRK_POS_IMPROVED_SENSORS, - QUIRK_POS_IMP_TARG_S, QUIRK_POS_SEARCHLIGHT, - QUIRK_POS_IMP_TARG_M, QUIRK_POS_IMP_TARG_L, QUIRK_POS_LOW_PROFILE, - QUIRK_NEG_BAD_REP_IS, QUIRK_NEG_BAD_REP_CLAN, QUIRK_NEG_DIFFICULT_MAINTAIN, - QUIRK_NEG_NON_STANDARD, QUIRK_NEG_POOR_PERFORMANCE, QUIRK_NEG_HARD_PILOT, - QUIRK_NEG_POOR_TARG_S, QUIRK_NEG_POOR_TARG_M, QUIRK_NEG_POOR_TARG_L, - QUIRK_NEG_POOR_WORK, QUIRK_NEG_PROTOTYPE, QUIRK_NEG_SENSOR_GHOSTS, - QUIRK_POS_UBIQUITOUS_IS, QUIRK_POS_UBIQUITOUS_CLAN); - } + return switch (qName) { + case QUIRK_POS_POWER_REVERSE -> en.getMovementMode().isTrackedOrWheeled() && !en.isSupportVehicle(); + case QUIRK_NEG_FRAGILE_FUEL -> (en.hasEngine() && en.getEngine().isICE()); + case QUIRK_POS_TRAILER_HITCH -> !(en.getMovementMode().isHover() || en.getMovementMode().isVTOL()); + case QUIRK_POS_SCOUT_BIKE -> (en.getMovementMode().isHover() || en.getMovementMode().isWheeled()) + && (en.getWeight() <= 10.0); + case QUIRK_POS_VTOL_ROTOR_COAXIAL, QUIRK_POS_VTOL_ROTOR_DUAL -> en instanceof VTOL; + default -> quirk.isAnyOf( + QUIRK_POS_ANTI_AIR, QUIRK_POS_BATTLE_COMP, QUIRK_POS_EASY_MAINTAIN, + QUIRK_POS_FAST_RELOAD, QUIRK_POS_GOOD_REP_1, QUIRK_POS_GOOD_REP_2, + QUIRK_POS_IMP_COM, QUIRK_POS_IMPROVED_SENSORS, + QUIRK_POS_IMP_TARG_S, QUIRK_POS_SEARCHLIGHT, + QUIRK_POS_IMP_TARG_M, QUIRK_POS_IMP_TARG_L, QUIRK_POS_LOW_PROFILE, + QUIRK_NEG_BAD_REP_IS, QUIRK_NEG_BAD_REP_CLAN, QUIRK_NEG_DIFFICULT_MAINTAIN, + QUIRK_NEG_NON_STANDARD, QUIRK_NEG_POOR_PERFORMANCE, QUIRK_NEG_HARD_PILOT, + QUIRK_NEG_POOR_TARG_S, QUIRK_NEG_POOR_TARG_M, QUIRK_NEG_POOR_TARG_L, + QUIRK_NEG_POOR_WORK, QUIRK_NEG_PROTOTYPE, QUIRK_NEG_SENSOR_GHOSTS, + QUIRK_POS_UBIQUITOUS_IS, QUIRK_POS_UBIQUITOUS_CLAN); + }; } if (en instanceof BattleArmor) { diff --git a/megamek/src/megamek/common/options/SBFRuleOptions.java b/megamek/src/megamek/common/options/SBFRuleOptions.java index 0c406dc1cc8..7933cc816ef 100644 --- a/megamek/src/megamek/common/options/SBFRuleOptions.java +++ b/megamek/src/megamek/common/options/SBFRuleOptions.java @@ -23,7 +23,7 @@ public class SBFRuleOptions extends BasicGameOptions { - /** Detection and recon rules aka "double blind", IO BF p.195 */ + /** Detection and recon rules aka "double-blind", IO BF p.195 */ public static final String BASE_RECON = "base_recon"; /** When using detection and recon rules, players on a team share their vision */ @@ -61,10 +61,10 @@ public class SBFRuleOptions extends BasicGameOptions { public static final String INIT_BATTLEFIELD_INT = "init_battlefield_int"; /** Banking initiative, IO BF p.223 IS AN SCA */ -// public static final String INIT_BANKING = "init_banking"; + public static final String INIT_BANKING = "init_banking"; /** Forcing initiative, IO BF p.223 */ -// public static final String INIT_FORCING = "init_forcing"; + public static final String INIT_FORCING = "init_forcing"; @Override public synchronized void initialize() { diff --git a/megamek/src/megamek/common/options/WeaponQuirks.java b/megamek/src/megamek/common/options/WeaponQuirks.java index ebf54230013..4cee2816561 100644 --- a/megamek/src/megamek/common/options/WeaponQuirks.java +++ b/megamek/src/megamek/common/options/WeaponQuirks.java @@ -17,6 +17,7 @@ import megamek.common.weapons.AmmoWeapon; import megamek.common.weapons.lasers.EnergyWeapon; +import java.io.Serial; import java.util.List; import static java.util.stream.Collectors.toList; @@ -28,8 +29,8 @@ * * @author Taharqa (Jay Lawson) */ -public class WeaponQuirks extends AbstractOptions { - +public class WeaponQuirks extends AbstractOptionsImpl { + @Serial private static final long serialVersionUID = -8455685281028804229L; public static final String WPN_QUIRKS = "WeaponQuirks"; @@ -84,72 +85,62 @@ public List activeQuirks() { return getOptionsList().stream().filter(IOption::booleanValue).collect(toList()); } - public static boolean isQuirkLegalFor(IOption quirk, Entity en, - EquipmentType etype) { + public static boolean isQuirkDisallowed(IOption quirk, Entity en, + EquipmentType equipmentType) { String qName = quirk.getName(); // There may be some non-WeaponType quirks, specifically melee weapons - if (!(etype instanceof WeaponType) && !etype.hasFlag(MiscType.F_CLUB)) { - return false; - } else if (etype.hasFlag(MiscType.F_CLUB)) { - if (qName.equals(OptionsConstants.QUIRK_WEAP_NEG_AMMO_FEED_PROBLEMS) - || qName.equals(OptionsConstants.QUIRK_WEAP_NEG_EM_INTERFERENCE) - || qName.equals(OptionsConstants.QUIRK_WEAP_NEG_NO_COOLING) - || qName.equals(OptionsConstants.QUIRK_WEAP_NEG_POOR_COOLING) - || qName.equals(OptionsConstants.QUIRK_WEAP_NEG_STATIC_FEED) - || qName.equals(OptionsConstants.QUIRK_WEAP_POS_IMP_COOLING) - || qName.equals(OptionsConstants.QUIRK_WEAP_POS_FAST_RELOAD)) { - return false; - } + if (!(equipmentType instanceof WeaponType) && !equipmentType.hasFlag(MiscType.F_CLUB)) { return true; + } else if (equipmentType.hasFlag(MiscType.F_CLUB)) { + return qName.equals(OptionsConstants.QUIRK_WEAP_NEG_AMMO_FEED_PROBLEMS) + || qName.equals(OptionsConstants.QUIRK_WEAP_NEG_EM_INTERFERENCE) + || qName.equals(OptionsConstants.QUIRK_WEAP_NEG_NO_COOLING) + || qName.equals(OptionsConstants.QUIRK_WEAP_NEG_POOR_COOLING) + || qName.equals(OptionsConstants.QUIRK_WEAP_NEG_STATIC_FEED) + || qName.equals(OptionsConstants.QUIRK_WEAP_POS_IMP_COOLING) + || qName.equals(OptionsConstants.QUIRK_WEAP_POS_FAST_RELOAD); + } + if (!(equipmentType instanceof WeaponType weaponType)) { + throw new IllegalArgumentException("EquipmentType must be a WeaponType"); } - // Anything else is a WeaponType - WeaponType wtype = (WeaponType) etype; - - if (!(wtype instanceof AmmoWeapon)) { - if (qName.equals(OptionsConstants.QUIRK_WEAP_NEG_AMMO_FEED_PROBLEMS)) { - return false; - } - if (qName.equals(OptionsConstants.QUIRK_WEAP_NEG_STATIC_FEED)) { - return false; - } - if (qName.equals(OptionsConstants.QUIRK_WEAP_POS_FAST_RELOAD)) { - return false; + if (!(weaponType instanceof AmmoWeapon)) { + switch (qName) { + case OptionsConstants.QUIRK_WEAP_NEG_AMMO_FEED_PROBLEMS, + OptionsConstants.QUIRK_WEAP_NEG_STATIC_FEED, + OptionsConstants.QUIRK_WEAP_POS_FAST_RELOAD -> { + return true; + } } } - if (!(wtype instanceof EnergyWeapon) && qName.equals(OptionsConstants.QUIRK_WEAP_NEG_EM_INTERFERENCE)) { - return false; + if (!(weaponType instanceof EnergyWeapon) && qName.equals(OptionsConstants.QUIRK_WEAP_NEG_EM_INTERFERENCE)) { + return true; } -/* if ((wtype instanceof EnergyWeapon) && qName.equals(OptionsConstants.QUIRK_WEAP_POS_FAST_RELOAD)) { - return false; - }*/ - if (en instanceof ProtoMek) { if (qName.equals(OptionsConstants.QUIRK_WEAP_POS_FAST_RELOAD) || qName.equals(OptionsConstants.QUIRK_WEAP_NEG_STATIC_FEED)) { - return false; + return true; } } + boolean hasBadCoolingQuirk = qName.equals(OptionsConstants.QUIRK_WEAP_POS_IMP_COOLING) + || qName.equals(OptionsConstants.QUIRK_WEAP_NEG_POOR_COOLING) + || qName.equals(OptionsConstants.QUIRK_WEAP_NEG_NO_COOLING); if (en instanceof Tank || en instanceof BattleArmor || en instanceof ProtoMek) { - if (qName.equals(OptionsConstants.QUIRK_WEAP_POS_IMP_COOLING) - || qName.equals(OptionsConstants.QUIRK_WEAP_NEG_POOR_COOLING) - || qName.equals(OptionsConstants.QUIRK_WEAP_NEG_NO_COOLING)) { - return false; + if (hasBadCoolingQuirk) { + return true; } } if (en.isConventionalInfantry()) { - return false; + return true; } - if (wtype.getHeat() == 0) { - if (qName.equals(OptionsConstants.QUIRK_WEAP_POS_IMP_COOLING) - || qName.equals(OptionsConstants.QUIRK_WEAP_NEG_POOR_COOLING) - || qName.equals(OptionsConstants.QUIRK_WEAP_NEG_NO_COOLING)) { - return false; + if (weaponType.getHeat() == 0) { + if (hasBadCoolingQuirk) { + return true; } } @@ -158,45 +149,45 @@ public static boolean isQuirkLegalFor(IOption quirk, Entity en, || en instanceof Aero || en instanceof GunEmplacement) { - return false; + return true; } } if (qName.equals(OptionsConstants.QUIRK_WEAP_POS_MOD_WEAPONS)) { if ((en instanceof ProtoMek) || (en instanceof Jumpship)) { - return false; + return true; } } if (qName.equals(OptionsConstants.QUIRK_WEAP_POS_DIRECT_TORSO_MOUNT)) { if ((en instanceof Aero) || (en instanceof BattleArmor) || (en instanceof Tank)) { - return false; + return true; } } if (qName.equals(OptionsConstants.QUIRK_WEAP_POS_STABLE_WEAPON)) { if (en instanceof Aero) { - return false; + return true; } } if (qName.equals(OptionsConstants.QUIRK_WEAP_NEG_EXPOSED_LINKAGE)) { if (en instanceof Aero) { - return false; + return true; } } if (qName.equals(OptionsConstants.QUIRK_WEAP_NEG_EM_INTERFERENCE)) { if (en instanceof Jumpship) { - return false; + return true; } } - return true; + return false; } private static class WeaponQuirksInfo extends AbstractOptionsInfo { - private static AbstractOptionsInfo instance = new WeaponQuirksInfo(); + private static final AbstractOptionsInfo instance = new WeaponQuirksInfo(); public static AbstractOptionsInfo getInstance() { return instance; diff --git a/megamek/src/megamek/common/pathfinder/AeroGroundPathFinder.java b/megamek/src/megamek/common/pathfinder/AeroGroundPathFinder.java index 49d94b69365..5613e8d4b47 100644 --- a/megamek/src/megamek/common/pathfinder/AeroGroundPathFinder.java +++ b/megamek/src/megamek/common/pathfinder/AeroGroundPathFinder.java @@ -14,23 +14,14 @@ */ package megamek.common.pathfinder; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import megamek.client.bot.princess.AeroPathUtil; -import megamek.common.Coords; -import megamek.common.Entity; -import megamek.common.Game; -import megamek.common.IAero; -import megamek.common.MovePath; +import megamek.common.*; import megamek.common.MovePath.MoveStepType; -import megamek.common.MoveStep; import megamek.common.pathfinder.AbstractPathFinder.Filter; import megamek.logging.MMLogger; +import java.util.*; + /** * This set of classes is intended for use for pathfinding by aerodyne units on * ground maps with an atmosphere @@ -275,7 +266,7 @@ protected List GenerateAllPaths(MovePath mp) { for (MovePath path : generateSidePaths(mp, MoveStepType.TURN_RIGHT)) { // we want to avoid adding paths that don't visit new hexes // off-board paths will get thrown out later - if (path.fliesOffBoard() || !pathIsRedundant(path)) { + if (path.fliesOffBoard() || pathIsntRedundant(path)) { retval.add(path); } } @@ -283,13 +274,13 @@ protected List GenerateAllPaths(MovePath mp) { for (MovePath path : generateSidePaths(mp, MoveStepType.TURN_LEFT)) { // we want to avoid adding paths that don't visit new hexes // off-board paths will get thrown out later - if (path.fliesOffBoard() || !pathIsRedundant(path)) { + if (path.fliesOffBoard() || pathIsntRedundant(path)) { retval.add(path); } } ForwardToTheEnd(mp); - if (mp.fliesOffBoard() || !pathIsRedundant(mp)) { + if (mp.fliesOffBoard() || pathIsntRedundant(mp)) { retval.add(mp); } @@ -302,8 +293,8 @@ protected List generateSidePaths(MovePath mp, MoveStepType stepType) { List retval = new ArrayList<>(); MovePath straightLine = mp.clone(); - if (logger.isDebugEnabled() && STACK_DEPTH - mp.length() < 10) { - logger.debug("Aero pathing stack depth: " + mp.length() + " (out of " + STACK_DEPTH + ")"); + if (STACK_DEPTH - mp.length() < 10) { + logger.debug("Aero pathing stack depth: {} (out of {})", mp.length(), STACK_DEPTH); } boolean firstTurn = true; @@ -413,7 +404,11 @@ protected void ForwardToTheEnd(MovePath mp) { } } - private Map visitedCoords = new HashMap<>(); + private final Map visitedCoords = new HashMap<>(); + + protected boolean pathIsntRedundant(MovePath mp) { + return !pathIsRedundant(mp); + } /** * Determines if the given move path is "redundant". diff --git a/megamek/src/megamek/common/scenario/ScenarioV2.java b/megamek/src/megamek/common/scenario/ScenarioV2.java index 46f3de99cc1..e24344a310f 100644 --- a/megamek/src/megamek/common/scenario/ScenarioV2.java +++ b/megamek/src/megamek/common/scenario/ScenarioV2.java @@ -43,6 +43,7 @@ import megamek.common.icons.Camouflage; import megamek.common.icons.FileCamouflage; import megamek.common.jacksonadapters.*; +import megamek.common.options.GameOptions; import megamek.common.planetaryconditions.PlanetaryConditions; import megamek.common.strategicBattleSystems.SBFGame; import megamek.logging.MMLogger; @@ -223,14 +224,15 @@ private void parsePlayers(IGame game) throws ScenarioLoaderException, IOExceptio } private void parseOptions(IGame game) { - game.getOptions().initialize(); + var gameOptions = ((GameOptions) game.getOptions()); + gameOptions.initialize(); if (node.has(OPTIONS)) { JsonNode optionsNode = node.get(OPTIONS); if (optionsNode.has(OPTIONS_FILE)) { File optionsFile = new File(scenariofile.getParentFile(), optionsNode.get(OPTIONS_FILE).textValue()); - game.getOptions().loadOptions(optionsFile, true); + gameOptions.loadOptions(optionsFile, true); } else { - game.getOptions().loadOptions(); + gameOptions.loadOptions(); } if (optionsNode.has(OPTIONS_ON)) { diff --git a/megamek/src/megamek/common/util/EmailService.java b/megamek/src/megamek/common/util/EmailService.java index 516a41095f8..49c364c4b4c 100644 --- a/megamek/src/megamek/common/util/EmailService.java +++ b/megamek/src/megamek/common/util/EmailService.java @@ -106,19 +106,17 @@ private static String newMessageId(InternetAddress from, } - private InternetAddress from; - private Map messageSequences = new HashMap<>(); - private Properties mailProperties; - private Session mailSession; + private final InternetAddress from; + private final Map messageSequences = new HashMap<>(); + private final Session mailSession; - private BlockingQueue mailQueue = new LinkedBlockingQueue<>(); - private Thread mailWorker; + private final BlockingQueue mailQueue = new LinkedBlockingQueue<>(); + private final Thread mailWorker; private boolean running = true; public EmailService(Properties mailProperties) throws Exception { this.from = InternetAddress.parse( mailProperties.getProperty("megamek.smtp.from", ""))[0]; - this.mailProperties = mailProperties; Authenticator auth = null; var login = mailProperties.getProperty("megamek.smtp.login", "").trim(); diff --git a/megamek/src/megamek/common/util/SerializationHelper.java b/megamek/src/megamek/common/util/SerializationHelper.java index 23c6670d1fc..edf2e428629 100644 --- a/megamek/src/megamek/common/util/SerializationHelper.java +++ b/megamek/src/megamek/common/util/SerializationHelper.java @@ -27,6 +27,7 @@ import megamek.common.Coords; import megamek.common.net.marshalling.SanityInputFilter; +import megamek.common.options.AbstractOptionsImpl; import megamek.server.victory.VictoryCondition; /** @@ -60,7 +61,7 @@ public static XStream getSaveGameXStream() { xStream.allowTypeHierarchy(megamek.common.Mounted.class); xStream.allowTypeHierarchy(megamek.common.actions.EntityAction.class); xStream.allowTypeHierarchy(megamek.common.icons.AbstractIcon.class); - xStream.allowTypeHierarchy(megamek.common.options.AbstractOptions.class); + xStream.allowTypeHierarchy(AbstractOptionsImpl.class); xStream.allowTypeHierarchy(megamek.common.options.IOption.class); xStream.allowTypeHierarchy(megamek.common.weapons.AttackHandler.class); xStream.allowTypeHierarchy(VictoryCondition.class); diff --git a/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectHomingHandler.java b/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectHomingHandler.java index a5dd62249f7..1b0dde239e6 100644 --- a/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectHomingHandler.java +++ b/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectHomingHandler.java @@ -19,11 +19,6 @@ */ package megamek.common.weapons; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Vector; - import megamek.common.*; import megamek.common.actions.ArtilleryAttackAction; import megamek.common.actions.WeaponAttackAction; @@ -32,25 +27,32 @@ import megamek.logging.MMLogger; import megamek.server.totalwarfare.TWGameManager; +import java.io.Serial; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Vector; + public class ArtilleryWeaponIndirectHomingHandler extends ArtilleryWeaponIndirectFireHandler { private static final MMLogger logger = MMLogger.create(ArtilleryBayWeaponIndirectHomingHandler.class); + @Serial private static final long serialVersionUID = -7243477723032010917L; boolean amsEngaged = false; boolean apdsEngaged = false; - boolean advancedAMS = false; - boolean advancedPD = false; + boolean advancedAMS; + boolean advancedPD; /** - * @param t - * @param w - * @param g + * @param toHitData + * @param weaponAttackAction + * @param game */ - public ArtilleryWeaponIndirectHomingHandler(ToHitData t, - WeaponAttackAction w, Game g, TWGameManager m) { - super(t, w, g, m); - advancedAMS = g.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_AMS); - advancedPD = g.getOptions().booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_ADV_POINTDEF); + public ArtilleryWeaponIndirectHomingHandler(ToHitData toHitData, + WeaponAttackAction weaponAttackAction, Game game, TWGameManager gameManager) { + super(toHitData, weaponAttackAction, game, gameManager); + advancedAMS = game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_AMS); + advancedPD = game.getOptions().booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_ADV_POINTDEF); } /* @@ -225,17 +227,13 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if ((bldg != null) && (bldgAbsorbs > 0)) { // building absorbs some damage r = new Report(6010); - if (entityTarget != null) { - r.subject = entityTarget.getId(); - } + r.subject = entityTarget.getId(); r.add(bldgAbsorbs); vPhaseReport.addElement(r); Vector buildingReport = gameManager.damageBuilding(bldg, nDamPerHit, target.getPosition()); - if (entityTarget != null) { - for (Report report : buildingReport) { - report.subject = entityTarget.getId(); - } + for (Report report : buildingReport) { + report.subject = entityTarget.getId(); } vPhaseReport.addAll(buildingReport); } @@ -310,7 +308,6 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { * Uses a CFR to let the player choose from eligible TAG */ public void convertHomingShotToEntityTarget() { - boolean debug = logger.isDebugEnabled(); ArtilleryAttackAction aaa = (ArtilleryAttackAction) waa; final Coords tc = target.getPosition(); @@ -352,11 +349,9 @@ public void convertHomingShotToEntityTarget() { newTarget = ti.target; if (!ti.missed && (newTarget != null)) { v.add(ti); - if (debug) { - logger.debug(new StringBuilder("Found valid TAG on target ") - .append(ti.target.getDisplayName()).append("; Range to original target is ") - .append(tc.distance(ti.target.getPosition()))); - } + logger.debug(new StringBuilder("Found valid TAG on target ") + .append(ti.target.getDisplayName()).append("; Range to original target is ") + .append(tc.distance(ti.target.getPosition()))); } } @@ -428,10 +423,7 @@ protected boolean handleSpecialMiss(Entity entityTarget, @Override protected boolean checkPDConditions() { advancedPD = game.getOptions().booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_ADV_POINTDEF); - if ((target == null) || !advancedPD || (target.getTargetType() != Targetable.TYPE_ENTITY)) { - return false; - } - return true; + return (target != null) && advancedPD && (target.getTargetType() == Targetable.TYPE_ENTITY); } /** @@ -458,11 +450,6 @@ protected int calcCapMissileAMSMod() { return CapMissileAMSMod; } - @Override - protected int getCapMissileAMSMod() { - return CapMissileAMSMod; - } - protected int handleAMS(Vector vPhaseReport) { int hits = 1; @@ -473,7 +460,7 @@ protected int handleAMS(Vector vPhaseReport) { // target gameManager.assignAMS(); calcCounterAV(); - // Report AMS/Pointdefense failure due to Overheating. + // Report AMS/Point-defense failure due to Overheating. if (pdOverheated && (!(amsBayEngaged || amsBayEngagedCap diff --git a/megamek/src/megamek/common/weapons/CLIATMWeapon.java b/megamek/src/megamek/common/weapons/CLIATMWeapon.java index 75f49ded90a..6281b1e36d0 100644 --- a/megamek/src/megamek/common/weapons/CLIATMWeapon.java +++ b/megamek/src/megamek/common/weapons/CLIATMWeapon.java @@ -26,7 +26,7 @@ import megamek.common.TechAdvancement; import megamek.common.ToHitData; import megamek.common.actions.WeaponAttackAction; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.weapons.missiles.MissileWeapon; import megamek.server.totalwarfare.TWGameManager; @@ -101,11 +101,11 @@ public boolean hasIndirectFire() { } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Indirect Fire - if (gOp.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { addMode(""); addMode("Indirect"); } else { diff --git a/megamek/src/megamek/common/weapons/Weapon.java b/megamek/src/megamek/common/weapons/Weapon.java index 6ebb4c41ef2..d5932baa674 100644 --- a/megamek/src/megamek/common/weapons/Weapon.java +++ b/megamek/src/megamek/common/weapons/Weapon.java @@ -1,14 +1,14 @@ /* * MegaMek - Copyright (C) 2004, 2005 Ben Mazur (bmazur@sev.org) * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) * any later version. * - * This program 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 + * This program 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. */ package megamek.common.weapons; @@ -16,7 +16,7 @@ import megamek.common.*; import megamek.common.actions.WeaponAttackAction; import megamek.common.annotations.Nullable; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.weapons.bayweapons.CapitalLaserBayWeapon; import megamek.common.weapons.bayweapons.SubCapLaserBayWeapon; @@ -26,7 +26,7 @@ /** * A class representing a weapon. - * @author Andrew Hunter + * @author Andrew Hunter * @since May 10, 2004 */ public abstract class Weapon extends WeaponType implements Serializable { @@ -36,34 +36,34 @@ public Weapon() { this.ammoType = AmmoType.T_NA; this.minimumRange = WEAPON_NA; } - + //Mode text tokens public static final String MODE_FLAMER_DAMAGE = "Damage"; public static final String MODE_FLAMER_HEAT = "Heat"; - + public static final String MODE_AMS_ON = "On"; public static final String MODE_AMS_OFF = "Off"; public static final String MODE_AMS_MANUAL = "Use as Weapon"; - + public static final String MODE_CAP_LASER_AAA = "AAA"; - + public static final String MODE_CAPITAL_BRACKET_80 = "Bracket 80%"; public static final String MODE_CAPITAL_BRACKET_60 = "Bracket 60%"; public static final String MODE_CAPITAL_BRACKET_40 = "Bracket 40%"; - + public static final String MODE_CAP_MISSILE_WAYPOINT_BEARING_EXT = "Waypoint Launch Bearings-Only Extreme Detection Range"; public static final String MODE_CAP_MISSILE_WAYPOINT_BEARING_LONG = "Waypoint Launch Bearings-Only Long Detection Range"; public static final String MODE_CAP_MISSILE_WAYPOINT_BEARING_MED = "Waypoint Launch Bearings-Only Medium Detection Range"; public static final String MODE_CAP_MISSILE_WAYPOINT_BEARING_SHORT = "Waypoint Launch Bearings-Only Short Detection Range"; public static final String MODE_CAP_MISSILE_WAYPOINT = "Waypoint Launch"; - + public static final String MODE_CAP_MISSILE_BEARING_EXT = "Bearings-Only Extreme Detection Range"; public static final String MODE_CAP_MISSILE_BEARING_LONG = "Bearings-Only Long Detection Range"; public static final String MODE_CAP_MISSILE_BEARING_MED = "Bearings-Only Medium Detection Range"; public static final String MODE_CAP_MISSILE_BEARING_SHORT = "Bearings-Only Short Detection Range"; - + public static final String MODE_CAP_MISSILE_TELE_OPERATED = "Tele-Operated"; - + public static final String MODE_AC_RAPID = "Rapid"; public static final String MODE_AC_SINGLE = "Single"; public static final String MODE_UAC_ULTRA = "Ultra"; @@ -72,18 +72,18 @@ public Weapon() { public static final String MODE_RAC_FOUR_SHOT = "4-shot"; public static final String MODE_RAC_FIVE_SHOT = "5-shot"; public static final String MODE_RAC_SIX_SHOT = "6-shot"; - + public static final String MODE_GAUSS_POWERED_DOWN = "Powered Down"; - + public static final String MODE_MISSILE_INDIRECT = "Indirect"; public static final String MODE_INDIRECT_HEAT = "Indirect/Heat"; - + public static final String MODE_PPC_CHARGE = "Charge"; - + public static final String MODE_POINT_DEFENSE = "Point Defense"; - + public static final String MODE_NORMAL = "Normal"; - + public @Nullable AttackHandler fire(WeaponAttackAction waa, Game game, TWGameManager gameManager) { ToHitData toHit = waa.toHit(game); @@ -99,21 +99,21 @@ protected AttackHandler getCorrectHandler(ToHitData toHit, WeaponAttackAction waa, Game game, TWGameManager gameManager) { return new WeaponHandler(toHit, waa, game, gameManager); } - + /** * Adapt the weapon type to the Game Options such as * PPC Field Inhibitors or Dial Down Damage, usually * adding or removing modes. When overriding this in a * weapon subclass, call super()! - * - * @param gOp The GameOptions (game.getOptions()) + * + * @param gameOptions The GameOptions (game.getOptions()) * @author Simon (Juliez) */ - public void adaptToGameOptions(GameOptions gOp) { + public void adaptToGameOptions(IGameOptions gameOptions) { // Flamers are spread out over all sorts of weapon types not limited to FlamerWeapon. - // Therefore modes are handled here. + // So modes are handled here. if (hasFlag(WeaponType.F_FLAMER)) { - if (!gOp.booleanOption(OptionsConstants.BASE_FLAMER_HEAT)) { + if (!gameOptions.booleanOption(OptionsConstants.BASE_FLAMER_HEAT)) { addMode(MODE_FLAMER_DAMAGE); addMode(MODE_FLAMER_HEAT); } else { @@ -121,7 +121,7 @@ public void adaptToGameOptions(GameOptions gOp) { removeMode(MODE_FLAMER_HEAT); } } - + // Capital weapons are spread out over all sorts of weapons. if (isCapital()) { if ((getAtClass() != WeaponType.CLASS_CAPITAL_MISSILE) @@ -130,7 +130,7 @@ public void adaptToGameOptions(GameOptions gOp) { if ((this instanceof CapitalLaserBayWeapon) || (this instanceof SubCapLaserBayWeapon)) { - if (gOp.booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_AAA_LASER)) { + if (gameOptions.booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_AAA_LASER)) { addMode(""); addMode("AAA"); addEndTurnMode("AAA"); @@ -138,7 +138,7 @@ public void adaptToGameOptions(GameOptions gOp) { removeMode("AAA"); } } - if (gOp.booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_BRACKET_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_BRACKET_FIRE)) { addMode(""); addMode("Bracket 80%"); addMode("Bracket 60%"); @@ -159,12 +159,12 @@ public void adaptToGameOptions(GameOptions gOp) { addMode(MODE_NORMAL); addMode(MODE_CAP_MISSILE_TELE_OPERATED); } - - if (gOp.booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_WAYPOINT_LAUNCH)) { + + if (gameOptions.booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_WAYPOINT_LAUNCH)) { setInstantModeSwitch(true); addMode(MODE_NORMAL); addMode(MODE_CAP_MISSILE_WAYPOINT); - if (gOp.booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_BEARINGS_ONLY_LAUNCH)) { + if (gameOptions.booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_BEARINGS_ONLY_LAUNCH)) { addMode(MODE_CAP_MISSILE_WAYPOINT_BEARING_EXT); addMode(MODE_CAP_MISSILE_WAYPOINT_BEARING_LONG); addMode(MODE_CAP_MISSILE_WAYPOINT_BEARING_MED); @@ -179,7 +179,7 @@ public void adaptToGameOptions(GameOptions gOp) { removeMode(MODE_CAP_MISSILE_WAYPOINT); } - if (gOp.booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_BEARINGS_ONLY_LAUNCH)) { + if (gameOptions.booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_BEARINGS_ONLY_LAUNCH)) { setInstantModeSwitch(true); addMode(MODE_NORMAL); addMode(MODE_CAP_MISSILE_BEARING_EXT); @@ -196,10 +196,10 @@ public void adaptToGameOptions(GameOptions gOp) { } if (hasFlag(WeaponType.F_AMS)) { - if (gOp.booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_MANUAL_AMS)) { + if (gameOptions.booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_MANUAL_AMS)) { addMode(Weapon.MODE_AMS_MANUAL); } - if (gOp.booleanOption(OptionsConstants.BASE_AUTO_AMS)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_AUTO_AMS)) { removeMode("Automatic"); } else { addMode("Automatic"); diff --git a/megamek/src/megamek/common/weapons/artillery/ArtilleryCannonWeapon.java b/megamek/src/megamek/common/weapons/artillery/ArtilleryCannonWeapon.java index f4cf89c7d6f..3071dfa2686 100644 --- a/megamek/src/megamek/common/weapons/artillery/ArtilleryCannonWeapon.java +++ b/megamek/src/megamek/common/weapons/artillery/ArtilleryCannonWeapon.java @@ -16,7 +16,7 @@ import megamek.common.Game; import megamek.common.ToHitData; import megamek.common.actions.WeaponAttackAction; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.weapons.AmmoWeapon; import megamek.common.weapons.ArtilleryCannonWeaponHandler; @@ -64,11 +64,11 @@ protected AttackHandler getCorrectHandler(ToHitData toHit, } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Indirect Fire - if (gOp.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { addMode(""); addMode("Indirect"); } else { diff --git a/megamek/src/megamek/common/weapons/autocannons/ACWeapon.java b/megamek/src/megamek/common/weapons/autocannons/ACWeapon.java index 838d3942184..cbc44e8df15 100644 --- a/megamek/src/megamek/common/weapons/autocannons/ACWeapon.java +++ b/megamek/src/megamek/common/weapons/autocannons/ACWeapon.java @@ -25,7 +25,7 @@ import megamek.common.ToHitData; import megamek.common.actions.WeaponAttackAction; import megamek.common.alphaStrike.AlphaStrikeElement; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.IOption; import megamek.common.options.OptionsConstants; import megamek.common.weapons.*; @@ -125,11 +125,11 @@ public int getBattleForceClass() { } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Modes for allowing standard and light AC rapid fire - IOption rapidAc = gOp.getOption(OptionsConstants.ADVCOMBAT_TACOPS_RAPID_AC); + IOption rapidAc = gameOptions.getOption(OptionsConstants.ADVCOMBAT_TACOPS_RAPID_AC); if ((rapidAc != null) && rapidAc.booleanValue()) { addMode(""); addMode(Weapon.MODE_AC_RAPID); diff --git a/megamek/src/megamek/common/weapons/battlearmor/CLBAMortarHeavy.java b/megamek/src/megamek/common/weapons/battlearmor/CLBAMortarHeavy.java index 7b771a47b1a..4562d1c4b3a 100644 --- a/megamek/src/megamek/common/weapons/battlearmor/CLBAMortarHeavy.java +++ b/megamek/src/megamek/common/weapons/battlearmor/CLBAMortarHeavy.java @@ -18,14 +18,14 @@ import megamek.common.Mounted; import megamek.common.WeaponType; import megamek.common.alphaStrike.AlphaStrikeElement; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.weapons.Weapon; /** * Added per IO Pg 53 - Tech Manual shows this is an IS weapon only * But IO seems to have made this a Clan weapon as well - * + * * @author Sebastian Brocks * @since Sep 24, 2004 */ @@ -74,11 +74,11 @@ public boolean hasIndirectFire() { } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Indirect Fire - if (gOp.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { addMode(""); addMode("Indirect"); } else { diff --git a/megamek/src/megamek/common/weapons/battlearmor/CLBAMortarLight.java b/megamek/src/megamek/common/weapons/battlearmor/CLBAMortarLight.java index 03b814fd5ec..820ac2f2e12 100644 --- a/megamek/src/megamek/common/weapons/battlearmor/CLBAMortarLight.java +++ b/megamek/src/megamek/common/weapons/battlearmor/CLBAMortarLight.java @@ -18,7 +18,7 @@ import megamek.common.Mounted; import megamek.common.WeaponType; import megamek.common.alphaStrike.AlphaStrikeElement; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.weapons.Weapon; @@ -74,11 +74,11 @@ public boolean hasIndirectFire() { } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Indirect Fire - if (gOp.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { addMode(""); addMode("Indirect"); } else { diff --git a/megamek/src/megamek/common/weapons/battlearmor/ISBATubeArtillery.java b/megamek/src/megamek/common/weapons/battlearmor/ISBATubeArtillery.java index 077624012ea..e09a797fd84 100644 --- a/megamek/src/megamek/common/weapons/battlearmor/ISBATubeArtillery.java +++ b/megamek/src/megamek/common/weapons/battlearmor/ISBATubeArtillery.java @@ -15,7 +15,7 @@ import megamek.common.AmmoType; import megamek.common.EquipmentTypeLookup; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.weapons.artillery.ArtilleryWeapon; @@ -62,11 +62,11 @@ public boolean hasIndirectFire() { } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Indirect Fire - if (gOp.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { addMode(""); addMode("Indirect"); } else { diff --git a/megamek/src/megamek/common/weapons/gaussrifles/GaussWeapon.java b/megamek/src/megamek/common/weapons/gaussrifles/GaussWeapon.java index b228e38d6af..d991e236d26 100644 --- a/megamek/src/megamek/common/weapons/gaussrifles/GaussWeapon.java +++ b/megamek/src/megamek/common/weapons/gaussrifles/GaussWeapon.java @@ -1,33 +1,25 @@ /** * MegaMek - Copyright (C) 2004 Ben Mazur (bmazur@sev.org) - * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. - * * This program 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. */ -/* - * Created on Oct 19, 2004 - * - */ package megamek.common.weapons.gaussrifles; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.weapons.AmmoWeapon; /** * @author Andrew Hunter + * Created on Oct 19, 2004 */ public abstract class GaussWeapon extends AmmoWeapon { - /** - * - */ private static final long serialVersionUID = 8640523093316267351L; public GaussWeapon() { @@ -39,11 +31,11 @@ public GaussWeapon() { } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Add modes for powering down Gauss weapons PPC field inhibitors according to TacOps, p.102 - if (gOp.booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_GAUSS_WEAPONS)) { + if (gameOptions.booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_GAUSS_WEAPONS)) { addMode("Powered Up"); addMode("Powered Down"); setInstantModeSwitch(false); diff --git a/megamek/src/megamek/common/weapons/infantry/InfantrySupportLRMInfernoWeapon.java b/megamek/src/megamek/common/weapons/infantry/InfantrySupportLRMInfernoWeapon.java index 288a39c1ad5..19d7730800d 100644 --- a/megamek/src/megamek/common/weapons/infantry/InfantrySupportLRMInfernoWeapon.java +++ b/megamek/src/megamek/common/weapons/infantry/InfantrySupportLRMInfernoWeapon.java @@ -18,7 +18,7 @@ package megamek.common.weapons.infantry; import megamek.common.AmmoType; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; /** @@ -58,18 +58,18 @@ public InfantrySupportLRMInfernoWeapon() { .setAvailability(RATING_X, RATING_X, RATING_D, RATING_D); } - + @Override - public void adaptToGameOptions(GameOptions gOp) { + public void adaptToGameOptions(IGameOptions gameOptions) { removeMode(""); removeMode(MODE_MISSILE_INDIRECT); removeMode(MODE_INDIRECT_HEAT); // add heat options - super.adaptToGameOptions(gOp); + super.adaptToGameOptions(gameOptions); // Indirect Fire - if (gOp.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { - if (gOp.booleanOption(OptionsConstants.BASE_INFANTRY_DAMAGE_HEAT)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INFANTRY_DAMAGE_HEAT)) { addMode(""); addMode(MODE_MISSILE_INDIRECT); } else { diff --git a/megamek/src/megamek/common/weapons/infantry/InfantrySupportLRMWeapon.java b/megamek/src/megamek/common/weapons/infantry/InfantrySupportLRMWeapon.java index 54abd87cf7d..23f15b822c1 100644 --- a/megamek/src/megamek/common/weapons/infantry/InfantrySupportLRMWeapon.java +++ b/megamek/src/megamek/common/weapons/infantry/InfantrySupportLRMWeapon.java @@ -18,7 +18,7 @@ package megamek.common.weapons.infantry; import megamek.common.AmmoType; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; /** @@ -55,13 +55,13 @@ public InfantrySupportLRMWeapon() { .setProductionFactions(F_FW).setTechRating(RATING_D) .setAvailability(RATING_X, RATING_X, RATING_D, RATING_D); } - + @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Indirect Fire - if (gOp.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { addMode(""); addMode("Indirect"); } else { diff --git a/megamek/src/megamek/common/weapons/infantry/InfantrySupportMortarHeavyInfernoWeapon.java b/megamek/src/megamek/common/weapons/infantry/InfantrySupportMortarHeavyInfernoWeapon.java index b3c1bd72ec2..8e9dc995140 100644 --- a/megamek/src/megamek/common/weapons/infantry/InfantrySupportMortarHeavyInfernoWeapon.java +++ b/megamek/src/megamek/common/weapons/infantry/InfantrySupportMortarHeavyInfernoWeapon.java @@ -18,7 +18,7 @@ package megamek.common.weapons.infantry; import megamek.common.AmmoType; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; /** @@ -61,16 +61,16 @@ public InfantrySupportMortarHeavyInfernoWeapon() { } @Override - public void adaptToGameOptions(GameOptions gOp) { + public void adaptToGameOptions(IGameOptions gameOptions) { removeMode(""); removeMode(MODE_MISSILE_INDIRECT); removeMode(MODE_INDIRECT_HEAT); // add heat options - super.adaptToGameOptions(gOp); + super.adaptToGameOptions(gameOptions); // Indirect Fire - if (gOp.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { - if (gOp.booleanOption(OptionsConstants.BASE_INFANTRY_DAMAGE_HEAT)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INFANTRY_DAMAGE_HEAT)) { addMode(""); addMode(MODE_MISSILE_INDIRECT); } else { diff --git a/megamek/src/megamek/common/weapons/infantry/InfantrySupportMortarHeavyWeapon.java b/megamek/src/megamek/common/weapons/infantry/InfantrySupportMortarHeavyWeapon.java index 6527461bca3..4811df88d9f 100644 --- a/megamek/src/megamek/common/weapons/infantry/InfantrySupportMortarHeavyWeapon.java +++ b/megamek/src/megamek/common/weapons/infantry/InfantrySupportMortarHeavyWeapon.java @@ -18,7 +18,7 @@ package megamek.common.weapons.infantry; import megamek.common.AmmoType; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; /** @@ -59,11 +59,11 @@ public InfantrySupportMortarHeavyWeapon() { } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Indirect Fire - if (gOp.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { addMode(""); addMode("Indirect"); } else { diff --git a/megamek/src/megamek/common/weapons/infantry/InfantrySupportMortarLightInfernoWeapon.java b/megamek/src/megamek/common/weapons/infantry/InfantrySupportMortarLightInfernoWeapon.java index b79118ae59a..068c248389f 100644 --- a/megamek/src/megamek/common/weapons/infantry/InfantrySupportMortarLightInfernoWeapon.java +++ b/megamek/src/megamek/common/weapons/infantry/InfantrySupportMortarLightInfernoWeapon.java @@ -18,7 +18,7 @@ package megamek.common.weapons.infantry; import megamek.common.AmmoType; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; /** @@ -61,11 +61,11 @@ public InfantrySupportMortarLightInfernoWeapon() { } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Indirect Fire - if (gOp.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { addMode(MODE_MISSILE_INDIRECT); addMode(MODE_INDIRECT_HEAT); } else { diff --git a/megamek/src/megamek/common/weapons/infantry/InfantrySupportMortarLightWeapon.java b/megamek/src/megamek/common/weapons/infantry/InfantrySupportMortarLightWeapon.java index 685c46ad40d..ebf0b148409 100644 --- a/megamek/src/megamek/common/weapons/infantry/InfantrySupportMortarLightWeapon.java +++ b/megamek/src/megamek/common/weapons/infantry/InfantrySupportMortarLightWeapon.java @@ -18,7 +18,7 @@ package megamek.common.weapons.infantry; import megamek.common.AmmoType; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; /** @@ -59,11 +59,11 @@ public InfantrySupportMortarLightWeapon() { } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Indirect Fire - if (gOp.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { addMode(""); addMode("Indirect"); } else { diff --git a/megamek/src/megamek/common/weapons/infantry/InfantryWeapon.java b/megamek/src/megamek/common/weapons/infantry/InfantryWeapon.java index 6ef7ac2eb34..344da45711d 100644 --- a/megamek/src/megamek/common/weapons/infantry/InfantryWeapon.java +++ b/megamek/src/megamek/common/weapons/infantry/InfantryWeapon.java @@ -17,7 +17,7 @@ import megamek.common.actions.WeaponAttackAction; import megamek.common.equipment.WeaponMounted; import megamek.common.equipment.AmmoMounted; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.weapons.AttackHandler; import megamek.common.weapons.Weapon; @@ -275,9 +275,9 @@ protected AttackHandler getCorrectHandler(ToHitData toHit, WeaponAttackAction wa } @Override - public void adaptToGameOptions(GameOptions gOp) { + public void adaptToGameOptions(IGameOptions gameOptions) { if (isFlameBased()) { - if (!gOp.booleanOption(OptionsConstants.BASE_INFANTRY_DAMAGE_HEAT)) { + if (!gameOptions.booleanOption(OptionsConstants.BASE_INFANTRY_DAMAGE_HEAT)) { addMode(MODE_FLAMER_DAMAGE); addMode(MODE_FLAMER_HEAT); } else { diff --git a/megamek/src/megamek/common/weapons/lasers/EnergyWeapon.java b/megamek/src/megamek/common/weapons/lasers/EnergyWeapon.java index df4052d447c..e3ce3bac5de 100644 --- a/megamek/src/megamek/common/weapons/lasers/EnergyWeapon.java +++ b/megamek/src/megamek/common/weapons/lasers/EnergyWeapon.java @@ -17,7 +17,7 @@ import megamek.common.ToHitData; import megamek.common.WeaponType; import megamek.common.actions.WeaponAttackAction; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.weapons.AttackHandler; import megamek.common.weapons.EnergyWeaponHandler; @@ -41,8 +41,8 @@ protected AttackHandler getCorrectHandler(ToHitData toHit, WeaponAttackAction wa } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Add modes for dialed-down damage according to TacOps, p.102 // Adds a mode for each damage value down to zero; zero is included @@ -50,7 +50,7 @@ public void adaptToGameOptions(GameOptions gOp) { // The bombast laser has its own rules with to-hit modifiers and does not // get additional dial-down if (!(this instanceof ISBombastLaser)) { - if (gOp.booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_ENERGY_WEAPONS)) { + if (gameOptions.booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_ENERGY_WEAPONS)) { int dmg = (damage == WeaponType.DAMAGE_VARIABLE) ? damageShort : damage; for (; dmg >= 0; dmg--) { addMode("Damage " + dmg); diff --git a/megamek/src/megamek/common/weapons/lasers/LaserWeapon.java b/megamek/src/megamek/common/weapons/lasers/LaserWeapon.java index b58bfd66a4f..2bcd01e4df1 100644 --- a/megamek/src/megamek/common/weapons/lasers/LaserWeapon.java +++ b/megamek/src/megamek/common/weapons/lasers/LaserWeapon.java @@ -21,8 +21,7 @@ import megamek.common.actions.WeaponAttackAction; import megamek.common.annotations.Nullable; import megamek.common.equipment.MiscMounted; -import megamek.common.options.GameOptions; -import megamek.common.options.OptionsConstants; +import megamek.common.options.IGameOptions; import megamek.common.weapons.AttackHandler; import megamek.common.weapons.EnergyWeaponHandler; import megamek.common.weapons.InsulatedLaserWeaponHandler; @@ -45,8 +44,8 @@ public LaserWeapon() { } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); if (!(this instanceof PulseLaserWeapon)) { addMode(""); diff --git a/megamek/src/megamek/common/weapons/lrms/LRMWeapon.java b/megamek/src/megamek/common/weapons/lrms/LRMWeapon.java index c3cae0ce530..8aee48cb33c 100644 --- a/megamek/src/megamek/common/weapons/lrms/LRMWeapon.java +++ b/megamek/src/megamek/common/weapons/lrms/LRMWeapon.java @@ -24,7 +24,7 @@ import megamek.common.Game; import megamek.common.ToHitData; import megamek.common.actions.WeaponAttackAction; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.weapons.AttackHandler; import megamek.common.weapons.LRMAntiTSMHandler; @@ -87,11 +87,11 @@ public boolean hasIndirectFire() { } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Indirect Fire - if (gOp.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { addMode(""); addMode("Indirect"); } else { diff --git a/megamek/src/megamek/common/weapons/lrms/LRTWeapon.java b/megamek/src/megamek/common/weapons/lrms/LRTWeapon.java index 865cca45d4c..c44fac6061a 100644 --- a/megamek/src/megamek/common/weapons/lrms/LRTWeapon.java +++ b/megamek/src/megamek/common/weapons/lrms/LRTWeapon.java @@ -30,7 +30,7 @@ import megamek.common.Mounted; import megamek.common.ToHitData; import megamek.common.actions.WeaponAttackAction; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.weapons.AttackHandler; import megamek.common.weapons.MissileWeaponHandler; @@ -109,11 +109,11 @@ public double getBattleForceDamage(int range, Mounted fcs) { } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Indirect Fire - if (gOp.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { addMode(""); addMode("Indirect"); } else { diff --git a/megamek/src/megamek/common/weapons/missiles/MMLWeapon.java b/megamek/src/megamek/common/weapons/missiles/MMLWeapon.java index a1882b6a74d..64a6c002859 100644 --- a/megamek/src/megamek/common/weapons/missiles/MMLWeapon.java +++ b/megamek/src/megamek/common/weapons/missiles/MMLWeapon.java @@ -23,7 +23,7 @@ import megamek.common.Game; import megamek.common.ToHitData; import megamek.common.actions.WeaponAttackAction; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.weapons.AttackHandler; import megamek.common.weapons.lrms.LRMWeapon; @@ -67,11 +67,11 @@ public boolean hasIndirectFire() { } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Indirect Fire - if (gOp.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { addMode(""); addMode("Indirect"); } else { diff --git a/megamek/src/megamek/common/weapons/missiles/ThunderBoltWeapon.java b/megamek/src/megamek/common/weapons/missiles/ThunderBoltWeapon.java index 632a6c9debc..8ccc8015448 100644 --- a/megamek/src/megamek/common/weapons/missiles/ThunderBoltWeapon.java +++ b/megamek/src/megamek/common/weapons/missiles/ThunderBoltWeapon.java @@ -23,7 +23,7 @@ import megamek.common.SimpleTechLevel; import megamek.common.ToHitData; import megamek.common.actions.WeaponAttackAction; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.weapons.AttackHandler; import megamek.common.weapons.ThunderBoltWeaponHandler; @@ -69,13 +69,13 @@ protected AttackHandler getCorrectHandler(ToHitData toHit, public boolean hasIndirectFire() { return true; } - + @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Indirect Fire - if (gOp.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { addMode(""); addMode("Indirect"); } else { @@ -83,4 +83,4 @@ public void adaptToGameOptions(GameOptions gOp) { removeMode("Indirect"); } } -} \ No newline at end of file +} diff --git a/megamek/src/megamek/common/weapons/mortars/MekMortarWeapon.java b/megamek/src/megamek/common/weapons/mortars/MekMortarWeapon.java index 9912e7cbe8c..991bd30962f 100644 --- a/megamek/src/megamek/common/weapons/mortars/MekMortarWeapon.java +++ b/megamek/src/megamek/common/weapons/mortars/MekMortarWeapon.java @@ -25,7 +25,7 @@ import megamek.common.Game; import megamek.common.ToHitData; import megamek.common.actions.WeaponAttackAction; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.weapons.AmmoWeapon; import megamek.common.weapons.AttackHandler; @@ -92,11 +92,11 @@ public boolean hasIndirectFire() { } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Indirect Fire - if (gOp.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { + if (gameOptions.booleanOption(OptionsConstants.BASE_INDIRECT_FIRE)) { addMode(""); addMode("Indirect"); } else { diff --git a/megamek/src/megamek/common/weapons/ppc/PPCWeapon.java b/megamek/src/megamek/common/weapons/ppc/PPCWeapon.java index e2ae8c4bc08..b476a7b77a3 100644 --- a/megamek/src/megamek/common/weapons/ppc/PPCWeapon.java +++ b/megamek/src/megamek/common/weapons/ppc/PPCWeapon.java @@ -19,7 +19,7 @@ import megamek.common.ToHitData; import megamek.common.actions.WeaponAttackAction; import megamek.common.alphaStrike.AlphaStrikeElement; -import megamek.common.options.GameOptions; +import megamek.common.options.IGameOptions; import megamek.common.options.OptionsConstants; import megamek.common.weapons.AttackHandler; import megamek.common.weapons.PPCHandler; @@ -81,14 +81,14 @@ public double getBattleForceDamage(int range, Mounted capacitor) { } @Override - public void adaptToGameOptions(GameOptions gOp) { - super.adaptToGameOptions(gOp); + public void adaptToGameOptions(IGameOptions gameOptions) { + super.adaptToGameOptions(gameOptions); // Modes for disengaging PPC field inhibitors according to TacOps, p.103. // The benefit is removing the minimum range, so only PPCs with a minimum range // get the modes. if (minimumRange > 0) { - if (gOp.booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_PPC_INHIBITORS)) { + if (gameOptions.booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_PPC_INHIBITORS)) { addMode("Field Inhibitor ON"); addMode("Field Inhibitor OFF"); } else { diff --git a/megamek/src/megamek/server/Server.java b/megamek/src/megamek/server/Server.java index cc51549c8c2..ca920f2100f 100644 --- a/megamek/src/megamek/server/Server.java +++ b/megamek/src/megamek/server/Server.java @@ -817,22 +817,7 @@ public void sendCurrentInfo(int connId) { * Adds a new player to the game */ private Player addNewPlayer(int connId, String name, boolean isBot) { - int team = Player.TEAM_UNASSIGNED; - if (getGame().getPhase().isLounge()) { - team = Player.TEAM_NONE; - final BasicGameOptions gOpts = getGame().getOptions(); - if (isBot || !gOpts.booleanOption(OptionsConstants.BASE_SET_DEFAULT_TEAM_1)) { - for (Player p : getGame().getPlayersList()) { - if (p.getTeam() > team) { - team = p.getTeam(); - } - } - team++; - } else { - team = 1; - } - - } + int team = getTeam(isBot); Player newPlayer = new Player(connId, name); newPlayer.setBot(isBot); PlayerColour colour = newPlayer.getColour(); @@ -854,6 +839,26 @@ private Player addNewPlayer(int connId, String name, boolean isBot) { return newPlayer; } + private int getTeam(boolean isBot) { + int team = Player.TEAM_UNASSIGNED; + if (getGame().getPhase().isLounge()) { + team = Player.TEAM_NONE; + final var gOpts = getGame().getOptions(); + if (isBot || !gOpts.booleanOption(OptionsConstants.BASE_SET_DEFAULT_TEAM_1)) { + for (Player p : getGame().getPlayersList()) { + if (p.getTeam() > team) { + team = p.getTeam(); + } + } + team++; + } else { + team = 1; + } + + } + return team; + } + /** * Validates the player info. */ diff --git a/megamek/src/megamek/server/totalwarfare/TWGameManager.java b/megamek/src/megamek/server/totalwarfare/TWGameManager.java index 9cad65ee4da..4e1abe347d0 100644 --- a/megamek/src/megamek/server/totalwarfare/TWGameManager.java +++ b/megamek/src/megamek/server/totalwarfare/TWGameManager.java @@ -143,8 +143,8 @@ public Vector getvPhaseReport() { public TWGameManager() { EquipmentType.initializeTypes(); - game.getOptions().initialize(); - game.getOptions().loadOptions(); + ((GameOptions) game.getOptions()).initialize(); + ((GameOptions) game.getOptions()).loadOptions(); game.setPhase(GamePhase.LOUNGE); MapSettings mapSettings = game.getMapSettings(); @@ -1355,7 +1355,7 @@ private void endCurrentTurn(Entity entityUsed) { } } final GamePhase currPhase = game.getPhase(); - final GameOptions gameOpts = game.getOptions(); + final var gameOpts = game.getOptions(); final int playerId = null == entityUsed ? Player.PLAYER_NONE : entityUsed.getOwnerId(); boolean infMoved = entityUsed instanceof Infantry; boolean infMoveMulti = gameOpts.booleanOption(OptionsConstants.INIT_INF_MOVE_MULTI) diff --git a/megamek/src/megamek/server/victory/VictoryHelper.java b/megamek/src/megamek/server/victory/VictoryHelper.java index 71e8c2b7226..c012abf22bb 100644 --- a/megamek/src/megamek/server/victory/VictoryHelper.java +++ b/megamek/src/megamek/server/victory/VictoryHelper.java @@ -19,19 +19,18 @@ */ package megamek.server.victory; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - import megamek.common.Game; import megamek.common.IGame; -import megamek.common.options.BasicGameOptions; import megamek.common.options.OptionsConstants; import megamek.server.scriptedevent.TriggeredEvent; import megamek.server.scriptedevent.VictoryTriggeredEvent; import megamek.server.trigger.TriggerSituation; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + /** * This class manages the victory conditions of a game. As victory conditions could potentially have some state they need to save in * savegames, this class is actually part of the Game rather than just a GameManager helper. TODO: This should be resolved by storing @@ -157,7 +156,7 @@ private VictoryResult checkOptionalVictoryConditions(Game game, Map