return toHit; }
    public static ToHitData toHit(IGame game, int attackerId, Targetable target, int arm) {        final Entity ae = game.getEntity(attackerId);        int targetId = Entity.NONE;        Entity te = null;        if ( target.getTargetType() == Targetable.TYPE_ENTITY ) {            te = (Entity) target;            targetId = target.getTargetId();        }        final int armLoc = (arm == BrushOffAttackAction.RIGHT)                           ? Mech.LOC_RARM : Mech.LOC_LARM;        ToHitData toHit;        // non-mechs can't BrushOff        if (!(ae instanceof Mech)) {            return new ToHitData(ToHitData.IMPOSSIBLE,                                 "Only mechs can brush off swarming infantry or iNarc Pods");        }        // arguments legal?        if ( arm != BrushOffAttackAction.RIGHT &&             arm != BrushOffAttackAction.LEFT ) {            throw new IllegalArgumentException("Arm must be LEFT or RIGHT");        }        if (ae == null || target == null) {            throw new IllegalArgumentException("Attacker or target not valid");        }        if ( ( targetId != ae.getSwarmAttackerId() ||                te == null || !(te instanceof Infantry) ) &&                target.getTargetType() != Targetable.TYPE_INARC_POD ) {            return new ToHitData(ToHitData.IMPOSSIBLE,            "Can only brush off swarming infantry or iNarc Pods" );        }        // Quads can't brush off.        if ( ae.entityIsQuad() ) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Attacker is a quad");        }        // Can't brush off with flipped arms        if (ae.getArmsFlipped()) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Arms are flipped to the rear. Can not punch.");        }        // check if arm is present        if (ae.isLocationBad(armLoc)) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Arm missing");        }        // check if shoulder is functional        if (!ae.hasWorkingSystem(Mech.ACTUATOR_SHOULDER, armLoc)) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Shoulder destroyed");        }        // check if attacker has fired arm-mounted weapons        if (ae.weaponFiredFrom(armLoc)) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Weapons fired from arm this turn");        }        // can't physically attack mechs making dfa attacks        if ( te != null && te.isMakingDfa() ) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Target is making a DFA attack");        }        // Can't brush off while prone.        if (ae.isProne()) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Attacker is prone");        }        // Can't target woods or a building with a brush off attack.        if ( target.getTargetType() == Targetable.TYPE_BUILDING ||             target.getTargetType() == Targetable.TYPE_BLDG_IGNITE ||             target.getTargetType() == Targetable.TYPE_HEX_CLEAR ||             target.getTargetType() == Targetable.TYPE_HEX_IGNITE ) {            return new ToHitData( ToHitData.IMPOSSIBLE, "Invalid attack");        }        // okay, modifiers...        toHit = new ToHitData(ae.getCrew().getPiloting(), "base PSR");        toHit.addModifier( 4, "brush off swarming infantry" );        // damaged or missing actuators        if (!ae.hasWorkingSystem(Mech.ACTUATOR_UPPER_ARM, armLoc)) {            toHit.addModifier(2, "Upper arm actuator destroyed");        }        if (!ae.hasWorkingSystem(Mech.ACTUATOR_LOWER_ARM, armLoc)) {            toHit.addModifier(2, "Lower arm actuator missing or destroyed");        }        if (!ae.hasWorkingSystem(Mech.ACTUATOR_HAND, armLoc)) {            toHit.addModifier(1, "Hand actuator missing or destroyed");        }        // If it has a torso-mounted cockpit and two head sensor hits or three sensor hits...        // It gets a =4 penalty for being blind!        if (((Mech)ae).getCockpitType() == Mech.COCKPIT_TORSO_MOUNTED) {            int sensorHits = ae.getBadCriticals(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_SENSORS, Mech.LOC_HEAD);            int sensorHits2 = ae.getBadCriticals(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_SENSORS, Mech.LOC_CT);            if ((sensorHits + sensorHits2) == 3) {                toHit.addModifier(4, "Sensors Completely Destroyed for Torso-Mounted Cockpit");            } else if (sensorHits == 2) {                toHit.addModifier(4, "Head Sensors Destroyed for Torso-Mounted Cockpit");            }        }        Compute.modifyPhysicalBTHForAdvantages(ae, te, toHit, game);        // If the target has Assault claws, give a 1 modifier.        // We can stop looking when we find our first match.    if (te != null) {        for (Mounted mount : te.getMisc()) {            EquipmentType equip = mount.getType();            if ( BattleArmor.ASSAULT_CLAW.equals                    (equip.getInternalName()) ) {                toHit.addModifier( 1, "defender has assault claws" );                break;            }        }    }        // done!        return toHit;    }