Mounted mount = (Mounted) ammo.nextElement();
    private static String getLocString( Entity entity ) {        boolean isMech = entity instanceof Mech;        boolean haveSlot = false;        StringBuffer output = new StringBuffer();        StringBuffer thisLoc = new StringBuffer();        boolean isDestroyed = false;        boolean blownOff = false;        // Walk through the locations for the entity,        // and only record damage and ammo.        for ( int loc = 0; loc < entity.locations(); loc++ ) {            // Record destroyed locations.            if ( entity.getOInternal(loc) != IArmorState.ARMOR_NA &&                 entity.getInternal(loc) <= 0 ) {                isDestroyed = true;            }            // Record damage to armor and internal structure.            // Destroyed locations have lost all their armor and IS.            if ( !isDestroyed ) {                if ( entity.getOArmor(loc) != entity.getArmor(loc) ) {                    thisLoc.append( "         <armor points=\"" );                    thisLoc.append( formatArmor(entity.getArmor(loc)) );                    thisLoc.append( "\"/>" );                    thisLoc.append( CommonConstants.NL );                }                if ( entity.getOInternal(loc) != entity.getInternal(loc) ) {                    thisLoc.append( "         <armor points=\"" );                    thisLoc.append( formatArmor(entity.getInternal(loc)) );                    thisLoc.append( "\" type=\"Internal\"/>" );                    thisLoc.append( CommonConstants.NL );                }                if ( entity.hasRearArmor(loc) && entity.getOArmor(loc, true) !=                     entity.getArmor(loc, true) ) {                    thisLoc.append( "         <armor points=\"" );                    thisLoc.append( formatArmor(entity.getArmor(loc, true)) );                    thisLoc.append( "\" type=\"Rear\"/>" );                    thisLoc.append( CommonConstants.NL );                }            }            // Walk through the slots in this location.            for ( int loop = 0; loop < entity.getNumberOfCriticals(loc);                  loop++ ) {                // Get this slot.                CriticalSlot slot = entity.getCritical( loc, loop );                // Did we get a slot?                if ( null == slot ) {                    // Nope.  Record missing actuators on Biped Mechs.                    if ( isMech && !entity.entityIsQuad() &&                         ( loc == Mech.LOC_RARM || loc == Mech.LOC_LARM ) &&                         ( loop == 2 || loop == 3 ) ) {                        thisLoc.append( "         <slot index=\"" );                        thisLoc.append( String.valueOf(loop+1) );                        thisLoc.append( "\" type=\"Empty\"/>" );                        thisLoc.append( CommonConstants.NL );                        haveSlot = true;                    }                } else {                    // Yup.  If the equipment isn't a system, get it.                    Mounted mount = null;                    if ( CriticalSlot.TYPE_EQUIPMENT == slot.getType() ) {                        mount = entity.getEquipment( slot.getIndex() );                    }                    // Destroyed locations on Mechs that contain slots                    // that are missing but not hit or destroyed must                    // have been blown off.                    if ( isDestroyed && isMech && slot.isMissing() &&                         !slot.isHit() && !slot.isDestroyed() ) {                        thisLoc.append( formatSlot( String.valueOf(loop+1),                                                    mount,                                                    slot.isHit(),                                                    slot.isDestroyed() ) );                        haveSlot = true;                        blownOff = true;                    }                    // Record damaged slots in undestroyed locations.                    else if ( !isDestroyed && slot.isDamaged() ) {                        thisLoc.append( formatSlot( String.valueOf(loop+1),                                                    mount,                                                    slot.isHit(),                                                    slot.isDestroyed() ) );                        haveSlot = true;                    }                    // Record ammunition slots in undestroyed locations.                    // N.B. the slot CAN\"T be damaged at this point.                    else if ( !isDestroyed && mount != null &&                              mount.getType() instanceof AmmoType ) {                        thisLoc.append( "         <slot index=\"" );                        thisLoc.append( String.valueOf(loop+1) );                        thisLoc.append( "\" type=\"" );                        thisLoc.append( mount.getType().getInternalName() );                        thisLoc.append( "\" shots=\"" );                        thisLoc.append( String.valueOf(mount.getShotsLeft()) );                        thisLoc.append( "\"/>" );                        thisLoc.append( CommonConstants.NL );                        haveSlot = true;                    }                    // Record the munition type of oneshot launchers                    else if ( !isDestroyed && mount != null &&                              mount.getType() instanceof WeaponType &&                              ((WeaponType)mount.getType()).hasFlag(WeaponType.F_ONESHOT)) {                        thisLoc.append( formatSlot( String.valueOf(loop+1),                                                    mount,                                                    slot.isHit(),                                                    slot.isDestroyed() ) );                        haveSlot = true;                    }                } // End have-slot            } // Check the next slot in this location            // Tanks don't have slots, and Protomechs only have            // system slots, so we have to handle the ammo specially.            if ( entity instanceof Tank ||                 entity instanceof Protomech ) {                Enumeration ammo = entity.getAmmo();                while ( ammo.hasMoreElements() ) {                    // Is this ammo in the current location?                    Mounted mount = (Mounted) ammo.nextElement();                    if ( mount.getLocation() == loc ) {                        thisLoc.append( formatSlot( "N/A",                                                    mount,                                                    false,                                                    false ) );                        haveSlot = true;                    }                } // Check the next ammo.                // TODO: handle slotless equipment.                // TODO: handle tank crits.            } // End is-tank-or-proto            // Did we record information for this location?            if ( thisLoc.length() > 0 ) {                // Add this location to the output string.                output.append( "      <location index=\"" );                output.append( String.valueOf(loc) );                if ( isDestroyed ) {                    output.append( "\" isDestroyed=\"true" );                }                output.append( "\"> " );                output.append( entity.getLocationName(loc) );                if ( blownOff ) {                    output.append( " has been blown off." );                }                output.append( CommonConstants.NL );                output.append( thisLoc.toString() );                output.append( "      </location>" );                output.append( CommonConstants.NL );                // Reset the location buffer.                thisLoc = new StringBuffer();                blownOff = false;            } // End output-location            // If the location is completely destroyed, log it anyway.            else if ( isDestroyed ) {                // Add this location to the output string.                output.append( "      <location index=\"" );                output.append( String.valueOf(loc) );                output.append( "\" isDestroyed=\"true\" /> " );                output.append( entity.getLocationName(loc) );                output.append( CommonConstants.NL );            } // End location-completely-destroyed            // Reset the "location is destroyed" flag.            isDestroyed = false;        } // Handle the next location        // If there is no location string, return a null.        if ( output.length() == 0 ) {            return null;        }        // If we recorded a slot, remind the player that slots start at 1.        if ( haveSlot ) {            output.insert( 0, CommonConstants.NL );            output.insert                ( 0, "      The first slot in a location is at index=\"1\"." );            // Tanks do wierd things with ammo.            if ( entity instanceof Tank ) {                output.insert( 0, CommonConstants.NL );                output.insert( 0, "      Tanks have special needs, so don't delete any ammo slots." );            }        }        // Convert the output into a String and return it.        return output.toString();    } // End private static String getLocString( Entity )