Package megamek.common

Examples of megamek.common.ITerrain


        ITerrainFactory tf = Terrains.getTerrainFactory();
        for (Iterator<Coords> i = elevators[roll].positions.iterator(); i
                .hasNext();) {
            Coords c = i.next();
            IHex hex = server.getGame().getBoard().getHex(c);
            ITerrain terr = hex.getTerrain(Terrains.ELEVATOR);
            // Swap the elevator and hex elevations
            // Entity elevations are not adjusted. This makes sense for
            // everything except possibly
            // VTOLs - lets assume they take an updraft and remain at the same
            // height relative to the hex
            int elevation = hex.getElevation();
            hex.setElevation(terr.getLevel());
            hex.removeTerrain(Terrains.ELEVATOR);
            hex.addTerrain(tf.createTerrain(Terrains.ELEVATOR, elevation, true,
                    terr.getExits()));
            server.sendChangedHex(c);
        }
    }
View Full Code Here


        Vector<Report> vPhaseReport = new Vector<Report>();
        IHex h = game.getBoard().getHex(c);
        if (h == null) {
            return vPhaseReport;
        }
        ITerrain woods = h.getTerrain(Terrains.WOODS);
        ITerrain jungle = h.getTerrain(Terrains.JUNGLE);
        ITerrain ice = h.getTerrain(Terrains.ICE);
        ITerrain magma = h.getTerrain(Terrains.MAGMA);
        Report r;
        if (woods != null) {
            int tf = woods.getTerrainFactor() - nDamage;
            int level = woods.getLevel();
            if (tf <= 0) {
                h.removeTerrain(Terrains.WOODS);
                h.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.ROUGH, 1));
                // light converted to rough
                r = new Report(3090);
                r.subject = entityId;
                vPhaseReport.add(r);
            } else if ((tf <= 50) && (level > 1)) {
                h.removeTerrain(Terrains.WOODS);
                h.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.WOODS, 1));
                woods = h.getTerrain(Terrains.WOODS);
                // heavy converted to light
                r = new Report(3085);
                r.subject = entityId;
                vPhaseReport.add(r);
            } else if ((tf <= 90) && (level > 2)) {
                h.removeTerrain(Terrains.WOODS);
                h.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.WOODS, 2));
                woods = h.getTerrain(Terrains.WOODS);
                // ultra heavy converted to heavy
                r = new Report(3082);
                r.subject = entityId;
                vPhaseReport.add(r);
            }
            woods.setTerrainFactor(tf);
        }
        if (jungle != null) {
            int tf = jungle.getTerrainFactor() - nDamage;
            int level = jungle.getLevel();
            if (tf < 0) {
                h.removeTerrain(Terrains.JUNGLE);
                h.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.ROUGH, 1));
                // light converted to rough
                r = new Report(3091);
                r.subject = entityId;
                vPhaseReport.add(r);
            } else if ((tf <= 50) && (level > 1)) {
                h.removeTerrain(Terrains.JUNGLE);
                h.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.JUNGLE, 1));
                jungle = h.getTerrain(Terrains.JUNGLE);
                // heavy converted to light
                r = new Report(3086);
                r.subject = entityId;
                vPhaseReport.add(r);
            } else if ((tf <= 90) && (level > 2)) {
                h.removeTerrain(Terrains.JUNGLE);
                h.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.JUNGLE, 2));
                jungle = h.getTerrain(Terrains.JUNGLE);
                // ultra heavy converted to heavy
                r = new Report(3083);
                r.subject = entityId;
                vPhaseReport.add(r);
            }
            jungle.setTerrainFactor(tf);
        }
        if (ice != null) {
            int tf = ice.getTerrainFactor() - nDamage;
            if (tf <= 0) {
                // ice melted
                r = new Report(3092);
                r.subject = entityId;
                vPhaseReport.add(r);
                vPhaseReport.addAll(resolveIceBroken(c));
            } else {
                ice.setTerrainFactor(tf);
            }
        }
        if ((magma != null) && (magma.getLevel() == 1)) {
            int tf = magma.getTerrainFactor() - nDamage;
            if (tf <= 0) {
                // magma crust destroyed
                r = new Report(3093);
                r.subject = entityId;
                vPhaseReport.add(r);
                h.removeTerrain(Terrains.MAGMA);
                h.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.MAGMA, 2));
                for (Enumeration<Entity> e = getGame()
                        .getEntities(c); e.hasMoreElements();) {
                    doMagmaDamage(e.nextElement(), false);
                }
            } else {
                magma.setTerrainFactor(tf);
            }
        }
        sendChangedHex(c);

        //any attempt to clear an heavy industrial hex may cause an exposion
