Package megamek.common

Examples of megamek.common.Protomech


     *
     * @param entity - the <code>Entity</code> to be displayed. This should be
     *            a <code>Protomech</code> unit.
     */
    public void setEntity(Entity entity) {
        Protomech proto = (Protomech) entity;

        int loc = proto.locations();
        if (loc != Protomech.NUM_PMECH_LOCATIONS) {
            armorLabels[5].setVisible(false);
            internalLabels[5].setVisible(false);
            sectionLabels[5].setVisible(false);
        } else {
            armorLabels[5].setVisible(true);
            internalLabels[5].setVisible(true);
            sectionLabels[5].setVisible(true);
        }
        for (int i = 0; i < loc; i++) {
            // armor = proto.getArmor(i);
            // internal = proto.getInternal(i);
            armorLabels[i].setValue(proto.getArmorString(i));
            internalLabels[i].setValue(proto.getInternalString(i));
            sectionLabels[i].setValue(proto.getLocationAbbr(i));
        }
    }
View Full Code Here


     *
     * @param entity - the <code>Entity</code> to be displayed. This should be
     *            a <code>Protomech</code> unit.
     */
    public void setEntity(Entity entity) {
        Protomech proto = (Protomech) entity;

        int loc = proto.locations();
        if (loc != Protomech.NUM_PMECH_LOCATIONS) {
            armorLabels[5].setVisible(false);
            internalLabels[5].setVisible(false);
            sectionLabels[5].setVisible(false);
        } else {
            armorLabels[5].setVisible(true);
            internalLabels[5].setVisible(true);
            sectionLabels[5].setVisible(true);
        }
        for (int i = 0; i < loc; i++) {
            // armor = proto.getArmor(i);
            // internal = proto.getInternal(i);
            armorLabels[i].setValue(proto.getArmorString(i));
            internalLabels[i].setValue(proto.getInternalString(i));
            sectionLabels[i].setValue(proto.getLocationAbbr(i));
        }
    }
View Full Code Here

        dataFile = bb;
    }

    public Entity getEntity() throws EntityLoadingException {

        Protomech t = new Protomech();

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

        // Model is not strictly necessary.
        if (dataFile.exists("Model") && dataFile.getDataAsString("Model")[0] != null) {
            t.setModel(dataFile.getDataAsString("Model")[0]);
        } else {
            t.setModel("");
        }

        if (dataFile.exists("source")) {
            t.setSource(dataFile.getDataAsString("source")[0]);
        }

        if (!dataFile.exists("year")) {
            throw new EntityLoadingException("Could not find year block.");
        }
        t.setYear(dataFile.getDataAsInt("year")[0]);

        setTechLevel(t);

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

        /***********************************************************************
         * 'Protos have only one motion type. if
         * (!dataFile.exists("motion_type")) throw new
         * EntityLoadingException("Could not find movement block."); String
         * sMotion = dataFile.getDataAsString("motion_type")[0]; int nMotion =
         * -1; for (int x = 0; x < MOVES.length; x++) { if
         * (sMotion.equals(MOVES[x])) { nMotion = x; break; } } if (nMotion ==
         * -1) throw new EntityLoadingException("Invalid movment type: " +
         * sMotion); t.setMovementType(nMotion); 'Protos have only one motion
         * type. *
         **********************************************************************/
        t.setMovementMode(IEntityMovementMode.INF_JUMP);

        if (!dataFile.exists("cruiseMP")) {
            throw new EntityLoadingException("Could not find cruiseMP block.");
        }
        t.setOriginalWalkMP(dataFile.getDataAsInt("cruiseMP")[0]);

        if (dataFile.exists("jumpingMP")) {
            t.setOriginalJumpMP(dataFile.getDataAsInt("jumpingMP")[0]);
        }

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

        int[] armor = dataFile.getDataAsInt("armor");

        boolean hasMainGun = false;
        if (Protomech.NUM_PMECH_LOCATIONS == armor.length) {
            hasMainGun = true;
        } else if (Protomech.NUM_PMECH_LOCATIONS - 1 == armor.length) {
            hasMainGun = false;
        } else {
            throw new EntityLoadingException("Incorrect armor array length");
        }

        t.setHasMainGun(hasMainGun);

        // add the body to the armor array
        for (int x = 0; x < armor.length; x++) {
            t.initializeArmor(armor[x], x);
        }

        t.autoSetInternal();

        String[] abbrs = t.getLocationNames();
        for (int loop = 0; loop < t.locations(); loop++) {
            loadEquipment(t, abbrs[loop], loop);
        }
        return t;
    }
