Examples of Mech


Examples of megamek.common.Mech

    public Vector<BackGroundDrawer> getBackgroundDrawers() {
        return bgDrawers;
    }

    public void setEntity(Entity e) {
        Mech m = (Mech) e;
        boolean mtHeat = false;
        if ((e.getGame() != null)
                && e.getGame().getOptions().booleanOption("tacops_heat")) {
            mtHeat = true;
        }
        int a = 1;
        int a0 = 1;
        for (int i = 0; i < m.locations(); i++) {
            a = m.getArmor(i);
            a0 = m.getOArmor(i);
            vLabels[i].setValue(m.getArmorString(i));
            WidgetUtils.setAreaColor(areas[i], vLabels[i], (double) a
                    / (double) a0);
            if (m.hasRearArmor(i)) {
                a = m.getArmor(i, true);
                a0 = m.getOArmor(i, true);
                vLabels[i + REAR_AREA_OFFSET].setValue(m
                        .getArmorString(i, true));
                WidgetUtils.setAreaColor(areas[i + REAR_AREA_OFFSET], vLabels[i
                        + REAR_AREA_OFFSET], (double) a / (double) a0);
            }
            a = m.getInternal(i);
            a0 = m.getOInternal(i);
            vLabels[i + INT_STRUCTURE_OFFSET].setValue(m.getInternalString(i));
            WidgetUtils.setAreaColor(areas[i + INT_STRUCTURE_OFFSET], vLabels[i
                    + INT_STRUCTURE_OFFSET], (double) a / (double) a0);
        }

        // heat
        vLabels[19].setValue(Integer.toString(m.heat));
        drawHeatControl(m.heat, mtHeat);
        //TODO: this messes up the layout a bit, but only for industrial
        // mechs FIXME
        if (m.hasBARArmor()) {
            content.addArea(labels[19]);
            content.addArea(vLabels[20]);
            vLabels[20].setValue(String.valueOf(m.getBARRating()));
        } else {
            content.removeArea(labels[19]);
            content.removeArea(vLabels[20]);
        }
View Full Code Here

Examples of megamek.common.Mech

            // Show Heat Effects, but only for Mechs.
            heatR.setText(""); //$NON-NLS-1$
            sinksR.setText("");

            if (en instanceof Mech) {
                Mech m = (Mech) en;

                sinks2B.setEnabled(!dontChange);
                sinks = m.getActiveSinksNextRound();
                if (m.hasDoubleHeatSinks()) {
                    sinksR.append(Messages.getString(
                            "MechDisplay.activeSinksTextDouble",
                            new Object[] { new Integer(sinks),
                                    new Integer(sinks * 2) }));
                } else {
View Full Code Here

Examples of megamek.common.Mech

            // Show Heat Effects, but only for Mechs.
            heatR.setText(""); //$NON-NLS-1$
            sinksR.setText("");

            if (en instanceof Mech) {
                Mech m = (Mech) en;

                sinks2B.setEnabled(!dontChange);
                sinks = m.getActiveSinksNextRound();
                if (m.hasDoubleHeatSinks()) {
                    sinksR.append(Messages.getString(
                            "MechDisplay.activeSinksTextDouble",
                            new Object[] { new Integer(sinks),
                                    new Integer(sinks * 2) }));
                } else {
View Full Code Here

Examples of megamek.common.Mech

    }

    /* OMIT_FOR_JHMPREAD_COMPILATION BLOCK_BEGIN */
    public Entity getEntity() throws EntityLoadingException {
        try {
            Mech mech = null;
            if ((chassisType == ChassisType.QUADRAPED_OMNI)
                    || (chassisType == ChassisType.QUADRAPED)) {
                mech = new QuadMech(gyroType, cockpitType);
            } else if (chassisType == ChassisType.ARMLESS) {
                mech = new ArmlessMech(gyroType, cockpitType);
            } else {
                mech = new BipedMech(gyroType, cockpitType);
            }

            mech.setChassis(name);
            mech.setModel(model);
            mech.setYear(year);
            mech.setFluff(fluff);

            mech.setOmni((chassisType == ChassisType.BIPED_OMNI)
                    || (chassisType == ChassisType.QUADRAPED_OMNI));

            if (techType == TechType.INNER_SPHERE) {
                switch (rulesLevel) {
                    case 1:
                        mech.setTechLevel(TechConstants.T_INTRO_BOXSET);
                        break;
                    case 2:
                        mech.setTechLevel(TechConstants.T_IS_TW_NON_BOX);
                        break;
                    case 3:
                        mech.setTechLevel(TechConstants.T_IS_ADVANCED);
                        break;
                    default:
                        throw new EntityLoadingException(
                                "Unsupported tech level: " + rulesLevel);
                }
            } else if (techType == TechType.CLAN) {
                switch (rulesLevel) {
                    case 2:
                        mech.setTechLevel(TechConstants.T_CLAN_TW);
                        break;
                    case 3:
                        mech.setTechLevel(TechConstants.T_CLAN_ADVANCED);
                        break;
                    default:
                        throw new EntityLoadingException(
                                "Unsupported tech level: " + rulesLevel);
                }
            } else if ((techType == TechType.MIXED)
                    && (mixedBaseTechType == TechType.INNER_SPHERE)) {
                mech.setTechLevel(TechConstants.T_IS_ADVANCED);
                mech.setMixedTech(true);
            } else if ((techType == TechType.MIXED)
                    && (mixedBaseTechType == TechType.CLAN)) {
                mech.setTechLevel(TechConstants.T_CLAN_ADVANCED);
                mech.setMixedTech(true);
            } else {
                throw new EntityLoadingException("Unsupported tech base: "
                        + techType);
            }

            mech.setWeight(tonnage);

            int engineFlags = 0;
            if ((techType == TechType.CLAN) || (engineTechType == TechType.CLAN)) {
                engineFlags = Engine.CLAN_ENGINE;
            }
            mech.setEngine(new Engine(engineRating, Engine
                            .getEngineTypeByString(engineType.toString()),
                            engineFlags));

            mech.setOriginalJumpMP(jumpMP);

            mech.setStructureType(internalStructureType.toString());
            mech.autoSetInternal();

            mech.setArmorType(armorType.toString());
            if (armorTechType == TechType.CLAN) {
                switch (rulesLevel) {
                case 2:
                    mech.setArmorTechLevel(TechConstants.T_CLAN_TW);
                    break;
                case 3:
                    mech.setArmorTechLevel(TechConstants.T_CLAN_ADVANCED);
                    break;
                default:
                    throw new EntityLoadingException(
                            "Unsupported tech level: " + rulesLevel);
                }
            } else {
                switch (rulesLevel) {
                case 1:
                    mech.setArmorTechLevel(TechConstants.T_INTRO_BOXSET);
                    break;
                case 2:
                    mech.setArmorTechLevel(TechConstants.T_IS_TW_NON_BOX);
                    break;
                case 3:
                    mech.setArmorTechLevel(TechConstants.T_IS_ADVANCED);
                    break;
                default:
                    throw new EntityLoadingException(
                            "Unsupported tech level: " + rulesLevel);
                }
            }
            mech.initializeArmor(laArmor, Mech.LOC_LARM);
            mech.initializeArmor(ltArmor, Mech.LOC_LT);
            mech.initializeRearArmor(ltrArmor, Mech.LOC_LT);
            mech.initializeArmor(llArmor, Mech.LOC_LLEG);

            mech.initializeArmor(raArmor, Mech.LOC_RARM);
            mech.initializeArmor(rtArmor, Mech.LOC_RT);
            mech.initializeRearArmor(rtrArmor, Mech.LOC_RT);
            mech.initializeArmor(rlArmor, Mech.LOC_RLEG);

            mech.initializeArmor(headArmor, Mech.LOC_HEAD);

            mech.initializeArmor(ctArmor, Mech.LOC_CT);
            mech.initializeRearArmor(ctrArmor, Mech.LOC_CT);

            setupCriticals(mech);

            if (mech.isClan()) {
                mech.addClanCase();
            }

            if (rulesLevel > 2) {
                mech.setTargSysType(getTargSys());
            }

            // add any heat sinks not allocated
            mech.addEngineSinks(heatSinks - mech.heatSinks(),
                    heatSinkType == HeatSinkType.DOUBLE);

            return mech;
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

Examples of megamek.common.Mech

         */
    }

    public Entity getEntity() throws EntityLoadingException {
        try {
            Mech mech;

            int iGyroType = Mech.GYRO_STANDARD;
            try {
                iGyroType = Mech.getGyroTypeForString(gyroType.substring(5));
                if (iGyroType == Mech.GYRO_UNKNOWN) {
                    iGyroType = Mech.GYRO_STANDARD;
                }
            } catch (Exception e) {
                iGyroType = Mech.GYRO_STANDARD;
            }
            int iCockpitType = Mech.COCKPIT_STANDARD;
            try {
                iCockpitType = Mech.getCockpitTypeForString(cockpitType
                        .substring(8));
                if (iCockpitType == Mech.COCKPIT_UNKNOWN) {
                    iCockpitType = Mech.COCKPIT_STANDARD;
                }
            } catch (Exception e) {
                iCockpitType = Mech.COCKPIT_STANDARD;
            }
            if (chassisConfig.indexOf("Quad") != -1) {
                mech = new QuadMech(iGyroType, iCockpitType);
            } else if (chassisConfig.indexOf("LAM") != -1) {
                mech = new LandAirMech(iGyroType, iCockpitType);
            } else {
                mech = new BipedMech(iGyroType, iCockpitType);
            }

            // aarg! those stupid sub-names in parenthesis screw everything up
            // we may do something different in the future, but for now, I'm
            // going to strip them out
            int pindex = name.indexOf("(");
            if (pindex == -1) {
                mech.setChassis(name.trim());
            } else {
                mech.setChassis(name.substring(0, pindex - 1).trim());
            }
            mech.setModel(model.trim());
            mech.setYear(Integer.parseInt(techYear.substring(4).trim()));
            mech.setSource(source.substring("Source:".length()).trim());

            if (chassisConfig.indexOf("Omni") != -1) {
                mech.setOmni(true);
            }

            if (techBase.substring(9).trim().equals("Inner Sphere")) {
                switch (Integer.parseInt(rulesLevel.substring(12).trim())) {
                    case 1:
                        mech.setTechLevel(TechConstants.T_INTRO_BOXSET);
                        break;
                    case 2:
                        mech.setTechLevel(TechConstants.T_IS_TW_NON_BOX);
                        break;
                    case 3:
                        mech.setTechLevel(TechConstants.T_IS_ADVANCED);
                        break;
                    case 4:
                        mech.setTechLevel(TechConstants.T_IS_EXPERIMENTAL);
                        break;
                    case 5:
                        mech.setTechLevel(TechConstants.T_IS_UNOFFICIAL);
                        break;
                    default:
                        throw new EntityLoadingException(
                                "Unsupported tech level: "
                                        + rulesLevel.substring(12).trim());
                }
            } else if (techBase.substring(9).trim().equals("Clan")) {
                switch (Integer.parseInt(rulesLevel.substring(12).trim())) {
                    case 2:
                        mech.setTechLevel(TechConstants.T_CLAN_TW);
                        break;
                    case 3:
                        mech.setTechLevel(TechConstants.T_CLAN_ADVANCED);
                        break;
                    case 4:
                        mech.setTechLevel(TechConstants.T_CLAN_EXPERIMENTAL);
                        break;
                    case 5:
                        mech.setTechLevel(TechConstants.T_CLAN_UNOFFICIAL);
                        break;
                    default:
                        throw new EntityLoadingException(
                                "Unsupported tech level: "
                                        + rulesLevel.substring(12).trim());
                }
            } else if (techBase.substring(9).trim()
                    .equals("Mixed (IS Chassis)")) {
                switch (Integer.parseInt(rulesLevel.substring(12).trim())) {
                case 3:
                    mech.setTechLevel(TechConstants.T_IS_ADVANCED);
                    break;
                case 4:
                    mech.setTechLevel(TechConstants.T_IS_EXPERIMENTAL);
                    break;
                case 5:
                    mech.setTechLevel(TechConstants.T_IS_UNOFFICIAL);
                    break;
                default:
                    throw new EntityLoadingException(
                            "Unsupported tech level: "
                                    + rulesLevel.substring(12).trim());
                }
                mech.setMixedTech(true);
            } else if (techBase.substring(9).trim().equals(
                    "Mixed (Clan Chassis)")) {
                switch (Integer.parseInt(rulesLevel.substring(12).trim())) {
                case 3:
                    mech.setTechLevel(TechConstants.T_CLAN_ADVANCED);
                    break;
                case 4:
                    mech.setTechLevel(TechConstants.T_CLAN_EXPERIMENTAL);
                    break;
                case 5:
                    mech.setTechLevel(TechConstants.T_CLAN_UNOFFICIAL);
                    break;
                default:
                    throw new EntityLoadingException(
                            "Unsupported tech level: "
                                    + rulesLevel.substring(12).trim());
                }
                mech.setMixedTech(true);
            } else if (techBase.substring(9).trim().equals("Mixed")) {
                throw new EntityLoadingException(
                        "Unsupported tech base: \"Mixed\" is no longer allowed by itself.  You must specify \"Mixed (IS Chassis)\" or \"Mixed (Clan Chassis)\".");
            } else {
                throw new EntityLoadingException("Unsupported tech base: "
                        + techBase.substring(9).trim());
            }

            mech.setWeight(Integer.parseInt(tonnage.substring(5)));

            int engineFlags = 0;
            if ((mech.isClan() && !mech.isMixedTech())
                    || (mech.isMixedTech() && mech.isClan() && !mech
                            .itemOppositeTech(engine))) {
                engineFlags = Engine.CLAN_ENGINE;
            }

            int engineRating = Integer.parseInt(engine.substring(engine
                    .indexOf(":") + 1, engine.indexOf(" ")));
            mech.setEngine(new Engine(engineRating, Engine
                    .getEngineTypeByString(engine), engineFlags));

            mech.setOriginalJumpMP(Integer.parseInt(jumpMP.substring(8)));

            boolean dblSinks = (heatSinks.substring(14).equalsIgnoreCase("Double"));

            boolean laserSinks = heatSinks.substring(14).equalsIgnoreCase("Laser");

            int expectedSinks = Integer.parseInt(heatSinks.substring(11, 13).trim());

            int baseHeatSinks = Integer.parseInt(baseChassieHeatSinks.substring("base chassis heat sinks:".length()).trim());

            String thisStructureType = internalType.substring(internalType.indexOf(':') + 1);
            if (thisStructureType.length() > 0) {
                mech.setStructureType(thisStructureType);
            } else {
                mech.setStructureType(EquipmentType.T_STRUCTURE_STANDARD);
            }
            mech.autoSetInternal();

            String thisArmorType = armorType
                    .substring(armorType.indexOf(':') + 1);
            if (thisArmorType.indexOf('(') != -1) {
                if (thisArmorType.toLowerCase().indexOf("clan") != -1) {
                    switch (Integer.parseInt(rulesLevel.substring(12).trim())) {
                    case 2:
                        mech.setArmorTechLevel(TechConstants.T_CLAN_TW);
                        break;
                    case 3:
                        mech.setArmorTechLevel(TechConstants.T_CLAN_ADVANCED);
                        break;
                    case 4:
                        mech.setArmorTechLevel(TechConstants.T_CLAN_EXPERIMENTAL);
                        break;
                    case 5:
                        mech.setArmorTechLevel(TechConstants.T_CLAN_UNOFFICIAL);
                        break;
                    default:
                        throw new EntityLoadingException(
                                "Unsupported tech level: "
                                + rulesLevel.substring(12).trim());
                    }
                } else if (thisArmorType.toLowerCase().indexOf("inner sphere") != -1) {
                    switch (Integer.parseInt(rulesLevel.substring(12).trim())) {
                    case 1:
                        mech.setArmorTechLevel(TechConstants.T_INTRO_BOXSET);
                        break;
                    case 2:
                        mech.setArmorTechLevel(TechConstants.T_IS_TW_NON_BOX);
                        break;
                    case 3:
                        mech.setArmorTechLevel(TechConstants.T_IS_ADVANCED);
                        break;
                    case 4:
                        mech.setArmorTechLevel(TechConstants.T_IS_EXPERIMENTAL);
                        break;
                    case 5:
                        mech.setArmorTechLevel(TechConstants.T_IS_UNOFFICIAL);
                        break;
                    default:
                        throw new EntityLoadingException(
                                "Unsupported tech level: "
                                + rulesLevel.substring(12).trim());
                    }
                }
                thisArmorType = thisArmorType.substring(0, thisArmorType.indexOf('('));
            } else {
                mech.setArmorTechLevel(mech.getTechLevel());
            }
            if (thisArmorType.length() > 0) {
                mech.setArmorType(thisArmorType);
            } else {
                mech.setArmorType(EquipmentType.T_ARMOR_STANDARD);
            }
            for (int x = 0; x < locationOrder.length; x++) {
                mech.initializeArmor(Integer.parseInt(armorValues[x]
                        .substring(armorValues[x].indexOf(':')+1)), locationOrder[x]);
            }
            for (int x = 0; x < rearLocationOrder.length; x++) {
                mech.initializeRearArmor(Integer.parseInt(armorValues[x
                        + locationOrder.length].substring(10)),
                        rearLocationOrder[x]);
            }

            // oog, crits.
            compactCriticals(mech);
            // we do these in reverse order to get the outermost
            // locations first, which is necessary for split crits to work
            for (int i = mech.locations() - 1; i >= 0; i--) {
                parseCrits(mech, i);
            }

            if (mech.isClan()) {
                mech.addClanCase();
            }

            // add any heat sinks not allocated
            if ( laserSinks ){
                mech.addEngineSinks(expectedSinks - mech.heatSinks(), "CLLaser Heat Sink");
            } else {
                mech.addEngineSinks(expectedSinks - mech.heatSinks(), dblSinks);
            }

            if (mech.isOmni()) {
                if (baseHeatSinks >= 10) {
                    mech.getEngine().setBaseChassisHeatSinks(baseHeatSinks);
                } else {
                    mech.getEngine().setBaseChassisHeatSinks(expectedSinks);
                }
            }
            return mech;
        } catch (NumberFormatException ex) {
            ex.printStackTrace();
View Full Code Here

Examples of megamek.common.Mech

                        && (cs.getType() == CriticalSlot.TYPE_SYSTEM)) {
                    int nMode = m_chMode.getSelectedIndex();
                    if (nMode >= 0) {
                        if ((cs.getIndex() == Mech.SYSTEM_COCKPIT)
                                && en.hasEiCockpit() && (en instanceof Mech)) {
                            Mech mech = (Mech) en;
                            mech.setCockpitStatus(nMode);
                            clientgui.getClient().sendSystemModeChange(
                                    en.getId(), Mech.SYSTEM_COCKPIT, nMode);
                            if (mech.getCockpitStatus() == mech
                                    .getCockpitStatusNextRound()) {
                                clientgui
                                        .systemMessage(Messages
                                                .getString(
                                                        "MechDisplay.switched", new Object[] { "Cockpit", m_chMode.getSelectedItem() }));//$NON-NLS-1$
View Full Code Here

Examples of megamek.common.Mech

                        && (cs.getType() == CriticalSlot.TYPE_SYSTEM)) {
                    int nMode = m_chMode.getSelectedIndex();
                    if (nMode >= 0) {
                        if ((cs.getIndex() == Mech.SYSTEM_COCKPIT)
                                && en.hasEiCockpit() && (en instanceof Mech)) {
                            Mech mech = (Mech) en;
                            mech.setCockpitStatus(nMode);
                            clientgui.getClient().sendSystemModeChange(
                                    en.getId(), Mech.SYSTEM_COCKPIT, nMode);
                            if (mech.getCockpitStatus() == mech
                                    .getCockpitStatusNextRound()) {
                                clientgui
                                        .systemMessage(Messages
                                                .getString(
                                                        "MechDisplay.switched", new Object[] { "Cockpit", m_chMode.getSelectedItem() }));//$NON-NLS-1$
View Full Code Here

Examples of megamek.common.Mech

        }
    }

    public Entity getEntity() throws EntityLoadingException {
        try {
            Mech mech;

            if ("Quad".equals(chassisType.trim())) {
                mech = new QuadMech();
            } else {
                mech = new BipedMech();
            }

            int firstSpace = name.indexOf(" ");
            if (firstSpace != -1) {
                mech.setChassis(name.substring(firstSpace).trim());
                mech.setModel(name.substring(5, firstSpace).trim());
            } else {
                mech.setChassis(name.substring(5).trim());
                mech.setModel(name.substring(5).trim());
            }

            mech.setWeight(Integer.decode(tonnage.trim()).intValue());
            mech.setYear(Integer.parseInt(techYear.trim()));
            mech.setOmni("OmniMech".equals(chassisType.trim()));

            // TODO: this ought to be a better test
            if ("InnerSphere".equals(innerSphere.trim())) {
                if (mech.getYear() == 3025) {
                    mech.setTechLevel(TechConstants.T_INTRO_BOXSET);
                } else {
                    mech.setTechLevel(TechConstants.T_IS_TW_NON_BOX);
                }
            } else {
                mech.setTechLevel(TechConstants.T_CLAN_TW);
            }

            int engineFlags = 0;
            if (mech.isClan()) {
                engineFlags = Engine.CLAN_ENGINE;
            }
            int engineRating = Integer.parseInt(walkMP.trim())
                    * (int) mech.getWeight();
            mech.setEngine(new Engine(engineRating, Engine
                    .getEngineTypeByString(engineType), engineFlags));
            // No support for moveable system crits due to goofy critical
            // format. Could be fixed, but I don't think anyone uses
            // MEP for level 3 designs.
            mech.addEngineCrits();
            mech.addCockpit();
            mech.addGyro();

            mech.setOriginalJumpMP(Integer.parseInt(jumpMP.trim()));

            boolean dblSinks = "Double".equals(heatSinkType.trim());
            mech.addEngineSinks(Integer.parseInt(heatSinks.trim()),
                    dblSinks);

            mech.setStructureType(internalType);

            mech.setArmorType(armorType);

            decodeArmorAndInternals(mech, Mech.LOC_HEAD, headArmor);
            decodeArmorAndInternals(mech, Mech.LOC_LARM, larmArmor);
            decodeArmorAndInternals(mech, Mech.LOC_LT, ltArmor);
            decodeRearArmor(mech, Mech.LOC_LT, ltrArmor);
            decodeArmorAndInternals(mech, Mech.LOC_CT, ctArmor);
            decodeRearArmor(mech, Mech.LOC_CT, ctrArmor);
            decodeArmorAndInternals(mech, Mech.LOC_RT, rtArmor);
            decodeRearArmor(mech, Mech.LOC_RT, rtrArmor);
            decodeArmorAndInternals(mech, Mech.LOC_RARM, rarmArmor);
            decodeArmorAndInternals(mech, Mech.LOC_RLEG, rlegArmor);
            decodeArmorAndInternals(mech, Mech.LOC_LLEG, llegArmor);

            // remove arm actuators
            for (int i = 0; i < equipData.length; i++) {
                String eqName = new String(equipData[i]);
                eqName = eqName.substring(5, 28).trim();

                if (eqName.equals("No Lower Right Arm")) {
                    mech.removeCriticals(Mech.LOC_RARM, new CriticalSlot(
                            CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_LOWER_ARM));
                    mech.removeCriticals(Mech.LOC_RARM, new CriticalSlot(
                            CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_HAND));
                } else if (eqName.equals("No Lower Left Arm")) {
                    mech.removeCriticals(Mech.LOC_LARM, new CriticalSlot(
                            CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_LOWER_ARM));
                    mech.removeCriticals(Mech.LOC_LARM, new CriticalSlot(
                            CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_HAND));
                } else if (eqName.equals("No Right Hand")) {
                    mech.removeCriticals(Mech.LOC_RARM, new CriticalSlot(
                            CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_HAND));
                } else if (eqName.equals("No Left Hand")) {
                    mech.removeCriticals(Mech.LOC_LARM, new CriticalSlot(
                            CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_HAND));
                }
            }

            // hmm, what to do with the rest of equipment list... I dunno.

            // prefix is "Clan " or "IS "
            String prefix;
            if (mech.getTechLevel() == TechConstants.T_CLAN_TW) {
                prefix = "Clan ";
            } else {
                prefix = "IS ";
            }

            // parse the critical hit slots
            for (int i = 0; i < critData.length; i++) {
                int loc = mech.getLocationFromAbbr(critData[i].substring(3, 5));
                int slot = Integer.parseInt(critData[i].substring(5, 7));
                boolean rearMounted = false;
                String critName = critData[i].substring(7).trim();

                // if the slot's full already, skip it.
                if (mech.getCritical(loc, slot) != null) {
                    continue;
                }

                if (critName.startsWith("(R)")) {
                    rearMounted = true;
                    critName = critName.substring(3).trim();
                }
                if (critName.equalsIgnoreCase("Armored Cowl")) {
                    mech.setCowl(5);
                }
                // this is a bit a kludge, but MEP is stupid
                if (critName.equals("Heat Sink") && dblSinks) {
                    critName = "Double Heat Sink";
                }

                EquipmentType etype = EquipmentType.get(prefix + critName);
                if (etype == null) {
                    // try w/o prefix
                    etype = EquipmentType.get(critName);
                }
                if (etype != null) {
                    try {
                        if (etype.isSpreadable()) {
                            // do we already have one of these? Key on Type
                            Mounted m = hSharedEquip.get(etype);
                            if (m != null) {
                                // use the existing one
                                mech.addCritical(loc, new CriticalSlot(
                                        CriticalSlot.TYPE_EQUIPMENT, mech
                                                .getEquipmentNum(m), etype
                                                .isHittable(), m));
                                continue;
                            }
                            m = mech.addEquipment(etype, loc, rearMounted);
                            hSharedEquip.put(etype, m);
                        } else {
                            mech.addEquipment(etype, loc, rearMounted);
                        }
                    } catch (LocationFullException ex) {
                        throw new EntityLoadingException(ex.getMessage());
                    }
                } else {
                    if (!critName.equals("-----------------")
                            && !critName.equals("''")) {
                        // Can't load this piece of equipment!
                        mech.addFailedEquipment(critName);
                    }
                }
            }

            if (mech.isClan()) {
                mech.addClanCase();
            }

            return mech;
        } catch (NumberFormatException ex) {
            throw new EntityLoadingException(
View Full Code Here

Examples of megamek.common.Mech

            chassisType = 0;
        } else {
            chassisType = dataFile.getDataAsInt("chassis_type")[0];
        }

        Mech mech = null;

        if (chassisType == 1)
            mech = new QuadMech();
        else
            mech = new BipedMech();

        // Do I even write the year for these??

        if (!dataFile.exists("name"))
            throw new EntityLoadingException("Could not find block.");
        mech.setChassis(dataFile.getDataAsString("Name")[0]);

        if (!dataFile.exists("model"))
            throw new EntityLoadingException("Could not find block.");
        mech.setModel(dataFile.getDataAsString("Model")[0]);

        setTechLevel(mech);

        if (!dataFile.exists("tonnage"))
            throw new EntityLoadingException("Could not find block.");
        mech.setWeight(dataFile.getDataAsFloat("tonnage")[0]);

        int engineCode = BLKFile.FUSION;
        if (dataFile.exists("engine_type")) {
            engineCode = dataFile.getDataAsInt("engine_type")[0];
        }
        int engineFlags = 0;
        if (mech.isClan())
            engineFlags = Engine.CLAN_ENGINE;
        if (!dataFile.exists("walkingMP"))
            throw new EntityLoadingException("Could not find walkingMP block.");
        int engineRating = dataFile.getDataAsInt("walkingMP")[0]
                * (int) mech.getWeight();
        mech.setEngine(new Engine(engineRating, BLKFile
                .translateEngineCode(engineCode), engineFlags));

        if (!dataFile.exists("jumpingMP"))
            throw new EntityLoadingException("Could not find block.");
        mech.setOriginalJumpMP(dataFile.getDataAsInt("jumpingMP")[0]);

        // I keep internal(integral) heat sinks seperate...
        if (!dataFile.exists("heatsinks"))
            throw new EntityLoadingException("Could not find block.");
        mech.addEngineSinks(dataFile.getDataAsInt("heatsinks")[0], false);

        if (dataFile.exists("internal_type"))
            mech.setStructureType(dataFile.getDataAsInt("internal_type")[0]);

        if (dataFile.exists("armor_type"))
            mech.setArmorType(dataFile.getDataAsInt("armor_type")[0]);

        if (!dataFile.exists("armor"))
            throw new EntityLoadingException("Could not find block.");

        int[] armor = new int[11]; // only 11 locations...

        if (dataFile.getDataAsInt("armor").length < 11) {
            System.err
                    .println("BLKMechFile->Read armor array doesn't match my armor array...");
            throw new EntityLoadingException("Could not find block.");

        }
        armor = dataFile.getDataAsInt("Armor");

        mech.initializeArmor(armor[BLKMechFile.HD], Mech.LOC_HEAD);

        mech.initializeArmor(armor[BLKMechFile.LA], Mech.LOC_LARM);
        mech.initializeArmor(armor[BLKMechFile.RA], Mech.LOC_RARM);
        mech.initializeArmor(armor[BLKMechFile.LL], Mech.LOC_LLEG);
        mech.initializeArmor(armor[BLKMechFile.RL], Mech.LOC_RLEG);

        mech.initializeArmor(armor[BLKMechFile.CF], Mech.LOC_CT);
        mech.initializeArmor(armor[BLKMechFile.LF], Mech.LOC_LT);
        mech.initializeArmor(armor[BLKMechFile.RF], Mech.LOC_RT);

        // changed...
        mech.initializeRearArmor(armor[BLKMechFile.CB], Mech.LOC_CT);
        mech.initializeRearArmor(armor[BLKMechFile.LB], Mech.LOC_LT);
        mech.initializeRearArmor(armor[BLKMechFile.RB], Mech.LOC_RT);

        if (!dataFile.exists("internal armor")) {
            // try to guess...
            mech.setInternal(3, (armor[CF] + armor[CB]) / 2,
                    (armor[LF] + armor[LB]) / 2, (armor[LA] / 2),
                    (armor[LL] / 2));
        } else {
            armor = dataFile.getDataAsInt("internal armor");
            // all the locations should be about the same...
            mech.setInternal(armor[HD], armor[CT], armor[LT], armor[LA],
                    armor[LL]);
        }

        // check for removed arm actuators...

        // no lower right arm
        if (!dataFile.getDataAsString("ra criticals")[2].trim()
                .equalsIgnoreCase("Lower Arm Actuator"))
            mech.removeCriticals(Mech.LOC_RARM, new CriticalSlot(
                    CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_LOWER_ARM));
        // no right hand
        if (!dataFile.getDataAsString("ra criticals")[3].trim()
                .equalsIgnoreCase("Hand Actuator"))
            mech.removeCriticals(Mech.LOC_RARM, new CriticalSlot(
                    CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_HAND));

        // no lower left arm
        if (!dataFile.getDataAsString("la criticals")[2].trim()
                .equalsIgnoreCase("Lower Arm Actuator"))
            mech.removeCriticals(Mech.LOC_LARM, new CriticalSlot(
                    CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_LOWER_ARM));
        // no left hand
        if (!dataFile.getDataAsString("la criticals")[3].trim()
                .equalsIgnoreCase("Hand Actuator"))
            mech.removeCriticals(Mech.LOC_LARM, new CriticalSlot(
                    CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_HAND));

        // load equipment stuff...
        Vector<String>[] criticals = new Vector[8];

        criticals[Mech.LOC_HEAD] = dataFile.getDataAsVector("hd criticals");
        criticals[Mech.LOC_LARM] = dataFile.getDataAsVector("la criticals");
        criticals[Mech.LOC_RARM] = dataFile.getDataAsVector("ra criticals");
        criticals[Mech.LOC_LLEG] = dataFile.getDataAsVector("ll criticals");
        criticals[Mech.LOC_RLEG] = dataFile.getDataAsVector("rl criticals");
        criticals[Mech.LOC_LT] = dataFile.getDataAsVector("lt criticals");
        criticals[Mech.LOC_RT] = dataFile.getDataAsVector("rt criticals");
        criticals[Mech.LOC_CT] = dataFile.getDataAsVector("ct criticals");

        // prefix is "Clan " or "IS "
        String prefix;
        if (mech.getTechLevel() == TechConstants.T_CLAN_TW) {
            prefix = "Clan ";
        } else {
            prefix = "IS ";
        }

        for (int loc = 0; loc < criticals.length; loc++) {
            for (int c = 0; c < criticals[loc].size(); c++) {
                String critName = criticals[loc].get(c).toString().trim();
                boolean rearMounted = false;

                if (critName.startsWith("(R) ")) {
                    rearMounted = true;
                    critName = critName.substring(4);
                }
                if (critName.equalsIgnoreCase("Armored Cowl")) {
                    mech.setCowl(5);
                }
                if (critName.indexOf("Engine") != -1) {
                    mech.setCritical(loc, c, new CriticalSlot(
                            CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_ENGINE));
                    continue;
                } else if (critName.equalsIgnoreCase("Life Support")) {
                    mech
                            .setCritical(loc, c, new CriticalSlot(
                                    CriticalSlot.TYPE_SYSTEM,
                                    Mech.SYSTEM_LIFE_SUPPORT));
                    continue;
                } else if (critName.equalsIgnoreCase("Sensors")) {
                    mech.setCritical(loc, c, new CriticalSlot(
                            CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_SENSORS));
                    continue;
                } else if (critName.equalsIgnoreCase("Cockpit")) {
                    mech.setCritical(loc, c, new CriticalSlot(
                            CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_COCKPIT));
                    continue;
                } else if (critName.equalsIgnoreCase("Gyro")) {
                    mech.setCritical(loc, c, new CriticalSlot(
                            CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_GYRO));
                    continue;
                }

                EquipmentType etype = EquipmentType.get(critName);
                if (etype == null) {
                    // try w/ prefix
                    etype = EquipmentType.get(prefix + critName);
                }
                if (etype != null) {
                    try {
                        mech.addEquipment(etype, loc, rearMounted);
                    } catch (LocationFullException ex) {
                        throw new EntityLoadingException(ex.getMessage());
                    }
                }

            }// end of specific location
        }// end of all crits

        if (mech.isClan()) {
            mech.addClanCase();
        }
       
        if (dataFile.exists("omni")) {
            mech.setOmni(true);
        }

        return mech;

    }
View Full Code Here

Examples of megamek.common.Mech

            tempPanel.add(fldStartElevation, GBC.eol());
        }

        // Auto-eject checkbox.
        if (entity instanceof Mech) {
            Mech mech = (Mech) entity;
            boolean hasEjectSeat = true;
            // torso mounted cockpits don't have an ejection seat
            if (mech.getCockpitType() == Mech.COCKPIT_TORSO_MOUNTED) {
                hasEjectSeat = false;
            }
            if (mech.isIndustrial()) {
                // industrials can only eject when they have an ejection seat
                for (Mounted misc : mech.getMisc()) {
                    if (misc.getType().hasFlag(MiscType.F_EJECTION_SEAT)) {
                        hasEjectSeat = true;
                    }
                }
            }
            if (hasEjectSeat) {
                tempPanel.add(labAutoEject, GBC.std());
                tempPanel.add(chAutoEject, GBC.eol());
                chAutoEject.setState(!mech.isAutoEject());
            }
        }

        tempPanel.add(labDeployment, GBC.std());
        tempPanel.add(choDeployment, GBC.eol());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.