From 4b75bf694d6d10a67da664695be2ae939dbfda2a Mon Sep 17 00:00:00 2001 From: sleet01 Date: Fri, 22 Dec 2023 00:47:11 -0800 Subject: [PATCH 1/3] Required for compatibility with MegaMek PR #4974 --- MekHQ/unittests/mekhq/campaign/unit/UnitTestUtilities.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MekHQ/unittests/mekhq/campaign/unit/UnitTestUtilities.java b/MekHQ/unittests/mekhq/campaign/unit/UnitTestUtilities.java index ffafbd4d38..b710032ca7 100644 --- a/MekHQ/unittests/mekhq/campaign/unit/UnitTestUtilities.java +++ b/MekHQ/unittests/mekhq/campaign/unit/UnitTestUtilities.java @@ -60,7 +60,7 @@ public static Entity parseBase64BlkFile(String base64) { try { InputStream in = new ByteArrayInputStream(TestUtilities.Decode(base64)); IMechLoader loader; - + BuildingBlock bb = new BuildingBlock(in); if (bb.exists("UnitType")) { String sType = bb.getDataAsString("UnitType")[0]; @@ -85,8 +85,10 @@ public static Entity parseBase64BlkFile(String base64) { loader = new BLKLargeSupportTankFile(bb); } else if (sType.equals("SupportVTOL")) { loader = new BLKSupportVTOLFile(bb); + } else if (sType.equals("AeroSpaceFighter")) { + loader = new BLKAeroSpaceFighterFile(bb); } else if (sType.equals("Aero")) { - loader = new BLKAeroFile(bb); + loader = new BLKAeroSpaceFighterFile(bb); } else if (sType.equals("FixedWingSupport")) { loader = new BLKFixedWingSupportFile(bb); } else if (sType.equals("ConvFighter")) { From 4f5c173062266e0a12ea4e78f3ce70716f50a3e9 Mon Sep 17 00:00:00 2001 From: sleet01 Date: Wed, 27 Dec 2023 09:14:36 -0800 Subject: [PATCH 2/3] Make clearGameData aware of two bomb types --- MekHQ/src/mekhq/campaign/Campaign.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/MekHQ/src/mekhq/campaign/Campaign.java b/MekHQ/src/mekhq/campaign/Campaign.java index 80e80a027c..d42cc9bb00 100644 --- a/MekHQ/src/mekhq/campaign/Campaign.java +++ b/MekHQ/src/mekhq/campaign/Campaign.java @@ -5683,17 +5683,23 @@ public void clearGameData(Entity entity) { IBomber bomber = (IBomber) entity; List mountedBombs = bomber.getBombs(); if (!mountedBombs.isEmpty()) { - // This should return an int[] filled with 0's - int[] bombChoices = bomber.getBombChoices(); + // These should return an int[] filled with 0's + int[] intBombChoices = bomber.getIntBombChoices(); + int[] extBombChoices = bomber.getExtBombChoices(); for (Mounted m : mountedBombs) { if (!(m.getType() instanceof BombType)) { continue; } if (m.getBaseShotsLeft() == 1) { - bombChoices[BombType.getBombTypeFromInternalName(m.getType().getInternalName())] += 1; + if (m.isInternalBomb()) { + intBombChoices[BombType.getBombTypeFromInternalName(m.getType().getInternalName())] += 1; + } else { + extBombChoices[BombType.getBombTypeFromInternalName(m.getType().getInternalName())] += 1; + } } } - bomber.setBombChoices(bombChoices); + bomber.setIntBombChoices(intBombChoices); + bomber.setExtBombChoices(extBombChoices); bomber.clearBombs(); } } From 96b49f09787659de66ca3f774c15d31121e0317c Mon Sep 17 00:00:00 2001 From: sleet01 Date: Wed, 27 Dec 2023 16:29:51 -0800 Subject: [PATCH 3/3] Add comments for bomb picker dialog, make XML writer aware of two bomb types --- MekHQ/src/mekhq/gui/dialog/BombsDialog.java | 2 ++ MekHQ/src/mekhq/utilities/MHQXMLUtility.java | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/MekHQ/src/mekhq/gui/dialog/BombsDialog.java b/MekHQ/src/mekhq/gui/dialog/BombsDialog.java index f1c67a11af..15a0f0972f 100644 --- a/MekHQ/src/mekhq/gui/dialog/BombsDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/BombsDialog.java @@ -86,6 +86,7 @@ private void initGUI() { typeMax[type] = availBombs[type] + bombChoices[type]; } + // BombChoicePanel takes care of managing internal and external stores, so we don't need to here. bombPanel = new BombChoicePanel(bomber, campaign.getGameOptions().booleanOption("at2_nukes"), true, typeMax); @@ -127,6 +128,7 @@ private void setUserPreferences() { @Override public void actionPerformed(ActionEvent e) { if (okayButton.equals(e.getSource())) { + // internal and external choices are applied by bombPanel; here we only care about the totals. bombPanel.applyChoice(); int[] newLoadout = bombPanel.getChoice(); diff --git a/MekHQ/src/mekhq/utilities/MHQXMLUtility.java b/MekHQ/src/mekhq/utilities/MHQXMLUtility.java index 25f1069a46..c1d4c256f2 100644 --- a/MekHQ/src/mekhq/utilities/MHQXMLUtility.java +++ b/MekHQ/src/mekhq/utilities/MHQXMLUtility.java @@ -254,10 +254,7 @@ public static String writeEntityToXmlString(Entity tgtEnt, int indentLvl, List 0) { retVal.append(MHQXMLUtility.indentStr(indentLvl + 1)).append("\n"); for (int type = 0; type < BombType.B_NUM; type++) { @@ -267,12 +264,22 @@ private static String getBombChoiceString(IBomber bomber, int indentLvl) { retVal.append(typeName); retVal.append("\" load=\""); retVal.append(bombChoices[type]); + retVal.append((isInternal) ? "\" Internal=\"true" : "\" Internal=\"false"); retVal.append("\"/>\n"); } } retVal.append(MHQXMLUtility.indentStr(indentLvl + 1)).append("\n"); } + } + private static String getBombChoiceString(IBomber bomber, int indentLvl) { + StringBuilder retVal = new StringBuilder(); + + int[] bombChoices = bomber.getIntBombChoices(); + compileBombChoices(bombChoices, retVal, indentLvl, true); + bombChoices = bomber.getExtBombChoices(); + compileBombChoices(bombChoices, retVal, indentLvl, false); + return retVal.toString(); }