public static ToHitData toHit(IGame game, int attackerId, Targetable target) { final Entity ae = game.getEntity(attackerId); int targetId = Entity.NONE; if ( target.getTargetType() != Targetable.TYPE_BUILDING ) { return new ToHitData(ToHitData.IMPOSSIBLE, "You can only target buildings"); } final Building b = game.getBoard().getBuildingAt(ae.getPosition()); if (ae == null) return new ToHitData(ToHitData.IMPOSSIBLE, "You can't attack from a null entity!");   if(!(ae instanceof Infantry)) return new ToHitData(ToHitData.IMPOSSIBLE, "Attacker is not infantry"); Infantry inf = (Infantry) ae; if(inf.turnsLayingExplosives > 0) return new ToHitData(ToHitData.AUTOMATIC_SUCCESS, "STOP: Expected Damage: "+getDamageFor(ae)); boolean ok = false; for(Enumeration<Mounted> e= ae.getMisc(); e.hasMoreElements();) { Mounted m = e.nextElement(); if(m.getType().hasFlag(MiscType.F_TOOLS) && m.getType().hasSubType(MiscType.S_DEMOLITION_CHARGE)) { ok = true; break; } } if(!ok) return new ToHitData(ToHitData.IMPOSSIBLE, "No explosives carried"); return new ToHitData(ToHitData.AUTOMATIC_SUCCESS, "START: Can't move or fire while laying explosives");
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);        int targetId = Entity.NONE;        if ( target.getTargetType() != Targetable.TYPE_BUILDING ) {            return new ToHitData(ToHitData.IMPOSSIBLE, "You can only target buildings");        }        final Building b = game.getBoard().getBuildingAt(ae.getPosition());        if (ae == null)            return new ToHitData(ToHitData.IMPOSSIBLE, "You can't attack from a null entity!");//        if(b == null || b.getId() != target.getTargetId())//            return new ToHitData(ToHitData.IMPOSSIBLE, "Target out of range");        if(!(ae instanceof Infantry))            return new ToHitData(ToHitData.IMPOSSIBLE, "Attacker is not infantry");        Infantry inf = (Infantry) ae;        if(inf.turnsLayingExplosives > 0)            return new ToHitData(ToHitData.AUTOMATIC_SUCCESS, "STOP: Expected Damage: "+getDamageFor(ae));        boolean ok = false;        for(Enumeration<Mounted> e= ae.getMisc(); e.hasMoreElements();) {            Mounted m = e.nextElement();            if(m.getType().hasFlag(MiscType.F_TOOLS) && m.getType().hasSubType(MiscType.S_DEMOLITION_CHARGE)) {                ok = true;                break;            }        }        if(!ok)            return new ToHitData(ToHitData.IMPOSSIBLE, "No explosives carried");        return new ToHitData(ToHitData.AUTOMATIC_SUCCESS, "START: Can't move or fire while laying explosives");    }