Skip to content

Commit

Permalink
Merge pull request #5814 from Sleet01/Fix_5796_npe_during_physical_ph…
Browse files Browse the repository at this point in the history
…ase_mm

Fix 5796: Safety check for entities with no hex location, e.g. just-loaded infantry
  • Loading branch information
Sleet01 authored Jul 28, 2024
2 parents 6ce0fe4 + f797f83 commit f50606e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions megamek/src/megamek/common/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10047,12 +10047,20 @@ public boolean isEligibleForPhysical() {
boolean canHit = false;
boolean friendlyFire = game.getOptions().booleanOption(OptionsConstants.BASE_FRIENDLY_FIRE);

if (getPosition() == null) {
return false; // not on board?
}

if ((this instanceof Infantry)
&& hasWorkingMisc(MiscType.F_TOOLS,
MiscType.S_DEMOLITION_CHARGE)) {
Hex hex = game.getBoard().getHex(getPosition());
if (hex == null) {
return false;
}
return hex.containsTerrain(Terrains.BUILDING);
}

// only mechs and protos have physical attacks (except tank charges)
if (!((this instanceof Mech) || (this instanceof Protomech) || (this instanceof Infantry))) {
return false;
Expand Down Expand Up @@ -10093,10 +10101,6 @@ && getCrew().isClanPilot() && !hasINarcPodsAttached()
return false;
}

if (getPosition() == null) {
return false; // not on board?
}

// check if we have iNarc pods attached that can be brushed off
if (hasINarcPodsAttached() && (this instanceof Mech)) {
return true;
Expand Down

0 comments on commit f50606e

Please sign in to comment.