View Full Code Here

                && org.getElevation() != com.getElevation()) {
            return 0;
        }
        // check terrain
        for (int i = 0; i < Terrains.SIZE; i++) {
            ITerrain cTerr = com.getTerrain(i);
            ITerrain oTerr = org.getTerrain(i);
            if (cTerr == null) {
                continue;
            } else if (oTerr == null
                    || (cTerr.getLevel() != ITerrain.WILDCARD && oTerr
                            .getLevel() != cTerr.getLevel())
                    || (cTerr.hasExitsSpecified() && oTerr.getExits() != cTerr
                            .getExits())) {
                return 0;
            }
        }
        // A themed original matches any unthemed comparason.
View Full Code Here

        // Bug 732188: Have a non-zero minimum terrain match.
        double maxTerrains = Math.max(org.terrainsPresent(), com
                .terrainsPresent());
        double matches = 0.0;
        for (int i = 0; i < Terrains.SIZE; i++) {
            ITerrain cTerr = com.getTerrain(i);
            ITerrain oTerr = org.getTerrain(i);
            if (cTerr == null || oTerr == null) {
                continue;
            }
            double thisMatch = 0;

            if (cTerr.getLevel() == ITerrain.WILDCARD) {
                thisMatch = 1.0;
            } else {
                thisMatch = 1.0 / (Math
                        .abs(oTerr.getLevel() - cTerr.getLevel()) + 1.0);
            }
            // without exit match, terrain counts... um, half?
            if (cTerr.hasExitsSpecified()
                    && oTerr.getExits() != cTerr.getExits()) {
                thisMatch *= 0.5;
            }
            // add up match value
            matches += thisMatch;
        }
View Full Code Here

                && org.getElevation() != com.getElevation()) {
            return 0;
        }
        // check terrain
        for (int i = 0; i < Terrains.SIZE; i++) {
            ITerrain cTerr = com.getTerrain(i);
            ITerrain oTerr = org.getTerrain(i);
            if (cTerr == null) {
                continue;
            } else if (oTerr == null
                    || (cTerr.getLevel() != ITerrain.WILDCARD && oTerr
                            .getLevel() != cTerr.getLevel())
                    || (cTerr.hasExitsSpecified() && oTerr.getExits() != cTerr
                            .getExits())) {
                return 0;
            }
        }
        // A themed original matches any unthemed comparason.
View Full Code Here

        // Bug 732188: Have a non-zero minimum terrain match.
        double maxTerrains = Math.max(org.terrainsPresent(), com
                .terrainsPresent());
        double matches = 0.0;
        for (int i = 0; i < Terrains.SIZE; i++) {
            ITerrain cTerr = com.getTerrain(i);
            ITerrain oTerr = org.getTerrain(i);
            if (cTerr == null || oTerr == null) {
                continue;
            }
            double thisMatch = 0;

            if (cTerr.getLevel() == ITerrain.WILDCARD) {
                thisMatch = 1.0;
            } else {
                thisMatch = 1.0 / (Math
                        .abs(oTerr.getLevel() - cTerr.getLevel()) + 1.0);
            }
            // without exit match, terrain counts... um, half?
            if (cTerr.hasExitsSpecified()
                    && oTerr.getExits() != cTerr.getExits()) {
                thisMatch *= 0.5;
            }
            // add up match value
            matches += thisMatch;
        }
View Full Code Here

    }

    private void connectHexes(Coords src, Coords dest, int roadStyle) {
        if (board.contains(src)) {
            IHex hex = board.getHex(src);
            ITerrain t = hex.getTerrain(Terrains.ROAD);
            if (t == null) {
                t = hex.getTerrain(Terrains.BRIDGE);
            }
            if (t == null) {
                addRoad(hex, src.direction(dest), roadStyle);
            } else {
                t.setExit(src.direction(dest), true);
            }
        }
    }
