}  if (target.getElevation() != ae.getElevation()) { return new ToHitData(ToHitData.IMPOSSIBLE, "Target not at same elevation");
    public ToHitData toHit(IGame game) {        final Entity ae = getEntity( game );        Entity te = null;        final Targetable target = getTarget( game );        if (target.getTargetType() == Targetable.TYPE_ENTITY) {            te = (Entity) target;        }        // arguments legal?        if (ae == null || target == null) {            throw new IllegalArgumentException("Attacker or target not valid");        }        // Non-mechs can't thrash.        if ( !(ae instanceof Mech) ) {            return new ToHitData( ToHitData.IMPOSSIBLE,                                  "Only mechs can thrash at infantry" );        }        // Mech must be prone.        if (!ae.isProne()) {            return new ToHitData( ToHitData.IMPOSSIBLE,                                  "Only prone mechs can thrash at infantry" );        }        // Can't thrash against non-infantry        if (te == null || !(te instanceof Infantry)) {            return new ToHitData( ToHitData.IMPOSSIBLE,                                  "Can only thrash at infantry" );        }        // Can't thrash against swarming infantry.        else if (te != null && Entity.NONE != te.getSwarmTargetId()) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Can't thrash at swarming infantry");        }        // Check range.        if (target.getPosition() == null || ae.getPosition().distance(target.getPosition()) > 0) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Target not in same hex");        }        // Check terrain.        IHex hex = game.getBoard().getHex(ae.getPosition());        if (hex.containsTerrain(Terrains.WOODS)                || hex.containsTerrain(Terrains.JUNGLE)                || hex.containsTerrain(Terrains.ROUGH)                || hex.containsTerrain(Terrains.RUBBLE)                || hex.containsTerrain(Terrains.FUEL_TANK)                || hex.containsTerrain(Terrains.BUILDING)) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Not a clear or pavement hex.");        }        // Can't target woods or a building with a thrash attack.        if (target.getTargetType() == Targetable.TYPE_BUILDING            || target.getTargetType() == Targetable.TYPE_BLDG_IGNITE            || target.getTargetType() == Targetable.TYPE_FUEL_TANK            || target.getTargetType() == Targetable.TYPE_FUEL_TANK_IGNITE            || target.getTargetType() == Targetable.TYPE_HEX_CLEAR            || target.getTargetType() == Targetable.TYPE_HEX_IGNITE) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Invalid attack");        }        // The Mech can't have fired a weapon this round.        for (int loop = 0; loop < ae.locations(); loop++) {            if (ae.weaponFiredFrom(loop)) {                return new ToHitData(                                     ToHitData.IMPOSSIBLE,                                     "Weapons fired from " + ae.getLocationName(loop) + " this turn");            }        }        // Mech must have at least one working arm or leg.        if (ae.isLocationBad(Mech.LOC_RARM)            && ae.isLocationBad(Mech.LOC_LARM)            && ae.isLocationBad(Mech.LOC_RLEG)            && ae.isLocationBad(Mech.LOC_LLEG)) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Mech has no arms or legs to thrash");        }        // If the attack isn't impossible, it's automatically successful.        return new ToHitData(ToHitData.AUTOMATIC_SUCCESS, "thrash attacks always hit");    }