public static ToHitData toHit(IGame game, int attackerId, Targetable target) { final Entity ae = game.getEntity(attackerId); if (ae == null) return new ToHitData(ToHitData.IMPOSSIBLE, "You can't attack from a null entity!");  if(!game.getOptions().booleanOption("maxtech_new_physicals")) return new ToHitData(ToHitData.IMPOSSIBLE, "no maxtech physicals");  String impossible = toHitIsImpossible(game, ae, target); if(impossible != null && !impossible.equals("Locked in Grapple")) { return new ToHitData(ToHitData.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 targetElevation = target.getElevation() + targHex.getElevation();  final boolean counter = ((Mech)ae).getGrappled() != Entity.NONE && !((Mech)ae).isGrappleAttacker();  ToHitData toHit;   if (!(ae instanceof BipedMech) || !(target instanceof Mech)) { return new ToHitData(ToHitData.IMPOSSIBLE, "Only biped mechs can trip other mechs"); }   if (ae.isLocationBad(Mech.LOC_LARM) || ae.isLocationBad(Mech.LOC_RARM)) { return new ToHitData(ToHitData.IMPOSSIBLE, "Arm missing"); }  if(!ae.hasWorkingSystem(Mech.ACTUATOR_SHOULDER, Mech.LOC_RARM) || !ae.hasWorkingSystem(Mech.ACTUATOR_SHOULDER, Mech.LOC_LARM)) { return new ToHitData(ToHitData.IMPOSSIBLE, "Shoulder missing/destroyed"); }   final int range = ae.getPosition().distance(target.getPosition()); if(range != 1 && !counter) { return new ToHitData(ToHitData.IMPOSSIBLE, "Target not in range"); }   if (Math.abs(attackerElevation - targetElevation) > ae.getMaxElevationChange()) { return new ToHitData(ToHitData.IMPOSSIBLE, "Target elevation not in range"); }   if (!counter && !Compute.isInArc(ae.getPosition(), ae.getFacing(), target.getPosition(), Compute.ARC_FORWARD)) { return new ToHitData(ToHitData.IMPOSSIBLE, "Target not in arc"); }   if (ae.isProne()) { return new ToHitData(ToHitData.IMPOSSIBLE, "Attacker is prone"); } if(((Entity)target).isProne()) { return new ToHitData(ToHitData.IMPOSSIBLE, "Target is prone"); }   if(!counter) { for (Mounted mounted : ae.getWeaponList()) { if (mounted.isUsedThisRound()) { return new ToHitData(ToHitData.IMPOSSIBLE, "Fired weapons"); } } }   int atGr = ((Mech)ae).getGrappled(); int deGr = ((Mech)target).getGrappled(); if((atGr != Entity.NONE || deGr != Entity.NONE) && atGr != target.getTargetId() && ((Mech)target).isGrappleAttacker()) { return new ToHitData(ToHitData.IMPOSSIBLE, "Already grappled"); }   int base = 5;   if ( game.getOptions().booleanOption("maxtech_physical_BTH") ) { base = ae.getCrew().getPiloting(); }   toHit = new ToHitData(base, "base");  setCommonModifiers(toHit, game, ae, target);   if (!ae.hasWorkingSystem(Mech.ACTUATOR_UPPER_ARM, Mech.LOC_LARM)) { toHit.addModifier(2, "Left upper arm actuator destroyed"); } if (!ae.hasWorkingSystem(Mech.ACTUATOR_LOWER_ARM, Mech.LOC_LARM)) { toHit.addModifier(2, "Left lower arm actuator destroyed"); } if (!ae.hasWorkingSystem(Mech.ACTUATOR_HAND, Mech.LOC_LARM)) { toHit.addModifier(1, "Left hand actuator destroyed"); }  if (!ae.hasWorkingSystem(Mech.ACTUATOR_UPPER_ARM, Mech.LOC_RARM)) { toHit.addModifier(2, "Right upper arm actuator destroyed"); } if (!ae.hasWorkingSystem(Mech.ACTUATOR_LOWER_ARM, Mech.LOC_RARM)) { toHit.addModifier(2, "Right lower arm actuator destroyed"); } if (!ae.hasWorkingSystem(Mech.ACTUATOR_HAND, Mech.LOC_RARM)) { toHit.addModifier(1, "Right hand actuator destroyed"); }   int wmod = ((Entity)target).getWeightClass() - ae.getWeightClass(); if(wmod != 0) { toHit.addModifier(wmod, "Weight class difference"); }  return toHit;
public ToHitData toHit(IGame game) { return toHit(game, getEntityId(), game.getTarget(getTargetType(), getTargetId()));
    public static ToHitData toHit(IGame game, int attackerId,                                      Targetable target) {        final Entity ae = game.getEntity(attackerId);        if (ae == null)            return new ToHitData(ToHitData.IMPOSSIBLE, "You can't attack from a null entity!");        if(!game.getOptions().booleanOption("maxtech_new_physicals"))            return new ToHitData(ToHitData.IMPOSSIBLE, "no maxtech physicals");                String impossible = toHitIsImpossible(game, ae, target);        if(impossible != null                && !impossible.equals("Locked in Grapple")) {            return new ToHitData(ToHitData.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();        final boolean counter = ((Mech)ae).getGrappled() != Entity.NONE                                && !((Mech)ae).isGrappleAttacker();        ToHitData toHit;        // non-mechs can't grapple or be grappled        if (!(ae instanceof BipedMech) || !(target instanceof Mech)) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Only biped mechs can trip other mechs");        }        // requires 2 good arms        if (ae.isLocationBad(Mech.LOC_LARM)            || ae.isLocationBad(Mech.LOC_RARM)) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Arm missing");        }        if(!ae.hasWorkingSystem(Mech.ACTUATOR_SHOULDER, Mech.LOC_RARM)                || !ae.hasWorkingSystem(Mech.ACTUATOR_SHOULDER, Mech.LOC_LARM)) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Shoulder missing/destroyed");        }        // check range        final int range = ae.getPosition().distance(target.getPosition());        if(range != 1 && !counter) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Target not in range");        }         // check elevation (attacker must be able to enter target hex)        if (Math.abs(attackerElevation - targetElevation) > ae.getMaxElevationChange()) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Target elevation not in range");        }         // check facing        if (!counter && !Compute.isInArc(ae.getPosition(), ae.getFacing(),                     target.getPosition(), Compute.ARC_FORWARD)) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Target not in arc");        }        // can't grapple while prone        if (ae.isProne()) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Attacker is prone");        }        if(((Entity)target).isProne()) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Target is prone");        }                // check if attacker has fired any weapons        if(!counter) {            for (Mounted mounted : ae.getWeaponList()) {                if (mounted.isUsedThisRound()) {                    return new ToHitData(ToHitData.IMPOSSIBLE, "Fired weapons");                }            }        }                //already done?        int atGr = ((Mech)ae).getGrappled();        int deGr = ((Mech)target).getGrappled();        if((atGr != Entity.NONE                || deGr != Entity.NONE)                && atGr != target.getTargetId()                && ((Mech)target).isGrappleAttacker()) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Already grappled");        }        //Set the base BTH        int base = 5;        // Level 3 rule: the BTH is PSR         if ( game.getOptions().booleanOption("maxtech_physical_BTH") ) {            base = ae.getCrew().getPiloting();        }        // Start the To-Hit        toHit = new ToHitData(base, "base");                setCommonModifiers(toHit, game, ae, target);                // damaged or missing actuators        if (!ae.hasWorkingSystem(Mech.ACTUATOR_UPPER_ARM, Mech.LOC_LARM)) {            toHit.addModifier(2, "Left upper arm actuator destroyed");        }        if (!ae.hasWorkingSystem(Mech.ACTUATOR_LOWER_ARM, Mech.LOC_LARM)) {            toHit.addModifier(2, "Left lower arm actuator destroyed");        }        if (!ae.hasWorkingSystem(Mech.ACTUATOR_HAND, Mech.LOC_LARM)) {            toHit.addModifier(1, "Left hand actuator destroyed");        }                if (!ae.hasWorkingSystem(Mech.ACTUATOR_UPPER_ARM, Mech.LOC_RARM)) {            toHit.addModifier(2, "Right upper arm actuator destroyed");        }        if (!ae.hasWorkingSystem(Mech.ACTUATOR_LOWER_ARM, Mech.LOC_RARM)) {            toHit.addModifier(2, "Right lower arm actuator destroyed");        }        if (!ae.hasWorkingSystem(Mech.ACTUATOR_HAND, Mech.LOC_RARM)) {            toHit.addModifier(1, "Right hand actuator destroyed");        }                //Weight class difference        int wmod = ((Entity)target).getWeightClass() - ae.getWeightClass();        if(wmod != 0) {            toHit.addModifier(wmod, "Weight class difference");        }        // done!        return toHit;    }