From 9fccad749c2a5dec205480385e9a8d2e59c3c74d Mon Sep 17 00:00:00 2001 From: sleet01 Date: Sun, 28 Jul 2024 01:11:40 -0700 Subject: [PATCH 1/2] Safety check for entities with no hex location, e.g. just-loaded infantry --- megamek/src/megamek/common/Entity.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/megamek/src/megamek/common/Entity.java b/megamek/src/megamek/common/Entity.java index a42d4d7b6e4..2d5aeab6e41 100644 --- a/megamek/src/megamek/common/Entity.java +++ b/megamek/src/megamek/common/Entity.java @@ -10046,6 +10046,9 @@ public boolean isEligibleForPhysical() { && 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) From f797f8357164f119d9a2ec091b23bd03e5158bba Mon Sep 17 00:00:00 2001 From: sleet01 Date: Sun, 28 Jul 2024 13:08:54 -0700 Subject: [PATCH 2/2] Move existing getPosition() check to start of function --- megamek/src/megamek/common/Entity.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/megamek/src/megamek/common/Entity.java b/megamek/src/megamek/common/Entity.java index 2d5aeab6e41..7fed397555c 100644 --- a/megamek/src/megamek/common/Entity.java +++ b/megamek/src/megamek/common/Entity.java @@ -10042,6 +10042,10 @@ 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)) { @@ -10051,6 +10055,7 @@ && hasWorkingMisc(MiscType.F_TOOLS, } 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; @@ -10091,10 +10096,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;