}
boolean rearMount = false;
int nAmmo = 1;
// set up a new weapons bay mount
Mounted bayMount = null;
// set up a new bay type
boolean newBay = false;
boolean subCap = false;
int bayDamage = 0;
int nBay = 1;
if (saEquip[0] != null) {
for (String element : saEquip) {
rearMount = false;
nAmmo = 1;
newBay = false;
subCap = false;
String equipName = element.trim();
// I will need to deal with rear-mounted bays on Dropships
if (equipName.startsWith("(R) ")) {
rearMount = true;
equipName = equipName.substring(4);
}
if (equipName.startsWith("(B) ")) {
newBay = true;
equipName = equipName.substring(4);
}
if (equipName.startsWith("(SC) ")) {
newBay = true;
subCap = true;
equipName = equipName.substring(4);
}
// check for ammo loadouts
if (equipName.contains(":") && equipName.contains("Ammo")) {
// then split by the :
String[] temp;
temp = equipName.split(":");
equipName = temp[0];
if (temp[1] != null) {
nAmmo = Integer.parseInt(temp[1]);
}
}
EquipmentType etype = EquipmentType.get(equipName);
if (etype == null) {
// try w/ prefix
etype = EquipmentType.get(prefix + equipName);
}
if (etype != null) {
// first load the equipment
Mounted newmount;
try {
if (nAmmo == 1) {
newmount = a.addEquipment(etype, nLoc, rearMount);
} else {
newmount = a.addEquipment(etype, nLoc, rearMount, nAmmo);
}
} catch (LocationFullException ex) {
throw new EntityLoadingException(ex.getMessage());
}
// this is where weapon bays go
// first, lets see if it is a weapon
if (newmount.getType() instanceof WeaponType) {
// if so then I need to find out if it is the same class
// as the current weapon bay
// If the current bay is null, then it needs to be
// initialized
WeaponType weap = (WeaponType) newmount.getType();
if (bayMount == null) {
if (subCap) {
try {
bayMount = a.addEquipment(WeaponType.getSubCapBayType(weap.getAtClass()), nLoc, rearMount);
newBay = false;
} catch (LocationFullException ex) {
throw new EntityLoadingException(ex.getMessage());
}
} else {
try {
bayMount = a.addEquipment(WeaponType.getBayType(weap.getAtClass()), nLoc, rearMount);
newBay = false;
} catch (LocationFullException ex) {
throw new EntityLoadingException(ex.getMessage());
}
}
}
int damage = weap.getRoundShortAV();
if (weap.isCapital()) {
damage *= 10;
}
if (!newBay && (bayDamage + damage) <= 700 && bayMount.isRearMounted() == rearMount && weap.getAtClass() == ((WeaponType) bayMount.getType()).getAtClass() && !(((WeaponType) bayMount.getType()).isSubCapital() && !weap.isSubCapital())) {
// then we should add this weapon to the current bay
bayMount.addWeaponToBay(a.getEquipmentNum(newmount));
bayDamage += damage;
} else {
if (subCap) {
try {
bayMount = a.addEquipment(WeaponType.getSubCapBayType(weap.getAtClass()), nLoc, rearMount);
} catch (LocationFullException ex) {
throw new EntityLoadingException(ex.getMessage());
}
} else {
try {
bayMount = a.addEquipment(WeaponType.getBayType(weap.getAtClass()), nLoc, rearMount);
} catch (LocationFullException ex) {
throw new EntityLoadingException(ex.getMessage());
}
}
bayMount.addWeaponToBay(a.getEquipmentNum(newmount));
// reset bay damage
bayDamage = damage;
nBay++;
}
}
// ammo should also get loaded into the bay
if (newmount.getType() instanceof AmmoType) {
bayMount.addAmmoToBay(a.getEquipmentNum(newmount));
}
} else if (equipName != "0") {
a.addFailedEquipment(equipName);
}