/**
* To-hit number for the specified leg to kick
*/
public static ToHitData toHit(IGame game, int attackerId,
Targetable target, int leg) {
final Entity ae = game.getEntity(attackerId);
if (ae == null)
return new ToHitData(TargetRoll.IMPOSSIBLE,
"You can't attack from a null entity!");
if (!game.getOptions().booleanOption("tacops_jump_jet_attack"))
return new ToHitData(TargetRoll.IMPOSSIBLE, "no Jump Jet attack");
String impossible = toHitIsImpossible(game, ae, target);
if (impossible != null) {
return new ToHitData(TargetRoll.IMPOSSIBLE, "impossible");
}
IHex attHex = game.getBoard().getHex(ae.getPosition());
IHex targHex = game.getBoard().getHex(target.getPosition());
final int attackerElevation = ae.getElevation() + attHex.getElevation();
final int attackerHeight = attackerElevation + ae.getHeight();
final int targetElevation = target.getElevation()
+ targHex.getElevation();
final int targetHeight = targetElevation + target.getHeight();
int[] kickLegs = new int[2];
if (ae.entityIsQuad() && !ae.isProne()) {
kickLegs[0] = Mech.LOC_RARM;
kickLegs[1] = Mech.LOC_LARM;
} else {
kickLegs[0] = Mech.LOC_RLEG;
kickLegs[1] = Mech.LOC_LLEG;
}
ToHitData toHit;
// arguments legal?
if (leg != RIGHT && leg != LEFT && leg != BOTH) {
throw new IllegalArgumentException("Leg must be LEFT or RIGHT");
}
// non-mechs can't kick
if (!(ae instanceof Mech)) {
return new ToHitData(TargetRoll.IMPOSSIBLE, "Non-mechs can't kick");
}
if (leg == BOTH && !ae.isProne()) {
return new ToHitData(TargetRoll.IMPOSSIBLE,
"Only prone mechs can attack with both legs");
}
// check if legs are present & working
if ((ae.isLocationBad(kickLegs[0]) && (leg == BOTH || leg == LEFT))
|| (ae.isLocationBad(kickLegs[1]) && (leg == BOTH || leg == RIGHT))) {
return new ToHitData(TargetRoll.IMPOSSIBLE, "Leg missing");
}
// check if attacker even has jump jets!
for (Mounted m : ae.getMisc()) {
boolean hasJJ = false;
int loc = m.getLocation();
if (m.getType().hasFlag(MiscType.F_JUMP_JET)
&& m.isReady()
&& ((loc == kickLegs[0] && (leg == BOTH || leg == LEFT)) || (loc == kickLegs[1] && (leg == BOTH || leg == RIGHT)))) {
hasJJ = true;
break;
}
if (!hasJJ) {
return new ToHitData(TargetRoll.IMPOSSIBLE,
"Jump jets missing or destroyed");
}
}
// check if attacker has fired leg-mounted weapons
for (Mounted mounted : ae.getWeaponList()) {
if (mounted.isUsedThisRound()) {
int loc = mounted.getLocation();
if (((leg == BOTH || leg == LEFT) && loc == kickLegs[0])
|| ((leg == BOTH || leg == RIGHT) && loc == kickLegs[1])) {
return new ToHitData(TargetRoll.IMPOSSIBLE,
"Weapons fired from leg this turn");
}
}
}
// check range
final int range = ae.getPosition().distance(target.getPosition());
if (1 != range) {
return new ToHitData(TargetRoll.IMPOSSIBLE,
"Enemy must be at range 1");
}
// check elevation
if (!ae.isProne() && attackerHeight - targetHeight != 1) {
return new ToHitData(TargetRoll.IMPOSSIBLE,
"Target elevation not in range");
}
if (ae.isProne()
&& (attackerHeight > targetHeight || attackerHeight < targetElevation)) {
return new ToHitData(TargetRoll.IMPOSSIBLE,
"Target elevation not in range");
}
// check facing
if (!ae.isProne()) {
if (!target.getPosition().equals(
ae.getPosition().translated(ae.getFacing()))) {
return new ToHitData(TargetRoll.IMPOSSIBLE,
"Target not directly ahead of feet");
}
} else {
if (!target.getPosition().equals(
ae.getPosition().translated((3 + ae.getFacing()) % 6))) {
return new ToHitData(TargetRoll.IMPOSSIBLE,
"Target not directly behind of feet");
}
}
// Attacks against adjacent buildings automatically hit.
if (target.getTargetType() == Targetable.TYPE_BUILDING
|| target.getTargetType() == Targetable.TYPE_FUEL_TANK
|| target instanceof GunEmplacement) {
return new ToHitData(TargetRoll.AUTOMATIC_SUCCESS,
"Targeting adjacent building.");
}
// Set the base BTH
int base = ae.getCrew().getPiloting() + 2;
// Start the To-Hit
toHit = new ToHitData(base, "base");
setCommonModifiers(toHit, game, ae, target);
// +2 for prone
if (ae.isProne()) {
toHit.addModifier(2, "Attacker is prone");
}
// factor in target side
toHit.setSideTable(Compute.targetSideTable(ae, target));