diff --git a/megamek/src/megamek/common/Compute.java b/megamek/src/megamek/common/Compute.java index 7688c8eeba3..da5e4a7dd39 100644 --- a/megamek/src/megamek/common/Compute.java +++ b/megamek/src/megamek/common/Compute.java @@ -6914,13 +6914,17 @@ public static int dialDownDamage(Mounted weapon, WeaponType wtype, int range) return toReturn; } - String damage = weapon.curMode().getName(); + String damage = weapon.curMode().getName().toLowerCase(); // Vehicle flamers have damage and heat modes so lets make sure this is // an actual dial down Damage. - if ((damage.trim().toLowerCase().indexOf("damage") == 0) - && (damage.trim().length() > 6)) { - toReturn = Integer.parseInt(damage.substring(6).trim()); + if ((damage.trim().length() > 6) && damage.contains("damage")) { + try { + toReturn = Integer.parseInt(damage.substring(damage.indexOf("damage") + 6).trim()); + } + catch (NumberFormatException e) { + logger.warn("Failed to get dialed down damage. " + e.getMessage()); + } } return Math.min(wtype.getDamage(range), toReturn); @@ -7252,7 +7256,7 @@ public static boolean allowAimedShotWith(WeaponMounted weapon, AimingMode aiming case TARGETING_COMPUTER: if (!wtype.hasFlag(WeaponType.F_DIRECT_FIRE) || wtype.hasFlag(WeaponType.F_PULSE) - || weapon.curMode().getName().equals("Pulse") + || weapon.curMode().getName().startsWith("Pulse") || (wtype instanceof HAGWeapon)) { return false; } diff --git a/megamek/src/megamek/common/equipment/WeaponMounted.java b/megamek/src/megamek/common/equipment/WeaponMounted.java index 390b0e9aaf3..5b5102d9bca 100644 --- a/megamek/src/megamek/common/equipment/WeaponMounted.java +++ b/megamek/src/megamek/common/equipment/WeaponMounted.java @@ -131,7 +131,7 @@ && getLinkedBy().getType().hasFlag( heat++; } } - if (curMode().equals("Pulse")) { + if (curMode().getName().startsWith("Pulse")) { heat += 2; } diff --git a/megamek/src/megamek/common/weapons/PulseLaserWeaponHandler.java b/megamek/src/megamek/common/weapons/PulseLaserWeaponHandler.java index 07ce462ee3b..3cd02182a6d 100644 --- a/megamek/src/megamek/common/weapons/PulseLaserWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/PulseLaserWeaponHandler.java @@ -42,7 +42,7 @@ protected boolean doChecks(Vector vPhaseReport) { WeaponMounted laser = waa.getEntity(game).getWeapon(waa.getWeaponId()); - if ((roll.getIntValue() == 2) && laser.curMode().equals("Pulse")) { + if ((roll.getIntValue() == 2) && laser.curMode().getName().startsWith("Pulse")) { vPhaseReport.addAll(gameManager.explodeEquipment(laser.getEntity(), laser.getLocation(), laser.getLinkedBy())); } return false; diff --git a/megamek/src/megamek/common/weapons/lasers/EnergyWeapon.java b/megamek/src/megamek/common/weapons/lasers/EnergyWeapon.java index df4052d447c..b92ac56073b 100644 --- a/megamek/src/megamek/common/weapons/lasers/EnergyWeapon.java +++ b/megamek/src/megamek/common/weapons/lasers/EnergyWeapon.java @@ -55,10 +55,13 @@ public void adaptToGameOptions(GameOptions gOp) { for (; dmg >= 0; dmg--) { addMode("Damage " + dmg); } + removeMode(""); + removeMode("Pulse"); } else { int dmg = (damage == WeaponType.DAMAGE_VARIABLE) ? damageShort : damage; for (; dmg >= 0; dmg--) { removeMode("Damage " + dmg); + removeMode("Pulse Damage " + dmg); } } } diff --git a/megamek/src/megamek/common/weapons/lasers/LaserWeapon.java b/megamek/src/megamek/common/weapons/lasers/LaserWeapon.java index b58bfd66a4f..a3898cf46b5 100644 --- a/megamek/src/megamek/common/weapons/lasers/LaserWeapon.java +++ b/megamek/src/megamek/common/weapons/lasers/LaserWeapon.java @@ -13,11 +13,7 @@ */ package megamek.common.weapons.lasers; -import megamek.common.AmmoType; -import megamek.common.Game; -import megamek.common.MiscType; -import megamek.common.Mounted; -import megamek.common.ToHitData; +import megamek.common.*; import megamek.common.actions.WeaponAttackAction; import megamek.common.annotations.Nullable; import megamek.common.equipment.MiscMounted; @@ -29,6 +25,8 @@ import megamek.common.weapons.PulseLaserWeaponHandler; import megamek.server.totalwarfare.TWGameManager; +import java.util.Collections; + /** * @author Andrew Hunter * @since Sep 2, 2004 @@ -49,8 +47,17 @@ public void adaptToGameOptions(GameOptions gOp) { super.adaptToGameOptions(gOp); if (!(this instanceof PulseLaserWeapon)) { - addMode(""); - addMode("Pulse"); + if (!hasModes()) { + addMode(""); + addMode("Pulse"); + } + else { + for (var mode : Collections.list(getModes())) { + if(!mode.getName().contains("Pulse") && !mode.getName().isEmpty()) { + addMode("Pulse " + mode.getName()); + } + } + } } } @@ -60,10 +67,13 @@ public int getModesCount(Mounted mounted) { if ((linkedBy instanceof MiscMounted) && !linkedBy.isInoperable() && ((MiscMounted) linkedBy).getType().hasFlag(MiscType.F_RISC_LASER_PULSE_MODULE)) { - return 2; - } else { - return 0; + return super.getModesCount(); + } else if(this instanceof PulseLaserWeapon) { + return super.getModesCount(); } + + //Only works if laser pulse module's "Pulse" modes are added last. + return (int) modes.stream().filter(mode -> !mode.getName().startsWith("Pulse")).count(); } @Override @@ -71,7 +81,7 @@ public int getToHitModifier(@Nullable Mounted mounted) { if ((mounted == null) || !(mounted.getLinkedBy() instanceof MiscMounted) || !mounted.getLinkedBy().getType().hasFlag(MiscType.F_RISC_LASER_PULSE_MODULE)) { return super.getToHitModifier(mounted); } - return mounted.curMode().getName().equals("Pulse") ? -2 : 0; + return mounted.curMode().getName().startsWith("Pulse") ? -2 : 0; } @Override