View Full Code Here

            field = iter.next();
            if (exclusive) {
                field.removeAllTerrains();
            }
            int tempInt = (Compute.randomInt(100) < probMore) ? 2 : 1;
            ITerrain tempTerrain = f.createTerrain(terrainType, tempInt);
            field.addTerrain(tempTerrain);
            unUsed.remove(field);
            findAllUnused(board, terrainType, alreadyUsed, unUsed, field,
                    reverseHex);
        }
View Full Code Here

        // Walk through the current data array and build a new one.
        int newX;
        int newY;
        IHex tempHex;
        ITerrain terr;
        for (int oldX = 0; oldX < stopX; oldX++) {
            // Calculate the new X position of the flipped hex.
            if (horiz) {
                newX = width - oldX - 1;
            } else {
                newX = oldX;
            }
            for (int oldY = 0; oldY < stopY; oldY++) {
                // Calculate the new Y position of the flipped hex.
                if (vert) {
                    newY = height - oldY - 1;
                } else {
                    newY = oldY;
                }

                // Swap the old hex for the new hex.
                tempHex = board.getHex(oldX, oldY);
                board.setHex(oldX, oldY, board.getHex(newX, newY));
                board.setHex(newX, newY, tempHex);

                IHex newHex = board.getHex(newX, newY);
                IHex oldHex = board.getHex(oldX, oldY);

                // Update the road exits in the swapped hexes.
                terr = newHex.getTerrain(Terrains.ROAD);
                if (null != terr) {
                    terr.flipExits(horiz, vert);
                }
                terr = oldHex.getTerrain(Terrains.ROAD);
                if (null != terr) {
                    terr.flipExits(horiz, vert);
                }

                // Update the building exits in the swapped hexes.
                terr = newHex.getTerrain(Terrains.BUILDING);
                if (null != terr) {
                    terr.flipExits(horiz, vert);
                }
                terr = oldHex.getTerrain(Terrains.BUILDING);
                if (null != terr) {
                    terr.flipExits(horiz, vert);
                }

                // Update the fuel tank exits in the swapped hexes.
                terr = newHex.getTerrain(Terrains.FUEL_TANK);
                if (null != terr) {
                    terr.flipExits(horiz, vert);
                }
                terr = oldHex.getTerrain(Terrains.FUEL_TANK);
                if (null != terr) {
                    terr.flipExits(horiz, vert);
                }

                // Update the bridge exits in the swapped hexes.
                terr = newHex.getTerrain(Terrains.BRIDGE);
                if (null != terr) {
                    terr.flipExits(horiz, vert);
                }
                terr = oldHex.getTerrain(Terrains.BRIDGE);
                if (null != terr) {
                    terr.flipExits(horiz, vert);
                }
            }
        }
    }
View Full Code Here

    public int checkTerrain(int nDamage, Entity entityTarget, Vector<Report>vPhaseReport){
        if ( game.getOptions().booleanOption("tacops_woods_cover") &&
                (game.getBoard().getHex(entityTarget.getPosition()).containsTerrain(Terrains.WOODS)
                || game.getBoard().getHex(entityTarget.getPosition()).containsTerrain(Terrains.JUNGLE))
                && !(entityTarget.getSwarmAttackerId() == ae.getId())) {
            ITerrain woodHex = game.getBoard().getHex(entityTarget.getPosition()).getTerrain(Terrains.WOODS);
            ITerrain jungleHex = game.getBoard().getHex(entityTarget.getPosition()).getTerrain(Terrains.JUNGLE);
            int treeAbsorbs = 0;
            String hexType = "";
            if ( woodHex != null ){
                treeAbsorbs = woodHex.getLevel() * 2;
                hexType = "wooded";
            }else if (jungleHex != null){
                treeAbsorbs = jungleHex.getLevel() * 2;
                hexType = "jungle";
            }

            //Do not absorb more damage then the weapon can do.
            treeAbsorbs = Math.min(nDamage, treeAbsorbs);
View Full Code Here

TOP

Related Classes of megamek.common.ITerrain

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.