Skip to content

Commit

Permalink
refactor: Use stream composition for air-to-ground target modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Saklad5 committed Aug 24, 2024
1 parent 891a17d commit b21fe79
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions megamek/src/megamek/common/actions/WeaponAttackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3676,18 +3676,16 @@ private static ToHitData compileAeroAttackerToHitMods(Game game, Entity ae, Targ
}
// units making air to ground attacks are easier to hit by air-to-air
// attacks
if (Compute.isAirToAir(ae, target)) {
for (Enumeration<EntityAction> i = game.getActions(); i.hasMoreElements();) {
EntityAction ea = i.nextElement();
if (!(ea instanceof WeaponAttackAction)) {
continue;
}
WeaponAttackAction prevAttack = (WeaponAttackAction) ea;
if ((te != null && prevAttack.getEntityId() == te.getId()) && prevAttack.isAirToGround(game)) {
toHit.addModifier(-3, Messages.getString("WeaponAttackAction.TeGroundAttack"));
break;
}
}

// The ID of the entity being targeted.
final Optional<Integer> targetEntityId = Optional.ofNullable(te).map(Entity::getId);

if (Compute.isAirToAir(ae, target) && targetEntityId.isPresent() && game.getActionsVector().stream()
.filter(WeaponAttackAction.class::isInstance)
.map(WeaponAttackAction.class::cast)
.anyMatch(prevAttack -> prevAttack.getEntityId() == targetEntityId.orElseThrow() && prevAttack.isAirToGround(game))
) {
toHit.addModifier(-3, Messages.getString("WeaponAttackAction.TeGroundAttack"));
}
// grounded aero
if (!ae.isAirborne() && !ae.isSpaceborne()) {
Expand Down

0 comments on commit b21fe79

Please sign in to comment.