Skip to content

Commit

Permalink
Merge pull request #3060 from NickAragua/to_hit_modifier_updates
Browse files Browse the repository at this point in the history
Fix #2951 and then some
  • Loading branch information
NickAragua authored Aug 18, 2021
2 parents 5ddb6de + 415a2df commit e574ee1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
4 changes: 3 additions & 1 deletion megamek/i18n/megamek/client/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3200,7 +3200,7 @@ WeaponAttackAction.Grappled=target grappled
WeaponAttackAction.GrappledByChain=target grappled (Chain Whip)
WeaponAttackAction.HullDown=Hull down target
WeaponAttackAction.ImmobileAero=target is not moving
WeaponAttackAction.ImmobileDs=immobile dropship
WeaponAttackAction.ImmobileDs=target is grounded DropShip
WeaponAttackAction.iNarcHoming=iNarc homing pod
WeaponAttackAction.LowProfile=narrow/low profile
WeaponAttackAction.MwTarget=ejected Pilot target
Expand All @@ -3213,6 +3213,8 @@ WeaponAttackAction.SensorShadow=Target in Sensor Shadow
WeaponAttackAction.SquadTarget=infantry squad target
WeaponAttackAction.TeGroundAttack=target making air-to-ground attack
WeaponAttackAction.TeSuperheavyMech=target is superheavy mech
WeaponAttackAction.TeLargeSupportUnit=target is large support unit
WeaponAttackAction.TeGroundedSmallCraft=target is grounded small craft
WeaponAttackAction.TeVehicle=target is vehicle
WeaponAttackAction.TeVelocity=velocity
#WeaponAttackAction - impossible/autohit shot descriptions
Expand Down
1 change: 0 additions & 1 deletion megamek/src/megamek/common/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16168,5 +16168,4 @@ public void setForceId(int newId) {
public boolean partOfForce() {
return forceId != Force.NO_FORCE;
}

}
17 changes: 11 additions & 6 deletions megamek/src/megamek/common/actions/PhysicalAttackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package megamek.common.actions;

import megamek.client.ui.Messages;
import megamek.common.BattleArmor;
import megamek.common.Building;
import megamek.common.Compute;
Expand All @@ -27,10 +28,10 @@
import megamek.common.IHex;
import megamek.common.IPlayer;
import megamek.common.Infantry;
import megamek.common.LargeSupportTank;
import megamek.common.Mech;
import megamek.common.MechWarrior;
import megamek.common.RangeType;
import megamek.common.SmallCraft;
import megamek.common.TargetRoll;
import megamek.common.Targetable;
import megamek.common.Terrains;
Expand Down Expand Up @@ -234,15 +235,19 @@ protected static void setCommonModifiers(ToHitData toHit, IGame game,

// target prone
if (te.isProne()) {
toHit.addModifier(-2, "target prone and adjacent");
toHit.addModifier(-2, Messages.getString("WeaponAttackAction.ProneAdj"));
}

if (te instanceof LargeSupportTank) {
toHit.addModifier(-2, "target is large support tank");
if ((te.getWeightClass() == EntityWeightClass.WEIGHT_LARGE_SUPPORT) && !te.isAirborne() && !te.isSpaceborne()) {
toHit.addModifier(-2, Messages.getString("WeaponAttackAction.TeLargeSupportUnit"));
}

if (te instanceof Dropship) {
toHit.addModifier(-2, "target is dropship");
if (te instanceof SmallCraft) {
if (te instanceof Dropship) {
toHit.addModifier(-4, Messages.getString("WeaponAttackAction.ImmobileDs"));
} else {
toHit.addModifier(-2, Messages.getString("WeaponAttackAction.TeGroundedSmallCraft"));
}
}

IHex targHex = game.getBoard().getHex(te.getPosition());
Expand Down
23 changes: 19 additions & 4 deletions megamek/src/megamek/common/actions/WeaponAttackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import megamek.common.Entity;
import megamek.common.EntityMovementMode;
import megamek.common.EntityMovementType;
import megamek.common.EntityWeightClass;
import megamek.common.EquipmentType;
import megamek.common.GunEmplacement;
import megamek.common.HexTarget;
Expand All @@ -63,6 +64,7 @@
import megamek.common.QuadMech;
import megamek.common.QuadVee;
import megamek.common.RangeType;
import megamek.common.SmallCraft;
import megamek.common.SpaceStation;
import megamek.common.SpecialResolutionTracker;
import megamek.common.SupportTank;
Expand All @@ -74,6 +76,7 @@
import megamek.common.Terrains;
import megamek.common.ToHitData;
import megamek.common.TripodMech;
import megamek.common.UnitType;
import megamek.common.VTOL;
import megamek.common.Warship;
import megamek.common.WeaponType;
Expand Down Expand Up @@ -4271,13 +4274,15 @@ else if ((atype != null)
boolean mekMortarMunitionsIgnoreImmobile = wtype != null && wtype.hasFlag(WeaponType.F_MEK_MORTAR)
&& (atype != null) && (munition == AmmoType.M_AIRBURST);
if (wtype != null && !(wtype instanceof ArtilleryCannonWeapon) && !mekMortarMunitionsIgnoreImmobile) {
ToHitData immobileMod = Compute.getImmobileMod(target, aimingAt, aimingMode);
ToHitData immobileMod;
// grounded dropships are treated as immobile as well for purpose of
// the mods
if ((null != te) && !te.isAirborne() && !te.isSpaceborne() && (te instanceof Dropship)
&& ((Aero) te).isSpheroid()) {
if ((null != te) && !te.isAirborne() && !te.isSpaceborne() && (te instanceof Dropship)) {
immobileMod = new ToHitData(-4, Messages.getString("WeaponAttackAction.ImmobileDs"));
} else {
immobileMod = Compute.getImmobileMod(target, aimingAt, aimingMode);
}

if (immobileMod != null) {
toHit.append(immobileMod);
toSubtract += immobileMod.getValue();
Expand All @@ -4287,10 +4292,20 @@ else if ((atype != null)
// Unit-specific modifiers

// -1 to hit a SuperHeavy mech
if (te != null && (te instanceof Mech) && ((Mech) te).isSuperHeavy()) {
if ((te != null) && (te instanceof Mech) && ((Mech) te).isSuperHeavy()) {
toHit.addModifier(-1, Messages.getString("WeaponAttackAction.TeSuperheavyMech"));
}

// large support tanks get a -1 per TW
if ((te != null) && (te.getWeightClass() == EntityWeightClass.WEIGHT_LARGE_SUPPORT) && !te.isAirborne() && !te.isSpaceborne()) {
toHit.addModifier(-1, Messages.getString("WeaponAttackAction.TeLargeSupportUnit"));
}

// "grounded small craft" get a -1 per TW
if ((te instanceof SmallCraft) && (te.getUnitType() == UnitType.SMALL_CRAFT) && !te.isAirborne() && !te.isSpaceborne()) {
toHit.addModifier(-1, Messages.getString("WeaponAttackAction.TeGroundedSmallCraft"));
}

// Battle Armor targets are hard for Meks and Tanks to hit.
if (!isAttackerInfantry && (te instanceof BattleArmor)) {
toHit.addModifier(1, Messages.getString("WeaponAttackAction.BaTarget"));
Expand Down

0 comments on commit e574ee1

Please sign in to comment.