Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 4801: silent NPE while Princess moving Wraith BA #4802

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions megamek/src/megamek/client/bot/princess/InfantryFireControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.util.ArrayList;
import java.util.List;

import static megamek.common.WeaponType.F_ARTILLERY;

/**
* This class is intended to help the bot calculate firing plans for infantry
* units.
Expand Down Expand Up @@ -67,8 +65,7 @@ public double getMaxDamageAtRange(final MovePath shooterPath, final MovePath tar
boolean shooterIsActualInfantry = shooter.hasETypeFlag(Entity.ETYPE_INFANTRY)
&& !shooter.hasETypeFlag(Entity.ETYPE_BATTLEARMOR);
// field guns can't fire if the unit in question moved
boolean fieldGunsDoDamage = (shooterIsActualInfantry && shooterPath.getMpUsed() == 0)
|| !shooterIsActualInfantry;
boolean otherWeaponsMayShoot = !shooterIsActualInfantry || shooterPath.getMpUsed() == 0;
boolean inBuilding = Compute.isInBuilding(target.getGame(), targetPath.getFinalElevation(),
targetPath.getFinalCoords());
boolean inOpen = ServerHelper.infantryInOpen(target, targetHex, target.getGame(), targetIsPlatoon, false,
Expand Down Expand Up @@ -96,8 +93,8 @@ public double getMaxDamageAtRange(final MovePath shooterPath, final MovePath tar
// weapon damage, multiply by building dmg reduction.
// 4. Shooter is non-infantry, target is infantry in "cover". Use
// "directBlowInfantryDamage".
// 5. Shooter is non-infantry, target is non-infantry. Use base
// class.
// 5. Shooter is infantry with field gun / field artillery and needs special damage calc.
// 6. Shooter is non-infantry, target is non-infantry. Use base class.

// case 1
if (weaponType.hasFlag(WeaponType.F_INFANTRY)) {
Expand All @@ -111,10 +108,8 @@ public double getMaxDamageAtRange(final MovePath shooterPath, final MovePath tar

maxInfantryWeaponDamage += ((InfantryWeapon) weaponType).getInfantryDamage()
* infantryCount;
// field guns can't fire if the infantry unit has done anything
// other than turning
} else if (targetIsActualInfantry && fieldGunsDoDamage) {
double damage = 0;
} else if (targetIsActualInfantry && otherWeaponsMayShoot) {
double damage;

// if we're outside, use the direct blow infantry damage
// calculation
Expand All @@ -134,15 +129,17 @@ public double getMaxDamageAtRange(final MovePath shooterPath, final MovePath tar
}

maxFGDamage += damage;
// field guns can't fire if the infantry unit has done anything
// other than turning
// case 5
} else if (fieldGunsDoDamage) {
// Some FGs are artillery, so check both damage/shot * shot num _and_ rack size.
AmmoType ammoType = (AmmoType) weapon.getLinked().getType();
int wDamage = (weaponType.hasFlag(F_ARTILLERY) ? weaponType.rackSize : weaponType.getDamage());
int ammoDamage = ammoType.getDamagePerShot()*ammoType.getShots();
maxFGDamage += Math.max(wDamage, ammoDamage);
} else if (otherWeaponsMayShoot) {
// case 5
if (shooterIsActualInfantry) {
// field guns can't fire if the infantry unit has done anything
// other than turning, so we only get here if infantry has not used MP.
// All valid Infantry Field Weapons can consider rackSize as their damage.
maxFGDamage += weaponType.rackSize;
// Case 6: all other unit types / weapons
} else {
maxFGDamage += weaponType.getDamage();
}
}
}

Expand Down