Skip to content

Commit

Permalink
Merge pull request MegaMek#4802 from Sleet01/fix_4801_silent_NPE_whil…
Browse files Browse the repository at this point in the history
…e_princess_moving_Wraith_BA

Fix 4801: silent NPE while Princess moving Wraith BA
  • Loading branch information
NickAragua authored Sep 24, 2023
2 parents 8c988c6 + c7fad9f commit 5fa6bd8
Showing 1 changed file with 16 additions and 19 deletions.
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

0 comments on commit 5fa6bd8

Please sign in to comment.