if (isWeaponInfantry && distance == 0) {    if (wtype.hasFlag(WeaponType.F_FLAMER)) { mods.addModifier(-1, "infantry flamer assault"); } else if (wtype.getAmmoType() == AmmoType.T_SRM ) { mods.addModifier(-1, "infantry SRM assault"); } else if (wtype.getAmmoType() != AmmoType.T_LRM) { mods.addModifier(-2, "infantry assault"); } }   int minRange = weaponRanges[RANGE_MINIMUM]; if (minRange > 0 && distance <= minRange) { int minPenalty = (minRange - distance) + 1;  if (isLRMInfantry) { mods.addModifier(minPenalty * 2, "infantry LRM minumum range"); } else { mods.addModifier(minPenalty, "minumum range"); } }   if ((target instanceof Entity) && ((Entity)target).isStealthActive()) { mods.append(((Entity)target).getStealthModifier(usingRange)); }  return mods; }
    private static ToHitData getRangeMods(Game game, Entity ae, int weaponId, Targetable target) {        Mounted weapon = ae.getEquipment(weaponId);        WeaponType wtype = (WeaponType)weapon.getType();        int[] weaponRanges = wtype.getRanges();        boolean isAttackerInfantry = (ae instanceof Infantry);        boolean isWeaponInfantry = wtype.hasFlag(WeaponType.F_INFANTRY);        boolean isLRMInfantry = isWeaponInfantry && wtype.getAmmoType() == AmmoType.T_LRM;        boolean isIndirect = !(wtype.hasFlag(WeaponType.F_ONESHOT)) && wtype.getAmmoType() == AmmoType.T_LRM //For now, oneshot LRM launchers won't be able to indirect.  Sue me, until I can figure out a better fix.            && weapon.curMode().equals("Indirect");        ToHitData mods = new ToHitData();        // modify the ranges for ATM missile systems based on the ammo selected        // TODO: this is not the right place to hardcode these        if (wtype.getAmmoType() == AmmoType.T_ATM) {            AmmoType atype = (AmmoType)weapon.getLinked().getType();            if (atype.getMunitionType() == AmmoType.M_EXTENDED_RANGE) {                weaponRanges = new int[] {4, 9, 18, 27};            }            else if (atype.getMunitionType() == AmmoType.M_HIGH_EXPLOSIVE) {                weaponRanges = new int[] {0, 3, 6, 9};            }        }        //is water involved?        Hex attHex = game.board.getHex(ae.getPosition());        Hex targHex = game.board.getHex(target.getPosition());        int targEl;        if (target == null) {            targEl = game.board.getHex(target.getPosition()).floor();        } else {            targEl = target.absHeight();        }        if (ae.getLocationStatus(weapon.getLocation()) == Entity.LOC_WET) {            weaponRanges = wtype.getWRanges();            //HACK on ranges: for those without underwater range,            // long == medium; iteration in rangeBracket() allows this            if (weaponRanges[RANGE_SHORT] == 0) {                return new ToHitData(ToHitData.IMPOSSIBLE,                                     "Weapon cannot fire underwater.");            }            if (!(targHex.contains(Terrain.WATER)) ||                targHex.surface() <= target.getElevation()) {                //target on land or over water                return new ToHitData(ToHitData.IMPOSSIBLE,                                     "Weapon underwater, but not target.");            }        } else if (targHex.contains(Terrain.WATER) &&                   targHex.surface() > targEl) {            //target completely underwater, weapon not            return new ToHitData(ToHitData.IMPOSSIBLE,                                 "Target underwater, but not weapon.");        }        // determine base distance & range bracket        int distance = effectiveDistance(game, ae, target);        int range = rangeBracket(distance, weaponRanges);        // short circuit if at zero range or out of range        if (range == RANGE_OUT_OF) {            return new ToHitData(ToHitData.AUTOMATIC_FAIL, "Target out of range");        }        if (distance == 0 && !isAttackerInfantry) {            return new ToHitData(ToHitData.AUTOMATIC_FAIL, "Only infantry shoot at zero range");        }        // find any c3 spotters that could help        Entity c3spotter = findC3Spotter(game, ae, target);        if (isIndirect) {            c3spotter = ae; // no c3 when using indirect fire        }        int c3dist = effectiveDistance(game, c3spotter, target);        int c3range = rangeBracket(c3dist, weaponRanges);        // determine which range we're using        int usingRange = Math.min(range, c3range);        // add range modifier        if (usingRange == range) {            // no c3 adjustment            if (range == RANGE_MEDIUM) {                mods.addModifier(2, "medium range");            }            else if (range == RANGE_LONG) {                // Protos that loose head sensors can't shoot long range.                if( (ae instanceof Protomech) &&                    (2 == ((Protomech)ae).getCritsHit(Protomech.LOC_HEAD)) ) {                    mods.addModifier                        ( ToHitData.IMPOSSIBLE,                          "No long range attacks with destroyed head sensors." );                } else {                    mods.addModifier(4, "long range");                }            }        }        else {            // report c3 adjustment            if (c3range == RANGE_SHORT) {                mods.addModifier(0, "short range due to C3 spotter");            }            else if (c3range == RANGE_MEDIUM) {                mods.addModifier(2, "medium range due to C3 spotter");            }        }    // add infantry LRM maximum range penalty    if (isLRMInfantry && distance == weaponRanges[RANGE_LONG]) {      mods.addModifier(1, "infantry LRM maximum range");    }    // add infantry zero-range modifier    // TODO: this is not the right place to hardcode these    if (isWeaponInfantry && distance == 0) {      // Infantry platoons attacking with infantry weapons can attack      // in the same hex with a base of 2, except for flamers and      // SRMs, which have a base of 3 and LRMs, which suffer badly.      if (wtype.hasFlag(WeaponType.F_FLAMER)) {        mods.addModifier(-1, "infantry flamer assault");      } else if (wtype.getAmmoType() == AmmoType.T_SRM ) {        mods.addModifier(-1, "infantry SRM assault");      } else if (wtype.getAmmoType() != AmmoType.T_LRM) {        mods.addModifier(-2, "infantry assault");      }    }    // add minumum range modifier    int minRange = weaponRanges[RANGE_MINIMUM];    if (minRange > 0 && distance <= minRange) {      int minPenalty = (minRange - distance) + 1;      // Infantry LRMs suffer double minimum range penalties.      if (isLRMInfantry) {        mods.addModifier(minPenalty * 2, "infantry LRM minumum range");      } else {        mods.addModifier(minPenalty, "minumum range");      }    }    // add any target stealth modifier    if ((target instanceof Entity) && ((Entity)target).isStealthActive()) {      mods.append(((Entity)target).getStealthModifier(usingRange));    }    return mods;  }