From 458c2dd1933fb727cff39694dfd620c7bdac07a8 Mon Sep 17 00:00:00 2001 From: psikomonkie <189469115+psikomonkie@users.noreply.github.com> Date: Sun, 22 Dec 2024 21:28:49 -0500 Subject: [PATCH 1/2] Issue 6305: Partial Cover from water should now apply and hull down should grant a bonus now --- .../common/actions/WeaponAttackAction.java | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/megamek/src/megamek/common/actions/WeaponAttackAction.java b/megamek/src/megamek/common/actions/WeaponAttackAction.java index 94a32d00e34..82e34ceebf0 100644 --- a/megamek/src/megamek/common/actions/WeaponAttackAction.java +++ b/megamek/src/megamek/common/actions/WeaponAttackAction.java @@ -4250,35 +4250,6 @@ private static ToHitData compileTargetToHitMods(Game game, Entity ae, Targetable toHit.addModifier(te.getEvasionBonus(), Messages.getString("WeaponAttackAction.TeEvading")); } - // Hull Down - if ((te != null) && te.isHullDown()) { - if ((te instanceof Mek) && !(te instanceof QuadVee && te.getConversionMode() == QuadVee.CONV_MODE_VEHICLE) - && (los.getTargetCover() > LosEffects.COVER_NONE)) { - toHit.addModifier(2, Messages.getString("WeaponAttackAction.HullDown")); - } - // tanks going Hull Down is different rules then 'Meks, the - // direction the attack comes from matters - else if ((te instanceof Tank - || (te instanceof QuadVee && te.getConversionMode() == QuadVee.CONV_MODE_VEHICLE)) - && targHex.containsTerrain(Terrains.FORTIFIED)) { - // TODO make this a LoS mod so that attacks will come in from - // directions that grant Hull Down Mods - int moveInDirection; - - if (!((Tank) te).isBackedIntoHullDown()) { - moveInDirection = ToHitData.SIDE_FRONT; - } else { - moveInDirection = ToHitData.SIDE_REAR; - } - - if ((te.sideTable(ae.getPosition()) == moveInDirection) - || (te.sideTable(ae.getPosition()) == ToHitData.SIDE_LEFT) - || (te.sideTable(ae.getPosition()) == ToHitData.SIDE_RIGHT)) { - toHit.addModifier(2, Messages.getString("WeaponAttackAction.HullDown")); - } - } - } - // Infantry taking cover per TacOps special rules if ((te instanceof Infantry) && ((Infantry) te).isTakingCover()) { if (te.getPosition().direction(ae.getPosition()) == te.getFacing()) { @@ -4668,7 +4639,7 @@ private static ToHitData compileTerrainAndLosToHitMods(Game game, Entity ae, Tar // target in partial water && (targHex.terrainLevel(Terrains.WATER) == partialWaterLevel) && (targEl == 0) && (te.height() > 0)) { los.setTargetCover(los.getTargetCover() | LosEffects.COVER_HORIZONTAL); - losMods = los.losModifiers(game, eistatus, underWater); + toHit.append(los.losModifiers(game, eistatus, underWater)); } // Change hit table for partial cover, accommodate for partial underwater (legs) @@ -4701,6 +4672,35 @@ private static ToHitData compileTerrainAndLosToHitMods(Game game, Entity ae, Tar } } + // Hull Down - Some cover states are dependent on LOS + if ((te != null) && te.isHullDown()) { + if ((te instanceof Mek) && !(te instanceof QuadVee && te.getConversionMode() == QuadVee.CONV_MODE_VEHICLE) + && (los.getTargetCover() > LosEffects.COVER_NONE)) { + toHit.addModifier(2, Messages.getString("WeaponAttackAction.HullDown")); + } + // tanks going Hull Down is different rules then 'Meks, the + // direction the attack comes from matters + else if ((te instanceof Tank + || (te instanceof QuadVee && te.getConversionMode() == QuadVee.CONV_MODE_VEHICLE)) + && targHex.containsTerrain(Terrains.FORTIFIED)) { + // TODO make this a LoS mod so that attacks will come in from + // directions that grant Hull Down Mods + int moveInDirection; + + if (!((Tank) te).isBackedIntoHullDown()) { + moveInDirection = ToHitData.SIDE_FRONT; + } else { + moveInDirection = ToHitData.SIDE_REAR; + } + + if ((te.sideTable(ae.getPosition()) == moveInDirection) + || (te.sideTable(ae.getPosition()) == ToHitData.SIDE_LEFT) + || (te.sideTable(ae.getPosition()) == ToHitData.SIDE_RIGHT)) { + toHit.addModifier(2, Messages.getString("WeaponAttackAction.HullDown")); + } + } + } + // Special Equipment // BAP Targeting rule enabled - TO:AR 6th p.97 From feb13bec50875134785a64cc5372b5a2c2f41886 Mon Sep 17 00:00:00 2001 From: psikomonkie <189469115+psikomonkie@users.noreply.github.com> Date: Mon, 23 Dec 2024 11:18:17 -0500 Subject: [PATCH 2/2] Issue 6305: Partial Cover from water should now apply and hull down should grant a bonus now - NPE prevention --- megamek/src/megamek/common/actions/WeaponAttackAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/megamek/src/megamek/common/actions/WeaponAttackAction.java b/megamek/src/megamek/common/actions/WeaponAttackAction.java index 82e34ceebf0..f3877de4896 100644 --- a/megamek/src/megamek/common/actions/WeaponAttackAction.java +++ b/megamek/src/megamek/common/actions/WeaponAttackAction.java @@ -4682,7 +4682,7 @@ private static ToHitData compileTerrainAndLosToHitMods(Game game, Entity ae, Tar // direction the attack comes from matters else if ((te instanceof Tank || (te instanceof QuadVee && te.getConversionMode() == QuadVee.CONV_MODE_VEHICLE)) - && targHex.containsTerrain(Terrains.FORTIFIED)) { + && targetHexContainsFortified) { // TODO make this a LoS mod so that attacks will come in from // directions that grant Hull Down Mods int moveInDirection;