Package megamek.common

Examples of megamek.common.Building$DemolitionCharge


        Report r;

        if (!flak) {
            vPhaseReport.addAll(tryClearHex(coords, damage * 2, subjectId));
        }
        Building bldg = game.getBoard().getBuildingAt(coords);
        int bldgAbsorbs = 0;
        if ((bldg != null) && !(flak && (flakElevation > hex.terrainLevel(Terrains.BLDG_ELEV)))) {
            bldgAbsorbs = bldg.getPhaseCF(coords) / 10;
            if (!((ammo != null) && (ammo.getMunitionType() == AmmoType.M_FLECHETTE))) {
                // damage the building
                Vector<Report> buildingReport = damageBuilding(bldg, damage, coords);
                for (Report report : buildingReport) {
                    report.subject = subjectId;
View Full Code Here


                : null;
        final boolean targetInBuilding = Compute.isInBuilding(game,
                entityTarget);

        // Which building takes the damage?
        Building bldg = game.getBoard().getBuildingAt(target.getPosition());

        // Report weapon attack and its to-hit value.
        r = new Report(3115);
        r.indent();
        r.newlines = 0;
View Full Code Here

            // Handle non-infantry moving into a building.
            int buildingMove = entity.checkMovementInBuilding(step, prevStep, curPos, lastPos);
            if ((buildingMove > 0) && !(entity instanceof Protomech)) {

                // Get the building being entered.
                Building bldgEntered = null;
                if ((buildingMove & 2) == 2) {
                    bldgEntered = client.game.getBoard().getBuildingAt(curPos);
                }

                if (bldgEntered != null) {
View Full Code Here

            else if (childName.equals("buildings")) {
                subnodes = child.elements();
                while (subnodes.hasMoreElements()) {
                    subnode = (ParsedXML) subnodes.nextElement();
                    if (subnode.getName().equals("building")) {
                        Building bldg = BuildingEncoder.decode(subnode, game);
                        if (null != bldg) {
                            buildings.addElement(bldg);
                        }
                    }
                } // Handle the next building
View Full Code Here

        if (mhex.containsTerrain(Terrains.SWAMP)) {
            out.add(Messages.getString("BoardView1.TipSwamp"));
        }

        if (mhex.containsTerrain(Terrains.FUEL_TANK)) {
            Building bldg = game.getBoard().getBuildingAt(coords);
            StringBuffer buf = new StringBuffer(Messages.getString("BoardView1.Height")); //$NON-NLS-1$
            buf.append(mhex.terrainLevel(Terrains.FUEL_TANK_ELEV));
            buf.append(" "); //$NON-NLS-1$
            buf.append(bldg.toString());
            buf.append(Messages.getString("BoardView1.CF")); //$NON-NLS-1$
            buf.append(bldg.getCurrentCF(coords));
            out.add(buf.toString());
        }

        if (mhex.containsTerrain(Terrains.BUILDING)) {
            Building bldg = game.getBoard().getBuildingAt(coords);
            StringBuffer buf = new StringBuffer(Messages.getString("BoardView1.Height")); //$NON-NLS-1$
            buf.append(mhex.terrainLevel(Terrains.BLDG_ELEV));
            buf.append(" "); //$NON-NLS-1$
            buf.append(bldg.toString());
            buf.append(Messages.getString("BoardView1.CF")); //$NON-NLS-1$
            buf.append(bldg.getCurrentCF(coords));
            out.add(buf.toString());
        }

        if (mhex.containsTerrain(Terrains.BRIDGE)) {
            Building bldg = game.getBoard().getBuildingAt(coords);
            StringBuffer buf = new StringBuffer(Messages.getString("BoardView1.Height")); //$NON-NLS-1$
            buf.append(mhex.terrainLevel(Terrains.BRIDGE_ELEV));
            buf.append(" "); //$NON-NLS-1$
            buf.append(bldg.toString());
            buf.append(Messages.getString("BoardView1.CF")); //$NON-NLS-1$
            buf.append(bldg.getCurrentCF(coords));
            out.add(buf.toString());
        }

        if (game.containsMinefield(coords)) {
            Vector<Minefield> minefields = game.getMinefields(coords);
View Full Code Here

     *             a valid <code>Building</code>.
     */
    public static Building decode(ParsedXML node, IGame game) {
        String attrStr = null;
        int attrVal = 0;
        Building retVal = null;
        Vector<Coords> coordVec = new Vector<Coords>();
        Map<Coords, Boolean> burning = new HashMap<Coords, Boolean>();
        Map<Coords, Integer> curCF = new HashMap<Coords, Integer>();
        Map<Coords, Integer> phaseCF = new HashMap<Coords, Integer>();
        Enumeration<?> subnodes = null;
        ParsedXML subnode = null;
        Coords coords = null;
        int type = -1;
        int id = -1;
        String name = null;

        // Walk the building 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 buildingData node?
            else if (childName.equals("buildingData")) {

                // There should be only one buildingData node.
                if (null != retVal) {
                    throw new IllegalStateException(
                            "More than one 'buildingData' node in a building node.");
                }

                // Read the coords of the building.
                subnodes = child.elements();
                while (subnodes.hasMoreElements()) {
                    subnode = (ParsedXML) subnodes.nextElement();

                    // Have we found the coords subnode?
                    if (subnode.getName().equals("coords")) {
                        coords = CoordsEncoder.decode(subnode, game);
                        if (null != coords) {
                            coordVec.addElement(coords);
                        }
                        // Do we have a 'currentCF' attribute?
                        attrStr = subnode.getAttribute("currentCF");
                        if (null != attrStr) {

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

                            // Do we have a valid value?
                            if (0 > attrVal) {
                                throw new IllegalStateException(
                                        "Illegal value for currentCF: " + attrStr);
                            }
                            curCF.put(coords, attrVal);
                        }

                        // Do we have a 'phaseCF' attribute?
                        attrStr = subnode.getAttribute("phaseCF");
                        if (null != attrStr) {

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

                            // Do we have a valid value?
                            if (0 >= attrVal) {
                                throw new IllegalStateException(
                                        "Illegal value for phaseCF: " + attrStr);
                            }
                            phaseCF.put(coords, attrVal);
                        }
                        // Set the building's 'isBurning' flag.
                        burning.put(coords,StringUtil.parseBoolean(child
                                .getAttribute("isBurning")));
                    }

                } // Check the next subnode

                // We *did* find at least one coords for the building, right?
                if (0 >= coordVec.size()) {
                    throw new IllegalStateException(
                            "Couldn't decode the coords for the building.");
                }

                // Get the building type.
                attrStr = child.getAttribute("type");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the buildingData for a building node.");
                }

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

                // Do we have a valid value?
                if (type < 0 || type > Building.WALL) {
                    throw new IllegalStateException("Illegal value for type: "
                            + attrStr);
                }

                // Get the building id.
                attrStr = child.getAttribute("id");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the buildingData for a building node.");
                }

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

                // Do we have a valid value?
                if (0 >= id) {
                    throw new IllegalStateException("Illegal value for id: "
                            + attrStr);
                }

                // Get the building name.
                attrStr = child.getAttribute("name");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the buildingData for a building node.");
                }
                name = attrStr;

                // Try to create the building.
                try {
                    retVal = new Building(type, id, name, coordVec);
                } catch (IllegalArgumentException iaexp) {
                    throw new IllegalStateException(iaexp.getMessage());
                }
                for (Coords coord : burning.keySet()) {
                    retVal.setBurning(burning.get(coord), coord);
                }
                for (Coords coord : curCF.keySet()) {
                    retVal.setCurrentCF(curCF.get(coord), coord);
                }
                for (Coords coord : phaseCF.keySet()) {
                    retVal.setPhaseCF(phaseCF.get(coord), coord);
                }

            } // End found-"buildingData"-child

        } // Look at the next child.
View Full Code Here

TOP

Related Classes of megamek.common.Building$DemolitionCharge

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.