mounted.setShotsLeft ( mounted.getShotsLeft() );
mounted.setShotsLeft( shotsVal );
    public void recordElementStart( String name,                                    Hashtable attr )        throws ParseException {        // TODO: handle template files.        // What kind of element have we started?        if ( name.equals( UNIT ) ) {            // Are we in the middle of parsing an Entity?            if ( this.entity != null ) {                 this.warning.append                    ( "Found a unit while parsing an Entity.\n" );            }            // Are there *multiple* units?            else if ( !this.entities.isEmpty() ) {                this.warning.append                    ( "Found a second unit.  Clearing first unit.\n" );                // Restart the unit list.                this.entities.removeAllElements();            }        }        else if ( name.equals( TEMPLATE ) ) {            // Do nothing.        }        else if ( name.equals( ENTITY ) ) {            // Are we in the middle of parsing an Entity?            if ( this.entity != null ) {                this.warning.append                    ( "Found another Entity while parsing an Entity.\n" );            }            // Are we in the middle of parsing an Entity's location?            else if ( this.loc != Entity.LOC_NONE ) {                this.warning.append                    ( "Found another Entity while parsing a location.\n" );            }            // Start a new entity.            else {                // Look for the element's attributes.                String chassis = (String) attr.get( CHASSIS );                String model = (String) attr.get( MODEL );                // Did we find required attributes?                if ( chassis == null || chassis.length() == 0 ) {                    this.warning.append                        ( "Could not find chassis for Entity.\n" );                }                else {                    // Try to find the entity.                    MechSummary ms = null;                    StringBuffer key = new StringBuffer( chassis );                    ms = MechSummaryCache.getInstance()                        .getMech( key.toString() );                    if ( model != null && model.length() > 0 ) {                        key.append( " " ).append( model );                        ms = MechSummaryCache.getInstance()                            .getMech( key.toString() );                        // That didn't work.  Try swaping model and chassis.                        if ( ms == null ) {                            key = new StringBuffer( model );                            key.append( " " ).append( chassis );                            ms = MechSummaryCache.getInstance()                                .getMech( key.toString() );                        }                    }                    // We should have found the mech.                    if ( ms == null ) {                        this.warning.append                            ( "Could not find Entity with chassis: " );                        this.warning.append( chassis );                        if ( model != null && model.length() > 0 ) {                            this.warning.append( ", and model: " );                            this.warning.append( model );                        }                        this.warning.append( ".\n" );                    }                    else {                        // Try to load the new mech.                        try {                            this.entity = new MechFileParser                                ( ms.getSourceFile(), ms.getEntryName() )                                .getEntity();                        } catch (EntityLoadingException excep) {                            excep.printStackTrace( System.err );                            this.warning.append( "Unable to load mech: " )                                .append( ms.getSourceFile() )                                .append( ": " )                                .append( ms.getEntryName() )                                .append( ": " )                                .append( excep.getMessage());                        }                    } // End found-MechSummary                } // End have-chassis            } // End ready-for-new-Entity        }        else if ( name.equals( FLUFF ) ) {            // Do nothing.        }        else if ( name.equals( PILOT ) ) {            // Are we in the outside of an Entity?            if ( this.entity == null ) {                this.warning.append                    ( "Found a pilot outside of an Entity.\n" );            }            // Are we in the middle of parsing an Entity's location?            else if ( this.loc != Entity.LOC_NONE ) {                this.warning.append                    ( "Found a pilot while parsing a location.\n" );            }            // Handle the pilot.            else {                // Look for the element's attributes.                String pilotName = (String) attr.get( NAME );                String gunnery = (String) attr.get( GUNNERY );                String piloting = (String) attr.get( PILOTING );                String hits = (String) attr.get( HITS );                // Did we find required attributes?                if ( gunnery == null || gunnery.length() == 0 ) {                    this.warning.append                        ( "Could not find gunnery for pilot.\n" );                }                else if ( piloting == null || piloting.length() == 0 ) {                    this.warning.append                        ( "Could not find piloting for pilot.\n" );                }                else {                    // Try to get a good gunnery value.                    int gunVal = -1;                    try {                        gunVal = Integer.parseInt( gunnery );                    } catch ( NumberFormatException excep ) {                        // Handled by the next if test.                    }                    if ( gunVal < 0 || gunVal > 7 ) {                        this.warning.append( "Found invalid gunnery value: " )                            .append( gunnery )                            .append( ".\n" );                        return;                    }                    // Try to get a good piloting value.                    int pilotVal = -1;                    try {                        pilotVal = Integer.parseInt( piloting );                    } catch ( NumberFormatException excep ) {                        // Handled by the next if test.                    }                    if ( pilotVal < 0 || pilotVal > 7 ) {                        this.warning.append( "Found invalid piloting value: " )                            .append( piloting )                            .append( ".\n" );                        return;                    }                    // Update the entity's crew.                    Pilot crew = entity.getCrew();                    if ( null == pilotName || pilotName.length() == 0 ) {                        pilotName = crew.getName();                    }                    crew = new Pilot( pilotName, gunVal, pilotVal );                    // Was the crew wounded?                    if ( hits != null ) {                        // Try to get a good hits value.                        int hitVal = -1;                        try {                            hitVal = Integer.parseInt( hits );                        } catch ( NumberFormatException excep ) {                            // Handled by the next if test.                        }                        if ( hits.equals( DEAD ) ) {                            crew.setDead( true );                            this.warning.append( "The pilot, " )                                .append( pilotName )                                .append( ", is dead.\n" );                        }                        else if ( hitVal < 0 || hitVal > 5 ) {                            this.warning.append( "Found invalid hits value: " )                                .append( hits )                                .append( ".\n" );                        }                        else {                            crew.setHits( hitVal );                        }                    } // End have-hits                    // Set the crew for this entity.                    this.entity.setCrew( crew );                } // End have-required-fields            } // End ready-for-pilot        }        else if ( name.equals( LOCATION ) ) {            // Are we in the outside of an Entity?            if ( this.entity == null ) {                this.warning.append                    ( "Found a location outside of an Entity.\n" );            }            // Are we in the middle of parsing an Entity's location?            else if ( this.loc != Entity.LOC_NONE ) {                this.warning.append                    ( "Found a location while parsing a location.\n" );            }            // Handle the location.            else {                // Look for the element's attributes.                String index = (String) attr.get( INDEX );                String destroyed = (String) attr.get( IS_DESTROYED );                // Did we find required attributes?                if ( index == null || index.length() == 0 ) {                    this.warning.append                        ( "Could not find index for location.\n" );                }                else {                    // Try to get a good index value.                    int indexVal = -1;                    try {                        indexVal = Integer.parseInt( index );                    } catch ( NumberFormatException excep ) {                        // Handled by the next if test.                    }                    if ( indexVal < 0 || indexVal > 7 ) {                        this.warning.append( "Found invalid index value for location: " )                            .append( index )                            .append( ".\n" );                        return;                    }                    else if ( indexVal >= entity.locations() ) {                        this.warning.append( "The entity, " )                            .append( entity.getShortName() )                            .append( " does not have a location at index: " )                            .append( indexVal )                            .append( ".\n" );                        return;                    }                    else {                        // We're now parsing the indexed location.                        this.loc = indexVal;                        // Is the location destroyed?                        this.locDestroyed = false;                        try {                            if ( destroyed != null ) {                                this.locDestroyed = destroyed.equals( "true" );                            }                        } catch ( Throwable excep ) {                            this.warning.append( "Found invalid isDestroyed value: " )                                .append( destroyed )                                .append( ".\n" );                        }                    } // End have-valid-index                } // End have-required-fields            } // End ready-for-location        }        else if ( name.equals( ARMOR ) ) {            // Are we in the outside of an Entity?            if ( this.entity == null ) {                this.warning.append                    ( "Found armor outside of an Entity.\n" );            }            // Are we in the outside of parsing an Entity's location?            else if ( this.loc == Entity.LOC_NONE ) {                this.warning.append                    ( "Found armor while outside of a location.\n" );            }            // Handle the location.            else {                // Look for the element's attributes.                String points = (String) attr.get( POINTS );                String type = (String) attr.get( TYPE );                // Did we find required attributes?                if ( points == null || points.length() == 0 ) {                    this.warning.append                        ( "Could not find points for armor.\n" );                }                else {                    // Try to get a good points value.                    int pointsVal = -1;                    try {                        pointsVal = Integer.parseInt( points );                    } catch ( NumberFormatException excep ) {                        // Handled by the next if test.                    }                    if ( points.equals( NA ) ) {                        pointsVal = Entity.ARMOR_NA;                    }                    else if ( points.equals( DESTROYED ) ) {                        pointsVal = Entity.ARMOR_DESTROYED;                    }                    else if ( pointsVal < 0 || pointsVal > 100 ) {                        this.warning.append( "Found invalid points value: " )                            .append( points )                            .append( ".\n" );                        return;                    }                    // Assign the points to the correct location.                    // Sanity check the armor value before setting it.                    if ( type == null || type.equals( FRONT ) ) {                        if ( this.entity.getOArmor(this.loc) < pointsVal ) {                            this.warning.append( "The entity, " )                                .append( this.entity.getShortName() )                                .append( " does not start with " )                                .append( pointsVal )                                .append( " points of armor for location: " )                                .append( this.loc )                                .append( ".\n" );                        } else {                            this.entity.setArmor( pointsVal, this.loc );                        }                    }                    else if ( type.equals( INTERNAL ) ) {                        if ( this.entity.getOInternal(this.loc) < pointsVal ) {                            this.warning.append( "The entity, " )                                .append( this.entity.getShortName() )                                .append( " does not start with " )                                .append( pointsVal )                                .append( " points of internal structure for location: " )                                .append( this.loc )                                .append( ".\n" );                        } else {                            this.entity.setInternal( pointsVal, this.loc );                        }                    }                    else if ( type.equals( REAR ) ) {                        if ( !this.entity.hasRearArmor( this.loc ) ) {                            this.warning.append( "The entity, " )                                .append( this.entity.getShortName() )                                .append( " has no rear armor for location: " )                                .append( this.loc )                                .append( ".\n" );                        } else if ( this.entity.getOArmor(this.loc, true) <                                    pointsVal ) {                            this.warning.append( "The entity, " )                                .append( this.entity.getShortName() )                                .append( " does not start with " )                                .append( pointsVal )                                .append( " points of rear armor for location: " )                                .append( this.loc )                                .append( ".\n" );                        } else {                            this.entity.setArmor( pointsVal, this.loc, true );                        }                    }                } // End have-required-fields            } // End ready-for-armor        }        else if ( name.equals( SLOT ) ) {            // Are we in the outside of an Entity?            if ( this.entity == null ) {                this.warning.append                    ( "Found a slot outside of an Entity.\n" );            }            // Are we in the outside of parsing an Entity's location?            else if ( this.loc == Entity.LOC_NONE ) {                this.warning.append                    ( "Found a slot while outside of a location.\n" );            }            // Handle the location.            else {                // Look for the element's attributes.                String index = (String) attr.get( INDEX );                String type = (String) attr.get( TYPE );                String rear = (String) attr.get( IS_REAR );                String shots = (String) attr.get( SHOTS );                String hit = (String) attr.get( IS_HIT );                String destroyed = (String) attr.get( IS_DESTROYED );                // Did we find required attributes?                if ( index == null || index.length() == 0 ) {                    this.warning.append                        ( "Could not find index for slot.\n" );                }                else if ( type == null || type.length() == 0 ) {                    this.warning.append                        ( "Could not find type for slot.\n" );                }                else {                    // Try to get a good index value.                    // Remember, slot index starts at 1.                    int indexVal = -1;                    try {                        indexVal = Integer.parseInt( index );                        indexVal -= 1;                    } catch ( NumberFormatException excep ) {                        // Handled by the next if test.                    }                    if ( index.equals( NA ) ) {                        indexVal = Entity.ARMOR_NA;                        // TODO: handle slotless equipment.                        return;                    }                    else if ( indexVal < 0 || indexVal > 12 ) {                        this.warning.append( "Found invalid index value for slot: " )                            .append( index )                            .append( ".\n" );                        return;                    }                    // Is this index valid for this entity?                    if ( indexVal > entity.getNumberOfCriticals(this.loc) ) {                        this.warning.append( "The entity, " )                            .append( this.entity.getShortName() )                            .append( " does not have " )                            .append( index )                            .append( " slots in location " )                            .append( this.loc )                            .append( ".\n" );                        return;                    }                    // Try to get a good isHit value.                    boolean hitFlag = false;                    try {                        if ( hit != null ) {                            hitFlag = hit.equals( "true" );                        }                    } catch ( Throwable excep ) {                            this.warning.append( "Found invalid isHit value: " )                                .append( hit )                                .append( ".\n" );                    }                    // Is the location destroyed?                    boolean destFlag = false;                    try {                        if ( destroyed != null ) {                            destFlag = destroyed.equals( "true" );                        }                    } catch ( Throwable excep ) {                        this.warning.append( "Found invalid isDestroyed value: " )                            .append( destroyed )                            .append( ".\n" );                    }                    // Try to get the critical slot.                    CriticalSlot slot = this.entity.getCritical( this.loc,                                                                 indexVal );                    // Did we get it?                    if ( slot == null ) {                        if ( !type.equals( EMPTY ) ) {                            this.warning.append( "Could not find the " )                                .append( type )                                .append( " equipment that was expected at index " )                                .append( indexVal )                                .append( " of location " )                                .append( this.loc )                                .append( ".\n" );                        }                        return;                    }                    // Is the slot for a critical system?                    if ( slot.getType() == CriticalSlot.TYPE_SYSTEM ) {                        // Does the XML file have some other kind of equipment?                        if ( !type.equals( SYSTEM ) ) {                            this.warning.append( "XML file expects to find " )                                .append( type )                                .append( " equipment at index " )                                .append( indexVal )                                .append( " of location " )                                .append( this.loc )                                .append( ", but Entity has a system.\n" );                        }                    } else {                        // Nope, we've got equipment.  Get this slot's mounted.                        Mounted mounted = this.entity.getEquipment                            ( slot.getIndex() );                        // Reset transient values.                        mounted.restore();                        // Hit and destroy the mounted, according to the flags.                        mounted.setDestroyed( hitFlag || destFlag );                        // Is the mounted a type of ammo?                        if ( mounted.getType() instanceof AmmoType ) {                            // Get the saved ammo load.                            EquipmentType newLoad =                                 EquipmentType.getByInternalName( type );                            if ( newLoad instanceof AmmoType ) {                                // Try to get a good shots value.                                int shotsVal = -1;                                try {                                    shotsVal = Integer.parseInt( shots );                                } catch ( NumberFormatException excep ) {                                    // Handled by the next if test.                                }                                if ( shots.equals( NA ) ) {                                    shotsVal = Entity.ARMOR_NA;                                    this.warning.append( "Expected to find number of shots for " )                                        .append( type )                                        .append( ", but found " )                                        .append( shots )                                        .append( " instead.\n" );                                }                                else if ( shotsVal < 0 || shotsVal > 200 ) {                                    this.warning.append( "Found invalid shots value for slot: " )                                        .append( shots )                                        .append( ".\n" );                                } else {                                    // Change to the saved ammo type and shots.                                    mounted.changeAmmoType((AmmoType) newLoad);                                    mounted.setShotsLeft                                        ( mounted.getShotsLeft() );                                } // End have-good-shots-value                            } else {                                // Bad XML equipment.                                this.warning.append( "XML file expects " )                                    .append( type )                                    .append( " equipment at index " )                                    .append( indexVal )                                    .append( " of location " )                                    .append( this.loc )                                    .append( ", but Entity has " )                                    .append( mounted.getType().getInternalName() )                                    .append( "there .\n" );                            }                        } // End slot-for-ammo                        // Not an ammo slot... does file agree with template?                        else if ( !mounted.getType().getInternalName()                                  .equals( type ) ) {                            // Bad XML equipment.                            this.warning.append( "XML file expects " )                                .append( type )                                .append( " equipment at index " )                                .append( indexVal )                                .append( " of location " )                                .append( this.loc )                                .append( ", but Entity has " )                                .append( mounted.getType().getInternalName() )                                .append( "there .\n" );                        }                    } // End have-equipment                    // Hit and destroy the slot, according to the flags.                    slot.setHit( hitFlag );                    slot.setDestroyed( destFlag );                } // End have-required-fields            } // End ready-for-slot        }    } // End public void recordElementStart( String, Hashtable )