Skip to content

Commit

Permalink
Merge pull request #6115 from SJuliez/inarc-brush-off-fix
Browse files Browse the repository at this point in the history
#6063: Fix targeting choice with iNarcs
  • Loading branch information
HammerGS authored Oct 21, 2024
2 parents 795f2c5 + dde30ed commit 09b63d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
19 changes: 15 additions & 4 deletions megamek/src/megamek/client/ui/swing/TargetChoiceDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import megamek.client.ui.swing.tooltip.UnitToolTip;
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.*;
import megamek.common.actions.BrushOffAttackAction;
import megamek.common.actions.WeaponAttackAction;
import megamek.common.annotations.Nullable;

Expand Down Expand Up @@ -90,15 +91,25 @@ protected String infoText(Targetable target) {
String result = "";

if (firingEntity != null) {
ToHitData thd = WeaponAttackAction.toHit(clientGUI.getClient().getGame(), firingEntity.getId(), target);
thd.setLocation(target.getPosition());
thd.setRange(firingEntity.getPosition().distance(target.getPosition()));
ToHitData thd;
if (target instanceof INarcPod) {
// must not call getPosition() on INarcPods! Check both arms if necessary
thd = BrushOffAttackAction.toHit(clientGUI.getClient().getGame(),
firingEntity.getId(), target, BrushOffAttackAction.RIGHT);
if (thd.getValue() == TargetRoll.IMPOSSIBLE) {
thd = BrushOffAttackAction.toHit(clientGUI.getClient().getGame(),
firingEntity.getId(), target, BrushOffAttackAction.LEFT);
}
} else {
thd = WeaponAttackAction.toHit(clientGUI.getClient().getGame(), firingEntity.getId(), target);
thd.setLocation(target.getPosition());
thd.setRange(firingEntity.getPosition().distance(target.getPosition()));
}
if (thd.needsRoll()) {
int mod = thd.getValue();
result += "<br>Target To Hit Mod: <b>" + (mod < 0 ? "" : "+") + mod + "</b>";
} else {
result += "<br><b>" + thd.getValueAsString() + " To Hit</b>: " + thd.getDesc();

}
}

Expand Down
5 changes: 4 additions & 1 deletion megamek/src/megamek/common/actions/WeaponAttackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,10 @@ public static ToHitData toHit(Game game, int attackerId, Targetable target) {
int aElev = ae.getElevation();
int tElev = target.getElevation();
int targEl;
if (te == null) {
if (target instanceof INarcPod) {
// brush off attached INarcs on oneself; use left arm as a placeholder here as no choice has been made
return BrushOffAttackAction.toHit(game, attackerId, target, BrushOffAttackAction.LEFT);
} else if (te == null) {
targEl = game.getBoard().getHex(target.getPosition()).floor();
} else {
targEl = te.relHeight();
Expand Down

0 comments on commit 09b63d6

Please sign in to comment.