Skip to content

Commit

Permalink
Merge pull request #3805 from Sleet01/implement_4397_internal_bomb_ba…
Browse files Browse the repository at this point in the history
…y_mhq

Implement #4397 Internal Bomb Bay (MHQ compatibility)
  • Loading branch information
SJuliez authored Jan 3, 2024
2 parents 84e450d + 96b49f0 commit edc25a6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
14 changes: 10 additions & 4 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -5683,17 +5683,23 @@ public void clearGameData(Entity entity) {
IBomber bomber = (IBomber) entity;
List<Mounted> 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();
}
}
Expand Down
2 changes: 2 additions & 0 deletions MekHQ/src/mekhq/gui/dialog/BombsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();

Expand Down
15 changes: 11 additions & 4 deletions MekHQ/src/mekhq/utilities/MHQXMLUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,7 @@ public static String writeEntityToXmlString(Entity tgtEnt, int indentLvl, List<E
return retVal.toString();
}

private static String getBombChoiceString(IBomber bomber, int indentLvl) {
StringBuilder retVal = new StringBuilder();

int[] bombChoices = bomber.getBombChoices();
private static void compileBombChoices(int[] bombChoices, StringBuilder retVal, int indentLvl, boolean isInternal) {
if (bombChoices.length > 0) {
retVal.append(MHQXMLUtility.indentStr(indentLvl + 1)).append("<bombs>\n");
for (int type = 0; type < BombType.B_NUM; type++) {
Expand All @@ -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("</bombs>\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();
}

Expand Down
6 changes: 4 additions & 2 deletions MekHQ/unittests/mekhq/campaign/unit/UnitTestUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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")) {
Expand Down

0 comments on commit edc25a6

Please sign in to comment.