Skip to content

Commit

Permalink
refactor: Use stream composition for finding TAG spotters
Browse files Browse the repository at this point in the history
  • Loading branch information
Saklad5 committed Aug 18, 2024
1 parent 175a3f1 commit 2db8795
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions megamek/src/megamek/common/actions/WeaponAttackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,12 @@ private static ToHitData toHitCalc(Game game, int attackerId, Targetable target,
|| (atype.getAmmoType() == AmmoType.T_NLRM)
|| (atype.getAmmoType() == AmmoType.T_MEK_MORTAR))
&& (munition.contains(AmmoType.Munitions.M_SEMIGUIDED))) {
for (TagInfo ti : game.getTagInfo()) {
if (target.getId() == ti.target.getId()) {
spotter = game.getEntity(ti.attackerId);
}
}
final Targetable currentTarget = target; // Required for concurrency reasons
spotter = game.getTagInfo().stream()
.filter(ti -> currentTarget.getId() == ti.target.getId())
.findAny()
.map(ti -> game.getEntity(ti.attackerId))
.orElse(null);
}
}

Expand Down

0 comments on commit 2db8795

Please sign in to comment.