View Full Code Here

     *             <code>null</code>.
     * @throws <code>IOException</code> if there's any error on write.
     */
    public static void encode(Entity entity, Writer out) throws IOException {
        int value;
        Protomech proto = (Protomech) entity;

        // First, validate our input.
        if (null == entity) {
            throw new IllegalArgumentException("The entity is null.");
        }
        if (null == out) {
            throw new IllegalArgumentException("The writer is null.");
        }

        // Our EntityEncoder already gave us our root element.
        out.write("<bv value=\"");
        value = (int) (proto.calculateBattleValue() / proto.getCrew()
                .getBVSkillMultiplier());
        out.write(value);
        out.write("\" /><hasMainGun value=\"");
        out.write(proto.hasMainGun() ? "true" : "false");
        for (int loc = 0; loc < proto.locations(); loc++) {
            out.write("\" /><pilotDamageTaken loc=\"");
            out.write(loc);
            out.write("\" value=\"");
            value = proto.getPilotDamageTaken(loc);
            out.write(value);
        } // Handle the next location
        out.write("\" />");

    }
View Full Code Here

     *             <code>null</code>.
     * @throws <code>IllegalStateException</code> if the node does not contain
     *             a valid <code>Entity</code>.
     */
    public static Entity decode(ParsedXML node, IGame game) {
        Protomech entity = null;
        String attrStr;
        int attrVal;
        int loc;

        // Did we get a null node?
        if (null == node) {
            throw new IllegalArgumentException("The Protomech node is null.");
        }

        // Make sure that the node is for an Protomech unit.
        attrStr = node.getAttribute("name");
        if (!node.getName().equals("class") || null == attrStr
                || !attrStr.equals("Protomech")) {
            throw new IllegalStateException("Not passed an Protomech node.");
        }

        // TODO : perform version checking.

        // Create the entity.
        entity = new Protomech();

        // Walk the board node's children.
        Enumeration<?> children = node.elements();
        while (children.hasMoreElements()) {
            ParsedXML child = (ParsedXML) children.nextElement();
            String childName = child.getName();

            // Handle null child names.
            if (null == childName) {

                // No-op.
            }

            // Did we find the main gun node?
            else if (childName.equals("hasMainGun")) {

                // See if the Proto has a main gun.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode hasMainGun for a Protomech unit.");
                }

                // If the value is "true", the Proto has a main gun.
                if (attrStr.equals("true")) {
                    entity.setHasMainGun(true);
                } else {
                    entity.setHasMainGun(false);
                }
            }

            // Did we find the location-specific pilot damage node?
            else if (childName.equals("pilotDamageTaken")) {

                // Get the damage taken by the pilot in this location.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the damage for a Protomech unit.");
                }

                // Try to pull the number from the attribute string
                try {
                    attrVal = Integer.parseInt(attrStr);
                } catch (NumberFormatException exp) {
                    throw new IllegalStateException(
                            "Couldn't get an integer from " + attrStr);
                }

                // Get this location.
                attrStr = child.getAttribute("loc");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the location for a Protomech unit.");
                }

                // Try to pull the number from the attribute string
                try {
                    loc = Integer.parseInt(attrStr);
                } catch (NumberFormatException exp) {
                    throw new IllegalStateException(
                            "Couldn't get an integer from " + attrStr);
                }
                entity.setPilotDamageTaken(loc, attrVal);
            }

        } // Handle the next element.

        // Return the entity.
View Full Code Here

TOP

Related Classes of megamek.common.Protomech

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.