Package megamek.common.loaders

Examples of megamek.common.loaders.EntityLoadingException


            try {
                parse(new FileInputStream(f.getAbsolutePath()), f.getName());
            } catch (Exception ex) {
                ex.printStackTrace();
                if (ex instanceof EntityLoadingException) {
                    throw new EntityLoadingException("While parsing file "
                            + f.getName() + ", " + ex.getMessage());
                }
                throw new EntityLoadingException("Exception from "
                        + ex.getClass() + ": " + ex.getMessage());
            }
        } else {

            // try zip file
            ZipFile zFile;
            try {
                zFile = new ZipFile(f.getAbsolutePath());
                parse(zFile.getInputStream(zFile.getEntry(entryName)),
                        entryName);
            } catch (EntityLoadingException ele) {
                throw new EntityLoadingException(ele.getMessage());
            } catch (NullPointerException npe) {
                throw new NullPointerException();
            } catch (Exception ex) {
                ex.printStackTrace();
                throw new EntityLoadingException("Exception from "
                        + ex.getClass() + ": " + ex.getMessage());
            }
        }
    }
View Full Code Here


        try {
            parse(is, fileName);
        } catch (Exception ex) {
            ex.printStackTrace();
            if (ex instanceof EntityLoadingException) {
                throw new EntityLoadingException(ex.getMessage());
            }
            throw new EntityLoadingException("Exception from " + ex.getClass()
                    + ": " + ex.getMessage());
        }
    }
View Full Code Here

                } else if (sType.equals("Warship")) {
                    loader = new BLKWarshipFile(bb);
                } else if (sType.equals("SpaceStation")) {
                    loader = new BLKSpaceStationFile(bb);
                } else {
                    throw new EntityLoadingException("Unknown UnitType: "
                            + sType);
                }
            } else {
                loader = new BLKMechFile(bb);
            }
        } else if (lowerName.endsWith(".dbm")) {
            throw new EntityLoadingException(
                    "In order to use mechs from The Drawing Board with MegaMek, you must save your mech as an XML file (look in the 'File' menu of TDB.)  Then use the resulting '.xml' file instead of the '.dbm' file.  Note that only version 2.0.23 or later of TDB is compatible with MegaMek.");
        } else {
            throw new EntityLoadingException("Unsupported file suffix");
        }

        m_entity = loader.getEntity();
        postLoadInit(m_entity);
    }
View Full Code Here

                    }
                }

                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.
View Full Code Here

TOP

Related Classes of megamek.common.loaders.EntityLoadingException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.