}
}
if (m.getLinked() == null) {
// huh. this shouldn't happen
throw new EntityLoadingException(
"Unable to match Artemis to launcher");
}
} // End link-Artemis
else if ((m.getType().hasFlag(MiscType.F_STEALTH)
|| m.getType().hasFlag(MiscType.F_VOIDSIG))
&& m.getLinked() == null
&& ent instanceof Mech) {
// Find an ECM suite to link to the stealth system.
// Stop looking after we find the first ECM suite.
for (Mounted mEquip : ent.getMisc()) {
MiscType mtype = (MiscType) mEquip.getType();
if (mtype.hasFlag(MiscType.F_ECM)) {
m.setLinked(mEquip);
break;
}
}
if (m.getLinked() == null) {
// This mech has stealth armor but no ECM. Probably
// an improperly created custom.
throw new EntityLoadingException(
"Unable to find an ECM Suite. Mechs with Stealth Armor or Void-Signature-System must also be equipped with an ECM Suite.");
}
} // End link-Stealth
// Link PPC Capacitor to PPC it its location.
else if (m.getType().hasFlag(MiscType.F_PPC_CAPACITOR)
&& m.getLinked() == null) {
// link up to a weapon in the same location
for (Mounted mWeapon : ent.getWeaponList()) {
WeaponType wtype = (WeaponType) mWeapon.getType();
// Only PPCS are Valid
if (!wtype.hasFlag(WeaponType.F_PPC)) {
continue;
}
// already linked?
if (mWeapon.getLinkedBy() != null) {
continue;
}
// check location
if (mWeapon.getLocation() == m.getLocation()) {
//Only Legal IS PPC's are allowed.
if ( mWeapon.getType() instanceof ISPPC
|| mWeapon.getType() instanceof ISLightPPC
|| mWeapon.getType() instanceof ISHeavyPPC
|| mWeapon.getType() instanceof ISERPPC
|| mWeapon.getType() instanceof ISSnubNosePPC ) {
m.setLinked(mWeapon);
break;
}
}
}
if (m.getLinked() == null) {
// huh. this shouldn't happen
throw new EntityLoadingException(
"Unable to match Capacitor to PPC");
}
} // End link-PPC Capacitor
// Link MRM Apollo fire-control systems to their missle racks.
else if (m.getType().hasFlag(MiscType.F_APOLLO)
&& m.getLinked() == null) {
// link up to a weapon in the same location
for (Mounted mWeapon : ent.getTotalWeaponList()) {
WeaponType wtype = (WeaponType) mWeapon.getType();
// only srm and lrm are valid for artemis
if (wtype.getAmmoType() != AmmoType.T_MRM) {
continue;
}
// already linked?
if (mWeapon.getLinkedBy() != null) {
continue;
}
// check location
if (mWeapon.getLocation() == m.getLocation()) {
m.setLinked(mWeapon);
break;
}
}
if (m.getLinked() == null) {
// huh. this shouldn't happen
throw new EntityLoadingException(
"Unable to match Apollo to launcher");
}
} // End link-Apollo
//now find any active probes and add them to the sensor list
//choose this sensor if added
if(m.getType().hasFlag(MiscType.F_BAP)) {
if(m.getType().getInternalName().equals(Sensor.BAP)) {
ent.getSensors().add(new Sensor(Sensor.TYPE_BAP));
ent.setNextSensor(ent.getSensors().lastElement());
} else if(m.getType().getInternalName().equals(Sensor.BLOODHOUND)) {
ent.getSensors().add(new Sensor(Sensor.TYPE_BLOODHOUND));
ent.setNextSensor(ent.getSensors().lastElement());
} else if(m.getType().getInternalName().equals(Sensor.WATCHDOG)) {
ent.getSensors().add(new Sensor(Sensor.TYPE_WATCHDOG));
ent.setNextSensor(ent.getSensors().lastElement());
} else if(m.getType().getInternalName().equals(Sensor.CLAN_AP)) {
ent.getSensors().add(new Sensor(Sensor.TYPE_CLAN_BAP));
ent.setNextSensor(ent.getSensors().lastElement());
} else if(m.getType().getInternalName().equals(Sensor.LIGHT_AP)) {
ent.getSensors().add(new Sensor(Sensor.TYPE_LIGHT_AP));
ent.setNextSensor(ent.getSensors().lastElement());
} else if(m.getType().getInternalName().equals(Sensor.CLIMPROVED)) {
ent.getSensors().add(new Sensor(Sensor.TYPE_BA_IMPROVED));
ent.setNextSensor(ent.getSensors().lastElement());
} else if(m.getType().getInternalName().equals(Sensor.ISIMPROVED)) {
ent.getSensors().add(new Sensor(Sensor.TYPE_BA_IMPROVED));
ent.setNextSensor(ent.getSensors().lastElement());
}
}
if (ent instanceof Mech
&& (m.getType().hasFlag(MiscType.F_CASE) || m.getType()
.hasFlag(MiscType.F_CASEII))) {
((Mech) ent).setAutoEject(false);
}
if ( ent instanceof Mech && m.getType().hasFlag(MiscType.F_ACTUATOR_ENHANCEMENT_SYSTEM)) {
if ( ent.hasTargComp()
|| ((Mech)ent).hasTSM()
|| (((Mech)ent).hasMASC() && !ent.hasWorkingMisc(MiscType.F_MASC, MiscType.S_SUPERCHARGER)) ) {
throw new EntityLoadingException("Unable to load AES due to incompatible systems");
}
if ( m.getLocation() != Mech.LOC_LARM && m.getLocation() != Mech.LOC_LLEG
&& m.getLocation() != Mech.LOC_RARM && m.getLocation() != Mech.LOC_RLEG) {
throw new EntityLoadingException("Unable to load AES due to incompatible location");
}
}
if ( m.getType().hasFlag(MiscType.F_HARJEL) && m.getLocation() == Mech.LOC_HEAD ) {
throw new EntityLoadingException("Unable to load harjel in head.");
}
if (m.getType().hasFlag(MiscType.F_MASS) && (m.getLocation() != Mech.LOC_HEAD || ((Mech) ent).getCockpitType() == Mech.COCKPIT_TORSO_MOUNTED && m.getLocation() != Mech.LOC_CT)) {
throw new EntityLoadingException("Unable to load MASS! Must be located in the same location as the cockpit.");
}
if ( m.getType().hasFlag(MiscType.F_MODULAR_ARMOR)
&& ( (ent instanceof Mech && m.getLocation() == Mech.LOC_HEAD) || (ent instanceof VTOL && m.getLocation() == VTOL.LOC_ROTOR) )) {
throw new EntityLoadingException("Unable to load Modular Armor in Rotor/Head location");
}
if ( m.getType().hasFlag(MiscType.F_TALON) ){
if ( ent instanceof BipedMech ){
if ( m.getLocation() != Mech.LOC_LLEG && m.getLocation() != Mech.LOC_RLEG ){
throw new EntityLoadingException("Talons are only legal in the Legs");
}
if ( !ent.hasWorkingMisc(MiscType.F_TALON,-1,Mech.LOC_RLEG) || !ent.hasWorkingMisc(MiscType.F_TALON,-1,Mech.LOC_LLEG) ){
throw new EntityLoadingException("Talons must be in all legs");
}
}else if ( ent instanceof QuadMech ){
if ( m.getLocation() != Mech.LOC_LLEG && m.getLocation() != Mech.LOC_RLEG &&
m.getLocation() != Mech.LOC_LARM && m.getLocation() != Mech.LOC_RARM){
throw new EntityLoadingException("Talons are only legal in the Legs");
}
if ( !ent.hasWorkingMisc(MiscType.F_TALON,-1,Mech.LOC_RLEG) || !ent.hasWorkingMisc(MiscType.F_TALON,-1,Mech.LOC_LLEG) ||
!ent.hasWorkingMisc(MiscType.F_TALON,-1,Mech.LOC_LARM) || !ent.hasWorkingMisc(MiscType.F_TALON,-1,Mech.LOC_LARM)){
throw new EntityLoadingException("Talons must be in all legs");
}
}else {
throw new EntityLoadingException("Unable to load talons in non-Mek entity");
}
}
} // Check the next piece of equipment.