if (Mech.isRearLocation(loc)) { loc = Mech.getFrontLocation(loc);
if (en.isRearLocation(loc)) { loc = en.getFrontLocation(loc);
    private String criticalEntity(Entity en, int loc) {        if (Mech.isRearLocation(loc)) {            loc = Mech.getFrontLocation(loc);        }        String desc = "        Critical hit on " + en.getLocationAbbr(loc) + ". ";        int hits = 0;        int roll = Compute.d6(2);        desc += "Roll = " + roll + ";";        if (roll <= 7) {                desc += " no effect.";                return desc;        } else if (roll >= 8 && roll <= 9) {                hits = 1;                desc += " 1 location.";        } else if (roll >= 10 && roll <= 11) {                hits = 2;                desc += " 2 locations.";        } else if (roll == 12) {            if (loc == Mech.LOC_HEAD ||                    loc == Mech.LOC_RARM || loc == Mech.LOC_LARM ||                    loc == Mech.LOC_RLEG || loc == Mech.LOC_LLEG) {                desc += "<<<LIMB BLOWN OFF>>> " + en.getLocationName(loc) + " blown off.";                destroyLocation(en, loc);                if (loc == Mech.LOC_HEAD) {                    en.crew.setDead(true);                    desc += "\n*** " + en.getDisplayName() + " PILOT KILLED! ***";                }                return desc;            }            hits = 3;            desc += " 3 locations.";        }        // transfer criticals, if needed        if (hits > 0 && en.getHitableCriticals(loc) <= 0                && en.getTransferLocation(loc) != Entity.LOC_DESTROYED) {            loc = en.getTransferLocation(loc);            desc += "\n            Location is empty, so criticals transfer to " + en.getLocationAbbr(loc) +".";        }        // roll criticals        while (hits > 0) {            if (en.getHitableCriticals(loc) <= 0) {                desc += "\n            Location empty.";                break;            }            int slot = (int)(Compute.random.nextDouble() * en.getNumberOfCriticals(loc));            CriticalSlot cs = en.getCritical(loc, slot);            if (cs != null && !cs.isHit()) {                cs.setDoomed(true);                en.setCritical(loc, slot, cs);                switch(cs.getType()) {                case CriticalSlot.TYPE_SYSTEM :                    desc += "\n            <<<CRITICAL HIT>>> on " + Mech.systemNames[cs.getIndex()] + ".";                    switch(cs.getIndex()) {                    case Mech.SYSTEM_COCKPIT :                        // boink!                        en.crew.setDead(true);                        desc += "\n*** " + en.getDisplayName() + " PILOT KILLED! ***";                        break;                    case Mech.SYSTEM_ENGINE :                        if (en.getHitCriticals(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_ENGINE, loc) > 2) {                            // third engine hit                            en.setDoomed(true);                            desc += "\n*** " + en.getDisplayName() + "ENGINE DESTROYED! ***";                        }                        break;                    case Mech.SYSTEM_GYRO :                        if (en.getHitCriticals(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_GYRO, loc) > 1) {                            // gyro destroyed                            pilotRolls.addElement(new PilotingRollData(en.getId(), PilotingRollData.AUTOMATIC_FALL, "gyro destroyed"));                        } else {                            // first gyro hit                            pilotRolls.addElement(new PilotingRollData(en.getId(), 3, "gyro hit"));                        }                        break;                    case Mech.ACTUATOR_LOWER_LEG :                    case Mech.ACTUATOR_FOOT :                        // leg/foot actuator piloting roll                        pilotRolls.addElement(new PilotingRollData(en.getId(), 1, "leg/foot actuator hit"));                        break;                    case Mech.ACTUATOR_HIP :                        // hip piloting roll                        pilotRolls.addElement(new PilotingRollData(en.getId(), 2, "hip actuator hit"));                        break;                    }                    break;                case CriticalSlot.TYPE_WEAPON :                    desc += "\n            <<<CRITICAL HIT>>> on " + en.getWeapon(cs.getIndex()).getType().getName() + ".";                    en.getWeapon(cs.getIndex()).setDestroyed(true);                    break;                case CriticalSlot.TYPE_AMMO :                    desc += "\n            <<<CRITICAL HIT>>> on " + en.getAmmo(cs.getIndex()).getName() + ".";                    en.getWeapon(cs.getIndex()).setDestroyed(true);                    desc += explodeAmmo(en, loc, slot);                    break;                }                hits--;                //System.err.println("s: critical loop, " + hits + " remaining");            }        }        return desc;    }