ex.printStackTrace(System.err);
System.err.println("... aborting entity loading.");
throw new EntityLoadingException(ex.getMessage());
}
} else if (criticalName != null) {
EquipmentType equipment = null;
try {
equipment = EquipmentType.get(criticalName);
if (equipment != null) {
// for experimental or unofficial equipment, we need
// to adjust the mech's techlevel, because HMP only
// knows lvl1/2/3
if ((equipment.getTechLevel() > mech.getTechLevel())
&& (mech.getTechLevel() >= TechConstants.T_IS_ADVANCED)) {
boolean isClan = mech.isClan();
if ((equipment.getTechLevel() == TechConstants.T_IS_EXPERIMENTAL) ||
(equipment.getTechLevel() == TechConstants.T_CLAN_EXPERIMENTAL)) {
mech.setTechLevel(isClan?TechConstants.T_CLAN_EXPERIMENTAL:TechConstants.T_IS_EXPERIMENTAL);
} else if ((equipment.getTechLevel() == TechConstants.T_IS_UNOFFICIAL) ||
(equipment.getTechLevel() == TechConstants.T_CLAN_UNOFFICIAL)) {
mech.setTechLevel(isClan?TechConstants.T_CLAN_UNOFFICIAL:TechConstants.T_IS_UNOFFICIAL);
}
}
boolean rearMounted = (equipment instanceof WeaponType)
&& isRearMounted(critical);
if (equipment.isSpreadable()) {
Mounted m = spreadEquipment.get(equipment);
if (m != null) {
CriticalSlot criticalSlot = new CriticalSlot(
CriticalSlot.TYPE_EQUIPMENT, mech
.getEquipmentNum(m),
equipment.isHittable(), m);
mech.addCritical(location, criticalSlot);
if (criticalName
.equalsIgnoreCase("Armored Cowl")) {
mech.setCowl(5); // Initialize
// armored cowl
}
} else {
m = mech.addEquipment(equipment, location,
rearMounted);
spreadEquipment.put(equipment, m);
}
} else if ((equipment instanceof WeaponType)
&& equipment
.hasFlag(WeaponType.F_SPLITABLE)) {
// do we already have this one in this or an
// outer location?
Mounted m = null;
boolean bFound = false;
for (int x = 0, n = vSplitWeapons.size(); x < n; x++) {
m = vSplitWeapons.elementAt(x);
int nLoc = m.getLocation();
if (((nLoc == location) || (location == Mech
.getInnerLocation(nLoc)))
&& m.getType().equals(equipment)) {
bFound = true;
break;
}
}
if (bFound) {
m.setFoundCrits(m.getFoundCrits() + 1);
if (m.getFoundCrits() >= equipment
.getCriticals(mech)) {
vSplitWeapons.removeElement(m);
}
// if we're in a new location, set the
// weapon as split
if (location != m.getLocation()) {
m.setSplit(true);
}
// give the most restrictive location for
// arcs
int help = m.getLocation();
m.setLocation(Mech.mostRestrictiveLoc(
location, help));
if (location != help) {
m.setSecondLocation(Mech
.leastRestrictiveLoc(location,
help));
}
} else {
// make a new one
m = new Mounted(mech, equipment);
m.setFoundCrits(1);
vSplitWeapons.addElement(m);
}
mech.addEquipment(m, location, rearMounted);
} else {
mech.addEquipment(equipment, location,
rearMounted);
}
} else {
if (!criticalName.equals("-Empty-")) {
// Can't load this piece of equipment!
// Add it to the list so we can show the user.
mech.addFailedEquipment(criticalName);
// Make the failed equipment an empty slot
crits[i] = 0;
// Compact criticals again
compactCriticals(crits);
// Re-parse the same slot, since the compacting
// could have moved new equipment to this slot
i--;
}
}
} catch (LocationFullException ex) {
System.err.print("Location was full when adding ");
System.err.print(equipment.getInternalName());
System.err.print(" to slot #");
System.err.print(i);
System.err.print(" of location ");
System.err.println(location);
ex.printStackTrace(System.err);