From 1519e0e95291704f727670b216663ef864882759 Mon Sep 17 00:00:00 2001 From: sleet01 Date: Mon, 18 Sep 2023 18:26:46 -0700 Subject: [PATCH 1/4] Fix several wrong munitions checks for MML #3761 --- .../src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java | 2 +- megamek/src/megamek/common/AmmoType.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java b/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java index aa3033e350f..2d4e27eb050 100644 --- a/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java +++ b/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java @@ -229,7 +229,7 @@ public String getElementAt(int index) { int totalShots = 0; EnumSet munition = ((AmmoType) mounted.getLinked().getType()).getMunitionType(); for (Mounted current = mounted.getLinked(); current != null; current = current.getLinked()) { - if (((AmmoType) current.getType()).getMunitionType() == munition) { + if (((AmmoType) current.getType()).getMunitionType().contains(munition)) { shotsLeft += current.getUsableShotsLeft(); totalShots += current.getOriginalShots(); } diff --git a/megamek/src/megamek/common/AmmoType.java b/megamek/src/megamek/common/AmmoType.java index f1a657e8d2f..4d5406d1fa3 100644 --- a/megamek/src/megamek/common/AmmoType.java +++ b/megamek/src/megamek/common/AmmoType.java @@ -407,7 +407,7 @@ public boolean isCompatibleWith(AmmoType other) { } // MML Launchers, ugh. - if ((is(T_MML) || other.is(T_MML)) && (getMunitionType() == other.getMunitionType())) { + if ((is(T_MML) || other.is(T_MML)) && (getMunitionType().contains(other.getMunitionType()))) { // LRMs... if (is(T_MML) && hasFlag(F_MML_LRM) && other.is(T_LRM)) { return true; @@ -424,7 +424,7 @@ public boolean isCompatibleWith(AmmoType other) { } // General Launchers - if (is(other.getAmmoType()) && (getMunitionType() == other.getMunitionType())) { + if (is(other.getAmmoType()) && (getMunitionType().contains(other.getMunitionType()))) { return true; } From 83e215c223beea29ff637071fd5c84241e91a413 Mon Sep 17 00:00:00 2001 From: sleet01 Date: Mon, 18 Sep 2023 23:38:42 -0700 Subject: [PATCH 2/4] Further tweaks to make EnumSet -> EnumSet comparisons correct --- megamek/src/megamek/common/AmmoType.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/megamek/src/megamek/common/AmmoType.java b/megamek/src/megamek/common/AmmoType.java index 4d5406d1fa3..673364be16b 100644 --- a/megamek/src/megamek/common/AmmoType.java +++ b/megamek/src/megamek/common/AmmoType.java @@ -407,7 +407,7 @@ public boolean isCompatibleWith(AmmoType other) { } // MML Launchers, ugh. - if ((is(T_MML) || other.is(T_MML)) && (getMunitionType().contains(other.getMunitionType()))) { + if ((is(T_MML) || other.is(T_MML)) && (getMunitionType().containsAll(other.getMunitionType()))) { // LRMs... if (is(T_MML) && hasFlag(F_MML_LRM) && other.is(T_LRM)) { return true; @@ -424,7 +424,7 @@ public boolean isCompatibleWith(AmmoType other) { } // General Launchers - if (is(other.getAmmoType()) && (getMunitionType().contains(other.getMunitionType()))) { + if (is(other.getAmmoType()) && (getMunitionType().containsAll(other.getMunitionType()))) { return true; } From 66a4282f9e4a7c5c275cec617a3e6456367ffd02 Mon Sep 17 00:00:00 2001 From: sleet01 Date: Mon, 18 Sep 2023 23:41:28 -0700 Subject: [PATCH 3/4] Two EnumSets can only be compared using .containsAll or .containsNone, or similar --- .../src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java b/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java index 2d4e27eb050..69ecf9e3d08 100644 --- a/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java +++ b/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java @@ -229,7 +229,7 @@ public String getElementAt(int index) { int totalShots = 0; EnumSet munition = ((AmmoType) mounted.getLinked().getType()).getMunitionType(); for (Mounted current = mounted.getLinked(); current != null; current = current.getLinked()) { - if (((AmmoType) current.getType()).getMunitionType().contains(munition)) { + if (((AmmoType) current.getType()).getMunitionType().containsAll(munition)) { shotsLeft += current.getUsableShotsLeft(); totalShots += current.getOriginalShots(); } From b418dee9113cdd5194a53a304a23fcddc86b27ba Mon Sep 17 00:00:00 2001 From: sleet01 Date: Mon, 18 Sep 2023 23:55:51 -0700 Subject: [PATCH 4/4] Two EnumSets can be compared with .equals(), who knew? --- .../src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java | 2 +- megamek/src/megamek/common/AmmoType.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java b/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java index 69ecf9e3d08..7d6b5feb9a6 100644 --- a/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java +++ b/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java @@ -229,7 +229,7 @@ public String getElementAt(int index) { int totalShots = 0; EnumSet munition = ((AmmoType) mounted.getLinked().getType()).getMunitionType(); for (Mounted current = mounted.getLinked(); current != null; current = current.getLinked()) { - if (((AmmoType) current.getType()).getMunitionType().containsAll(munition)) { + if (((AmmoType) current.getType()).getMunitionType().equals(munition)) { shotsLeft += current.getUsableShotsLeft(); totalShots += current.getOriginalShots(); } diff --git a/megamek/src/megamek/common/AmmoType.java b/megamek/src/megamek/common/AmmoType.java index 673364be16b..02a9f72d3a3 100644 --- a/megamek/src/megamek/common/AmmoType.java +++ b/megamek/src/megamek/common/AmmoType.java @@ -407,7 +407,7 @@ public boolean isCompatibleWith(AmmoType other) { } // MML Launchers, ugh. - if ((is(T_MML) || other.is(T_MML)) && (getMunitionType().containsAll(other.getMunitionType()))) { + if ((is(T_MML) || other.is(T_MML)) && (getMunitionType().equals(other.getMunitionType()))) { // LRMs... if (is(T_MML) && hasFlag(F_MML_LRM) && other.is(T_LRM)) { return true; @@ -424,7 +424,7 @@ public boolean isCompatibleWith(AmmoType other) { } // General Launchers - if (is(other.getAmmoType()) && (getMunitionType().containsAll(other.getMunitionType()))) { + if (is(other.getAmmoType()) && (getMunitionType().equals(other.getMunitionType()))) { return true; }