Skip to content

Commit

Permalink
Merge pull request #5485 from Sleet01/Fix_5483_npe_with_searchlight_a…
Browse files Browse the repository at this point in the history
…nd_offboard_fled_or_undeployed_target

Fix 5483: Make various calls safer from NPE and ensure searchlight target on board
  • Loading branch information
HammerGS authored May 18, 2024
2 parents 334bee4 + f81ce48 commit 31a6aa3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
8 changes: 5 additions & 3 deletions megamek/src/megamek/client/ui/swing/FiringDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -1941,11 +1941,13 @@ void updateFlipArms(boolean armsFlipped) {
}

protected void updateSearchlight() {
setSearchlightEnabled((ce() != null)
setSearchlightEnabled(
(ce() != null)
&& (target != null)
&& ce().isUsingSearchlight()
&& ce().getCrew().isActive()
&& (clientgui.getClient().getGame().getBoard().contains(target.getPosition()))
&& !ce().isHidden()
&& ce().getCrew().isActive()
&& ce().isUsingSearchlight()
&& SearchlightAttackAction.isPossible(clientgui.getClient().getGame(), cen, target, null)
&& !((ce() instanceof Tank) && (((Tank) ce()).getStunnedTurns() > 0)));
}
Expand Down
23 changes: 19 additions & 4 deletions megamek/src/megamek/common/Compute.java
Original file line number Diff line number Diff line change
Expand Up @@ -4028,10 +4028,20 @@ public static boolean isInArc(Coords src, int facing, Targetable target,
Vector<Coords> tPosV = new Vector<>();
tPosV.add(target.getPosition());
// check for secondary positions
if ((target instanceof Entity)
&& (null != ((Entity) target).getSecondaryPositions())) {
for (int key : ((Entity) target).getSecondaryPositions().keySet()) {
tPosV.add(((Entity) target).getSecondaryPositions().get(key));
if (target instanceof Entity) {
Map<Integer, Coords> secondaryPositions = ((Entity) target).getSecondaryPositions();
if (null != secondaryPositions && !secondaryPositions.isEmpty()) {
// Some units fill additional hexes
for (Coords hex : secondaryPositions.values()) {
// Some hexes may not be configured, or be invalid
if (null != hex) {
tPosV.add(hex);
} else {
LogManager.getLogger().warn(
"Entity " + ((Entity) target).getDisplayName() + " has null secondary location!"
);
}
}
}
}

Expand Down Expand Up @@ -4068,6 +4078,11 @@ public static boolean isInArc(Coords src, int facing, Vector<Coords> destV,
// if any of the destination coords are in the right place, then return
// true
for (Coords dest : destV) {
// Sometimes we get non-null destV containing null Coord entries.
if (null == dest) {
return true;
}

// calculate firing angle
int fa = src.degree(dest) - (facing * 60);
if (fa < 0) {
Expand Down

0 comments on commit 31a6aa3

Please sign in to comment.