Skip to content

Commit

Permalink
prevent AMS targeting mortars
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Oct 31, 2024
1 parent 347ab66 commit 937879d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
41 changes: 14 additions & 27 deletions megamek/src/megamek/server/totalwarfare/TWGameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9666,19 +9666,16 @@ public void assignAMS() {
WeaponHandler wh = (WeaponHandler) ah;
WeaponAttackAction waa = wh.waa;

// for artillery attacks, the attacking entity
// might no longer be in the game.
// TODO : Yeah, I know there's an exploit here, but better able to shoot some
// ArrowIVs than none, right?
// for artillery attacks, the attacking entity might no longer be in the game.
// TODO : Yeah, I know there's an exploit here, but better able to shoot some ArrowIVs than none, right?
if (game.getEntity(waa.getEntityId()) == null) {
logger.info("Can't Assign AMS: Artillery firer is null!");
continue;
}

Mounted<?> weapon = game.getEntity(waa.getEntityId()).getEquipment(waa.getWeaponId());

// Only entities can have AMS. Arrow IV doesn't target an entity until later, so
// we have to ignore them
// Only entities can have AMS. Arrow IV doesn't target an entity until later, so we have to ignore them
if (!(waa instanceof ArtilleryAttackAction) && (Targetable.TYPE_ENTITY != waa.getTargetType())) {
continue;
}
Expand All @@ -9688,9 +9685,7 @@ public void assignAMS() {
continue;
}

// Can only use AMS versus missiles. Artillery Bays might be firing Arrow IV
// homing missiles,
// but lack the flag
// Can only use AMS versus missiles. Artillery Bays might be firing Arrow IV homing missiles, but lack the flag
boolean isHomingMissile = false;
if (wh instanceof ArtilleryWeaponIndirectHomingHandler
|| wh instanceof ArtilleryBayWeaponIndirectHomingHandler) {
Expand All @@ -9701,7 +9696,8 @@ public void assignAMS() {
isHomingMissile = true;
}
}
if (!weapon.getType().hasFlag(WeaponType.F_MISSILE) && !isHomingMissile) {
if ((!weapon.getType().hasFlag(WeaponType.F_MISSILE) && !isHomingMissile)
|| weapon.getType().hasFlag(WeaponType.F_MEK_MORTAR)) {
continue;
}

Expand Down Expand Up @@ -9797,32 +9793,27 @@ private WeaponAttackAction manuallyAssignAPDSTarget(WeaponMounted apds,
// Create a list of valid assignments for this APDS
List<WeaponAttackAction> vAttacksInArc = new ArrayList<>(vAttacks.size());
for (WeaponHandler wr : vAttacks) {
boolean isInArc = Compute.isInArc(e.getGame(), e.getId(),
e.getEquipmentNum(apds),
game.getEntity(wr.waa.getEntityId()));
boolean isInRange = e.getPosition().distance(
wr.getWaa().getTarget(game).getPosition()) <= 3;
boolean isInArc = Compute.isInArc(e.getGame(), e.getId(), e.getEquipmentNum(apds), game.getEntity(wr.waa.getEntityId()));
boolean isInRange = e.getPosition().distance(wr.getWaa().getTarget(game).getPosition()) <= 3;
if (isInArc && isInRange) {
vAttacksInArc.add(wr.waa);
}
}

// If there are no valid attacks left, don't bother
if (vAttacksInArc.size() < 1) {
if (vAttacksInArc.isEmpty()) {
return null;
}

WeaponAttackAction targetedWAA = null;

if (apds.curMode().equals("Automatic")) {
targetedWAA = Compute.getHighestExpectedDamage(game,
vAttacksInArc, true);
targetedWAA = Compute.getHighestExpectedDamage(game, vAttacksInArc, true);
} else {
// Send a client feedback request
List<Integer> apdsDists = new ArrayList<>();
for (WeaponAttackAction waa : vAttacksInArc) {
apdsDists.add(waa.getTarget(game).getPosition()
.distance(e.getPosition()));
apdsDists.add(waa.getTarget(game).getPosition().distance(e.getPosition()));
}
sendAPDSAssignCFR(e, apdsDists, vAttacksInArc);
synchronized (cfrPacketQueue) {
Expand Down Expand Up @@ -9865,9 +9856,7 @@ private WeaponAttackAction manuallyAssignAPDSTarget(WeaponMounted apds,
* @param vAttacks
* List of missile attacks directed at e
*/
private void manuallyAssignAMSTarget(Entity e,
Vector<WeaponHandler> vAttacks) {
// Fix for bug #1051 - don't send the targeting nag for a shutdown unit
private void manuallyAssignAMSTarget(Entity e, Vector<WeaponHandler> vAttacks) {
if (e.isShutDown()) {
return;
}
Expand All @@ -9883,15 +9872,13 @@ private void manuallyAssignAMSTarget(Entity e,
List<WeaponAttackAction> vAttacksInArc = new ArrayList<>(vAttacks.size());
for (WeaponHandler wr : vAttacks) {
if (!amsTargets.contains(wr.waa)
&& Compute.isInArc(game, e.getId(),
e.getEquipmentNum(ams),
game.getEntity(wr.waa.getEntityId()))) {
&& Compute.isInArc(game, e.getId(), e.getEquipmentNum(ams), game.getEntity(wr.waa.getEntityId()))) {
vAttacksInArc.add(wr.waa);
}
}

// If there are no valid attacks left, don't bother
if (vAttacksInArc.size() < 1) {
if (vAttacksInArc.isEmpty()) {
continue;
}

Expand Down
24 changes: 24 additions & 0 deletions megamek/testresources/data/scenarios/test_setups/ams_mortar.mms
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
MMSVersion: 2
name: AMS vs Mortars
planet: None
description: AMS may not engage mortars - test setup
map: Beginner Box/16x17 Grassland 1.board

options:
#off:
# - auto_ams

factions:
- name: Test Player

units:
#AMS
- fullname: Atlas AS7-K
at: [ 9, 7 ]
facing: 3
#Mortar and SRM
- fullname: Minsk 2
at: [ 9, 14 ]
crew:
gunnery: 0

0 comments on commit 937879d

Please sign in to comment.