From 6cee9867887d8ac9f5a680f3bb36f2db50cccab8 Mon Sep 17 00:00:00 2001 From: sleet01 Date: Fri, 26 Apr 2024 16:29:14 -0700 Subject: [PATCH] Remove redundancy in ATM/iATM range calcs; un-revert ammo selection --- .../client/bot/princess/FireControl.java | 8 ++--- .../client/bot/princess/WeaponFireInfo.java | 8 +++-- .../ui/swing/unitDisplay/WeaponPanel.java | 31 +++++-------------- megamek/src/megamek/common/Compute.java | 14 ++++++--- megamek/src/megamek/server/GameManager.java | 31 ++++++++++--------- 5 files changed, 43 insertions(+), 49 deletions(-) diff --git a/megamek/src/megamek/client/bot/princess/FireControl.java b/megamek/src/megamek/client/bot/princess/FireControl.java index 97d2940d7c6..7431b08655d 100644 --- a/megamek/src/megamek/client/bot/princess/FireControl.java +++ b/megamek/src/megamek/client/bot/princess/FireControl.java @@ -1213,7 +1213,7 @@ private String checkGuess(final Entity shooter, } else { // For certain weapon types, look over all their loaded ammos List ammos; - if (wtype.getAmmoType() == AmmoType.T_ATM || wtype.getAmmoType() == AmmoType.T_MML) { + if (List.of(AmmoType.T_ATM, AmmoType.T_IATM, AmmoType.T_MML).contains(wtype.getAmmoType())) { ammos = shooter.getAmmo(weapon); } else { // Otherwise assume the current loaded ammo is suitable representative @@ -1810,7 +1810,7 @@ FiringPlan guessFullAirToGroundPlan(final Entity shooter, } else { // For certain weapon types, look over all their loaded ammos List ammos; - if (wtype.getAmmoType() == AmmoType.T_ATM || wtype.getAmmoType() == AmmoType.T_MML) { + if (List.of(AmmoType.T_ATM, AmmoType.T_IATM, AmmoType.T_MML).contains(wtype.getAmmoType())) { ammos = shooter.getAmmo(weapon); } else { // Otherwise assume the current loaded ammo is suitable representative @@ -2649,7 +2649,7 @@ public static double getMaxDamageAtRange(final Entity shooter, // For certain weapon types, look over all their loaded ammos List ammos; - if (weaponType.getAmmoType() == AmmoType.T_ATM || weaponType.getAmmoType() == AmmoType.T_MML) { + if (List.of(AmmoType.T_ATM, AmmoType.T_IATM, AmmoType.T_MML).contains(weaponType.getAmmoType())) { ammos = shooter.getAmmo(weapon); } else { // Otherwise assume the current loaded ammo is suitable representative @@ -2728,7 +2728,7 @@ void loadAmmo(final Entity shooter, } final AmmoMounted suggestedAmmo = info.getAmmo(); - final AmmoMounted mountedAmmo = getPreferredAmmo(shooter, info.getTarget(), currentWeapon); + final AmmoMounted mountedAmmo = getPreferredAmmo(shooter, info.getTarget(), currentWeapon, suggestedAmmo); // if we found preferred ammo but can't apply it to the weapon, log it and continue. if ((null != mountedAmmo) && !shooter.loadWeapon(currentWeapon, mountedAmmo)) { LogManager.getLogger().warn(shooter.getDisplayName() + " tried to load " diff --git a/megamek/src/megamek/client/bot/princess/WeaponFireInfo.java b/megamek/src/megamek/client/bot/princess/WeaponFireInfo.java index 592031861d7..b0bef4aec3b 100644 --- a/megamek/src/megamek/client/bot/princess/WeaponFireInfo.java +++ b/megamek/src/megamek/client/bot/princess/WeaponFireInfo.java @@ -421,9 +421,11 @@ private WeaponAttackAction buildBombAttackAction(final HashMap bo // but we'll roll an "average" cluster for the given weapon size to estimate damage. if ((weaponType.getDamage() == WeaponType.DAMAGE_BY_CLUSTERTABLE) || (weaponType.getDamage() == WeaponType.DAMAGE_ARTILLERY)) { - // Assume average cluster size for this weapon - int rs = weaponType.getRackSize(); - return Compute.calculateClusterHitTableAmount(7, rs); + // Assume average cluster size for this weapon, unless it has Streak capabilities + if (!List.of(AmmoType.T_SRM_STREAK, AmmoType.T_LRM_STREAK, AmmoType.T_IATM).contains(weaponType.getAmmoType())) { + int rs = weaponType.getRackSize(); + return Compute.calculateClusterHitTableAmount(7, rs); + } } // infantry weapons use number of troopers multiplied by weapon damage, diff --git a/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java b/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java index be3d0f4732a..f78a62a570e 100644 --- a/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java +++ b/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java @@ -2086,42 +2086,25 @@ private void setFieldOfFire(WeaponMounted mounted) { ranges[1] = new int[] { 0, 0, 0, 0, 0 }; } - // Override for the various ATM and MML ammos + // Override for the MML ammos if (atype != null) { - if (atype.getAmmoType() == AmmoType.T_ATM) { - if (atype.getMunitionType().contains(AmmoType.Munitions.M_EXTENDED_RANGE)) { - ranges[0] = new int[] { 4, 9, 18, 27, 36 }; - } else if (atype.getMunitionType().contains(AmmoType.Munitions.M_HIGH_EXPLOSIVE)) { - ranges[0] = new int[] { 0, 3, 6, 9, 12 }; - } else { - ranges[0] = new int[] { 4, 5, 10, 15, 20 }; - } - } else if (atype.getAmmoType() == AmmoType.T_MML) { + if (atype.getAmmoType() == AmmoType.T_MML) { if (atype.hasFlag(AmmoType.F_MML_LRM)) { if (atype.getMunitionType().contains(AmmoType.Munitions.M_DEAD_FIRE)) { - ranges[0] = new int[] { 4, 5, 10, 15, 20 }; + ranges[0] = new int[]{4, 5, 10, 15, 20}; } else { - ranges[0] = new int[] { 6, 7, 14, 21, 28 }; + ranges[0] = new int[]{6, 7, 14, 21, 28}; } } else { if (atype.getMunitionType().contains(AmmoType.Munitions.M_DEAD_FIRE)) { - ranges[0] = new int[] { 0, 2, 4, 6, 8 }; + ranges[0] = new int[]{0, 2, 4, 6, 8}; } else { - ranges[0] = new int[] { 0, 3, 6, 9, 12 }; + ranges[0] = new int[]{0, 3, 6, 9, 12}; } } - } else if (atype.getAmmoType() == AmmoType.T_IATM) { - if (atype.getMunitionType().contains(AmmoType.Munitions.M_EXTENDED_RANGE)) { - ranges[0] = new int[] { 4, 9, 18, 27, 36 }; - } else if (atype.getMunitionType().contains(AmmoType.Munitions.M_HIGH_EXPLOSIVE)) { - ranges[0] = new int[] { 0, 3, 6, 9, 12 }; - } else if (atype.getMunitionType().contains(AmmoType.Munitions.M_IATM_IMP)) { - ranges[0] = new int[] { 0, 3, 6, 9, 12 }; - } else { - ranges[0] = new int[] { 4, 5, 10, 15, 20 }; - } } } + // No minimum range for hotload if ((mounted.getLinked() != null) && mounted.getLinked().isHotLoaded()) { ranges[0][0] = 0; diff --git a/megamek/src/megamek/common/Compute.java b/megamek/src/megamek/common/Compute.java index e122f4d0308..022d835058b 100644 --- a/megamek/src/megamek/common/Compute.java +++ b/megamek/src/megamek/common/Compute.java @@ -1335,7 +1335,7 @@ public static ToHitData getRangeMods(Game game, Entity ae, WeaponMounted weapon, } int maxRange = wtype.getMaxRange(weapon, ammo); - // if aero and greater than max range then swith to range_out + // if aero and greater than max range then switch to range_out if ((ae.isAirborne() || (ae.usesWeaponBays() && game.getBoard() .onGround())) && (range > maxRange)) { range = RangeType.RANGE_OUT; @@ -3211,18 +3211,22 @@ public static float getExpectedDamage(Game g, WeaponAttackAction waa, } } - if (use_table == true) { + if (use_table) { if (!(attacker instanceof BattleArmor)) { if (weapon.getLinked() == null) { return 0.0f; } } + AmmoType at = null; - if ((weapon.getLinked() != null) + if (waa.getAmmoId() != -1) { + // If a preferred ammo has been set for this WAA, use that + at = waa.getEntity(g).getAmmo(waa.getAmmoId()).getType(); + } else if ((weapon.getLinked() != null) && (weapon.getLinked().getType() instanceof AmmoType)) { at = (AmmoType) weapon.getLinked().getType(); - fDamage = at.getDamagePerShot(); } + fDamage = (at != null) ? at.getDamagePerShot() : fDamage; float fHits = 0.0f; if ((wt.getRackSize() != 40) && (wt.getRackSize() != 30)) { @@ -3230,8 +3234,10 @@ public static float getExpectedDamage(Game g, WeaponAttackAction waa, } else { fHits = 2.0f * expectedHitsByRackSize[wt.getRackSize() / 2]; } + // Streaks / iATMs will _all_ hit, if they hit at all. if (((wt.getAmmoType() == AmmoType.T_SRM_STREAK) || (wt.getAmmoType() == AmmoType.T_LRM_STREAK)) + || (wt.getAmmoType() == AmmoType.T_IATM) && !ComputeECM.isAffectedByAngelECM(attacker, attacker .getPosition(), waa.getTarget(g).getPosition(), allECMInfo)) { diff --git a/megamek/src/megamek/server/GameManager.java b/megamek/src/megamek/server/GameManager.java index 1779cd62ab4..4927c3cb74a 100644 --- a/megamek/src/megamek/server/GameManager.java +++ b/megamek/src/megamek/server/GameManager.java @@ -43,6 +43,7 @@ import megamek.common.util.fileUtils.MegaMekFile; import megamek.common.verifier.*; import megamek.common.weapons.*; +import megamek.common.weapons.bayweapons.BayWeapon; import megamek.common.weapons.infantry.InfantryWeapon; import megamek.server.commands.*; import megamek.server.victory.VictoryResult; @@ -25358,20 +25359,22 @@ private Vector applyAeroCritical(Aero aero, int loc, CriticalSlot cs, in } } // if this is a weapons bay then also hit all the other weapons - for (WeaponMounted bayWeap : ((WeaponMounted) equipmentHit).getBayWeapons()) { - bayWeap.setHit(true); - // Taharqa : We should also damage the critical slot, or MM and MHQ - // won't remember that this weapon is damaged on the MUL file - for (int i = 0; i < aero.getNumberOfCriticals(loc); i++) { - CriticalSlot slot1 = aero.getCritical(loc, i); - if ((slot1 == null) - || (slot1.getType() == CriticalSlot.TYPE_SYSTEM)) { - continue; - } - Mounted mounted = slot1.getMount(); - if (mounted.equals(bayWeap)) { - aero.hitAllCriticals(loc, i); - break; + if (equipmentHit instanceof WeaponMounted) { + for (WeaponMounted bayWeap : ((WeaponMounted) equipmentHit).getBayWeapons()) { + bayWeap.setHit(true); + // Taharqa : We should also damage the critical slot, or MM and MHQ + // won't remember that this weapon is damaged on the MUL file + for (int i = 0; i < aero.getNumberOfCriticals(loc); i++) { + CriticalSlot slot1 = aero.getCritical(loc, i); + if ((slot1 == null) + || (slot1.getType() == CriticalSlot.TYPE_SYSTEM)) { + continue; + } + Mounted mounted = slot1.getMount(); + if (mounted.equals(bayWeap)) { + aero.hitAllCriticals(loc, i); + break; + } } } }