boolean curInFrontArc = isInArc(attacker.getPosition(), attacker.getSecondaryFacing(), target.getPosition(), ARC_FORWARD);  int primaryTarget = Entity.NONE; for (Enumeration i = game.getActions(); i.hasMoreElements();) { Object o = i.nextElement(); if (!(o instanceof WeaponAttackAction)) { continue; } WeaponAttackAction prevAttack = (WeaponAttackAction)o; if (prevAttack.getEntityId() == attacker.getId()) {    Targetable pte = game.getTarget(prevAttack.getTargetType(), prevAttack.getTargetId());    if ( pte == null ) { continue; }  if (pte instanceof Entity && ((Entity)pte).isStealthActive() && pte != target ) { return new ToHitData(ToHitData.IMPOSSIBLE, "When targeting a stealthed Mech, can not attack secondary targets"); } if (isInArc(attacker.getPosition(), attacker.getSecondaryFacing(), pte.getPosition(), ARC_FORWARD)) { primaryTarget = prevAttack.getTargetId(); break; } else if (primaryTarget == Entity.NONE && !curInFrontArc) { primaryTarget = prevAttack.getTargetId(); } } }  if (primaryTarget == Entity.NONE || primaryTarget == target.getTargetId()) {  return null; }     if (attacker instanceof Infantry) { return new ToHitData(ToHitData.IMPOSSIBLE, "Can't have multiple targets."); }   if ((target instanceof Entity) && ((Entity)target).isStealthActive() ) { return new ToHitData(ToHitData.IMPOSSIBLE, "Can't target Mech with active stealth armor as secondary target"); }  if (curInFrontArc) { return new ToHitData(1, "secondary target modifier"); } else { return new ToHitData(2, "secondary target modifier"); }
return getSecondaryTargetMod(game, attacker, target, false);
    public static ToHitData getSecondaryTargetMod(IGame game, Entity attacker, Targetable target) {    boolean curInFrontArc = isInArc(attacker.getPosition(), attacker.getSecondaryFacing(), target.getPosition(), ARC_FORWARD);    int primaryTarget = Entity.NONE;        for (Enumeration i = game.getActions(); i.hasMoreElements();) {            Object o = i.nextElement();            if (!(o instanceof WeaponAttackAction)) {                continue;            }            WeaponAttackAction prevAttack = (WeaponAttackAction)o;            if (prevAttack.getEntityId() == attacker.getId()) {                // first front arc target is our primary.                // if first target is non-front, and either a later target or                // the current one is in front, use that instead.                Targetable pte = game.getTarget(prevAttack.getTargetType(), prevAttack.getTargetId());                // in double blind play, we might not have the target in our                 // local copy of the game. In that case, the sprite won't                // have the correct to-hit number, but at least we don't crash                if ( pte == null ) {                    continue;                }                // When targeting a stealthed Mech, you can _only_ target it, not anything else (BMRr, pg. 147)                if (pte instanceof Entity && ((Entity)pte).isStealthActive() && pte != target ) {                    return new ToHitData(ToHitData.IMPOSSIBLE, "When targeting a stealthed Mech, can not attack secondary targets");                }                if (isInArc(attacker.getPosition(), attacker.getSecondaryFacing(), pte.getPosition(), ARC_FORWARD)) {                    primaryTarget = prevAttack.getTargetId();                    break;                } else if (primaryTarget == Entity.NONE && !curInFrontArc) {                    primaryTarget = prevAttack.getTargetId();                }            }        }        if (primaryTarget == Entity.NONE || primaryTarget == target.getTargetId()) {          // current target is primary target          return null; // no modifier        }        // current target is secondary        // Infantry can't attack secondary targets (BMRr, pg. 32).        if (attacker instanceof Infantry) {          return new ToHitData(ToHitData.IMPOSSIBLE, "Can't have multiple targets.");        }                // Stealthed Mechs can't be secondary targets (BMRr, pg. 147)        if ((target instanceof Entity) && ((Entity)target).isStealthActive() ) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Can't target Mech with active stealth armor as secondary target");        }                if (curInFrontArc) {      return new ToHitData(1, "secondary target modifier");        } else {      return new ToHitData(2, "secondary target modifier");        }    }